-
-
Notifications
You must be signed in to change notification settings - Fork 814
✨ Add option to set the width of the Rich exception output #528
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
Open
indiVar0508
wants to merge
29
commits into
fastapi:master
Choose a base branch
from
indiVar0508:fix_523
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
637a6a1
add `pretty_exceptions_width` to DeveloperExceptionConfig
indiVar0508 f4b44a4
add `pretty_exceptions_width` in Typer class
indiVar0508 0d209d8
add tutorial 005 to showcase pretty_exceptions_width
svlandeg 0460e47
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] 3e81d23
add comment about default value
svlandeg 0c82ef0
Merge branch 'fix_523' of https://github.com/indiVar0508/typer into f…
svlandeg 6d87cfd
Merge branch 'master' into fix_523
svlandeg cb05984
avoid F841 error
svlandeg 45e9736
add test case for new tutorial file
svlandeg b9d9fc0
fix coverage and unused var warnings
svlandeg ea2d475
fix test
svlandeg 1039c11
Merge branch 'master' into fix_523
svlandeg f037896
add PYTHONIOENCODING to env settings
svlandeg 96c0b5e
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] 4c4d1d5
Merge branch 'master' into fix_523
svlandeg 91c79fb
Merge branch 'fix_523' of https://github.com/indiVar0508/typer into f…
svlandeg fc4f3a6
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] 7b0679b
use MAX_WIDTH as default for Typer init
svlandeg 5914d78
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] e1eec6d
fix
svlandeg 1c58bdf
Merge branch 'fix_523' of https://github.com/indiVar0508/typer into f…
svlandeg 8872822
allow None as width
svlandeg be51839
remove print statement
svlandeg e9431c3
Merge branch 'master' into fix_523
svlandeg bcb816c
update docs format
svlandeg 16cb47f
avoid importing rich_utils too early
svlandeg b96cde2
Merge branch 'master' into fix_523
svlandeg b6e569d
Merge branch 'master' into fix_523
svlandeg d651993
fix
svlandeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import typer | ||
|
|
||
| app = typer.Typer(pretty_exceptions_width=120) | ||
|
|
||
|
|
||
| @app.command() | ||
| def main(name: str = "morty"): | ||
| deep_dict_or_json = { | ||
| "this_is_a_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "this_is_the_next_long_key": { | ||
| "and_once_again_a_very_long_key": { | ||
| "but_this_is_not_the_end": { | ||
| "end": True | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| print(name + deep_dict_or_json + 3) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from typer.testing import CliRunner | ||
|
|
||
| from docs_src.exceptions import tutorial005 as mod | ||
|
|
||
| runner = CliRunner() | ||
|
|
||
|
|
||
| def test_traceback_rich_pretty_width(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🤔 |
||
| file_path = Path(mod.__file__) | ||
| result = subprocess.run( | ||
| [sys.executable, "-m", "coverage", "run", str(file_path)], | ||
| capture_output=True, | ||
| encoding="utf-8", | ||
| env={ | ||
| **os.environ, | ||
| "_TYPER_STANDARD_TRACEBACK": "", | ||
| "PYTHONIOENCODING": "utf-8", | ||
| }, | ||
| ) | ||
|
|
||
| assert "print(name + deep_dict_or_json + 3)" in result.stderr | ||
| assert 'TypeError: can only concatenate str (not "dict") to str' in result.stderr | ||
| assert "name = 'morty'" in result.stderr | ||
|
|
||
|
|
||
| def test_script(): | ||
| result = subprocess.run( | ||
| [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], | ||
| capture_output=True, | ||
| encoding="utf-8", | ||
| ) | ||
| assert "Usage" in result.stdout | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.