Skip to content

Commit

Permalink
Updated increment_version.py to not overwrite the first lines with co…
Browse files Browse the repository at this point in the history
…mments.
  • Loading branch information
notactuallyfinn committed Jul 19, 2024
1 parent b1674eb commit 7e3ce84
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions increment_version.py
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()

0 comments on commit 7e3ce84

Please sign in to comment.