diff --git a/packaging/specifiers.py b/packaging/specifiers.py index 5afafe3f..d2ba13d1 100644 --- a/packaging/specifiers.py +++ b/packaging/specifiers.py @@ -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 )? diff --git a/tests/test_specifiers.py b/tests/test_specifiers.py index 92d04eb0..043dd065 100644 --- a/tests/test_specifiers.py +++ b/tests/test_specifiers.py @@ -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 @@ -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"), @@ -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"), @@ -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), ],