From f33a0a63a7442f0b665320ac3e2eb55de315f1f7 Mon Sep 17 00:00:00 2001 From: Russ Garrett Date: Sun, 28 Apr 2019 12:46:48 +0100 Subject: [PATCH] Add inspect and prepare_sanic hooks This adds two new plugin hooks: The `inspect` hook allows plugins to add data to the inspect dictionary. The `prepare_sanic` hook allows plugins to hook into the web router. I've attached a warning to this hook in the docs in light of #272 but I want this hook now... On quick inspection, I don't think it's worthwhile to try and make this hook independent of the web framework (but it looks like Starlette would make the hook implementation a bit nicer). Ref #14 --- datasette/app.py | 3 +++ datasette/hookspecs.py | 10 +++++++++ docs/plugins.rst | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/datasette/app.py b/datasette/app.py index 793bc931eb..5b3494b47f 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -443,6 +443,8 @@ def inspect(self): "views": inspect_views(conn), "tables": inspect_tables(conn, (self.metadata("databases") or {}).get(name, {})) } + for result in pm.hook.inspect(database=name, conn=conn, datasette=self): + self._inspect[name].update(result) except sqlite3.OperationalError as e: if (e.args[0] == 'no such module: VirtualSpatialIndex'): raise click.UsageError( @@ -716,6 +718,7 @@ async def handle_request(self, request, write_callback, stream_callback): RowView.as_view(self), r"///", ) + pm.hook.prepare_sanic(app=app, datasette=self) self.register_custom_units() # On 404 with a trailing slash redirect to path without that slash: diff --git a/datasette/hookspecs.py b/datasette/hookspecs.py index 6db9534457..886e3be1d8 100644 --- a/datasette/hookspecs.py +++ b/datasette/hookspecs.py @@ -30,6 +30,16 @@ def extra_body_script(template, database, table, datasette): "Extra JavaScript code to be included in