Skip to content

Commit

Permalink
Merge pull request #13073 from mgorny/rich-pipe-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Nov 9, 2024
2 parents 4204359 + 099ae97 commit fe0925b
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

1 comment on commit fe0925b

@The-Lincoln
Copy link

Choose a reason for hiding this comment

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

this

Please sign in to comment.