Skip to content

Commit f0bb386

Browse files
q0wpradyunsg
andauthored
Forward --no-color to the rich.Console instance (#11048)
Co-authored-by: Pradyun Gedam <[email protected]>
1 parent d483ff3 commit f0bb386

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

news/11045.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set ``no_color`` to global ``rich.Console`` instance.

src/pip/_internal/cli/base_command.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from optparse import Values
1111
from typing import Any, Callable, List, Optional, Tuple
1212

13+
from pip._vendor.rich import reconfigure
1314
from pip._vendor.rich import traceback as rich_traceback
1415

1516
from pip._internal.cli import cmdoptions
@@ -115,6 +116,7 @@ def _main(self, args: List[str]) -> int:
115116
# Set verbosity so that it can be used elsewhere.
116117
self.verbosity = options.verbose - options.quiet
117118

119+
reconfigure(no_color=options.no_color)
118120
level_number = setup_logging(
119121
verbosity=self.verbosity,
120122
no_color=options.no_color,

tests/functional/test_no_color.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from tests.lib import PipTestEnvironment
1313

1414

15+
@pytest.mark.network
1516
@pytest.mark.skipif(shutil.which("script") is None, reason="no 'script' executable")
1617
def test_no_color(script: PipTestEnvironment) -> None:
1718
"""Ensure colour output disabled when --no-color is passed."""
@@ -23,7 +24,7 @@ def test_no_color(script: PipTestEnvironment) -> None:
2324
# 'script' and well as the mere use of the same.
2425
#
2526
# This test will stay until someone has the time to rewrite it.
26-
pip_command = "pip uninstall {} noSuchPackage"
27+
pip_command = "pip download {} setuptools==62.0.0 --no-cache-dir -d /tmp/"
2728
if sys.platform == "darwin":
2829
command = f"script -q /tmp/pip-test-no-color.txt {pip_command}"
2930
else:
@@ -45,6 +46,7 @@ def get_run_output(option: str = "") -> str:
4546
return retval
4647
finally:
4748
os.unlink("/tmp/pip-test-no-color.txt")
49+
os.unlink("/tmp/setuptools-62.0.0-py3-none-any.whl")
4850

4951
assert "\x1b[3" in get_run_output(""), "Expected color in output"
5052
assert "\x1b[3" not in get_run_output("--no-color"), "Expected no color in output"

0 commit comments

Comments
 (0)