If things look a little dusty around here, it's because I'm away on a mission for two years. I'll be back in August 2012, but in the mean time feel free to fork my projects on github.
Easy python dependency graphs
Jul 16, 2010
by Jared
http://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Directed.svg/200px-Directed.svg.png

I was looking around for ways to get a look at a python dependency graph, and found this site which actually does a pretty good job. The only gripe I have regards the command you must use:

python py2depgraph.py path/to/my/script.py | python depgraph2dot.py | dot -T png -o depgraph.png

Couldn't be easier, right? ...

Anyway, I added a bit of sugar on top of it.

First I put the two files they provided in ~/clone/modgraph

mkdir ~/clone/modgraph
cd ~/clone/modgraph
wget http://www.tarind.com/py2depgraph.py
wget http://www.tarind.com/depgraph2dot.py
touch ~/bin/modgraph
chmod +x ~/bin/modgraph

and then in ~/bin/modgraph

if [ -z "$2" ]
then
    echo "usage: modgraph somepythonfile.py out.png"
    exit
fi
python ~/clone/modgraph/py2depgraph.py $1 | python ~/clone/modgraph/depgraph2dot.py | dot -T png -o $2

And of course to use it:

modgraph myfile.py outfile.png

Is there another module that does this better? Should I package this up and throw it on pypi?

blog comments powered by Disqus