forked from spacetelescope/crds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_version
executable file
·69 lines (49 loc) · 1.8 KB
/
save_version
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env pysh
#-*-python-*-
# requires CRDS install for pysh
import re
from crds import pysh
# -----------------------------------------------------------------
def rewrite(filename, regex, replacement):
with open(filename) as file:
contents = file.read()
contents = re.sub(regex, replacement, contents)
with open(filename, "w+") as file:
file.write(contents)
def indirect_out(command):
return pysh.out("${command}").strip()
def main():
pysh.usage("<x.y.z> 'rationale for this version.'", 2, 2, """
Save the semantic version number and rationale string within the
necessary CRDS source code files.
This script is run as part of development closeout and requires
CRDS to be installed. It is not run during setup.
""")
semantic_version = pysh.arg(1)
rationale = pysh.arg(2)
with open("crds/core/git_version.py", "w+") as file:
git_version = indirect_out("git show -s --pretty=%h")
git_branch = indirect_out("git rev-parse --abbrev-ref HEAD")
git_sha1 = indirect_out("git show -s --pretty=%h")
file.write(f"""
__version__ = '{git_version}'
__full_version_info__ = '''
branch: {git_branch}
sha1: {git_sha1}
'''
""")
rewrite("setup.py",
r"version\s*=\s*'(\d+\.)*\d+'",
f"version = '{semantic_version}'")
rewrite("setup.cfg",
r'version\s*=\s*(\d+\.)*\d+',
f"version = {semantic_version}")
rewrite("crds/__init__.py",
r"__version__\s*=\s*\"(\d+\.)*\d+\"",
f'__version__ = "{semantic_version}"')
rewrite("crds/__init__.py",
r'__rationale__\s*=\s*"(\w|\s|[-+,.%$&*()!@#~])+"',
f'__rationale__ = "{rationale}"')
# -----------------------------------------------------------------
if __name__ == "__main__":
main()