Feat/python dependency integration#203
Conversation
…ionType cases Temporary composite-build wiring lets DC consume TSE changes from the sibling worktree during the Python migration iteration. Reverts before the DC PR, per plans/add-python-dependency-support.md Task 7. The newer TSE adds FUNCTION and VARIABLE to DeclarationType for Python's top-level shapes; TseMappings.toNodeType() gains the corresponding branches so the when-expression stays exhaustive. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the legacy PythonAnalyzer body (TSQuery walks + PythonImportQuery / PythonTypeIdentifierQuery / PythonTypeAttributeQuery / PythonDefinitionsQuery) with a thin adapter over TreeSitterDependencies.analyze(content, Language.PYTHON). The adapter: - Derives modulePath from FileInfo.physicalPath (ADR-0001). - Resolves leading-dots relative IMPORT_FROM paths against modulePath (ADR-0003). - Synthesizes the canonical/__init__ twin pair per IMPORT_FROM and per matched STANDARD-import attribute access (ADR-0004). - Pre-loads non-aliased and wildcard FROM-import twins on every CLASS/FUNCTION declaration; conditionally pre-loads aliased FROM-import twins when the resolved tail name appears in the identifier stream (ADR-0006). - Emits VARIABLE declarations as isolated leaves with empty dependencies and empty usedTypes, mirroring DC main's early return at PythonAnalyzer.kt:94-103 (Q10). - For __init__.py files, emits one re-export Node per non-aliased IMPORT_FROM with dependencies = the regular FROM-import twin set. - Maps usedTypes by partitioning on UsedType.namespacePrefix.isEmpty() (ADR-0005): identifier-stream entries become Node.usedTypes; attribute-stream entries drive STANDARD-import attribute matching into Node.dependencies. Legacy queries and PythonUtils.kt are intentionally kept on disk unused — they will be deleted only after dc-compare parity is established (Task 6). All 12 existing PythonAnalyzerTest cases pass against the rewrite. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PythonAnalyzer was rewritten as a thin TSE adapter in de3c509; the TSQuery-based extraction it used to delegate to is now dead code. Remove PythonUtils.kt and the four query classes plus the now-empty queries/ directory: - PythonUtils.kt - queries/PythonDefinitionsQuery.kt - queries/PythonImportQuery.kt - queries/PythonTypeAttributeQuery.kt - queries/PythonTypeIdentifierQuery.kt Verified zero references remain in main and test sources, and ./gradlew ktlintCheck build (which runs the full test suite) passes green with TSE wired via composite build. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR consolidates Python analysis from multiple dedicated tree-sitter query classes into a unified ChangesPython Analyzer Migration to TreeSitterExcavationSite
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@analysis/build.gradle.kts`:
- Around line 23-24: The temporary composite-build coordinate and its broken
plan reference cause missing-plan and build-on-other-machines failures: either
(A) add the missing plan file plans/add-python-dependency-support.md with
explicit Task 7 revert instructions that state restoring
implementation("com.github.MaibornWolff:TreeSitterExcavationSite:<tag>") and
removing includeBuild("../../TreeSitterExcavationSite"), (B) add a CI pre-merge
check that validates includeBuild("../../TreeSitterExcavationSite") is
resolvable (fail the job with a clear message if the external repo is absent),
or (C) document the local checkout requirement for TreeSitterExcavationSite in
CLAUDE.md and the developer setup steps so builds are reproducible; update
references to
implementation("de.maibornwolff.treesitter.excavationsite:treesitter-excavationsite")
and includeBuild("../../TreeSitterExcavationSite") accordingly.
In `@analysis/settings.gradle.kts`:
- Around line 6-8: The settings.gradle.kts currently force-includes a local
composite build via includeBuild("../../TreeSitterExcavationSite") which breaks
builds for devs without that repo; also build.gradle.kts still references the
TSE composite dependency. Fix by either removing the composite wiring entirely
and reverting the dependency in build.gradle.kts to a published, pinned
coordinate (replace
implementation("de.maibornwolff.treesitter.excavationsite:treesitter-excavationsite")
with a stable group:artifact:version), or make the composite conditional: in
settings.gradle.kts check for the local path (File(...).exists()) before calling
includeBuild and otherwise do nothing so the published dependency in
build.gradle.kts is used as a fallback; update the inline REVERT comments to
reflect the chosen approach and ensure implementation(...) points to the
published coordinate when the composite is not included.
In
`@analysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/PythonAnalyzer.kt`:
- Line 47: The current call
nodes.addAll(initFileReexportNodes(regularFromImports, regularFromTwins.toSet(),
modulePath)) makes every synthetic __init__ re-export node depend on the entire
regularFromTwins set; change the logic so each re-export node is tied to exactly
one source import: iterate over regularFromTwins (or map over it) and call
initFileReexportNodes (or a new helper) with a singleton twin (or a parameter
for the single twin) along with regularFromImports and modulePath so each
produced node references only its originating twin; update equivalent calls in
the same file (the 55–69 region) to follow the same per-twin/singleton pattern.
- Around line 93-114: The current code builds usedTypes from identifierStream
(losing qualified types like pkg.Foo); instead keep the partition logic for
dependency matching but set usedTypes to declaration.usedTypes (as a Set)
instead of identifierStream.map { Type.simple(...) }, so the Node(...) uses the
full set of used types from declaration.usedTypes; leave the deps construction
(basePreloadedDeps, aliasedFromImports.forEach, attributeStream.forEach calling
matchStandardImportAttribute) unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9b76d155-20a5-492e-b7e8-5593c959eb26
📒 Files selected for processing (9)
analysis/build.gradle.ktsanalysis/settings.gradle.ktsanalysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/TseMappings.ktanalysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/PythonAnalyzer.ktanalysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/PythonUtils.ktanalysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonDefinitionsQuery.ktanalysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonImportQuery.ktanalysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonTypeAttributeQuery.ktanalysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonTypeIdentifierQuery.kt
💤 Files with no reviewable changes (5)
- analysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonTypeAttributeQuery.kt
- analysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonDefinitionsQuery.kt
- analysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonTypeIdentifierQuery.kt
- analysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/queries/PythonImportQuery.kt
- analysis/src/main/kotlin/de/maibornwolff/dependacharta/pipeline/analysis/analyzers/python/PythonUtils.kt
Migrate python analysis to TSE
Summary by CodeRabbit
New Features
Refactor