-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump_version.py
More file actions
67 lines (49 loc) · 1.88 KB
/
bump_version.py
File metadata and controls
67 lines (49 loc) · 1.88 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
import re
import argparse
PYPROJECT_FILES = [
"humitifier-server/pyproject.toml",
"humitifier-scanner/pyproject.toml",
"humitifier-common/pyproject.toml",
]
PYTHON_FILES = [
"humitifier-server/src/humitifier_server/settings.py",
"humitifier-scanner/src/humitifier_scanner/constants.py",
]
def update_version_in_django_settings(file_path, new_version):
# Yes, this is terrible. But it works.
with open(file_path, "r") as file:
lines = file.readlines()
pattern = re.compile(r'^(HUMITIFIER_VERSION = ")(\d+\.\d+\.\d+)(")$')
updated_lines = []
for line in lines:
match = pattern.match(line)
if match:
updated_line = f"{match.group(1)}{new_version}{match.group(3)}\n"
updated_lines.append(updated_line)
else:
updated_lines.append(line)
with open(file_path, "w") as file:
file.writelines(updated_lines)
def update_version_in_project_toml(file_path, new_version):
# Yes, this is terrible. But it works.
with open(file_path, "r") as file:
lines = file.readlines()
pattern = re.compile(r'^(version = ")(\d+\.\d+\.\d+)(")$')
updated_lines = []
for line in lines:
match = pattern.match(line)
if match:
updated_line = f"{match.group(1)}{new_version}{match.group(3)}\n"
updated_lines.append(updated_line)
else:
updated_lines.append(line)
with open(file_path, "w") as file:
file.writelines(updated_lines)
if __name__ == "__main__":
argparser = argparse.ArgumentParser(description="Bump version")
argparser.add_argument("new_version", type=str, help="New version")
args = argparser.parse_args()
for file in PYPROJECT_FILES:
update_version_in_project_toml(file, args.new_version)
for file in PYTHON_FILES:
update_version_in_django_settings(file, args.new_version)