From bd746e3136e5e1be2374a079bac66071dd967a8c 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 10ed17c1924..2273315234d 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 a8f94d4e096..50d89b1be37 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 86d135fca1b..216b0b81c27 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 7c2aae3b8b4..2c315b4600c 100644 --- a/src/pip/_internal/resolution/resolvelib/candidates.py +++ b/src/pip/_internal/resolution/resolvelib/candidates.py @@ -280,6 +280,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)