From 216cde5ee88e6fff6aa0bf2b961eb4abcf263959 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Fri, 31 Jan 2025 14:31:13 -0800 Subject: [PATCH] Add --print-deps-only for computing dependencies --- llama_stack/cli/stack/_build.py | 33 ++++++++++++++++++++++----------- llama_stack/cli/stack/build.py | 6 ++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/llama_stack/cli/stack/_build.py b/llama_stack/cli/stack/_build.py index 8fde31779..9d2976dd2 100644 --- a/llama_stack/cli/stack/_build.py +++ b/llama_stack/cli/stack/_build.py @@ -22,7 +22,12 @@ from termcolor import cprint from llama_stack.cli.table import print_table -from llama_stack.distribution.build import build_image, ImageType +from llama_stack.distribution.build import ( + build_image, + get_provider_dependencies, + ImageType, + SERVER_DEPENDENCIES, +) from llama_stack.distribution.datatypes import ( BuildConfig, DistributionSpec, @@ -35,7 +40,6 @@ from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR from llama_stack.distribution.utils.dynamic import instantiate_class_type from llama_stack.providers.datatypes import Api - TEMPLATES_PATH = Path(__file__).parent.parent.parent / "templates" @@ -78,14 +82,7 @@ def run_stack_build_command( color="red", ) return - _run_stack_build_command_from_build_config( - build_config, - image_name=image_name, - template_name=args.template, - ) - return - - if not args.config and not args.template: + elif not args.config and not args.template: name = prompt( "> Enter a name for your Llama Stack (e.g. my-local-stack): ", validator=Validator.from_callable( @@ -180,8 +177,22 @@ def run_stack_build_command( ) return + if args.print_deps_only: + print(f"# Dependencies for {args.template or args.config or image_name}") + normal_deps, special_deps = get_provider_dependencies( + build_config.distribution_spec.providers + ) + normal_deps += SERVER_DEPENDENCIES + print(f"pip install {' '.join(normal_deps)}") + for special_dep in special_deps: + print(f"pip install {special_dep}") + return + _run_stack_build_command_from_build_config( - build_config, image_name=image_name, config_path=args.config + build_config, + image_name=image_name, + config_path=args.config, + template_name=args.template, ) diff --git a/llama_stack/cli/stack/build.py b/llama_stack/cli/stack/build.py index 48c811839..1b673b889 100644 --- a/llama_stack/cli/stack/build.py +++ b/llama_stack/cli/stack/build.py @@ -63,6 +63,12 @@ environment is active, you must specify a name. ), default=None, ) + self.parser.add_argument( + "--print-deps-only", + default=False, + action="store_true", + help="Print the dependencies for the stack only, without building the stack", + ) def _run_stack_build_command(self, args: argparse.Namespace) -> None: # always keep implementation completely silo-ed away from CLI so CLI