Skip to content

Commit

Permalink
Override rich.console pipe handler for rich 13.8.0+
Browse files Browse the repository at this point in the history
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 pypa#13006
Bug pypa#13072
  • Loading branch information
mgorny committed Nov 9, 2024
1 parent 4204359 commit 099ae97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Empty file added news/13072.trivial.rst
Empty file.
9 changes: 8 additions & 1 deletion src/pip/_internal/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,19 @@ def __rich_console__(
yield Segment("\n")


class PipConsole(Console):
def on_broken_pipe(self) -> None:
# Reraise the original exception, rich 13.8.0+ exits by default
# instead, preventing our handler from firing.
raise BrokenPipeError() from None


class RichPipStreamHandler(RichHandler):
KEYWORDS: ClassVar[Optional[List[str]]] = []

def __init__(self, stream: Optional[TextIO], no_color: bool) -> None:
super().__init__(
console=Console(file=stream, no_color=no_color, soft_wrap=True),
console=PipConsole(file=stream, no_color=no_color, soft_wrap=True),
show_time=False,
show_level=False,
show_path=False,
Expand Down

0 comments on commit 099ae97

Please sign in to comment.