<commit_before>
import os
import yaml


class Config(object):

    def __init__(self, config):
        self._config = config

    def __repr__(self):
        return repr(self._config)

    def __getattr__(self, key):
        if key in self._config:
            return self._config[key]

    def get(self, *args, **kwargs):
        return self._config.get(*args, **kwargs)


_config = None


def load():
    global _config
    if _config is not None:
        return _config
    data = None
    config_file = os.environ.get('DOCKER_REGISTRY_CONFIG', 'config.yml')
    config_path = os.path.join(os.path.dirname(__file__), '..', config_file)
    with open(config_path) as f:
        data = yaml.load(f)
    config = data.get('common', {})
    flavor = os.environ.get('SETTINGS_FLAVOR', 'dev')
    config.update(data.get(flavor, {}))
    config['flavor'] = flavor
    _config = Config(config)
    return _config<commit_msg>Add ability to set env var in config value<commit_after>
import os
import yaml


class Config(object):

    def __init__(self, config):
        self._config = config

    def __repr__(self):
        return repr(self._config)

    def __getattr__(self, key):
        if key in self._config:
            return self._config[key]

    def get(self, *args, **kwargs):
        return self._config.get(*args, **kwargs)


def _walk_object(obj, callback):
    if not hasattr(obj, '__iter__'):
        return callback(obj)
    if isinstance(obj, dict):
        for i, value in obj.iteritems():
            obj[i] = _walk_object(value, callback)
        return obj
    for i, value in enumerate(obj):
        obj[i] = _walk_object(value, callback)
    return obj


def convert_env_vars(config):
    def _replace_env(s):
        if isinstance(s, basestring) and s.startswith('_env:'):
            return os.environ.get(s[5:], '!ENV_NOT_FOUND')
        return s

    return _walk_object(config, _replace_env)


_config = None


def load():
    global _config
    if _config is not None:
        return _config
    data = None
    config_file = os.environ.get('DOCKER_REGISTRY_CONFIG', 'config.yml')
    config_path = os.path.join(os.path.dirname(__file__), '..', config_file)
    with open(config_path) as f:
        data = yaml.load(f)
    config = data.get('common', {})
    flavor = os.environ.get('SETTINGS_FLAVOR', 'dev')
    config.update(data.get(flavor, {}))
    config['flavor'] = flavor
    config = convert_env_vars(config)
    _config = Config(config)
    return _config
{'fraction_non_alphanumeric': 0.12294094013660105, 'fraction_numerical': 0.0004017677782241864, 'mean_word_length': 2.8425925925925926, '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': '7168563', 'n_tokens_mistral': 825, 'n_tokens_neox': 807, 'n_words': 200}