mirror of
https://github.com/initialcommit-com/git-sim.git
synced 2026-04-27 03:25:53 +03:00
[GH-ISSUE #38] [Refactoring] Change inheritance structure? #28
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/git-sim#28
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @paketb0te on GitHub (Jan 27, 2023).
Original GitHub issue: https://github.com/initialcommit-com/git-sim/issues/38
@initialcommit-io Following our discussion in #8, I have created an example of what I think would be a simpler way of handling class inheritance - see my branch inheritance (only
git-sim logfor now).Basically I did the following:
GitSimBaseCommanda ManimMovingCameraSceneself.sceneinGitSimBaseCommandwithself.GitSimBaseCommandtakesargsinstead ofsceneas argument to its__init__()GitSimLogpassesargsinstead ofsceneto itssuper().__init__()GitSimclass to select the correct subclass for each commandNot sure if that makes sense, but at least my brain can process it better like this 😆
Using Typer to make the whole argument- and option-handling easier could be a next step, but I think this would be a great starting point, if you are interested / if it makes sense to you.
Obviously there is no point in changing that up only so that I understand it better, so I'd highly appreciate any feedback!
@initialcommit-io commented on GitHub (Jan 27, 2023):
Great summary @paketb0te !
After reviewing I do like this better than the current setup for now, it's clearer and more straightforward - great suggestion! Although I do like the idea of separation of Manim scene from the GitSimCommand, I think in essence a scene can be thought of as an inherent part of a Git-Sim simulation/command, so it can make sense to combine it and think about it that way.
Can you take care of the refactor for this in a new PR?
Random thought: For the forseeable future I do see the project relying on Manim, but I do wonder if down the line it might be useful to keep our options open for plugging in other animation libraries, and even maybe making that a customizable thing. We could potentially do this by abstracting out the animation library, and in that kind of setup it might be worth thinking about a way to separate the actual "drawing and animating" stuff from the "git command stuff". I think that is sort of what I was going for with my current design, but obviously it's still pretty tightly coupled...
Do you have any thoughts on the design for keeping our options open/flexible to something like this down the line?
@paketb0te commented on GitHub (Jan 28, 2023):
Glad to hear you like it!
Actually I just realised that maybe I was a bit over-eager...
What confused me was that we set
self.args = argsinGitSim's__init__(), and then access the args and everything contained ther asself.scene.args.fooin theGitSimBaseCommandclass.Maybe
GitSimBaseCommandcan initialize a newMovingCameraSceneinstead of being passed one - the only thing happening before is the setting of the args insGitSim:So, maybe we just need to separate the
argsfrom thescene? 🤔And to select the right subclass, we could still use
get_scene_for_command()as in my example:Thoughts?
@initialcommit-io commented on GitHub (Jan 28, 2023):
@paketb0te Hmm so yeah this sort of brings up something I forgot to mention before - that the GitSim class isn't just an "empty" class - it's the scene that has its
construct()method called by Manim. As far as I know, all of the animation stuff that goes into a scene needs to be called from within a construct() method, so you can think of the GitSim class as kind of a wrapper class for that, and to choose which subcommand functionality to actually run based onargs, then finally feed in the scene object and args into the GitSimCommand flow.The main reason I made GitSim a class and not a function is that it needs to have the
construct()method in order to kick off Manim's scene generation process.If GitSimBaseCommand inherits the MovingCameraScene then its own construct() method would need to be called, and it just seemed weird for a Git command class to have all these manim members as a part of it.
In the method you proposed above, where does the
construct()live that gets called?@paketb0te commented on GitHub (Jan 28, 2023):
Ah, I see.
If we need a subclass of the Manim Scene, I guess the approach to make
GitSimBaseCommanda subclass ofm.MovingCameraScene(and then subclassing the individualGitSimFooclasses for each command from that) works better.@paketb0te commented on GitHub (Jan 28, 2023):
@initialcommit-io just to make sure we are on the same page: We go ahead with the "original" idea of this issue as described in my first comment (
GitSimBaseCommandinherits fromm.MovingCameraScene, and then the class for each command inherits from that)?@initialcommit-io commented on GitHub (Jan 28, 2023):
@paketb0te Yeah let's try it! So I guess you will be adding a
construct()method into the GitSimBaseCommand which just calls theexecute()method.Then I think we can get rid of the
git_sim.pyentirely and move the command selectionifstatement into__main__.py, which would just directly instantiate the command class and pass in the args.Let me know if I'm missing anything...
@paketb0te commented on GitHub (Jan 28, 2023):
Yeah basically that.
If I understand the docs for the
Sceneclass correctly, we only need to override theconstruct()method (which contains all the animation logic) and could skip theexecute()method?E.g.
Since that could be a bit confusing with the passed
args, maybe we can create adataclassthat stores all the options / flags that are gathered from argparse?(We could then later change that to be a pydantic
BaseSettingsclass (which automatically parses env vars with the same name as the specified attributes) 😁I'll see what I can do the next few days.
@initialcommit-io commented on GitHub (Jan 28, 2023):
@paketb0te Yes I guess we only really do need
construct(). In that case, you'll just be replacing theexecute()methods (which aren't Manim methods - it's just a custom method I made up to make a call from the originalGitSimclass) withconstruct().And yes I think getting args into the mix is our last remaining puzzle piece at the moment. It is a little messy to have to pass the args into the Git command class when it overrides init from the GitSimBaseCommand class, not sure if there is a cleaner way. I'm open to either of the options you suggested if you want to take a crack at it we can review when ready.
Thanks again!!!
@initialcommit-io commented on GitHub (Jan 29, 2023):
Thanks for this! Changes merged.