question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable colours when FORCE_COLOR env var is set

See original GitHub issue

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):

https://github.com/pypa/pip/blob/4a508c268ee4be5bc279f1522954b78fa9e25050/.github/workflows/ci.yml#L14-L17

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 https://github.com/Textualize/rich/issues/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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
hugovkcommented, Jul 27, 2022

If FORCE_COLOR (any value -> on) has emerged as a standard. I could implement that in Rich.

@willmcgugan This would be great! What’s the next step? Would you like an issue created at https://github.com/Textualize/rich?

2reactions
potiukcommented, Feb 14, 2022

Yeah. That would be indeed very useful. Colors in CI are great for visual communication (as otherwise you end up with big blob of text) - especially that often in Ci you enable pretty verbose output to be able to diagnose problems. Nany tools allows forcing colors indeed so it woud be useful to have it in ‘pip’. Happy to help and create a PR for that one if preferred way to do it is agreed to by the maintainers…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any env variable to turn --color (and the like) on for all ...
FreeBSD has CLICOLOR. On Linux and any other system with GNU tools, you need to set LS_COLORS, GREP_COLOR, and GREP_OPTIONS='--color=auto', but even then ......
Read more >
Support environment variable CLICOLOR_FORCE to enable
When piping gcc, colored output gets disabled because isatty returns false. But for many people this is the normal way of running gcc, ......
Read more >
lib.rs - source - Docs.rs
Environment variable name for enabling/disabling color /// /// Whan a tty is attached to the environment and this environment variable is /// either...
Read more >
How to enable colored output from shell command wrapped in ...
To force color output from grep : ... The colors are defined by the environment variable GREP_COLORS. ... Task: Turn on colors.
Read more >
No_color | Hacker News
Don't most terminal emulators allow you to set your own color palette? ... Especially when no environment variable tells you whether to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found