-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathverify_tag.py
54 lines (42 loc) · 1.41 KB
/
verify_tag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Standard library imports
import argparse
import os
import re
def is_appropriate_tag(version, tag):
# Make sure the tag version and version in __about__.py match
return (
re.match(
r"^" + tag + r"(\.post(0|[1-9]\d*))?(\.dev(0|[1-9]\d*))?$", "v" + version
)
is not None
)
def is_canonical(version):
return (
re.match(
r"^([1-9]\d*!)?(0|[1-9]\d*)(\.(0|[1-9]\d*))*((a|b|rc)(0|[1-9]\d*))?(\.post(0|[1-9]\d*))?(\.dev(0|[1-9]\d*))?$",
version,
)
is not None
)
def _get_current_version():
about = {}
with open(os.path.join("uplink", "__about__.py")) as fp:
exec(fp.read(), about)
return about.get("__version__", None)
def verify_version(tag):
# Get version defined in package
version = _get_current_version()
assert version is not None, "The version is not defined in uplink/__about__.py."
assert tag is not None, "The tag is not defined."
assert is_canonical(version), "The version string [%s] violates PEP-440"
assert is_appropriate_tag(version, tag), (
f"The tag [{tag}] does not match the current version in uplink/__about__.py [{version}]"
)
return version
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--tag", required=True)
args = parser.parse_args()
return verify_version(args.tag)
if __name__ == "__main__":
print(main())