-
Notifications
You must be signed in to change notification settings - Fork 551
Fix for Click 8.2 breaking change #4061
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
base: feature/update-modal-step-operator
Are you sure you want to change the base?
Changes from 10 commits
ae4f71f
d28f68b
5d07137
5ce39d5
7476168
db1907a
e891353
ad309a8
515610f
37ba025
e331ce8
92baa4d
5fae563
65abb21
0ba7fdf
8cca137
be76ce5
60f14ae
6dd8121
de20aff
37dd260
ff10561
d9e6158
aac47c2
9b2b3bf
f89bb14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,17 +137,29 @@ def format_commands( | |
| help_ = cmd.get_short_help_str(limit=formatter.width) | ||
| rows.append((tag.value, subcommand, help_)) | ||
| if rows: | ||
| colored_section_title = ( | ||
| "[dim cyan]Available ZenML Commands (grouped)[/dim cyan]" | ||
| ) | ||
| with formatter.section(colored_section_title): | ||
| formatter.write_dl(rows) # type: ignore[arg-type] | ||
|
|
||
|
|
||
| @click.group(cls=ZenMLCLI) | ||
| if isinstance(formatter, ZenFormatter): | ||
| section_title = "[dim cyan]Available ZenML Commands (grouped)[/dim cyan]" | ||
| with formatter.section(section_title): | ||
| formatter.write_dl(rows) | ||
| else: | ||
| # Fallback: use simple pairs without category and avoid rich markup in header | ||
| section_title = "Available ZenML Commands" | ||
| with formatter.section(section_title): | ||
| pair_rows: List[Tuple[str, str]] = [ | ||
| (subcmd, help_) for _, subcmd, help_ in rows | ||
| ] | ||
| formatter.write_dl(pair_rows) | ||
|
|
||
|
|
||
| @click.group(cls=ZenMLCLI, invoke_without_command=True) | ||
| @click.version_option(__version__, "--version", "-v") | ||
| def cli() -> None: | ||
| """CLI base command for ZenML.""" | ||
| @click.pass_context | ||
| def cli(ctx: click.Context) -> None: | ||
| """CLI base command for ZenML. | ||
|
|
||
| Args: | ||
| ctx: The click context. | ||
| """ | ||
| set_root_verbosity() | ||
| source_context.set(SourceContextTypes.CLI) | ||
| repo_root = Client.find_repository() | ||
|
|
@@ -158,6 +170,15 @@ def cli() -> None: | |
| # packages directory | ||
| source_utils.set_custom_source_root(source_root=os.getcwd()) | ||
|
|
||
| # Manually show help and exit with code 0 when invoked without a subcommand. | ||
| # Click 8.2+ raises NoArgsIsHelpError before the callback runs when | ||
| # no_args_is_help=True. By relying solely on invoke_without_command=True | ||
| # and handling help here, we ensure consistent behavior across Click | ||
| # versions while leveraging our custom help formatter in ZenMLCLI.get_help(). | ||
| if ctx.invoked_subcommand is None and not ctx.resilient_parsing: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I really get why this is necessary. Why wouldn't click display the help anymore in newer versions with our previous setup? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue isn't that Click won't display help in newer versions (it will). The problem is that Click 8.2+ would display help using its default formatter instead of our custom (As far as I understand it, without I will improve the comment to make it clearer maybe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just that I can't reproduce it. I have click 8.2+, I run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also if the code that defined |
||
| ctx.command.get_help(ctx) | ||
strickvl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ctx.exit(0) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| cli() | ||
Uh oh!
There was an error while loading. Please reload this page.