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.

[REQUEST] Respect PY_COLORS environment variable

See original GitHub issue

PY_COLORS is a very popular method for forcing ANSI mode on or off in a command line application.

Basically undefined means keeping application default behavior, likely auto-detection. Having it PY_COLORS=0 means application will not use any ANSI codes and PY_COLORS=1 will force ANSI mode regardless if terminal reports it or not.

For me personally is not a big deal as I already have code in applications I work with, but it would prove useful to have this directly into rich, so any user of rich would get this for free.

An implementation example can be seen at https://github.com/ansible-community/molecule/blob/20e1fa8a23308a9103e2dbdb4d3c4ae1ffe59c9d/molecule/logger.py#L42-L48

That is very useful feature to have when running on CI as you do not want to end-up defining 50-100 environment variables only to control ANSI behavior.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
willmcgugancommented, Nov 5, 2020

They not really standards, since they’re not documented by any kind of authority. And not all that established, since relatively few apps support them.

They’re also implemented inconsistently, for instance on some apps FORCE_COLOR=0 would force color on because anything other than empty string is considered True, but some apps would treat “0” as false and disable color. And if I implement more than one, what if they conflict?

If I was to add support for these env vars, then I’ve baked that in to all apps using Rich, which means that if I change it in the future when / if a standard emerges @willmcgugan is going to get a lot of angry mentions.

So I’d rather to leave it up to the developer what env vars they should support. It’s only a line or two to set force_color on the Console constructor.

I may yet relent on this. I try to be pragmatic!

0reactions
ewelscommented, Nov 5, 2020

Yes, for future googlers wanting to copy and paste, here was my workaround to do the same with our codebase: https://github.com/nf-core/tools/pull/760/files (bit simpler / more crude, includes direct detection for GitHub Actions).

Read more comments on GitHub >

github_iconTop Results From Across the Web

[REQUEST] Respect PY_COLORS environment variable #343
PY_COLORS is a very popular method for forcing ANSI mode on or off in a command line application. Basically undefined means keeping ...
Read more >
Python "requests" module does not respect http_proxy ...
I am trying to get a Python script that uses the requests module to request data through a proxy.
Read more >
Github Actions Environment Variables: Guide, Examples & Tips
Github Actions environment variables allow you to store information―API keys, login credentials, app secrets, constants, etc―to use in your ...
Read more >
mod_setenvif - Apache HTTP Server
The mod_setenvif module allows you to set environment variables according to whether different aspects of the request match regular expressions you specify.
Read more >
mod_setenvif - Apache HTTP Server Version 2.5
The mod_setenvif module allows you to set internal environment variables according to whether different aspects of the request match regular expressions you ...
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