Skip to content

Conversation

fatelei
Copy link

@fatelei fatelei commented Sep 14, 2025

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

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@github-actions github-actions bot added the no ticket Based on PR title, no linked Trac ticket label Sep 14, 2025
@fatelei fatelei force-pushed the ticket_36376 branch 2 times, most recently from b14bada to 5bce27f Compare September 15, 2025 05:58
Copy link
Member

@adamchainz adamchainz left a 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"])
Copy link
Member

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 ?

Copy link
Author

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

@adamchainz
Copy link
Member

Also, please assign the ticket to yourself on Trac.

@fatelei
Copy link
Author

fatelei commented Sep 19, 2025

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.

image

@fatelei
Copy link
Author

fatelei commented Sep 19, 2025

Also, please assign the ticket to yourself on Trac.

where can i assign to me

@adamchainz
Copy link
Member

where can i assign to me

  1. Log in
  2. Click "Modify ticket":
Xnapper-2025-09-23-00 10 38 3. Click "assign to" and enter your username: Xnapper-2025-09-23-00 10 43

See more: https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/submitting-patches/

@fatelei
Copy link
Author

fatelei commented Sep 22, 2025

where can i assign to me

  1. Log in
  2. Click "Modify ticket":

Xnapper-2025-09-23-00 10 38 3. Click "assign to" and enter your username: Xnapper-2025-09-23-00 10 43
See more: https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/submitting-patches/

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no ticket Based on PR title, no linked Trac ticket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants