Skip to content

Commit dd7386d

Browse files
committed
Update version detection script for CI
Signed-off-by: Joffrey F <[email protected]>
1 parent a3111d9 commit dd7386d

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

scripts/versions.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@
1111
'test'
1212
]
1313

14+
STAGES = ['tp', 'beta', 'rc']
1415

15-
class Version(namedtuple('_Version', 'major minor patch rc edition')):
16+
17+
class Version(namedtuple('_Version', 'major minor patch stage edition')):
1618

1719
@classmethod
1820
def parse(cls, version):
1921
edition = None
2022
version = version.lstrip('v')
21-
version, _, rc = version.partition('-')
22-
if rc:
23-
if 'rc' not in rc:
24-
edition = rc
25-
rc = None
26-
elif '-' in rc:
27-
edition, rc = rc.split('-')
28-
23+
version, _, stage = version.partition('-')
24+
if stage:
25+
if not any(marker in stage for marker in STAGES):
26+
edition = stage
27+
stage = None
28+
elif '-' in stage:
29+
edition, stage = stage.split('-')
2930
major, minor, patch = version.split('.', 3)
30-
return cls(major, minor, patch, rc, edition)
31+
return cls(major, minor, patch, stage, edition)
3132

3233
@property
3334
def major_minor(self):
@@ -38,14 +39,22 @@ def order(self):
3839
"""Return a representation that allows this object to be sorted
3940
correctly with the default comparator.
4041
"""
41-
# rc releases should appear before official releases
42-
rc = (0, self.rc) if self.rc else (1, )
43-
return (int(self.major), int(self.minor), int(self.patch)) + rc
42+
# non-GA releases should appear before GA releases
43+
# Order: tp -> beta -> rc -> GA
44+
if self.stage:
45+
for st in STAGES:
46+
if st in self.stage:
47+
stage = (STAGES.index(st), self.stage)
48+
break
49+
else:
50+
stage = (len(STAGES),)
51+
52+
return (int(self.major), int(self.minor), int(self.patch)) + stage
4453

4554
def __str__(self):
46-
rc = '-{}'.format(self.rc) if self.rc else ''
55+
stage = '-{}'.format(self.stage) if self.stage else ''
4756
edition = '-{}'.format(self.edition) if self.edition else ''
48-
return '.'.join(map(str, self[:3])) + edition + rc
57+
return '.'.join(map(str, self[:3])) + edition + stage
4958

5059

5160
def main():

0 commit comments

Comments
 (0)