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

cli: sopel-plugins (basic version) #1588

Merged
merged 17 commits into from
Jul 21, 2019
Merged

Conversation

Exirel
Copy link
Contributor

@Exirel Exirel commented May 6, 2019

Should fix #244 and fix #1519 at the same time.

This PR adds a new command line to Sopel: sopel-plugins.

This command line supports 4 actions:

  • list, to list available plugins (all by default, or just enabled/disabled plugins)
  • show, to show detailed information about a plugin
  • configure, to run a config wizard for a plugin
  • enable, to enable a plugin
  • disable, to disable a plugin

In order to implement it, I had to update the plugin handlers, adding methods to get meta description. I think we could built from that to include other meta-data (such as version, author, etc.).

This is the first version of the command. I think it's better to stop here for now, let users test it, play with it, etc. and see what's asked.

In the future, I think we will need to rework how a plugin can expose the commands, URL callback, rules, and jobs to the outside world, but I don't want to do that in that PR, which is big enough as it is, and fairly usable to me.

sopel-plugins list

usage: sopel-plugins list [-h] [-c filename] [-C] [-e | -d] [-n]

List available Sopel plugins from all possible sources: built-in, from
``sopel_modules.*``, from ``sopel.plugins`` entry points, or Sopel's plugin
directories. Enabled plugins are displayed in green; disabled, in red.

optional arguments:
  -h, --help            show this help message and exit
  -c filename, --config filename
                        Use a specific configuration file
  -C, --no-color        Disable colors
  -e, --enabled-only    Display only enabled plugins
  -d, --disabled-only   Display only disabled plugins
  -n, --name-only       Display only plugin names

sopel-plugins show

usage: sopel-plugins show [-h] [-c filename] name

Show detailed information about a plugin.

positional arguments:
  name                  Plugin name

optional arguments:
  -h, --help            show this help message and exit
  -c filename, --config filename
                        Use a specific configuration file

sopel-plugins configure

usage: sopel-plugins configure [-h] [-c filename] name

Run a config wizard to configure a plugin. This can be used whether the plugin
is enabled or not.

positional arguments:
  name                  Plugin name

optional arguments:
  -h, --help            show this help message and exit
  -c filename, --config filename
                        Use a specific configuration file

sopel-plugins enable

usage: sopel-plugins enable [-h] [-c filename] [-a] name

Enable a Sopel plugin by its name, no matter where it comes from. The
``coretasks`` plugin is always enabled. By default, a plugin that is not
excluded is enabled, unless at least one plugin is defined in the
``core.enable`` list. In that case, Sopel uses a "allow-only" policy for
plugins, and enabled plugins must be added to this list.

positional arguments:
  name                  Name of the plugin to enable

optional arguments:
  -h, --help            show this help message and exit
  -c filename, --config filename
                        Use a specific configuration file
  -a, --allow-only      Enforce allow-only policy, adding the plugin to the
                        ``core.enable`` list.

sopel-plugins disable

usage: sopel-plugins disable [-h] [-c filename] [-f] [-r] name

Disable a Sopel plugin by its name, no matter where it comes from. It is not
possible to disable the ``coretasks`` plugin.

positional arguments:
  name                  Name of the plugin to disable

optional arguments:
  -h, --help            show this help message and exit
  -c filename, --config filename
                        Use a specific configuration file
  -f, --force           Force exclusion of the plugin. When ``core.enable`` is
                        defined, a plugin may be disabled without being
                        excluded. In this case, use this option to force its
                        exclusion.
  -r, --remove          Remove from ``core.enable`` list if applicable.

@Exirel Exirel added the Feature label May 6, 2019
@Exirel Exirel added this to the 7.0.0 milestone May 6, 2019
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple tiny line notes, but my main point of interest is in the future evolution of cli.utils.

I'm thinking maybe the formatting bits should go in a subpackage, like cli.utils.formatting or cli.utils.text? That would be a nice place to stick things like the ANSI escape-sequence constants—which should probably have all colors added, at least, if not other things too (bold; maybe also underline, etc.).

Also, isn't color 30 black, not gray? 🤔 (And it's not used anywhere, so if you were trying to add only the formatting functions you needed… ya missed one. 😜)

sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
@Exirel Exirel force-pushed the sopel-cli-plugin branch 2 times, most recently from cffac7f to e0bf601 Compare May 18, 2019 19:29
@Exirel
Copy link
Contributor Author

Exirel commented May 18, 2019

@dgw I changed the sopel-plugins list to have an output like this:

admin/python-module admin.py - Sopel Admin Module (sopel.modules.admin) [enabled]
coretasks/python-module Tasks that allow the bot to run, but aren't user-facing functionality (sopel.coretasks) [enabled]

and I use green for enabled plugins, red for disabled one, and yellow for enabled but that can't be loaded properly.

All I need now is #1564 to write the documentation.

@Exirel
Copy link
Contributor Author

Exirel commented Jul 8, 2019

Update: actually it needs #1646 to be merged so I can write the doc, then, it can be merged!

@Exirel Exirel force-pushed the sopel-cli-plugin branch from 374492b to 6889fe4 Compare July 8, 2019 21:50
@Exirel
Copy link
Contributor Author

Exirel commented Jul 8, 2019

I added a --name-only option to sopel-plugins list.

Next step before I can hit the "ready for review", is to implement a sopel-plugins show <plugin> subcommand.

@Exirel Exirel marked this pull request as ready for review July 9, 2019 21:19
@Exirel Exirel requested a review from dgw July 9, 2019 21:19
@Exirel
Copy link
Contributor Author

Exirel commented Jul 10, 2019

And now, with sopel-plugins configure <name> in order to fix #1519

@Exirel Exirel force-pushed the sopel-cli-plugin branch from c4fef65 to fbc7658 Compare July 17, 2019 18:54
@Exirel
Copy link
Contributor Author

Exirel commented Jul 17, 2019

And now with documentation! 🕺

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round! I can't run this through its paces on my CLI just yet, but I will between this and my next review.

This is all little stuff. I wouldn't even bother submitting before I can test the new CLI myself, but 1) I promised a review today and 2) there's a semi-important line note (the first one) that needs to be published anyway.

setup.py Show resolved Hide resolved
sopel/cli/plugins.py Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
test/plugins/test_plugins_handlers.py Outdated Show resolved Hide resolved
@Exirel Exirel force-pushed the sopel-cli-plugin branch 2 times, most recently from cb8eb71 to abcd818 Compare July 18, 2019 21:27
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're clearly working on this (or were very recently), I'll submit the notes I collected today.

I'm sure there will be more to come. Or maybe not… Depends on whether you want to do error-case handling and such in a future PR or just chuck it into this one. :)

sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Show resolved Hide resolved
Exirel added 9 commits July 21, 2019 00:50
Inspired by `apt list`, the `list` action now display the plugin list
like this:

    plugin-name/plugin-type label (source) [status]

where:

* `plugin-name` is the plugin's name, as used to enable/disable it
* `plugin-type` is the type of plugin handler used
* `label` is the plugin's label (once loaded)
* `source` can be either the python path to the module, or its filename
* `status` can be "enabled", "disabled", or "error" (in case of error on
  loading the plugin)

Colors are used on the plugin's name:

* green if the plugin is loaded properly and is enabled
* red if the plugin is disabled
* yellow if the plugin cannot be loaded properly but should be enabled

The error status is displayed in red if colors are activated.
@Exirel Exirel force-pushed the sopel-cli-plugin branch from a168c57 to ce41e85 Compare July 20, 2019 22:50
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we're down to nitpick territory. 🎉

I'll open a PR momentarily to take care of sopel-config being absent from the CLI docs, so we needn't worry about that particular conversation in this PR.

sopel/cli/plugins.py Outdated Show resolved Hide resolved
sopel/cli/plugins.py Outdated Show resolved Hide resolved
@dgw dgw force-pushed the sopel-cli-plugin branch from 0a5ecde to 4e2cd3f Compare July 21, 2019 19:34
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that a new PR would mean even more merge conflicts down the road, so I added sopel-config to the CLI docs myself in this PR, and also fixed the latest round of grammar nitpicks myself. 😁

@dgw dgw merged commit 52a5b27 into sopel-irc:master Jul 21, 2019
@Exirel Exirel deleted the sopel-cli-plugin branch September 5, 2019 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Configuring individual modules only? Make module whitelisting setup easier
2 participants