Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

[pre-commit.ci] auto fixes from pre-commit.com hooks

pre-commit-ci[bot]f693b6a09657
diff --git a/studio/backend/auth/terminal_prompt.py b/studio/backend/auth/terminal_prompt.py
index 9700bf07530..a3358517bab 100644
--- a/studio/backend/auth/terminal_prompt.py
+++ b/studio/backend/auth/terminal_prompt.py
@@ -186,7 +186,10 @@ def _wait_for_first_key(timeout: float) -> bool:
def _read_password(
- prompt: str, *, out: "TextIO | None" = None, first_key_timeout: "float | None" = None
+ prompt: str,
+ *,
+ out: "TextIO | None" = None,
+ first_key_timeout: "float | None" = None,
) -> str:
"""Read one masked line: echo ``*`` per char, support backspace editing.
@@ -332,8 +335,7 @@ def prompt_for_password_change(
return True
except PromptUnattended:
out.write(
- "No response at the terminal; leaving the auto-generated admin "
- "password in place.\n"
+ "No response at the terminal; leaving the auto-generated admin password in place.\n"
)
out.flush()
return False
diff --git a/studio/backend/run.py b/studio/backend/run.py
index 09fce7ab92c..cdf1472b400 100644
--- a/studio/backend/run.py
+++ b/studio/backend/run.py
@@ -2224,9 +2224,7 @@ def _terminal_password_gate(
# read-only or locked home a new place to fail, none of which a container
# operator asked for. Tunnel launches are unaffected: they always came here.
if not tunnel_will_start and not (
- _stream_isatty(sys.stdin)
- and _stream_isatty(sys.stderr)
- and _prompt_owns_the_terminal()
+ _stream_isatty(sys.stdin) and _stream_isatty(sys.stderr) and _prompt_owns_the_terminal()
):
return True, False
diff --git a/studio/backend/tests/test_password_prompt_backstop.py b/studio/backend/tests/test_password_prompt_backstop.py
index d01f1122086..484d839362e 100644
--- a/studio/backend/tests/test_password_prompt_backstop.py
+++ b/studio/backend/tests/test_password_prompt_backstop.py
@@ -603,9 +603,7 @@ def test_a_backgrounded_raw_bind_does_not_prompt(monkeypatch):
monkeypatch.setattr(auth_storage, "ensure_default_admin", _boom)
- assert run._terminal_password_gate(
- tunnel_will_start = False, **_RAW_BIND_KWARGS
- ) == (True, False)
+ assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, False)
def test_a_backgrounded_tunnel_launch_still_fails_closed(monkeypatch):
@@ -615,16 +613,12 @@ def test_a_backgrounded_tunnel_launch_still_fails_closed(monkeypatch):
monkeypatch.setattr(run.os, "tcgetpgrp", lambda _fd: 4242)
monkeypatch.setattr(run.os, "getpgrp", lambda: 99)
_patch_seeded_admin(monkeypatch, requires_change = True)
- monkeypatch.setattr(
- terminal_prompt, "prompt_for_password_change", lambda **_kw: False
- )
+ monkeypatch.setattr(terminal_prompt, "prompt_for_password_change", lambda **_kw: False)
# The process group check is scoped to the raw-bind branch, so a tunnel
# launch still reaches the prompt and still aborts when it is refused.
assert run._prompt_owns_the_terminal() is False
- assert run._terminal_password_gate(
- tunnel_will_start = True, **_GATE_KWARGS
- ) == (False, False)
+ assert run._terminal_password_gate(tunnel_will_start = True, **_GATE_KWARGS) == (False, False)
def test_a_foreground_raw_bind_still_reaches_the_prompt(monkeypatch):
@@ -634,18 +628,15 @@ def test_a_foreground_raw_bind_still_reaches_the_prompt(monkeypatch):
monkeypatch.setattr(run.os, "tcgetpgrp", lambda _fd: 4242)
monkeypatch.setattr(run.os, "getpgrp", lambda: 4242)
_patch_seeded_admin(monkeypatch, requires_change = True)
- monkeypatch.setattr(
- terminal_prompt, "prompt_for_password_change", lambda **_kw: True
- )
+ monkeypatch.setattr(terminal_prompt, "prompt_for_password_change", lambda **_kw: True)
- assert run._terminal_password_gate(
- tunnel_will_start = False, **_RAW_BIND_KWARGS
- ) == (True, True)
+ assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, True)
def test_no_job_control_falls_back_to_the_isatty_answer(monkeypatch):
"""Windows / no controlling terminal: nothing can stop us, so still prompt."""
for exc in (OSError("ENOTTY"), AttributeError(), ValueError()):
+
def _boom(_fd, _exc = exc):
raise _exc
@@ -770,12 +761,10 @@ def test_a_refusal_does_not_promise_a_deadline_that_is_disabled(monkeypatch):
_patch_seeded_admin(monkeypatch, requires_change = True)
from auth import terminal_prompt
- monkeypatch.setattr(terminal_prompt, "prompt_for_password_change",
- lambda **_kw: False)
- assert run._terminal_password_gate(
- tunnel_will_start = False, **_RAW_BIND_KWARGS
- ) == (True, False)
+ monkeypatch.setattr(terminal_prompt, "prompt_for_password_change", lambda **_kw: False)
+
+ assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, False)
err = stderr.getvalue()
assert "DISABLED for this launch" in err, err
assert "shuts down after the bootstrap deadline" not in err, err
@@ -787,12 +776,10 @@ def test_a_refusal_still_names_the_deadline_when_one_will_arm(monkeypatch):
_patch_seeded_admin(monkeypatch, requires_change = True)
from auth import terminal_prompt
- monkeypatch.setattr(terminal_prompt, "prompt_for_password_change",
- lambda **_kw: False)
- assert run._terminal_password_gate(
- tunnel_will_start = False, **_RAW_BIND_KWARGS
- ) == (True, False)
+ monkeypatch.setattr(terminal_prompt, "prompt_for_password_change", lambda **_kw: False)
+
+ assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, False)
err = stderr.getvalue()
assert "shuts down after the bootstrap deadline" in err, err
assert "DISABLED" not in err, err
diff --git a/unsloth_cli/commands/_password_prompt.py b/unsloth_cli/commands/_password_prompt.py
index e7d6c28d702..69dd9c7c0a5 100644
--- a/unsloth_cli/commands/_password_prompt.py
+++ b/unsloth_cli/commands/_password_prompt.py
@@ -110,7 +110,11 @@ class _RestoreTtyOnSignals:
pass
-def _read_masked_posix(prompt: str, out: TextIO, first_key_timeout: "float | None" = None) -> str:
+def _read_masked_posix(
+ prompt: str,
+ out: TextIO,
+ first_key_timeout: "float | None" = None,
+) -> str:
import codecs
import termios
import tty
@@ -169,7 +173,11 @@ def _read_masked_posix(prompt: str, out: TextIO, first_key_timeout: "float | Non
return "".join(chars)
-def _read_masked_windows(prompt: str, out: TextIO, first_key_timeout: "float | None" = None) -> str:
+def _read_masked_windows(
+ prompt: str,
+ out: TextIO,
+ first_key_timeout: "float | None" = None,
+) -> str:
import msvcrt
out.write(prompt)
@@ -209,7 +217,10 @@ def _read_masked_windows(prompt: str, out: TextIO, first_key_timeout: "float | N
def read_masked(
- prompt: str, out: TextIO | None = None, *, first_key_timeout: "float | None" = None
+ prompt: str,
+ out: TextIO | None = None,
+ *,
+ first_key_timeout: "float | None" = None,
) -> str:
"""Read one line with ``*`` echo. Raises KeyboardInterrupt on Ctrl-C and
EOFError on Ctrl-D/Ctrl-Z at an empty prompt, and PromptUnattended when
diff --git a/unsloth_cli/tests/test_studio_password_prompt.py b/unsloth_cli/tests/test_studio_password_prompt.py
index f42e885a1b6..228cafceca9 100644
--- a/unsloth_cli/tests/test_studio_password_prompt.py
+++ b/unsloth_cli/tests/test_studio_password_prompt.py
@@ -204,7 +204,11 @@ def _install_prompt_env(
# dedicated test that overrides this.
monkeypatch.setattr(studio_mod, "_tunnel_binary_confirmed_unavailable", lambda: False)
- def fake_prompt(verify_current, out = None, **_kw):
+ def fake_prompt(
+ verify_current,
+ out = None,
+ **_kw,
+ ):
events.append(("prompt", verify_current))
if isinstance(scripted, BaseException):
raise scripted
@@ -1854,14 +1858,20 @@ def test_a_backgrounded_raw_bind_does_not_prompt(monkeypatch):
monkeypatch.setattr(studio.os, "getpgrp", lambda: 99)
monkeypatch.setattr(studio.sys, "stdin", _FdStream())
- assert studio._should_prompt_password_change(
- cloudflare = None, host = "0.0.0.0", secure = False, api_only = False
- ) is False
+ assert (
+ studio._should_prompt_password_change(
+ cloudflare = None, host = "0.0.0.0", secure = False, api_only = False
+ )
+ is False
+ )
# The tunnel is published on the public internet either way: it must keep
# failing closed rather than quietly proceeding.
- assert studio._should_prompt_password_change(
- cloudflare = None, host = "0.0.0.0", secure = True, api_only = False
- ) is True
+ assert (
+ studio._should_prompt_password_change(
+ cloudflare = None, host = "0.0.0.0", secure = True, api_only = False
+ )
+ is True
+ )
def test_a_foreground_raw_bind_still_prompts(monkeypatch):
@@ -1872,9 +1882,12 @@ def test_a_foreground_raw_bind_still_prompts(monkeypatch):
monkeypatch.setattr(studio.os, "getpgrp", lambda: 4242)
monkeypatch.setattr(studio.sys, "stdin", _FdStream())
- assert studio._should_prompt_password_change(
- cloudflare = None, host = "0.0.0.0", secure = False, api_only = False
- ) is True
+ assert (
+ studio._should_prompt_password_change(
+ cloudflare = None, host = "0.0.0.0", secure = False, api_only = False
+ )
+ is True
+ )
@pytest.mark.parametrize("raised", [OSError("ENOTTY"), AttributeError(), ValueError()])
@@ -1889,14 +1902,20 @@ def test_no_job_control_falls_back_to_the_isatty_answer(monkeypatch, raised):
monkeypatch.setattr(studio.os, "tcgetpgrp", _boom, raising = False)
monkeypatch.setattr(studio.sys, "stdin", _FdStream())
- assert studio._should_prompt_password_change(
- cloudflare = None, host = "0.0.0.0", secure = False, api_only = False
- ) is True
+ assert (
+ studio._should_prompt_password_change(
+ cloudflare = None, host = "0.0.0.0", secure = False, api_only = False
+ )
+ is True
+ )
class _FdStream:
- def fileno(self): return 0
- def isatty(self): return True
+ def fileno(self):
+ return 0
+
+ def isatty(self):
+ return True
# ── a pty is not a person ────────────────────────────────────────────
@@ -1937,7 +1956,11 @@ def test_an_unattended_pty_still_aborts_a_tunnel_launch(monkeypatch, tmp_path):
studio_mod = _studio()
seen = {}
- def _fake_prompt(verify_current, out = None, **kw):
+ def _fake_prompt(
+ verify_current,
+ out = None,
+ **kw,
+ ):
seen.update(kw)
return _NEW_PW
@@ -1954,7 +1977,11 @@ def test_a_raw_bind_prompt_carries_the_unattended_deadline(monkeypatch, tmp_path
studio_mod = _studio()
seen = {}
- def _fake_prompt(verify_current, out = None, **kw):
+ def _fake_prompt(
+ verify_current,
+ out = None,
+ **kw,
+ ):
seen.update(kw)
return _NEW_PW
@@ -1978,8 +2005,12 @@ def test_read_masked_gives_up_on_a_pty_nobody_types_into(monkeypatch):
class _PtyStdin:
encoding = "utf-8"
- def fileno(self): return slave
- def isatty(self): return True
+
+ def fileno(self):
+ return slave
+
+ def isatty(self):
+ return True
try:
monkeypatch.setattr(_password_prompt.sys, "stdin", _PtyStdin())