I need a way to find the dependencies for each of my Python package's sub-modules at runtime so I can initialize them in a proper order (see my current [EDIT: former] solution here, which doesn't work to well), so at first I used the standard Python module modulefinder, but that was way too slow (~1-2 seconds per module).
My next choice was to analyze all the globals of each module, and find from those globals which sub-module each sub-module depends upon. (This is my current solution EDIT: I have a better solution now - see my answer). This algorithm is much faster than modulefinder (it takes <200ms per module), but it only works for relative imports, instead of the fully-qualified import style, which is unacceptable.
So, what I need is either:
- A quicker alternative to modulefinder
- An alternative algorithm
NOTE: I call my dependency analyzer at the start of each module, like so:
# File my_package/module3.py import my_package.module1 # Some misc. module import my_package.module2 # Some other misc. module import my_package.dependency_analyzer my_package.dependency_analyzer.gendeps() (Just in case it helps you any.)
Thank you!
EDIT: I have a solution now - see my answer.