Skip to content

Make the formatter refuse a ruff it is not pinned to, and re-format the four files that drifted - #10512

Merged
danielhanchen merged 1 commit into
mainfrom
fmt-pin-guard
Sep 8, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fmt-pin-guard

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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).

…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).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T13:26:41.526093Z 570189b PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen
danielhanchen merged commit 4953744 into main Sep 8, 2026
6 of 87 checks passed
@danielhanchen
danielhanchen deleted the fmt-pin-guard branch September 8, 2026 13:38
danielhanchen added a commit that referenced this pull request Sep 8, 2026
#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.
danielhanchen added a commit that referenced this pull request Sep 8, 2026
… 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.
danielhanchen added a commit that referenced this pull request Sep 8, 2026
… 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)
danielhanchen added a commit that referenced this pull request Sep 8, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant