Skip to content

Commit

Permalink
fix: fix the incorrect priority for binary wheels
Browse files Browse the repository at this point in the history
Fix #1698
  • Loading branch information
frostming committed Feb 10, 2023
1 parent 3238865 commit 8643ab6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/1698.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that built wheels are prioritized over source distributions with higher version number.
4 changes: 2 additions & 2 deletions src/pdm/models/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def attempt_to_find() -> Link | None:
found = attempt_to_find()
if ignore_compatibility and (found is None or not found.is_wheel):
# try to find a wheel for easy metadata extraction
finder.ignore_compatibility = finder.prefer_binary = True
finder.ignore_compatibility = True
new_found = attempt_to_find()
if new_found is not None:
found = new_found
finder.ignore_compatibility = finder.prefer_binary = False
finder.ignore_compatibility = False
return found


Expand Down
11 changes: 9 additions & 2 deletions src/pdm/models/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def _replace_shebang(contents: bytes, new_executable: bytes) -> bytes:
return contents.replace(match.group(1), new_executable, 1)


class PackageFinder(unearth.PackageFinder):
def _sort_key(self, package: unearth.Package) -> tuple:
key = super()._sort_key(package)
*front, last = key
# prefer wheel if all others are equal
return (*front, package.link.is_wheel, last)


class Environment:
"""Environment dependent stuff related to the selected Python interpreter."""

Expand Down Expand Up @@ -166,13 +174,12 @@ def get_finder(
index_urls, find_links, trusted_hosts = get_index_urls(sources)

session = self._build_session(index_urls, trusted_hosts)
finder = unearth.PackageFinder(
finder = PackageFinder(
session=session,
index_urls=index_urls,
find_links=find_links,
target_python=self.target_python,
ignore_compatibility=ignore_compatibility,
prefer_binary=ignore_compatibility,
no_binary=os.getenv("PDM_NO_BINARY", "").split(","),
only_binary=os.getenv("PDM_ONLY_BINARY", "").split(","),
respect_source_order=self.project.pyproject.settings.get(
Expand Down

0 comments on commit 8643ab6

Please sign in to comment.