better exceptions

This commit is contained in:
Joe Kaufeld 2022-08-16 13:17:43 -04:00
parent 4580ab21a7
commit 8fffbb52a5

View File

@ -7,7 +7,7 @@ import uuid
import click
import httpx
from rich import pretty
from rich import print # yes, deliberately shadow `print`
from rich.traceback import install
from shiv.bootstrap import current_zipfile
import src
@ -24,24 +24,12 @@ from src.art import BANNERS
def main(ctx):
"""Launch a utility or drop into a command line REPL if no command is given."""
if ctx.invoked_subcommand is None:
def print_wrapper(*args, **kwargs):
# I know this is dumb.
# https://github.com/Textualize/rich/discussions/2462
if "crop" in kwargs:
del kwargs["crop"]
print(*args, **kwargs)
banner = random.choice(BANNERS)
# source of code.interact, just expanded to fit Rich in there
console = code.InteractiveConsole(globals())
console.print = print_wrapper
pretty.install(console) # type: ignore
try:
import readline
except ImportError:
pass
console.interact(banner, None)
pretty.install() # type: ignore
install() # traceback handler
code.interact(banner, None)
sys.exit()