From 8579517a35ef1865fc9b428899d73d52dcb27a14 Mon Sep 17 00:00:00 2001 From: historia Date: Wed, 2 Sep 2026 01:26:09 -0400 Subject: feat: sglang backend support --- app/backends/common.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'app/backends/common.py') diff --git a/app/backends/common.py b/app/backends/common.py index 24746b6..811f13a 100644 --- a/app/backends/common.py +++ b/app/backends/common.py @@ -371,7 +371,8 @@ def write_prompt_text(wav_dir: Path, def run_console_subprocess(argv: List[str], cwd: Optional[Path] = None, *, emit=None, cancel=None, on_cancel=None, - stall_timeout: Optional[float] = None) -> int: + stall_timeout: Optional[float] = None, + env: Optional[Dict[str, str]] = None) -> int: """Run a subprocess, streaming output to the console or to EMIT. With EMIT None the child inherits the real terminal and its output @@ -393,13 +394,17 @@ def run_console_subprocess(argv: List[str], cwd: Optional[Path] = None, returned so callers can report a stall distinctly from a plain failure. None (the default) waits forever, as before. + ENV, when given, replaces the child's environment wholesale (e.g. + provisioning helpers pointing uv at a project-local interpreter + install dir); None inherits the parent's. + Returns the process exit code. """ import subprocess if emit is None: try: - result = subprocess.run(argv, - cwd=str(cwd) if cwd is not None else None) + result = subprocess.run( + argv, cwd=str(cwd) if cwd is not None else None, env=env) except OSError as exc: print(f"[ERROR] Could not run {' '.join(argv)}: {exc}") return 1 @@ -408,6 +413,8 @@ def run_console_subprocess(argv: List[str], cwd: Optional[Path] = None, popen_kwargs = {"stdout": subprocess.PIPE, "stderr": subprocess.STDOUT} if cwd is not None: popen_kwargs["cwd"] = str(cwd) + if env is not None: + popen_kwargs["env"] = env if sys.platform == "win32": popen_kwargs["creationflags"] = \ subprocess.CREATE_NEW_PROCESS_GROUP # type: ignore[attr-defined] @@ -673,23 +680,28 @@ def run_console_subprocess_quiet(argv: List[str], def pip_install(packages: List[str], *, emit=None, cancel=None, env_dir: Optional[Path] = None, - upgrade: bool = False) -> int: + upgrade: bool = False, + extra_args: Optional[List[str]] = None, + interpreter: Optional[Path] = None) -> int: """pip install PACKAGES into a managed venv. Returns exit code. Delegates to ``backends.envs.pip_install`` so backend TTS packages are installed into their dedicated tool-managed environments (``envs/tts`` - default; ``envs/qwen`` / ``envs/faster`` via ENV_DIR) rather than into - whatever interpreter happens to be running the wizard — and never two - conflicting stacks into the same env. With UPGRADE pip runs with - ``-U`` (the backend update action's freshness check: pip only installs - when a newer version resolves, else reports "already satisfied"). - With EMIT given (the in-TUI task view) pip runs with its output streamed - into EMIT; CANCEL aborts it. The import is local to avoid a circular - import (envs imports this module). + default; ``envs/qwen`` / ``envs/faster`` / ``envs/sglomni`` via ENV_DIR) + rather than into whatever interpreter happens to be running the wizard + — and never two conflicting stacks into the same env. With UPGRADE pip + runs with ``-U`` (the backend update action's freshness check: pip only + installs when a newer version resolves, else reports "Requirement + already satisfied"). EXTRA_ARGS pass through to pip verbatim (e.g. + ``--pre``, ``--no-deps``); INTERPRETER builds a missing env from that + Python. With EMIT given (the in-TUI task view) pip runs with its output + streamed into EMIT; CANCEL aborts it. The import is local to avoid a + circular import (envs imports this module). """ from backends import envs return envs.pip_install(packages, emit=emit, cancel=cancel, - env_dir=env_dir, upgrade=upgrade) + env_dir=env_dir, upgrade=upgrade, + extra_args=extra_args, interpreter=interpreter) def pip_uninstall(packages: List[str], *, emit=None, -- cgit v1.2.3