-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
GH-139809: Fix argparse subcommand prog not respecting color environment variables #139818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
savannahostrowski
merged 9 commits into
python:main
from
savannahostrowski:fix-colorize-subparser
Oct 9, 2025
+18
−2
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1e3e343
Add fix to decolorize and test
savannahostrowski 8511193
Remove extra line
savannahostrowski c94021b
📜🤖 Added by blurb_it.
blurb-it[bot] 98b78b6
Remove parens in blurb
savannahostrowski 666dd43
Use formatter class to avoid premature colorization of prog
savannahostrowski f2c813a
Update blurb
savannahostrowski 5ba525a
Update test
savannahostrowski 86551d1
Move blurb and simplify setUp
savannahostrowski 8274bc7
Merge branch 'main' into fix-colorize-subparser
savannahostrowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure this removes to the coloring independent if coloring is on or not, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well,
_decolor
strips ANSI codes when coloring is enabled. When coloring is disabled, it's a no-op since no ANSI codes should exist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not going to be enough. I mentioned before, but
prog
is a public metadata on theparser
that contains the name of the application. We should not color it until it's about to be printed later on, otherwise will not fix my issue here https://github.com/tox-dev/sphinx-argparse-cli/blob/main/src/sphinx_argparse_cli/_logic.py#L340-L342. Thanks!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see your point. I think another approach here could be to create a separate formatter explicitly set with
color=False
, so thatprog
wouldn't get colored in the first place (rather than having to decolor it).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated but I should mention it here that I was surprised that setting color to False for the formatter (see here https://github.com/tox-dev/sphinx-argparse-cli/blob/main/src/sphinx_argparse_cli/_logic.py#L402-L404) doesn't actually disables color printing, had to set NO_COLOR during
format_usage
to not color that output 🤔 Seems thecolor
argument of theparser
is instead used 🤔 not sure if that's a bug or a feature, but suprised me.By the way I love the colors in the CLI ❤️ (definitely the best feature of 3.14) , just they are not needed when you're writing a sphinx plugin to render it for other outputs 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this seems like a bug.
HelpFormatter
acceptscolor
, but it is then seemingly overridden in_get_formatter
. This should probably be respected, or we should remove it to avoid confusion.