Code that graphs code
Project description
Code that graphs code
Uses the python AST to parse Python source code and build a call graph.
Output
An example of the current output of the parser parsing itself.
Installation
pip install codegrapher
To generate graphs, graphviz must be installed.
Usage
At the command line
To parse a file and output results to the console:
codegrapher path/to/file.py --printed
To parse a file and output results to a file:
codegrapher path/to/file.py --output output_file_name --output-type png
To analyze a directory of files, along with all files it contains:
codegrapher -r path/to/directory --output multiple_file_analysis
And if you have a list of functions that aren’t useful in your graph, add it to a .cg_ignore file:
# cg_ignore file # all lines beginning with '#' are ignored # every function calls this, so it's not helpful in my graph: log_error # I don't want to see this in my graph: parse lower
Then add the –ignore flag to your command. Using the flag –remove-builtins provides the same functionality for ignoring items found in __builtins__.
As a Python module
To easily parse code in Python :
from codegrapher.parser import FileObject
file_object = FileObject('path/to/file.py')
file_object.visit()
And then to add that code to a graph and render it (using graphviz):
from codegrapher.graph import FunctionGrapher
graph = FunctionGrapher()
graph.add_file_to_graph(file_object)
graph.name = 'name.gv'
graph.format = 'png'
graph.render()
Which will produce your code as a png file, name.gv.png, along with a dot file name.gv
More documentation for the Python module can be found at Read the Docs.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file codegrapher-0.2.1.tar.gz
.
File metadata
- Download URL: codegrapher-0.2.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 201527186f7ce9da0bc4d6343408832be54b7c415399e43ce5020f59054197d0 |
|
MD5 | 622bbfde1dd2014625b324fbe9af5f0d |
|
BLAKE2b-256 | 6d7f52208131149719b65662ccd34c0cb40eb4a6f74d0408b7d21cd2c83df0d8 |