Skip to content

[rejected AI] support FORCE_COLOR, NO_COLOR, and PYTHON_COLORS environment variables - #3845

Closed
taran-dev4u wants to merge 1 commit into
pallets:mainfrom
taran-dev4u:feat/support-force-color-and-no-color
Closed

[rejected AI] support FORCE_COLOR, NO_COLOR, and PYTHON_COLORS environment variables#3845
taran-dev4u wants to merge 1 commit into
pallets:mainfrom
taran-dev4u:feat/support-force-color-and-no-color

Conversation

@taran-dev4u

Copy link
Copy Markdown

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 where isatty() is False, which strips color and ANSI styling unless color=True is explicitly passed.

Standards like NO_COLOR, FORCE_COLOR, and Python 3.13's standard PYTHON_COLORS allow users and build environments to control ANSI color output globally.

Changes

  1. src/click/globals.py:
    • Extended resolve_color_default() to inspect NO_COLOR, FORCE_COLOR, and PYTHON_COLORS when no explicit color flag or ctx.color is configured:
      • NO_COLOR (non-empty) or PYTHON_COLORS="0" / FORCE_COLOR="0" -> returns False (disable color).
      • FORCE_COLOR (non-zero/true) or PYTHON_COLORS="1" -> returns True (enable color).
  2. src/click/_compat.py:
    • Updated should_strip_ansi() to respect NO_COLOR, FORCE_COLOR, and PYTHON_COLORS when color is None.
  3. src/click/testing.py:
    • Updated CliRunner.isolation()'s should_strip_ansi mock to evaluate environment variables during test runs.
  4. tests/test_utils/test_echo.py:
    • Added test_echo_force_color testing FORCE_COLOR=1, FORCE_COLOR=true, FORCE_COLOR=0, PYTHON_COLORS=1, PYTHON_COLORS=0, and explicit color=False override on non-TTY streams.
    • Added test_echo_no_color testing NO_COLOR=1, NO_COLOR="", and explicit color=True override on TTY streams.
    • Added test_echo_runner_env_color testing CliRunner invocations with environment variables.

Closes #3022

@davidism davidism changed the title feat(color): support FORCE_COLOR, NO_COLOR, and PYTHON_COLORS environment variables [rejected AI] support FORCE_COLOR, NO_COLOR, and PYTHON_COLORS environment variables Sep 6, 2026
@davidism davidism added the rejected AI Contribution rejected because of its untrustworthy AI origin label Sep 6, 2026
@davidism

davidism commented Sep 6, 2026

Copy link
Copy Markdown
Member

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

Labels

rejected AI Contribution rejected because of its untrustworthy AI origin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support FORCE_COLOR and NO_COLOR environment variables

2 participants