Split monolithic Python packages into per-subpackage components#12
Merged
ethenotethan merged 1 commit intomainfrom Apr 21, 2026
Merged
Split monolithic Python packages into per-subpackage components#12ethenotethan merged 1 commit intomainfrom
ethenotethan merged 1 commit intomainfrom
Conversation
The Python discovery plugin previously emitted exactly one Component per pyproject.toml, even when the source tree contained many logically independent sub-packages. For monolithic Python codebases (the common case — PEP 621 has no workspace manifest like Cargo/npm), this hid the internal dependency structure that Flashlight's multi-agent analysis is designed to exploit. Mirror the Go plugin's single-module-monorepo approach: when a project has a flat- or src-layout source tree with ≥2 substantial top-level sub-packages, emit a Component per sub-package in addition to the root, with internal_dependencies derived from AST-based import analysis (handles both absolute `from pkg.sub import X` and relative `from ..sub import X` forms). Classification per sub-package uses import-statement regex with word boundaries to avoid false positives (e.g., "dashboard" in a docstring was previously matching the "dash" frontend framework marker). Validated end-to-end against jundot/omlx via GLM-5.1 on OpenRouter: 12 components discovered across 6 dependency-depth levels, correctly classifying the FastAPI-based `api` as SERVICE and everything else as LIBRARY. - agent/discovery/languages/python.py: add _find_source_package, _discover_subpackages, _scan_python_imports (with relative-import resolution), and _classify_subpackage; tighten classifier to use word-boundary matching on import statements - tests/discovery/test_python_plugin.py: 17 new tests covering flat/src layouts, relative imports, hyphenated project names, skip rules for tests/private dirs, min-sub-package threshold, classification, and the docstring-false-positive regression
0xClandestine
approved these changes
Apr 21, 2026
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.
Summary
The Python discovery plugin previously emitted exactly one
Componentperpyproject.toml, even when the source tree contained many logically independent sub-packages. For monolithic Python codebases (the common case — PEP 621 has no workspace manifest like Cargo/npm), this hid the internal dependency structure that Flashlight's multi-agent analysis is designed to exploit.This PR mirrors the Go plugin's single-module-monorepo approach: when a project has a flat- or src-layout source tree with ≥2 substantial top-level sub-packages, emit a
Componentper sub-package in addition to the root, withinternal_dependenciesderived from AST-based import analysis (handles both absolutefrom pkg.sub import Xand relativefrom ..sub import Xforms).Classification per sub-package uses import-statement regex with word boundaries to avoid false positives (e.g., "dashboard" in a docstring was previously matching the "dash" frontend framework marker).
Changes
agent/discovery/languages/python.py— add_find_source_package,_discover_subpackages,_scan_python_imports(with relative-import resolution), and_classify_subpackage; tighten classifier to use word-boundary matching on import statements.tests/discovery/test_python_plugin.py— 17 new tests covering flat/src layouts, relative imports, hyphenated project names, skip rules for tests/private dirs, min-sub-package threshold, classification, and the docstring-false-positive regression.Validation
Validated end-to-end against
jundot/omlxvia GLM-5.1 on OpenRouter: 12 components discovered across 6 dependency-depth levels, correctly classifying the FastAPI-basedapiasSERVICEand everything else asLIBRARY.Test plan
pytest tests/discovery/test_python_plugin.py— 17 new tests plus existing coverage.