Add support for beta/rc release versions.
This commit is contained in:
@@ -63,7 +63,7 @@ class Version (object):
|
|||||||
'''A release version.'''
|
'''A release version.'''
|
||||||
|
|
||||||
RGX = re.compile(
|
RGX = re.compile(
|
||||||
r'^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-([1-9]\d*))?$',
|
r'^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(beta|rc)?([1-9]\d*))?$',
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -77,23 +77,33 @@ class Version (object):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
[major, minor, patch, _, hotfix] = m.groups()
|
[major, minor, patch, _, betarc, hotfix] = m.groups()
|
||||||
return Version(
|
return Version(
|
||||||
int(major),
|
int(major),
|
||||||
int(minor),
|
int(minor),
|
||||||
int(patch),
|
int(patch),
|
||||||
|
betarc,
|
||||||
int(hotfix) if hotfix is not None else None,
|
int(hotfix) if hotfix is not None else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, major, minor, patch, hotfix):
|
def __init__(self, major, minor, patch, betarc, hotfix):
|
||||||
|
for i in [major, minor, patch]:
|
||||||
|
assert type(i) is int, i
|
||||||
|
assert betarc in {None, 'rc', 'beta'}, betarc
|
||||||
|
assert hotfix is None or type(hotfix) is int, hotfix
|
||||||
|
|
||||||
self.major = major
|
self.major = major
|
||||||
self.minor = minor
|
self.minor = minor
|
||||||
self.patch = patch
|
self.patch = patch
|
||||||
|
self.betarc = betarc
|
||||||
self.hotfix = hotfix
|
self.hotfix = hotfix
|
||||||
|
|
||||||
self.vtext = 'v{}.{}.{}'.format(major, minor, patch)
|
self.vtext = 'v{}.{}.{}'.format(major, minor, patch)
|
||||||
if hotfix is not None:
|
if hotfix is not None:
|
||||||
self.vtext += '-{}'.format(hotfix)
|
self.vtext += '-{}{}'.format(
|
||||||
|
'' if betarc is None else betarc,
|
||||||
|
hotfix,
|
||||||
|
)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Version {}>'.format(self.vtext)
|
return '<Version {}>'.format(self.vtext)
|
||||||
@@ -135,7 +145,6 @@ class TestVersion (unittest.TestCase):
|
|||||||
cases = [
|
cases = [
|
||||||
'v07.0.0',
|
'v07.0.0',
|
||||||
'v1.0.03',
|
'v1.0.03',
|
||||||
'v1.0.0-rc2',
|
|
||||||
'v1.2.3-0', # Hotfix numbers must begin w/ 1
|
'v1.2.3-0', # Hotfix numbers must begin w/ 1
|
||||||
'v1.2.3~0',
|
'v1.2.3~0',
|
||||||
'v1.2.3+0',
|
'v1.2.3+0',
|
||||||
|
|||||||
Reference in New Issue
Block a user