|
| 1 | +# Dependency Analyzer |
| 2 | + |
| 3 | +## Goal |
| 4 | + |
| 5 | +The dependency analyzer scans selected Python files, extracts imports, and suggests missing external packages to install. |
| 6 | + |
| 7 | +## Classification model |
| 8 | + |
| 9 | +Each import root is classified into: |
| 10 | + |
| 11 | +- `stdlib`: Python standard library modules. |
| 12 | +- `internal`: modules that belong to the current workspace. |
| 13 | +- `third_party`: modules resolved from `site-packages` / environment libraries. |
| 14 | +- `unknown`: unresolved imports (kept for manual review). |
| 15 | + |
| 16 | +Only `third_party` and `unknown` are proposed as install candidates. |
| 17 | + |
| 18 | +## Internal module detection strategy |
| 19 | + |
| 20 | +The analyzer combines multiple signals: |
| 21 | + |
| 22 | +1. Package chains with `__init__.py`. |
| 23 | +1. Common source layouts (`src/`, `lib/`, `python/`). |
| 24 | +1. Top-level package directories in workspace. |
| 25 | +1. Project metadata (`pyproject.toml`, `setup.cfg`) names converted to module roots. |
| 26 | + |
| 27 | +## Import extraction coverage |
| 28 | + |
| 29 | +- Standard imports: `import x`, `from x import y` |
| 30 | +- Relative imports: `from .x import y`, `from ..x import y` |
| 31 | +- Dynamic imports: |
| 32 | + - `__import__("pkg.mod")` |
| 33 | + - `importlib.import_module("pkg.mod")` |
| 34 | + |
| 35 | +## File filtering |
| 36 | + |
| 37 | +The analyzer excludes non-relevant paths: |
| 38 | + |
| 39 | +- virtual environments (`venv`, `.venv`, `env`, `.env`) |
| 40 | +- caches/build artifacts (`__pycache__`, `.pytest_cache`, `.mypy_cache`, `build`, `dist`) |
| 41 | +- VCS folders (`.git`, `.svn`, `.hg`) |
| 42 | +- binary artifacts (`.pyc`, `.pyo`, `.pyd`, `*.egg-info`) |
| 43 | + |
| 44 | +## Notes |
| 45 | + |
| 46 | +- `unknown` imports are intentionally conservative to avoid false negatives. |
| 47 | +- Dynamic runtime-only imports may still require manual validation. |
0 commit comments