Is there a good dependency analysis tool for Python? [closed]
Asked Answered
E

4

32

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?

Euglena answered 3/2, 2009 at 18:18 Comment(1)
These days, looks like pydeps is a popular solution.Enact
S
29

I recommend using snakefood for 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.

Of course, you can omit the graph-creation step and receive a dependency dictionary in a file instead.

Sultanate answered 3/2, 2009 at 22:26 Comment(4)
Very interesting stuff: I was looking for a quick way to determine the files used by a given python file and this was perfect: it's so much faster than the other solutions I've seen (using modulefinder etc). I think when I get the time I'll write my own AST based solution but this did the trick for now: thanks!Venality
@Venality snakefood is AST based, what's the problem?Euglena
Thanks for tip. Exactly what I needed. Not that it is not very Windows friendly. I ended up using it in Linux.Those
It's an interesting tool, but it is python 2 based, and chokes on some python 3 code. For example: print('something', file=sys.stderr)Gombach
M
2

I don't know what is the best dependency 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.

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.

Myriad answered 3/2, 2009 at 21:30 Comment(0)
E
1

PyStructure – Automated Structure and Dependency Analysis of Python Code

This is used for PyDev's refactoring features. http://pystructure.ifs.hsr.ch/trac/

Euglena answered 14/5, 2009 at 21:3 Comment(1)
PyStructure includes a type inference engine.Euglena
J
0

I'm not sure about the best tool, but dependency analysis is best done using extracting and scanning the python files of the project.

Here is one such tool using the above technique : orkohunter.net/depends

Jenna answered 6/1, 2017 at 17:4 Comment(1)
This link of yours is now dead :-(Apple

© 2022 - 2024 — McMap. All rights reserved.