New 'datasette --pdb' option, closes #962

pull/977/head
Simon Willison 2020-09-11 11:37:55 -07:00
rodzic d0c752d50c
commit ca5c405d0f
4 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -191,10 +191,12 @@ class Datasette:
secret=None, secret=None,
version_note=None, version_note=None,
config_dir=None, config_dir=None,
pdb=False,
): ):
assert config_dir is None or isinstance( assert config_dir is None or isinstance(
config_dir, Path config_dir, Path
), "config_dir= should be a pathlib.Path" ), "config_dir= should be a pathlib.Path"
self.pdb = pdb
self._secret = secret or secrets.token_hex(32) self._secret = secret or secrets.token_hex(32)
self.files = tuple(files) + tuple(immutables or []) self.files = tuple(files) + tuple(immutables or [])
if config_dir: if config_dir:
@ -1057,6 +1059,11 @@ class DatasetteRouter:
await self.handle_500(request, send, exception or NotFound("404")) await self.handle_500(request, send, exception or NotFound("404"))
async def handle_500(self, request, send, exception): async def handle_500(self, request, send, exception):
if self.ds.pdb:
import pdb
pdb.post_mortem(exception.__traceback__)
title = None title = None
if isinstance(exception, NotFound): if isinstance(exception, NotFound):
status = 404 status = 404

Wyświetl plik

@ -352,6 +352,7 @@ def uninstall(packages, yes):
) )
@click.option("--version-note", help="Additional note to show on /-/versions") @click.option("--version-note", help="Additional note to show on /-/versions")
@click.option("--help-config", is_flag=True, help="Show available config options") @click.option("--help-config", is_flag=True, help="Show available config options")
@click.option("--pdb", is_flag=True, help="Launch debugger on any errors")
def serve( def serve(
files, files,
immutable, immutable,
@ -373,6 +374,7 @@ def serve(
get, get,
version_note, version_note,
help_config, help_config,
pdb,
return_instance=False, return_instance=False,
): ):
"""Serve up specified SQLite database files with a web UI""" """Serve up specified SQLite database files with a web UI"""
@ -418,6 +420,7 @@ def serve(
memory=memory, memory=memory,
secret=secret, secret=secret,
version_note=version_note, version_note=version_note,
pdb=pdb,
) )
# if files is a single directory, use that as config_dir= # if files is a single directory, use that as config_dir=

Wyświetl plik

@ -38,4 +38,5 @@ Options:
--version-note TEXT Additional note to show on /-/versions --version-note TEXT Additional note to show on /-/versions
--help-config Show available config options --help-config Show available config options
--pdb Launch debugger on any errors
--help Show this message and exit. --help Show this message and exit.

Wyświetl plik

@ -104,6 +104,7 @@ def test_metadata_yaml():
version_note=None, version_note=None,
get=None, get=None,
help_config=False, help_config=False,
pdb=False,
return_instance=True, return_instance=True,
) )
client = _TestClient(ds.app()) client = _TestClient(ds.app())