diff --git a/llama_stack/cli/stack/run.py b/llama_stack/cli/stack/run.py index 5a8a14b0a..62a45ada0 100644 --- a/llama_stack/cli/stack/run.py +++ b/llama_stack/cli/stack/run.py @@ -6,7 +6,6 @@ import argparse import os -import sys from pathlib import Path from llama_stack.cli.subcommand import Subcommand @@ -71,7 +70,7 @@ class StackRun(Subcommand): BUILDS_BASE_DIR, DISTRIBS_BASE_DIR, ) - from llama_stack.distribution.utils.exec import run_with_pty, run_with_win + from llama_stack.distribution.utils.exec import run_with_pty if not args.config: self.parser.error("Must specify a config file to run") @@ -199,4 +198,4 @@ class StackRun(Subcommand): return run_args.extend(["--env", f"{key}={value}"]) - run_with_win(args) if sys.platform.startswith("win") else run_with_pty(args) + run_with_pty(run_args) diff --git a/llama_stack/distribution/build.py b/llama_stack/distribution/build.py index 1600f54cb..a29c8d5d1 100644 --- a/llama_stack/distribution/build.py +++ b/llama_stack/distribution/build.py @@ -21,7 +21,7 @@ from llama_stack.distribution.distribution import get_provider_registry from llama_stack.distribution.utils.config_dirs import BUILDS_BASE_DIR -from llama_stack.distribution.utils.exec import run_command, run_with_pty, run_with_win +from llama_stack.distribution.utils.exec import run_command, run_with_pty from llama_stack.providers.datatypes import Api log = logging.getLogger(__name__) @@ -157,9 +157,7 @@ def build_image( is_terminal = sys.stdin.isatty() if is_terminal: - return_code = ( - run_with_win(args) if sys.platform.startswith("win") else run_with_pty(args) - ) + return_code = run_with_pty(args) else: return_code = run_command(args) diff --git a/llama_stack/distribution/utils/exec.py b/llama_stack/distribution/utils/exec.py index 65cdfeea4..63af35f84 100644 --- a/llama_stack/distribution/utils/exec.py +++ b/llama_stack/distribution/utils/exec.py @@ -15,9 +15,16 @@ import sys log = logging.getLogger(__name__) +def run_with_pty(command): + if sys.platform.startswith("win"): + return _run_with_pty_win(command) + else: + return _run_with_pty_unix(command) + + # run a command in a pseudo-terminal, with interrupt handling, # useful when you want to run interactive things -def run_with_pty(command): +def _run_with_pty_unix(command): import pty import termios @@ -99,9 +106,8 @@ def run_with_pty(command): # run a command in a pseudo-terminal in windows, with interrupt handling, -def run_with_win(command): +def _run_with_pty_win(command): """ - Alternative to run_with_pty for Windows platforms. Runs a command with interactive support using subprocess directly. """ try: