thebjorn / pydeps

Python Module Dependency graphs
https://pydeps.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
1.8k stars 114 forks source link

Show only top-level imports #216

Open ThibaudDauce opened 7 months ago

ThibaudDauce commented 7 months ago

Hi,

Thanks for the awesome tool. I'm doing some research on a big Python project and I try to improve the number of top-level imports/imported_by. I don't care about imports inside function definition since they do not raise problems for import cycles… Is there a way to only report the top-level imports and exclude imports inside function definition?

Thanks!

thebjorn commented 7 months ago

Hi @ThibaudDauce and thank you for your interest in pydeps.

Pydeps uses (a patched version of) the standard library moduluefinder module and unfortunaetly there is no functionality there that knows whether an import is in the global namespace.

If you want to look into the possibility of making this (i.e. making the modulefinder code context aware) work, the code that needs to change is in pydeps/mf27.py in the ModuleFinder.scan_code(..) method. (I'm always happy to merge PRs ;-) )