From efe2d27451d50b165df78093bf5885da713fbdf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 14 Apr 2023 08:12:33 +0200 Subject: [PATCH] Further refactor is_wheel_from_cache --- src/pip/_internal/req/req_install.py | 14 +++++++++----- src/pip/_internal/resolution/legacy/resolver.py | 1 - .../_internal/resolution/resolvelib/candidates.py | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 50d89b1be37..a0ea58bd194 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -109,11 +109,9 @@ def __init__( link = Link(req.url) self.link = self.original_link = link - # When is_wheel_from_cache is True, it means that this InstallRequirement - # is a local wheel file in the cache of locally built wheels. - self.is_wheel_from_cache = False - # When is_wheel_from_cache is True, this is the source link corresponding - # to the cache entry, which was used to download and build the cached wheel. + # When this InstallRequirement is a wheel obtained from the cache of locally + # built wheels, this is the source link corresponding to the cache entry, which + # was used to download and build the cached wheel. self.cached_wheel_source_link: Optional[Link] = None # Information about the location of the artifact that was downloaded . This @@ -443,6 +441,12 @@ def is_wheel(self) -> bool: return False return self.link.is_wheel + @property + def is_wheel_from_cache(self) -> bool: + # When True, it means that this InstallRequirement is a local wheel file in the + # cache of locally built wheels. + return self.cached_wheel_source_link is not None + # Things valid for sdists @property def unpacked_source_directory(self) -> str: diff --git a/src/pip/_internal/resolution/legacy/resolver.py b/src/pip/_internal/resolution/legacy/resolver.py index 216b0b81c27..b17b7e4530b 100644 --- a/src/pip/_internal/resolution/legacy/resolver.py +++ b/src/pip/_internal/resolution/legacy/resolver.py @@ -432,7 +432,6 @@ def _populate_link(self, req: InstallRequirement) -> None: logger.debug("Using cached wheel link: %s", cache_entry.link) if req.link is req.original_link and cache_entry.persistent: req.cached_wheel_source_link = req.link - req.is_wheel_from_cache = True if cache_entry.origin is not None: req.download_info = cache_entry.origin else: diff --git a/src/pip/_internal/resolution/resolvelib/candidates.py b/src/pip/_internal/resolution/resolvelib/candidates.py index 2c315b4600c..31020e27ad1 100644 --- a/src/pip/_internal/resolution/resolvelib/candidates.py +++ b/src/pip/_internal/resolution/resolvelib/candidates.py @@ -281,7 +281,6 @@ def __init__( assert ireq.link.is_file if cache_entry.persistent and template.link is template.original_link: ireq.cached_wheel_source_link = source_link - ireq.is_wheel_from_cache = True if cache_entry.origin is not None: ireq.download_info = cache_entry.origin else: