-
-
Notifications
You must be signed in to change notification settings - Fork 624
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
✨ Add option to set the width of the Rich exception output #528
base: master
Are you sure you want to change the base?
Conversation
📝 Docs preview for commit d82e751 at: https://63b9cedb2674445f42edea4e--typertiangolo.netlify.app |
📝 Docs preview for commit 36405da at: https://63dba78174f4db37545e5176--typertiangolo.netlify.app |
📝 Docs preview for commit 0e54ace at: https://63ef5180d07132579c80cd4c--typertiangolo.netlify.app |
📝 Docs preview for commit 7814341 at: https://64034f719f540d3ebc0ef662--typertiangolo.netlify.app |
78eb706
to
2587d6d
Compare
Hi @tiangolo , |
I definitely would like for this to be merged in! @tiangolo |
Yes, feature looks really good. @tiangolo Could you please, review? |
adding new attribute in DeveloperExceptionConfig to allow setting width for rick traceback.
add `pretty_exceptions_width` in typer class to be used by `DeveloperConfigException` to allow setting width of traceback boxes.
📝 Docs preview for commit 0460e47 at: https://293c1362.typertiangolo.pages.dev |
📝 Docs preview for commit 6d87cfd at: https://126b3831.typertiangolo.pages.dev |
📝 Docs preview for commit cb05984 at: https://e1850eae.typertiangolo.pages.dev |
📝 Docs preview for commit 45e9736 at: https://d38a79ef.typertiangolo.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution @indiVar0508!
I tested this feature with the code from #523 and I added this example to the docs as docs_src/exceptions/tutorial005.py
. When running this on my system on master
, the output gets split up by artificial newlines:
However, setting pretty_exceptions_width=120
with this PR shows it more nicely:
So I think having this additional parameter makes sense. I'll leave the decision with Tiangolo though. I also added a unit test and a section in the docs, but I'm not 100% sure this is how we want it so I left some review comments where I was unsure.
If you want to control the width of the yellow and red Rich exception borders, you can set the parameter `pretty_exceptions_width` to a specific integer (it's 100 by default): | ||
|
||
```Python hl_lines="3" | ||
{!../docs_src/exceptions/tutorial005.py!} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, should we rename tutorial004 to 005 and call the new one from this PR 004?
``` | ||
|
||
This prevents artificial line breaks in cases where there is sufficient horizontal space on the console. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiangolo: I'm not sure whether we want to show output here in a <div class="termy">
, it gets a bit unwieldy.
runner = CliRunner() | ||
|
||
|
||
def test_traceback_rich_pretty_width(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test simply checks that the program runs like expected, but it doesn't (yet) actually test the Rich borders length as I wasn't quite sure how to do that 🤔
📝 Docs preview for commit b9d9fc0 at: https://ef0f8797.typertiangolo.pages.dev |
📝 Docs preview for commit ea2d475 at: https://a7fc6f5d.typertiangolo.pages.dev |
add parameter as suggested feature in issue #523