aboutsummaryrefslogtreecommitdiff
path: root/app/backends/common.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-09-02 01:26:09 -0400
committerhistoria <historiavg@proton.me>2026-09-02 01:26:09 -0400
commit8579517a35ef1865fc9b428899d73d52dcb27a14 (patch)
treedba52f8d99cfe4014e0b787367de99f238e5a0db /app/backends/common.py
parent391f50da7a085bec75155c0eb9b47910266058cc (diff)
downloadtts-audiobook-generator-8579517a35ef1865fc9b428899d73d52dcb27a14.tar.gz
feat: sglang backend support
Diffstat (limited to 'app/backends/common.py')
-rw-r--r--app/backends/common.py38
1 files changed, 25 insertions, 13 deletions
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,