Skip to content

Commit

Permalink
feat: ignore wheels for pythons not in range (#2113)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Jul 20, 2023
1 parent 759507e commit 8d65ac6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/2113.dep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update `unearth` to 0.10.0
1 change: 1 addition & 0 deletions news/2113.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore wheels for python versions not in range.
8 changes: 4 additions & 4 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
"virtualenv>=20",
"pyproject-hooks",
"requests-toolbelt",
"unearth>=0.9.0",
"unearth>=0.10.0",
"findpython>=0.3.0,<1.0.0a0",
"tomlkit>=0.11.1,<1",
"shellingham>=1.3.2",
Expand Down
36 changes: 36 additions & 0 deletions src/pdm/models/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,40 @@ def _get_dependency_from_local_package(self, candidate: Candidate) -> CandidateI
project.pyproject.metadata.get("description", "UNKNOWN"),
)

def _is_python_match(self, link: Link) -> bool:
from packaging.tags import Tag
from packaging.utils import parse_wheel_filename

def is_tag_match(tag: Tag, python_requires: PySpecSet) -> bool:
if tag.interpreter.startswith(("cp", "py")):
major, minor = tag.interpreter[2], tag.interpreter[3:]
if not minor:
version = f"{major}.0"
else:
version = f"{major}.{minor}.0"
if tag.abi == "abi3":
spec = PySpecSet(f">={version}") # cp37-abi3 is compatible with >=3.7
else:
spec = PySpecSet(f"~={version}") # cp37-cp37 is only compatible with 3.7.*
return not (spec & python_requires).is_impossible
else:
# we don't know about compatility for non-cpython implementations
# assume it is compatible
return True

if not link.is_wheel:
return True
python_requires = self.environment.python_requires
tags = parse_wheel_filename(link.filename)[-1]
result = any(is_tag_match(tag, python_requires) for tag in tags)
if not result:
termui.logger.debug(
"Skipping %r because it is not compatible with %r",
link,
python_requires,
)
return result

def get_hashes(self, candidate: Candidate) -> list[FileHash]:
"""Get hashes of all possible installable candidates
of a given package version.
Expand Down Expand Up @@ -272,6 +306,8 @@ def get_hashes(self, candidate: Candidate) -> list[FileHash]:
links: list[Link] = [this_link]
else: # the req must be a named requirement
links = [package.link for package in finder.find_matches(req.as_line())]
if self.ignore_compatibility:
links = [link for link in links if self._is_python_match(link)]
for link in links:
if not link or link.is_vcs or link.is_file and link.file_path.is_dir():
# The links found can still be a local directory or vcs, skippping it.
Expand Down

0 comments on commit 8d65ac6

Please sign in to comment.