summaryrefslogtreecommitdiff
path: root/semantic_version
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 /semantic_version
parent5688677a89f6d8f0168290ca069e473c15b7617c (diff)
downloadsemantic-version-9e88ed992c989bd0e4bfd92a1dd1cbe176407d98.tar.gz
Accept '*' as a Spec (Closes #8).
Spec('*') will match all valid Version objects.
Diffstat (limited to 'semantic_version')
-rw-r--r--semantic_version/base.py18
1 files changed, 8 insertions, 10 deletions
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