Renamed plugin_extra_options to extra_serve_options

This commit is contained in:
Simon Willison 2019-07-25 17:15:51 +03:00
commit f4b0bc64dc
5 changed files with 13 additions and 13 deletions

View file

@ -151,7 +151,7 @@ class Datasette:
memory=False, memory=False,
config=None, config=None,
version_note=None, version_note=None,
plugin_extra_options=None, extra_serve_options=None,
): ):
immutables = immutables or [] immutables = immutables or []
self.files = tuple(files) + tuple(immutables) self.files = tuple(files) + tuple(immutables)
@ -160,7 +160,7 @@ class Datasette:
self.files = [MEMORY] self.files = [MEMORY]
elif memory: elif memory:
self.files = (MEMORY,) + self.files self.files = (MEMORY,) + self.files
self.plugin_extra_options = plugin_extra_options or {} self.extra_serve_options = extra_serve_options or {}
self.databases = {} self.databases = {}
self.inspect_data = inspect_data self.inspect_data = inspect_data
for file in self.files: for file in self.files:

View file

@ -312,7 +312,7 @@ def serve(
config, config,
version_note, version_note,
help_config, help_config,
**plugin_extra_options, **extra_serve_options,
): ):
"""Serve up specified SQLite database files with a web UI""" """Serve up specified SQLite database files with a web UI"""
if help_config: if help_config:
@ -359,7 +359,7 @@ def serve(
config=dict(config), config=dict(config),
memory=memory, memory=memory,
version_note=version_note, 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 # Run async sanity checks - but only if we're not under pytest
asyncio.get_event_loop().run_until_complete(ds.run_sanity_checks()) asyncio.get_event_loop().run_until_complete(ds.run_sanity_checks())

View file

@ -818,7 +818,7 @@ This example plugin adds a ``x-databases`` HTTP header listing the currently att
extra_serve_options() 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 .. code-block:: python
@ -850,7 +850,7 @@ Your other plugin hooks can then access these settings like so:
@hookimpl @hookimpl
def extra_template_vars(datasette): def extra_template_vars(datasette):
return { 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. 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.

View file

@ -108,7 +108,7 @@ def make_app_client(
inspect_data=None, inspect_data=None,
static_mounts=None, static_mounts=None,
template_dir=None, template_dir=None,
plugin_extra_options=None, extra_serve_options=None,
): ):
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
filepath = os.path.join(tmpdir, filename) filepath = os.path.join(tmpdir, filename)
@ -152,7 +152,7 @@ def make_app_client(
inspect_data=inspect_data, inspect_data=inspect_data,
static_mounts=static_mounts, static_mounts=static_mounts,
template_dir=template_dir, 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)))) ds.sqlite_functions.append(("sleep", 1, lambda n: time.sleep(float(n))))
client = TestClient(ds.app()) client = TestClient(ds.app())
@ -389,7 +389,7 @@ def extra_template_vars(template, database, table, view_name, request, datasette
"extra_template_vars": json.dumps({ "extra_template_vars": json.dumps({
"template": template, "template": template,
"scope_path": request.scope["path"], "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")) }, default=lambda b: b.decode("utf8"))
} }
""" """

View file

@ -203,7 +203,7 @@ def test_plugins_extra_template_vars(restore_working_directory):
assert { assert {
"template": "show_json.html", "template": "show_json.html",
"scope_path": "/-/metadata", "scope_path": "/-/metadata",
"plugin_extra_options": {}, "extra_serve_options": {},
} == extra_template_vars } == extra_template_vars
extra_template_vars_from_awaitable = json.loads( extra_template_vars_from_awaitable = json.loads(
Soup(response.body, "html.parser") Soup(response.body, "html.parser")
@ -217,14 +217,14 @@ def test_plugins_extra_template_vars(restore_working_directory):
} == extra_template_vars_from_awaitable } == 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( for client in make_app_client(
template_dir=str(pathlib.Path(__file__).parent / "test_templates"), template_dir=str(pathlib.Path(__file__).parent / "test_templates"),
plugin_extra_options={"foo": "bar"}, extra_serve_options={"foo": "bar"},
): ):
response = client.get("/-/metadata") response = client.get("/-/metadata")
assert response.status == 200 assert response.status == 200
extra_template_vars = json.loads( extra_template_vars = json.loads(
Soup(response.body, "html.parser").select("pre.extra_template_vars")[0].text 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"]