Skip to content

Commit 748cb69

Browse files
lesebclaude
andauthored
refactor: remove dead code across the codebase (#5779)
## Summary - Remove 6 unused modules (`cli/utils.py`, `core/utils/image_types.py`, `core/utils/serialize.py`, `providers/utils/pagination.py`, `providers/utils/scheduler.py`) and the scheduler test file - Remove unused classes, functions, and re-exports from 15 files including `configure_api_providers`, `resolve_remote_stack_impls`, `build_hf_repo_model_entry`, `get_shield_registry`, `formulate_run_args`, `run_command`, and others - Net removal of **936 lines** of dead code identified via static analysis ## Test plan - [ ] Pre-commit checks pass (`uv run pre-commit run --all-files`) - [ ] Unit tests pass (`uv run pytest tests/unit/ -x --tb=short`) - [ ] No new import errors — removed symbols had zero callers - [ ] API spec unchanged — no public API surface affected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Sébastien Han <seb@redhat.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2c8f065 commit 748cb69

21 files changed

Lines changed: 5 additions & 936 deletions

File tree

src/ogx/cli/stack/utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from __future__ import annotations
88

99
import argparse
10-
from enum import Enum
1110
from pathlib import Path
1211
from typing import Any
1312

@@ -18,13 +17,6 @@
1817
TEMPLATES_PATH = Path(__file__).parent.parent.parent / "distributions"
1918

2019

21-
class ImageType(Enum):
22-
"""Supported image types for building OGX distributions."""
23-
24-
CONTAINER = "container"
25-
VENV = "venv"
26-
27-
2820
def print_subcommand_description(parser: argparse.ArgumentParser, subparsers: argparse._SubParsersAction[Any]) -> None:
2921
"""Print descriptions of subcommands."""
3022
description_text = ""

src/ogx/cli/utils.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/ogx/core/build.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import sys
88

9-
from pydantic import BaseModel
109
from termcolor import cprint
1110

1211
from ogx.core.datatypes import StackConfig
@@ -30,13 +29,6 @@
3029
]
3130

3231

33-
class ApiInput(BaseModel):
34-
"""Input specification pairing an API with its provider type."""
35-
36-
api: Api
37-
provider: str
38-
39-
4032
def get_provider_dependencies(
4133
config: StackConfig,
4234
) -> tuple[list[str], list[str], list[str]]:

src/ogx/core/configure.py

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@
33
#
44
# This source code is licensed under the terms described in the LICENSE file in
55
# the root directory of this source tree.
6-
import textwrap
76
from typing import Any
87

98
from ogx.core.datatypes import (
109
OGX_RUN_CONFIG_VERSION,
11-
DistributionSpec,
1210
Provider,
1311
StackConfig,
1412
)
15-
from ogx.core.distribution import (
16-
builtin_automatically_routed_apis,
17-
get_provider_registry,
18-
)
1913
from ogx.core.stack import cast_distro_name_to_string, replace_env_vars
2014
from ogx.core.utils.dynamic import instantiate_class_type
2115
from ogx.core.utils.prompt_for_config import prompt_for_config
2216
from ogx.log import get_logger
23-
from ogx_api import Api, ProviderSpec
17+
from ogx_api import ProviderSpec
2418

2519
logger = get_logger(name=__name__, category="core")
2620

@@ -53,89 +47,6 @@ def configure_single_provider(registry: dict[str, ProviderSpec], provider: Provi
5347
)
5448

5549

56-
def configure_api_providers(config: StackConfig, build_spec: DistributionSpec) -> StackConfig:
57-
"""Interactively configure providers for all APIs in the stack configuration.
58-
59-
Args:
60-
config: The current stack configuration to update.
61-
build_spec: The distribution specification defining available providers.
62-
63-
Returns:
64-
The updated StackConfig with user-configured providers.
65-
"""
66-
is_nux = len(config.providers) == 0
67-
68-
if is_nux:
69-
logger.info(
70-
textwrap.dedent(
71-
"""
72-
OGX is composed of several APIs working together. For each API served by the Stack,
73-
we need to configure the providers (implementations) you want to use for these APIs.
74-
"""
75-
)
76-
)
77-
78-
provider_registry = get_provider_registry()
79-
builtin_apis = [a.routing_table_api for a in builtin_automatically_routed_apis()]
80-
81-
if config.apis:
82-
apis_to_serve = config.apis
83-
else:
84-
apis_to_serve = [a.value for a in Api if a not in (Api.inspect, Api.providers, Api.admin)]
85-
86-
for api_str in apis_to_serve:
87-
api = Api(api_str)
88-
if api in builtin_apis:
89-
continue
90-
if api not in provider_registry:
91-
raise ValueError(f"Unknown API `{api_str}`")
92-
93-
existing_providers = config.providers.get(api_str, [])
94-
if existing_providers:
95-
logger.info("Re-configuring existing providers for API", api=api_str)
96-
updated_providers = []
97-
for p in existing_providers:
98-
logger.info("Configuring provider", provider_type=p.provider_type)
99-
updated_providers.append(configure_single_provider(provider_registry[api], p))
100-
logger.info("")
101-
else:
102-
# we are newly configuring this API
103-
plist = build_spec.providers.get(api_str, [])
104-
plist = plist if isinstance(plist, list) else [plist]
105-
106-
if not plist:
107-
raise ValueError(f"No provider configured for API {api_str}?")
108-
109-
logger.info("Configuring API", api=api_str)
110-
updated_providers = []
111-
for i, provider in enumerate(plist):
112-
if i >= 1:
113-
others = ", ".join(p.provider_type for p in plist[i:])
114-
logger.info(
115-
"Not configuring other providers () interactively. Please edit the resulting YAML directly.\n",
116-
others=others,
117-
)
118-
break
119-
120-
logger.info("Configuring provider", provider_type=provider.provider_type)
121-
pid = provider.provider_type.split("::")[-1]
122-
updated_providers.append(
123-
configure_single_provider(
124-
provider_registry[api],
125-
Provider(
126-
provider_id=(f"{pid}-{i:02d}" if len(plist) > 1 else pid),
127-
provider_type=provider.provider_type,
128-
config={},
129-
),
130-
)
131-
)
132-
logger.info("")
133-
134-
config.providers[api_str] = updated_providers
135-
136-
return config
137-
138-
13950
def upgrade_from_routing_table(
14051
config_dict: dict[str, Any],
14152
) -> dict[str, Any]:

src/ogx/core/resolver.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import inspect
1010
from typing import Any
1111

12-
from ogx.core.client import get_client_impl
1312
from ogx.core.datatypes import (
1413
AccessRule,
1514
AutoRoutedProviderSpec,
@@ -41,7 +40,6 @@
4140
ModelsProtocolPrivate,
4241
Prompts,
4342
ProviderSpec,
44-
RemoteProviderConfig,
4543
RemoteProviderSpec,
4644
Responses,
4745
Safety,
@@ -519,38 +517,3 @@ def check_protocol_compliance(obj: Any, protocol: Any) -> None:
519517
raise ValueError(
520518
f"Provider `{obj.__provider_id__} ({obj.__provider_spec__.api})` does not implement the following methods:\n{missing_methods}"
521519
)
522-
523-
524-
async def resolve_remote_stack_impls(
525-
config: RemoteProviderConfig,
526-
apis: list[str],
527-
) -> dict[Api, Any]:
528-
"""Resolve provider implementations for a remote stack by creating API clients.
529-
530-
Args:
531-
config: Remote provider configuration containing the connection URL.
532-
apis: List of API names to resolve.
533-
534-
Returns:
535-
Dictionary mapping APIs to their remote client implementations.
536-
"""
537-
protocols = api_protocol_map()
538-
additional_protocols = additional_protocols_map()
539-
540-
impls = {}
541-
for api_str in apis:
542-
api = Api(api_str)
543-
impls[api] = await get_client_impl(
544-
protocols[api],
545-
config,
546-
{},
547-
)
548-
if api in additional_protocols:
549-
_, additional_protocol, additional_api = additional_protocols[api]
550-
impls[additional_api] = await get_client_impl(
551-
additional_protocol,
552-
config,
553-
{},
554-
)
555-
556-
return impls

src/ogx/core/utils/exec.py

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,6 @@
44
# This source code is licensed under the terms described in the LICENSE file in
55
# the root directory of this source tree.
66

7-
import importlib
8-
import os
9-
import signal
10-
import subprocess
11-
import sys
12-
13-
from termcolor import cprint
14-
15-
from ogx.log import get_logger
16-
17-
log = get_logger(name=__name__, category="core")
18-
19-
20-
def formulate_run_args(image_type: str, distro_name: str) -> list:
21-
"""Build the command-line arguments for starting a OGX server.
22-
23-
Args:
24-
image_type: The image type (e.g., 'venv', 'container').
25-
distro_name: The distribution or virtual environment name.
26-
27-
Returns:
28-
A list of command-line arguments, or an empty list if no environment is detected.
29-
"""
30-
# Only venv is supported now
31-
current_venv = os.environ.get("VIRTUAL_ENV")
32-
env_name = distro_name or current_venv
33-
if not env_name:
34-
cprint(
35-
"No current virtual environment detected, please specify a virtual environment name with --image-name",
36-
color="red",
37-
file=sys.stderr,
38-
)
39-
return []
40-
41-
cprint(f"Using virtual environment: {env_name}", file=sys.stderr)
42-
43-
script = importlib.resources.files("ogx") / "core/start_stack.sh"
44-
run_args = [
45-
script,
46-
image_type,
47-
env_name,
48-
]
49-
50-
return run_args
51-
527

538
def in_notebook():
549
"""Detect whether the current code is running inside a Jupyter notebook.
@@ -67,53 +22,3 @@ def in_notebook():
6722
except AttributeError:
6823
return False
6924
return True
70-
71-
72-
def run_command(command: list[str]) -> int:
73-
"""
74-
Run a command with interrupt handling and output capture.
75-
Uses subprocess.run with direct stream piping for better performance.
76-
77-
Args:
78-
command (list): The command to run.
79-
80-
Returns:
81-
int: The return code of the command.
82-
"""
83-
original_sigint = signal.getsignal(signal.SIGINT)
84-
ctrl_c_pressed = False
85-
86-
def sigint_handler(signum, frame):
87-
nonlocal ctrl_c_pressed
88-
ctrl_c_pressed = True
89-
log.info("\nCtrl-C detected. Aborting...")
90-
91-
try:
92-
# Set up the signal handler
93-
signal.signal(signal.SIGINT, sigint_handler)
94-
95-
# Run the command with stdout/stderr piped directly to system streams
96-
result = subprocess.run(
97-
command,
98-
text=True,
99-
check=False,
100-
)
101-
102-
# Print stdout and stderr if command failed
103-
if result.returncode != 0:
104-
log.error(f"Command {' '.join(command)} failed with returncode {result.returncode}")
105-
if result.stdout:
106-
log.error(f"STDOUT: {result.stdout}")
107-
if result.stderr:
108-
log.error(f"STDERR: {result.stderr}")
109-
110-
return result.returncode
111-
except subprocess.SubprocessError as e:
112-
log.error(f"Subprocess error: {e}")
113-
return 1
114-
except Exception as e:
115-
log.exception(f"Unexpected error: {e}")
116-
return 1
117-
finally:
118-
# Restore the original signal handler
119-
signal.signal(signal.SIGINT, original_sigint)

src/ogx/core/utils/image_types.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/ogx/core/utils/serialize.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)