from pathlib import Path
import yaml


def get_mapping(filepath: Path, var: str) -> dict:
    """
    Loa a YAML file and return a dictionary given a variable.
    :param filepath: YAML file path
    :param var: variable to return the dictionary for.
    :return: a dictionary
    """

    with open(filepath, "r") as stream:
        techs = yaml.safe_load(stream)

    mapping = {}
    for key, val in techs.items():
        if var in val:
            mapping[key] = val[var]

    return mapping