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

sopel: reduce and reorganize imports for critical modules #2179

Merged
merged 7 commits into from
Dec 21, 2021

Conversation

Exirel
Copy link
Contributor

@Exirel Exirel commented Aug 29, 2021

Description

Sopel has critical modules (sopel.bot, sopel.coretasks, etc.) and I wasn't really happy with their dependencies, starting with a dependency to sopel.loader. This is where I started: I tried to remove dependencies to loader when possible or necessary, and I followed that by reducing imports when possible, with few reorganization here and there.

This is not much, and some may argue that this isn't necessary. However, I'd rather take preventive action now against circular imports or dependency hell now than facing these issues later.

Also I had to extract privilege constants from sopel.plugin into their own module, which lead me to write some proper documentation about privileges.

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 have tested the functionality of the things this change touches

@Exirel Exirel added this to the 8.0.0 milestone Aug 29, 2021
@Exirel Exirel requested a review from dgw August 29, 2021 15:03
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.

OK, I pulled together a full review. Only took (I think) three sessions—which is shamefully inefficient on my part, but there has been a lot going on IRL and it's been hard to find time to focus on this stuff. Should be more or less caught up on unreviewed PRs after this, though. 🥳

sopel/plugin.py Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Show resolved Hide resolved
docs/source/plugin/privileges.rst Show resolved Hide resolved
docs/source/plugin/privileges.rst Outdated Show resolved Hide resolved
docs/source/plugin/privileges.rst Outdated Show resolved Hide resolved
docs/source/plugin/privileges.rst Outdated Show resolved Hide resolved
docs/source/plugin/privileges.rst Outdated Show resolved Hide resolved
@Exirel
Copy link
Contributor Author

Exirel commented Sep 22, 2021

Alright so, 2 topics to discuss that needs an action:

  • I like sopel.plugin as a shortcut and I think it makes sense to present that to plugin authors and to document it as such (i.e. keep using sopel.plugin in the doc). Action: keep or switch to sopel.privileges in the doc?
  • Plugin, handler, and name conflict: I wanted to prevent a conflict between from sopel import plugins, plugin and using the words plugins and plugin for variable name that would conflict with that (specifically in loops). Action: see below.

Name conflict resolutions

Before even talking about semantics, there is still a name conflict to deal with. There are 3 options:

  • keep it that way (handler, handlers for variable, plugin, plugins for module)
  • replace handler by plugin_handler, and handlers by plugin_handlers, no more conflict
  • use aliases from sopel import plugin as plugin_, plugins as plugins_ which I honestly hate but it exists

Semantics

There is a question behind this, which is "what is a Plugin Handler?", and with it, "what does it do?". I argue that a Plugin Handler is not a plugin, it's a handler: it's a proxy between Sopel and its plugins. I argue that its actions are to load, setup, configure, and shutdown the plugin that it handles, and that "plugin" is its action's target. When I read handler.load() I read it as "handler, load your plugin", and not "handler, load yourself". So, for me, there is no confusion, however it looks like it is for others.

"Hold up!" said @dgw "why is PyModulePlugin named like that, and not PyModulePluginHandler?" AH AH. Great question my friend: it's because they are internal names, and their "handlerness" comes from their module: handler.PyModulePlugin already tells me that it's a Handler, not a "plugin". I tend not to do repetition too much, like sopel.plugins.handlers.SopelPyModulePluginHandlerClass (I know, cheeky me!).

However... nothing is that simple, because I know there are functions that call handlers "plugins", which create inconsistency in Sopel's codebase. That's not new, but that's not great either.

@Exirel
Copy link
Contributor Author

Exirel commented Oct 21, 2021

@dgw before I rebase to fix conflict, would you consider my first question?

I like sopel.plugin as a shortcut and I think it makes sense to present that to plugin authors and to document it as such (i.e. keep using sopel.plugin in the doc). Action: keep or switch to sopel.privileges in the doc?

That would close a lot of comment, as I would either apply the changes or mark as resolved!

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 like sopel.plugin as a shortcut and I think it makes sense to present that to plugin authors and to document it as such (i.e. keep using sopel.plugin in the doc). Action: keep or switch to sopel.privileges in the doc?

I like the shortcut, too, but it seems to me that we should always document things as they appear in the docs—and these constants don't appear in the documentation for plugin any more after this change.


Marked up a couple little things that I noticed while idly scrolling around, thinking about the answer above.

sopel/privileges.py Outdated Show resolved Hide resolved
docs/source/plugin/privileges.rst Outdated Show resolved Hide resolved
@Exirel
Copy link
Contributor Author

Exirel commented Oct 22, 2021

I like the shortcut, too, but it seems to me that we should always document things as they appear in the docs—and these constants don't appear in the documentation for plugin any more after this change.

Alright, so I've to find a way to properly convey that information. Thanks!

@Exirel Exirel force-pushed the plugin-prevent-circular-imports branch from 4ec003a to 2277425 Compare October 22, 2021 08:22
@Exirel
Copy link
Contributor Author

Exirel commented Nov 13, 2021

  • changed "plugin" and "handler" to "plugin_handler" so it's less confusing for, hopefully, everyone
  • plugins.jobs and tools.jobs will be handled in a separate PR (in an undefined future time)
  • didn't rebase yet but there is a conflict to fix

ping @dgw for the follow up :)

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.

Turns out I had more thoughts left than expected—and that was after writing (then deleting) a whole thing about the plugin_jobs/tools_jobs thing that will be addressed in a separate patch.

docs/source/plugin/privileges.rst Show resolved Hide resolved
docs/source/plugin/privileges.rst Outdated Show resolved Hide resolved
docs/source/plugin/privileges.rst Show resolved Hide resolved
@Exirel Exirel force-pushed the plugin-prevent-circular-imports branch from 1e20f85 to 912f616 Compare December 16, 2021 14:59
@Exirel Exirel requested a review from dgw December 16, 2021 14:59
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 say if any typo or other mistake has eluded both of us for this long, it deserves to make it into master and then get patched out in X months when we finally notice. 😁

@Exirel Exirel mentioned this pull request Dec 17, 2021
4 tasks
@dgw dgw merged commit bdcf9b3 into sopel-irc:master Dec 21, 2021
@Exirel Exirel deleted the plugin-prevent-circular-imports branch January 20, 2022 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants