$ show xnuinside/codegraph
CodeGraph is a Python command-line tool that performs static analysis on Python source code to generate dependency graphs. It parses Python files to extract functions, classes, and import statements, then builds a graph showing how these entities depend on each other. The tool outputs an interactive HTML visualization (using D3.js by default) or can export the data to CSV or print it to the console. The architecture is modular, consisting of a parser (using Python's tokenize module), a core module that builds the dependency graph, utility functions for file discovery, and a visualizer that supports both D3.js (interactive) and matplotlib (legacy) backends. The tool does not execute the code being analyzed, making it safe and fast for large codebases. Key strengths include a robust parser that handles various import styles and class inheritance, and a flexible visualization system that provides features like search, collapsing/expanding nodes, and detailed tooltips. The project is actively maintained with comprehensive tests and supports multiple Python versions.
The LLM identified 2 files worth highlighting for reuse:
The parser module uses Python's tokenize module to extract functions, classes, and import statements from Python source code without executing it. It handles various import formats (simple, from, aliased, comma-separated, multi-line) and class inheritance (single and multiple). This component is self-contained (only uses standard library) and could be reused in any project that needs to analyze Python code structure.
The vizualyzer module contains functions to convert the internal graph representation to D3.js format (`convert_to_d3_format`) and to generate a complete HTML visualization with embedded CSS and JavaScript (`get_d3_html_template`). The conversion function handles nodes (modules, entities, external dependencies) and links (module-module, module-entity, dependency) and computes additional metadata for the UI (like unlinked modules and link counts). This component is largely self-contained (depends only on standard library and the input data structure) and could be adapted for use with other graph data to produce D3.js visualizations.