|
2 | 2 | import sys
|
3 | 3 |
|
4 | 4 | if len(sys.argv) != 3:
|
5 |
| - raise ValueError('original version number and new version number are both needed!') |
6 |
| - |
7 |
| -origin_version, new_version = sys.argv[1], sys.argv[2] |
8 |
| - |
9 |
| -# file_path contains all files'(README, code, documentation source) paths that may contain version number. |
10 |
| -file_path = ['README.md', 'setup.py'] |
11 |
| - |
12 |
| -# Walk through directories to add all corresponding files' paths into file_path |
13 |
| -for root, _, files in os.walk('./pydatastructs'): |
14 |
| - for file in files: |
15 |
| - |
16 |
| - if file.endswith('.py'): |
17 |
| - file_path.append(os.path.join(root, file)) |
18 |
| - |
19 |
| -for root, dirs, files in os.walk('./docs/source'): |
20 |
| - for file in files: |
21 |
| - if file.endswith('.rst') or file.endswith('.py'): |
22 |
| - file_path.append(os.path.join(root, file)) |
23 |
| - |
24 |
| -# Update version number everywhere |
25 |
| -for path in file_path: |
26 |
| - with open(path, 'r') as file: |
27 |
| - data = file.read() |
28 |
| - if origin_version in data: |
29 |
| - data = data.replace(origin_version, new_version) |
30 |
| - with open(path, 'w') as file: |
31 |
| - file.write(data) |
32 |
| - |
33 |
| -print('Updated version number!') |
| 5 | + print('original version number and new version number are both needed!') |
| 6 | +else: |
| 7 | + origin_version, new_version = sys.argv[1], sys.argv[2] |
| 8 | + |
| 9 | + # file_path contains all files'(README, code, documentation source) paths that may contain version number. |
| 10 | + file_path = ['README.md', 'setup.py'] |
| 11 | + |
| 12 | + # Walk through directories to add all corresponding files' paths into file_path |
| 13 | + for root, _, files in os.walk('./pydatastructs'): |
| 14 | + for file in files: |
| 15 | + |
| 16 | + if file.endswith('.py'): |
| 17 | + file_path.append(os.path.join(root, file)) |
| 18 | + |
| 19 | + for root, dirs, files in os.walk('./docs/source'): |
| 20 | + for file in files: |
| 21 | + if file.endswith('.rst') or file.endswith('.py'): |
| 22 | + file_path.append(os.path.join(root, file)) |
| 23 | + |
| 24 | + # Update version number everywhere |
| 25 | + for path in file_path: |
| 26 | + with open(path, 'r') as file: |
| 27 | + data = file.read() |
| 28 | + if origin_version in data: |
| 29 | + data = data.replace(origin_version, new_version) |
| 30 | + with open(path, 'w') as file: |
| 31 | + file.write(data) |
| 32 | + |
| 33 | + print('Updated version number!') |
0 commit comments