-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Per-channel configuration doesn't work as expected/documented #1839
Comments
Sadly, this is not true. Before I replied, I read both PR #1479 and #1235, and I've to say that the bug, as described here, is actually what was implemented in the first place in #1235. The reason is: that's how Python works. More general information about that in the Python documentation. Here is an example, taken from Sopel's source code:
What the code does is it looks to the function's
Same plugin name, not the same I'd argue that this feature requires a complete rework, and that your solution of adding a |
Note that if we consider that, prior to #1479, this worked for both And the lack of tests didn't help. :( |
Splitting hairs, I was half-right about it working before #1479 because it made core plugins behave differently from user plugins. But that doesn't help fix the bug. 😛 Per discussion here, in #1840, and on IRC, I'll work on the |
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.
Closing keyword in #1840 didn't work |
Description
It is not possible (any longer?) to use just the plugin name in per-channel configuration.
Reproduction steps
#channel
#channel
is any different from before.Expected behavior
Per the intended functionality of this feature, and according to the website documentation, this configuration should prevent the use of all
emoticons
commands and block automatic link title fetching in the#channel
channel.Environment
.version
: 7.0.1.dev07.0.x
branch/version
: n/aNotes
The problem stems from use of
func.__module__
in the code that applies these restrictions:sopel/sopel/bot.py
Lines 567 to 587 in c705f45
func.__module__
used to be justpluginname
for plugin callables, but that is clearly no longer the case. Now,func.__module__
for a core plugin likeurl
is the full module path,sopel.modules.url
. (It probably changed with #1479 and associated work, but I haven't verified that with agit bisect
or anything. Circumstantially, #1235 implemented this long before #1479 altered the plugin mechanics, and multiple reports confirm that this used to work as documented.)Initial implementation ideas
The immediately obvious solution is to add an attribute to each plugin callable during loading, containing the plugin name as expected by this feature's code. Presumably, being able to tell which plugin a callable came from would be useful for future features too.
Alternatively, the bot's internal tracking of loaded plugins could include a way to translate module names into plugin names. I'm partial to the first solution because retrieving an attribute of the function currently being processed is probably cheaper from a performance perspective, and logically clearer than performing a lookup on some (probably) dict stored in the bot's global state.
But either idea would work for the current version. I really don't want to wait to fix this until @Exirel's very admirable goal of refactoring plugins from "bunch of callables with attributes" to "actual Plugin object with state & behavior" happens in 8.0 or 9.0. 😅
The text was updated successfully, but these errors were encountered: