Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 583
joeforker Avatar asked Feb 03 '09 18:02

joeforker


People also ask

How do you prefer to manage Python dependencies?

Using venv and pipenv are two methods of managing dependencies in Python. They are simple to implement and, for most users, adequate solutions for handling multiple projects with different dependencies. However, they are not the only solutions. Other services can complement their use.

How do I check the dependencies of a Python package?

Pip Check Command – Check Python Dependencies After Installation. Because pip doesn't currently address dependency issues on installation, the pip check command option can be used to verify that dependencies have been installed properly in your project. For example: $ pip check No broken requirements found.

Can Python modules have dependencies?

Dependency Hell Dependency conflicts occur when different Python packages have the same dependency, but depend on different and incompatible versions of that shared package. Because only a single version of a dependency is permitted in any project's environment, finding a compatible solution can be difficult.

How do you find the dependency tree in Python?

One easy way of doing so is to use the pipdeptree utility. The pipdeptree works on the command line and shows the installed python packages in the form of a dependency tree.


3 Answers

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.

like image 146
DzinX Avatar answered Oct 10 '22 03:10

DzinX


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.

like image 40
John Fouhy Avatar answered Oct 10 '22 01:10

John Fouhy


PyStructure – Automated Structure and Dependency Analysis of Python Code

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

like image 44
joeforker Avatar answered Oct 10 '22 02:10

joeforker