Update BuildConfig.external_providers_dir datatype plus fallout.

This commit is contained in:
Michael Anstis 2025-05-19 09:42:01 +01:00
parent e89e1d0cc2
commit 856e27c6df
2 changed files with 15 additions and 6 deletions

View file

@ -12,6 +12,7 @@ import shutil
import sys import sys
import textwrap import textwrap
from functools import lru_cache from functools import lru_cache
from importlib.abc import Traversable
from pathlib import Path from pathlib import Path
import yaml import yaml
@ -250,11 +251,10 @@ def run_stack_build_command(args: argparse.Namespace) -> None:
sys.exit(1) sys.exit(1)
if args.run: if args.run:
run_config = Path(run_config)
config_dict = yaml.safe_load(run_config.read_text()) config_dict = yaml.safe_load(run_config.read_text())
config = parse_and_maybe_upgrade_config(config_dict) config = parse_and_maybe_upgrade_config(config_dict)
if not os.path.exists(str(config.external_providers_dir)): if not os.path.exists(config.external_providers_dir):
os.makedirs(str(config.external_providers_dir), exist_ok=True) os.makedirs(config.external_providers_dir, exist_ok=True)
run_args = formulate_run_args(args.image_type, args.image_name, config, args.template) run_args = formulate_run_args(args.image_type, args.image_name, config, args.template)
run_args.extend([str(os.getenv("LLAMA_STACK_PORT", 8321)), "--config", run_config]) run_args.extend([str(os.getenv("LLAMA_STACK_PORT", 8321)), "--config", run_config])
run_command(run_args) run_command(run_args)
@ -264,7 +264,7 @@ def _generate_run_config(
build_config: BuildConfig, build_config: BuildConfig,
build_dir: Path, build_dir: Path,
image_name: str, image_name: str,
) -> str: ) -> Path:
""" """
Generate a run.yaml template file for user to edit from a build.yaml file Generate a run.yaml template file for user to edit from a build.yaml file
""" """
@ -343,7 +343,7 @@ def _run_stack_build_command_from_build_config(
image_name: str | None = None, image_name: str | None = None,
template_name: str | None = None, template_name: str | None = None,
config_path: str | None = None, config_path: str | None = None,
) -> str: ) -> Path | Traversable:
image_name = image_name or build_config.image_name image_name = image_name or build_config.image_name
if build_config.image_type == LlamaStackImageType.CONTAINER.value: if build_config.image_type == LlamaStackImageType.CONTAINER.value:
if template_name: if template_name:

View file

@ -340,8 +340,17 @@ class BuildConfig(BaseModel):
default=None, default=None,
description="Name of the distribution to build", description="Name of the distribution to build",
) )
external_providers_dir: str | None = Field( external_providers_dir: Path | None = Field(
default=None, default=None,
description="Path to directory containing external provider implementations. The providers packages will be resolved from this directory. " description="Path to directory containing external provider implementations. The providers packages will be resolved from this directory. "
"pip_packages MUST contain the provider package name.", "pip_packages MUST contain the provider package name.",
) )
@field_validator("external_providers_dir")
@classmethod
def validate_external_providers_dir(cls, v):
if v is None:
return None
if isinstance(v, str):
return Path(v)
return v