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.

Keep scripts/run_ruff_format.py executable (#10518)

Daniel Han82848f76208b
diff --git a/tests/test_enforce_kwargs_spacing.py b/tests/test_enforce_kwargs_spacing.py
index 48c524c015c..5a62759b4a9 100644
--- a/tests/test_enforce_kwargs_spacing.py
+++ b/tests/test_enforce_kwargs_spacing.py
@@ -405,3 +405,39 @@ def test_collapse_short_assert_left_alone(name, src):
out, changed = collapse_short_asserts(src)
assert changed is False
assert out == src
+
+
+class TestTheRewriteKeepsThePermissions:
+ """The rewrite is a temp file moved over the target, so the mode travels with it.
+
+ tempfile.mkstemp creates 0600 and os.replace carries that onto the target, so
+ every file this hook touched came back 0600: an executable script lost the bit,
+ git recorded 100755 -> 100644, and pre-commit.ci committed that mode change on
+ a branch whose diff showed nothing. scripts/run_ruff_format.py is one of the
+ files this hook formats, so it did it to itself.
+ """
+
+ @staticmethod
+ def _rewrite(path: Path) -> None:
+ import subprocess
+ script = Path(__file__).resolve().parent.parent / "scripts" / "enforce_kwargs_spacing.py"
+ subprocess.run([sys.executable, str(script), str(path)], check = True, capture_output = True)
+
+ @pytest.mark.skipif(sys.platform.startswith("win"), reason = "no POSIX mode bits")
+ @pytest.mark.parametrize("mode", [0o755, 0o644, 0o600])
+ def test_a_rewritten_file_keeps_the_mode_it_had(self, tmp_path, mode):
+ target = tmp_path / "sample.py"
+ target.write_text("x = f(a=1)\n", encoding = "utf-8")
+ target.chmod(mode)
+ self._rewrite(target)
+ # It really did rewrite: otherwise this asserts nothing about the writer.
+ assert target.read_text(encoding = "utf-8") == "x = f(a = 1)\n"
+ assert target.stat().st_mode & 0o777 == mode
+
+ @pytest.mark.skipif(sys.platform.startswith("win"), reason = "no POSIX mode bits")
+ def test_a_file_it_leaves_alone_is_not_touched_either(self, tmp_path):
+ target = tmp_path / "already.py"
+ target.write_text("x = f(a = 1)\n", encoding = "utf-8")
+ target.chmod(0o755)
+ self._rewrite(target)
+ assert target.stat().st_mode & 0o777 == 0o755
diff --git a/tests/test_run_ruff_format_pin.py b/tests/test_run_ruff_format_pin.py
index d6122518622..611a898b98b 100644
--- a/tests/test_run_ruff_format_pin.py
+++ b/tests/test_run_ruff_format_pin.py
@@ -118,8 +118,17 @@ class TestRefusing:
assert main([str(target)]) == 1
assert target.read_text(encoding = "utf-8") == original
+ @pytest.mark.skipif(
+ installed_ruff_version() is None,
+ reason = "this one really runs the formatter, and ruff is not installed here",
+ )
def test_the_override_lets_it_through(self, tmp_path, monkeypatch):
# An escape hatch, because a pin bump has to be runnable before it is merged.
+ #
+ # Skipped rather than asserted where ruff is absent: main() forwards the
+ # formatter's own exit code, so on an interpreter with no ruff this returns
+ # 1 for a reason that has nothing to do with the version gate. That is how
+ # it failed on the repo-tests CI runner, which installs no ruff.
target = tmp_path / "sample.py"
target.write_text("x = f(a=1)\n", encoding = "utf-8")
monkeypatch.setattr("run_ruff_format.installed_ruff_version", lambda *a, **k: "9.9.9")
@@ -133,3 +142,15 @@ class TestRefusing:
# and must not be failed for a version it never used.
monkeypatch.setattr("run_ruff_format.installed_ruff_version", lambda *a, **k: "9.9.9")
assert main([]) == 0
+
+
+class TestTheScriptStaysRunnable:
+ """It is invoked as a program, so the mode bit matters, and a wholesale rewrite drops it invisibly."""
+
+ @pytest.mark.skipif(sys.platform.startswith("win"), reason = "no POSIX mode bits")
+ def test_the_formatter_is_executable(self):
+ script = _ROOT / "scripts" / "run_ruff_format.py"
+ assert script.read_text(encoding = "utf-8").startswith("#!")
+ assert (
+ script.stat().st_mode & 0o111
+ ), "scripts/run_ruff_format.py lost its executable bit; git tracks it as 100755"