python 有没有好的Python依赖分析工具?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/508277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a good dependency analysis tool for Python?
提问by joeforker
Dependency analysis programs help us organize code by controlling the dependencies between modules in our code. When one module is a circular dependency of another module, it is a clue to find a way to turn that into a unidirectional dependency or merge two modules into one module.
依赖分析程序通过控制代码中模块之间的依赖关系来帮助我们组织代码。当一个模块是另一个模块的循环依赖时,找到一种方法将其转换为单向依赖或将两个模块合并为一个模块是一个线索。
What is the best dependency analysis tool for Python code?
Python 代码的最佳依赖分析工具是什么?
采纳答案by DzinX
I recommend using snakefoodfor creating graphical dependency graphs of Python projects. It detects dependencies nicely enough to immediately see areas for refactorisation. Its usage is pretty straightforward if you read a little bit of documentation.
我推荐使用snakefood来创建 Python 项目的图形依赖图。它可以很好地检测依赖关系,可以立即看到需要重构的区域。如果您阅读一些文档,它的用法非常简单。
Of course, you can omit the graph-creation step and receive a dependency dictionary in a file instead.
当然,您可以省略图形创建步骤,而是在文件中接收依赖字典。
回答by joeforker
PyStructure – Automated Structure and Dependency Analysis of Python Code
PyStructure - Python 代码的自动化结构和依赖分析
This is used for PyDev's refactoring features. http://pystructure.ifs.hsr.ch/trac/
这用于 PyDev 的重构功能。http://pystructure.ifs.hsr.ch/trac/
回答by John Fouhy
I don't know what is the bestdependency analysis tool. You could look into modulefinder
– it's a module in the standard library that determines the set of modules imported by a script.
我不知道最好的依赖分析工具是什么。您可以查看modulefinder
- 它是标准库中的一个模块,用于确定脚本导入的模块集。
Of course, with python you have problems of conditional imports, and even potentially scripts calling __import__
directly, so it may not find everything. This is why tools like py2exe need special help to cope with packages like PIL.
当然,使用 python 你会遇到条件导入的问题,甚至可能会__import__
直接调用脚本,所以它可能无法找到所有内容。这就是为什么像 py2exe 这样的工具需要特殊帮助来处理像 PIL 这样的包的原因。
回答by Himanshu Mishra
I'm not sure about the best tool, but dependency analysis is best done using extracting and scanning the python files of the project.
我不确定最好的工具,但最好使用提取和扫描项目的 python 文件来完成依赖项分析。
Here is one such tool using the above technique : orkohunter.net/depends
这是使用上述技术的一个这样的工具:orkohunter.net/depends