forked from phoenix-oss/llama-stack-mirror
refactor: ImageType
to LlamaStackImageType
(#1500)
This disambiguates "Image" term from "container image" alternative usage and allows for: ```python if image_type == LlamaStackImagetype.venv: ... ``` accesses rather than `ImageType.venv.value` # What does this PR do? [Provide a short summary of what this PR does and why. Link to relevant issues if applicable.] Changes enum use to comply with semantic python styling and naming conventions. ## Test Plan [Describe the tests you ran to verify your changes with result summaries. *Provide clear instructions so the plan can be easily re-executed.*] Refactor was automated and small so simple run-through of creating images was done. Signed-off-by: James Kunstle <jkunstle@redhat.com>
This commit is contained in:
parent
6dbac3beed
commit
735892cbd2
4 changed files with 18 additions and 18 deletions
|
@ -39,7 +39,7 @@ from llama_stack.distribution.resolver import InvalidProviderError
|
||||||
from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR
|
from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR
|
||||||
from llama_stack.distribution.utils.dynamic import instantiate_class_type
|
from llama_stack.distribution.utils.dynamic import instantiate_class_type
|
||||||
from llama_stack.distribution.utils.exec import formulate_run_args, run_with_pty
|
from llama_stack.distribution.utils.exec import formulate_run_args, run_with_pty
|
||||||
from llama_stack.distribution.utils.image_types import ImageType
|
from llama_stack.distribution.utils.image_types import LlamaStackImageType
|
||||||
from llama_stack.providers.datatypes import Api
|
from llama_stack.providers.datatypes import Api
|
||||||
|
|
||||||
TEMPLATES_PATH = Path(__file__).parent.parent.parent / "templates"
|
TEMPLATES_PATH = Path(__file__).parent.parent.parent / "templates"
|
||||||
|
@ -170,7 +170,7 @@ def run_stack_build_command(args: argparse.Namespace) -> None:
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if build_config.image_type == ImageType.container.value and not args.image_name:
|
if build_config.image_type == LlamaStackImageType.CONTAINER.value and not args.image_name:
|
||||||
cprint(
|
cprint(
|
||||||
"Please specify --image-name when building a container from a config file",
|
"Please specify --image-name when building a container from a config file",
|
||||||
color="red",
|
color="red",
|
||||||
|
@ -226,7 +226,7 @@ def _generate_run_config(
|
||||||
"""
|
"""
|
||||||
apis = list(build_config.distribution_spec.providers.keys())
|
apis = list(build_config.distribution_spec.providers.keys())
|
||||||
run_config = StackRunConfig(
|
run_config = StackRunConfig(
|
||||||
container_image=(image_name if build_config.image_type == ImageType.container.value else None),
|
container_image=(image_name if build_config.image_type == LlamaStackImageType.CONTAINER.value else None),
|
||||||
image_name=image_name,
|
image_name=image_name,
|
||||||
apis=apis,
|
apis=apis,
|
||||||
providers={},
|
providers={},
|
||||||
|
@ -279,16 +279,16 @@ def _run_stack_build_command_from_build_config(
|
||||||
template_name: Optional[str] = None,
|
template_name: Optional[str] = None,
|
||||||
config_path: Optional[str] = None,
|
config_path: Optional[str] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
if build_config.image_type == ImageType.container.value:
|
if build_config.image_type == LlamaStackImageType.CONTAINER.value:
|
||||||
if template_name:
|
if template_name:
|
||||||
image_name = f"distribution-{template_name}"
|
image_name = f"distribution-{template_name}"
|
||||||
else:
|
else:
|
||||||
if not image_name:
|
if not image_name:
|
||||||
raise ValueError("Please specify an image name when building a container image without a template")
|
raise ValueError("Please specify an image name when building a container image without a template")
|
||||||
elif build_config.image_type == ImageType.conda.value:
|
elif build_config.image_type == LlamaStackImageType.CONDA.value:
|
||||||
if not image_name:
|
if not image_name:
|
||||||
raise ValueError("Please specify an image name when building a conda image")
|
raise ValueError("Please specify an image name when building a conda image")
|
||||||
elif build_config.image_type == ImageType.venv.value:
|
elif build_config.image_type == LlamaStackImageType.VENV.value:
|
||||||
if not image_name and os.environ.get("UV_SYSTEM_PYTHON"):
|
if not image_name and os.environ.get("UV_SYSTEM_PYTHON"):
|
||||||
image_name = "__system__"
|
image_name = "__system__"
|
||||||
if not image_name:
|
if not image_name:
|
||||||
|
|
|
@ -16,7 +16,7 @@ from termcolor import cprint
|
||||||
from llama_stack.distribution.datatypes import BuildConfig, Provider
|
from llama_stack.distribution.datatypes import BuildConfig, Provider
|
||||||
from llama_stack.distribution.distribution import get_provider_registry
|
from llama_stack.distribution.distribution import get_provider_registry
|
||||||
from llama_stack.distribution.utils.exec import run_command, run_with_pty
|
from llama_stack.distribution.utils.exec import run_command, run_with_pty
|
||||||
from llama_stack.distribution.utils.image_types import ImageType
|
from llama_stack.distribution.utils.image_types import LlamaStackImageType
|
||||||
from llama_stack.providers.datatypes import Api
|
from llama_stack.providers.datatypes import Api
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -95,7 +95,7 @@ def build_image(
|
||||||
normal_deps, special_deps = get_provider_dependencies(build_config.distribution_spec.providers)
|
normal_deps, special_deps = get_provider_dependencies(build_config.distribution_spec.providers)
|
||||||
normal_deps += SERVER_DEPENDENCIES
|
normal_deps += SERVER_DEPENDENCIES
|
||||||
|
|
||||||
if build_config.image_type == ImageType.container.value:
|
if build_config.image_type == LlamaStackImageType.CONTAINER.value:
|
||||||
script = str(importlib.resources.files("llama_stack") / "distribution/build_container.sh")
|
script = str(importlib.resources.files("llama_stack") / "distribution/build_container.sh")
|
||||||
args = [
|
args = [
|
||||||
script,
|
script,
|
||||||
|
@ -104,7 +104,7 @@ def build_image(
|
||||||
container_base,
|
container_base,
|
||||||
" ".join(normal_deps),
|
" ".join(normal_deps),
|
||||||
]
|
]
|
||||||
elif build_config.image_type == ImageType.conda.value:
|
elif build_config.image_type == LlamaStackImageType.CONDA.value:
|
||||||
script = str(importlib.resources.files("llama_stack") / "distribution/build_conda_env.sh")
|
script = str(importlib.resources.files("llama_stack") / "distribution/build_conda_env.sh")
|
||||||
args = [
|
args = [
|
||||||
script,
|
script,
|
||||||
|
@ -112,7 +112,7 @@ def build_image(
|
||||||
str(build_file_path),
|
str(build_file_path),
|
||||||
" ".join(normal_deps),
|
" ".join(normal_deps),
|
||||||
]
|
]
|
||||||
elif build_config.image_type == ImageType.venv.value:
|
elif build_config.image_type == LlamaStackImageType.VENV.value:
|
||||||
script = str(importlib.resources.files("llama_stack") / "distribution/build_venv.sh")
|
script = str(importlib.resources.files("llama_stack") / "distribution/build_venv.sh")
|
||||||
args = [
|
args = [
|
||||||
script,
|
script,
|
||||||
|
|
|
@ -20,14 +20,14 @@ import importlib
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from llama_stack.distribution.utils.image_types import ImageType
|
from llama_stack.distribution.utils.image_types import LlamaStackImageType
|
||||||
|
|
||||||
|
|
||||||
def formulate_run_args(image_type, image_name, config, template_name) -> list:
|
def formulate_run_args(image_type, image_name, config, template_name) -> list:
|
||||||
env_name = ""
|
env_name = ""
|
||||||
if image_type == ImageType.container.value or config.container_image:
|
if image_type == LlamaStackImageType.CONTAINER.value or config.container_image:
|
||||||
env_name = f"distribution-{template_name}" if template_name else config.container_image
|
env_name = f"distribution-{template_name}" if template_name else config.container_image
|
||||||
elif image_type == ImageType.conda.value:
|
elif image_type == LlamaStackImageType.CONDA.value:
|
||||||
current_conda_env = os.environ.get("CONDA_DEFAULT_ENV")
|
current_conda_env = os.environ.get("CONDA_DEFAULT_ENV")
|
||||||
env_name = image_name or current_conda_env
|
env_name = image_name or current_conda_env
|
||||||
if not env_name:
|
if not env_name:
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
# This source code is licensed under the terms described in the LICENSE file in
|
# This source code is licensed under the terms described in the LICENSE file in
|
||||||
# the root directory of this source tree.
|
# the root directory of this source tree.
|
||||||
|
|
||||||
from enum import Enum
|
import enum
|
||||||
|
|
||||||
|
|
||||||
class ImageType(Enum):
|
class LlamaStackImageType(enum.Enum):
|
||||||
container = "container"
|
CONTAINER = "container"
|
||||||
conda = "conda"
|
CONDA = "conda"
|
||||||
venv = "venv"
|
VENV = "venv"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue