示例#1
0
def default_loader(obj, defaults=None):
    """Loads default settings and check if there are overridings
    exported as environment variables"""
    defaults = defaults or {}
    default_settings_values = {
        key: value
        for key, value in default_settings.__dict__.items() if key.isupper()
    }

    all_keys = list(default_settings_values.keys()) + list(defaults.keys())

    for key in all_keys:
        value = defaults.get(key, default_settings_values.get(key))
        obj.logger.debug("default_loader: loading: %s:%s", key, value)
        obj.set(key, value)

    # start dotenv to get default env vars from there
    # check overrides in env vars
    default_settings.start_dotenv(obj)
    for key in all_keys:
        env_value = obj.get_environ(key, '_not_found')
        if env_value != '_not_found':
            obj.logger.debug("default_loader: overriding from envvar: %s:%s",
                             key, env_value)
            obj.set(key, env_value, tomlfy=True)
示例#2
0
def default_loader(obj, defaults=None):
    """Loads default settings and check if there are overridings
    exported as environment variables"""
    defaults = defaults or {}
    default_settings_values = {
        key: value
        for key, value in default_settings.__dict__.items()  # noqa
        if key.isupper()
    }

    all_keys = deduplicate(
        list(defaults.keys()) + list(default_settings_values.keys())
    )

    for key in all_keys:
        if not obj.exists(key):
            value = defaults.get(key, default_settings_values.get(key))
            obj.logger.debug("loading: %s:%s", key, value)
            obj.set(key, value)

    # start dotenv to get default env vars from there
    # check overrides in env vars
    default_settings.start_dotenv(obj)

    # Deal with cases where a custom ENV_SWITCHER_IS_PROVIDED
    # Example: Flask and Django Extensions
    env_switcher = defaults.get(
        "ENV_SWITCHER_FOR_DYNACONF", "ENV_FOR_DYNACONF"
    )

    for key in all_keys:
        if key not in default_settings_values.keys():
            continue

        env_value = obj.get_environ(
            env_switcher if key == "ENV_FOR_DYNACONF" else key,
            default="_not_found",
        )

        if env_value != "_not_found":
            obj.logger.debug("overriding from envvar: %s:%s", key, env_value)
            obj.set(key, env_value, tomlfy=True)
示例#3
0
def default_loader(obj, defaults=None):
    defaults = defaults or {}
    default_settings_values = {
        key: value
        for key, value in default_settings.__dict__.items() if key.isupper()
    }

    all_keys = list(default_settings_values.keys()) + list(defaults.keys())

    for key in all_keys:
        value = defaults.get(key, default_settings_values.get(key))
        obj.logger.debug("default_loader:loading: %s:%s", key, value)
        obj.set(key, value)

    # start dotenv to get default env vars from there
    # check overrides in env vars
    default_settings.start_dotenv(obj)
    for key in all_keys:
        env_value = obj.get_env(key)
        if env_value:
            obj.logger.debug("default_loader:overriding from envvar: %s:%s",
                             key, env_value)
            obj.set(key, env_value)