Skip to content

Option to force color output #8132

@cjolowicz

Description

@cjolowicz

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. 🐾

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions