Skip to content

Commit 51fbca7

Browse files
committed
Conform to PEP440
1 parent 5da370e commit 51fbca7

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/pip/_internal/index/package_finder.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ def evaluate_link(self, link: Link) -> tuple[LinkType, str]:
171171
candidate's version string; if one is not found, it contains the
172172
reason the link fails to qualify.
173173
"""
174+
175+
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
176+
print(link.requires_python)
177+
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
178+
174179
version = None
175180
if link.is_yanked and not self._allow_yanked:
176181
reason = link.yanked_reason or "<none given>"
@@ -248,17 +253,20 @@ def evaluate_link(self, link: Link) -> tuple[LinkType, str]:
248253
ignore_requires_python=self._ignore_requires_python,
249254
)
250255
if not supports_python:
251-
rp_specs = specifiers.SpecifierSet(link.requires_python)
252-
rp_versions = []
253-
for rp_spec in rp_specs:
254-
rp_version = rp_spec.version
255-
if rp_spec.operator in ["==", "!="] and rp_version.endswith(".*"):
256-
rp_version = rp_version[:-2]
257-
rp_versions.append(Version(rp_version))
258-
sorted_requires_python = ",".join(
259-
[str(s) for _, s in sorted(zip(rp_versions, rp_specs))]
260-
)
261-
reason = f"{version} Requires-Python {sorted_requires_python}"
256+
requires_python = link.requires_python
257+
try:
258+
rp_ver_spec_list = []
259+
for rp_spec in specifiers.SpecifierSet(requires_python):
260+
rp_version = rp_spec.version
261+
if rp_spec.operator == "==" and rp_version.endswith(".*"):
262+
rp_version = rp_version[:-2]
263+
rp_ver_spec_list.append((Version(rp_version), rp_spec))
264+
requires_python = ",".join(
265+
[str(s) for _, s in sorted(rp_ver_spec_list)]
266+
)
267+
except InvalidVersion:
268+
pass
269+
reason = f"{version} Requires-Python {requires_python}"
262270
return (LinkType.requires_python_mismatch, reason)
263271

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

src/pip/_vendor/packaging/specifiers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ def prereleases(self) -> bool:
256256
# operators, and if they are if they are including an explicit
257257
# prerelease.
258258
operator, version = self._spec
259-
if operator in ["==", "!=", ">=", "<=", "~=", "===", ">", "<"]:
260-
# The == and != specifier can include a trailing .*, if it does we
259+
if operator in ["==", ">=", "<=", "~=", "===", ">", "<"]:
260+
# The == specifier can include a trailing .*, if it does we
261261
# want to remove before parsing.
262-
if operator in ["==", "!="] and version.endswith(".*"):
262+
if operator == "==" and version.endswith(".*"):
263263
version = version[:-2]
264264

265265
# Parse the version, and if it is a pre-release than this

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,!=3.13.*",
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.13.*, == 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)