I need to find the dependencies for each of my Python package submodules at runtime so that I can initialize them in the correct order (see current solution < EDIT: href = "http://openblox.hg.sourceforge.net/hgweb/openblox/openblox/file/c4ee2c09fe03/src/obengine/depman.py" rel = "nofollow"> here , which does not work well), so first I used the standard Python module modulefinder , but it was so too slow (~ 1-2 seconds per module).
My next choice was to analyze all the global values of each module and find from those globals on which each submodule depends. (This is my current EDIT solution : I now have a better solution - see My answer). This algorithm is much faster than modulefinder (200 ms per module is required), but it works only for relative imports, and not for a fully qualified import style, which is unacceptable.
So I need either:
- A quick alternative to modulefinder
- Alternative algorithm
NOTE. I call my dependency analyzer at the beginning of each module, for example:
import my_package.module1
import my_package.module2
import my_package.dependency_analyzer
my_package.dependency_analyzer.gendeps()
(Just in case, this will help you.)
Thank!
EDIT: I have a solution now - see my answer.