-
-
Notifications
You must be signed in to change notification settings - Fork 403
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
plugin: reload using new interface #1490
Conversation
Each plugin has a name, but it might not be unique. These plugins have the same "name" (here, "xkcd"): * `sopel.modules.xkcd`, * `~/.sopel/modules/xkcd.py`, but only one can be loaded as the `xkcd` plugin. For that purpose, the previous implementation used a `dict`, without consideration for loading order. The new implementation uses an `OrderedDict`, to keep the same behavior (last plugin found overrides previous ones), but also to make sure to always load the core plugin at the end of the process.
Looking at issues:
Overall, "reload" in Python is very hard, and I'm not sure we can really fix it. There are too many use cases and corner cases where we don't have the right tools for that. |
b0e0f31
to
2b3b760
Compare
So, after further consideration, I've some issues to fix first. |
Makes sense to me. :) |
Based on #1479 - this PR starts at the
plugin: add AbstractPluginHandler.reload
commit.Using the new plugin interface defined in
sopel.plugins
, I replaced how plugins are reloaded insopel.modules.reload
:sopel.bot.Sopel
now exposes methods to add, remove, and reload pluginssopel.modules.reload
uses the bot's method to reload plugins (all of them, or only one)sopel.plugin.handlers.AbstractPluginHandler
defines a newreload
methodsopel.plugin.handlers.AbstractPluginHandler
's implementations use the bot's new methods to add or remove the pluginIt Is Not Perfect And Here Is Why
There are problems unsolved and questions unanswered here:
imp.reload
andimportlib.reload
do not remove names undefined in a new version of a reloaded module (fix possible only with Py3.4+),Problem 1: Reload Module Tree
This one is a big problem to solve, because there is more than meets the eye:
This leads me to conclude that
.reload
should not be used in production in these cases. And they are hard as hell to fix, or even to warn the user about.So it's half a problem, half a question. And I don't have the answer either way.
Problem 2: Python's
reload
Is WeirdNote: this behavior is the one currently in place in Sopel. This is not new.
Both
imp.reload
andimportlib.reload
have this weird behavior, explained by this line from the documentation (python2 reload / python3 importlib.reload):Meaning that:
something
, is loaded at Sopel's startupsomething
does not exist anymore.reload <this-module>
command is usedsomething
still exists and is seen by Sopel, no matter what we do,However, this can be fixed... with Python 3.4's public internals (namely,
importlib.util
andimportlib.machinery
) (see a snippet of code). By the way, using Py3.4's public machinery would fix Problem 1 too...Problem 3: Job Are Weird Too
Note: this behavior is the one currently in place in Sopel. This is not new.
I didn't change any of the "unregister a job" behavior, so this is something that requires more work. The good part is: this can be done in a future PR, without any consequences so far, because it's already like that right now.
Question: Does
.reload
Should Use Updated Configuration?In Sopel's current version,
.reload
uses the current configuration (potentially modified since startup), to gather a list of plugins:And that is a problem for me, because it means inconsistency and unexpected behavior. I would rather have something stable, that always work, in a predicable way, than the current behavior.
That's why this new version reloads the list of plugins as it exists at the moment in the bot's memory (ie. in
bot._plugins
). We could, if we want, change this behavior to unload a plugin (enabled or not), and to load only the plugin if it's still enabled, and enable all new enabled plugins.And that's the question: what should we do?