<commit_before>import importlib
import logging

import core.input

log = logging.getLogger(__name__)

def load(module_name, config=None):
    try:
        mod = importlib.import_module('modules.{}'.format(module_name))
    except ImportError as error:
        log.fatal('failed to import {}: {}'.format(module_name, str(error)))
        return Error(module_name)
    return getattr(mod, 'Module')(config)

class Module(core.input.Object):
    def __init__(self, config=None, widgets=[]):
        super().__init__()
        self._config = config
        self._widgets = widgets if isinstance(widgets, list) else [ widgets ]
        self._name = None

    def parameter(self, key, default=None):
        value = default

        for prefix in [ self.name(), self.module_name() ]:
            value = self._config.get('{}.{}'.format(prefix, key), value)
        # TODO retrieve from config file
        return value

    def update(self):
        pass

    def name(self):
        return self._name if self._name else self.module_name()

    def module_name(self):
        return self.__module__.split('.')[-1]

    def widgets(self):
        return self._widgets

class Error(Module):
    def __init__(self, loaded_module_name):
        self._loaded_module_name = loaded_module_name

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4<commit_msg>[core/module] Fix error display<commit_after>import importlib
import logging

import core.input
import core.widget

log = logging.getLogger(__name__)

def load(module_name, config=None):
    try:
        mod = importlib.import_module('modules.{}'.format(module_name))
    except ImportError as error:
        log.fatal('failed to import {}: {}'.format(module_name, error))
        return Error(config, module_name, error)
    return getattr(mod, 'Module')(config)

class Module(core.input.Object):
    def __init__(self, config=None, widgets=[]):
        super().__init__()
        self._config = config
        self._widgets = widgets if isinstance(widgets, list) else [ widgets ]
        self._name = None

    def parameter(self, key, default=None):
        value = default

        for prefix in [ self.name(), self.module_name() ]:
            value = self._config.get('{}.{}'.format(prefix, key), value)
        # TODO retrieve from config file
        return value

    def update(self):
        pass

    def name(self):
        return self._name if self._name else self.module_name()

    def module_name(self):
        return self.__module__.split('.')[-1]

    def widgets(self):
        return self._widgets

class Error(Module):
    def __init__(self, config, module, error):
        super().__init__(config, core.widget.Widget(self.full_text))
        self._module = module
        self._error = error

    def full_text(self):
        return '{}: {}'.format(self._module, self._error)

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
{'fraction_non_alphanumeric': 0.12168217855911755, 'fraction_numerical': 0.002757669769045157, 'mean_word_length': 2.997245179063361, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678988', 'n_tokens_mistral': 863, 'n_tokens_neox': 842, 'n_words': 215}