forked from FEniCS/basix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_version.py
More file actions
70 lines (54 loc) · 2.04 KB
/
update_version.py
File metadata and controls
70 lines (54 loc) · 2.04 KB
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
70
"""Utility to update the version number in all locations.
Example usage
-------------
To update the version numbers in all files to "1.0.0", run either of the following:
```bash
python3 update_version.py -v 1.0.0
python3 update_version.py --version 1.0.0
```
To update the C++ version numbers to "1.0.0.3" and the Python version numbers to "1.0.0dev3", run
either of the following:
```bash
python3 update_version.py -v 1.0.0.dev3
python3 update_version.py --version 1.0.0.dev3
```
"""
import argparse
import os
import re
def replace_version(content, version):
content = re.sub(r"((?:VERSION)|(?:version))([\s=]+)([\"']).+?\3",
lambda matches: f"{matches[1]}{matches[2]}{matches[3]}{version}{matches[3]}", content)
return content
parser = argparse.ArgumentParser(description="Update version numbering")
parser.add_argument('-v', '--version', metavar='version', help="Version number to update to", required=True)
args = parser.parse_args()
version = args.version
pyversion = version
if ".dev" in version:
version = version.replace("dev", "")
print("About to update version numbers to:")
print(f" C++ version: {version}")
print(f" Python version: {pyversion}")
answer = None
while answer not in ["Y", "N"]:
if answer is None:
answer = input("Do you want to proceed? [Y/N] ").upper()
else:
answer = input("Please enter Y or N: ").upper()
if answer == "N":
print("Aborting.")
exit()
path = os.path.dirname(os.path.realpath(__file__))
for file in ["CMakeLists.txt", "cpp/CMakeLists.txt", "python/CMakeLists.txt"]:
print(f"Replacing version numbers in {file}.")
with open(os.path.join(path, file)) as f:
content = f.read()
with open(os.path.join(path, file), "w") as f:
f.write(replace_version(content, version))
for file in ["setup.py", "python/setup.py"]:
print(f"Replacing version numbers in {file}.")
with open(os.path.join(path, file)) as f:
content = f.read()
with open(os.path.join(path, file), "w") as f:
f.write(replace_version(content, pyversion))