-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Automatically import Plugins #967
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f162a23
Automatically import Plugins
naveen521kk fa2f24c
Fix Doc tests
naveen521kk 61b5b5e
clean manim.cfg
naveen521kk a5e2f73
Add more explanatory docs
naveen521kk 0477db0
add info about plugins site
naveen521kk 1205f68
use property method
naveen521kk c054c6f
use types module and f-strings
naveen521kk e5e4463
Add tests
naveen521kk 1852dfa
Merge branch 'master' of https://github.com/ManimCommunity/manim into…
naveen521kk 10c6f3f
lint
naveen521kk 75d341b
remove --plugins
naveen521kk d536827
fix doc tests
naveen521kk 4205490
don't define unnecessary variables
naveen521kk d818182
Merge branch 'master' of https://github.com/ManimCommunity/manim into…
naveen521kk 05e9241
Apply suggestions from code review
naveen521kk 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
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 was deleted.
Oops, something went wrong.
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 @@ | ||
from .import_plugins import * |
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,42 @@ | ||
import types | ||
from importlib import import_module | ||
|
||
import pkg_resources | ||
|
||
from .. import config, logger | ||
|
||
__all__ = [] | ||
|
||
|
||
plugins_requested: list = config["plugins"] | ||
if "" in plugins_requested: | ||
plugins_requested.remove("") | ||
for plugin in pkg_resources.iter_entry_points("manim.plugins"): | ||
if plugin.name not in plugins_requested: | ||
continue | ||
loaded_plugin = plugin.load() | ||
if isinstance(loaded_plugin, types.ModuleType): | ||
# it is a module so it can't be called | ||
# see if __all__ is defined | ||
# if it is defined use that to load all the modules necessary | ||
# essentially this would be similar to `from plugin import *`` | ||
# if not just import the module with the plugin name | ||
if hasattr(loaded_plugin, "__all__"): | ||
for thing in loaded_plugin.__all__: | ||
exec(f"{thing}=loaded_plugin.{thing}") | ||
__all__.append(thing) | ||
else: | ||
exec(f"{plugin.name}=loaded_plugin") | ||
__all__.append(plugin.name) | ||
elif isinstance(loaded_plugin, types.FunctionType): | ||
# call the function first | ||
# it will return a list of modules to add globally | ||
# finally add it | ||
lists = loaded_plugin() | ||
for l in lists: | ||
exec(f"{l.__name__}=l") | ||
__all__.append(l.__name__) | ||
plugins_requested.remove(plugin.name) | ||
else: | ||
if plugins_requested != []: | ||
logger.warning("Missing Plugins: %s", plugins_requested) |
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.