summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStéphane Bidoul <stephane.bidoul@gmail.com>2023-04-10 14:46:12 +0200
committerStéphane Bidoul <stephane.bidoul@gmail.com>2023-04-14 08:03:49 +0200
commitbd746e3136e5e1be2374a079bac66071dd967a8c (patch)
tree899f6b1ca027daae876c3379f98985a26546559c
parentcaafe6e87d4f2998a77b194297e1c204cf6e10c2 (diff)
downloadpip-bd746e3136e5e1be2374a079bac66071dd967a8c.tar.gz
Introduce ireq.cached_wheel_source_link
-rw-r--r--src/pip/_internal/operations/prepare.py5
-rw-r--r--src/pip/_internal/req/req_install.py3
-rw-r--r--src/pip/_internal/resolution/legacy/resolver.py1
-rw-r--r--src/pip/_internal/resolution/resolvelib/candidates.py1
-rw-r--r--tests/unit/test_req.py2
5 files changed, 8 insertions, 4 deletions
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
index 10ed17c19..227331523 100644
--- a/src/pip/_internal/operations/prepare.py
+++ b/src/pip/_internal/operations/prepare.py
@@ -575,10 +575,7 @@ class RequirementPreparer:
"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 a8f94d4e0..50d89b1be 100644
--- a/src/pip/_internal/req/req_install.py
+++ b/src/pip/_internal/req/req_install.py
@@ -112,6 +112,9 @@ class InstallRequirement:
# 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 86d135fca..216b0b81c 100644
--- a/src/pip/_internal/resolution/legacy/resolver.py
+++ b/src/pip/_internal/resolution/legacy/resolver.py
@@ -431,6 +431,7 @@ class Resolver(BaseResolver):
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 7c2aae3b8..2c315b460 100644
--- a/src/pip/_internal/resolution/resolvelib/candidates.py
+++ b/src/pip/_internal/resolution/resolvelib/candidates.py
@@ -280,6 +280,7 @@ class LinkCandidate(_InstallRequirementBackedCandidate):
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 eb486ba0f..c9742812b 100644
--- a/tests/unit/test_req.py
+++ b/tests/unit/test_req.py
@@ -412,6 +412,7 @@ class TestRequirementSet:
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 @@ class TestRequirementSet:
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)