Replies: 6 comments 6 replies
-
One of the main issues highlighted by the mailing list discussion is the dependencies added by such frameworks that aren't part of the standard library, and the recurring problems in general with Python modules that evolve without backwards-compatible support. If users need to set up a One approach of course to mitigate this is the 3rd option to stick to argparse, but we also know this makes the implementation more complex and to some extent the command line user experience is not as good. Arguably, Typer adds some usability and can help provide some user flows on the command line rather than with a web dashboard - or as a complement to it. It's interesting to also consider ways to use such frameworks without impacting the users with all the dependencies, such as including the dependencies directly in the KernelCI package or providing a "plain" tool based only on argparse and a "fancy" one with optional dependencies for users who have it installed. These ideas might not be very practical, a bit of investigation would need to be done to get to the bottom of pros/cons there. Regardless of which implementation framework we choose, we can already start proposing a stable design for the |
Beta Was this translation helpful? Give feedback.
-
For completeness, I tried to write an equivalent PoC using Handling the TOML settings for default values seems a lot more brittle there as it's replacing object attributes in the args namespace. Then the idea of having the subcommands path as a TOML section isn't really practical without a lot more work so the sections are called Basically, Click has huge benefits over argparse. It makes the implementation much simpler and provides a much nicer user experience. Then Typer just builds on top of Click so it just goes a bit further with flashy extra features. The Click project was created nearly 10 years ago and has over 1 million projects listed on GitHub as users and 340 contributors. Several well-supported and broadly used tools depend on it such as The Typer project seems to be a lot less used and it's not in Debian, so while it might be really nice with auto-completion and improved error handling and auto-generated help, it might be harder to adopt due to the effort required to install it. |
Beta Was this translation helpful? Give feedback.
-
As of today, if we include one additional vote for argparse from the mailing list discussion, we basically have 3 votes for each option: Click, Typer and argparse. Here's a summary with pros / cons of each solution based on the discussions so far: ClickPros:
Cons:
TyperPros:
Cons:
argparsePros:
Cons:
|
Beta Was this translation helpful? Give feedback.
-
Meanwhile we've started looking into the So what I would propose is to start with Click using the version currently in Debian Stable (v8.1.3) as it has so many advantages over argparse. Then if users find the Click dependencies too cumbersome, we may consider bundling it directly with the |
Beta Was this translation helpful? Give feedback.
-
In my opinion Click would be the best middle ground between barebones |
Beta Was this translation helpful? Give feedback.
-
OK I think we can resolve this now, and re-open in case some more discussion is needed. |
Beta Was this translation helpful? Give feedback.
-
This is not a "Trick or Treat" question :) The
kci
command line tool is to go hand-in-hand with the new API and as such we still have a few weeks to refine it and come up with a user-friendly design. Ideally, the main choices should be made by the end of October so we can have a first stable version available in December at the same time as the API production release candidate.As part of this work, I've read some advice and guidelines from several places including clig.dev. The legacy KernelCI command line tools are based on the standard library
argparse
which works well but has some limitations. In particular, nested sub-commands like we need forkci
is a bit tedious to implement. Assuming we're keeping the code as Python, it seems like the best alternatives would be Click and Typer which itself is based on Click. They have a few dependencies but they would seem worth adding to the project as they're quite common and lightweight ones.See also the mailing list discussion.
Roadmap issue: kernelci/kernelci-core#2125
Option 1: Click
Here's an RFC if you want to try it out: kernelci/kernelci-core#2111
Basically, a typical command using an API token can be implemented this way with a custom class
KciSecrets
to handle settings files and pass secrets to the function:The help message looks like this, basically the same as with
argparse
:Then when running it, with a TOML settings file containing the API token:
In summary, this basically provides a similar user experience as with
argparse
but with a cleaner and simpler implementation. It makes the command line design easier to implement so it can remove some burden with nested commands and default values in TOML etc. It should also help users write their own commands or contribute to the code base.The only downside found so far is that it adds some external package dependency, as
argparse
is in the Python 3 standard library but Click is not. This should be a very minor thing though. Most distros already have a Click package (Debian Bookworm has v8.1.3).Option 2: Typer
Here's an RFC if you want to try it out: kernelci/kernelci-core#2112
The equivalent implementation for the
whoami
command looks like this:So it's arguably even simpler than with Click without losing any of the flexibility. As Typer uses
rich
to format its output (help, errors etc.) it seemed worthwhile also using it to show the output here too. Here are some sample commands with screenshots to show the full colours (secrets
is a special hidden argument added byKciSecrets
automatically so it's not shown in the help message):Then it has some nice ways to handle errors and even suggest what the user got wrong:
Then on top of this, it provides a straightforward way to install auto-completion:
This appears to be just expanding possibilities on top of the Click implementation with no big downsides. Potentially, some people might not like the formatted output with panels and ASCII art and lots of colours. It should be possible to configure it with a theme to address this. It does add a bit more dependencies such as
rich
but we might want to use that anyway to provide some more readable output even if we didn't choose Typer. They're all packaged in Debian as well. There are many other Typer features that aren't showcased here, and as it's developed by Tiangolo like FastAPI it could bring some familiarity for developers who contribute both to the KernelCI API and thekci
command-line tool.Time to vote!
We'll take a look at the results on Monday 2nd October and wrap up this discussion then.
9 votes ·
Beta Was this translation helpful? Give feedback.
All reactions