What's the problem this feature will solve?
Sometimes you want color output when the output stream is not a tty. For example, GitHub Actions does not currently provide a tty to jobs, see actions/runner#241.
Describe the solution you'd like
Add a new option --color=WHEN. WHEN can be always, auto, or never:
always: Force color output
auto: Enable color output if output is a tty (default behavior)
never: Do not color output.
With this change, the existing option --no-color becomes a shorthand for --color=never.
For example, on a CI system which does not provide a tty, you can invoke pip --color=always to enable color output explicitly.
Alternative Solutions
I am not aware of an alternative solution. You can work around this by allocating a pseudoterminal explicitly, for example using pyinvoke with pty=True.
Update: pip already enables color output when TERM=ANSI is passed in the environment. AFAICS this behavior is undocumented.
Additional context
The proposed design comes from the ls(1) command of GNU coreutils. Additionally, the ls option allows passing --color without an argument, in which case WHEN defaults to always.
Happy to provide a PR, if there is interest in this. 🐾
What's the problem this feature will solve?
Sometimes you want color output when the output stream is not a tty. For example, GitHub Actions does not currently provide a tty to jobs, see actions/runner#241.
Describe the solution you'd like
Add a new option
--color=WHEN.WHENcan bealways,auto, ornever:always: Force color outputauto: Enable color output if output is a tty (default behavior)never: Do not color output.With this change, the existing option
--no-colorbecomes a shorthand for--color=never.For example, on a CI system which does not provide a tty, you can invoke
pip --color=alwaysto enable color output explicitly.Alternative Solutions
I am not aware of an alternative solution. You can work around this by allocating a pseudoterminal explicitly, for example using pyinvoke with
pty=True.Update: pip already enables color output when
TERM=ANSIis passed in the environment. AFAICS this behavior is undocumented.Additional context
The proposed design comes from the ls(1) command of GNU coreutils. Additionally, the
lsoption allows passing--colorwithout an argument, in which caseWHENdefaults toalways.Happy to provide a PR, if there is interest in this. 🐾