Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion typer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import rich

has_rich = True
from . import rich_utils

except ImportError: # pragma: no cover
has_rich = False
Expand Down Expand Up @@ -275,6 +274,8 @@ def get_docs_for_click(
def _parse_html(input_text: str) -> str:
if not has_rich: # pragma: no cover
return input_text
from . import rich_utils

return rich_utils.rich_to_html(input_text)


Expand Down
10 changes: 8 additions & 2 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
try:
import rich

from . import rich_utils

DEFAULT_MARKUP_MODE: MarkupMode = "rich"

except ImportError: # pragma: no cover
Expand Down Expand Up @@ -216,6 +214,8 @@ def _main(
raise
# Typer override
if rich and rich_markup_mode is not None:
from . import rich_utils

rich_utils.rich_format_error(e)
else:
e.show()
Expand Down Expand Up @@ -246,6 +246,8 @@ def _main(
raise
# Typer override
if rich and rich_markup_mode is not None:
from . import rich_utils

rich_utils.rich_abort_error()
else:
click.echo(_("Aborted!"), file=sys.stderr)
Expand Down Expand Up @@ -691,6 +693,8 @@ def main(
def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
if not rich or self.rich_markup_mode is None:
return super().format_help(ctx, formatter)
from . import rich_utils

return rich_utils.rich_format_help(
obj=self,
ctx=ctx,
Expand Down Expand Up @@ -754,6 +758,8 @@ def main(
def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
if not rich or self.rich_markup_mode is None:
return super().format_help(ctx, formatter)
from . import rich_utils

return rich_utils.rich_format_help(
obj=self,
ctx=ctx,
Expand Down
12 changes: 5 additions & 7 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@

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
rich = None # type: ignore
Expand Down Expand Up @@ -82,16 +77,19 @@ def except_hook(
supress_internal_dir_names = [typer_path, click_path]
exc = exc_value
if rich:
from .rich_utils import MAX_WIDTH
from rich.traceback import Traceback

from . import rich_utils

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,
width=rich_utils.MAX_WIDTH,
)
console_stderr = rich_utils._get_rich_console(stderr=True)
console_stderr.print(rich_tb)
return
tb_exc = traceback.TracebackException.from_exception(exc)
Expand Down
Loading