Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add new "lazy-wheel" config option #8815

Merged
merged 9 commits into from
Jan 20, 2024
17 changes: 17 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ across all your projects if incorrectly set.

Use parallel execution when using the new (`>=1.1.0`) installer.

### `solver.lazy-wheel`

**Type**: `boolean`

**Default**: `true`

**Environment Variable**: `POETRY_SOLVER_LAZY_WHEEL`

*Introduced in 1.8.0*

Do not download entire wheels to extract metadata but use
[HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests)
to only download the METADATA files of wheels.
Especially with slow network connections this setting can speed up dependency resolution significantly.
If the cache has already been filled or the server does not support HTTP range requests,
this setting makes no difference.

### `virtualenvs.create`

**Type**: `boolean`
Expand Down
4 changes: 4 additions & 0 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class Config:
"max-workers": None,
"no-binary": None,
},
"solver": {
"lazy-wheel": True,
},
"warnings": {
"export": True,
},
Expand Down Expand Up @@ -296,6 +299,7 @@ def _get_normalizer(name: str) -> Callable[[str], Any]:
"experimental.system-git-client",
"installer.modern-installation",
"installer.parallel",
"solver.lazy-wheel",
"warnings.export",
}:
return boolean_normalizer
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any]]:
),
"virtualenvs.path": (str, lambda val: str(Path(val))),
"virtualenvs.prefer-active-python": (boolean_validator, boolean_normalizer),
"virtualenvs.prompt": (str, str),
"experimental.system-git-client": (boolean_validator, boolean_normalizer),
"installer.modern-installation": (boolean_validator, boolean_normalizer),
"installer.parallel": (boolean_validator, boolean_normalizer),
"installer.max-workers": (lambda val: int(val) > 0, int_normalizer),
"virtualenvs.prompt": (str, lambda val: str(val)),
"installer.no-binary": (
PackageFilterPolicy.validator,
PackageFilterPolicy.normalize,
),
"solver.lazy-wheel": (boolean_validator, boolean_normalizer),
"warnings.export": (boolean_validator, boolean_normalizer),
}

Expand Down
24 changes: 20 additions & 4 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
if TYPE_CHECKING:
from collections.abc import Iterator

from packaging.metadata import RawMetadata
from poetry.core.packages.project_package import ProjectPackage


Expand Down Expand Up @@ -392,7 +393,22 @@ def _find_dist_info(path: Path) -> Iterator[Path]:
yield Path(d)

@classmethod
def from_metadata(cls, path: Path) -> PackageInfo | None:
def from_metadata(cls, metadata: RawMetadata) -> PackageInfo:
"""
Create package information from core metadata.

:param metadata: raw metadata
"""
return cls(
name=metadata.get("name"),
version=metadata.get("version"),
summary=metadata.get("summary"),
requires_dist=metadata.get("requires_dist"),
requires_python=metadata.get("requires_python"),
)

@classmethod
def from_metadata_directory(cls, path: Path) -> PackageInfo | None:
"""
Helper method to parse package information from an unpacked metadata directory.

Expand Down Expand Up @@ -474,7 +490,7 @@ def from_directory(cls, path: Path, disable_build: bool = False) -> PackageInfo:
if project_package:
info = cls.from_package(project_package)
else:
info = cls.from_metadata(path)
info = cls.from_metadata_directory(path)

if not info or info.requires_dist is None:
try:
Expand Down Expand Up @@ -583,7 +599,7 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
*PEP517_META_BUILD_DEPS,
)
venv.run_python_script(pep517_meta_build_script)
info = PackageInfo.from_metadata(dest_dir)
info = PackageInfo.from_metadata_directory(dest_dir)
except EnvCommandError as e:
# something went wrong while attempting pep517 metadata build
# fallback to egg_info if setup.py available
Expand All @@ -600,7 +616,7 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
os.chdir(path)
try:
venv.run("python", "setup.py", "egg_info")
info = PackageInfo.from_metadata(path)
info = PackageInfo.from_metadata_directory(path)
except EnvCommandError as fbe:
raise PackageInfoError(
path, e, "Fallback egg_info generation failed.", fbe
Expand Down
Loading