Accept '*' as a Spec (Closes #8).
Spec('*') will match all valid Version objects.
This commit is contained in:
@@ -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)
|
||||
------------------
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user