-
Notifications
You must be signed in to change notification settings - Fork 2.3k
POC: Implement Plugin using Hooks (with pluggy) #2635
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
POC: Implement Plugin using Hooks (with pluggy) #2635
Conversation
d2fbb84
to
3ab3b78
Compare
This uses pluggy to manage plugins, by implementing hooks, which the plugins can implement to modify the default behaviour in Manim. For now, there's only one hook `default_font()`, which plugins or even the users can define. REF: ManimCommunity#1133
3939fa8
to
3136a18
Compare
As an example of how this hook can be used. from manim import *
@pluggy_hookimpl
def default_font(requestor):
return 'Source code pro'
class HelloWorld(Scene):
def construct(self):
self.add(Text('Nice!')) All the |
…k/manim into pluggy-implementation
Sorry for the late reply. For what it is worth, I really like the cleaner approach! I think that it would be nice to have hooks in various places of the render loop such that plugins are able to modify this. I'm not as big of a fan when it comes to modification of default arguments of mobjects; in that context pluggy seems to be a bit overkill for my taste – but I'm happy to be convinced otherwise. A reasonable extension of the plugin interface probably only makes sense after we have at the very least decoupled the renderer and the scene some more (e.g., #2455); I'm not sure whether introducing hooks at this particular point would really the increase code quality of the project. |
I thought that this would be one of the best ways that plugins can control the styles of the mobject, see #279. For example, one can create a theme plugin (say a light theme), and all the mobjects created are now in light colours along with background and the user doesn't need to change each of them manually. Do you have a better suggestion for this situation?
Makes sense 👍. I've just made it as a Proof of concept so that I can build upon then when we really need it. |
Closing this for now but i linked it in the issue related to pluggy so we will not loose this PR and can reopen it later |
Overview: What does this pull request change?
This uses pluggy to manage plugins, by implementing hooks, which the plugins can implement to modify the default behaviour in Manim. For now, there's only one hook
default_font()
, which plugins or even the users can define.REF: #1133
Motivation and Explanation: Why and how do your changes improve the library?
This is a Proof of Concept and can be improved with more hooks added if we are going to follow this way. For example, we can make renderers as plugins, and this should allow renderers to be implemented as plugins. Another hook I could think of is a hook to configure the default colours of
Mobjects
, this would help plugins to have a theme defined which will be followed across all Mobject.Links to added or changed documentation pages
TODO
Further Information and Comments
We have to first decide whether we are going this way. We could also, go the monkey patching route (which we are currently doing), but those are problematic see https://pluggy.readthedocs.io/en/stable/#why-is-it-useful.
Reviewer Checklist