From 1806de366fbed62564445ecc0e9126347594a518 Mon Sep 17 00:00:00 2001 From: reidliu Date: Thu, 6 Mar 2025 07:20:33 +0800 Subject: [PATCH] feat: add list built stacks Signed-off-by: reidliu --- llama_stack/cli/stack/list.py | 50 ++++++++++++++++++++++++++++++++++ llama_stack/cli/stack/stack.py | 2 ++ 2 files changed, 52 insertions(+) create mode 100644 llama_stack/cli/stack/list.py diff --git a/llama_stack/cli/stack/list.py b/llama_stack/cli/stack/list.py new file mode 100644 index 000000000..f88c14d0c --- /dev/null +++ b/llama_stack/cli/stack/list.py @@ -0,0 +1,50 @@ +# 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 argparse +import os +import time + +from llama_stack.cli.subcommand import Subcommand +from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR + + +class StackList(Subcommand): + def __init__(self, subparsers: argparse._SubParsersAction): + super().__init__() + self.parser = subparsers.add_parser( + "list", + prog="llama stack list", + description="List the built stacks", + formatter_class=argparse.RawTextHelpFormatter, + ) + self._add_arguments() + self.parser.set_defaults(func=self._run_stack_list_cmd) + + def _add_arguments(self): + pass + + def _run_stack_list_cmd(self, args: argparse.Namespace) -> None: + from llama_stack.cli.table import print_table + + headers = ["Stack(s)", "Modified Time"] + + rows = [] + for stack in os.listdir(DISTRIBS_BASE_DIR): + abs_path = os.path.join(DISTRIBS_BASE_DIR, stack) + modified_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(os.path.getmtime(abs_path))) + rows.append( + [ + stack, + modified_time, + ] + ) + + print_table( + rows, + headers, + separate_rows=True, + ) diff --git a/llama_stack/cli/stack/stack.py b/llama_stack/cli/stack/stack.py index ccf1a5ffc..3b812dad0 100644 --- a/llama_stack/cli/stack/stack.py +++ b/llama_stack/cli/stack/stack.py @@ -11,6 +11,7 @@ from llama_stack.cli.stack.utils import print_subcommand_description from llama_stack.cli.subcommand import Subcommand from .build import StackBuild +from .list import StackList from .list_apis import StackListApis from .list_providers import StackListProviders from .run import StackRun @@ -38,6 +39,7 @@ class StackParser(Subcommand): # Add sub-commands StackBuild.create(subparsers) + StackList.create(subparsers) StackListApis.create(subparsers) StackListProviders.create(subparsers) StackRun.create(subparsers)