<commit_before># ~/ceam/ceam/modules/__init__.py
from collections import defaultdict

import pandas as pd

from ceam.events import EventHandler

class ModuleException(Exception):
    pass
class DependencyException(ModuleException):
    pass

class ModuleRegistry(object):
    def __init__(self, base_module_class=None):
        self._base_module_id = None
        self._modules = {}
        if base_module_class is not None:
            module = base_module_class()
            module.setup()
            self._base_module_id = module.module_id()
            self.__register(module)

    def __register(self, module):
        module.register(self)
        self._modules[module.module_id()] = module

    def register_modules(self, modules):
        for module in modules:
            self.__register(module)

        self._sort_modules()

    def __deregister(self, module):
        module.deregister(self)
        del self._modules[module.__class__]

    def deregister_modules(self, modules):
        for module in modules:
            self.__deregister(module)

        self._sort_modules()

    @property
    def modules(self):
        """
        A read only list of registered modules.
        """
        return tuple(self._ordered_modules)

    def _sort_modules(self):
        def inner_sort(sorted_modules, current):
            if current in sorted_modules:
                return sorted_modules
            if not current.DEPENDENCIES:
                return [current] + sorted_modules
            else:
                i = 0
                for dependency in current.DEPENDENCIES:
                    if dependency not in self._modules:
                        self.__register(dependency())

                    try:
                        i = max(i, sorted_modules.index(self._modules[dependency]))
                    except ValueError:
                        sorted_modules = inner_sort(sorted_modules, self._modules[dependency])
                        i = max(i, sorted_modules.index(self._modules[dependency]))
                return sorted_modules[0:i+1] + [current] + sorted_modules[i+1:]

        to_sort = set(self._modules.values())

        if self._base_module_id is not None:<commit_msg>Minor spelling and line-space.<commit_after># ~/ceam/ceam/modules/__init__.py

from collections import defaultdict

import pandas as pd

from ceam.events import EventHandler

class ModuleException(Exception):
    pass
class DependencyException(ModuleException):
    pass

class ModuleRegistry(object):
    def __init__(self, base_module_class=None):
        self._base_module_id = None
        self._modules = {}
        if base_module_class is not None:
            module = base_module_class()
            module.setup()
            self._base_module_id = module.module_id()
            self.__register(module)

    def __register(self, module):
        module.register(self)
        self._modules[module.module_id()] = module

    def register_modules(self, modules):
        for module in modules:
            self.__register(module)

        self._sort_modules()

    def __deregister(self, module):
        module.deregister(self)
        del self._modules[module.__class__]

    def deregister_modules(self, modules):
        for module in modules:
            self.__deregister(module)

        self._sort_modules()

    @property
    def modules(self):
        """
        A read-only list of registered modules.
        """
        return tuple(self._ordered_modules)

    def _sort_modules(self):
        def inner_sort(sorted_modules, current):
            if current in sorted_modules:
                return sorted_modules
            if not current.DEPENDENCIES:
                return [current] + sorted_modules
            else:
                i = 0
                for dependency in current.DEPENDENCIES:
                    if dependency not in self._modules:
                        self.__register(dependency())

                    try:
                        i = max(i, sorted_modules.index(self._modules[dependency]))
                    except ValueError:
                        sorted_modules = inner_sort(sorted_modules, self._modules[dependency])
                        i = max(i, sorted_modules.index(self._modules[dependency]))
                return sorted_modules[0:i+1] + [current] + sorted_modules[i+1:]

        to_sort = set(self._modules.values())

        if self._base_module_id is not None:
{'fraction_non_alphanumeric': 0.08202247191011236, 'fraction_numerical': 0.0017977528089887641, 'mean_word_length': 2.0423786739576215, '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': '7023915', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1132, 'n_words': 269}