-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathupdate_version.py
More file actions
36 lines (30 loc) · 1.14 KB
/
update_version.py
File metadata and controls
36 lines (30 loc) · 1.14 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
import os
import re
with open("prj/pyproject.toml", "rt", encoding="utf-8") as f:
lines = f.read().splitlines()
for line in lines:
if line.startswith("version"):
version_toml = line.split("=")[1].strip()[1:-1]
break
with open("prj/CMakeLists.txt", "rt", encoding="utf-8") as f:
lines = f.read().splitlines()
for line in lines:
if "PROJECT_VERSION_STR" in line:
tmp = re.findall('([^)]+)', line)[0]
version_cmakelist = re.sub(r'[^0-9\.]', '', tmp)
break
print(f'prj/pyptoject.toml: {version_toml}')
print(f'prj/CMakeLists.txt: {version_cmakelist}')
if version_toml != version_cmakelist:
print("Incorrect Version")
new_version = input("Enter new version: ")
print(f'Version: {version_toml} => {new_version}')
check = input('Update version(y,n): ')
if check == "y":
for file in ['CMakeLists.txt', 'prj/pyproject.toml', 'prj/CMakeLists.txt', 'prj/include/version.h']:
with open(file, "rt", encoding="utf-8") as f:
data = f.read().replace(version_toml, new_version)
with open(file, "wt", encoding="utf-8") as f:
f.write(data)
else:
print("Cancel update")