GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-129061: Fix `FORCE_COLOR` and `NO_COLOR` when empty strings by hugovk · Pull Request #129140 · python/cpython

Conversation

@hugovk

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

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • Issue: Empty values of FORCE_COLOR and NO_COLOR are not ignored #129061

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Jan 21, 2025
Empty values of FORCE_COLOR and NO_COLOR are not ignored #129061
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 21, 2025
@hugovk hugovk added the needs backport to 3.13 only security fixes label Jan 21, 2025
@hugovk
hugovk marked this pull request as draft January 21, 2025 17:07
@bedevere-app bedevere-app Bot removed the awaiting core review label Jan 21, 2025
hugovk added 2 commits January 21, 2025 23:29
@hugovk
Refactor into subtests
96c2e76
@hugovk
Fix FORCE_COLOR and NO_COLOR when empty strings
c7b5419
@hugovk
hugovk force-pushed the 3.14-empty-force-color-no-color branch from b67ac03 to c7b5419 Compare January 21, 2025 21:48
@hugovk 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 hugovk mentioned this pull request Jan 22, 2025
Revert "run make regen-requirements (#568)" python/buildmaster-config#569
Merged
@hugovk 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
@bedevere-bot

This comment was marked as resolved.

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

This comment was marked as resolved.

Sign in to view
@bedevere-bot

This comment was marked as resolved.

Sign in to view
@hugovk

This comment was marked as resolved.

Sign in to view
@bedevere-bot

This comment was marked as resolved.

Sign in to view
@hugovk

This comment was marked as resolved.

Sign in to view
@bedevere-bot

This comment was marked as resolved.

Sign in to view
@hugovk

This comment was marked as resolved.

Sign in to view
@bedevere-bot

This comment was marked as resolved.

Sign in to view
@hugovk

This comment was marked as resolved.

Sign in to view
@bedevere-bot

This comment was marked as resolved.

Sign in to view
@hugovk

This comment was marked as resolved.

Sign in to view
@bedevere-bot

This comment was marked as resolved.

Sign in to view
@hugovk
Merge branch 'main' into 3.14-empty-force-color-no-color
ec36e22
@hugovk hugovk added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 22, 2025
@bedevere-bot

bedevere-bot commented 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
hugovk marked this pull request as ready for review January 23, 2025 10:07
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 23, 2025
serhiy-storchaka
serhiy-storchaka reviewed Jan 23, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test__colorize.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test__colorize.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test__colorize.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test__colorize.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test__colorize.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
Add test cases
a738098
serhiy-storchaka
serhiy-storchaka approved these changes Jan 23, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jan 23, 2025
@hugovk

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Jan 23, 2025

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.

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk added 3 commits January 25, 2025 17:37
@hugovk
Reset tests to main
621e4ab
@hugovk
Add test cases for empty values
5027272
@hugovk
Merge remote-tracking branch 'upstream/main' into 3.14-empty-force-co…
5d40ced
…lor-no-color
serhiy-storchaka
serhiy-storchaka reviewed Jan 26, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hugovk
Just add the first two
e86c7f7
@hugovk

hugovk commented Jan 27, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka approved these changes Jan 27, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

LGTM! 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@hugovk
hugovk merged commit 9546fe2 into python:main Jan 27, 2025
@hugovk
hugovk deleted the 3.14-empty-force-color-no-color branch January 27, 2025 14:24
@miss-islington-app

miss-islington-app Bot commented Jan 27, 2025

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 27, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 27, 2025
@hugovk @miss-islington
pythongh-129061: Fix FORCE_COLOR and NO_COLOR when empty strings (p…
a8eeea9
…ythonGH-129140)

(cherry picked from commit 9546fe2)

Co-authored-by: Hugo van Kemenade <[email protected]>
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app 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
@miss-islington @hugovk
[3.13] gh-129061: Fix FORCE_COLOR and NO_COLOR when empty strings (…
c7f9e74
…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 <[email protected]>
@freakboy3742 freakboy3742 mentioned this pull request Feb 20, 2025
gh-130293: Ensure test__colorize will pass on dumb terminals. #130333
Merged
@hugovk hugovk mentioned this pull request Feb 28, 2025
Only apply FORCE_COLOR, NO_COLOR and ANSI_COLORS_DISABLED when present and not an empty string termcolor/termcolor#92
Merged
@hugovk hugovk mentioned this pull request Mar 22, 2025
[BUG] v13.3.4 broke coloring Textualize/rich#2924
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@hugovk @bedevere-bot @serhiy-storchaka
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.