-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathversion_bumper.py
50 lines (40 loc) · 1.05 KB
/
version_bumper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# /// script
# dependencies = [
# "toml>=0.10.2"
# ]
# ///
import subprocess
from typing import Literal
import toml
def bump_version(part: Literal["major", "minor", "patch"] = "patch") -> None:
file_path = "pyproject.toml"
with open(file_path, "r") as f:
pyproject = toml.load(f)
version = pyproject["project"]["version"]
major, minor, patch = map(int, version.split("."))
if part == "major":
major += 1
minor = 0
patch = 0
elif part == "minor":
minor += 1
patch = 0
elif part == "patch":
patch += 1
else:
raise ValueError("Invalid part value. Choose 'major', 'minor', or 'patch'.")
new_version = f"{major}.{minor}.{patch}"
subprocess.run(
[
"uvx",
"--from=toml-cli",
"toml",
"set",
"--toml-path=pyproject.toml",
"project.version",
new_version,
]
)
print(f"Version bumped to {major}.{minor}.{patch}")
if __name__ == "__main__":
bump_version()