def load_environment_variables()

in composer_local_dev/environment.py [0:0]


def load_environment_variables(env_dir_path: pathlib.Path) -> Dict:
    """
    Load environment variable to be sourced in the local Composer environment.
    Raises an error if the variables.env file does not exist
    in the ``env_dir_path``.
    Args:
        env_dir_path (pathlib.Path): Path to the local composer environment.

    Returns:
        Dict:
            Environment variables.
    """
    env_file_path = env_dir_path / "variables.env"
    LOG.info("Loading environment variables from %s", env_file_path)
    if not env_file_path.is_file():
        raise errors.ComposerCliError(
            f"Environment variables file '{env_file_path}' not found."
        )
    env_vars = dict()
    with open(env_file_path) as fp:
        for line in fp:
            line = line.strip()
            if not line or line.startswith("#"):
                continue
            key, value = parse_env_variable(line, env_file_path)
            if key in constants.NOT_MODIFIABLE_ENVIRONMENT_VARIABLES:
                LOG.warning(
                    "'%s' environment variable cannot be set "
                    "and will be ignored.",
                    key,
                )
            elif key in constants.STRICT_ENVIRONMENT_VARIABLES:
                possible_values = constants.STRICT_ENVIRONMENT_VARIABLES[key]
                if value not in possible_values:
                    LOG.warning(
                        "'%s' environment variable can be set "
                        "to the one of the following values: '%s'",
                        key,
                        ",".join(possible_values),
                    )
                else:
                    env_vars[key] = value
            else:
                env_vars[key] = value
    return env_vars