From 5ca781f439e8d402ada7f51c31d21ba211f673b6 Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Thu, 15 Oct 2015 11:41:19 +1100 Subject: Add support for npm/composer caret and tilde condition extensions --- semantic_version/base.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'semantic_version/base.py') diff --git a/semantic_version/base.py b/semantic_version/base.py index 982fcc8..e001005 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -392,8 +392,11 @@ class SpecItem(object): KIND_GTE = '>=' KIND_GT = '>' KIND_NEQ = '!=' + KIND_CARET = '^' + KIND_TILDE = '~' - re_spec = re.compile(r'^(<|<=|==|>=|>|!=)(\d.*)$') + caret = re.escape('^') + re_spec = re.compile(r'^(<|<=|==|>=|>|!=|{}|~)(\d.*)$'.format(caret)) def __init__(self, requirement_string): kind, spec = self.parse(requirement_string) @@ -436,9 +439,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) -- cgit v1.2.1 From 6004bfd349a0707309be52fc4d418fc579dc91d4 Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Mon, 19 Oct 2015 20:14:27 +1100 Subject: Make regex more readable --- semantic_version/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'semantic_version/base.py') diff --git a/semantic_version/base.py b/semantic_version/base.py index e001005..deebbc9 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -395,8 +395,7 @@ class SpecItem(object): KIND_CARET = '^' KIND_TILDE = '~' - caret = re.escape('^') - re_spec = re.compile(r'^(<|<=|==|>=|>|!=|{}|~)(\d.*)$'.format(caret)) + re_spec = re.compile(r'^(<|<=|==|>=|>|!=|\^|~)(\d.*)$') def __init__(self, requirement_string): kind, spec = self.parse(requirement_string) -- cgit v1.2.1 From a8a75320eb274ed27227b70a3d4d090c4674237d Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Mon, 19 Oct 2015 16:54:16 +1100 Subject: Support for alternative equals specs Composer assumes equals if no operator is used npm uses a single equals operator --- semantic_version/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'semantic_version/base.py') diff --git a/semantic_version/base.py b/semantic_version/base.py index deebbc9..d0f5db8 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -389,13 +389,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) @@ -430,7 +432,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 -- cgit v1.2.1