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

✨ Add option to set the width of the Rich exception output #528

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

indiVar0508
Copy link

add parameter as suggested feature in issue #523

@github-actions
Copy link

github-actions bot commented Jan 7, 2023

📝 Docs preview for commit d82e751 at: https://63b9cedb2674445f42edea4e--typertiangolo.netlify.app

@github-actions
Copy link

github-actions bot commented Feb 2, 2023

📝 Docs preview for commit 36405da at: https://63dba78174f4db37545e5176--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 0e54ace at: https://63ef5180d07132579c80cd4c--typertiangolo.netlify.app

@github-actions
Copy link

github-actions bot commented Mar 4, 2023

📝 Docs preview for commit 7814341 at: https://64034f719f540d3ebc0ef662--typertiangolo.netlify.app

@indiVar0508
Copy link
Author

Hi @tiangolo ,
Did you get a chance to review this PR

@Napo2k
Copy link

Napo2k commented Feb 12, 2024

I definitely would like for this to be merged in! @tiangolo

@svlandeg svlandeg added feature New feature, enhancement or request p3 labels Mar 1, 2024
@nikita-b
Copy link

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.
@svlandeg svlandeg changed the title Add #523 ✨ Add a new parameter to set the width of the Rich exception output Apr 18, 2024
Copy link

📝 Docs preview for commit 0460e47 at: https://293c1362.typertiangolo.pages.dev

@svlandeg svlandeg changed the title ✨ Add a new parameter to set the width of the Rich exception output ✨ Add option to set the width of the Rich exception output Apr 18, 2024
Copy link

📝 Docs preview for commit 6d87cfd at: https://126b3831.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit cb05984 at: https://e1850eae.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit 45e9736 at: https://d38a79ef.typertiangolo.pages.dev

Copy link
Collaborator

@svlandeg svlandeg left a 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:

image

However, setting pretty_exceptions_width=120 with this PR shows it more nicely:

image

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!}
Copy link
Collaborator

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.

Copy link
Collaborator

@svlandeg svlandeg Apr 18, 2024

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():
Copy link
Collaborator

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 🤔

Copy link

📝 Docs preview for commit b9d9fc0 at: https://ef0f8797.typertiangolo.pages.dev

Copy link

📝 Docs preview for commit ea2d475 at: https://a7fc6f5d.typertiangolo.pages.dev

@svlandeg svlandeg linked an issue Apr 18, 2024 that may be closed by this pull request
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature, enhancement or request p3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New setting to increase the width of the rich (exception) output
4 participants