Alexander Payne
|
4998c5b6bf
|
feat(visualization): add import_graph — Python module dependency visualizer
Test / pytest (pull_request) Failing after 8s
Issue #133 — "feat: import graph visualization for hermes-agent"
Adds scripts/import_graph.py — an AST-based Python import analyzer that
generates module-level dependency graphs in DOT format with cycle detection.
**Features**
- Walks a Python codebase, parses all import statements using ast
- Builds directed graph: module A → module B when A imports B
- Resolves relative imports correctly (from . import X, from ..pkg import Y)
- Distinguishes local packages from stdlib/third-party
- Detects circular dependencies — DFS cycle finder with detailed paths
- Exports DOT (Graphviz) for rendering to PNG/SVG
- CLI: path, --output, --cycles-only, --render-png, --render-svg
**Smoke tests** — tests/test_import_graph.py (3 passing)
- test_import_graph_creates_dot: validates DOT output on real repo
- test_import_graph_excludes_site_packages: handles noisy dirs cleanly
- test_import_graph_cycles_only_flag: --cycles-only exit codes
**Usage on hermes-agent**
```bash
# Generate DOT
python3 scripts/import_graph.py /path/to/hermes-agent --output hermes_imports.dot
# Only check for cycles
python3 scripts/import_graph.py /path/to/hermes-agent --cycles-only
# Render PNG (requires graphviz)
python3 scripts/import_graph.py /path/to/hermes-agent --render-png
```
Next: run on actual hermes-agent checkout to get the full graph.
Closes #133
|
2026-04-26 00:57:33 -04:00 |
|