Skip to content

Enable colours when FORCE_COLOR env var is set #10909

Closed
@hugovk

Description

What's the problem this feature will solve?

pip 22 now uses Rich for installation progress bars and some error handling, which gives us pretty colours!

image

Colour can help diagnose problems, and a common place for pip and the need to diagnose problems is on a CI.

However, because the GitHub Actions isn't a tty, output of tools which autodetect the terminal output is usually monochrome. That's why many tools and CI setups use the FORCE_COLOR environment variable, and/or command-line options to turn it back on.

The pip CI included (#10830):

env:
# The "FORCE_COLOR" variable, when set to 1,
# tells Nox to colorize itself.
FORCE_COLOR: "1"

However, pip itself (and Rich) don't use FORCE_COLOR, meaning we get monochrome output:

image

Compare with nox:

image

https://github.com/pypa/pip/runs/5177210581?check_suite_focus=true

And pytest:

image

https://github.com/pytest-dev/pytest/runs/5185781927?check_suite_focus=true

Describe the solution you'd like

Enable colour when FORCE_COLOR is set.

For reference:

Alternative Solutions

Get Rich to support FORCE_COLOR directly. This was considered in 2020 but rejected in Textualize/rich#343 to leave it up to the developer to support it.

But Will said "I may yet relent on this. I try to be pragmatic!" so it may still be a better option :)

Additional context

I'm not specifically requesting it here, but could be worth considering also disabling when NO_COLOR is set: https://no-color.org/

Similarly not requesting it here, but for completeness I'll mention pytest also has this command-line option:

  --color=color         color terminal output (yes/no/auto).

And nox:

  --nocolor, --no-color
                        Disable all color output.
  --forcecolor, --force-color
                        Force color output, even if stdout is not an interactive terminal.

Whereas pip only has the negative:

  --no-color                  Suppress colored output.

Code of Conduct

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions