def gendeps():
    """Adds the calling module to the initialization queue."""
calling_module_name = getframe(1).f_globals['__name__']
examined_modules.append(calling_module_name)

def init():
    """Initializes all examined modules in the correct order."""
for module in examined_modules:
    module = sys.modules[module]
if hasattr(module, 'init'):
    module.init()
if hasattr(module, 'deinit'):
    atexit.register(module.deinit)
Python dependency analyzer library