forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_version.py
40 lines (29 loc) · 1.03 KB
/
generate_version.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
# Note: This file has to live next to versioneer.py or it will not work
import argparse
import os
import versioneer
def write_version_info(path):
vinfo = versioneer.get_versions()
full_version = vinfo['version']
git_revision = vinfo['full-revisionid']
if os.environ.get("MESON_DIST_ROOT"):
path = os.path.join(os.environ.get("MESON_DIST_ROOT"), path)
with open(path, "w") as f:
f.write("def get_versions():\n")
f.write(" return {\n")
f.write(f" 'full-revisionid': '{git_revision}',\n")
f.write(f" 'version': '{full_version}'\n")
f.write("}")
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-o", "--outfile", type=str, help="Path to write version info to"
)
args = parser.parse_args()
if not args.outfile.endswith(".py"):
raise ValueError(
f"Output file must be a Python file. "
f"Got: {args.outfile} as filename instead"
)
write_version_info(args.outfile)
main()