Skip to content

Commit 8abc7e9

Browse files
committed
Introduce ireq.cached_wheel_source_link
1 parent 63537d0 commit 8abc7e9

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

src/pip/_internal/operations/prepare.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,7 @@ def _prepare_linked_requirement(
575575
"don't match, ignoring cached built wheel "
576576
"and re-downloading source."
577577
)
578-
# For some reason req.original_link is not set here, even though
579-
# req.is_wheel_from_cache is True. So we get the original
580-
# link from download_info.
581-
req.link = Link(req.download_info.url) # TODO comes_from?
578+
req.link = req.cached_wheel_source_link
582579
link = req.link
583580

584581
self._ensure_link_req_src_dir(req, parallel_builds)

src/pip/_internal/req/req_install.py

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def __init__(
112112
# When is_wheel_from_cache is True, it means that this InstallRequirement
113113
# is a local wheel file in the cache of locally built wheels.
114114
self.is_wheel_from_cache = False
115+
# When is_wheel_from_cache is True, this is the source link corresponding
116+
# to the cache entry, which was used to download and build the cached wheel.
117+
self.cached_wheel_source_link: Optional[Link] = None
115118

116119
# Information about the location of the artifact that was downloaded . This
117120
# property is guaranteed to be set in resolver results.

src/pip/_internal/resolution/legacy/resolver.py

+1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ def _populate_link(self, req: InstallRequirement) -> None:
431431
if cache_entry is not None:
432432
logger.debug("Using cached wheel link: %s", cache_entry.link)
433433
if req.link is req.original_link and cache_entry.persistent:
434+
req.cached_wheel_source_link = req.link
434435
req.is_wheel_from_cache = True
435436
if cache_entry.origin is not None:
436437
req.download_info = cache_entry.origin

src/pip/_internal/resolution/resolvelib/candidates.py

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def __init__(
277277
assert ireq.link.is_wheel
278278
assert ireq.link.is_file
279279
if cache_entry.persistent and template.link is template.original_link:
280+
ireq.cached_wheel_source_link = source_link
280281
ireq.is_wheel_from_cache = True
281282
if cache_entry.origin is not None:
282283
ireq.download_info = cache_entry.origin

tests/unit/test_req.py

+2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def test_download_info_archive_legacy_cache(
412412
assert len(reqset.all_requirements) == 1
413413
req = reqset.all_requirements[0]
414414
assert req.is_wheel_from_cache
415+
assert req.cached_wheel_source_link
415416
assert req.download_info
416417
assert req.download_info.url == url
417418
assert isinstance(req.download_info.info, ArchiveInfo)
@@ -438,6 +439,7 @@ def test_download_info_archive_cache_with_origin(
438439
assert len(reqset.all_requirements) == 1
439440
req = reqset.all_requirements[0]
440441
assert req.is_wheel_from_cache
442+
assert req.cached_wheel_source_link
441443
assert req.download_info
442444
assert req.download_info.url == url
443445
assert isinstance(req.download_info.info, ArchiveInfo)

0 commit comments

Comments
 (0)