This commit is contained in:
Raphaël Barrois 2016-09-01 13:48:40 +02:00
parent ae9ccbd517
commit 730b9f2270
3 changed files with 18 additions and 11 deletions

View File

@ -3,8 +3,8 @@
# This code is distributed under the two-clause BSD License.
from .base import compare, match, validate, Spec, SpecItem, Version
__author__ = "Raphaël Barrois <raphael.barrois+semver@polytechnique.org>"
__version__ = '2.5.0'
from .base import compare, match, validate, Spec, SpecItem, Version

View File

@ -10,12 +10,14 @@ import re
from .compat import base_cmp
def _to_int(value):
try:
return int(value), True
except ValueError:
return value, False
def _has_leading_zero(value):
return (value
and value[0] == '0'
@ -133,8 +135,10 @@ class Version(object):
match = base_re.match(version_string)
if not match:
raise ValueError("Version string lacks a numerical component: %r"
% version_string)
raise ValueError(
"Version string lacks a numerical component: %r"
% version_string
)
version = version_string[:match.end()]
if not partial:
@ -242,8 +246,11 @@ class Version(object):
def _validate_identifiers(cls, identifiers, allow_leading_zeroes=False):
for item in identifiers:
if not item:
raise ValueError("Invalid empty identifier %r in %r"
% (item, '.'.join(identifiers)))
raise ValueError(
"Invalid empty identifier %r in %r"
% (item, '.'.join(identifiers))
)
if item[0] == '0' and item.isdigit() and item != '0' and not allow_leading_zeroes:
raise ValueError("Invalid leading zero in identifier %r" % item)
@ -336,7 +343,6 @@ class Version(object):
]
def __compare(self, other):
field_pairs = zip(self, other)
comparison_functions = self._comparison_functions(partial=self.partial or other.partial)
comparisons = zip(comparison_functions, self, other)
@ -440,8 +446,9 @@ class SpecItem(object):
spec = Version(version, partial=True)
if spec.build is not None and kind not in (cls.KIND_EQUAL, cls.KIND_NEQ):
raise ValueError(
"Invalid requirement specification %r: build numbers have no ordering."
% requirement_string)
"Invalid requirement specification %r: build numbers have no ordering."
% requirement_string
)
return (kind, spec)
def match(self, version):

View File

@ -102,7 +102,7 @@ def add_south_rules():
try: # pragma: no cover
import south
except ImportError: # pragma: no cover
except ImportError: # pragma: no cover
south = None
if south: # pragma: no cover