FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-129061: Fix `FORCE_COLOR` and `NO_COLOR` when empty strings by hugovk · Pull Request #129140 · python/cpython · GitHub

Repository navigation

gh-129061: Fix FORCE_COLOR and NO_COLOR when empty strings - #129140

Merged
hugovk merged 8 commits into
python:mainfrom
hugovk:3.14-empty-force-color-no-color
Jan 27, 2025
Merged

hugovk merged 8 commits into
python:mainfrom
hugovk:3.14-empty-force-color-no-color

Conversation

hugovk commented Jan 21, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

First refactor the tests into subtests, which makes it easier compare the env var inputs and expected outputs.

hugovk force-pushed the 3.14-empty-force-color-no-color branch from b67ac03 to c7b5419 Compare January 21, 2025 21:48
hugovk added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels Jan 21, 2025
hugovk added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels Jan 22, 2025

This comment was marked as resolved.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 22, 2025

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

hugovk added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 22, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @hugovk for commit ec36e22 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F30617%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 22, 2025

hugovk commented Jan 23, 2025

Copy link
Copy Markdown
Member Author

Like #129137 (comment), test_external_inspection failed on Fedora and RHEL8 buildbots and is unrelated.

hugovk marked this pull request as ready for review January 23, 2025 10:07

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We only need to test pairs of environment variables that set conflicting values.
For example, NO_COLOR=1 and TERM=dumb should be tested with FORCE_COLOR=1 and PYTHON_COLOR=1. Tests for a single environment variable which forces color (FORCE_COLOR and PYTHON_COLOR) should be performed when the fallback value determined by isatty or _supports_virtual_terminal is False.

We need also to test can_colorize() when stderr is a TTY, but stdout is not, and with an explicit file argument. Including corner cases: no file.fileno, no file.isatty, file.isatty() and os.isatty(file.fileno()) return different results. BTW, I think that file.isatty() should perhaps be tested before os.isatty(file.fileno()).

This is a large issue and can be done in a separate PR.

Comment thread Lib/test/test__colorize.py Outdated
Comment thread Lib/test/test__colorize.py Outdated
Comment thread Lib/test/test__colorize.py Outdated
Comment thread Lib/test/test__colorize.py Outdated
Comment thread Lib/test/test__colorize.py Outdated

hugovk commented Jan 23, 2025

Copy link
Copy Markdown
Member Author

Some failures on Windows for:

                ({"PYTHON_COLORS": "true"}, True),
                ({"PYTHON_COLORS": "2"}, True),
                ({"PYTHON_COLORS": ""}, True),

That's because according to the docs:

If this variable is set to 1, the interpreter will colorize various kinds of output. Setting it to 0 deactivates this behavior.

Therefore everything that is not "0" or "1" is ignored, and the result depends on other conditions.


This also fails on Windows:

                ({"NO_COLOR": ""}, True),

That's because an empty value means we ignore it, and again the result depends on other conditions.


Shall we remove these four, or use them in combination with some other variables?

Copy link
Copy Markdown
Member

See improved tests in #129234. They cover all corner cases. I propose to push it first, and then add tests for empty values.

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Only the first two checks are necessary. Others do not add anything useful. They look out of place and make the intention of the tests less clear.

The first group tests the different values of the variables. The second group tests relative priority of the variables (it does not repeat tests for different values). Then the same is done for PYTHON_COLORS -- first the different values of PYTHON_COLORS (including the empty value), then its relative priority to other variables.

hugovk commented Jan 27, 2025 •
edited
Loading

Copy link
Copy Markdown
Member Author

Okay, I've removed all but the first two.

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM! 👍

hugovk merged commit 9546fe2 into python:main Jan 27, 2025
hugovk deleted the 3.14-empty-force-color-no-color branch January 27, 2025 14:24

Copy link
Copy Markdown

Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 27, 2025
…ythonGH-129140)

(cherry picked from commit 9546fe2)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>

bedevere-app Bot commented Jan 27, 2025

Copy link
Copy Markdown

GH-129360 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jan 27, 2025
hugovk added a commit that referenced this pull request Jan 27, 2025
…GH-129140) (#129360)

gh-129061: Fix `FORCE_COLOR` and `NO_COLOR` when empty strings (GH-129140)
(cherry picked from commit 9546fe2)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL