Refactor "Cogs" cog#484
Conversation
The cog now keeps a set of full qualified names of all extensions.
The converter fully qualifies the extension's name and ensures the extension exists. * Make the extensions set a module constant instead of an instant attribute and make it a frozenset. * Add a cog error handler to handle BadArgument locally and prevent the help command from showing for such errors.
* Store just the names rather than entire ModuleInfo objects * Fix prefix argument
* Rewrite docstrings for commands * Rename KEEP_LOADED to UNLOAD_BLACKLIST and make it a set * Change single quotes to double quotes * Add "cogs" as an alias to the extensions group
* Rename reload_all to batch_reload
* Simplify output format of batch reload with only 1 list of failures * Show success/failure emoji for batch reloads * Simplify logic in the manage() function * Clean up some imports
* Rename accordingly from cogs to extensions * Use the Extension converter * Make the argument variable instead of keyword-only
99455af to
82fb11c
Compare
MarkKoz
left a comment
There was a problem hiding this comment.
The extension names are displayed to the user as fully qualified (though commands accept unqualified names). The only exception is the list command, which always displays unqualified names. Is this OK? It was just simpler implementation-wise but wouldn't be a lot of code to add it either.
| except (commands.ExtensionAlreadyLoaded, commands.ExtensionNotLoaded): | ||
| if action is Action.RELOAD: | ||
| # When reloading, just load the extension if it was not loaded. | ||
| return self.manage(ext, Action.LOAD) |
There was a problem hiding this comment.
Is implicitly loading an extension if it isn't loaded undesirable behaviour? If not, another candidate would be to implicitly reload when !ext load is done on an already loaded extension.
There was a problem hiding this comment.
I think that the intention of loading the cog is clear when someone tries to reload a cog, so I don't mind this behavior. The alternative proposal, reloading when someone tries to load something, sounds more counter-intuitive to me. If I recall correctly, the previous version with the misnomer cogs denied both, but I often found it annoying that it wouldn't just load an extension on reload when it wasn't loaded.
There was a problem hiding this comment.
Yeah, I felt the same way with the second proposal. Leaving this unresolved for now in case anyone else has opinions to share.
There was a problem hiding this comment.
I think it's fine, too.
| except (commands.ExtensionAlreadyLoaded, commands.ExtensionNotLoaded): | ||
| if action is Action.RELOAD: | ||
| # When reloading, just load the extension if it was not loaded. | ||
| return self.manage(ext, Action.LOAD) |
There was a problem hiding this comment.
I think that the intention of loading the cog is clear when someone tries to reload a cog, so I don't mind this behavior. The alternative proposal, reloading when someone tries to load something, sounds more counter-intuitive to me. If I recall correctly, the previous version with the misnomer cogs denied both, but I often found it annoying that it wouldn't just load an extension on reload when it wasn't loaded.
* Rename batch_reload() to batch_manage() and make it accept an action as a parameter so that it can be a generic function. * Switch parameter order for manage() to make it consistent with batch_manage(). * Always call batch_manage() and make it defer to manage() when only 1 extension is given. * Make batch_manage() a regular method instead of a coroutine.
SebastiaanZ
left a comment
There was a problem hiding this comment.
Looks good to me. I think I've tested everything.
Notable user-facing changes:
*can be used to reload only all loaded extensions and**can be used to "reload" all extensions, even unloaded extensions.*is also given, a union will be done with all loaded extensions and the extensions named explicitly.reload_extension()is used for reloading, so if an error occurs while reloading, the extension will be reverted to its previously working state.Plan is to rename it to
extensionsand re-do it based on how I did it in another bot, which has less redundancy in terms of output messages:https://github.com/MarkKoz/d.py-test-bot/blob/master/testbot/extensions/manager.py
https://github.com/MarkKoz/d.py-test-bot/blob/master/testbot/utils/extensions.py