diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2019-08-18 18:45:16 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2019-08-24 15:13:09 +0200 |
commit | ea98f9fb7c76264df5e600ed597b79713e6cb2ce (patch) | |
tree | 22f774aa4b31d97554d550b4ac40dd7c4b7b12f8 /semantic_version/base.py | |
parent | 65d76a46cb1898d9a0dc5c20baf9e014fe974fd8 (diff) | |
download | semantic-version-ea98f9fb7c76264df5e600ed597b79713e6cb2ce.tar.gz |
Drop support for Python<3.4.
Diffstat (limited to 'semantic_version/base.py')
-rw-r--r-- | semantic_version/base.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/semantic_version/base.py b/semantic_version/base.py index 8d9098d..93291e7 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -2,15 +2,10 @@ # Copyright (c) The python-semanticversion project # This code is distributed under the two-clause BSD License. -from __future__ import unicode_literals - import functools import re -from .compat import base_cmp - - def _to_int(value): try: return int(value), True @@ -25,6 +20,17 @@ def _has_leading_zero(value): and value != '0') +def base_cmp(x, y): + if x == y: + return 0 + elif x > y: + return 1 + elif x < y: + return -1 + else: + return NotImplemented + + def identifier_cmp(a, b): """Compare two identifier (for pre-release/build components).""" @@ -68,7 +74,7 @@ def identifier_list_cmp(a, b): return base_cmp(len(a), len(b)) -class Version(object): +class Version: version_re = re.compile(r'^(\d+)\.(\d+)\.(\d+)(?:-([0-9a-zA-Z.-]+))?(?:\+([0-9a-zA-Z.-]+))?$') partial_version_re = re.compile(r'^(\d+)(?:\.(\d+)(?:\.(\d+))?)?(?:-([0-9a-zA-Z.-]*))?(?:\+([0-9a-zA-Z.-]*))?$') @@ -82,8 +88,7 @@ class Version(object): patch=None, prerelease=None, build=None, - partial=False, - ): + partial=False): has_text = version_string is not None has_parts = not (major is minor is patch is prerelease is build is None) if not has_text ^ has_parts: @@ -467,7 +472,7 @@ class Version(object): return self.__compare_helper(other, lambda x: x >= 0, notimpl_target=False) -class SpecItem(object): +class SpecItem: """A requirement specification.""" KIND_ANY = '*' @@ -570,7 +575,7 @@ class SpecItem(object): return hash((self.kind, self.spec)) -class Spec(object): +class Spec: def __init__(self, *specs_strings): subspecs = [self.parse(spec) for spec in specs_strings] self.specs = sum(subspecs, ()) |