From f4b0bc64dc5edd560153ce8eca46e8eeeede5c11 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 25 Jul 2019 17:15:51 +0300 Subject: [PATCH] Renamed plugin_extra_options to extra_serve_options --- datasette/app.py | 4 ++-- datasette/cli.py | 4 ++-- docs/plugins.rst | 4 ++-- tests/fixtures.py | 6 +++--- tests/test_plugins.py | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 032c244a..d80b2094 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -151,7 +151,7 @@ class Datasette: memory=False, config=None, version_note=None, - plugin_extra_options=None, + extra_serve_options=None, ): immutables = immutables or [] self.files = tuple(files) + tuple(immutables) @@ -160,7 +160,7 @@ class Datasette: self.files = [MEMORY] elif memory: self.files = (MEMORY,) + self.files - self.plugin_extra_options = plugin_extra_options or {} + self.extra_serve_options = extra_serve_options or {} self.databases = {} self.inspect_data = inspect_data for file in self.files: diff --git a/datasette/cli.py b/datasette/cli.py index 68104aee..f478d496 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -312,7 +312,7 @@ def serve( config, version_note, help_config, - **plugin_extra_options, + **extra_serve_options, ): """Serve up specified SQLite database files with a web UI""" if help_config: @@ -359,7 +359,7 @@ def serve( config=dict(config), memory=memory, version_note=version_note, - plugin_extra_options=plugin_extra_options, + extra_serve_options=extra_serve_options, ) # Run async sanity checks - but only if we're not under pytest asyncio.get_event_loop().run_until_complete(ds.run_sanity_checks()) diff --git a/docs/plugins.rst b/docs/plugins.rst index ead0c569..72473a39 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -818,7 +818,7 @@ This example plugin adds a ``x-databases`` HTTP header listing the currently att extra_serve_options() ~~~~~~~~~~~~~~~~~~~~~ -Add extra Click options to the ``datasette serve`` command. Options you add here will be displayed in ``datasette serve --help`` and their values will be available to your plugin anywhere it can access the ``datasette`` object by reading from ``datasette.plugin_extra_options``. +Add extra Click options to the ``datasette serve`` command. Options you add here will be displayed in ``datasette serve --help`` and their values will be available to your plugin anywhere it can access the ``datasette`` object by reading from ``datasette.extra_serve_options``. .. code-block:: python @@ -850,7 +850,7 @@ Your other plugin hooks can then access these settings like so: @hookimpl def extra_template_vars(datasette): return { - "my_plugin_paths": datasette.plugin_extra_options.get("my_plugin_paths") or [] + "my_plugin_paths": datasette.extra_serve_options.get("my_plugin_paths") or [] } Be careful not to define an option which clashes with a Datasette default option, or with options provided by another plugin. For this reason we recommend using a common prefix for your plugin, as shown above. diff --git a/tests/fixtures.py b/tests/fixtures.py index 5a272e12..272458fe 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -108,7 +108,7 @@ def make_app_client( inspect_data=None, static_mounts=None, template_dir=None, - plugin_extra_options=None, + extra_serve_options=None, ): with tempfile.TemporaryDirectory() as tmpdir: filepath = os.path.join(tmpdir, filename) @@ -152,7 +152,7 @@ def make_app_client( inspect_data=inspect_data, static_mounts=static_mounts, template_dir=template_dir, - plugin_extra_options=plugin_extra_options, + extra_serve_options=extra_serve_options, ) ds.sqlite_functions.append(("sleep", 1, lambda n: time.sleep(float(n)))) client = TestClient(ds.app()) @@ -389,7 +389,7 @@ def extra_template_vars(template, database, table, view_name, request, datasette "extra_template_vars": json.dumps({ "template": template, "scope_path": request.scope["path"], - "plugin_extra_options": datasette.plugin_extra_options, + "extra_serve_options": datasette.extra_serve_options, }, default=lambda b: b.decode("utf8")) } """ diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 939b4627..b306963c 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -203,7 +203,7 @@ def test_plugins_extra_template_vars(restore_working_directory): assert { "template": "show_json.html", "scope_path": "/-/metadata", - "plugin_extra_options": {}, + "extra_serve_options": {}, } == extra_template_vars extra_template_vars_from_awaitable = json.loads( Soup(response.body, "html.parser") @@ -217,14 +217,14 @@ def test_plugins_extra_template_vars(restore_working_directory): } == extra_template_vars_from_awaitable -def test_plugin_extra_options_available_on_datasette(restore_working_directory): +def test_extra_serve_options_available_on_datasette(restore_working_directory): for client in make_app_client( template_dir=str(pathlib.Path(__file__).parent / "test_templates"), - plugin_extra_options={"foo": "bar"}, + extra_serve_options={"foo": "bar"}, ): response = client.get("/-/metadata") assert response.status == 200 extra_template_vars = json.loads( Soup(response.body, "html.parser").select("pre.extra_template_vars")[0].text ) - assert {"foo": "bar"} == extra_template_vars["plugin_extra_options"] + assert {"foo": "bar"} == extra_template_vars["extra_serve_options"]