Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request]datasette install plugins.json options #2133

Closed
HaveF opened this issue Aug 8, 2023 · 9 comments
Closed

[feature request]datasette install plugins.json options #2133

HaveF opened this issue Aug 8, 2023 · 9 comments

Comments

@HaveF
Copy link

HaveF commented Aug 8, 2023

Hi, simon ❤️

datasette plugins --all > plugins.json could generate all plugins info. On another machine, it would be great to install all plugins just by datasette install plugins.json

@simonw
Copy link
Owner

simonw commented Aug 9, 2023

Neat idea! We already have this command:

datasette install -r requirements.txt

So maybe datasetet plugins --requirements could generate a requirements.txt file which could be used there.

@simonw
Copy link
Owner

simonw commented Aug 9, 2023

diff --git a/datasette/cli.py b/datasette/cli.py
index 32266888..370b722c 100644
--- a/datasette/cli.py
+++ b/datasette/cli.py
@@ -223,15 +223,22 @@ 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():
+            click.echo("{}=={}".format(plugin["name"], plugin["version"]))
+    else:
+        click.echo(json.dumps(app._plugins(all=all), indent=4))
 
 
 @cli.command()

Output:

% datasette plugins --requirements  
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

@HaveF
Copy link
Author

HaveF commented Aug 9, 2023

Yes, using this approach(datasette install -r requirements.txt) will result in more consistency.

I'm curious about the results of the datasette plugins --all command. Where will we use the output of this command? Will it include configuration information for these plugins in the future? If so, will we need to consider the configuration of these plugins in addition to installing them on different computers?

@simonw
Copy link
Owner

simonw commented Aug 9, 2023

Honestly the --all option isn't particularly useful - it's really more of a debugging tool for myself than something that I expect anyone else to use.

The purpose of datasette plugins generally is to help people confirm that plugins installed correctly. It's effectively the CLI alternative to hitting https://datasette.io/-/plugins

@simonw
Copy link
Owner

simonw commented Aug 9, 2023

Plugin configuration itself currently lives in metadata.json which I don't like - that file was supposed to be for metadata about your databases, it's a bit of an accident that it grew configuration options as well.

I'm hoping to fix that for Datasette 1.0, but I'm still figuring out how to do that.

@simonw
Copy link
Owner

simonw commented Aug 9, 2023

Problem - if there are plugins in the plugins directory it was returning this:

messages_output_renderer.py==None
my_plugin.py==None
my_plugin_2.py==None
register_output_renderer.py==None
sleep_sql_function.py==None
view_name.py==None

@simonw
Copy link
Owner

simonw commented Aug 9, 2023

I'm going to have it only return plugins with a version other than None.

@simonw simonw closed this as completed in 4a42476 Aug 9, 2023
@simonw
Copy link
Owner

simonw commented Aug 9, 2023

Documentation: https://docs.datasette.io/en/latest/plugins.html#seeing-what-plugins-are-installed

@HaveF
Copy link
Author

HaveF commented Aug 10, 2023

It looks very nice now.
Finally, no more manual installation of plugins one by one. Thank you, Simon! ❤️

simonw added a commit that referenced this issue Aug 22, 2023
* API explorer requires view-instance permission

* Check database/table permissions on /-/api page

* Release notes for 1.0a4

Refs #2119, #2133, #2138, #2140

Refs GHSA-7ch3-7pp7-7cpq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants