-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_project_version.py
executable file
·58 lines (42 loc) · 1.46 KB
/
update_project_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
import re
import sys
def update_version(version, update_type):
major, minor, patch = map(int, version.split("."))
if update_type == "major":
major += 1
minor = 0
patch = 0
elif update_type == "minor":
minor += 1
patch = 0
elif update_type == "patch":
patch += 1
else:
raise ValueError("Invalid update type. Use 'major', 'minor', or 'patch'.")
return f"{major}.{minor}.{patch}"
def update_version_files(new_version):
# Update version.txt
with open("version.txt", "w") as f:
f.write(new_version)
# Update setup.py if it exists
try:
with open("setup.py", "r") as f:
content = f.read()
new_content = re.sub(
r'version="[0-9]+\.[0-9]+\.[0-9]+"', f'version="{new_version}"', content
)
with open("setup.py", "w") as f:
f.write(new_content)
print("Updated version in setup.py")
except FileNotFoundError:
print("setup.py not found, skipping")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python update_project_version.py <major|minor|patch>")
sys.exit(1)
update_type = sys.argv[1].lower()
with open("version.txt", "r") as f:
current_version = f.read().strip()
new_version = update_version(current_version, update_type)
update_version_files(new_version)
print(f"Project version updated from {current_version} to {new_version}")