<commit_before>import functools
from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import LazyObject
from django.conf import settings as django_settings
from avocado.conf import global_settings


class Settings(object):
    def __init__(self, settings_dict):
        # set the initial settings as defined in the global_settings
        for setting in iter(dir(global_settings)):
            if setting == setting.upper():
                setattr(self, setting, getattr(global_settings, setting))

        # iterate over the user-defined settings and override the default
        # settings
        for key, value in iter(settings_dict.items()):
            if key == key.upper():
                setattr(self, key, value)


class LazySettings(LazyObject):
    def _setup(self):
        self._wrapped = Settings(getattr(django_settings, 'AVOCADO', {}))


settings = LazySettings()


# Keep track of the officially supported apps and libraries used for various
# features.
OPTIONAL_DEPS = {
    'haystack': False,
    'numpy': False,
    'scipy': False,
    'actstream': False,
    'openpyxl': False,
    'guardian': False,
}

# Full-text search engine
try:
    import haystack
    OPTIONAL_DEPS['haystack'] = True
except ImportError:
    pass

# High performance data structures
try:
    import numpy
    OPTIONAL_DEPS['numpy'] = True
except ImportError:
    pass

# Statistical functions
try:
    import scipy
    OPTIONAL_DEPS['scipy'] = True
except ImportError:
    pass

# Activity streams
try:
    import actstream
    if 'actstream' in django_settings.INSTALLED_APPS:
        OPTIONAL_DEPS['acstream'] = True
except ImportError:
    pass

# Native MS Excel reading/writing support
try:
    import openpyxl
    OPTIONAL_DEPS['openpyxl'] = True
except ImportError:
    pass

# Generic object-level permissions
try:
    import guardian
    OPTIONAL_DEPS['guardian'] = True
except ImportError:
    pass


def requires_dep(lib):
    "Decorator for functions that require a supported third-party library."
    def decorator(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            if not OPTIONAL_DEPS[lib]:
                raise ImproperlyConfigured('{0} must be installed to use this feature.'.format(lib))
            return f(*args, **kwargs)
        return wrapper
    return decorator
<commit_msg>Catch Haystack ImproperlyConfigured exception for dependency checking<commit_after>import functools
from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import LazyObject
from django.conf import settings as django_settings
from avocado.conf import global_settings


class Settings(object):
    def __init__(self, settings_dict):
        # set the initial settings as defined in the global_settings
        for setting in iter(dir(global_settings)):
            if setting == setting.upper():
                setattr(self, setting, getattr(global_settings, setting))

        # iterate over the user-defined settings and override the default
        # settings
        for key, value in iter(settings_dict.items()):
            if key == key.upper():
                setattr(self, key, value)


class LazySettings(LazyObject):
    def _setup(self):
        self._wrapped = Settings(getattr(django_settings, 'AVOCADO', {}))


settings = LazySettings()


# Keep track of the officially supported apps and libraries used for various
# features.
OPTIONAL_DEPS = {
    'haystack': False,
    'numpy': False,
    'scipy': False,
    'actstream': False,
    'openpyxl': False,
    'guardian': False,
}

# Full-text search engine
try:
    import haystack
    OPTIONAL_DEPS['haystack'] = True
except (ImportError, ImproperlyConfigured):
    pass

# High performance data structures
try:
    import numpy
    OPTIONAL_DEPS['numpy'] = True
except ImportError:
    pass

# Statistical functions
try:
    import scipy
    OPTIONAL_DEPS['scipy'] = True
except ImportError:
    pass

# Activity streams
try:
    import actstream
    if 'actstream' in django_settings.INSTALLED_APPS:
        OPTIONAL_DEPS['acstream'] = True
except ImportError:
    pass

# Native MS Excel reading/writing support
try:
    import openpyxl
    OPTIONAL_DEPS['openpyxl'] = True
except ImportError:
    pass

# Generic object-level permissions
try:
    import guardian
    OPTIONAL_DEPS['guardian'] = True
except ImportError:
    pass


def requires_dep(lib):
    "Decorator for functions that require a supported third-party library."
    def decorator(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            if not OPTIONAL_DEPS[lib]:
                raise ImproperlyConfigured('{0} must be installed to use this feature.'.format(lib))
            return f(*args, **kwargs)
        return wrapper
    return decorator

{'fraction_non_alphanumeric': 0.08433985839233653, 'fraction_numerical': 0.00041649312786339027, 'mean_word_length': 3.2354497354497354, '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': '480958', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1365, 'n_words': 423}