-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-130645: Add colour to argparse
help
#132323
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
Conversation
🤖 New build scheduled with the buildbot fleet by @hugovk for commit 3d174b7 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132323%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
When you're done making the requested changes, leave the comment: |
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.
A comment about the approach and whether we can simplify a bit.
Many argparse CLIs I see already use keywords for most parameters, but I think we should make these new ones keyword-only, especially for new bools, as a long list of
What do you think? |
Commandeering this to make the beta 1 cut. Code owner's feedback can be addressed in follow-up PRs.
Add
color
parameter toargparse.ArgumentParser
, which by default isFalse
. When set toTrue
, the help text is in colour if allowed (for example, we're not piping,NO_COLOR=1
is not set).Example output
Using this script:
Performance
With the same script and PGO+LTO on macOS, running it once (
time ./python.exe argparse-cli.py --help
) and 100 times (time ./100.sh
):main
(3feac7a):PR and colour not enabled:
PR and colour enabled:
Something like 0.65 ms difference per run between before and after, averaging from
100.sh
.argparse
help #130645📚 Documentation preview 📚: https://cpython-previews--132323.org.readthedocs.build/