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

use .metadata distribution info when possible #11512

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/11512.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid downloading wheels when performing a ``--dry-run`` install when .metadata files are used.
4 changes: 3 additions & 1 deletion src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ def run(self, options: Values, args: List[str]) -> int:
self.trace_basic_info(finder)

requirement_set = resolver.resolve(
reqs, check_supported_wheels=not options.target_dir
reqs,
check_supported_wheels=not options.target_dir,
dry_run=options.dry_run,
)

if options.json_report_file:
Expand Down
12 changes: 12 additions & 0 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ def _fetch_metadata_using_link_data_attr(
raise MetadataInconsistent(
req, "Name", req.req.name, metadata_dist.raw_name
)
# (5) Store the dist in the install requirement for reporting
req.dist_from_metadata = metadata_dist
return metadata_dist

def _fetch_metadata_using_lazy_wheel(
Expand Down Expand Up @@ -490,6 +492,16 @@ def prepare_linked_requirement(
# None of the optimizations worked, fully prepare the requirement
return self._prepare_linked_requirement(req, parallel_builds)

def prepare_download_info(self, reqs: Iterable[InstallRequirement]) -> None:
"""Prepare linked requirements with download_info, if needed."""
# During install --dry-run, .metadata files or lazy wheels may be used when determining
# distribution dependencies. The associated wheel does not need to be downloaded so the
# download_info need to be derived from the link. If the link does not contain a hash no
# hash will be included in the download_info.
for req in reqs:
if req.download_info is None:
req.download_info = direct_url_from_link(req.link, req.source_dir)

def prepare_linked_requirements_more(
self, reqs: Iterable[InstallRequirement], parallel_builds: bool = False
) -> None:
Expand Down
6 changes: 6 additions & 0 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def __init__(
# This requirement needs more preparation before it can be built
self.needs_more_preparation = False

# Distribution from the .metadata file referenced by the PEP 658
# data-dist-info-metadata attribute.
self.dist_from_metadata: Optional[BaseDistribution] = None

def __str__(self) -> str:
if self.req:
s = str(self.req)
Expand Down Expand Up @@ -568,6 +572,8 @@ def get_dist(self) -> BaseDistribution:
return get_wheel_distribution(
FilesystemWheel(self.local_file_path), canonicalize_name(self.name)
)
elif self.is_wheel and self.dist_from_metadata:
return self.dist_from_metadata
raise AssertionError(
f"InstallRequirement {self} has no metadata directory and no wheel: "
f"can't make a distribution."
Expand Down
10 changes: 8 additions & 2 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def __init__(
self._result: Optional[Result] = None

def resolve(
self, root_reqs: List[InstallRequirement], check_supported_wheels: bool
self,
root_reqs: List[InstallRequirement],
check_supported_wheels: bool,
dry_run: bool = False,
) -> RequirementSet:
collected = self.factory.collect_root_requirements(root_reqs)
provider = PipProvider(
Expand Down Expand Up @@ -158,7 +161,10 @@ def resolve(
req_set.add_named_requirement(ireq)

reqs = req_set.all_requirements
self.factory.preparer.prepare_linked_requirements_more(reqs)
if dry_run:
self.factory.preparer.prepare_download_info(reqs)
else:
self.factory.preparer.prepare_linked_requirements_more(reqs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this to resolve the merge conflict, but I need to look into the change that introduced this:

Suggested change
self.factory.preparer.prepare_linked_requirements_more(reqs)
self.factory.preparer.prepare_linked_requirements_more(reqs)
for req in reqs:
req.prepared = True
req.needs_more_preparation = False

return req_set

def get_installation_order(
Expand Down