views:

470

answers:

3

I'm digging into a huge legacy Python class that has a lot of methods. I eventually break complex ones into smaller pieces so the amount of methods increases even more. I wonder if there is a tool that can scan the Python code and build some kind of dependency diagram for its methods.

I define method x() to be a dependency of method y() if x() is called at least once in y().

I could use such a tool to isolate (if possible) subsets of class methods that have no external dependencies (all their dependencies are methods from the same subset).

I'm planning to move some functionality into other classes and I think that such an approach would help me to decide which parts to extract from the initial huge class.

Edit: I would really like a command-line tool.

A: 

Have you tried pydev? It's a python extension for eclipse. I believe it allows you to use the "call hierarchy" feature of Eclipse to view a call graph for a given method. It's not quite what you want but maybe it's enough to get started.

sk
I'm using vim and a couple of command-line tools for coding, but thanks for the suggestion. It would be great if you could suggest how to reach that feature in Eclipse/pydev, because I'm scared by huge IDEs with zillions of features :( Do I have to create a project, add source files etc or would it be enough to open a .py file in Eclipse/pydev and inspect it using the suggested feature by clicking somewhere in the Eclipse menu? Thanks in advance.
Anonymous
+1  A: 

Have you looked at Snakefood yet? It looks like it's exactly what you're looking for.

Joce
I have tried it, but it works on a set of files. I have only one module file containing a huge class with many methods. I've tried running snakefold in verbose mode against that file and it does not show any dependencies between class methods.
Anonymous
A: 

i was confuse in this question too,i have found a search helper help me to find the call hierarchy in another way. not very good but better than donot have. sorry about my english.

ps.IDE eclipse+pydev

Chous