kopia lustrzana https://github.com/simonw/datasette
Use optional rich dependency to render tracebacks, closes #1416
rodzic
a679d0de87
commit
54b6e96ee8
|
@ -81,6 +81,11 @@ from .tracer import AsgiTracer
|
||||||
from .plugins import pm, DEFAULT_PLUGINS, get_plugins
|
from .plugins import pm, DEFAULT_PLUGINS, get_plugins
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
|
|
||||||
|
try:
|
||||||
|
import rich
|
||||||
|
except ImportError:
|
||||||
|
rich = None
|
||||||
|
|
||||||
app_root = Path(__file__).parent.parent
|
app_root = Path(__file__).parent.parent
|
||||||
|
|
||||||
# https://github.com/simonw/datasette/issues/283#issuecomment-781591015
|
# https://github.com/simonw/datasette/issues/283#issuecomment-781591015
|
||||||
|
@ -1270,6 +1275,9 @@ class DatasetteRouter:
|
||||||
|
|
||||||
pdb.post_mortem(exception.__traceback__)
|
pdb.post_mortem(exception.__traceback__)
|
||||||
|
|
||||||
|
if rich is not None:
|
||||||
|
rich.console.Console().print_exception(show_locals=True)
|
||||||
|
|
||||||
title = None
|
title = None
|
||||||
if isinstance(exception, Forbidden):
|
if isinstance(exception, Forbidden):
|
||||||
status = 403
|
status = 403
|
||||||
|
|
|
@ -31,6 +31,14 @@ from .utils.sqlite import sqlite3
|
||||||
from .utils.testing import TestClient
|
from .utils.testing import TestClient
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
|
|
||||||
|
# Use Rich for tracebacks if it is installed
|
||||||
|
try:
|
||||||
|
from rich.traceback import install
|
||||||
|
|
||||||
|
install(show_locals=True)
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Config(click.ParamType):
|
class Config(click.ParamType):
|
||||||
# This will be removed in Datasette 1.0 in favour of class Setting
|
# This will be removed in Datasette 1.0 in favour of class Setting
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -75,6 +75,7 @@ setup(
|
||||||
"pytest-timeout>=1.4.2,<1.5",
|
"pytest-timeout>=1.4.2,<1.5",
|
||||||
"trustme>=0.7,<0.9",
|
"trustme>=0.7,<0.9",
|
||||||
],
|
],
|
||||||
|
"rich": ["rich"],
|
||||||
},
|
},
|
||||||
tests_require=["datasette[test]"],
|
tests_require=["datasette[test]"],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
|
Ładowanie…
Reference in New Issue