Python
api update
DeepBeepMeep511318a3f7c8
diff --git a/docs/API.md b/docs/API.mdindex 8b97c00..ea66a96 100644--- a/docs/API.md+++ b/docs/API.md@@ -73,6 +73,7 @@ session = init(callbacks=MyCallbacks(), # optionalcli_args=["--attention", "sdpa"], # optionalconsole_output=True, # optional, default=True+ console_isatty=True, # optional, default=True)```@@ -101,6 +102,11 @@ session = init(- Default: `True`- The stream object always receives a copy of stdout/stderr, regardless of this setting.+- `console_isatty`+ - Controls the TTY capability reported by the API's console capture wrapper.+ - Default: `True`+ - Keep this enabled if you want tqdm or other terminal-style progress output to behave like a live console stream even when WanGP is called from another Python process.+## Accepted Input ShapesRelative attachment paths are normalized to absolute paths when the job is submitted.diff --git a/shared/api.py b/shared/api.pyindex 9bb0bc8..506ae5a 100644--- a/shared/api.py+++ b/shared/api.py@@ -123,15 +123,30 @@ class SessionStream:class _OutputCapture(io.TextIOBase):- def __init__(self, stream_name: str, emit_line, console: io.TextIOBase | None = None) -> None:+ def __init__(+ self,+ stream_name: str,+ emit_line,+ console: io.TextIOBase | None = None,+ *,+ console_isatty: bool = True,+ ) -> None:self._stream_name = stream_nameself._emit_line = emit_lineself._console = console+ self._console_isatty = bool(console_isatty)self._buffer = ""def writable(self) -> bool:return True+ @property+ def encoding(self) -> str:+ return str(getattr(self._console, "encoding", "utf-8"))++ def isatty(self) -> bool:+ return self._console_isatty+def write(self, text: str) -> int:if not text:return 0@@ -225,6 +240,7 @@ class WanGPSession:callbacks: object | None = None,cli_args: Sequence[str] = (),console_output: bool = True,+ console_isatty: bool = True,) -> None:self._root = Path(root or Path(__file__).resolve().parents[1]).resolve()self._config_path = Path(config_path).resolve() if config_path is not None else (self._root / "wgp_config.json").resolve()@@ -232,6 +248,7 @@ class WanGPSession:self._callbacks = callbacksself._cli_args = tuple(str(arg) for arg in cli_args)self._console_output = bool(console_output)+ self._console_isatty = bool(console_isatty)self._state = self._create_headless_state()self._active_job: SessionJob | None = Noneself._job_lock = threading.Lock()@@ -345,11 +362,13 @@ class WanGPSession:"stdout",lambda stream_name, line: self._emit_stream(job, stream_name, line),console=sys.__stdout__ if self._console_output else None,+ console_isatty=self._console_isatty,)stderr_capture = _OutputCapture("stderr",lambda stream_name, line: self._emit_stream(job, stream_name, line),console=sys.__stderr__ if self._console_output else None,+ console_isatty=self._console_isatty,)try:with contextlib.redirect_stdout(stdout_capture), contextlib.redirect_stderr(stderr_capture):