refactor: combine start scripts for each env (#1139)

# What does this PR do?

now that llama stack supports running in venv, conda, and container
modes and the 3 scripts overlap alot, combine these three into ons
`start_stack.sh` script

## Test Plan

tested this locally on venv, conda, and container

---------

Signed-off-by: Charlie Doern <cdoern@redhat.com>
Co-authored-by: Ashwin Bharambe <ashwin.bharambe@gmail.com>
Co-authored-by: Yuan Tang <terrytangyuan@gmail.com>
This commit is contained in:
Charlie Doern 2025-02-24 19:53:31 -05:00 committed by GitHub
parent 47f8c592b9
commit 4684fd3f8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 173 additions and 192 deletions

View file

@ -24,14 +24,13 @@ from llama_stack.distribution.utils.image_types import ImageType
def formulate_run_args(image_type, image_name, config, template_name) -> list:
env_name = ""
if image_type == ImageType.container.value or config.container_image:
script = importlib.resources.files("llama_stack") / "distribution/start_container.sh"
image_name = f"distribution-{template_name}" if template_name else config.container_image
run_args = [script, image_name]
env_name = f"distribution-{template_name}" if template_name else config.container_image
elif image_type == ImageType.conda.value:
current_conda_env = os.environ.get("CONDA_DEFAULT_ENV")
image_name = image_name or current_conda_env
if not image_name:
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",
@ -51,11 +50,11 @@ def formulate_run_args(image_type, image_name, config, template_name) -> list:
return envpath
return None
print(f"Using conda environment: {image_name}")
conda_prefix = get_conda_prefix(image_name)
print(f"Using conda environment: {env_name}")
conda_prefix = get_conda_prefix(env_name)
if not conda_prefix:
cprint(
f"Conda environment {image_name} does not exist.",
f"Conda environment {env_name} does not exist.",
color="red",
)
return
@ -67,21 +66,25 @@ def formulate_run_args(image_type, image_name, config, template_name) -> list:
color="red",
)
return
script = importlib.resources.files("llama_stack") / "distribution/start_conda_env.sh"
run_args = [
script,
image_name,
]
else:
# else must be venv since that is the only valid option left.
current_venv = os.environ.get("VIRTUAL_ENV")
venv = image_name or current_venv
script = importlib.resources.files("llama_stack") / "distribution/start_venv.sh"
run_args = [
script,
venv,
]
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",
)
return
print(f"Using virtual environment: {env_name}")
script = importlib.resources.files("llama_stack") / "distribution/start_stack.sh"
run_args = [
script,
image_type,
env_name,
]
return run_args