mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Renamed plugin_extra_options to extra_serve_options
This commit is contained in:
parent
a0fd07adc1
commit
f4b0bc64dc
5 changed files with 13 additions and 13 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
}
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue