Creating Dependency Graphs in Python [closed]
Asked Answered
Q

1

34

I have inherited a huge codebase that I need to make some small changes into. I was wondering if there are utilities that would parse python code and give dependencies between functions, as in if I make changes to a function I want to be sure that I dont break other functions, so if I could see in a graph like diagram it would make my life easier.

Quarrier answered 12/11, 2010 at 1:0 Comment(1)
See also #798889Hoffmann
F
35
  • Usually "dependency" is defined for module / package import.
  • What you are looking for is a visualizing call flow.

  • You can still not guarantee that you will not break functionality :)

  • My experience and solution:

    Many a times, I found the call flow data overwhelming and the diagram too complex. So what i usually do is trace call flow partially for the function, I am interested in.

    This is done by utilizing the sys.settrace(...) function. After generating the call flows as textual data, I generate a call graph using graphviz.

[Edit: based on comments]

Then my piecemeal solution works better. Just insert the code and use the decorator on a function that you want to trace. You will see gaps where deferred comes into picture but that can be worked out. You will not get the complete picture directly.

I have been trying to do that and made a few post that works on that understanding.

Fdic answered 12/11, 2010 at 1:12 Comment(6)
+1 for last point about guarantees. I would be very impressed if it could follow much of the type of code that uses a lot of HOF and other dynamic features. I imagine that it would be useful mainly for evaluating the work of programmers that are either not smart enough to use such features or smart enough not to.Iolaiolande
I am not looking for a silver bullet. What I am looking for is more to give me a general idea.Quarrier
@Quarrier : Then you got it. :) pycallgraph should do your job. I have also provided the solution which I use more frequently to learn what going on. This can be made difficult though. Try tracing calls in a twisted application.Fdic
it is a twisted application :(Quarrier
your posts are great, I am trying your solution will keep you posted on how it turns out :)Quarrier
The pycallgraph module has now been moved I think. Follow this link for documentation and it had become an unmaintained one.Robbie

© 2022 - 2025 — McMap. All rights reserved.