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 Jun 19, 2022
1 parent c533201 commit 2dc52eb
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
Expand Up @@ -328,19 +328,19 @@ class Specifier(_IndividualSpecifier):
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, dev or
# local version together so group them with a | and make them optional.
(?:
(?: # 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
Expand Up @@ -71,7 +71,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 @@ -311,8 +318,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 @@ -408,8 +413,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 @@ -535,7 +538,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 2dc52eb

Please sign in to comment.