-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated increment_version.py to not overwrite the first lines with co…
…mments.
- Loading branch information
1 parent
b1674eb
commit 7e3ce84
Showing
1 changed file
with
41 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
import toml | ||
import os | ||
|
||
def main(): | ||
with open("pyproject.toml", 'r+') as f: | ||
data = toml.load(f) | ||
project = data.get("project") | ||
if not project is None: | ||
version = project.get("version") | ||
if not version is None: | ||
a,b,c = map(int, version.split(".")) | ||
if c < 99: | ||
c += 1 | ||
elif b < 99: | ||
c = 0 | ||
b += 1 | ||
try: | ||
os.rename("pyproject.toml", "pyproject.txt") | ||
with open("pyproject.txt", 'r+') as f: | ||
comment = [] | ||
while True: | ||
line = f.readline() | ||
if line[0] == "#": | ||
comment = [line] + comment | ||
else: | ||
c = 0 | ||
b = 0 | ||
a += 1 | ||
data["project"]["version"] = str(a) + "." + str(b) + "." + str(c) | ||
if not data == {}: | ||
with open("pyproject.toml", 'w') as f: | ||
toml.dump(data, f) | ||
break | ||
os.rename("pyproject.txt", "pyproject.toml") | ||
with open("pyproject.toml", 'r+') as f: | ||
data = toml.load(f) | ||
project = data.get("project") | ||
if not project is None: | ||
version = project.get("version") | ||
if not version is None: | ||
a,b,c = map(int, version.split(".")) | ||
if c < 99: | ||
c += 1 | ||
elif b < 99: | ||
c = 0 | ||
b += 1 | ||
else: | ||
c = 0 | ||
b = 0 | ||
a += 1 | ||
data["project"]["version"] = str(a) + "." + str(b) + "." + str(c) | ||
if not data == {}: | ||
with open("pyproject.toml", 'w') as f: | ||
toml.dump(data, f) | ||
os.rename("pyproject.toml", "pyproject.txt") | ||
with open("pyproject.txt", 'r+') as f: | ||
content = f.readlines() | ||
content = comment + content | ||
with open("pyproject.txt", 'w') as f: | ||
for line in content: | ||
f.write(line) | ||
os.rename("pyproject.txt", "pyproject.toml") | ||
except (FileNotFoundError): | ||
pass | ||
|
||
main() |