pydeps icon indicating copy to clipboard operation
pydeps copied to clipboard

Selecting depth for graph

Open androa opened this issue 5 years ago • 3 comments

I'm trying to analyze a very large Django app. The repo looks like something like this:

my_app
├── __init__.py
├── client
│   ├── __init__.py
│   ├── client.py
│   ├── middleware.py
│   ├── models.py
│   ├── settings.py
│   └── tasks.py
├── api
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── authentication.py
│   ├── managers.py
│   ├── migrations
│   ├── models.py
│   ├── permissions.py
│   ├── routers.py
│   ├── serializers.py
│   ├── templates
│   ├── tests
│   ├── urls
│   ├── views.py
│   └── viewsets.py
├── users
│   ├── __init__.py
│   ├── apps.py
│   ├── blocks
│   ├── documents.py

I'd like to be able to specify to what depth to graph the dependencies. I would like to figure out which modules (client, api, users, etc.) are depending on which, and which way the dependency goes.

As far as I've figured out, I can only generate a graph of everything, but that becomes huge and hard to navigate in. Or I can specify which modules I want with --only but then I'm missing the dependencies I already don't know about.

Is there any way I can graph everything, but create clusters of each module?

androa avatar Nov 05 '19 10:11 androa

Hi @androa and thank you for your interest in pydeps. Could you explain a bit more how you would like the graph filtered? I'm assuming you mean depth to mean the number of directories counted from the root of your app..? There are -x flags to exclude parts of the graph, --max-bacon to limit the number of "import" hops, and there is also a new --cluster flag, but that is mostly for external modules...

thebjorn avatar Nov 05 '19 10:11 thebjorn

That is correct. I think I've managed to get where I wanted by --max-bacon 1. The graph is still rather massive though. Which leads me into another question; is it possible to control the colors somehow? There is now two shades of red (which I don't quite understand the difference between), but it would very helpful to either out of the box get different colors for each module, or control it somehow (f.ex. a pattern that tells which items should be in different colors).

androa avatar Nov 05 '19 12:11 androa

Ok, good to know. I have min/max-depth functionality that works that way on an internal tool that's used for inter-module dependency analysis. It's a bit complex, but I'll see about moving it over to pydeps.

The current color algorithm takes the number of root nodes (in this context what is before the first dot in the module name), then it divides the H part of the HSL color space's 360 degrees by the number of root nodes to get the initial set of colors. Each Hue "angle" is then adjusted in the Saturation and Lightness dimensions by the in/out connectedness of a node. With many root-nodes, and because of deficiencies of the HSL color model (https://en.wikipedia.org/wiki/HSL_and_HSV#Disadvantages), this can lead to colors that are perceptually very similar.

Of the many algorithms I've tried, this has been the least sucky one... it has room for improvement ;-)

Feel free to add any ideas or suggestions to issue #34.

thebjorn avatar Nov 05 '19 13:11 thebjorn