Skip to content

Commit 422cb0b

Browse files
authored
Merge pull request #13394 from qraqras/dev_issue_13367
2 parents b6e7748 + 8f8e159 commit 422cb0b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

news/13367.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Requires-Python error message now sorts versions numerically.

src/pip/_internal/index/package_finder.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,19 @@ def evaluate_link(self, link: Link) -> tuple[LinkType, str]:
248248
ignore_requires_python=self._ignore_requires_python,
249249
)
250250
if not supports_python:
251-
reason = f"{version} Requires-Python {link.requires_python}"
251+
requires_python = link.requires_python
252+
if requires_python:
253+
254+
def get_version_sort_key(v: str) -> tuple[int, ...]:
255+
return tuple(int(s) for s in v.split(".") if s.isdigit())
256+
257+
requires_python = ",".join(
258+
sorted(
259+
(str(s) for s in specifiers.SpecifierSet(requires_python)),
260+
key=get_version_sort_key,
261+
)
262+
)
263+
reason = f"{version} Requires-Python {requires_python}"
252264
return (LinkType.requires_python_mismatch, reason)
253265

254266
logger.debug("Found link %s, version: %s", link, version)

tests/unit/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class TestLinkEvaluator:
133133
False,
134134
(
135135
LinkType.requires_python_mismatch,
136-
"1.12 Requires-Python == 3.6.5",
136+
"1.12 Requires-Python ==3.6.5,!=3.13.3",
137137
),
138138
id="requires-python-mismatch",
139139
),
@@ -162,7 +162,7 @@ def test_evaluate_link(
162162
)
163163
link = Link(
164164
"https://example.com/#egg=twine-1.12",
165-
requires_python="== 3.6.5",
165+
requires_python="!= 3.13.3, == 3.6.5",
166166
)
167167
actual = evaluator.evaluate_link(link)
168168
assert actual == expected

0 commit comments

Comments
 (0)