From 0c96767bd36ea082620f444ff5f3410025a9e99f Mon Sep 17 00:00:00 2001 From: Martin Ek Date: Tue, 23 Feb 2016 23:24:32 +0100 Subject: Add support for compatible release ranges, fixes #37 --- semantic_version/base.py | 9 ++++++++- tests/test_base.py | 8 ++++++++ tests/test_match.py | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/semantic_version/base.py b/semantic_version/base.py index 1504642..83a9c25 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -405,6 +405,7 @@ class SpecItem(object): KIND_NEQ = '!=' KIND_CARET = '^' KIND_TILDE = '~' + KIND_COMPATIBLE = '~=' # Map a kind alias to its full version KIND_ALIASES = { @@ -412,7 +413,7 @@ class SpecItem(object): 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) @@ -468,6 +469,12 @@ class SpecItem(object): 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) diff --git a/tests/test_base.py b/tests/test_base.py index 24bf86e..0675b24 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -514,6 +514,14 @@ class SpecItemTestCase(unittest.TestCase): ['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): diff --git a/tests/test_match.py b/tests/test_match.py index 49464f8..4d1a96f 100755 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -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 = { @@ -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): -- cgit v1.2.1 From 48dbcc96a9eb4ce6661ea40ff9358d2c432fb27e Mon Sep 17 00:00:00 2001 From: Martin Ek Date: Thu, 25 Feb 2016 22:48:08 +0100 Subject: Add Martin Ek to contributors list --- CREDITS | 1 + 1 file changed, 1 insertion(+) diff --git a/CREDITS b/CREDITS index 53fdef1..ca9a781 100644 --- a/CREDITS +++ b/CREDITS @@ -23,6 +23,7 @@ The project has received contributions from (in alphabetical order): * Michael Hrivnak (https://github.com/mhrivnak) * William Minchin (https://github.com/minchinweb) * Dave Hall (https://github.com/skwashd) +* Martin Ek (https://github.com/ekmartin) Contributor license agreement -- cgit v1.2.1