-
Notifications
You must be signed in to change notification settings - Fork 9
Replace Typer app with click cli #47
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
Conversation
Typer app is now a click cli as Typer rich panel is not supported in click, pytest fails as package source is not printed
as click does not support `rich_help_panel` by default, grouping by origin was reimplemented by overriding some of the functions of click.Group
even though our mission is to drop Typer, we need to defer breaking changes
we need to update help message anyway, whether the module is either click command, typer app, or any other format
introduce click cli object with custom commands in pytest note that `test_plugin_origin` checks OriginGroup help while `test_plugin_origin_subcommand` checks imported module's help
let click checks if name is None and raise
for more information, see https://pre-commit.ci
ryanking13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @evenharder!
Overall the change looks good. But I found that I am getting an error when I call any subcommands on my local machine. Could you please take a look on that?
Interestingly, --help works fine.
|
|
||
| def test_plugin_origin(plugins): | ||
| output = check_output(["pyodide", "--help"]).decode("utf-8") | ||
| msg = "Registered by: plugin-test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this message changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command section message is currently displayed as Commands Registered by <source>:, instead of Commands Registered by: <source> If the original message suits better, I will revert the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I think this one is better. Thanks. Could you also update here too for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The referenced message is appended to the long help message of each subcommands, which is slightly different from what test_plugin_origin is checking (it is checked in test_plugin_origin_subcommand instead). Would you like to update it as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it is good to be consistent.
pyodide_cli/app.py
Outdated
| # NOTE: gettext is used in click! Any i18n support? | ||
| with formatter.section(f"{gettext('Commands')}{source_desc}"): | ||
| formatter.write_dl(rows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you prefer removing Commands in this case? If that's the case, I would like to preserve it only when the subcommand was added without origin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when the subcommand was added without origin
When can this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the commands provided by pyodide-cli would be, please correct me if I am wrong or it is an unintended scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pyodide-cli is a meta package and will not provide any subcommands.
pyodide_cli/app.py
Outdated
| cmd = click.Command( | ||
| plugin_name, | ||
| callback=module, | ||
| help=help_with_origin, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I am also testing on my local and it does yield some unexpected behaviors. I will investigate it a bit more. |
After some thorough investigation, non-typer functions should not be directly passed as a callback. One example is |
Huh, I see. Thanks for the explanation. This kind of refactoring is always tricky and have many edge cases. |
ryanking13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left some minor comments, otherwise looks good to me.
I think we can start refactoring other downstream packages after merging this. Could you please update CHANGELOG? I think we can release this with a version 0.4.0
Directly passing module as a click callback yields a weird behavior when the module is a function which accepts yper arguments and options In this case, their default values are neither checked nor assigned. To properly handle, construct typer app and append as a command. Actually this is identical to the original implementation except registering origins! Additionally, we have to reassign the help message of the original command. I am not sure if direct manipulation of attribute of click is a good idea...
Print 'Commands' section only once (if command exists) with removal of i18n support of 'Commands'.
78b2e9d to
9f76ca0
Compare
now 'Registered by {pkgname}:' is used instead.
|
I have updated the changelog as well, please review! |
|
@evenharder I just released 0.4.0. Thanks! |

Replace main typer app of pyodide-cli with click group.
As pytest depends on Typer's rich help integration which yields the origin of the subcommand,
it was implemented by subclassing
click.Group. The following is an excerpt from pytest.Technically
typer_kwargsis still supported. Perhaps we may need to introduceclick_kwargslater on as a substitute.I expect the overall behavior to be compatible, barring subtle difference due to different default behavior of click and typer.
Related: pyodide/pyodide-build#204