Merge branch 'tilde-caret' of https://github.com/skwashd/python-semanticversion into skwashd-tilde-caret
This commit is contained in:
commit
15277fdb8e
1
CREDITS
1
CREDITS
|
@ -22,6 +22,7 @@ The project has received contributions from (in alphabetical order):
|
|||
* Hugo Rodger-Brown <hugo@yunojuno.com> (https://github.com/yunojuno)
|
||||
* Michael Hrivnak <mhrivnak@hrivnak.org> (https://github.com/mhrivnak)
|
||||
* William Minchin <w_minchin@hotmail.com> (https://github.com/minchinweb)
|
||||
* Dave Hall <skwadhd@gmail.com> (https://github.com/skwashd)
|
||||
|
||||
|
||||
Contributor license agreement
|
||||
|
|
|
@ -398,11 +398,15 @@ class SpecItem(object):
|
|||
KIND_LT = '<'
|
||||
KIND_LTE = '<='
|
||||
KIND_EQUAL = '=='
|
||||
KIND_SHORTEQ = '='
|
||||
KIND_EMPTY = ''
|
||||
KIND_GTE = '>='
|
||||
KIND_GT = '>'
|
||||
KIND_NEQ = '!='
|
||||
KIND_CARET = '^'
|
||||
KIND_TILDE = '~'
|
||||
|
||||
re_spec = re.compile(r'^(<|<=|==|>=|>|!=)(\d.*)$')
|
||||
re_spec = re.compile(r'^(<|<=|={,2}|>=|>|!=|\^|~)(\d.*)$')
|
||||
|
||||
def __init__(self, requirement_string):
|
||||
kind, spec = self.parse(requirement_string)
|
||||
|
@ -437,7 +441,7 @@ class SpecItem(object):
|
|||
return version < self.spec
|
||||
elif self.kind == self.KIND_LTE:
|
||||
return version <= self.spec
|
||||
elif self.kind == self.KIND_EQUAL:
|
||||
elif self.kind in [self.KIND_EQUAL, self.KIND_SHORTEQ, self.KIND_EMPTY]:
|
||||
return version == self.spec
|
||||
elif self.kind == self.KIND_GTE:
|
||||
return version >= self.spec
|
||||
|
@ -445,9 +449,21 @@ class SpecItem(object):
|
|||
return version > self.spec
|
||||
elif self.kind == self.KIND_NEQ:
|
||||
return version != self.spec
|
||||
elif self.kind == self.KIND_CARET:
|
||||
return self.caretCompare(version)
|
||||
elif self.kind == self.KIND_TILDE:
|
||||
return self.tildeCompare(version)
|
||||
else: # pragma: no cover
|
||||
raise ValueError('Unexpected match kind: %r' % self.kind)
|
||||
|
||||
def caretCompare(self, version):
|
||||
max_version = version.next_major()
|
||||
return version >= self.spec and version < max_version
|
||||
|
||||
def tildeCompare(self, version):
|
||||
max_version = version.next_minor()
|
||||
return version >= self.spec and version < max_version
|
||||
|
||||
def __str__(self):
|
||||
return '%s%s' % (self.kind, self.spec)
|
||||
|
||||
|
|
|
@ -14,19 +14,23 @@ class MatchTestCase(unittest.TestCase):
|
|||
'!0.1',
|
||||
'<=0.1.4a',
|
||||
'>0.1.1.1',
|
||||
'~0.1.2-rc23,1',
|
||||
'<0.1.2-rc1.3-14.15+build.2012-01-01.11h34',
|
||||
]
|
||||
|
||||
valid_specs = [
|
||||
'*',
|
||||
'==0.1.0',
|
||||
'=0.1.0',
|
||||
'0.1.0',
|
||||
'<=0.1.1',
|
||||
'<0.1',
|
||||
'1',
|
||||
'>0.1.2-rc1',
|
||||
'>=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.1.2',
|
||||
'~0.1.2',
|
||||
]
|
||||
|
||||
matches = {
|
||||
|
@ -47,6 +51,18 @@ class MatchTestCase(unittest.TestCase):
|
|||
'0.1.2+build42-12.2012-01-01.12h23',
|
||||
'0.1.2-rc1.3-14.15+build.2012-01-01.11h34',
|
||||
],
|
||||
'=0.1.2': [
|
||||
'0.1.2-rc1',
|
||||
'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.1.2': [
|
||||
'0.1.2-rc1',
|
||||
'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.1.2': [
|
||||
'0.1.1',
|
||||
'0.1.2-rc1',
|
||||
|
@ -86,6 +102,17 @@ class MatchTestCase(unittest.TestCase):
|
|||
'0.1.1-rc4',
|
||||
'0.1.0+12.3',
|
||||
],
|
||||
'^0.1.2': [
|
||||
'0.1.2',
|
||||
'0.1.2+build4.5',
|
||||
'0.1.3-rc1.3',
|
||||
'0.2.0',
|
||||
],
|
||||
'~0.1.2': [
|
||||
'0.1.2',
|
||||
'0.1.2+build4.5',
|
||||
'0.1.3-rc1.3',
|
||||
],
|
||||
}
|
||||
|
||||
def test_invalid(self):
|
||||
|
|
Loading…
Reference in New Issue