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 #13006
Bug #13072
  • Loading branch information
mgorny committed Nov 9, 2024
1 parent 4204359 commit 8cfd050
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


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 8cfd050

Please sign in to comment.