Repository navigation
feat(pregate): lanes follows Python imports and mock.patch targets - #3201
Closed
scottgigante-hubflow wants to merge 1 commit into
Closed
scottgigante-hubflow wants to merge 1 commit into
scottgigante-hubflow wants to merge 1 commit into
Conversation
The import graph only parsed JS/TS imports, so in a Python repo every touched module failed `lanes` with PREGATE_NO_LANE even though SOURCE_EXT, TEST_FILE_RE and the pytest runner/summary already understood Python. Python sources now contribute `import a.b`, `from a.b import c` (c may be a submodule), parenthesised multi-line lists and relative `from ..pkg import x` edges, resolved to `a/b.py` or `a/b/__init__.py` from the repository root. Package `__init__.py` files on the path get edges too, since Python executes them on import. Modules outside the repo resolve to nothing. In test files, dotted string literals such as `'pkg.mod.Class.method'` (mock.patch targets) resolve to the longest dotted prefix that is a repo module. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Contributor
garrytan
added a commit
that referenced
this pull request
Oct 17, 2026
Review of #3201 on the integrated tree found two quadratic paths on untrusted Python source and three ways a test could be left unselected: - The from-import module spec let two repetitions share a dot, so a failed match on a long run of dots backtracked quadratically. The spec is now dots followed by an optional word-led name. - Dotted literals and imports resolved every prefix with repeated split/join. Names are capped at 32 segments, deeper than any module path. - A literal that also named a repo file skipped its mock.patch reading; both readings now add edges. - A package and a same-named module both map (Python loads the package). - Imports after `;` or a compound statement's `:` are recognised. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
capy-ai Bot
added a commit
that referenced
this pull request
Oct 18, 2026
…dependencies regen diagnostic (#3252) * feat(pregate): lanes follows Python imports and mock.patch targets The import graph only parsed JS/TS imports, so in a Python repo every touched module failed `lanes` with PREGATE_NO_LANE even though SOURCE_EXT, TEST_FILE_RE and the pytest runner/summary already understood Python. Python sources now contribute `import a.b`, `from a.b import c` (c may be a submodule), parenthesised multi-line lists and relative `from ..pkg import x` edges, resolved to `a/b.py` or `a/b/__init__.py` from the repository root. Package `__init__.py` files on the path get edges too, since Python executes them on import. Modules outside the repo resolve to nothing. In test files, dotted string literals such as `'pkg.mod.Class.method'` (mock.patch targets) resolve to the longest dotted prefix that is a repo module. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(regen): report missing dependencies as REGEN_DEPS_MISSING, not REGEN_STALE When package.json declares dependencies and node_modules is missing, the scratch worktree runs the generator without them. A generator that degrades and still exits 0 then looked stale, and the fix line sent people to rerun the generator. gstack-regen check and the pregate regen check now report "dependencies missing; run <install>" with its own result code and troubleshooting anchor; the install command follows the lockfile. The fixture reproduces the shape GSTA-31 saw in gbrain. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(pregate): keep Python import scanning linear and conservative Review of #3201 on the integrated tree found two quadratic paths on untrusted Python source and three ways a test could be left unselected: - The from-import module spec let two repetitions share a dot, so a failed match on a long run of dots backtracked quadratically. The spec is now dots followed by an optional word-led name. - Dotted literals and imports resolved every prefix with repeated split/join. Names are capped at 32 segments, deeper than any module path. - A literal that also named a repo file skipped its mock.patch reading; both readings now add edges. - A package and a same-named module both map (Python loads the package). - Imports after `;` or a compound statement's `:` are recognised. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(pregate): linear Python string blanking, non-empty from-spec, repo-bounded depth Second review round on the Python import scanner: - An empty from-spec let the whitespace on both sides of it compete, so `from` followed by a long run of spaces backtracked quadratically. The spec now starts with a dot or a word character. - Strings and comments are blanked by a single linear scanner that honours backslash escapes, so an escaped triple quote no longer ends a docstring early and swallows the imports after it. - The fixed 32-segment cap dropped real deep modules. Dotted names are now bounded by the repo's deepest path, which no module can exceed. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(changelog): unreleased entry for Python import lanes and REGEN_DEPS_MISSING Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * v1.91.126.0 stamp Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * release slot 1.91.126.0: back to unstamped (CHANGELOG entry unreleased) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(changelog): resolve the main-merge conflict (Unreleased entry above 1.91.127.0) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * v1.91.131.0 stamp Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: Scott Gigante <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Contributor
|
Thank you, @scottgigante-hubflow. Your Python import support for pregate landed in #3252 (v1.91.131.0, 8f103ba), with your commit cherry-picked under your authorship. Review found and fixed some backtracking and selection edge cases on top of it, and each fix has a regression test. Closing as merged via #3252. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
gstack-pregate'slanescheck maps each touched file to the tests that depend on it throughlib/pregate/import-graph.ts.SOURCE_EXT,TEST_FILE_RE,detectRunnerandparseSummaryalready handle Python and pytest, butreferencesIn()only parsed imports for JS/TS, and the literal scan only resolved slash paths with JS extensions. In a Python repo, nearly every touched.pyfile therefore failslaneswithPREGATE_NO_LANE.The case that prompted this is a private FastAPI service: about 2,200
.pyfiles, about 700 of them pytest test files, absolute imports from the repo root (from managers.stop import StopManager), tests undertests/test_<layer>/test_<module>.py, and heavy use ofmock.patch("pkg.mod.Class.method"). Every touched Python file came back NO_LANE.Change
For
.pysources,referencesInnow adds:importedges fromimport a.b.c [as x],import a, b.c,from a.b import c, d(each ofa.b,a.b.canda.b.dis tried, becausecmay be a submodule), parenthesised multi-line import lists, and relativefrom . import x/from ..pkg.mod import y, which resolve against the importing file's package directory.a/b/c.pyora/b/c/__init__.pywhen that file is in the repo. Stdlib and site-packages modules resolve to nothing.literaledges from Python test files (anywherescansLiteralsis true): a dotted string such as'pkg.mod.Class.method', the form amock.patchtarget takes, resolves to the longest dotted prefix that is a repo module.#comments are blanked in one left-to-right pass before imports are matched. Triple-quoted docstrings, ordinary strings and comments that mentionimport xtherefore create no edge, and a#inside a string does not cut a line short. Backslash line continuations are joined.The parser is a dependency-free line/regex scanner. It does not spawn Python.
Design decision:
__init__.pyedgesImporting
a.b.calso adds an edge froma/__init__.pyanda/b/__init__.py(when they exist), because Python executes those files on the way in. This is cheap: onefiles.hasper path segment. It matches the graph's rule that uncertainty selects more tests: a touched package__init__.pyselects every test that imports anything beneath it. Dotted patch literals get the same treatment.Effect
I built the graph over the repo described above. Counting non-test
.pyfiles with no lane:.pyfiles (of 1,517 non-test)Almost all of the remaining 780 are things no import reaches:
conftest.py, test helpers and package__init__.pyfiles undertests/Only about 9 application modules are still unmapped. Those can use
.gstack/pregate.jsondependenciesdeclarations.Known gaps (left as follow-ups)
conftest.py: pytest loads it implicitly, so no edge reaches it. A follow-up could map eachconftest.pyto every test under its directory.src/layout, or a package rooted in a subdirectory, does not resolve. Declarations cover these today.importlib.import_module("…"): dynamic imports only resolve when they appear in a test file, through the dotted-literal path.Tests
The new case in
test/pregate-selection.test.tsuses a small Python package with tests. It covers:.and..importsos,json,os.path) producing no edgemock.patchdotted literal__init__.pyselectionThe other pregate files (
pregate-guards,pregate-invalidation,pregate-regate, the bin tests inpregate-selection) fail locally on this Mac, but they fail on unmodifiedmainin the same way. They are subprocesslanesruns plus 5s timeouts inpregate-regate(local bun 1.3.11, CI pins 1.4.2). Which regate tests time out changes from run to run. None of these tests involve a.pyfile. I'm relying on CI for the full suite.VERSION and CHANGELOG are not bumped. I've left that to the maintainer's release slot.
🤖 Generated with Claude Code