Set any configuration options which have an environment var set.

    Args:
        config (confpy.core.config.Configuration): A configuration object which
            has been initialized with options.
        env (dict): Optional dictionary which contains environment variables.
            The default is os.environ if no value is given.
        prefix (str): The string prefix prepended to all environment variables.
            This value will be set to upper case. The default is CONFPY.

    Returns:
        confpy.core.config.Configuration: A configuration object with
            environment variables set.

    The pattern to follow when setting environment variables is:

        <PREFIX>_<SECTION>_<OPTION>

    Each value should be upper case and separated by underscores.

def set_environment_var_options(config, env=None, prefix='CONFPY'):
    """Set any configuration options which have an environment var set.

    Args:
        config (confpy.core.config.Configuration): A configuration object which
            has been initialized with options.
        env (dict): Optional dictionary which contains environment variables.
            The default is os.environ if no value is given.
        prefix (str): The string prefix prepended to all environment variables.
            This value will be set to upper case. The default is CONFPY.

    Returns:
        confpy.core.config.Configuration: A configuration object with
            environment variables set.

    The pattern to follow when setting environment variables is:

        <PREFIX>_<SECTION>_<OPTION>

    Each value should be upper case and separated by underscores.
    """
    env = env or os.environ
    for section_name, section in config:

        for option_name, _ in section:

            var_name = '{0}_{1}_{2}'.format(
                prefix.upper(),
                section_name.upper(),
                option_name.upper(),
            )
            env_var = env.get(var_name)
            if env_var:

                setattr(section, option_name, env_var)

    return config