fix: fixup config_resolution.py

fix some config resolution logic that still had "Modes" (build or run) and was using run.yaml

Signed-off-by: Charlie Doern <cdoern@redhat.com>
This commit is contained in:
Charlie Doern 2025-12-01 11:10:05 -05:00
parent 0424afb7ed
commit 7a57957f13
5 changed files with 22 additions and 30 deletions

View file

@ -1,6 +1,6 @@
name: Backward Compatibility Check
run-name: Check backward compatibility for config.yaml configs
run-name: Check backward compatibility for config.yaml files
on:
pull_request:

View file

@ -64,9 +64,9 @@ def format_output_deps_only(
def run_stack_list_deps_command(args: argparse.Namespace) -> None:
if args.config:
try:
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
config_file = resolve_config_or_distro(args.config, Mode.RUN)
config_file = resolve_config_or_distro(args.config)
except ValueError as e:
cprint(
f"Could not parse config file {args.config}: {e}",

View file

@ -30,7 +30,7 @@ from llama_stack.core.storage.datatypes import (
StorageConfig,
)
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
from llama_stack.core.utils.dynamic import instantiate_class_type
from llama_stack.log import LoggingConfig, get_logger
@ -108,9 +108,9 @@ class StackRun(Subcommand):
if args.config:
try:
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
config_file = resolve_config_or_distro(args.config, Mode.RUN)
config_file = resolve_config_or_distro(args.config)
except ValueError as e:
self.parser.error(str(e))
elif args.providers:
@ -187,7 +187,7 @@ class StackRun(Subcommand):
if not config_file:
self.parser.error("Config file is required")
config_file = resolve_config_or_distro(str(config_file), Mode.RUN)
config_file = resolve_config_or_distro(str(config_file))
with open(config_file) as fp:
config_contents = yaml.safe_load(fp)
if isinstance(config_contents, dict) and (cfg := config_contents.get("logging_config")):

View file

@ -53,7 +53,7 @@ from llama_stack.core.stack import (
from llama_stack.core.telemetry import Telemetry
from llama_stack.core.telemetry.tracing import CURRENT_TRACE_CONTEXT, setup_logger
from llama_stack.core.utils.config import redact_sensitive_fields
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
from llama_stack.core.utils.context import preserve_contexts_async_generator
from llama_stack.log import LoggingConfig, get_logger, setup_logging
from llama_stack_api import Api, ConflictError, PaginatedResponse, ResourceNotFoundError
@ -374,7 +374,7 @@ def create_app() -> StackApp:
if config_file is None:
raise ValueError("LLAMA_STACK_CONFIG environment variable is required")
config_file = resolve_config_or_distro(config_file, Mode.RUN)
config_file = resolve_config_or_distro(config_file)
# Load and process configuration
logger_config = None

View file

@ -4,7 +4,6 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
from enum import StrEnum
from pathlib import Path
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
@ -16,21 +15,14 @@ logger = get_logger(name=__name__, category="core")
DISTRO_DIR = Path(__file__).parent.parent.parent.parent / "llama_stack" / "distributions"
class Mode(StrEnum):
RUN = "run"
BUILD = "build"
def resolve_config_or_distro(
config_or_distro: str,
mode: Mode = Mode.RUN,
) -> Path:
"""
Resolve a config/distro argument to a concrete config file path.
Args:
config_or_distro: User input (file path, distribution name, or built distribution)
mode: Mode resolving for ("run", "build", "server")
Returns:
Path to the resolved config file
@ -47,7 +39,7 @@ def resolve_config_or_distro(
# Strategy 2: Try as distribution name (if no .yaml extension)
if not config_or_distro.endswith(".yaml"):
distro_config = _get_distro_config_path(config_or_distro, mode)
distro_config = _get_distro_config_path(config_or_distro)
if distro_config.exists():
logger.debug(f"Using distribution: {distro_config}")
return distro_config
@ -63,34 +55,34 @@ def resolve_config_or_distro(
return distro_config
# Strategy 4: Try as built distribution name
distrib_config = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
distrib_config = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-config.yaml"
if distrib_config.exists():
logger.debug(f"Using built distribution: {distrib_config}")
return distrib_config
distrib_config = DISTRIBS_BASE_DIR / f"{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
distrib_config = DISTRIBS_BASE_DIR / f"{config_or_distro}" / "config.yaml"
if distrib_config.exists():
logger.debug(f"Using built distribution: {distrib_config}")
return distrib_config
# Strategy 5: Failed - provide helpful error
raise ValueError(_format_resolution_error(config_or_distro, mode))
raise ValueError(_format_resolution_error(config_or_distro))
def _get_distro_config_path(distro_name: str, mode: str) -> Path:
def _get_distro_config_path(distro_name: str, path: str | None = None) -> Path:
"""Get the config file path for a distro."""
if not mode.endswith(".yaml"):
mode = f"{mode}.yaml"
return DISTRO_DIR / distro_name / mode
if not path or not path.endswith(".yaml"):
path = "config.yaml"
return DISTRO_DIR / distro_name / path
def _format_resolution_error(config_or_distro: str, mode: Mode) -> str:
def _format_resolution_error(config_or_distro: str) -> str:
"""Format a helpful error message for resolution failures."""
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
distro_path = _get_distro_config_path(config_or_distro, mode)
distrib_path = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
distrib_path2 = DISTRIBS_BASE_DIR / f"{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
distro_path = _get_distro_config_path(config_or_distro)
distrib_path = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-config.yaml"
distrib_path2 = DISTRIBS_BASE_DIR / f"{config_or_distro}" / f"{config_or_distro}-config.yaml"
available_distros = _get_available_distros()
distros_str = ", ".join(available_distros) if available_distros else "none found"
@ -111,7 +103,7 @@ Did you mean one of these distributions?
def _get_available_distros() -> list[str]:
"""Get list of available distro names."""
if not DISTRO_DIR.exists() and not DISTRIBS_BASE_DIR.exists():
if not DISTRO_DIR.exists() or not DISTRIBS_BASE_DIR.exists():
return []
return list(