FE-1415: Generate import edges for Python packages - #9265
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
PR SummaryLow Risk Overview
The Python path is intentionally conservative (skips docstrings/comments; errors on duplicate module names across packages) so diagrams do not invent dependencies. Copy in Reviewed by Cursor Bugbot for commit 58aab4f. Bugbot is set up for automated code reviews on this repo. Configure here. |
39ccc33 to
0bc4d8a
Compare
0bc4d8a to
b13e2d8
Compare
b13e2d8 to
109b220
Compare
f68e94a to
2047c0a
Compare
2047c0a to
55608c1
Compare
55608c1 to
4d92f94
Compare
4d92f94 to
eab8f6b
Compare
eab8f6b to
524bc78
Compare
🌟 What is the purpose of this PR?
Python packages had layers but no edges, because the import graph came from dependency-cruiser, which reads TypeScript only. The optimizer's real dependency on the Python bindings was invisible, and its diagram suggested dead code. The bundle now derives Python import edges the same way as TypeScript ones:
{ "from": "optimizer", "to": "python-bindings", "provenance": "imports", "fileDependencies": 2, "crossesPackage": true }FE-1447 (#9264) sits below in this stack and FE-1456 (#9266) above.
🔗 Related links
python-bindings → cliedge stays declared, and the duplicate check confirms the two never overlap.🔍 What does this change?
libs/@local/petrinaut-arch-docs:graph.ts:buildGraphsplits covered packages by language. TypeScript goes through dependency-cruiser as before, Python through a new collector, and both emit the same file-level records, so aggregation, intra-layer dropping, example pairs,crossesPackage, rules, and the declared-edge duplicate check apply to Python unchanged.python-imports.ts(new, no dependencies): a line-based parser forimport a.bandfrom a.b import c, covering aliases, comma lists, parenthesised continuations and relative imports; a module index over the covered packages; and a resolver. Imports resolving to nothing covered drop silently, as the TypeScript ones do. The parser skips strings and comments conservatively, because a missed import loses one edge while an invented one puts a false claim in the docs. Two packages claiming one dotted module name is an error, since last-write-wins would let an import in one app resolve into another's file and invent a cross-package edge.content/index.mdxno longer say Python contributes no edges.The one new edge is the optimizer's import of the bindings. Intra-package Python imports aggregate away as intra-layer, as they should.
Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
🛡 What tests cover this?
python-imports.test.ts(new): parsing (absolute, from-imports, aliases, relative, continuations, comment and string non-matches), module indexing, the module-name collision diagnostic, and resolution.graph.test.ts: a full-chain assertion that a Python cross-package import aggregates into an edge.lint:arch-docsexercises the real repo with zero diagnostics.❓ How to test this?
yarn workspace @local/petrinaut-arch-docs lint:arch-docspasses.turbo run dev --filter @apps/petrinaut-docs: theoptimizerpage showspython-bindingsunder "Depends on" with an import count, and the overview diagram draws the solid edge beside the dashed declared one.🤖 Generated with Claude Code