Skip to content

Refactor "Cogs" cog#484

Merged
jchristgit merged 19 commits into
masterfrom
extensions-cog
Oct 11, 2019
Merged

Refactor "Cogs" cog#484
jchristgit merged 19 commits into
masterfrom
extensions-cog

Conversation

@MarkKoz
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz commented Oct 2, 2019

Notable user-facing changes:

  • Fixes The "Cogs" cog does not support loading of extensions which are packages instead of modules #479
  • Embeds have been ditched everywhere except for the list command.
  • Renamed to extensions because it really loads extensions, not cogs (cogs just happen to be inside extensions). The old cogs aliases are still available.
  • * can be used to reload only all loaded extensions and ** can be used to "reload" all extensions, even unloaded extensions.
  • Multiple names of extensions can be given to the reload command. If * is also given, a union will be done with all loaded extensions and the extensions named explicitly.
  • The fully qualified name of the extension is shown in response messages (e.g. confirmation/failure messages, errors, etc.). The list command is an exception and shows unqualified names.
  • When batch reloading, errors have been merged into a single list (no more distinction between load/unload errors).
  • reload_extension() is used for reloading, so if an error occurs while reloading, the extension will be reverted to its previously working state.
  • When reloading, if an extension was not initially loaded, it will be implicitly loaded anyway.

Plan is to rename it to extensions and 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

@MarkKoz MarkKoz added t: bug Something isn't working area: cogs labels Oct 2, 2019
MarkKoz added 14 commits October 3, 2019 15:08
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
Copy link
Copy Markdown
Contributor Author

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bot/cogs/extensions.py Outdated
Comment thread bot/cogs/extensions.py Outdated
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)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I felt the same way with the second proposal. Leaving this unresolved for now in case anyone else has opinions to share.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine, too.

Comment thread bot/cogs/alias.py
@MarkKoz MarkKoz marked this pull request as ready for review October 4, 2019 05:53
Comment thread bot/cogs/alias.py
Comment thread bot/cogs/extensions.py Outdated
Comment thread bot/cogs/extensions.py Outdated
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bot/cogs/extensions.py Outdated
Comment thread bot/cogs/extensions.py Outdated
Comment thread bot/cogs/extensions.py
* 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.
@MarkKoz MarkKoz requested a review from SebastiaanZ October 7, 2019 17:36
Copy link
Copy Markdown
Contributor

@SebastiaanZ SebastiaanZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I think I've tested everything.

Comment thread bot/cogs/extensions.py
Copy link
Copy Markdown
Contributor

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solid

@jchristgit jchristgit merged commit 20f815a into master Oct 11, 2019
@jchristgit jchristgit deleted the extensions-cog branch October 11, 2019 19:07
@jchristgit jchristgit self-assigned this Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The "Cogs" cog does not support loading of extensions which are packages instead of modules

6 participants