File tree Expand file tree Collapse file tree 2 files changed +10
-28
lines changed Expand file tree Collapse file tree 2 files changed +10
-28
lines changed Original file line number Diff line number Diff line change 19
19
from guidellm .utils import DefaultGroupHandler
20
20
from guidellm .utils import cli as cli_tools
21
21
22
- # Import version information
23
- try :
24
- from guidellm .version import version
25
- except ImportError :
26
- version = "unknown"
27
-
28
22
STRATEGY_PROFILE_CHOICES = list (
29
23
set (list (get_args (ProfileType )) + list (get_args (StrategyType )))
30
24
)
31
25
32
26
33
- def _version_callback (ctx : click .Context , _param : click .Parameter , value : bool ) -> None :
34
- """Callback for --version flag."""
35
- if value :
36
- click .echo (f"guidellm version: { version } " )
37
- ctx .exit ()
38
-
39
-
40
27
@click .group ()
41
- @click .option (
42
- "--version" ,
43
- is_flag = True ,
44
- expose_value = False ,
45
- is_eager = True ,
46
- help = "Show the version and exit." ,
47
- callback = _version_callback ,
48
- )
28
+ @click .version_option (package_name = "guidellm" , message = "guidellm version: %(version)s" )
49
29
def cli ():
50
30
pass
51
31
Original file line number Diff line number Diff line change @@ -83,21 +83,23 @@ def test_version_flag_case_sensitivity():
83
83
84
84
@pytest .mark .integration
85
85
def test_version_integration_with_actual_version ():
86
- """Integration test to verify version matches what's in version.py."""
86
+ """Integration test to verify version matches importlib.metadata."""
87
+ import importlib .metadata
88
+
87
89
try :
88
- from guidellm .version import (
89
- version as actual_version ,
90
- )
90
+ actual_version = importlib .metadata .version ("guidellm" )
91
91
92
92
runner = CliRunner ()
93
93
result = runner .invoke (cli , ["--version" ])
94
94
95
95
assert result .exit_code == 0
96
96
expected_output = f"guidellm version: { actual_version } "
97
97
assert expected_output in result .output
98
- except ImportError :
98
+ except importlib .metadata .PackageNotFoundError :
99
+ # If package is not installed, the CLI should show an error
100
+ # This is expected behavior when the package isn't properly installed
99
101
runner = CliRunner ()
100
102
result = runner .invoke (cli , ["--version" ])
101
103
102
- assert result . exit_code == 0
103
- assert "guidellm version: unknown" in result .output
104
+ # Click will handle the error when package is not found
105
+ assert result .exit_code != 0
You can’t perform that action at this time.
0 commit comments