mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 02:53:30 +00:00
Some checks failed
Integration Auth Tests / test-matrix (oauth2_token) (push) Failing after 3s
Integration Tests / test-matrix (http, providers) (push) Failing after 8s
Integration Tests / test-matrix (http, agents) (push) Failing after 11s
Integration Tests / test-matrix (http, datasets) (push) Failing after 12s
Integration Tests / test-matrix (http, scoring) (push) Failing after 10s
Integration Tests / test-matrix (library, inference) (push) Failing after 8s
Integration Tests / test-matrix (http, post_training) (push) Failing after 12s
Integration Tests / test-matrix (http, inference) (push) Failing after 12s
Integration Tests / test-matrix (library, agents) (push) Failing after 10s
Integration Tests / test-matrix (http, inspect) (push) Failing after 12s
Integration Tests / test-matrix (library, datasets) (push) Failing after 10s
Integration Tests / test-matrix (http, tool_runtime) (push) Failing after 12s
Integration Tests / test-matrix (library, inspect) (push) Failing after 7s
Test Llama Stack Build / generate-matrix (push) Successful in 5s
Test Llama Stack Build / build-single-provider (push) Failing after 6s
Integration Tests / test-matrix (library, post_training) (push) Failing after 9s
Integration Tests / test-matrix (library, scoring) (push) Failing after 8s
Test Llama Stack Build / build-ubi9-container-distribution (push) Failing after 6s
Integration Tests / test-matrix (library, providers) (push) Failing after 10s
Integration Tests / test-matrix (library, tool_runtime) (push) Failing after 9s
Test External Providers / test-external-providers (venv) (push) Failing after 7s
Unit Tests / unit-tests (3.10) (push) Failing after 9s
Update ReadTheDocs / update-readthedocs (push) Failing after 7s
Unit Tests / unit-tests (3.12) (push) Failing after 7s
Unit Tests / unit-tests (3.13) (push) Failing after 8s
Test Llama Stack Build / build (push) Failing after 7s
Unit Tests / unit-tests (3.11) (push) Failing after 8s
Test Llama Stack Build / build-custom-container-distribution (push) Failing after 30s
Pre-commit / pre-commit (push) Successful in 2m1s
# What does this PR do? [Provide a short summary of what this PR does and why. Link to relevant issues if applicable.] Removes the ability to run llama stack container images through the llama stack CLI Closes #2110 ## 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.*] Run: ``` llama stack run /path/to/run.yaml --image-type container ``` Expected outcome: ``` llama stack run: error: argument --image-type: invalid choice: 'container' (choose from 'conda', 'venv') ``` [//]: # (## Documentation)
143 lines
4.4 KiB
Python
143 lines
4.4 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
import logging
|
|
import os
|
|
import signal
|
|
import subprocess
|
|
import sys
|
|
|
|
from termcolor import cprint
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
import importlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from llama_stack.distribution.utils.image_types import LlamaStackImageType
|
|
|
|
|
|
def formulate_run_args(image_type, image_name, config, template_name) -> list:
|
|
env_name = ""
|
|
|
|
if image_type == LlamaStackImageType.CONDA.value:
|
|
current_conda_env = os.environ.get("CONDA_DEFAULT_ENV")
|
|
env_name = image_name or current_conda_env
|
|
if not env_name:
|
|
cprint(
|
|
"No current conda environment detected, please specify a conda environment name with --image-name",
|
|
color="red",
|
|
file=sys.stderr,
|
|
)
|
|
return
|
|
|
|
def get_conda_prefix(env_name):
|
|
# Conda "base" environment does not end with "base" in the
|
|
# prefix, so should be handled separately.
|
|
if env_name == "base":
|
|
return os.environ.get("CONDA_PREFIX")
|
|
# Get conda environments info
|
|
conda_env_info = json.loads(subprocess.check_output(["conda", "info", "--envs", "--json"]).decode())
|
|
envs = conda_env_info["envs"]
|
|
for envpath in envs:
|
|
if os.path.basename(envpath) == env_name:
|
|
return envpath
|
|
return None
|
|
|
|
cprint(f"Using conda environment: {env_name}", color="green", file=sys.stderr)
|
|
conda_prefix = get_conda_prefix(env_name)
|
|
if not conda_prefix:
|
|
cprint(
|
|
f"Conda environment {env_name} does not exist.",
|
|
color="red",
|
|
file=sys.stderr,
|
|
)
|
|
return
|
|
|
|
build_file = Path(conda_prefix) / "llamastack-build.yaml"
|
|
if not build_file.exists():
|
|
cprint(
|
|
f"Build file {build_file} does not exist.\n\nPlease run `llama stack build` or specify the correct conda environment name with --image-name",
|
|
color="red",
|
|
file=sys.stderr,
|
|
)
|
|
return
|
|
else:
|
|
# else must be venv since that is the only valid option left.
|
|
current_venv = os.environ.get("VIRTUAL_ENV")
|
|
env_name = image_name or current_venv
|
|
if not env_name:
|
|
cprint(
|
|
"No current virtual environment detected, please specify a virtual environment name with --image-name",
|
|
color="red",
|
|
file=sys.stderr,
|
|
)
|
|
return
|
|
cprint(f"Using virtual environment: {env_name}", file=sys.stderr)
|
|
|
|
script = importlib.resources.files("llama_stack") / "distribution/start_stack.sh"
|
|
run_args = [
|
|
script,
|
|
image_type,
|
|
env_name,
|
|
]
|
|
|
|
return run_args
|
|
|
|
|
|
def in_notebook():
|
|
try:
|
|
from IPython import get_ipython
|
|
|
|
if "IPKernelApp" not in get_ipython().config: # pragma: no cover
|
|
return False
|
|
except ImportError:
|
|
return False
|
|
except AttributeError:
|
|
return False
|
|
return True
|
|
|
|
|
|
def run_command(command: list[str]) -> int:
|
|
"""
|
|
Run a command with interrupt handling and output capture.
|
|
Uses subprocess.run with direct stream piping for better performance.
|
|
|
|
Args:
|
|
command (list): The command to run.
|
|
|
|
Returns:
|
|
int: The return code of the command.
|
|
"""
|
|
original_sigint = signal.getsignal(signal.SIGINT)
|
|
ctrl_c_pressed = False
|
|
|
|
def sigint_handler(signum, frame):
|
|
nonlocal ctrl_c_pressed
|
|
ctrl_c_pressed = True
|
|
log.info("\nCtrl-C detected. Aborting...")
|
|
|
|
try:
|
|
# Set up the signal handler
|
|
signal.signal(signal.SIGINT, sigint_handler)
|
|
|
|
# Run the command with stdout/stderr piped directly to system streams
|
|
result = subprocess.run(
|
|
command,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
return result.returncode
|
|
except subprocess.SubprocessError as e:
|
|
log.error(f"Subprocess error: {e}")
|
|
return 1
|
|
except Exception as e:
|
|
log.exception(f"Unexpected error: {e}")
|
|
return 1
|
|
finally:
|
|
# Restore the original signal handler
|
|
signal.signal(signal.SIGINT, original_sigint)
|