Skip to content

Support older Python and find-links #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: pep-xxx-wheel-variants-dev
Choose a base branch
from
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)
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
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('-', '_')}-"
"variants.json"
)

Expand Down
20 changes: 14 additions & 6 deletions src/pip/_vendor/packaging/utils.py
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