Skip to content

Commit

Permalink
Introduce ireq.cached_wheel_source_link
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Apr 10, 2023
1 parent 63537d0 commit 8abc7e9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/resolution/legacy/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8abc7e9

Please sign in to comment.