Search code examples
pythondependency-managementcall-flow

Creating Dependency Graphs in Python


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.


Solution

    • 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.