Format data with given env.

    :param data: a string/integer/float/boolean/list/dict object.
    :param env: a dictionary.
    :return: return formatted data.

    `format_config` will try to format strings contained env placeholder `{{ ENV_KEY }}`.

    If `ENV_KEY` does not exist in env, then this function will trhow assertion error.

def format_config(data, env):
    """
    Format data with given env.

    :param data: a string/integer/float/boolean/list/dict object.
    :param env: a dictionary.
    :return: return formatted data.

    `format_config` will try to format strings contained env placeholder `{{ ENV_KEY }}`.

    If `ENV_KEY` does not exist in env, then this function will trhow assertion error.
    """
    if isinstance(data, list):
        return [format_config(datum, env) for datum in data]
    elif isinstance(data, dict):
        return {
            format_config(key, env): format_config(value, env)
            for key, value in data.items()
        }
    elif isinstance(data, str):
        def replace(match):
            var_name = match.group(1)
            var = env.get(var_name)
            assert var, 'Variable %s undefined.' % var_name
            return var
        return ENV_PLACEHODLER.sub(replace, data)
    else:
        return data