summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2014-03-16 20:33:43 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2014-03-16 20:33:43 +0100
commit9e88ed992c989bd0e4bfd92a1dd1cbe176407d98 (patch)
tree4db869e3d2cc38511a5463139796b4426a27e45d
parent5688677a89f6d8f0168290ca069e473c15b7617c (diff)
downloadsemantic-version-9e88ed992c989bd0e4bfd92a1dd1cbe176407d98.tar.gz
Accept '*' as a Spec (Closes #8).
Spec('*') will match all valid Version objects.
-rw-r--r--ChangeLog9
-rw-r--r--docs/reference.rst4
-rw-r--r--semantic_version/base.py18
-rwxr-xr-xtests/test_match.py12
4 files changed, 33 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 9b84739..30563a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,15 @@ ChangeLog
=========
+2.3.0 (2014-03-16)
+------------------
+
+*New:*
+
+ * Handle the full ``semver-2.0.0`` specifications (instead of the ``2.0.0-rc2`` of previous releases)
+ * `#8 <https://github.com/rbarrois/python-semanticversion/issues/8>`_: Allow ``'*'`` as a valid version spec
+
+
2.2.2 (2013-12-23)
------------------
diff --git a/docs/reference.rst b/docs/reference.rst
index 5b8ca3e..3550c25 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -270,6 +270,10 @@ This means that::
>>> Version('1.1.1-rc1+build4') in Spec('<=1.1.1-rc1+build2')
False
+
+.. note:: python-semanticversion also accepts ``"*"`` as a version spec,
+ that matches all (valid) version strings.
+
In order to force matches to *strictly* compare version numbers, these additional
rules apply:
diff --git a/semantic_version/base.py b/semantic_version/base.py
index a8e39a4..d34d03e 100644
--- a/semantic_version/base.py
+++ b/semantic_version/base.py
@@ -379,6 +379,7 @@ class Version(object):
class SpecItem(object):
"""A requirement specification."""
+ KIND_ANY = '*'
KIND_LT = '<'
KIND_LTE = '<='
KIND_EQUAL = '=='
@@ -386,15 +387,6 @@ class SpecItem(object):
KIND_GT = '>'
KIND_NEQ = '!='
- STRICT_KINDS = (
- KIND_LT,
- KIND_LTE,
- KIND_EQUAL,
- KIND_GTE,
- KIND_GT,
- KIND_NEQ,
- )
-
re_spec = re.compile(r'^(<|<=|==|>=|>|!=)(\d.*)$')
def __init__(self, requirement_string):
@@ -407,6 +399,10 @@ class SpecItem(object):
if not requirement_string:
raise ValueError("Invalid empty requirement specification: %r" % requirement_string)
+ # Special case: the 'any' version spec.
+ if requirement_string == '*':
+ return (cls.KIND_ANY, '')
+
match = cls.re_spec.match(requirement_string)
if not match:
raise ValueError("Invalid requirement specification: %r" % requirement_string)
@@ -416,7 +412,9 @@ class SpecItem(object):
return (kind, spec)
def match(self, version):
- if self.kind == self.KIND_LT:
+ if self.kind == self.KIND_ANY:
+ return True
+ elif self.kind == self.KIND_LT:
return version < self.spec
elif self.kind == self.KIND_LTE:
return version <= self.spec
diff --git a/tests/test_match.py b/tests/test_match.py
index fe75179..155a612 100755
--- a/tests/test_match.py
+++ b/tests/test_match.py
@@ -18,6 +18,7 @@ class MatchTestCase(unittest.TestCase):
]
valid_specs = [
+ '*',
'==0.1.0',
'<=0.1.1',
'<0.1',
@@ -28,6 +29,17 @@ class MatchTestCase(unittest.TestCase):
]
matches = {
+ '*': [
+ '0.1.1',
+ '0.1.1+build4.5',
+ '0.1.2-rc1',
+ '0.1.2-rc1.3',
+ '0.1.2-rc1.3.4',
+ '0.1.2+build42-12.2012-01-01.12h23',
+ '0.1.2-rc1.3-14.15+build.2012-01-01.11h34',
+ '0.2.0',
+ '1.0.0',
+ ],
'==0.1.2': [
'0.1.2-rc1',
'0.1.2-rc1.3.4',