Skip to content

Commit d82ae7e

Browse files
use click to get package version
Signed-off-by: Harshith-umesh <[email protected]>
1 parent 1313bca commit d82ae7e

File tree

2 files changed

+10
-28
lines changed

2 files changed

+10
-28
lines changed

src/guidellm/__main__.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,13 @@
1919
from guidellm.utils import DefaultGroupHandler
2020
from guidellm.utils import cli as cli_tools
2121

22-
# Import version information
23-
try:
24-
from guidellm.version import version
25-
except ImportError:
26-
version = "unknown"
27-
2822
STRATEGY_PROFILE_CHOICES = list(
2923
set(list(get_args(ProfileType)) + list(get_args(StrategyType)))
3024
)
3125

3226

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-
4027
@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")
4929
def cli():
5030
pass
5131

tests/unit/test_cli.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@ def test_version_flag_case_sensitivity():
8383

8484
@pytest.mark.integration
8585
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+
8789
try:
88-
from guidellm.version import (
89-
version as actual_version,
90-
)
90+
actual_version = importlib.metadata.version("guidellm")
9191

9292
runner = CliRunner()
9393
result = runner.invoke(cli, ["--version"])
9494

9595
assert result.exit_code == 0
9696
expected_output = f"guidellm version: {actual_version}"
9797
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
99101
runner = CliRunner()
100102
result = runner.invoke(cli, ["--version"])
101103

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

0 commit comments

Comments
 (0)