Skip to content

Commit

Permalink
Rename original_link_is_in_wheel_cache to is_wheel_from_cache
Browse files Browse the repository at this point in the history
This more accurately reflects that it is not necessarily
related to original_link, original_link being the direct URL
link,
and the wheel cache can also be populated from sdists
URL discovered by the finder.
  • Loading branch information
sbidoul committed Apr 14, 2023
1 parent ff8c8e3 commit a6ef648
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def __init__(

def _log_preparing_link(self, req: InstallRequirement) -> None:
"""Provide context for the requirement being prepared."""
if req.link.is_file and not req.original_link_is_in_wheel_cache:
if req.link.is_file and not req.is_wheel_from_cache:
message = "Processing %s"
information = str(display_path(req.link.file_path))
else:
Expand All @@ -288,7 +288,7 @@ def _log_preparing_link(self, req: InstallRequirement) -> None:
self._previous_requirement_header = (message, information)
logger.info(message, information)

if req.original_link_is_in_wheel_cache:
if req.is_wheel_from_cache:
with indent_log():
logger.info("Using cached %s", req.link.filename)

Expand Down Expand Up @@ -499,7 +499,7 @@ def prepare_linked_requirement(
# original link, not the cached link. It that case the already
# downloaded file will be removed and re-fetched from cache (which
# implies a hash check against the cache entry's origin.json).
warn_on_hash_mismatch=not req.original_link_is_in_wheel_cache,
warn_on_hash_mismatch=not req.is_wheel_from_cache,
)

if file_path is not None:
Expand Down Expand Up @@ -553,7 +553,7 @@ def _prepare_linked_requirement(

hashes = self._get_linked_req_hashes(req)

if hashes and req.original_link_is_in_wheel_cache:
if hashes and req.is_wheel_from_cache:
assert req.download_info is not None
assert link.is_wheel
assert link.is_file
Expand All @@ -576,7 +576,7 @@ def _prepare_linked_requirement(
"and re-downloading source."
)
# For some reason req.original_link is not set here, even though
# req.original_link_is_in_wheel_cache is True. So we get the original
# 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?
link = req.link
Expand Down
5 changes: 4 additions & 1 deletion src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def __init__(
# PEP 508 URL requirement
link = Link(req.url)
self.link = self.original_link = link
self.original_link_is_in_wheel_cache = False

# 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

# Information about the location of the artifact that was downloaded . This
# property is guaranteed to be set in resolver results.
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/legacy/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +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.original_link_is_in_wheel_cache = True
req.is_wheel_from_cache = True
if cache_entry.origin is not None:
req.download_info = cache_entry.origin
else:
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def __init__(

if cache_entry is not None:
if cache_entry.persistent and template.link is template.original_link:
ireq.original_link_is_in_wheel_cache = True
ireq.is_wheel_from_cache = True
if cache_entry.origin is not None:
ireq.download_info = cache_entry.origin
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def test_download_info_archive_legacy_cache(
reqset = resolver.resolve([ireq], True)
assert len(reqset.all_requirements) == 1
req = reqset.all_requirements[0]
assert req.original_link_is_in_wheel_cache
assert req.is_wheel_from_cache
assert req.download_info
assert req.download_info.url == url
assert isinstance(req.download_info.info, ArchiveInfo)
Expand All @@ -437,7 +437,7 @@ def test_download_info_archive_cache_with_origin(
reqset = resolver.resolve([ireq], True)
assert len(reqset.all_requirements) == 1
req = reqset.all_requirements[0]
assert req.original_link_is_in_wheel_cache
assert req.is_wheel_from_cache
assert req.download_info
assert req.download_info.url == url
assert isinstance(req.download_info.info, ArchiveInfo)
Expand Down

0 comments on commit a6ef648

Please sign in to comment.