pydeps icon indicating copy to clipboard operation
pydeps copied to clipboard

Show only top-level imports

Open ThibaudDauce opened this issue 1 year ago • 1 comments

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!

ThibaudDauce avatar Apr 03 '24 09:04 ThibaudDauce

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 ;-) )

thebjorn avatar Apr 03 '24 13:04 thebjorn