Skip to content

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

Closed

Conversation

naveen521kk
Copy link
Member

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

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@naveen521kk naveen521kk force-pushed the pluggy-implementation branch from d2fbb84 to 3ab3b78 Compare March 24, 2022 04:59
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
@naveen521kk naveen521kk force-pushed the pluggy-implementation branch from 3939fa8 to 3136a18 Compare March 24, 2022 05:02
@naveen521kk
Copy link
Member Author

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 Text would use Source code pro font.

@naveen521kk naveen521kk marked this pull request as draft March 24, 2022 05:39
@naveen521kk naveen521kk added the needs discussion Things which needs to be discussed before implemented. label Apr 15, 2022
@behackl
Copy link
Member

behackl commented Apr 21, 2022

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.

@naveen521kk
Copy link
Member Author

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.

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?

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.

Makes sense 👍. I've just made it as a Proof of concept so that I can build upon then when we really need it.

@MrDiver MrDiver linked an issue Jun 18, 2022 that may be closed by this pull request
@MrDiver
Copy link
Collaborator

MrDiver commented Jun 18, 2022

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

@MrDiver MrDiver closed this Jun 18, 2022
@naveen521kk naveen521kk deleted the pluggy-implementation branch June 19, 2022 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion Things which needs to be discussed before implemented.
Projects
Status: Rejected
Development

Successfully merging this pull request may close these issues.

Using pluggy for managing Plugins
3 participants