Repository navigation
Use the report destination to color ruff check diagnostics - #29899
Merged
Merged
Conversation
AlexWaygood
temporarily deployed
to
automations
November 2, 2026 10:10 — with
GitHub Actions
Inactive
Contributor
|
AlexWaygood
force-pushed
the
alex/ruff-check-output-color
branch
from
November 2, 2026 14:30
779a511 to
28be99e
Compare
AlexWaygood
temporarily deployed
to
automations
November 2, 2026 14:30 — with
GitHub Actions
Inactive
ntBre
approved these changes
Nov 2, 2026
Member
|
I'm not sure I agree with this change. What's the motivation to force color in This also makes ruff and ty inconsistent with uv |
Member
Author
|
I assumed |
Member
|
I think I'd prefer that. The motivation here isn't clear to me. |
Member
Author
|
Reverting in #29908 |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On
main,ruff check --color=always example.py >report.txtsaves colored diagnostics, but replacing>report.txtwith--output-file report.txtstrips the color. This PR makes both ways of saving the report honor--color=always.Automatic color also goes wrong with
ruff check --fix -. Ruff writes the fixed source to stdout and diagnostics to stderr, yet it checks whether stdout is a terminal to decide whether to color the diagnostics. Redirecting only stderr can put ANSI escapes in the saved report, while redirecting only stdout can leave the diagnostics plain on the terminal.Ruff now applies the color policy from #29898 to the destination that receives the diagnostics. When the flags and environment leave color up to terminal detection, Ruff checks that destination. With
--diff -, for example, a patch printed to the terminal on stdout can keep its color while the fix summary redirected from stderr stays plain.Test plan
This video compares the base of this PR (#29898 at
baa3088701) with the fix (779a511358). Each command uses the same one-line input,print(unknown).ruff-report-color.mp4
Manual split-stream reproduction and results
Run these commands from a terminal in a scratch directory, first with
rufffrom the base commit (baa3088701) onPATH, then with the build from this PR. Thetrpipelines count escape bytes in the redirected files.On the base commit,
errcontained 11 escape bytes. With this change it contains zero. Reversing the redirection (>out) changed the F821 diagnostic on the terminal from plain to colored. On both revisions,outcontained the unchanged source,print(unknown).With
--diff, stdout carries the patch and stderr carries the fix summary.The removed import was red on the terminal on both revisions, while the escape count in
summarydropped from 10 to zero. With>patch, the patch contained zero escapes on both revisions, and the fix summary on the terminal changed from plain to colored.