From 8abc7e9caafcf9b9f925f275051e73bbb4f810c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Mon, 10 Apr 2023 14:46:12 +0200 Subject: [PATCH] Introduce ireq.cached_wheel_source_link --- src/pip/_internal/operations/prepare.py | 5 +---- src/pip/_internal/req/req_install.py | 3 +++ src/pip/_internal/resolution/legacy/resolver.py | 1 + src/pip/_internal/resolution/resolvelib/candidates.py | 1 + tests/unit/test_req.py | 2 ++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 3e8242e797a..8584e216a78 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -575,10 +575,7 @@ def _prepare_linked_requirement( "don't match, ignoring cached built wheel " "and re-downloading source." ) - # For some reason req.original_link is not set here, even though - # req.is_wheel_from_cache is True. So we get the original - # link from download_info. - req.link = Link(req.download_info.url) # TODO comes_from? + req.link = req.cached_wheel_source_link link = req.link self._ensure_link_req_src_dir(req, parallel_builds) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index b23c861fbec..8b0bf587cdc 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -112,6 +112,9 @@ def __init__( # 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. + self.cached_wheel_source_link: Optional[Link] = None # Information about the location of the artifact that was downloaded . This # property is guaranteed to be set in resolver results. diff --git a/src/pip/_internal/resolution/legacy/resolver.py b/src/pip/_internal/resolution/legacy/resolver.py index 2e02a0f7f2d..6e873262f0e 100644 --- a/src/pip/_internal/resolution/legacy/resolver.py +++ b/src/pip/_internal/resolution/legacy/resolver.py @@ -431,6 +431,7 @@ def _populate_link(self, req: InstallRequirement) -> None: if cache_entry is not 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 diff --git a/src/pip/_internal/resolution/resolvelib/candidates.py b/src/pip/_internal/resolution/resolvelib/candidates.py index 2db00297d81..7df48d9e43a 100644 --- a/src/pip/_internal/resolution/resolvelib/candidates.py +++ b/src/pip/_internal/resolution/resolvelib/candidates.py @@ -277,6 +277,7 @@ def __init__( assert ireq.link.is_wheel 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 diff --git a/tests/unit/test_req.py b/tests/unit/test_req.py index eb486ba0f43..c9742812be4 100644 --- a/tests/unit/test_req.py +++ b/tests/unit/test_req.py @@ -412,6 +412,7 @@ def test_download_info_archive_legacy_cache( assert len(reqset.all_requirements) == 1 req = reqset.all_requirements[0] assert req.is_wheel_from_cache + assert req.cached_wheel_source_link assert req.download_info assert req.download_info.url == url assert isinstance(req.download_info.info, ArchiveInfo) @@ -438,6 +439,7 @@ def test_download_info_archive_cache_with_origin( assert len(reqset.all_requirements) == 1 req = reqset.all_requirements[0] assert req.is_wheel_from_cache + assert req.cached_wheel_source_link assert req.download_info assert req.download_info.url == url assert isinstance(req.download_info.info, ArchiveInfo)