Refactor CogManager and extension loading #2446
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2446
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/cogmgr_refactor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This kicked off with me realising our use of
Loader.load_module()as a hacky way to import modules from random locations is deprecated. Looking closer, I realised there were a couple of smelly things here which could be cleaned up. Here's what's changed:redbot.ext_cogs.__path__. This means to import any external cog (from install path, cogmanager path, whatever), the import path would beredbot.ext_cogs.cog_to_import. It makes the rest of the logic really straightforward.importlib.import_module- this is a high-level function which allows us to delegate all of the nitty gritty import logic to Python itself, and it should be much more reliable. We're also no longer dealing withModuleSpecobjects, we just go straight from cog name to module.importlib.reloadto reload modules like a good boy. This is done from the bottom-up, twice, to make sure most internal imports in the package are updated. Some old imports could hang around if people do lazy relative importing at the module level.Red.load_extensioncan take either a module, or a straight name. This means loading a package is as simple asRed.load_extension(package_name), no more needing to know what method ofCogManagerto use.redbot.core.cog_manager.I haven't noticed any issues so far in using this, so it seems good. However, I would like to see some more widespread
battlefieldtesting with a variety of third party cogs and external modules before giving my 👍.This is ready for review again and will be targetting 3.2
I still have a few concerns with regard to using
importlib.reloadin this manner, but I also haven't seen this break any cogs which I use in any way which wouldn't already be broken with the current reload strategy. I'd like to do another pass over this later before merging it, but it should make the reload behavior of cogs more consistent from an end user standpoint at least.@ -615,0 +614,4 @@await setup(self)else:setup(self)except Exception as e:@Tobotimus is this something you are still actively working on or have you dropped this PR. Unsure whether you are currently working on this locally and just haven't pushed any commits.
Closing due to innactivity, Will convert into an issue so that other users can pick this up.
Pull request closed