Skip to content

Commit

Permalink
Forbid prefix version matching on pre-release/post-release segments
Browse files Browse the repository at this point in the history
It does not make much sense to have this.
Let's forbid it.
  • Loading branch information
mayeut committed Aug 6, 2022
1 parent 213cb95 commit 80bce7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
22 changes: 11 additions & 11 deletions packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ class Specifier(BaseSpecifier):
v?
(?:[0-9]+!)? # epoch
[0-9]+(?:\.[0-9]+)* # release
(?: # pre release
[-_\.]?
(a|b|c|rc|alpha|beta|pre|preview)
[-_\.]?
[0-9]*
)?
(?: # post release
(?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
)?
# You cannot use a wild card and a dev or local version
# together so group them with a | and make them optional.
# You cannot use a wild card and a pre-release, post-release, a dev or
# local version together so group them with a | and make them optional.
(?:
\.\* # Wild card syntax of .*
|
(?: # pre release
[-_\.]?
(a|b|c|rc|alpha|beta|pre|preview)
[-_\.]?
[0-9]*
)?
(?: # post release
(?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
)?
(?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
(?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local
)?
Expand Down
14 changes: 8 additions & 6 deletions tests/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def test_specifiers_valid(self, specifier):
# support one or the other
"==1.0.*+5",
"!=1.0.*+deadbeef",
# Prefix matching cannot be used inside of a local version
# Prefix matching cannot be used with a pre-release, post-release,
# dev or local version
"==2.0a1.*",
"!=2.0a1.*",
"==2.0.post1.*",
"!=2.0.post1.*",
"==2.0.dev1.*",
"!=2.0.dev1.*",
"==1.0+5.*",
"!=1.0+deadbeef.*",
# Prefix matching must appear at the end
Expand Down Expand Up @@ -304,8 +311,6 @@ def test_comparison_non_specifier(self):
("2", "==2.*"),
("2.0", "==2.*"),
("2.0.0", "==2.*"),
("2.0.post1", "==2.0.post1.*"),
("2.0.post1.dev1", "==2.0.post1.*"),
("2.1+local.version", "==2.1.*"),
# Test the in-equality operation
("2.1", "!=2"),
Expand Down Expand Up @@ -401,8 +406,6 @@ def test_comparison_non_specifier(self):
("2", "!=2.*"),
("2.0", "!=2.*"),
("2.0.0", "!=2.*"),
("2.0.post1", "!=2.0.post1.*"),
("2.0.post1.dev1", "!=2.0.post1.*"),
# Test the greater than equal operation
("2.0.dev1", ">=2"),
("2.0a1", ">=2"),
Expand Down Expand Up @@ -526,7 +529,6 @@ def test_specifier_prereleases_detection(self, specifier, expected):
(">=1.0", "2.0.dev1", False),
(">=2.0.dev1", "2.0a1", True),
("==2.0.*", "2.0a1.dev1", False),
("==2.0a1.*", "2.0a1.dev1", True),
("<=2.0", "1.0.dev1", False),
("<=2.0.dev1", "1.0a1", True),
],
Expand Down

0 comments on commit 80bce7a

Please sign in to comment.