-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Using Cleo instead of Argparse #452
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
Comments
Yeah I've been thinking about ditching argparse too. Why Cleo and not Click? |
I didn't use any of the two. So your choice. For me, cleo looks more good. |
Hi, could I take up this issue? However, it looks like |
@radiantly thanks so much for volunteering! This is a fairly major switch, so before you devote any time to it, I would like to have a discussion here about the pros and cons of each alternative. Why are we leaving argparse? Why should we take up any other library instead? Etc. |
Just to contribute to the discussion, you may want to take a look at typer, which wraps click :) |
@radiantly any updates on this? :) |
If the community comes to a decision, I can start working on the code. A brief look at the options mentioned above:
|
Thanks @radiantly. I do think that #620 does a good job at simplifying our argument parsing needs. There is a trade-off here between how hard it is to maintain our own code vs how robust and supported the underlying library is. Right now, our code is hard to maintain, but there is TONS of support for argparse since it is part of stdlib. If we change to click (or other), our code may become cleaner, but we run the risk of going with something outside of stdlib (and adding yet another dependency). @naveen521kk Can I ask you to please look at the argument parsing logic behind #620? Do you think that code is still too hard to maintain and we should incur in the risk of moving away from stdlib? |
I would suggest moving to another lib which is maintained would help us a lot in furture. For now, the current structure seems satisfying, but it would be difficult to add a new subcommand( I heard people working on addon system). Also, it will not hurt to add another dependency if it is more useful and keeps the logic simpler. Just because of an external dependency we should not make it hard to maintain also this looks like the same like that we picked rich. |
You are very convincing. I vote we go with the one that is the most supported, but let's do this after #620 is merged and stabilizes a bit. Cc @ManimCommunity/core to hear from others. |
I would highly recommend moving to another command line parsing library other than |
According to the all-dev call yesterday, whoever wants to rewrite CLI parsing has the go-ahead. |
From the cleo documentation:
I am strongly against introducing functionality in the docstrings, so I would vote against using cleo. Also, click seems to have a wider audience (and thus, possibly, better support). However, the person who works on this should have final say, so let's discuss once there's a PR 🙂 |
I'm preemptively assigning myself this task as I'm currently learning Click for a different FOSS project. Feel free to take this up anytime within the next week @radiantly before I start the refactoring. |
After some time familiarizing myself with Click, I believe Click would run into issues translating the current argparse CLI positional argument handling. For example: Currently, we manually intercept/filter commands and if the second argument matches one of the subcommands (i.e. {cfg,init,plugins}), we know that the argument is instead a subcommand -- not a positional arg like If the There is definitely a beauty in the simplistic notation of |
@jsonvillanueva It sounds like this is a bit more complicated than expected. However, could you clarify the following: if you can't figure out a way of making |
The alternative I currently see is to add the new subcommand, |
Could it be at all possible to support Right now, we have some hacky ways of supporting sub-commands. If the move to click/cleo makes the handling of sub-commands clean, but we need some hacky ways of supporting Unless others think that we should change to |
I've figured out how to hack/support using manim as both a command with non-required positional args and still use subcommands. Note, in argparse the
@ManimCommunity/core --- I can't seem to use the tag. What do you guys think? I think by design |
On the one hand, On the other hand, the entire purpose of the config files is to make the CLI usage faster. So an experienced user would be using So I'm of two minds about this, though I think I would like to still keep |
See, I'm entirely on the other side here. To me, |
I agree! It's just that 90% of the time it will just be redundant I think. I guess what I'm saying is that "manim" should be synonymous with "manim render". But whatever 🤷 |
ah. ok. |
I agree,
Implementation aside, I think making By the way the package click-default-group handles this nicer than I would've in manually recreating our current approach (i.e. manim is the render command). Also, there's other click-contrib packages that may be of interest including:
|
Currently, Manim uses Argparse for handling CLI arguments. It has been good but hard to maintain it, the currently introduced subcommands make it worse. Using something which was built for CLI management would help a lot of something like Cleo.
Cleo allows us to create beautiful and testable command-line commands. (Picked from docs) Where it uses
docstrings
to generate a command argument. (Bonus it allow autocompletion https://cleo.readthedocs.io/en/latest/introduction.html#autocompletion).Many projects use this for CLI for example poetry.
The text was updated successfully, but these errors were encountered: