[rejected AI] support FORCE_COLOR, NO_COLOR, and PYTHON_COLORS environment variables - #3845
Closed
taran-dev4u wants to merge 1 commit into
Closed
[rejected AI] support FORCE_COLOR, NO_COLOR, and PYTHON_COLORS environment variables#3845taran-dev4u wants to merge 1 commit into
taran-dev4u wants to merge 1 commit into
Conversation
Member
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
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.
Description
Currently, Click only determines the default color preference by checking whether the output stream is a physical TTY (
isatty(stream)). In CI/CD environments (GitHub Actions, GitLab CI, Jenkins) and automated build logs, output streams are pipes/files whereisatty()is False, which strips color and ANSI styling unlesscolor=Trueis explicitly passed.Standards like NO_COLOR, FORCE_COLOR, and Python 3.13's standard
PYTHON_COLORSallow users and build environments to control ANSI color output globally.Changes
src/click/globals.py:resolve_color_default()to inspectNO_COLOR,FORCE_COLOR, andPYTHON_COLORSwhen no explicitcolorflag orctx.coloris configured:NO_COLOR(non-empty) orPYTHON_COLORS="0"/FORCE_COLOR="0"-> returnsFalse(disable color).FORCE_COLOR(non-zero/true) orPYTHON_COLORS="1"-> returnsTrue(enable color).src/click/_compat.py:should_strip_ansi()to respectNO_COLOR,FORCE_COLOR, andPYTHON_COLORSwhencolor is None.src/click/testing.py:CliRunner.isolation()'sshould_strip_ansimock to evaluate environment variables during test runs.tests/test_utils/test_echo.py:test_echo_force_colortestingFORCE_COLOR=1,FORCE_COLOR=true,FORCE_COLOR=0,PYTHON_COLORS=1,PYTHON_COLORS=0, and explicitcolor=Falseoverride on non-TTY streams.test_echo_no_colortestingNO_COLOR=1,NO_COLOR="", and explicitcolor=Trueoverride on TTY streams.test_echo_runner_env_colortestingCliRunnerinvocations with environment variables.Closes #3022