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

bot: fix per-channel configuration by plugin names #1840

Merged
merged 1 commit into from
Apr 10, 2020

Conversation

dgw
Copy link
Member

@dgw dgw commented Apr 8, 2020

Description

Annotate callables with the source plugin name during plugin registration. Use that name when applying per-channel configuration settings instead of the Python module name.

Old solution: Translates plugin names given in the config to the module names that would/will be returned by func.__module__, and uses those when filtering per-channel configuration.

Resolves #1839.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
    • I can't reasonably run make quality locally due to other long-term work on adding new flake8 checks that currently generate hundreds of warnings, so I'll leave this unchecked even though make test does pass.
  • I have tested the functionality of the things this change touches
    • Most of it. I made sure it works for core plugins and entry-point plugins, and the debug log output of module names I used to get this far tells me it should also work for sopel_modules plugins and single-file plugins (a few of which I have on my test install). The only wildcard should be folder plugins. This disclaimer does not apply to the replacement plugin_name attribute solution.

Other

The below comments are no longer relevant, but are kept for posterity.

I fully expect at least one method name to get bikeshedded. That's fine. My primary concern is making sure that the base principle of this change isn't complete lunacy. 😹

I'm also fully aware that @Exirel disagrees with this approach on principle—but I'm hoping that having a PR in which to discuss it will at least push us toward either accepting this one (perhaps with modifications) or developing a different kind of fix that we can ship relatively soon.

@dgw dgw added the Bugfix Generally, PRs that reference (and fix) one or more issue(s) label Apr 8, 2020
@dgw dgw added this to the 7.0.2 milestone Apr 8, 2020
@dgw dgw requested a review from a team April 8, 2020 05:20
@Exirel
Copy link
Contributor

Exirel commented Apr 9, 2020

I found what I disliked here, because the code is good but I wasn't happy about it. For me the problem is that it creates a hard coupling between a Plugin and a Python module, which is exactly what I wanted to avoid with entrypoint. It looks fine for now, because a) it fixes a bug that is properly annoying and b) it works fine with the current code without having to break anything. However, it has the side effect of blocking future options.

So that's a no for me. I've added more information on the bug #1839 about the context, and my suggested solution.

Sorry @dgw to delay the resolution further. :(

When this feature was first implemented, core plugins and user plugins
(from `~/.sopel/modules`) both loaded in a similar way. Their Python
module names matched the file names, and nobody thought to test how this
feature worked (or might not) for `sopel_modules` packages. Certainly,
no one thought to test entry-point plugins (new in 7.0, implemented
*after* this was).

To make a long story short (the full narrative is summarized in #1839),
this feature was never going to work as intended in all cases. Changes
to the plugin machinery simply made it *also* not work for core plugins,
which made the shortcomings of its implementation much more obvious.

Before passing the module contents back to `bot` during registration,
the `plugins.handlers.PyModulePlugin` class (and derivatives) now adds a
`plugin_name` attribute to each "relevant part" (callable). This is
immediately useful for improving the per-channel filtering so it works
as expected, and will likely find more use in the future (e.g. as a
substitute for the long-deprecated `bot.command_groups` property).

In `bot`, in addition to using the new callable attribute instead of
Python's module name for per-channel filtering, I also added log output
to debug mode for completeness.
@dgw dgw force-pushed the fix-channel-config-plugin-names branch from 26c4204 to 8776354 Compare April 9, 2020 21:32
@dgw
Copy link
Member Author

dgw commented Apr 9, 2020

@Exirel I think you'll be much happier with the replacement solution I just force-pushed. Or at least I hope you are, because the new approach is based directly on your suggestions! 😛

@dgw dgw merged commit 748a2c6 into 7.0.x Apr 10, 2020
@dgw dgw deleted the fix-channel-config-plugin-names branch April 10, 2020 05:42
@dgw dgw linked an issue Apr 11, 2020 that may be closed by this pull request
Exirel added a commit to Exirel/sopel that referenced this pull request May 18, 2020
The "_command_groups" attribute is used to generate the documentation
for plugin's command (there is an old piece of code for some
undocumented feature here but that's something else).

The problem is that it tries to derive the plugin's name from the Python
module the callable come from, instead of, you know, the actual plugin's
name.

Since we added the "plugin_name" attribute on all callable back in
8776354 (see sopel-irc#1840) we can now use it
safely for the command group.

One-line fix for you all!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Generally, PRs that reference (and fix) one or more issue(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Per-channel configuration doesn't work as expected/documented
2 participants