summaryrefslogtreecommitdiff
path: root/semantic_version/compat.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2015-09-15 23:18:13 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2015-09-15 23:40:59 +0200
commit2ed3d39c291080c61edd9139370939e1fdc3209a (patch)
tree22a90dfae0e0fc9fd7949ca18e7e47daa8f8aabb /semantic_version/compat.py
parent4aac5768db2fc158fa87900b54210ecba4dfe6d5 (diff)
downloadsemantic-version-2ed3d39c291080c61edd9139370939e1fdc3209a.tar.gz
Forbid build metadata ordering (See #18)
SemVer 2.0.0 states that "Build metadata SHOULD be ignored when determining version precedence". This means that, when comparing ``0.1.0+1`` to ``0.1.0+bcd``:: >>> Version('0.1.0+1') == Version('0.1.0+bcd') False >>> Version('0.1.0+1') != Version('0.1.0+bcd') True >>> Version('0.1.0+1') < Version('0.1.0+bcd') False >>> Version('0.1.0+1') > Version('0.1.0+bcd') False >>> Version('0.1.0+1') <= Version('0.1.0+bcd') False >>> Version('0.1.0+1') >= Version('0.1.0+bcd') False >>> compare(Version('0.1.0+1'), Version('0.1.0+bcd')) NotImplemented This change also has the following effects: - When including build metadata in a ``Spec``, the only valid options are ``Spec('==0.1.0+sth')`` and ``Spec('!=0.1.0+sth')`` - The meaning of ``Spec('==0.1.0+')`` is now "Only version 0.1.0 without build metadata" - ``Spec('==0.1.0')`` now matches ``Version('0.1.0+anything')``
Diffstat (limited to 'semantic_version/compat.py')
-rw-r--r--semantic_version/compat.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/semantic_version/compat.py b/semantic_version/compat.py
index bea6f67..4dd60fe 100644
--- a/semantic_version/compat.py
+++ b/semantic_version/compat.py
@@ -2,17 +2,14 @@
# Copyright (c) 2012-2014 The python-semanticversion project
# This code is distributed under the two-clause BSD License.
-import sys
-is_python2 = (sys.version_info[0] == 2)
-
-if is_python2: # pragma: no cover
- base_cmp = cmp
-else: # pragma: no cover
- def base_cmp(x, y):
- if x < y:
- return -1
- elif x > y:
- return 1
- else:
- return 0
+def base_cmp(x, y):
+ if x == y:
+ return 0
+ elif x > y:
+ return 1
+ elif x < y:
+ return -1
+ else:
+ # Fix Py2's behavior: cmp(x, y) returns -1 for unorderable types
+ return NotImplemented