Skip to content

Commit d0f80a4

Browse files
authored
Merge pull request #8804 from McSinyx/fast-deps-check-dl-dir
2 parents fe2075b + 2ef8040 commit d0f80a4

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

news/8804.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Check the download directory for existing wheels to possibly avoid
2+
fetching metadata when the ``fast-deps`` feature is used with
3+
``pip wheel`` and ``pip download``.

src/pip/_internal/operations/prepare.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -491,26 +491,32 @@ def prepare_linked_requirement(self, req, parallel_builds=False):
491491
link = req.link
492492
self._log_preparing_link(req)
493493
with indent_log():
494-
wheel_dist = self._fetch_metadata_using_lazy_wheel(link)
495-
if wheel_dist is not None:
496-
req.needs_more_preparation = True
497-
return wheel_dist
494+
# Check if the relevant file is already available
495+
# in the download directory
496+
file_path = None
497+
download_dir = self._get_download_dir(req.link)
498+
if download_dir is not None and link.is_wheel:
499+
hashes = self._get_linked_req_hashes(req)
500+
file_path = _check_download_dir(req.link, download_dir, hashes)
501+
502+
if file_path is not None:
503+
# The file is already available, so mark it as downloaded
504+
self._downloaded[req.link.url] = file_path, None
505+
else:
506+
# The file is not available, attempt to fetch only metadata
507+
wheel_dist = self._fetch_metadata_using_lazy_wheel(link)
508+
if wheel_dist is not None:
509+
req.needs_more_preparation = True
510+
return wheel_dist
511+
512+
# None of the optimizations worked, fully prepare the requirement
498513
return self._prepare_linked_requirement(req, parallel_builds)
499514

500515
def prepare_linked_requirements_more(self, reqs, parallel_builds=False):
501516
# type: (Iterable[InstallRequirement], bool) -> None
502517
"""Prepare a linked requirement more, if needed."""
503518
reqs = [req for req in reqs if req.needs_more_preparation]
504-
links = [] # type: List[Link]
505-
for req in reqs:
506-
download_dir = self._get_download_dir(req.link)
507-
if download_dir is not None:
508-
hashes = self._get_linked_req_hashes(req)
509-
file_path = _check_download_dir(req.link, download_dir, hashes)
510-
if download_dir is None or file_path is None:
511-
links.append(req.link)
512-
else:
513-
self._downloaded[req.link.url] = file_path, None
519+
links = [req.link for req in reqs]
514520

515521
# Let's download to a temporary directory.
516522
tmpdir = TempDirectory(kind="unpack", globally_managed=True).path

0 commit comments

Comments
 (0)