Skip to content

Commit

Permalink
Fix prerelease detection for > and < (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
notatallshaw authored Sep 16, 2024
1 parent a716c52 commit cf2cbe2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def prereleases(self) -> bool:
# operators, and if they are if they are including an explicit
# prerelease.
operator, version = self._spec
if operator in ["==", ">=", "<=", "~=", "==="]:
if operator in ["==", ">=", "<=", "~=", "===", ">", "<"]:
# The == specifier can include a trailing .*, if it does we
# want to remove before parsing.
if operator == "==" and version.endswith(".*"):
Expand Down
14 changes: 12 additions & 2 deletions tests/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def test_comparison_non_specifier(self):
("2.0.post1", ">=2"),
("2.0.post1.dev1", ">=2"),
("3", ">=2"),
("3.0.0a8", ">=3.0.0a7"),
# Test the less than equal operation
("2.0", "<=2"),
("2.0", "<=2.0"),
Expand All @@ -341,16 +342,19 @@ def test_comparison_non_specifier(self):
("2.0c1.post1.dev1", "<=2"),
("2.0rc1", "<=2"),
("1", "<=2"),
("3.0.0a7", "<=3.0.0a8"),
# Test the greater than operation
("3", ">2"),
("2.1", ">2.0"),
("2.0.1", ">2"),
("2.1.post1", ">2"),
("2.1+local.version", ">2"),
("3.0.0a8", ">3.0.0a7"),
# Test the less than operation
("1", "<2"),
("2.0", "<2.1"),
("2.0.dev0", "<2.1"),
("3.0.0a7", "<3.0.0a8"),
# Test the compatibility operation
("1", "~=1.0"),
("1.0.1", "~=1.0"),
Expand Down Expand Up @@ -519,8 +523,9 @@ def test_specifiers_identity(self, version, spec, expected):
("~=1.0", False),
("<1.0", False),
(">1.0", False),
("<1.0.dev1", False),
(">1.0.dev1", False),
("<1.0.dev1", True),
(">1.0.dev1", True),
("!=1.0.dev1", False),
("==1.0.*", False),
("==1.0.dev1", True),
(">=1.0.dev1", True),
Expand Down Expand Up @@ -559,6 +564,11 @@ def test_specifiers_prereleases(self, specifier, version, expected):
(">=1.0", None, ["2.0a1"], ["2.0a1"]),
(">=1.0.dev1", None, ["1.0", "2.0a1"], ["1.0", "2.0a1"]),
(">=1.0.dev1", False, ["1.0", "2.0a1"], ["1.0"]),
("!=2.0a1", None, ["1.0a2", "1.0", "2.0a1"], ["1.0"]),
("==2.0a1", None, ["2.0a1"], ["2.0a1"]),
(">2.0a1", None, ["2.0a1", "3.0a2", "3.0"], ["3.0a2", "3.0"]),
("<2.0a1", None, ["1.0a2", "1.0", "2.0a1"], ["1.0a2", "1.0"]),
("~=2.0a1", None, ["1.0", "2.0a1", "3.0a2", "3.0"], ["2.0a1"]),
],
)
def test_specifier_filter(self, specifier, prereleases, input, expected):
Expand Down

0 comments on commit cf2cbe2

Please sign in to comment.