Skip to content

Commit 347831a

Browse files
committed
versioning hatch scripts
1 parent 1084bcb commit 347831a

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

bump-release.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# updates the version number in the __about__.py file
2+
import subprocess
3+
4+
5+
def update_version(version_type):
6+
with open("src/api/__about__.py", "r") as f:
7+
version = f.read().split("=")[1].replace('"', "").strip()
8+
patch_version = version.split(".")[2]
9+
minor_version = version.split(".")[1]
10+
major_version = version.split(".")[0]
11+
if version_type == "major":
12+
major_version = str(int(major_version) + 1)
13+
minor_version = "0"
14+
patch_version = "0"
15+
elif version_type == "minor":
16+
minor_version = str(int(minor_version) + 1)
17+
patch_version = "0"
18+
elif version_type == "patch":
19+
patch_version = str(int(patch_version) + 1)
20+
else:
21+
raise ValueError("Invalid version type. Please use major, minor, or patch.")
22+
with open("src/api/__about__.py", "w") as f:
23+
new_version = f"{major_version}.{minor_version}.{patch_version}"
24+
f.write(f'__version__ = "{new_version}"\n')
25+
return f"v{new_version}"
26+
27+
28+
# passes the command line argument to the function
29+
if __name__ == "__main__":
30+
import sys
31+
32+
new_version = update_version(sys.argv[1])
33+
message = input(f"Version updated to {new_version}. Enter commit message: \n")
34+
subprocess.run(["git", "add", "."])
35+
subprocess.run(["git", "commit", "-m", message.strip()])
36+
subprocess.run(["git", "push"])
37+
subprocess.run(["git", "tag", "-a", new_version, "-m", new_version])
38+
subprocess.run(["git", "push", "origin", new_version])

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ allow-direct-references = true
3232

3333
[tool.hatch.envs.default.scripts]
3434
start = "python -m src.api.main"
35+
patch = "python bump-release.py patch"
36+
minor = "python bump-release.py minor"
37+
major = "python bump-release.py major"
3538

3639
[tool.hatch.build.targets.wheel]
3740
packages = ["src/api"]

src/api/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.3"
1+
__version__ = "1.0.4"

0 commit comments

Comments
 (0)