fix(cli): show correct short help for sys, untruncate build/quantize - #1254
Conversation
_parse_click_help grabbed the first decorated function's docstring, so 'winml --help' showed an internal @contextlib.contextmanager docstring for 'sys' instead of the command's. It now reads only the function carrying a @click.command/@click.group decorator and honors an explicit short_help= argument. Added short_help to build and quantize so their rows no longer truncate at 80 columns. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
DingmaomaoBJTU
left a comment
There was a problem hiding this comment.
Clean fix — the root cause is clear (sys.py's @contextlib.contextmanager isolated_ep_register was the first decorated function, so its docstring leaked as the command's short help). The AST-based approach correctly targets only @click.command/@click.group. A couple of minor inline notes.
Address review feedback: clarify why we stop searching (return '') once the Click command function is found even when it has no docstring or short_help, rather than falling through to an unrelated helper's docstring. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
DingmaomaoBJTU
left a comment
There was a problem hiding this comment.
Clean fix. The root cause was clear — _parse_click_help grabbed the first decorated function's docstring, which for sys.py was a @contextlib.contextmanager helper instead of the Click command. The new AST-based _command_decorator filter is precise and handles both @click.command and bare @command forms.
Explicit short_help= on build and quantize is the right call since their docstrings are multi-paragraph and Click's auto-truncation cut them off.
Tests are solid — regression test on actual sys.py, synthetic tests for decorator ordering and short_help= precedence.
DingmaomaoBJTU
left a comment
There was a problem hiding this comment.
Second pass — checked edge cases in AST parsing, decorator form variations, and multi-command modules. All solid.
Address review feedback: _command_decorator now accepts the attribute form only when its owner is the 'click' name (plus bare @command/@group from 'from click import ...'), so a non-Click decorator like @typer.command can no longer be mistaken for a Click command. Add a regression test covering the @typer.command case. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
DingmaomaoBJTU
left a comment
There was a problem hiding this comment.
LGTM. AST-based Click command detection is correct and well-tested. All inline comments are non-blocking.
Address review feedback: add an explicit test that a Click command with no docstring and no short_help returns '' without falling through to a later decorated helper, and document why ast.AsyncFunctionDef is skipped. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Problem
winml --helpshowed a garbage description forsys:_parse_click_helpextracted the first decorated function's docstring from each command module. Insys.pythe first decorated function is an internal@contextlib.contextmanagerhelper, not the@click.command, so its docstring leaked into the command listing — the very first screen a new user sees.Two other rows (
build,quantize) also truncated mid-sentence at an 80-column width.Fix
cli.py—_parse_click_helpnow only reads the function carrying a@click.command/@click.groupdecorator, and prefers an explicitshort_help=decorator argument when present. Still AST-only (no module import), so startup stays fast. Added_command_decoratorand_short_help_kwarghelpers.build.py/quantize.py— added conciseshort_help=so their rows no longer truncate.Result
Tests
Added
TestParseClickHelpintests/cli/test_help_cli.py:sysregression test — asserts the real command docstring and thatdll_path/subprocessnever leak.short_help=over the docstring.All 55 tests in
test_help_cli.pypass;ruff checkclean.