Giter Site home page Giter Site logo

codegrapher's Introduction

codegrapher

image

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.

parser.py

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.