Skip to content

Commit 221af24

Browse files
committed
Added update version script
1 parent 5ea4700 commit 221af24

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

scripts/versioning/update_version.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import sys
2+
3+
from pydatastructs.utils.tests.test_code_quality import _list_files
4+
5+
6+
def update_version_in_files(file_paths, origin_version, new_version):
7+
"""
8+
Updates the version number in the specified files.
9+
10+
Parameters
11+
==========
12+
13+
file_paths: list
14+
List of file paths to be updated.
15+
origin_version: str
16+
The original version number to be replaced.
17+
new_version: str
18+
The new version number to replace the original.
19+
20+
Returns
21+
=======
22+
23+
None
24+
"""
25+
was_updated = False
26+
for path in file_paths:
27+
with open(path, 'r') as file:
28+
data = file.read()
29+
if origin_version in data:
30+
was_updated = True
31+
data = data.replace(origin_version, new_version)
32+
with open(path, 'w') as file:
33+
file.write(data)
34+
35+
return was_updated
36+
37+
38+
def main():
39+
if len(sys.argv) != 3:
40+
print('Usage: python update_version.py <origin_version> <new_version>')
41+
return
42+
43+
origin_version, new_version = sys.argv[1], sys.argv[2]
44+
print(f'Updating version number from {origin_version} to {new_version}...')
45+
46+
pydatastructs_files = _list_files(lambda _file: _file.endswith('.py'),
47+
'./pydatastructs')
48+
docs_files = _list_files(lambda _file: _file.endswith('.rst') or _file.endswith('.py'),
49+
'./docs/source')
50+
file_paths = ['README.md', 'setup.py'] + pydatastructs_files + docs_files
51+
52+
was_updated = update_version_in_files(
53+
file_paths, origin_version, new_version)
54+
55+
if was_updated:
56+
print('Version number updated successfully!')
57+
else:
58+
print('WARNING: Version number not found in the specified files.')
59+
60+
61+
if __name__ == "__main__":
62+
main()

0 commit comments

Comments
 (0)