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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Restore the executable bit on the formatter hook (#10519)
Daniel Han971e2e640d7a
diff --git a/scripts/enforce_kwargs_spacing.py b/scripts/enforce_kwargs_spacing.pyindex 4191d526262..9df428a9e19 100755--- a/scripts/enforce_kwargs_spacing.py+++ b/scripts/enforce_kwargs_spacing.py@@ -12,6 +12,7 @@ import astimport argparseimport ioimport os+import statimport sysimport tempfileimport tokenize@@ -23,12 +24,24 @@ def _atomic_write_text(path: Path, data: str, encoding: str) -> None:"""Write ``data`` to ``path`` atomically via same-dir tmp + fsync + os.replace,so a crash mid-write leaves either the old or full new content, never a truncation."""dirpath = str(path.parent) or "."+ # mkstemp creates the file 0600, and os.replace carries that mode over the+ # original's, so an executable script rewritten by this pass came back+ # without its bit. scripts/run_ruff_format.py is the hook's own entry+ # point and is itself processed here: once it carried kwarg spacing every+ # run stripped its executable bit, pre-commit.ci committed the flip, and the+ # next run failed with "not executable". Carry the mode across.+ try:+ mode = stat.S_IMODE(os.stat(path).st_mode)+ except OSError:+ mode = Nonefd, tmp_path = tempfile.mkstemp(prefix=".kwargs_fix.", dir=dirpath)try:with os.fdopen(fd, "w", encoding=encoding) as handle:handle.write(data)handle.flush()os.fsync(handle.fileno())+ if mode is not None:+ os.chmod(tmp_path, mode)os.replace(tmp_path, path)except Exception:try:diff --git a/scripts/run_ruff_format.py b/scripts/run_ruff_format.pyold mode 100644new mode 100755diff --git a/tests/python/test_windows_xformers_wheel_match.py b/tests/python/test_windows_xformers_wheel_match.pyindex bf3a59f074f..d36ef2e9269 100644--- a/tests/python/test_windows_xformers_wheel_match.py+++ b/tests/python/test_windows_xformers_wheel_match.py@@ -108,9 +108,9 @@ def test_windows_resolves_a_cuda_matched_wheel(family: str, torch_tag: str):extra = f"{family}onlytorch{torch_tag}"specs = _windows_xformers(_extras()[extra])- assert len(specs) == 1, (- f"{extra} must resolve exactly one xformers wheel on Windows, got {specs}"- )+ assert (+ len(specs) == 1+ ), f"{extra} must resolve exactly one xformers wheel on Windows, got {specs}"spec = specs[0]if "@" in spec:url = spec.split("@", 1)[1].strip()@@ -119,9 +119,9 @@ def test_windows_resolves_a_cuda_matched_wheel(family: str, torch_tag: str):# Version-pin form: the index is the install-time --index-url, so the version is# the only half of the pairing this branch can carry. It still has to be the# version that index publishes for this torch, which is what the matrix holds.- assert spec == f"xformers=={version}", (- f"{extra} must pin the {family} wheel version for torch {torch_tag}, got {spec!r}"- )+ assert (+ spec == f"xformers=={version}"+ ), f"{extra} must pin the {family} wheel version for torch {torch_tag}, got {spec!r}"@pytest.mark.parametrize(("family", "torch_tag"), sorted(XFORMERS_WHEEL_MATRIX))diff --git a/tests/test_enforce_kwargs_spacing_mode.py b/tests/test_enforce_kwargs_spacing_mode.pynew file mode 100644index 00000000000..50b8c0b48b2--- /dev/null+++ b/tests/test_enforce_kwargs_spacing_mode.py@@ -0,0 +1,43 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+"""The kwarg-spacing pass must leave a file's mode alone.++It rewrites through a temp file and os.replace, and mkstemp creates that temp+file 0600. scripts/run_ruff_format.py is the pre-commit hook's own entry point+and is processed by the hook it runs, so once it carried kwarg spacing every+run stripped its executable bit, pre-commit.ci committed the flip, and the next+run failed before doing anything with "not executable".+"""++from __future__ import annotations++import os+import stat+import subprocess+import sys+from pathlib import Path++_ROOT = Path(__file__).resolve().parent.parent+_SCRIPT = _ROOT / "scripts" / "enforce_kwargs_spacing.py"+++def _rewrite(tmp_path: Path, mode: int) -> Path:+ target = tmp_path / "tool.py"+ target.write_text("def f(a=1):\n return g(b=2)\n", encoding = "utf-8")+ os.chmod(target, mode)+ proc = subprocess.run(+ [sys.executable, str(_SCRIPT), str(target)], capture_output = True, text = True, timeout = 120+ )+ assert proc.returncode == 0, proc.stderr+ assert "g(b = 2)" in target.read_text(encoding = "utf-8"), "the pass did not rewrite the file"+ return target+++def test_an_executable_script_keeps_its_bit_through_the_rewrite(tmp_path):+ target = _rewrite(tmp_path, 0o755)+ assert stat.S_IMODE(target.stat().st_mode) == 0o755+++def test_a_plain_file_keeps_its_group_and_other_read_bits(tmp_path):+ target = _rewrite(tmp_path, 0o644)+ assert stat.S_IMODE(target.stat().st_mode) == 0o644diff --git a/tests/test_torch2110_cuda_extras.py b/tests/test_torch2110_cuda_extras.pyindex 4a1c700fce9..15072439bc2 100644--- a/tests/test_torch2110_cuda_extras.py+++ b/tests/test_torch2110_cuda_extras.py@@ -82,14 +82,14 @@ def _assert_xformers_035(xformers: list[Requirement], cuda: str, extra: str) ->windows = [r for r in urls if r.url.endswith("win_amd64.whl")]assert len(linux) == 1 and len(windows) == 1, f"{extra}: unexpected wheels {xformers}"for r in linux + windows:- assert f"/whl/{cuda}/xformers-0.0.35-" in r.url, (- f"{extra}: xformers not on the {cuda} index: {r.url}"- )+ assert (+ f"/whl/{cuda}/xformers-0.0.35-" in r.url+ ), f"{extra}: xformers not on the {cuda} index: {r.url}"else:(req,) = xformers- assert str(req.specifier) == "==0.0.35", (- f"{extra}: xformers pinned as '{req.specifier}', expected ==0.0.35"- )+ assert (+ str(req.specifier) == "==0.0.35"+ ), f"{extra}: xformers pinned as '{req.specifier}', expected ==0.0.35"linux = windows = xformersfor r in xformers: