pydeps
                                
                                 pydeps copied to clipboard
                                
                                    pydeps copied to clipboard
                            
                            
                            
                        Draw module internal dependencies
Hi,
my question somewhat relates to issue #25.
First, I encounter the same issue as outlined in that ticket. It got closed without addressing the issue unfortunately. The workaround mentioned there correctly works in the way that the python files become part of the output.
But the workaround does not work in case a modules file imports another file from the same module.
Given
mydir
|   `-- __init__.py
|   `-- controller.py
|   `-- database.py
|   `-- exceptions.py
|   `-- mainclass.py
    `-- models.py
and mydir.controller imports and uses mydir.database, then this dependency is not available in the graph.
Is there any way to make this dependency visible? I would like to use that information as it would ease refactoring / organizing code as it would greatly make internal oddities visible.
Kind regards alex
Hi Alexander, and thank you for your interest in pydeps.
I'm not sure I understand what you mean when you say:
and mydir.controller imports and uses mydir.database, then this dependency is not available in the graph.
Given the following project (the yamldirs command is from the https://pypi.org/project/yamldirs/ project, and packages up a directory into a yaml format -- sort of like tree but with contents):
(dev) go|c:\srv\tmp\issue42> yamldirs mydir
mydir:
  models.py: from . import exceptions
  __init__.py: from . import mainclass
  controller.py: from . import database, exceptions
  database.py: from . import exceptions
  exceptions.py: ''
  mainclass.py: from . import models, controller
where only mainclass.py is imported into __init__.py, but where the modules are "strongly connected", i.e. all modules are imported by some other module, and there is an import path from any module to __init__.py.  Running pydeps:
(dev) go|c:\srv\tmp\issue42> pydeps mydir
produces:

Ah, thanks for the quick reply! You understood me fully correctly. I see that this works with relative imports. The project I was testing with, uses absolute imports, even for files in the same module. I see if I can change that. Still, those absolute imports are not visible.
I'm also interested in absolute imports being shown, to visualise the structure of a given module that's being worked on.
@rugg2 I can't reproduce this with the current version of pydeps (v1.9.3). Changing the code to use absolute imports:
(dev) go|c:\srv\tmp\issue42> yamldirs mydir
mydir:
  models.py: from mydir import exceptions
  __init__.py: from mydir import mainclass
  controller.py: from mydir import database, exceptions
  database.py: from mydir import exceptions
  exceptions.py: ''
  mainclass.py: from mydir import models, controller
I still get the same graph. I've set the PYTHONPATH to the issue42 directory before running pydeps since there is no setup.py file here.
I have the same issue - the internal dependencies are not shown in the graphic.
When running with --show-deps, all internal modules are listed as being imported by __main__, rather than the actual imports between each other.
I am using absolute paths and mostly from ... import ....
@FabianNiehaus and @rugg2 if you want me to take a look at it, I'll need a small test case that reproduces the problem (I'm assuming I'm not understanding the situation since I've provided a testcase above that works for me).
I created an minimum working example: pydeps-test.zip
I set the pythonpath to the src directory.
This is the output of pydeps:
(venv) [...]\pydeps-test\app> pydeps --show-deps --show-dot src
{
    "__main__": {
        "bacon": 0,
        "imports": [
            "src",
            "src.main_class"
        ],
        "name": "__main__",
        "path": null
    },
    "src": {
        "bacon": 1,
        "imported_by": [
            "__main__"
        ],
        "name": "src",
        "path": "[...]\\pydeps-test\\app\\src\\__init__.py"
    },
    "src.main_class": {
        "bacon": 1,
        "imported_by": [
            "__main__"
        ],
        "name": "src.main_class",
        "path": "[...]\\pydeps-test\\app\\src\\main_class.py"
    }
}
digraph G {
    concentrate = true;
    rankdir = TB;
    node [style=filled,fillcolor="#ffffff",fontcolor="#000000",fontname=Helvetica,fontsize=10];
}
You have your pythonpath set to the wrong directory. If you set it to the app directory you'll get the graph you want with by running the exact same pydeps call from the exact same directory.
Hi @thebjorn, hi everyone! just to support the thread. I found the same issue, not being able to see absolute imports. I have been changing the pythonpath to root directory and elsewhere, without any results. It looks impossible to see the arrows for relating modules in the same package. (That can be even perceived from each of the examples in git repo README). Myself have tried with several projects, and looks no issue of configuration. It will be of great help if the project supports this feature, if some help is needed I'd be happy to help. Cheers
Hi @intiamaru and thanks for your interest in pydeps. Since I can't reproduce this problem, it would be helpful with a complete description of how to reproduce it...