From 909cc8fbdfc9c05e447f40e9a73489809602c3cd Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 26 Jan 2019 12:01:16 -0800 Subject: [PATCH] New 'datasette plugins' command to list installed plugins --- datasette/app.py | 7 +++++-- datasette/cli.py | 13 +++++++++++++ docs/plugins.rst | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 8252184c..7bbdef3e 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -369,7 +369,10 @@ class Datasette: }, } - def plugins(self): + def plugins(self, show_all=False): + ps = list(get_plugins(pm)) + if not show_all: + ps = [p for p in ps if p["name"] not in DEFAULT_PLUGINS] return [ { "name": p["name"], @@ -377,7 +380,7 @@ class Datasette: "templates": p["templates_path"] is not None, "version": p.get("version"), } - for p in get_plugins(pm) if p["name"] not in DEFAULT_PLUGINS + for p in ps ] async def execute( diff --git a/datasette/cli.py b/datasette/cli.py index 2cadabbf..34ed0020 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -159,6 +159,19 @@ def skeleton(files, metadata, sqlite_extensions): click.echo("Wrote skeleton to {}".format(metadata)) +@cli.command() +@click.option("--all", help="Include built-in default plugins", is_flag=True) +@click.option( + "--plugins-dir", + type=click.Path(exists=True, file_okay=False, dir_okay=True), + help="Path to directory containing custom plugins", +) +def plugins(all, plugins_dir): + "List currently available plugins" + app = Datasette([], plugins_dir=plugins_dir) + click.echo(json.dumps(app.plugins(all), indent=4)) + + @cli.command() @click.argument("files", type=click.Path(exists=True), nargs=-1, required=True) @click.option( diff --git a/docs/plugins.rst b/docs/plugins.rst index 0ec30434..6efa131b 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -58,6 +58,49 @@ Now you can navigate to http://localhost:8001/mydb and run this SQL:: To see the output of your plugin. +Seeing what plugins are installed +--------------------------------- + +You can see a list of installed plugins by navigating to the ``/-/plugins`` page of your Datasette instance - for example: https://fivethirtyeight.datasettes.com/-/plugins + +You can also use the ``datasette plugins`` command:: + + $ datasette plugins + [ + { + "name": "datasette_json_html", + "static": false, + "templates": false, + "version": "0.4.0" + } + ] + +If you run ``datasette plugins --all`` it will include default plugins that ship as part of Datasette:: + + $ datasette plugins --all + [ + { + "name": "datasette_json_html", + "static": false, + "templates": false, + "version": "0.4.0" + }, + { + "name": "datasette.publish.heroku", + "static": false, + "templates": false, + "version": null + }, + { + "name": "datasette.publish.now", + "static": false, + "templates": false, + "version": null + } + ] + +You can add the ``--plugins-dir=`` option to include any plugins found in that directory. + Packaging a plugin ------------------