forked from hydrocode-de/RUINSapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.py
51 lines (41 loc) · 1.17 KB
/
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
import os
from ruins import __version__
def increment(which='patch'):
"""
Increment the version number.
"""
parts = __version__.split('.')
if which == 'patch':
parts[2] = str(int(parts[2]) + 1)
elif which == 'minor':
parts[1] = str(int(parts[1]) + 1)
parts[2] = '0'
elif which == 'major':
parts[0] = str(int(parts[0]) + 1)
parts[1] = '0'
parts[2] = '0'
else:
raise ValueError("Invalid version increment.")
return '.'.join(parts)
def replace(which='patch'):
"""
Increment the version number for RUINS.
"""
# find the file
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'ruins', '__init__.py'))
# read
with open(path, 'r') as f:
lines = f.readlines()
# replace the version
for i, line in enumerate(lines):
if '__version__' in line:
new_version = increment(which)
lines[i] = f"__version__ = '{new_version}'\n"
break
# overwrite
with open(path, 'w') as f:
f.writelines(lines)
print(new_version)
if __name__ == '__main__':
import fire
fire.Fire(replace)