-
Notifications
You must be signed in to change notification settings - Fork 145
refactor: Bot.load_extensions rework
#796
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
Open
shiftinv
wants to merge
36
commits into
master
Choose a base branch
from
refactor/load-extensions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
67bea2f
refactor!: rewrite `Bot.load_extensions` and corresponding utils method
shiftinv 60e7622
feat: yield loaded extension names
shiftinv 0c9182b
fix: catch `ValueError` raised by `resolve_name` on 3.8
shiftinv 8b8db8f
fix: change exception types
shiftinv 5e2ada4
feat: add `return_exceptions` parameter
shiftinv 42ccd93
feat: discover all ext names first
shiftinv 82300de
chore: rename `walk_extensions` to `walk_modules`
shiftinv 9c4e784
docs: improve `walk_modules` docs
shiftinv f3b24db
fix: update `load_extensions` return type
shiftinv 33819be
fix: make `walk_modules:ignore` less complex
shiftinv 2b7d78a
feat: avoid duplicate `__path__` entries
shiftinv a09045e
fix(test): update walk_modules tests
shiftinv ea069ae
fix: un-deprecate `load_extensions(<path>)`
shiftinv 2ff26be
docs: improve exception documentation
shiftinv be6122e
fix: use proper error type
shiftinv 3610789
feat: update `test_bot.__main__`
shiftinv 460cdf3
fix: update module not found exception
shiftinv 3084698
feat: add `load_callback` parameter, remove iterator
shiftinv 7690556
refactor: move to separate find_extensions method for easier customiz…
shiftinv 08033a7
chore: use list instead of sequence
shiftinv 2f28f20
docs: mention find_extensions for customization
shiftinv b402320
chore(test): move directory utils to separate file
shiftinv e83249c
test: add some simple tests
shiftinv 3be2be5
fix: python 3.8 moment
shiftinv 413a5a3
docs: add changelog entries
shiftinv c6a779b
revert: remove `return_exceptions`, unnecessary complexity
shiftinv e159c7e
chore: move to separate documentation
shiftinv 1a3b309
fix: reinstate `utils.search_directory` for now
shiftinv 04b0bb3
Merge branch 'master' into refactor/load-extensions
shiftinv 7ceaa17
Merge remote-tracking branch 'upstream/master' into refactor/load-ext…
shiftinv bece2cf
feat: use tuple instead of list in `find_extensions`
shiftinv b008329
chore: invert condition to save one indent level
shiftinv 5db6b12
Merge remote-tracking branch 'upstream/master' into refactor/load-ext…
shiftinv 3f14848
Merge branch 'master' into refactor/load-extensions
onerandomusername d3a1127
Merge remote-tracking branch 'upstream/master' into refactor/load-ext…
shiftinv 4ed28a6
chore: resolve lint issues
shiftinv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| :func:`disnake.utils.search_directory` will be removed in a future version, in favor of :func:`disnake.ext.commands.Bot.find_extensions` which is the most common usecase and is more consistent. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| |commands| Improve :func:`Bot.load_extensions <ext.commands.Bot.load_extensions>`, add :func:`Bot.find_extensions <ext.commands.Bot.find_extensions>`. | ||
| - Better support for more complex extension hierarchies. | ||
| - New ``package``, ``ignore``, and ``load_callback`` parameters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # SPDX-License-Identifier: MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # SPDX-License-Identifier: MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| import asyncio | ||
| from pathlib import Path | ||
| from typing import Iterator | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
|
|
||
| from disnake.ext.commands import errors | ||
| from disnake.ext.commands.common_bot_base import CommonBotBase | ||
|
|
||
| from ... import helpers | ||
|
|
||
|
|
||
| class TestExtensions: | ||
| @pytest.fixture() | ||
| def module_root(self, tmpdir: Path) -> Iterator[str]: | ||
| with helpers.chdir_module(tmpdir): | ||
| yield str(tmpdir) | ||
|
|
||
| @pytest.fixture() | ||
| def bot(self): | ||
| with mock.patch.object(asyncio, "get_event_loop", mock.Mock()), mock.patch.object( | ||
| CommonBotBase, "_fill_owners", mock.Mock() | ||
| ): | ||
| bot = CommonBotBase() | ||
| return bot | ||
|
|
||
| def test_find_path_invalid(self, bot: CommonBotBase): | ||
| with pytest.raises(ValueError, match=r"Paths outside the cwd are not supported"): | ||
| bot.find_extensions("../../etc/passwd") | ||
|
|
||
| def test_find(self, bot: CommonBotBase, module_root: str): | ||
| helpers.create_dirs(module_root, {"test_cogs": {"__init__.py": "", "admin.py": ""}}) | ||
|
|
||
| assert bot.find_extensions("test_cogs") | ||
|
|
||
| with pytest.raises(errors.ExtensionError, match=r"Unable to find root module 'other_cogs'"): | ||
| bot.find_extensions("other_cogs") | ||
|
|
||
| with pytest.raises( | ||
| errors.ExtensionError, match=r"Module 'test_cogs.admin' is not a package" | ||
| ): | ||
| bot.find_extensions(".admin", package="test_cogs") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.