Hacker News new | past | comments | ask | show | jobs | submit login

Could it be, that this can't check absolute imports? My python project, has many files which depend on each other, but are not linked together in the generated graph. But one of my modules has a __init__.py with relative imports, and this shows links between the files imported in the __init__.py.

Lets say my project looks like this:

src/example/foo.py

src/example/bar.py

And If bar.py containse the statement "from example.foo import Foo" there is no link between the files foo and bar. Though, if the statement is "from .foo import Foo" it shows a link.




That's because dep-tree doesn't know it needs to resolve names starting from `src/`, as your imports have that piece of information trimmed. You can solve this by setting the PYTHONPATH env variable like this:

export PYTHONPATH=src


Perfect, that worked, thank you!

I thought this could be solved by changing the directory to src/ and then executing that command, but this didn't work.

This also seems to be an issue with the web app, e.g. the repository for the formatter black is only one white dot https://dep-tree-explorer.vercel.app/api?repo=https://github...


Yeah, the web app is quite limited, it doesn't accept any kind of configuration. Implementing the Python absolute path resolution mechanism was actually quite challenging, as there is just too many ways you can handle absolute imports.

I've seen people using tricks like the `sys.path.extend(["src"])` in the main file for being able to place source code into an `src` folder, but unfortunately, dep-tree is not able to take that into account.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: