Repository navigation
Make the formatter refuse a ruff it is not pinned to, and re-format the four files that drifted - #10512
Conversation
…he four files that drifted main is currently red under its own formatting hook. `pre-commit run --all-files` reformats four files nobody is touching, so every open PR fails `ruff-format-with-kwargs` with "files were modified by this hook" and a diff that has nothing to do with it. #10494 is one; there will be more. ## Why the drift happens `scripts/run_ruff_format.py` runs `sys.executable -m ruff`, which under pre-commit is the pinned `ruff==0.6.9` and on a contributor's machine is whatever they have. ruff's formatting is not stable across releases -- 0.9 moved the wrapping in `assert cond, "msg"` from the condition to the message -- so a file written under a newer ruff is committed in a style the hook reformats back, and the hook then fails on it forever. The linter hook beside it is on v0.15.18 and autoupdates, which makes a modern ruff the natural thing to have installed. Nothing catches it locally: the file looks formatted, `ruff format --check` agrees (with the newer ruff), and the failure only appears on pre-commit.ci. ## The change `run_ruff_format.py` reads the pin out of `.pre-commit-config.yaml` and refuses, before rewriting anything, when the ruff it would run is a different version. The message names both versions and how to fix it, since "files were modified by this hook" sends people looking for a defect in their own diff. `UNSLOTH_RUFF_FORMAT_ANY_VERSION=1` overrides it, which a pin bump needs. The pin is read rather than copied, so there is no second thing to forget; an unreadable pin or an unreadable ruff is not a mismatch, because the format step below already fails loudly on its own. ## The four files Re-formatted with the pinned 0.6.9, no other change: the assert wrapping in `test_docker_studio_keep_cuda_prebuilt.py`, `test_password_prompt_backstop.py` and `test_studio_password_prompt.py`, and the blank line after a short local import in `unsloth_cli/commands/studio.py`, which is the repo's own rule from #6079. Not a pin bump: moving to 0.16 reformats 1062 files and would conflict with every open PR. That is worth doing deliberately, on a quiet branch, not as a side effect of unblocking CI. 15 new tests, and the existing kwarg-spacing suite still passes (77 total).
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 570189b9ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os |
There was a problem hiding this comment.
Restore executable permission on the formatter hook
The file mode changes from 100755 to 100644, but .pre-commit-config.yaml still invokes it directly with entry: scripts/run_ruff_format.py. On Unix runners, every invocation of ruff-format-with-kwargs now fails with Permission denied before this code runs, so the commit leaves the formatting hook—and therefore pre-commit CI—universally broken.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct. The rewrite wrote the file at 0644 and the mode change is invisible in the content diff: git diff --summary on the branch showed mode change 100755 => 100644, and the file keeps its #!/usr/bin/env python3.
Restored to 100755 in 3b68522, with a test that fails when the bit is dropped (TestTheScriptStaysRunnable, skipped on Windows where there are no POSIX mode bits). Verified both ways: chmod 644 fails it, chmod 755 passes it. 16 tests in tests/test_run_ruff_format_pin.py pass.
#10512 rewrote scripts/run_ruff_format.py and the file came back 100644, so pre-commit.ci fails every run with "Executable scripts/run_ruff_format.py is not executable" before the hook does anything. Mode only, no content change.
… formatter hook's executable bit The spacing pass rewrites through a mkstemp temp file and os.replace, and mkstemp creates that file 0600, so every file the pass touches loses its mode. scripts/run_ruff_format.py is the pre-commit hook's own entry point and is processed by the hook it runs; #10512 gave it kwarg spacing, so from then on every run stripped its executable bit, pre-commit.ci committed the flip (7c48499 here, and main's own push check is red the same way), and the next run failed before doing anything with "not executable". The writer now carries the original mode onto the temp file before the replace, pinned by a test that rewrites a 0755 script and a 0644 file, and the hook's entry script goes back to 100755.
… formatter hook's executable bit The spacing pass rewrites through a mkstemp temp file and os.replace, and mkstemp creates that file 0600, so every file the pass touches loses its mode. scripts/run_ruff_format.py is the pre-commit hook's own entry point and is processed by the hook it runs; #10512 gave it kwarg spacing, so from then on every run stripped its executable bit, pre-commit.ci committed the flip (7c48499 here, and main's own push check is red the same way), and the next run failed before doing anything with "not executable". The writer now carries the original mode onto the temp file before the replace, pinned by a test that rewrites a 0755 script and a 0644 file, and the hook's entry script goes back to 100755. (cherry picked from commit db7df60daa97fb6191776a6d489c229c3877888f)
* Restore the executable bit on the formatter hook #10512 rewrote scripts/run_ruff_format.py and the file came back 100644, so pre-commit.ci fails every run, on main and on every open PR, with "Executable scripts/run_ruff_format.py is not executable" before the hook does anything. Mode only, no content change. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep a file's mode through the kwarg-spacing rewrite, and restore the formatter hook's executable bit The spacing pass rewrites through a mkstemp temp file and os.replace, and mkstemp creates that file 0600, so every file the pass touches loses its mode. scripts/run_ruff_format.py is the pre-commit hook's own entry point and is processed by the hook it runs; #10512 gave it kwarg spacing, so from then on every run stripped its executable bit, pre-commit.ci committed the flip (7c48499 here, and main's own push check is red the same way), and the next run failed before doing anything with "not executable". The writer now carries the original mode onto the temp file before the replace, pinned by a test that rewrites a 0755 script and a 0644 file, and the hook's entry script goes back to 100755. (cherry picked from commit db7df60daa97fb6191776a6d489c229c3877888f) * Restore the formatter hook's executable bit after the autofix flip --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
main is currently red under its own formatting hook.
pre-commit run --all-filesreformats four files nobody is touching, so every open PR fails
ruff-format-with-kwargswith "files were modified by this hook" and a diff thathas nothing to do with it. #10494 is one; there will be more.
Why the drift happens
scripts/run_ruff_format.pyrunssys.executable -m ruff, which underpre-commit is the pinned
ruff==0.6.9and on a contributor's machine is whateverthey have. ruff's formatting is not stable across releases -- 0.9 moved the
wrapping in
assert cond, "msg"from the condition to the message -- so a filewritten under a newer ruff is committed in a style the hook reformats back, and
the hook then fails on it forever. The linter hook beside it is on v0.15.18 and
autoupdates, which makes a modern ruff the natural thing to have installed.
Nothing catches it locally: the file looks formatted,
ruff format --checkagrees (with the newer ruff), and the failure only appears on pre-commit.ci.
The change
run_ruff_format.pyreads the pin out of.pre-commit-config.yamland refuses,before rewriting anything, when the ruff it would run is a different version. The
message names both versions and how to fix it, since "files were modified by this
hook" sends people looking for a defect in their own diff.
UNSLOTH_RUFF_FORMAT_ANY_VERSION=1overrides it, which a pin bump needs.The pin is read rather than copied, so there is no second thing to forget; an
unreadable pin or an unreadable ruff is not a mismatch, because the format step
below already fails loudly on its own.
The four files
Re-formatted with the pinned 0.6.9, no other change: the assert wrapping in
test_docker_studio_keep_cuda_prebuilt.py,test_password_prompt_backstop.pyand
test_studio_password_prompt.py, and the blank line after a short localimport in
unsloth_cli/commands/studio.py, which is the repo's own rule from#6079.
Not a pin bump: moving to 0.16 reformats 1062 files and would conflict with every
open PR. That is worth doing deliberately, on a quiet branch, not as a side
effect of unblocking CI.
15 new tests, and the existing kwarg-spacing suite still passes (77 total).