-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
feat: add color for argparse #19861
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
base: main
Are you sure you want to change the base?
feat: add color for argparse #19861
Conversation
b14bada
to
5bce27f
Compare
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.
Thanks for getting this started.
I would like to see tests that hit both pathways, rather than only for a command.
Also, could you share a screenshot of what you're seeing on Python 3.14, as a final check that things are working within a real live terminal? That would be with and without DJANGO_COLORS=nocolor
.
Also, per the committing guidelines, please retitle your commit:
Fixed #36376 -- Made Python 3.14 colourization obey DJANGO_COLORS.
I think we'd also do well to include a small release note with similar wording. That will need to target Django 6.1 after today's Django 6.0 feature freeze.
def test_help_is_colorized_on_py314(self): | ||
# Use a command that doesn't need settings. | ||
with mock.patch.dict(os.environ, {}, clear=False): | ||
out, err = self.run_django_admin(["startproject", "--help"]) |
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.
can we use just --help
?
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.
• --help triggers ManagementUtility’s custom help path that prints main_help_text(), not argparse’s help.
• The colorization we’re testing is specifically argparse’s colorized help introduced in Python 3.14.
• To hit argparse’s help (and thus see ANSI color sequences), we need a subcommand’s help, e.g., startproject --help (or equivalently help startproject).
Also, please assign the ticket to yourself on Trac. |
5bce27f
to
a44a793
Compare
|
where can i assign to me |
See more: https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/submitting-patches/ |
done |
Trac ticket number
ticket-36376
Branch description
• Enabled colorized help for management command parsers on Python 3.14+ by setting the argparse color parameter when creating the command parser, unless DJANGO_COLORS=nocolor is set.
• Kept compatibility with older Python versions by guarding the new parameter behind a Python 3.14+ check.
Checklist
main
branch.