Skip to content

Commit 8cfd050

Browse files
committed
Override rich.console pipe handler for rich 13.8.0+
Explicitly override `rich.console.Console.on_broken_pipe()` to reraise the original exception, to bring the behavior of rich 13.8.0+ in line with older versions. The new versions instead close output fds and exit with error instead, which prevents pip's pipe handler from firing. This is the minimal change needed to make pip's test suite pass after upgrading vendored rich. Bug #13006 Bug #13072
1 parent 4204359 commit 8cfd050

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

news/13072.trivial.rst

Whitespace-only changes.

src/pip/_internal/utils/logging.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,19 @@ def __rich_console__(
137137
yield Segment("\n")
138138

139139

140+
class PipConsole(Console):
141+
def on_broken_pipe(self) -> None:
142+
# Reraise the original exception, rich 13.8.0+ exits by default
143+
# instead, preventing our handler from firing.
144+
raise
145+
146+
140147
class RichPipStreamHandler(RichHandler):
141148
KEYWORDS: ClassVar[Optional[List[str]]] = []
142149

143150
def __init__(self, stream: Optional[TextIO], no_color: bool) -> None:
144151
super().__init__(
145-
console=Console(file=stream, no_color=no_color, soft_wrap=True),
152+
console=PipConsole(file=stream, no_color=no_color, soft_wrap=True),
146153
show_time=False,
147154
show_level=False,
148155
show_path=False,

0 commit comments

Comments
 (0)