Skip to content

Commit

Permalink
Stricter semantic version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jul 7, 2019
1 parent 51eead1 commit 779539c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions tests/test_update_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def setUp(self):
'1.0.3a',
'1.0.0.0',
'1.2.3.4',
'v.1.1',
'.1.2.1',
]
self.valid_versions = [
('1', '1.0.0'),
Expand Down
10 changes: 4 additions & 6 deletions workflow/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Version(object):
"""

#: Match version and pre-release/build information in version strings
match_version = re.compile(r'([0-9\.]+)(.+)?').match
match_version = re.compile(r'([0-9][0-9\.]*)(.+)?').match

def __init__(self, vstr):
"""Create new `Version` object.
Expand All @@ -247,7 +247,7 @@ def _parse(self, vstr):
else:
m = self.match_version(vstr)
if not m:
raise ValueError('invalid version number: {!r}'.format(vstr))
raise ValueError('invalid version number: ' + vstr)

version, suffix = m.groups()
parts = self._parse_dotted_string(version)
Expand All @@ -257,7 +257,7 @@ def _parse(self, vstr):
if len(parts):
self.patch = parts.pop(0)
if not len(parts) == 0:
raise ValueError('version number too long: {!r}'.format(vstr))
raise ValueError('version number too long: ' + vstr)

if suffix:
# Build info
Expand All @@ -268,11 +268,9 @@ def _parse(self, vstr):
if suffix:
if not suffix.startswith('-'):
raise ValueError(
'suffix must start with - : {0}'.format(suffix))
'suffix must start with - : ' + suffix)
self.suffix = suffix[1:]

# wf().logger.debug('version str `{}` -> {}'.format(vstr, repr(self)))

def _parse_dotted_string(self, s):
"""Parse string ``s`` into list of ints and strings."""
parsed = []
Expand Down
2 changes: 1 addition & 1 deletion workflow/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.37.1
1.37.2

0 comments on commit 779539c

Please sign in to comment.