-
Notifications
You must be signed in to change notification settings - Fork 3
/
update-version.py
59 lines (48 loc) · 2.13 KB
/
update-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
import subprocess
# Run build - expected to fail due to different versions
ret = subprocess.run(("python", "-m", "build"))
if ret.returncode == 0:
print("Build did not fail, so must be same version - exit script!!!")
lines = []
pyversion_line = None
version_line = None
revision_line = None
with open("pyproject.toml") as f:
for i, line in enumerate(f.readlines()):
if "version = " in line:
pyversion_line = i
elif "-Drevision" in line:
revision_line = i
elif "-Dversion" in line:
version_line = i
lines.append(line)
new_version = subprocess.check_output("./check-version.sh", text=True).strip()
old_version = lines[version_line][len(" '-Dversion="):-len("'\n")]
print(f"New version is {new_version}, old version was {old_version}")
if old_version == new_version:
print("No change - exit script!!!")
lines[version_line] = f" '-Dversion={new_version}'\n"
new_revision = subprocess.check_output(["git", "-C", "libcamera", "describe", "--tags", "origin/main"], text=True).strip()
old_revision = lines[revision_line][len(" '-Drevision="):-len("',\n")]
print(f"New revision is {new_revision}, old version was {old_revision}")
if old_revision == new_revision:
print("No change - exit script!!!")
lines[revision_line] = f" '-Drevision={new_revision}',\n"
old_pyversion = lines[pyversion_line][len("version = '"):-len("'\n")]
new_pyversion = input(f"New pyversion - currently {old_pyversion}: ")
lines[pyversion_line] = f"version = '{new_pyversion}'\n"
with open("pyproject.toml", "w") as f:
f.writelines(lines)
lines = []
table_end_line = None
with open("README.md") as f:
for i, line in enumerate(f.readlines()):
if "| --------------- | -------------------------- | ------------------- |" in line:
table_end_line = i+1
lines.append(line)
new_table_line = f"| {input('System and Date (eg Raspberry Pi Bookworm 22/11/2023): ')} | {new_version} | {new_pyversion} |\n"
lines.insert(table_end_line, new_table_line)
with open("README.md", "w") as f:
f.writelines(lines)
# Run build - should now succeed
ret = subprocess.run(("python", "-m", "build"))