-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Clean up star imports #8
Comments
@initialcommit-io could you help me understand what the I think it is a I am a bit confused 😅 |
WIP -> branch clean_star_imports on my fork |
Thanks for this! I like what you did with And as for the And yes you're right it expects to be passed in a GitSim object, which inherits from MovingCameraScene from Manim. So yes, GitSim is actually a scene object that gets created in
As you can see the command line arguments The main reason for this is so that Manim scene actions can be taken within each of the base command class and individual command classes, such as Note that since the arguments were added directly to the scene too (maybe better to separate those honestly...), I currently access those like Let me know if that makes sense. In a nutshell the reason is so that the individual commands can get access to Manim scene methods, attributes, and functionality. |
I understand that we do not want to explicitly import every used object from the As for "not prefixing every Manim thing wirh Easy/quick to type, but we get all the advantages of not polluting our modules namespace with a star import 😁 the explicit import makes it much easier to see where an object is defined, and it helps against accidentally overriding an object (although I think the main advantage in our case would be improved readability). Also helps with static code analysis / type hints. Let me know what you think :) |
@initialcommit-io thanks for the explanation re: the scene objects. I think we can improve the class relationships there, I just ran into a circular import when trying to add type hints... Could the Right now the |
Great points and suggestions. Ok - you sold me on the star imports. Let's use For the GitSim class, the main reason I set it up this way is that I was thinking of each Git command class (like GitSimLog or GitSimReset) as representing a Git command itself wit corresponding Git functionality, not representing a Manim scene. Inheriting But I kind of like the design of having 1 overarching scene object, which the Git command classes can simply modify/add-to as needed. That's why I passed the scene instance in as an argument to the init... Thoughts? Can you think of any other way to preserve separate scene and Git command classes that would avoid the circular references you mentioned? |
Hi @initialcommit-io , I opened #17 for this issue. Regarding the class inheritance, I'll try to think of something, but I guess we can continue that discussion in a separate thread as it is not directly related to the star-imports 😃 |
@initialcommit-io I realize I am having difficulties wrapping my head around the nested classes and their (partially circular) references 🤪 Recently I stumbled upon Typer, which probably can simplify the whole command / subcommand / arguments stuff, but I experimented a bit with it and it would definitely require heavy changes (although I personally find the result much easier to reason about). |
@paketb0te Hmm can you identify more specifically what you mean by "partially circular references"? The only one I can think of is what we talked about before where the GitSim class passes itself into each Git subcommand instance, like Here is how I think about it: Program entry point: main.py
git_sim.py (contains the GitSim.py scene subclass)
git_sim_base_command:Contains common Git-Sim command attributes and methods to be shared by subclass commands, so basically all current and future Git subcommand classes (like GitSimStatus) will inherit from GitSimBaseCommand. These inherited methods can be (and are) overridden where necessary. git_sim_xyz:One of these is defined for each subcommand supported by Git-Sim. In general these will override the init and Finishing up:Once the code in the corresponding execute() method has finished running, flow goes back to the main.py for some final logic based on whether an image or video should be generated. One of the main reasons I did it this way was that originally I had all the code for each Git subcommand in it's own module, but that got to be very unruly when the number of commands grows, because every module ends up with minor changes and differences in their code, and sometimes a single change needs to be propagated to ALL files which is a nightmare for maintenance. The current setup allows most global changes to be done to the GitSimBaseCommand class, with the exception of changes to specific methods which have been overridden by a GitSimCommand class. So the main way I reason about the code when I need to figure out where something happens, is I open the corresponding file for the command I am working on, like GitSimAdd for "git add", then look straight at the BUT, I am curious what kind of other structures might be appropriate, while taking into account some of my design preferences regarding separation of scene and command, and also using inheritance to encapsulate the functionality for methods that are common to all (or many) commands. Can you provide a sample structure of how Typer would adjust the structure of this codebase? |
Yeah I was referring to that - it's not really a circular reference I guess, bad naming on my part. I'll try to hack something together to show what I think could be useful with Typer, might take a while though because I don't have much time the next days... |
Cool, looking forward to seeing it! I do think that if we decide to do a structural refactoring of the codebase we should do it earlier as opposed to later, while the codebase is still pretty small. |
Hi @initialcommit-io,
This is a really cool project and I#d like to contribute where I can!
One thing that struck me while looking at the code was that there seem to be quite a lot of "star imports" (
from foo import *
), which are considered bad practice AFAIK.They also make it much more difficult to infer what the exact types of the different objects are (since you can't have any type hints).
Would you mind if I clean those up a little bit and replace them with explicit imports?
The text was updated successfully, but these errors were encountered: