Python: importing count modules?

I am a mid-end python developer at an animation studio and have been presented with a unique diagnostic request;

To evaluate which code is used and what is not.

As part of the expanding disorganized structure of Python modules importing modules: I need to count the python modules that are imported and, possibly at a deeper level, to find which methods call.

As for determining which methods are being called, I think it would be easy to solve by writing my own logging metaclass.

However, I cannot imagine how I should calculate or register the import of modules at different depths.

Thanks for any ideas you may have.

+7
python metaclass counting
source share
1 answer

If you have a way to implement the code, you can run the code under coverage.py . It is usually used for testing, but its main function will work here: it indicates which lines of code are launched and which are not.

+2
source share

All Articles