Skip to content

Commit

Permalink
feature: add new "lazy-wheel" config option
Browse files Browse the repository at this point in the history
If active and a server supports range requests, we do not have to download entire wheels to fetch metadata but can just download the METADATA file from the remote wheel with a couple of range requests.
  • Loading branch information
radoering committed Jan 4, 2024
1 parent 022308e commit 9c20ca6
Show file tree
Hide file tree
Showing 19 changed files with 1,466 additions and 18 deletions.
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, lambda val: str(val)),
"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
22 changes: 16 additions & 6 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

from poetry.core.packages.project_package import ProjectPackage

from poetry.inspection.lazy_wheel import MemoryWheel


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -229,9 +231,7 @@ def to_package(
return package

@classmethod
def _from_distribution(
cls, dist: pkginfo.BDist | pkginfo.SDist | pkginfo.Wheel
) -> PackageInfo:
def _from_distribution(cls, dist: pkginfo.Distribution) -> PackageInfo:
"""
Helper method to parse package information from a `pkginfo.Distribution`
instance.
Expand All @@ -242,7 +242,7 @@ def _from_distribution(

if dist.requires_dist:
requirements = list(dist.requires_dist)
else:
elif isinstance(dist, (pkginfo.BDist, pkginfo.SDist, pkginfo.Wheel)):
requires = Path(dist.filename) / "requires.txt"
if requires.exists():
text = requires.read_text(encoding="utf-8")
Expand All @@ -256,8 +256,9 @@ def _from_distribution(
requires_python=dist.requires_python,
)

info._source_type = "file"
info._source_url = Path(dist.filename).resolve().as_posix()
if isinstance(dist, (pkginfo.BDist, pkginfo.SDist, pkginfo.Wheel)):
info._source_type = "file"
info._source_url = Path(dist.filename).resolve().as_posix()

return info

Expand Down Expand Up @@ -520,6 +521,15 @@ def from_wheel(cls, path: Path) -> PackageInfo:
except ValueError:
return PackageInfo()

@classmethod
def from_memory_wheel(cls, wheel: MemoryWheel) -> PackageInfo:
"""
Gather package information from a partial fetched wheel kept in memory.
:param path: Path to wheel.
"""
return cls._from_distribution(wheel)

@classmethod
def from_bdist(cls, path: Path) -> PackageInfo:
"""
Expand Down
Loading

0 comments on commit 9c20ca6

Please sign in to comment.