@@ -23,62 +23,34 @@ def cli():
23
23
@click .command ()
24
24
def version () -> None :
25
25
"""Display the installed version of warnet"""
26
- # Try to get dynamic version from the Git repository
27
- # This allows a developer to get up-to-date version information
28
- # depending on the state of their local git repository
29
- # (e.g. when installed from source in editable mode).
26
+ # First try to get the version from the installed package
27
+ try :
28
+ from warnet ._version import __version__
29
+ version_str = __version__
30
+ except ImportError :
31
+ version_str = "0.0.0"
32
+
33
+ # Try to get git commit to append
30
34
try :
31
35
# Check if we're in a git repository
32
36
subprocess .check_output (
33
37
["git" , "rev-parse" , "--is-inside-work-tree" ], stderr = subprocess .DEVNULL
34
38
)
35
39
36
- # Get the base version from the latest tag
37
- try :
38
- tag = (
39
- subprocess .check_output (
40
- ["git" , "describe" , "--tags" , "--abbrev=0" ],
41
- stderr = subprocess .DEVNULL ,
42
- text = True ,
43
- )
44
- .strip ()
45
- .lstrip ("v" )
46
- )
47
- except subprocess .SubprocessError :
48
- # No tags found
49
- tag = "0.0.0"
50
-
51
40
# Get the short commit hash
52
41
commit = subprocess .check_output (
53
42
["git" , "rev-parse" , "--short=8" , "HEAD" ], stderr = subprocess .DEVNULL , text = True
54
43
).strip ()
55
44
56
- # Check if there are uncommitted changes
57
- status = subprocess .check_output (
58
- ["git" , "status" , "--porcelain" ], stderr = subprocess .DEVNULL , text = True
59
- ).strip ()
60
-
61
- # Format the version string to match setup.py
62
- version_str = tag
63
- if commit :
64
- version_str += f".{ commit } "
65
- if status :
66
- version_str += "-dirty"
45
+ # If we have a commit hash, append it to the version
46
+ # Don't append if already has a hash
47
+ if commit and "-" not in version_str :
48
+ version_str = f"{ version_str } -{ commit } "
67
49
68
- click .echo (f"warnet version { version_str } (from git)" )
69
- return
50
+ click .echo (f"warnet version { version_str } " )
70
51
except (subprocess .SubprocessError , FileNotFoundError ):
71
- # Git commands failed or git not available, fall back to installed version
72
- pass
73
-
74
- # Fall back to the version file generated during installation
75
- try :
76
- from warnet ._version import __version__
77
-
78
- version = __version__
79
- click .echo (f"warnet version { version } " )
80
- except ImportError :
81
- click .echo ("warnet version unknown" )
52
+ # Git commands failed or git not available, just use the version without the commit
53
+ click .echo (f"warnet version { version_str } " )
82
54
83
55
84
56
cli .add_command (admin )
0 commit comments