From 038682686a4c0b7477327ca33eff6588590bf73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Ra=C4=8Dinsk=C3=BD?= Date: Tue, 2 Apr 2024 18:25:52 +0200 Subject: [PATCH 1/2] fix: unifies the rich console between traceback and CLI --- typer/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/typer/main.py b/typer/main.py index ccf9f0956c..68f58cb923 100644 --- a/typer/main.py +++ b/typer/main.py @@ -38,10 +38,9 @@ try: import rich - from rich.console import Console from rich.traceback import Traceback - - console_stderr = Console(stderr=True) + from . import rich_utils + console_stderr = rich_utils._get_rich_console(stderr=True) except ImportError: # pragma: no cover rich = None # type: ignore @@ -69,12 +68,14 @@ def except_hook( supress_internal_dir_names = [typer_path, click_path] exc = exc_value if rich: + from .rich_utils import MAX_WIDTH rich_tb = Traceback.from_exception( type(exc), exc, exc.__traceback__, show_locals=exception_config.pretty_exceptions_show_locals, suppress=supress_internal_dir_names, + width=MAX_WIDTH, ) console_stderr.print(rich_tb) return From 8fbea8df8cc578a709c4e71d63b77178eb10fa13 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:29:07 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/typer/main.py b/typer/main.py index 68f58cb923..dc77143667 100644 --- a/typer/main.py +++ b/typer/main.py @@ -39,7 +39,9 @@ try: import rich from rich.traceback import Traceback + from . import rich_utils + console_stderr = rich_utils._get_rich_console(stderr=True) except ImportError: # pragma: no cover @@ -69,6 +71,7 @@ def except_hook( exc = exc_value if rich: from .rich_utils import MAX_WIDTH + rich_tb = Traceback.from_exception( type(exc), exc,