forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_version.py
69 lines (54 loc) · 1.67 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
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 python3
# Note: This file has to live next to setup.py or versioneer will not work
import argparse
import os
import sys
import versioneer
sys.path.insert(0, "")
def write_version_info(path) -> None:
version = None
git_version = None
try:
import _version_meson
version = _version_meson.__version__
git_version = _version_meson.__git_version__
except ImportError:
version = versioneer.get_version()
git_version = versioneer.get_versions()["full-revisionid"]
if os.environ.get("MESON_DIST_ROOT"):
path = os.path.join(os.environ.get("MESON_DIST_ROOT"), path)
with open(path, "w", encoding="utf-8") as file:
file.write(f'__version__="{version}"\n')
file.write(f'__git_version__="{git_version}"\n')
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"-o",
"--outfile",
type=str,
help="Path to write version info to",
required=False,
)
parser.add_argument(
"--print",
default=False,
action="store_true",
help="Whether to print out the version",
required=False,
)
args = parser.parse_args()
if args.outfile:
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)
if args.print:
try:
import _version_meson
version = _version_meson.__version__
except ImportError:
version = versioneer.get_version()
print(version)
main()