import importlib
import pkgutil


def register_module(module, recursive=False):
    """
    Ensure module is loaded, so that decorators inside that module are activated.
    :param module:
    :param recursive: load also sub-modules.
    """
    if not recursive:
        # do nothing, thus function just makes sure that the module is loaded
        # before init() is called, to force registration of inner config objects
        return

    package_name = module.__name__
    return {
        name: importlib.import_module(package_name + '.' + name)
        for loader, name, is_pkg in pkgutil.walk_packages(module.__path__)
    }