Clean up pyi_hashes.json annoyances#6614
Conversation
Building a component package previously rewrote pyi_hashes.json, replacing the entire registry with only the package being built and wiping every other entry. A bare `uv build packages/<pkg>` (or the build triggered by `uv sync`) was enough to leave the registry with a single hash. The build hooks now only emit the .pyi stubs shipped in the wheel and never touch the registry; maintaining pyi_hashes.json is reserved for the update-pyi-files pre-commit step. scripts/make_pyi.py: - --force regenerates every default target, ignoring the incremental markers. - Explicit targets are regenerated and merged into pyi_hashes.json (never pruned) and leave the .pyi_generator_last_run / .pyi_generator_diff markers untouched; only a default run with no targets owns those markers. - An unreachable last-run commit (branch switch or rebase) now forces a full regeneration instead of diffing against a meaningless base. - --check fails if any pyi_hashes.json entry has no corresponding .py source, and is wired into the pre-commit CI job so a deleted component can't leave a stale entry behind (explicit-target runs merge rather than prune). pyi_generator.scan_all() gained a prune_stale flag that decouples "replace the whole registry" from "scan everything", so a partial run can regenerate its targets without dropping unrelated hashes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR fixes a long-standing issue where building any single component package (or running
Confidence Score: 5/5Safe to merge — changes are narrowly scoped to pyi-generation tooling with no impact on runtime Reflex behavior. All three code paths are exercised by new unit tests, the regression test covers the core bug scenario end-to-end, and the CI guard catches future drift. Only a minor UX gap exists where --check and --force can be combined without a warning. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "Clean up pyi_hashes.json annoyances" | Re-trigger Greptile |
The build-hooks regression test failed on Python 3.10-3.12 because `_scan_file` called `inspect.getsource` on an empty `__init__.py`, which raises `OSError: could not get source code` on Python < 3.13 (it returns "" on 3.13+). Treat a module with no retrievable source as "no stub" so the scanner no longer crashes and behaves consistently across versions. Also address review feedback: `--check` now rejects being combined with `--force` or explicit targets (previously silently ignored by the early `--check` return), and add the missing `reflex-base` news fragment so the towncrier changelog check passes for the affected package. https://claude.ai/code/session_01YRoWCrG3XtiZKSUGTfPCYt
masenf
left a comment
There was a problem hiding this comment.
the two news fragments seem to overlap too much, can you make each one more focused
De-duplicate the two changelog entries: the root reflex fragment now covers only the scripts/make_pyi.py CLI and the CI --check guard, while the reflex-base fragment covers the shipped build-hook entrypoint and scanner robustness. Addresses PR review feedback. https://claude.ai/code/session_01YRoWCrG3XtiZKSUGTfPCYt
Building a component package previously rewrote pyi_hashes.json, replacing the entire registry with only the package being built and wiping every other entry. A bare
uv build packages/<pkg>(or the build triggered byuv sync) was enough to leave the registry with a single hash. The build hooks now only emit the .pyi stubs shipped in the wheel and never touch the registry; maintaining pyi_hashes.json is reserved for the update-pyi-files pre-commit step.scripts/make_pyi.py:
pyi_generator.scan_all() gained a prune_stale flag that decouples "replace the whole registry" from "scan everything", so a partial run can regenerate its targets without dropping unrelated hashes.