12
12
13
13
def get_git_tag ():
14
14
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" )
17
19
except subprocess .CalledProcessError :
18
20
return None
19
21
20
22
def get_latest_tag ():
21
23
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 ()
23
27
return tag .lstrip ("v" )
24
28
except subprocess .CalledProcessError :
25
29
return "0.0.0"
26
30
27
31
def get_commit_count_since (tag ):
28
32
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 ()
30
36
return int (output )
31
37
except subprocess .CalledProcessError :
32
38
return 0
33
39
34
40
def inject_version (version : str ):
35
- print (f"🔁 Injecting version: { version } " )
41
+ print (f"\U0001f501 Injecting version: { version } " )
36
42
37
43
# Update __init__.py
38
44
init_content = INIT_FILE .read_text ()
@@ -48,20 +54,20 @@ def inject_version(version: str):
48
54
PYPROJECT_FILE .write_text (new_pyproject )
49
55
50
56
def main ():
51
- mode = "--dev" if "--dev" in sys .argv else "release"
57
+ dev_mode = "--dev" in sys .argv
52
58
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 :
54
64
version = get_git_tag ()
55
65
if not version :
56
- print ("❌ Error: No exact tag found for release." )
66
+ print ("\u274c Error: No exact tag found for release." )
57
67
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 } "
62
68
63
69
inject_version (version )
64
- print (f"✅ Injected { mode } version: { version } " )
70
+ print (f"\u2705 Injected { 'dev' if dev_mode else 'release' } version: { version } " )
65
71
66
72
if __name__ == "__main__" :
67
- main ()
73
+ main ()
0 commit comments