在Python中创建依赖图 [英] Creating Dependency Graphs in Python

查看:206
本文介绍了在Python中创建依赖图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个巨大的代码库,需要对其进行一些小的更改。我想知道是否有实用程序可以解析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.

推荐答案


  • 通常,依赖性是为模块/包导入定义的。

  • 您正在寻找可视化的呼叫流程。

    • Usually "dependency" is defined for module / package import.
    • What you are looking for is a visualizing call flow.

      • http://pycallgraph.slowchop.com/

      您仍然不能保证不会破坏功能:)

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

      我的经验和解决方案:

      很多次,我发现呼叫流数据不堪重负,并且图表过于复杂。
      所以我通常做的是对该函数感兴趣的跟踪调用流程。

      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.

      这是通过利用sys.settrace(。 。)功能。在将调用流作为文本数据生成之后,我使用graphviz生成了一个调用图。

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

      • http://docs.python.org/library/sys.html
      • On call tracing
      • For generating graphs, use graphviz solutions from networkX.

      然后我的零散解决方案效果更好。只需插入代码,然后在要跟踪的函数上使用装饰器即可。您会看到延迟出现的差距,但是可以解决。您不会直接获得完整的图片。

      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.

      这篇关于在Python中创建依赖图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆