Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override rich.console pipe handler for rich 13.8.0+ #13073

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Nov 9, 2024

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

(I'm assuming this doesn't need a news item, since vendored rich update itself will have one)

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
@uranusjr uranusjr merged commit fe0925b into pypa:main Nov 9, 2024
32 checks passed
@notatallshaw
Copy link
Member

There were a few pushes on this PR and I'm pretty sure the comment got out of sync with what is happening:

        # Reraise the original exception, rich 13.8.0+ exits by default
        # instead, preventing our handler from firing.
        raise BrokenPipeError() from None

It looks to me that it's not reraising the original exception but instead raising a new BrokenPipeError exception to simulate the same functionality as existed before.

@notatallshaw
Copy link
Member

@uranusjr @sbidoul Given this got merged into main is the plan to include this in a possible 24.3.2 with a possible packaging 24.1.1?

@mgorny mgorny deleted the rich-pipe-handling branch November 9, 2024 17:54
@mgorny
Copy link
Contributor Author

mgorny commented Nov 9, 2024

There were a few pushes on this PR and I'm pretty sure the comment got out of sync with what is happening:

        # Reraise the original exception, rich 13.8.0+ exits by default
        # instead, preventing our handler from firing.
        raise BrokenPipeError() from None

It looks to me that it's not reraising the original exception but instead raising a new BrokenPipeError exception to simulate the same functionality as existed before.

Sorry about that. Ruff was unhappy with the bare raise, so I went for the next thing that triggered the same behavior.

@notatallshaw
Copy link
Member

notatallshaw commented Nov 9, 2024

Sorry about that. Ruff was unhappy with the bare raise, so I went for the next thing that triggered the same behavior.

Hmm, IMO this is one of those cases where general best practise linting is suggesting the wrong thing, a callback of an exception handler where you want to preserve the exception is exactly the time a bare raise makes sense. I would have put a noqa note explaining why. But it's a fairly minor issue.

@mgorny
Copy link
Contributor Author

mgorny commented Nov 9, 2024

I think the problem is that we'd be relying on rich not clobbering the exception, so it's a bit unsafe. That said, we're basically catching the exception right away and replacing it, so shouldn't matter much.

@sbidoul
Copy link
Member

sbidoul commented Nov 9, 2024

Given this got merged into main is the plan to include this in a possible 24.3.2 with a possible packaging 24.1.1?

That is not my plan. I don't want to take any risk with 24.3.2.

@ichard26
Copy link
Member

Thank you @mgorny! I'll update the vendoring PR sometime tomorrow.

@mgorny
Copy link
Contributor Author

mgorny commented Nov 10, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants