Skip to content

Commit 048d421

Browse files
committed
Adding back in auto increment of version
1 parent 00293c5 commit 048d421

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

.hooks/sync_version.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,33 @@
1212

1313
def get_git_tag():
1414
try:
15-
tag = subprocess.check_output(["git", "describe", "--tags", "--exact-match"], stderr=subprocess.DEVNULL, text=True).strip()
16-
return tag.lstrip("v") # Remove 'v' prefix
15+
tag = subprocess.check_output([
16+
"git", "describe", "--tags", "--exact-match"
17+
], stderr=subprocess.DEVNULL, text=True).strip()
18+
return tag.lstrip("v")
1719
except subprocess.CalledProcessError:
1820
return None
1921

2022
def get_latest_tag():
2123
try:
22-
tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"], text=True).strip()
24+
tag = subprocess.check_output([
25+
"git", "describe", "--tags", "--abbrev=0"
26+
], text=True).strip()
2327
return tag.lstrip("v")
2428
except subprocess.CalledProcessError:
2529
return "0.0.0"
2630

2731
def get_commit_count_since(tag):
2832
try:
29-
output = subprocess.check_output(["git", "rev-list", f"{tag}..HEAD", "--count"], text=True).strip()
33+
output = subprocess.check_output([
34+
"git", "rev-list", f"v{tag}..HEAD", "--count"
35+
], text=True).strip()
3036
return int(output)
3137
except subprocess.CalledProcessError:
3238
return 0
3339

3440
def inject_version(version: str):
35-
print(f"🔁 Injecting version: {version}")
41+
print(f"\U0001f501 Injecting version: {version}")
3642

3743
# Update __init__.py
3844
init_content = INIT_FILE.read_text()
@@ -48,20 +54,20 @@ def inject_version(version: str):
4854
PYPROJECT_FILE.write_text(new_pyproject)
4955

5056
def main():
51-
mode = "--dev" if "--dev" in sys.argv else "release"
57+
dev_mode = "--dev" in sys.argv
5258

53-
if mode == "release":
59+
if dev_mode:
60+
base = get_latest_tag()
61+
commits = get_commit_count_since(base)
62+
version = f"{base}.dev{commits}"
63+
else:
5464
version = get_git_tag()
5565
if not version:
56-
print(" Error: No exact tag found for release.")
66+
print("\u274c Error: No exact tag found for release.")
5767
sys.exit(1)
58-
else:
59-
base = get_latest_tag()
60-
commits = get_commit_count_since(f"v{base}")
61-
version = f"{base}.dev{commits}"
6268

6369
inject_version(version)
64-
print(f" Injected {mode} version: {version}")
70+
print(f"\u2705 Injected {'dev' if dev_mode else 'release'} version: {version}")
6571

6672
if __name__ == "__main__":
67-
main()
73+
main()

0 commit comments

Comments
 (0)