Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/pip/_internal/index/package_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from pip._internal.utils.misc import build_netloc
from pip._internal.utils.packaging import check_requires_python
from pip._internal.utils.unpacking import SUPPORTED_EXTENSIONS
from pip._internal.utils.urls import path_to_url
from pip._internal.utils.variant import (
VariantJson,
get_cached_variant_hashes_by_priority,
Expand Down Expand Up @@ -930,6 +931,14 @@ def find_all_candidates(self, project_name: str) -> List[InstallationCandidate]:
)
page_candidates = list(page_candidates_it)

# Since candidates_from_page does not get used to process file sources
# from find-links, manually inject evaluate_links calls here.
_links = [
Link(path_to_url(fl.variants_json))
for fl in collected_sources.find_links
if fl.variants_json is not None
]
self.evaluate_links(link_evaluator, _links)
Comment on lines +934 to +941
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a very clean way of doing things, but I figured better than nothing given that we're still prototyping. I'd be happy with a more structured solution at some point but I don't think it's urgent.

file_links_it = itertools.chain.from_iterable(
source.file_links()
for sources in collected_sources
Expand Down
7 changes: 7 additions & 0 deletions src/pip/_internal/index/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, path: str) -> None:
self._path = path
self._page_candidates: List[str] = []
self._project_name_to_urls: Dict[str, List[str]] = defaultdict(list)
self.variants_json = None
self._scanned_directory = False

def _scan_directory(self) -> None:
Expand All @@ -71,6 +72,8 @@ def _scan_directory(self) -> None:
try:
project_filename = parse_sdist_filename(entry.name)[0]
except InvalidSdistFilename:
if entry.name.endswith("-variants.json"):
self.variants_json = entry.path
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this class have to account for multiple versions? If yes, then you'd probably need a dict from package names+versions to paths, similarly to how we do it in the regular codepath.

continue

self._project_name_to_urls[project_filename].append(url)
Expand Down Expand Up @@ -130,6 +133,10 @@ def file_links(self) -> FoundLinks:
for url in self._path_to_urls.project_name_to_urls[self._project_name]:
yield Link(url)

@property
def variants_json(self):
return self._path_to_urls.variants_json


class _LocalFileSource(LinkSource):
"""``--find-links=<path-or-url>`` or ``--[extra-]index-url=<path-or-url>``.
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __hash__(self) -> int:
def get_variants_json_filename(wheel: Wheel) -> str:
# these are normalized, but with .replace("_", "-")
return (
f"{wheel.name.replace("-", "_")}-{wheel.version.replace("-", "_")}-"
f"{wheel.name.replace('-', '_')}-{wheel.version.replace('-', '_')}-"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for pre-PEP 701 compatibility.

"variants.json"
)

Expand Down
20 changes: 14 additions & 6 deletions src/pip/_vendor/packaging/utils.py
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably we would need this upstreamed to packaging itself as well (although we'll need the change in both places since pip will continue vendoring it anyway).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, kinda. I didn't change that API since we didn't need it at the time, and — well, it can't return the variant label, so it won't be correct for variant wheels anyway.

That said, don't worry about upstreaming much — our pip fork is based on old version, and pip's changed too much in main to justify rebasing the demo.

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def parse_wheel_filename(

filename = filename[:-4]
dashes = filename.count("-")
if dashes not in (4, 5):
if dashes not in (4, 5, 6):
raise InvalidWheelFilename(
f"Invalid wheel filename (wrong number of parts): {filename!r}"
)
Expand All @@ -120,14 +120,22 @@ def parse_wheel_filename(
f"Invalid wheel filename (invalid version): {filename!r}"
) from e

if dashes == 5:
if dashes in (5, 6):
build_part = parts[2]
build_match = _build_tag_regex.match(build_part)
if build_match is None:
raise InvalidWheelFilename(
f"Invalid build number: {build_part} in {filename!r}"
)
build = cast(BuildTag, (int(build_match.group(1)), build_match.group(2)))
# When there are 5 dashes, not matching the build number could be OK because
# we could have a variant tag.
variant_hash_pattern = r'[a-zA-Z0-9]{8}'
possible_variant_hash = parts[-1].split("-")[-1]
if dashes == 6 or (dashes == 5 and not re.match(variant_hash_pattern, possible_variant_hash)):
raise InvalidWheelFilename(
f"Invalid build number: {build_part} in {filename!r}"
)
else:
build = ()
else:
build = cast(BuildTag, (int(build_match.group(1)), build_match.group(2)))
else:
build = ()
tags = parse_tag(parts[-1])
Expand Down
Loading