Skip to content

Commit

Permalink
Merge pull request #38 from ekmartin/compatible_release
Browse files Browse the repository at this point in the history
Add support for compatible release ranges
  • Loading branch information
rbarrois committed Feb 28, 2016
2 parents d10ab4c + 48dbcc9 commit ec2c25c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The project has received contributions from (in alphabetical order):
* 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)
* Martin Ek <mail@ekmartin.com> (https://github.com/ekmartin)


Contributor license agreement
Expand Down
9 changes: 8 additions & 1 deletion semantic_version/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,15 @@ class SpecItem(object):
KIND_NEQ = '!='
KIND_CARET = '^'
KIND_TILDE = '~'
KIND_COMPATIBLE = '~='

# Map a kind alias to its full version
KIND_ALIASES = {
KIND_SHORTEQ: KIND_EQUAL,
KIND_EMPTY: KIND_EQUAL,
}

re_spec = re.compile(r'^(<|<=||=|==|>=|>|!=|\^|~)(\d.*)$')
re_spec = re.compile(r'^(<|<=||=|==|>=|>|!=|\^|~|~=)(\d.*)$')

def __init__(self, requirement_string):
kind, spec = self.parse(requirement_string)
Expand Down Expand Up @@ -468,6 +469,12 @@ def match(self, version):
return self.spec <= version < upper
elif self.kind == self.KIND_TILDE:
return self.spec <= version < self.spec.next_minor()
elif self.kind == self.KIND_COMPATIBLE:
if self.spec.patch:
upper = self.spec.next_minor()
else:
upper = self.spec.next_major()
return self.spec <= version < upper
else: # pragma: no cover
raise ValueError('Unexpected match kind: %r' % self.kind)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,14 @@ def test_components(self):
['0.0.2', '0.0.2-alpha', '0.0.2+abb'],
['0.1.0', '0.0.3', '1.0.0'],
),
'~=1.4.5': (
['1.4.5', '1.4.10-alpha', '1.4.10'],
['1.3.6', '1.4.4', '1.5.0'],
),
'~=1.4': (
['1.4.0', '1.6.10-alpha', '1.6.10'],
['1.3.0', '2.0.0'],
),
}

def test_matches(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MatchTestCase(unittest.TestCase):
'!=0.1.2-rc1.3-14.15+build.2012-01-01.11h34',
'^0.1.2',
'~0.1.2',
'~=0.1.2',
]

matches = {
Expand Down Expand Up @@ -113,6 +114,16 @@ class MatchTestCase(unittest.TestCase):
'0.1.2+build4.5',
'0.1.3-rc1.3',
],
'~=1.4.5': (
'1.4.5',
'1.4.10-alpha',
'1.4.10',
),
'~=1.4': [
'1.4.0',
'1.6.10-alpha',
'1.6.10',
],
}

def test_invalid(self):
Expand Down

0 comments on commit ec2c25c

Please sign in to comment.