Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a global option to disable colors #4739

Merged
merged 9 commits into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/reference/pip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Console logging
~~~~~~~~~~~~~~~

pip offers :ref:`-v, --verbose <--verbose>` and :ref:`-q, --quiet <--quiet>`
to control the console log level.
to control the console log level. By default, some messages (error and warnnings)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: warnings

are colored in the terminal. If you want to suppress the colored output use
:ref:`--no-color <--no-color>`.


.. _`FileLogging`:
Expand Down
2 changes: 2 additions & 0 deletions news/2449.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add `--no-color` to `pip`. All colored output is disabled
if this flag is detected.
10 changes: 8 additions & 2 deletions src/pip/_internal/basecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,21 @@ def main(self, args):
"console": {
"level": level,
"class":
"pip._internal.utils.logging.ColorizedStreamHandler",
"logging.StreamHandler"
oz123 marked this conversation as resolved.
Show resolved Hide resolved
if options.no_color
else ("pip._internal.utils.logging."
"ColorizedStreamHandler"),
"stream": self.log_streams[0],
"filters": ["exclude_warnings"],
"formatter": "indent",
},
"console_errors": {
"level": "WARNING",
"class":
"pip._internal.utils.logging.ColorizedStreamHandler",
"logging.StreamHandler"
if options.no_color
else ("pip._internal.utils.logging"
".ColorizedStreamHandler"),
"stream": self.log_streams[1],
"formatter": "indent",
},
Expand Down
10 changes: 10 additions & 0 deletions src/pip/_internal/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ def getname(n):
help='Give more output. Option is additive, and can be used up to 3 times.'
)

no_color = partial(
Option,
'--no-color',
dest='no_color',
action='store_true',
default=False,
help="Suppress colored output"
oz123 marked this conversation as resolved.
Show resolved Hide resolved
)

version = partial(
Option,
'-V', '--version',
Expand Down Expand Up @@ -566,6 +575,7 @@ def _merge_hash(option, opt_str, value, parser):
cache_dir,
no_cache,
disable_pip_version_check,
no_color
oz123 marked this conversation as resolved.
Show resolved Hide resolved
]
}

Expand Down