未验证 提交 46098800 编写于 作者: F Frost Ming

Fix the version parsing and validation

上级 63f6cab5
Fix the version validator of wheel metadata to align with the implementation of `packaging`.
Fix the version parsing of Python requires to allow `>`, `>=`, `<`, `<=` to combine with star versions.
......@@ -33,12 +33,17 @@ def _patch_version_parsing():
list.
"""
from distlib.version import VersionScheme
from packaging.requirements import InvalidRequirement
from packaging.requirements import Requirement as PRequirement
def is_valid_constraint_list(self, s):
s = ",".join(v for v in s.strip().split(",") if v)
return self.is_valid_matcher("dummy_name (%s)" % s)
def is_valid_matcher(self, s):
try:
PRequirement(s)
except InvalidRequirement:
return False
return True
VersionScheme.is_valid_constraint_list = is_valid_constraint_list
VersionScheme.is_valid_matcher = is_valid_matcher
_patch_version_parsing()
......
......@@ -103,6 +103,21 @@ class PySpecSet(SpecifierSet):
elif op == "!=":
excludes.add(version)
continue
elif op == ">": # >X.Y.* => >=X.Y+1.0
op = ">="
version = bump_version(version, -2)
elif op in ("<", ">=", "<="):
# <X.Y.* => <X.Y.0
# >=X.Y.* => >=X.Y.0
# <=X.Y.* => <X.Y.0
version = version[:-1] + (0,)
if op == "<=":
op = "<"
else:
raise InvalidPyVersion(
f"Unsupported version specifier: {spec.op}{spec.version}"
)
if op != "~=":
version = _complete_version(version)
if op in ("==", "==="):
......
......@@ -19,6 +19,10 @@ from pdm.models.specifiers import PySpecSet
(">=3.6,<3.8,!=3.8.*", ">=3.6,<3.8"),
(">=2.7,<3.2,!=3.0.*,!=3.1.*", ">=2.7,<3.0"),
("!=3.0.*,!=3.0.2", "!=3.0.*"),
(">=3.4.*", ">=3.4"),
(">3.4.*", ">=3.5"),
("<=3.4.*", "<3.4"),
("<3.4.*", "<3.4"),
],
)
def test_normalize_pyspec(original, normalized):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册