-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_version.py
executable file
·57 lines (46 loc) · 1.67 KB
/
bump_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
#!/usr/bin/env python3
import re
import sys
import argparse
from pathlib import Path
def bump_version(version: str, bump_type: str) -> str:
major, minor, patch = map(int, version.strip('"').split('.'))
if bump_type == 'major':
major += 1
minor = 0
patch = 0
elif bump_type == 'minor':
minor += 1
patch = 0
elif bump_type == 'patch':
patch += 1
return f'"{major}.{minor}.{patch}"'
def update_setup_files(bump_type: str):
setup_files = [
'mt5_grpc_server/setup.py',
'mt5_grpc_proto/setup.py'
]
version_pattern = re.compile(r'version="(\d+\.\d+\.\d+)"')
for setup_file in setup_files:
path = Path(setup_file)
if not path.exists():
print(f"Warning: {setup_file} not found")
continue
content = path.read_text()
match = version_pattern.search(content)
if match:
old_version = match.group(0)
new_version = f'version={bump_version(match.group(1), bump_type)}'
updated_content = content.replace(old_version, new_version)
path.write_text(updated_content)
print(f"Updated {setup_file}: {old_version} -> {new_version}")
else:
print(f"Warning: No version found in {setup_file}")
def main():
parser = argparse.ArgumentParser(description='Bump version numbers in setup.py files')
parser.add_argument('bump_type', choices=['major', 'minor', 'patch'],
help='Which version number to increment')
args = parser.parse_args()
update_setup_files(args.bump_type)
if __name__ == '__main__':
main()