Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tolerate local version in specifiers #2102

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2102.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tolerate and actually ignore the local versions in version specifiers.
2 changes: 1 addition & 1 deletion src/pdm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def init_parser(self) -> None:
ignore_python_option.add_to_parser(self.parser)
pep582_option.add_to_parser(self.parser)

self.subparsers = self.parser.add_subparsers(parser_class=ArgumentParser, metavar="__root__")
self.subparsers = self.parser.add_subparsers(parser_class=ArgumentParser, dest="fooo")
for _, name, _ in pkgutil.iter_modules(COMMANDS_MODULE_PATH):
module = importlib.import_module(f"pdm.cli.commands.{name}", __name__)
try:
Expand Down
18 changes: 12 additions & 6 deletions src/pdm/models/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@ def fix_legacy_specifier(specifier: str) -> str:
"""Since packaging 22.0, legacy specifiers like '>=4.*' are no longer
supported. We try to normalize them to the new format.
"""
from pdm.utils import deprecation_warning

def fix_wildcard(match: Match[str]) -> str:
operator, _, version = match.groups()
if ".*" not in version or operator in ("==", "!="):
if operator in ("==", "!="):
return match.group(0)
version = version.replace(".*", ".0")
if operator in ("<", "<="): # <4.* and <=4.* are equivalent to <4.0
operator = "<"
elif operator in (">", ">="): # >4.* and >=4.* are equivalent to >=4.0
operator = ">="
if ".*" in version:
deprecation_warning(".* suffix can only be used with `==` or `!=` operators", stacklevel=4)
version = version.replace(".*", ".0")
if operator in ("<", "<="): # <4.* and <=4.* are equivalent to <4.0
operator = "<"
elif operator in (">", ">="): # >4.* and >=4.* are equivalent to >=4.0
operator = ">="
elif "+" in version: # Drop the local version
deprecation_warning("Local version label can only be used with `==` or `!=` operators", stacklevel=4)
version = version.split("+")[0]
return f"{operator}{version}"

return _legacy_specifier_re.sub(fix_wildcard, specifier)
Expand Down
1 change: 1 addition & 0 deletions tests/models/test_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def test_legacy_pep345_tag_link(project):
assert candidate.requires_python == ">=3,<4"


@pytest.mark.filterwarnings("ignore::FutureWarning")
def test_ignore_invalid_py_version(project):
project.project_config["pypi.url"] = "https://my.pypi.org/simple"
req = parse_requirement("wheel")
Expand Down
6 changes: 6 additions & 0 deletions tests/models/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@
"foo<5.0,>=4.0",
marks=pytest.mark.skipif(not PACKAGING_22, reason="packaging 22+ required"),
),
pytest.param(
"foo>=3.0+g1234; python_version>='3.6'",
'foo>=3.0; python_version >= "3.6"',
marks=pytest.mark.skipif(not PACKAGING_22, reason="packaging 22+ required"),
),
]


@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.parametrize("req, result", REQUIREMENTS)
def test_convert_req_dict_to_req_line(req, result):
r = parse_requirement(req)
Expand Down
4 changes: 4 additions & 0 deletions tests/models/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pdm.models.specifiers import PySpecSet


@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.parametrize(
"original,normalized",
[
Expand All @@ -23,6 +24,8 @@
(">3.4.*", ">=3.4"),
("<=3.4.*", "<3.4"),
("<3.4.*", "<3.4"),
(">=3.0+g1234", ">=3.0"),
("<3.0+g1234", "<3.0"),
("<3.10.0a6", "<3.10.0a6"),
("<3.10.2a3", "<3.10.2a3"),
],
Expand Down Expand Up @@ -79,6 +82,7 @@ def test_impossible_pyspec():
assert str(spec_copy) == "impossible"


@pytest.mark.filterwarnings("ignore::FutureWarning")
@pytest.mark.parametrize(
"left,right",
[
Expand Down