fix(pyi): incremental .pyi regen now follows the import graph#6422
fix(pyi): incremental .pyi regen now follows the import graph#6422FarhanAliRaza wants to merge 7 commits intoreflex-dev:mainfrom
Conversation
…l files Replace the .pyi_generator_last_run/.pyi_generator_diff sentinel files with the last commit that touched pyi_hashes.json as the regen baseline, and expand the change set along the import graph so editing a parent class also regenerates subclass stubs. Set pass_filenames: false on the pre-commit hook and rewrite scan_all's pyi_hashes.json update as a per-file evidence-based merge so partial-target runs no longer truncate the file.
Merging this PR will degrade performance by 4.29%
Performance Changes
Comparing Footnotes
|
Greptile SummaryThis PR overhauls the incremental Confidence Score: 4/5Safe to merge; all findings are P2 style/hardening suggestions with no correctness-breaking defects on the happy path. The logic is sound and well-tested. Three P2 notes: missing ast.TryStar handling (minor Python 3.11+ gap), the uncommitted-hashes loop (usability only), and the single-anchor heuristic replacing LCA (low risk with one root-level hashes file). No P0/P1 issues found. scripts/make_pyi.py and packages/reflex-base/src/reflex_base/utils/pyi_generator.py contain all substantive logic changes. Important Files Changed
Reviews (1): Last reviewed commit: "fix(pyi): regenerate stubs from pyi_hash..." | Re-trigger Greptile |
… races Add --no-update-hashes flag to pyi_generator and use it from both the top-level and per-package hatch build hooks. The shared hash file is a dev-tooling artifact; reading/writing it during parallel workspace package builds caused races and isn't needed at wheel-build time.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
The hash file is workspace-scoped, so walking up from the first entry in written_files made the resolved path depend on iteration order and could latch onto a package-local file before reaching the repo root. Also warn when pyi_hashes.json exists locally but isn't tracked in git, since that forces a full regen on every run until it's committed.
…/reflex into fix-pyi-generation
| modules: list = [] | ||
| root: str = "" | ||
| current_module: Any = {} | ||
| written_files: list[tuple[str, str]] = [] | ||
|
|
||
| def __init__(self) -> None: | ||
| """Initialize per-instance scan state.""" | ||
| self.written_files: list[tuple[str, str]] = [] |
There was a problem hiding this comment.
shouldn't the same be done to modules and current module?
There was a problem hiding this comment.
They need to be removed. They are not used.
| if use_json and (file_paths or file_targets): | ||
| file_paths = list(map(Path, file_paths)) |
There was a problem hiding this comment.
this might be a good time to take PYI hash generation into its own function
Move the pyi_hashes.json merge logic out of PyiGenerator.scan_all into a module-level _update_pyi_hashes_file() so scan_all reads as scan + ruff fixup + (optional) hash update. Remove unused class attributes (modules, root, current_module) that were never read or written, and collapse a duplicate _relative_to_pwd() call in the file walk. Also fix test_tailwind flake: the stylesheet is now written to Path.cwd() / assets so it survives AppHarness's importlib.reload() across pytest reruns (the cached __file__ pinned writes to the prior tmp_path while the compiler read from the current cwd).
masenf
left a comment
There was a problem hiding this comment.
i might be reading it wrong, but are we regenerating modules that are imported by modules that changed? the other fixes seem legit.
| path.write_text(json.dumps(mapping, indent=2, sort_keys=True) + "\n") | ||
|
|
||
|
|
||
| def _make_workspace(root: Path) -> Path: |
There was a problem hiding this comment.
this should be a fixture that returns the workspace path based on the tmp_path fixture
|
For example if react_player is changed, in the main branch now it only generates react_player.pyi because it only sees this in git diff. But it should have also changed audio.pyi and video.pyi because they import react player amd inherit from it . Before partial generation missed it. Only full regneration catches that. So we are regenerating that imports the changed modules. |
Fixed
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission: