Skip to content

Commit d48afb1

Browse files
committed
Remove private imports from client, move util function only used by CLI to cli/_utils.py
1 parent 5ef4e1f commit d48afb1

File tree

7 files changed

+40
-36
lines changed

7 files changed

+40
-36
lines changed

tests/vec_inf/cli/test_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Tests for the utils functions in the vec-inf cli."""
2+
3+
from vec_inf.cli._utils import create_table
4+
5+
6+
def test_create_table_with_header():
7+
"""Test that create_table creates a table with the correct header."""
8+
table = create_table("Key", "Value")
9+
assert table.columns[0].header == "Key"
10+
assert table.columns[1].header == "Value"
11+
assert table.show_header is True
12+
13+
14+
def test_create_table_without_header():
15+
"""Test create_table without header."""
16+
table = create_table(show_header=False)
17+
assert table.show_header is False

tests/vec_inf/client/test_utils.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests for the utility functions in the CLI module."""
1+
"""Tests for the utility functions in the vec-inf client."""
22

33
import os
44
from unittest.mock import MagicMock, patch
@@ -8,7 +8,6 @@
88

99
from vec_inf.client._utils import (
1010
MODEL_READY_SIGNATURE,
11-
create_table,
1211
get_base_url,
1312
is_server_running,
1413
load_config,
@@ -134,20 +133,6 @@ def test_model_health_check_request_exception():
134133
assert result == ("FAILED", "Connection error")
135134

136135

137-
def test_create_table_with_header():
138-
"""Test that create_table creates a table with the correct header."""
139-
table = create_table("Key", "Value")
140-
assert table.columns[0].header == "Key"
141-
assert table.columns[1].header == "Value"
142-
assert table.show_header is True
143-
144-
145-
def test_create_table_without_header():
146-
"""Test create_table without header."""
147-
table = create_table(show_header=False)
148-
assert table.show_header is False
149-
150-
151136
def test_load_config_default_only():
152137
"""Test loading the actual default configuration file from the filesystem."""
153138
configs = load_config()

vec_inf/cli/_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
MetricsResponseFormatter,
1414
StatusResponseFormatter,
1515
)
16-
from vec_inf.client._models import LaunchOptions, LaunchOptionsDict
17-
from vec_inf.client.api import VecInfClient
16+
from vec_inf.client import LaunchOptions, LaunchOptionsDict, VecInfClient
1817

1918

2019
CONSOLE = Console()

vec_inf/cli/_helper.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
from rich.panel import Panel
1010
from rich.table import Table
1111

12-
import vec_inf.client._utils as utils
1312
from vec_inf.cli._models import MODEL_TYPE_COLORS, MODEL_TYPE_PRIORITY
14-
from vec_inf.client._config import ModelConfig
15-
from vec_inf.client._models import ModelInfo, StatusResponse
13+
from vec_inf.cli._utils import create_table
14+
from vec_inf.client import ModelConfig, ModelInfo, StatusResponse
1615

1716

1817
class LaunchResponseFormatter:
@@ -24,7 +23,7 @@ def __init__(self, model_name: str, params: dict[str, Any]):
2423

2524
def format_table_output(self) -> Table:
2625
"""Format output as rich Table."""
27-
table = utils.create_table(key_title="Job Config", value_title="Value")
26+
table = create_table(key_title="Job Config", value_title="Value")
2827

2928
# Add key information with consistent styling
3029
table.add_row("Slurm Job ID", self.params["slurm_job_id"], style="blue")
@@ -89,7 +88,7 @@ def output_json(self) -> None:
8988

9089
def output_table(self) -> Table:
9190
"""Create and display rich table."""
92-
table = utils.create_table(key_title="Job Status", value_title="Value")
91+
table = create_table(key_title="Job Status", value_title="Value")
9392
table.add_row("Model Name", self.status_info.model_name)
9493
table.add_row("Model Status", self.status_info.server_status, style="blue")
9594

@@ -107,7 +106,7 @@ class MetricsResponseFormatter:
107106

108107
def __init__(self, metrics: Union[dict[str, float], str]):
109108
self.metrics = self._set_metrics(metrics)
110-
self.table = utils.create_table("Metric", "Value")
109+
self.table = create_table("Metric", "Value")
111110
self.enabled_prefix_caching = self._check_prefix_caching()
112111

113112
def _set_metrics(self, metrics: Union[dict[str, float], str]) -> dict[str, float]:
@@ -211,7 +210,7 @@ def _format_single_model_output(
211210
)
212211
return config_dict
213212

214-
table = utils.create_table(key_title="Model Config", value_title="Value")
213+
table = create_table(key_title="Model Config", value_title="Value")
215214
for field, value in config.model_dump().items():
216215
if field not in {"venv", "log_dir"}:
217216
table.add_row(field, str(value))

vec_inf/cli/_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Helper functions for the CLI."""
2+
3+
from rich.table import Table
4+
5+
6+
def create_table(
7+
key_title: str = "", value_title: str = "", show_header: bool = True
8+
) -> Table:
9+
"""Create a table for displaying model status."""
10+
table = Table(show_header=show_header, header_style="bold magenta")
11+
table.add_column(key_title, style="dim")
12+
table.add_column(value_title)
13+
return table

vec_inf/client/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
users direct control over the lifecycle of inference servers via python scripts.
66
"""
77

8+
from vec_inf.client._config import ModelConfig
89
from vec_inf.client._models import (
910
LaunchOptions,
1011
LaunchOptionsDict,
@@ -28,4 +29,5 @@
2829
"ModelType",
2930
"LaunchOptions",
3031
"LaunchOptionsDict",
32+
"ModelConfig",
3133
]

vec_inf/client/_utils.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import requests
1111
import yaml
12-
from rich.table import Table
1312

1413
from vec_inf.client._config import ModelConfig
1514
from vec_inf.client._models import ModelStatus
@@ -118,16 +117,6 @@ def model_health_check(
118117
return (ModelStatus.FAILED, str(e))
119118

120119

121-
def create_table(
122-
key_title: str = "", value_title: str = "", show_header: bool = True
123-
) -> Table:
124-
"""Create a table for displaying model status."""
125-
table = Table(show_header=show_header, header_style="bold magenta")
126-
table.add_column(key_title, style="dim")
127-
table.add_column(value_title)
128-
return table
129-
130-
131120
def load_config() -> list[ModelConfig]:
132121
"""Load the model configuration."""
133122
default_path = (

0 commit comments

Comments
 (0)