<commit_before>import os
from celery.loaders.base import BaseLoader

DEFAULT_CONFIG_MODULE = "celeryconfig"

DEFAULT_SETTINGS = {
    "DEBUG": False,
    "DATABASE_ENGINE": "sqlite3",
    "DATABASE_NAME": "celery.sqlite",
    "INSTALLED_APPS": ("celery", ),
}


def wanted_module_item(item):
    is_private = item.startswith("_")
    return not is_private


class Loader(BaseLoader):
    """The default loader.

    See the FAQ for example usage.

    """

    def read_configuration(self):
        """Read configuration from ``celeryconfig.py`` and configure
        celery and Django so it can be used by regular Python."""
        config = dict(DEFAULT_SETTINGS)
        configname = os.environ.get("CELERY_CONFIG_MODULE",
                                    DEFAULT_CONFIG_MODULE)
        celeryconfig = __import__(configname, {}, {}, [''])
        import celeryconfig
        usercfg = dict((key, getattr(celeryconfig, key))
                            for key in dir(celeryconfig)
                                if wanted_module_item(key))
        config.update(usercfg)
        from django.conf import settings
        if not settings.configured:
            settings.configure()
        for config_key, config_value in usercfg.items():
            setattr(settings, config_key, config_value)
        return settings

    def on_worker_init(self):
        """Imports modules at worker init so tasks can be registered
        and used by the worked.

        The list of modules to import is taken from the ``CELERY_IMPORTS``
        setting in ``celeryconf.py``.

        """
        imports = getattr(self.conf, "CELERY_IMPORTS", [])
        for module in imports:
            __import__(module, [], [], [''])<commit_msg>Default Loader: Always add celery to INSTALLED_APPS<commit_after>import os
from celery.loaders.base import BaseLoader

DEFAULT_CONFIG_MODULE = "celeryconfig"

DEFAULT_SETTINGS = {
    "DEBUG": False,
    "DATABASE_ENGINE": "sqlite3",
    "DATABASE_NAME": "celery.sqlite",
    "INSTALLED_APPS": ("celery", ),
}


def wanted_module_item(item):
    is_private = item.startswith("_")
    return not is_private


class Loader(BaseLoader):
    """The default loader.

    See the FAQ for example usage.

    """

    def read_configuration(self):
        """Read configuration from ``celeryconfig.py`` and configure
        celery and Django so it can be used by regular Python."""
        config = dict(DEFAULT_SETTINGS)
        configname = os.environ.get("CELERY_CONFIG_MODULE",
                                    DEFAULT_CONFIG_MODULE)
        celeryconfig = __import__(configname, {}, {}, [''])
        import celeryconfig
        usercfg = dict((key, getattr(celeryconfig, key))
                            for key in dir(celeryconfig)
                                if wanted_module_item(key))
        config.update(usercfg)
        from django.conf import settings
        if not settings.configured:
            settings.configure()
        for config_key, config_value in usercfg.items():
            setattr(settings, config_key, config_value)
        installed_apps = set(DEFAULT_SETTINGS["INSTALLED_APPS"] + \
                             settings.INSTALLED_APPS)
        settings.INSTALLED_APPS = tuple(installed_apps)
        return settings

    def on_worker_init(self):
        """Imports modules at worker init so tasks can be registered
        and used by the worked.

        The list of modules to import is taken from the ``CELERY_IMPORTS``
        setting in ``celeryconf.py``.

        """
        imports = getattr(self.conf, "CELERY_IMPORTS", [])
        for module in imports:
            __import__(module, [], [], [''])
{'fraction_non_alphanumeric': 0.09766050054406965, 'fraction_numerical': 0.000544069640914037, 'mean_word_length': 2.398336414048059, 'pattern_counts': {'":': 8, '<': 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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5664018', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1031, 'n_words': 273}