在 python 中构建调用图,包括模块和函数? [英] Build a Call graph in python including modules and functions?
问题描述
我有一堆脚本来执行任务.而且我真的需要知道项目的调用图,因为它很混乱.我无法执行代码,因为它需要额外的硬件和软件才能执行.但是,我需要了解其背后的逻辑.所以,我需要知道是否有一个工具(不需要任何 python 文件执行)可以使用模块而不是跟踪或 python 解析器来构建调用图.我有这样的 C 工具,但没有 Python.
谢谢.
我发现的最好的工具是 pyan
,它是
Edmund Horner 的原始代码现在最好在他的 github 存储库中a>,并且有人还制作了一个两个版本的存储库,您可以从那里下载 Juha Jeronen 的版本.我制作了一个干净的版本,将他们的贡献结合到 我自己的 pyan 存储库,因为两个存储库都有很多其他软件.
I have a bunch of scripts to perform a task. And I really need to know the call graph of the project because it is very confusing. I am not able to execute the code because it needs extra HW and SW to do so. However, I need to understand the logic behind it. So, I need to know if there is a tool (which do not require any python file execution) that can build a call graph using the modules instead of the trace or python parser. I have such tools for C but not for python.
Thank you.
The best tool I've found is called pyan
, and was originally written by Edmund Horner, improved by him, and then given colorization and other features by Juha Jeronen. That version has useful commandline options:
Usage: pyan.py FILENAME... [--dot|--tgf]
Analyse one or more Python source files and generate an approximate call graph
of the modules, classes and functions within them.
Options:
-h, --help show this help message and exit
--dot output in GraphViz dot format
--tgf output in Trivial Graph Format
-v, --verbose verbose output
-d, --defines add edges for 'defines' relationships [default]
-n, --no-defines do not add edges for 'defines' relationships
-u, --uses add edges for 'uses' relationships [default]
-N, --no-uses do not add edges for 'uses' relationships
-c, --colored color nodes according to namespace [dot only]
-g, --grouped group nodes (create subgraphs) according to namespace
[dot only]
-e, --nested-groups create nested groups (subgraphs) for nested namespaces
(implies -g) [dot only]
Here's the result of running pyan.py --dot -c -e pyan.py | fdp -Tpng
:
Edmund Horner's original code is now best found in his github repository, and somebody has also made a repository with both versions, from where you can download Juha Jeronen's version. I've made a clean version combining their contributions into my own repository just for pyan, since both repositories have lots of other software.
这篇关于在 python 中构建调用图,包括模块和函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!