from pathlib import Path
from typing import Dict
from typing import Any
import yaml
from typing import cast


def read_variables_from_yaml(yaml_file: Path) -> Dict[str, Any]:
    """Read all variables from given yaml file and return as a dictionary."""
    if not yaml_file.is_file():
        raise FileNotFoundError(f"No file found at: {yaml_file}")  # pragma: no cover
    yaml_contents = yaml.safe_load(open(str(yaml_file), "r"))
    v = "variables"
    if v in yaml_contents:
        return cast(Dict[str, Any], yaml_contents[v])
    else:
        raise KeyError("The Yaml file was expected to contain a section '{}'".format(v))