Skip to content

fix(build): keep Click command docstrings in release binaries#1307

Merged
danielmeppiel merged 1 commit into
microsoft:mainfrom
edenfunf:fix/1298
May 14, 2026
Merged

fix(build): keep Click command docstrings in release binaries#1307
danielmeppiel merged 1 commit into
microsoft:mainfrom
edenfunf:fix/1298

Conversation

@edenfunf
Copy link
Copy Markdown
Contributor

Problem

apm --help shows the view row with no summary, and apm view --help shows only Usage: / Options: with no description, fields, or examples — in release binaries only. Source builds render the help correctly.

Reported in #1298 against 0.8.13 (the first release containing view; the same shape previously affected outdated in #1204 / #1216).

Root cause

build/apm.spec sets PyInstaller optimize=2, which is python -OO — it strips both asserts AND __doc__. Every Click @click.command() that omits an explicit help= kwarg loses its summary and detailed help in the binary, because Click's documented fallback is func.__doc__.

The project has been working around this by defensively setting help= on every command. view was the only command that relied on the docstring fallback, so it was the only one broken in v0.13.0; outdated hit the same trap previously (#1216 patched it the same defensive way).

Fix

Lower optimize=2optimize=1 in build/apm.spec. -O still strips asserts (the actual perf / size benefit), but __doc__ survives, so Click's documented help-from-docstring fallback works as advertised. The apm info hidden alias (which reads view_cmd.help) is fixed automatically as a side-effect.

One-line spec change with a one-line comment recording the trade-off.

Validation

Built two binaries from this branch on Windows (PyInstaller 6.16.0):

  • Baseline (optimize=2) reproduces [BUG] Help missing for view command #1298: view$ (empty summary) and apm view --help missing description / Fields / Examples.
  • Fix (optimize=1): apm view --help is byte-identical to source apm view --help (only difference is argv[0] program name in Usage:). All 25 visible commands still have summaries; apm info hidden alias also renders correctly.

Functional tests against the fix binary:

  • apm view <installed-pkg> — renders Rich panel
  • apm view <missing-pkg> — exits 1 with available-package list
  • apm view <pkg> <invalid-field> — exits 1 with valid-field hint
  • apm info <pkg> — works (hidden alias)

Test suite (tests/unit/): 8275 passed, 5 skipped. Pre-existing 3 failures + 2 errors (Windows path absoluteness in test_config_command, missing optional jsonschema dep) reproduce on origin/main without this change.

Binary size delta: bundle 29.6 MB → 31.0 MB (+1.4 MB / +4.6 %); exe 8.86 MB → 10.1 MB. Trade-off documented in the spec comment.

Fixes #1298

Copilot AI review requested due to automatic review settings May 13, 2026 10:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes missing Click command help text in PyInstaller-built release binaries by changing the PyInstaller optimization level so Python docstrings are preserved (allowing Click’s documented __doc__ fallback to populate command summaries and detailed help).

Changes:

  • Update build/apm.spec to use optimize=1 (strip asserts, keep docstrings) so apm view --help renders correctly in release binaries.
  • Add a corresponding entry to CHANGELOG.md under ## [Unreleased] describing the fix and trade-off.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
CHANGELOG.md Records the fix in the Unreleased “Fixed” section with PR/issue reference.
build/apm.spec Lowers PyInstaller optimization to preserve __doc__ so Click help text is retained in release builds.

@sergio-sisternes-epam sergio-sisternes-epam added the panel-review Trigger the apm-review-panel gh-aw workflow label May 13, 2026
@sergio-sisternes-epam sergio-sisternes-epam added this pull request to the merge queue May 13, 2026
@sergio-sisternes-epam sergio-sisternes-epam added the status/accepted Direction approved, safe to start work. label May 13, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch May 13, 2026
@sergio-sisternes-epam sergio-sisternes-epam added status/triaged Initial agentic triage complete; pending maintainer ratification (silence = approval). and removed status/accepted Direction approved, safe to start work. labels May 13, 2026
PyInstaller `optimize=2` (= `python -OO`) was stripping `__doc__` from
every Click `@click.command()`. Every other top-level command works
around this by setting an explicit `help=` kwarg; `view` was the only
one relying on Click's documented docstring fallback, so in release
binaries `apm view --help` was missing its description / Fields /
Examples and the `view` row in `apm --help` had no summary.

Lower the spec to `optimize=1` so asserts are still stripped (the real
size/perf benefit) but `__doc__` survives. Click's help-from-docstring
fallback works as documented for all current and future commands; the
hidden `apm info` alias (which reads `view_cmd.help`) is fixed
automatically as a side-effect. Binary grows ~1.4 MB on the bundle.

Fixes microsoft#1298
@edenfunf
Copy link
Copy Markdown
Contributor Author

@sergio-sisternes-epam To resolve the conflict, thank you!

@danielmeppiel danielmeppiel added this pull request to the merge queue May 14, 2026
Merged via the queue into microsoft:main with commit 5283aaa May 14, 2026
9 checks passed
sergio-sisternes-epam pushed a commit that referenced this pull request May 19, 2026
PyInstaller `optimize=2` (= `python -OO`) was stripping `__doc__` from
every Click `@click.command()`. Every other top-level command works
around this by setting an explicit `help=` kwarg; `view` was the only
one relying on Click's documented docstring fallback, so in release
binaries `apm view --help` was missing its description / Fields /
Examples and the `view` row in `apm --help` had no summary.

Lower the spec to `optimize=1` so asserts are still stripped (the real
size/perf benefit) but `__doc__` survives. Click's help-from-docstring
fallback works as documented for all current and future commands; the
hidden `apm info` alias (which reads `view_cmd.help`) is fixed
automatically as a side-effect. Binary grows ~1.4 MB on the bundle.

Fixes #1298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

panel-review Trigger the apm-review-panel gh-aw workflow status/triaged Initial agentic triage complete; pending maintainer ratification (silence = approval).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Help missing for view command

4 participants