-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Automatically import Plugins #967
Conversation
Specify plugins using CLI and config file Signed-off-by: Naveen M K <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very knowledgeable about how plugins work and all that, so please bear with me if that shows overmuch. Generally I don't think I'm on board with plugins sharing manim's namespace; I think their own namespaces should be preserved somehow, but if that's not possible then I can live with that.
manim/plugins/import_plugins.py
Outdated
# 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 *`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the plugins' namespaces have to be eradicated? Because I'd rather they be preserved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like that to happen :)
Because users can also import plugins manually if there want its namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the result of the discussion on Discord was that we should use a config file to determine the default plugins that are imported/used (as well as manually using --plugins
to specify which plugins to use/import in the entry point)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm just not a fan of the possible namespace thrashing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind the potential namespace thrashing (some plugins like the manim-onlinetex @Aathish04 rely on this); however, I do mind the syntax highlighting issue this presents and I think others would too -- which is why I would opt for CLI to change the plugins/__init__.py
file which wouldn't hinder syntax highlighting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for CLI to change the plugins/init.py file which wouldn't hinder syntax highlighting
That is bad practice. Some package managers checksum the files it installs and doing so will break it. And other times things installed from the package manager isn't usually writable and it would need to run in sudo mode which may create unnecessary problems.
manim/plugins/import_plugins.py
Outdated
# 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}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried searching for a cleaner way to set local variables with dynamic names, unfortunately could not find one, and exec
seems to be the cleanest way. I'm not sure of the purpose of this review comment, I guess a general lamentation and a note to any others who might know of a cleaner way. Writing to locals()
, vars()
, or globals()
is explicitly discouraged by the python docs, so that's not an option. I'm not sure if maybe preserving plugins' namespaces would make this unnecessary?
Co-authored-by: friedkeenan <[email protected]>
I will add a test for these soon. |
it seems it is not possible currently to implement that
This is ready with a Test :) |
|
||
|
||
def cfg_file_create(cfg_file_contents, path): | ||
file_loc = (path / "manim.cfg").absolute() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally not too big a fan of the /
operator on paths, I like to make it more explicit like Path(path, "manim.cfg")
or you could use the .joinpath
method, but the way it currently is is still fine.
I'd point out the other places but I accidentally hit "Add single comment" on my first comment and now feel it might be weird to start a whole new separate review but also don't want to spam this so yeah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this way though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean yeah fair enough I'm just not too big a fan of it, I'm not at all staunchly against the /
operator here. Feel perfectly free to not change anything unless maybe someone else wants to throw in an opinion I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the library seems to use
Path(your_file_name) / "rest" / "of" / "path"
So I would just go for consistency here and do whatever is done mostly elsewhere in the codebase. Although, in general we should just have one style for these sorts of things.
Edit: This might not be mostly done elsewhere, but it is another way I've seen this done in the library.
In particular see: manim_directive.py
, utils.py
, sounds.py
, make_and_open_docs.py
, test_copy.py
, conftest.py
, and text_mobject.py
In other files, it seems to use @naveen521kk preferred syntax: test_img_and_svg.py
and test_cli_flags.py
.
However, keep in mind that using this feature will break syntax highlighting in the VS Code editor. If syntax highlighting is necessary, it's better to instead have this file (which defeats the purpose of this PR): from manim import *
from manim_plugintemplate.mobjects.dotgrid import DotGrid
class MyScene(Scene):
def construct(self):
grid = DotGrid()
self.add(grid)
self.wait() |
Co-authored-by: Leo Torres <[email protected]>
Motivation
Specify plugins using CLI and config file
This was discussed on Discord
Overview / Explanation for Changes
With
manim_plugintemplate
it can be used aspreviously this needs manual import of
manim_plugintemplate
Oneline Summary of Changes
Testing Status
Locally worked with a slight modification to plugin_template. Will make a PR there also. See ManimCommunity/manim-plugintemplate#6
cc @jsonvillanueva
Acknowledgements
Reviewer Checklist