kopia lustrzana https://github.com/simonw/datasette
datasette plugins --requirements, closes #2133
rodzic
19ab4552e2
commit
4a42476bb7
|
@ -223,15 +223,23 @@ pm.hook.publish_subcommand(publish=publish)
|
|||
|
||||
@cli.command()
|
||||
@click.option("--all", help="Include built-in default plugins", is_flag=True)
|
||||
@click.option(
|
||||
"--requirements", help="Output requirements.txt of installed 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):
|
||||
def plugins(all, requirements, plugins_dir):
|
||||
"""List currently installed plugins"""
|
||||
app = Datasette([], plugins_dir=plugins_dir)
|
||||
click.echo(json.dumps(app._plugins(all=all), indent=4))
|
||||
if requirements:
|
||||
for plugin in app._plugins():
|
||||
if plugin["version"]:
|
||||
click.echo("{}=={}".format(plugin["name"], plugin["version"]))
|
||||
else:
|
||||
click.echo(json.dumps(app._plugins(all=all), indent=4))
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
|
|
@ -282,6 +282,7 @@ Output JSON showing all currently installed plugins, their versions, whether the
|
|||
|
||||
Options:
|
||||
--all Include built-in default plugins
|
||||
--requirements Output requirements.txt of installed plugins
|
||||
--plugins-dir DIRECTORY Path to directory containing custom plugins
|
||||
--help Show this message and exit.
|
||||
|
||||
|
|
|
@ -90,7 +90,12 @@ You can see a list of installed plugins by navigating to the ``/-/plugins`` page
|
|||
|
||||
You can also use the ``datasette plugins`` command::
|
||||
|
||||
$ datasette plugins
|
||||
datasette plugins
|
||||
|
||||
Which outputs:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
[
|
||||
{
|
||||
"name": "datasette_json_html",
|
||||
|
@ -107,7 +112,8 @@ You can also use the ``datasette plugins`` command::
|
|||
cog.out("\n")
|
||||
result = CliRunner().invoke(cli.cli, ["plugins", "--all"])
|
||||
# cog.out() with text containing newlines was unindenting for some reason
|
||||
cog.outl("If you run ``datasette plugins --all`` it will include default plugins that ship as part of Datasette::\n")
|
||||
cog.outl("If you run ``datasette plugins --all`` it will include default plugins that ship as part of Datasette:\n")
|
||||
cog.outl(".. code-block:: json\n")
|
||||
plugins = [p for p in json.loads(result.output) if p["name"].startswith("datasette.")]
|
||||
indented = textwrap.indent(json.dumps(plugins, indent=4), " ")
|
||||
for line in indented.split("\n"):
|
||||
|
@ -115,7 +121,9 @@ You can also use the ``datasette plugins`` command::
|
|||
cog.out("\n\n")
|
||||
.. ]]]
|
||||
|
||||
If you run ``datasette plugins --all`` it will include default plugins that ship as part of Datasette::
|
||||
If you run ``datasette plugins --all`` it will include default plugins that ship as part of Datasette:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
[
|
||||
{
|
||||
|
@ -236,6 +244,22 @@ If you run ``datasette plugins --all`` it will include default plugins that ship
|
|||
|
||||
You can add the ``--plugins-dir=`` option to include any plugins found in that directory.
|
||||
|
||||
Add ``--requirements`` to output a list of installed plugins that can then be installed in another Datasette instance using ``datasette install -r requirements.txt``::
|
||||
|
||||
datasette plugins --requirements
|
||||
|
||||
The output will look something like this::
|
||||
|
||||
datasette-codespaces==0.1.1
|
||||
datasette-graphql==2.2
|
||||
datasette-json-html==1.0.1
|
||||
datasette-pretty-json==0.2.2
|
||||
datasette-x-forwarded-host==0.1
|
||||
|
||||
To write that to a ``requirements.txt`` file, run this::
|
||||
|
||||
datasette plugins --requirements > requirements.txt
|
||||
|
||||
.. _plugins_configuration:
|
||||
|
||||
Plugin configuration
|
||||
|
@ -390,7 +414,7 @@ Any values embedded in ``metadata.yaml`` will be visible to anyone who views the
|
|||
|
||||
If you are publishing your data using the :ref:`datasette publish <cli_publish>` family of commands, you can use the ``--plugin-secret`` option to set these secrets at publish time. For example, using Heroku you might run the following command::
|
||||
|
||||
$ datasette publish heroku my_database.db \
|
||||
datasette publish heroku my_database.db \
|
||||
--name my-heroku-app-demo \
|
||||
--install=datasette-auth-github \
|
||||
--plugin-secret datasette-auth-github client_id your_client_id \
|
||||
|
|
|
@ -108,6 +108,9 @@ def test_plugins_cli(app_client):
|
|||
assert set(names).issuperset({p["name"] for p in EXPECTED_PLUGINS})
|
||||
# And the following too:
|
||||
assert set(names).issuperset(DEFAULT_PLUGINS)
|
||||
# --requirements should be empty because there are no installed non-plugins-dir plugins
|
||||
result3 = runner.invoke(cli, ["plugins", "--requirements"])
|
||||
assert result3.output == ""
|
||||
|
||||
|
||||
def test_metadata_yaml():
|
||||
|
|
Ładowanie…
Reference in New Issue