| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This example demonstrates how to use Graph-sitter to automatically analyze and visualize module dependencies in Python codebases. The script creates a directed graph showing relationships between different modules, making it easier to understand code architecture and dependencies.
Note
This codemod helps developers understand module relationships by creating a visual representation of import dependencies between different parts of the codebase.
The script analyzes module dependencies in several key steps:
Graph Initialization
G = nx.DiGraph()
list_apps = ["src/sentry/api", "src/sentry/auth", "src/sentry/flags"]
for app in list_apps:
G.add_node(app, metadata={"color": "red"})Import Analysis
for file in codebase.files:
if app in file.filepath:
for import_statement in file.import_statements:
# Analyze imports and build edgesGraph Cleanup
nodes_to_remove = [node for node, degree in G.degree() if degree == 1]
G.remove_nodes_from(nodes_to_remove)Automated Dependency Detection
Visual Representation
Simplified Analysis
# The script will detect dependencies like:
from src.sentry.api import endpoint # Creates edge from current module to api
from src.sentry.auth import tokens # Creates edge from current module to authDiGraph with n nodes and m edges where: - Nodes represent major modules - Edges show import relationships - Node colors indicate module types
Better Architecture Understanding
Refactoring Support
Documentation Aid
# install graph-sitter and dependencies
pip install graph-sitter networkx
# Run the visualization
python run.pyThe script will:
You can customize the analysis by:
Feel free to submit issues and enhancement requests! Contributions to improve the visualization or add new features are welcome.
| Back | FazBrowse Home | New Git URL |