|
1 | 1 | import toml |
| 2 | +import os |
2 | 3 |
|
3 | 4 | def main(): |
4 | | - with open("pyproject.toml", 'r+') as f: |
5 | | - data = toml.load(f) |
6 | | - project = data.get("project") |
7 | | - if not project is None: |
8 | | - version = project.get("version") |
9 | | - if not version is None: |
10 | | - a,b,c = map(int, version.split(".")) |
11 | | - if c < 99: |
12 | | - c += 1 |
13 | | - elif b < 99: |
14 | | - c = 0 |
15 | | - b += 1 |
| 5 | + try: |
| 6 | + os.rename("pyproject.toml", "pyproject.txt") |
| 7 | + with open("pyproject.txt", 'r+') as f: |
| 8 | + comment = [] |
| 9 | + while True: |
| 10 | + line = f.readline() |
| 11 | + if line[0] == "#": |
| 12 | + comment = [line] + comment |
16 | 13 | else: |
17 | | - c = 0 |
18 | | - b = 0 |
19 | | - a += 1 |
20 | | - data["project"]["version"] = str(a) + "." + str(b) + "." + str(c) |
21 | | - if not data == {}: |
22 | | - with open("pyproject.toml", 'w') as f: |
23 | | - toml.dump(data, f) |
| 14 | + break |
| 15 | + os.rename("pyproject.txt", "pyproject.toml") |
| 16 | + with open("pyproject.toml", 'r+') as f: |
| 17 | + data = toml.load(f) |
| 18 | + project = data.get("project") |
| 19 | + if not project is None: |
| 20 | + version = project.get("version") |
| 21 | + if not version is None: |
| 22 | + a,b,c = map(int, version.split(".")) |
| 23 | + if c < 99: |
| 24 | + c += 1 |
| 25 | + elif b < 99: |
| 26 | + c = 0 |
| 27 | + b += 1 |
| 28 | + else: |
| 29 | + c = 0 |
| 30 | + b = 0 |
| 31 | + a += 1 |
| 32 | + data["project"]["version"] = str(a) + "." + str(b) + "." + str(c) |
| 33 | + if not data == {}: |
| 34 | + with open("pyproject.toml", 'w') as f: |
| 35 | + toml.dump(data, f) |
| 36 | + os.rename("pyproject.toml", "pyproject.txt") |
| 37 | + with open("pyproject.txt", 'r+') as f: |
| 38 | + content = f.readlines() |
| 39 | + content = comment + content |
| 40 | + with open("pyproject.txt", 'w') as f: |
| 41 | + for line in content: |
| 42 | + f.write(line) |
| 43 | + os.rename("pyproject.txt", "pyproject.toml") |
| 44 | + except (FileNotFoundError): |
| 45 | + pass |
24 | 46 |
|
25 | 47 | main() |
0 commit comments