def load_modules():
    """
    Read names of enabled modules in modules/enabled directory and
    import them from modules directory.
    """
    pre_module_loading.send_robust(sender="module_loader")
    modules = {}
    for module_import_path in get_modules_to_load():
        module_name = module_import_path.split('.')[-1]
        try:
            modules[module_name] = importlib.import_module(module_import_path)
        except Exception as exception:
            logger.exception('Could not import %s: %s', module_import_path,
                             exception)
            if cfg.develop:
                raise

    ordered_modules = []
    remaining_modules = dict(modules)  # Make a copy
    # Place all essential modules ahead of others in module load order
    sorted_modules = sorted(
        modules, key=lambda module: not _is_module_essential(modules[module]))
    for module_name in sorted_modules:
        if module_name not in remaining_modules:
            continue

        module = remaining_modules.pop(module_name)
        try:
            _insert_modules(module_name, module, remaining_modules,
                            ordered_modules)
        except KeyError:
            logger.error('Unsatified dependency for module - %s', module_name)

    logger.info('Initializing apps - %s', ', '.join(ordered_modules))

    for module_name in ordered_modules:
        _initialize_module(module_name, modules[module_name])
        loaded_modules[module_name] = modules[module_name]

    logger.debug('App initialization completed.')
    post_module_loading.send_robust(sender="module_loader")
Exemple #2
0
def load_modules():
    """
    Read names of enabled modules in modules/enabled directory and
    import them from modules directory.
    """
    pre_module_loading.send_robust(sender="module_loader")
    modules = {}
    for module_import_path in get_modules_to_load():
        logger.debug('Importing %s', module_import_path)
        module_name = module_import_path.split('.')[-1]
        try:
            modules[module_name] = importlib.import_module(module_import_path)
        except Exception as exception:
            logger.exception('Could not import %s: %s', module_import_path,
                             exception)
            if cfg.debug:
                raise

        _include_module_urls(module_import_path, module_name)

    ordered_modules = []
    remaining_modules = dict(modules)  # Make a copy
    for module_name in modules:
        if module_name not in remaining_modules:
            continue

        module = remaining_modules.pop(module_name)
        try:
            _insert_modules(module_name, module, remaining_modules,
                            ordered_modules)
        except KeyError:
            logger.error('Unsatified dependency for module - %s',
                         module_name)

    logger.info('Module load order - %s', ordered_modules)

    for module_name in ordered_modules:
        _initialize_module(module_name, modules[module_name])
        loaded_modules[module_name] = modules[module_name]

    post_module_loading.send_robust(sender="module_loader")
Exemple #3
0
def load_modules():
    """
    Read names of enabled modules in modules/enabled directory and
    import them from modules directory.
    """
    pre_module_loading.send_robust(sender="module_loader")
    modules = {}
    for module_import_path in get_modules_to_load():
        logger.info('Importing %s', module_import_path)
        module_name = module_import_path.split('.')[-1]
        try:
            modules[module_name] = importlib.import_module(module_import_path)
        except Exception as exception:
            logger.exception('Could not import %s: %s', module_import_path,
                             exception)
            if cfg.debug:
                raise

        _include_module_urls(module_import_path, module_name)

    ordered_modules = []
    remaining_modules = dict(modules)  # Make a copy
    for module_name in modules:
        if module_name not in remaining_modules:
            continue

        module = remaining_modules.pop(module_name)
        try:
            _insert_modules(module_name, module, remaining_modules,
                            ordered_modules)
        except KeyError:
            logger.error('Unsatified dependency for module - %s', module_name)

    logger.debug('Module load order - %s', ordered_modules)

    for module_name in ordered_modules:
        _initialize_module(module_name, modules[module_name])
        loaded_modules[module_name] = modules[module_name]

    post_module_loading.send_robust(sender="module_loader")