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

[fast-deps] Check download directory before making requests #8804

Merged
merged 2 commits into from
Oct 1, 2020
Merged
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
3 changes: 3 additions & 0 deletions news/8804.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Check the download directory for existing wheels to possibly avoid
fetching metadata when the ``fast-deps`` feature is used with
``pip wheel`` and ``pip download``.
34 changes: 20 additions & 14 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,26 +486,32 @@ def prepare_linked_requirement(self, req, parallel_builds=False):
link = req.link
self._log_preparing_link(req)
with indent_log():
wheel_dist = self._fetch_metadata_using_lazy_wheel(link)
if wheel_dist is not None:
req.needs_more_preparation = True
return wheel_dist
# Check if the relevant file is already available
# in the download directory
file_path = None
download_dir = self._get_download_dir(req.link)
if download_dir is not None and link.is_wheel:
hashes = self._get_linked_req_hashes(req)
file_path = _check_download_dir(req.link, download_dir, hashes)

if file_path is not None:
# The file is already available, so mark it as downloaded
self._downloaded[req.link.url] = file_path, None
else:
# The file is not available, attempt to fetch only metadata
wheel_dist = self._fetch_metadata_using_lazy_wheel(link)
if wheel_dist is not None:
req.needs_more_preparation = True
return wheel_dist

# None of the optimizations worked, fully prepare the requirement
return self._prepare_linked_requirement(req, parallel_builds)

def prepare_linked_requirements_more(self, reqs, parallel_builds=False):
# type: (Iterable[InstallRequirement], bool) -> None
"""Prepare a linked requirement more, if needed."""
reqs = [req for req in reqs if req.needs_more_preparation]
links = [] # type: List[Link]
for req in reqs:
download_dir = self._get_download_dir(req.link)
if download_dir is not None:
hashes = self._get_linked_req_hashes(req)
file_path = _check_download_dir(req.link, download_dir, hashes)
if download_dir is None or file_path is None:
links.append(req.link)
else:
self._downloaded[req.link.url] = file_path, None
links = [req.link for req in reqs]

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