Add verify_pyi script to validate .pyi stubs in distributions
Merged
MA
3mo ago+414+414+012345678901234567890123456789-11-11-01234567890123456789
Type of change
- New feature (non-breaking change which adds functionality)
Description
Adds a new scripts/verify_pyi.py script that validates built distributions (wheels and sdists) contain the .pyi type 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.py for the root package and the hatch-reflex-pyi hook for component packages). Since *.pyi files 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:
- Reads each package's
pyproject.tomlto determine if it generates stubs (by checking for thereflex-pyihook or*.pyiartifact declarations) - For packages that should generate stubs, verifies every built artifact (wheel and sdist) contains at least one
.pyifile - Fails the build if any artifact is missing stubs, preventing the release from proceeding to the approval gate
Changes:
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
- Added 233 lines of comprehensive unit tests in
tests/units/test_verify_pyi.py - Tests cover: configuration parsing, stub detection logic, artifact inspection, error cases, and real package detection
- Tests validate both synthetic test cases and real packages in the repository (reflex and component packages)
- All tests pass with the implementation
Checklist
- Tests pass with adequate coverage
- Code follows project conventions (Google-style docstrings, concise implementation)
- Linting configured appropriately for the new script