Skip to content

Commit

Permalink
/-/plugins now shows details of hooks, closes #794
Browse files Browse the repository at this point in the history
Also added /-/plugins?all=1 parameter to see default plugins.
  • Loading branch information
simonw committed Jun 2, 2020
1 parent 9dd6d1a commit 69aa027
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
9 changes: 6 additions & 3 deletions datasette/app.py
Expand Up @@ -626,16 +626,17 @@ def _versions(self):
},
}

def _plugins(self, show_all=False):
def _plugins(self, request):
ps = list(get_plugins())
if not show_all:
if not request.args.get("all"):
ps = [p for p in ps if p["name"] not in DEFAULT_PLUGINS]
return [
{
"name": p["name"],
"static": p["static_path"] is not None,
"templates": p["templates_path"] is not None,
"version": p.get("version"),
"hooks": p["hooks"],
}
for p in ps
]
Expand Down Expand Up @@ -823,7 +824,9 @@ def add_route(view, regex):
r"/-/versions(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "plugins.json", self._plugins),
JsonDataView.as_asgi(
self, "plugins.json", self._plugins, needs_request=True
),
r"/-/plugins(?P<as_format>(\.json)?)$",
)
add_route(
Expand Down
1 change: 1 addition & 0 deletions datasette/plugins.py
Expand Up @@ -49,6 +49,7 @@ def get_plugins():
"name": plugin.__name__,
"static_path": static_path,
"templates_path": templates_path,
"hooks": [h.name for h in pm.get_hookcallers(plugin)],
}
distinfo = plugin_to_distinfo.get(plugin)
if distinfo:
Expand Down
5 changes: 4 additions & 1 deletion docs/introspection.rst
Expand Up @@ -78,10 +78,13 @@ Shows a list of currently installed plugins and their versions. `Plugins example
"name": "datasette_cluster_map",
"static": true,
"templates": false,
"version": "0.4"
"version": "0.10",
"hooks": ["extra_css_urls", "extra_js_urls", "extra_body_script"]
}
]
Add ``?all=1`` to include details of the default plugins baked into Datasette.

.. _JsonDataView_config:

/-/config
Expand Down
61 changes: 53 additions & 8 deletions tests/test_api.py
Expand Up @@ -1260,14 +1260,59 @@ def test_threads_json(app_client):
def test_plugins_json(app_client):
response = app_client.get("/-/plugins.json")
expected = [
{"name": name, "static": False, "templates": False, "version": None}
for name in (
"messages_output_renderer.py",
"my_plugin.py",
"my_plugin_2.py",
"register_output_renderer.py",
"view_name.py",
)
{
"name": "messages_output_renderer.py",
"static": False,
"templates": False,
"version": None,
"hooks": ["register_output_renderer"],
},
{
"name": "my_plugin.py",
"static": False,
"templates": False,
"version": None,
"hooks": [
"actor_from_request",
"extra_body_script",
"extra_css_urls",
"extra_js_urls",
"extra_template_vars",
"permission_allowed",
"prepare_connection",
"prepare_jinja2_environment",
"register_facet_classes",
"render_cell",
],
},
{
"name": "my_plugin_2.py",
"static": False,
"templates": False,
"version": None,
"hooks": [
"actor_from_request",
"asgi_wrapper",
"extra_js_urls",
"extra_template_vars",
"permission_allowed",
"render_cell",
],
},
{
"name": "register_output_renderer.py",
"static": False,
"templates": False,
"version": None,
"hooks": ["register_output_renderer"],
},
{
"name": "view_name.py",
"static": False,
"templates": False,
"version": None,
"hooks": ["extra_template_vars"],
},
]
assert expected == sorted(response.json, key=lambda p: p["name"])

Expand Down

0 comments on commit 69aa027

Please sign in to comment.