From c6d0b0c791aa868ff6df9ece4f982e1f4523a4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Thu, 1 Oct 2020 20:56:01 +0700 Subject: [PATCH] Comment and rework conditionals in download dir check Co-authored-by: Pradyun Gedam <3275593+pradyunsg@users.noreply.github.com> --- src/pip/_internal/operations/prepare.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 09540edce74..b413e9af7f6 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -486,20 +486,24 @@ def prepare_linked_requirement(self, req, parallel_builds=False): link = req.link self._log_preparing_link(req) with indent_log(): + # 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: - self._downloaded[req.link.url] = file_path, None - else: - file_path = None - if file_path is None: + 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):