Skip to content

Commit

Permalink
Merge pull request #9575 from hexagonrecursion/test-sort-order
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Apr 2, 2021
2 parents b601497 + e96791f commit d08f968
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/9565.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make wheel compatibility tag preferences more important than the build tag
4 changes: 2 additions & 2 deletions src/pip/_internal/index/package_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

BuildTag = Union[Tuple[()], Tuple[int, str]]
CandidateSortingKey = (
Tuple[int, int, int, _BaseVersion, BuildTag, Optional[int]]
Tuple[int, int, int, _BaseVersion, Optional[int], BuildTag]
)


Expand Down Expand Up @@ -530,7 +530,7 @@ def _sort_key(self, candidate):
yank_value = -1 * int(link.is_yanked) # -1 for yanked.
return (
has_allowed_hash, yank_value, binary_preference, candidate.version,
build_tag, pri,
pri, build_tag,
)

def sort_best_candidate(
Expand Down
47 changes: 45 additions & 2 deletions tests/unit/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def test_existing_over_wheel_priority(self, data):
with pytest.raises(BestVersionAlreadyInstalled):
finder.find_requirement(req, True)


class TestCandidateEvaluator:
def test_link_sorting(self):
"""
Test link sorting
Expand Down Expand Up @@ -249,7 +251,8 @@ def test_link_sorting(self):
results = sorted(links, key=sort_key, reverse=True)
results2 = sorted(reversed(links), key=sort_key, reverse=True)

assert links == results == results2, results2
assert links == results, results
assert links == results2, results2

def test_link_sorting_wheels_with_build_tags(self):
"""Verify build tags affect sorting."""
Expand All @@ -274,7 +277,47 @@ def test_link_sorting_wheels_with_build_tags(self):
sort_key = candidate_evaluator._sort_key
results = sorted(links, key=sort_key, reverse=True)
results2 = sorted(reversed(links), key=sort_key, reverse=True)
assert links == results == results2, results2

assert links == results, results
assert links == results2, results2

def test_build_tag_is_less_important_than_other_tags(self):
links = [
InstallationCandidate(
"simple",
"1.0",
Link('simple-1.0-1-py3-abi3-linux_x86_64.whl'),
),
InstallationCandidate(
"simple",
'1.0',
Link('simple-1.0-2-py3-abi3-linux_i386.whl'),
),
InstallationCandidate(
"simple",
'1.0',
Link('simple-1.0-2-py3-any-none.whl'),
),
InstallationCandidate(
"simple",
'1.0',
Link('simple-1.0.tar.gz'),
),
]
valid_tags = [
Tag('py3', 'abi3', 'linux_x86_64'),
Tag('py3', 'abi3', 'linux_i386'),
Tag('py3', 'any', 'none'),
]
evaluator = CandidateEvaluator(
'my-project', supported_tags=valid_tags, specifier=SpecifierSet(),
)
sort_key = evaluator._sort_key
results = sorted(links, key=sort_key, reverse=True)
results2 = sorted(reversed(links), key=sort_key, reverse=True)

assert links == results, results
assert links == results2, results2


def test_finder_priority_file_over_page(data):
Expand Down

0 comments on commit d08f968

Please sign in to comment.