Add verify_pyi script to validate .pyi stubs in distributions - #6961
Add verify_pyi script to validate .pyi stubs in distributions#6961masenf wants to merge 2 commits into
Conversation
post_build.sh only checked the reflex wheel, so a component package whose build silently produced no stubs could be published with no type information — a release that is not recoverable, since a version can only be uploaded to PyPI once. The check now covers every package whose build generates stubs: reflex itself and the 14 packages driven by the hatch-reflex-pyi hook. Which packages those are is read out of the package's own pyproject rather than listed anywhere, so one that starts or stops generating stubs is covered without touching the check. Either signal is enough: declaring the hook, or declaring *.pyi as a build artifact (how the root package's custom hook is recognized). Reading them independently is what catches a package that generates stubs but never declares them — *.pyi is gitignored, so hatchling leaves the generated files out of the artifact unless listed. Also widens what is inspected. Sdists are checked alongside wheels, since a stubless sdist rebuilds without stubs wherever reflex-base is unavailable. And every artifact must carry stubs rather than just one: the old `unzip -l "$DIST_DIR"/*.whl` passed a second wheel to unzip as a member pattern instead of listing it, so a build matrix leg that lost its stubs went unnoticed. Verified against real builds of all 15 packages (wheel and sdist each), a package that generates no stubs, and a stub-stripped wheel. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NwKbDTae52hrg5HY63whHb
Greptile SummaryThe PR adds a release-time validator that checks generated Python type stubs are present in wheel and source distributions before publication.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| scripts/verify_pyi.py | Adds package-configuration detection and wheel/sdist inspection that fails the release hook when expected stubs are absent. |
| .github/scripts/publish/post_build.sh | Replaces the package-specific unzip check with the new verifier and explicitly requires the package build directory. |
| tests/units/test_verify_pyi.py | Covers stub-generation detection, archive counting, success and failure paths, mixed artifacts, and real repository package configurations. |
| pyproject.toml | Permits intentional print calls in the command-line verification script. |
Reviews (2): Last reviewed commit: "Provision the tomllib backport for the ...." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
The 3.10 fallback could not work as written: the hook ran the verifier with `uv run --no-project`, which resolves none of the project's dependencies, so `import tomli` raised ModuleNotFoundError on any interpreter below 3.11 rather than falling back. Declare the backport as inline script metadata and run the verifier with `uv run --script`, which provisions it from the script's own dependencies. Matches scripts/check_min_deps.py, which carries the same block for the same reason. `--no-config` keeps the ephemeral resolution clear of the workspace's uv settings. The publish job runs 3.14, where tomllib is stdlib and the block resolves to no dependencies at all, so the release path installs nothing new. Verified by running the hook against a real build on 3.10 (reproduced the ModuleNotFoundError first), on 3.14 and with no UV_PYTHON set, across the pass, skip and stub-stripped-wheel paths. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NwKbDTae52hrg5HY63whHb
Type of change
Description
Adds a new
scripts/verify_pyi.pyscript that validates built distributions (wheels and sdists) contain the.pyitype stub files they are expected to generate. This script is run by the publish workflow's post-build hook (.github/scripts/publish/post_build.sh) to prevent releasing packages without type information.Why this matters: Reflex generates type stubs at build time (via
scripts/hatch_build.pyfor the root package and thehatch-reflex-pyihook for component packages). Since*.pyifiles are gitignored, only the build process creates them. A build that silently fails to generate stubs would ship a release with no type information, which is not recoverable since PyPI versions are immutable.How it works:
pyproject.tomlto determine if it generates stubs (by checking for thereflex-pyihook or*.pyiartifact declarations).pyifileChanges:
scripts/verify_pyi.py: New script with functions to read build configuration, detect stub-generating packages, count stubs in artifacts, and validate distributionstests/units/test_verify_pyi.py: Comprehensive unit tests covering all code paths, including edge cases (empty dist dirs, mixed build matrices, non-distribution files).github/scripts/publish/post_build.sh: Updated to call the new verification script instead of the previous reflex-only checkpyproject.toml: Added linting exception for the new script's use ofprint()Testing
tests/units/test_verify_pyi.pyChecklist
https://claude.ai/code/session_01NwKbDTae52hrg5HY63whHb