import yaml


def _get_yaml_versions(yaml_file):
    """
    Return a dict with packages and versions from requirements.yaml.
    """
    with open(yaml_file, "r") as stream:
        env = yaml.safe_load(stream)

    versions = {}
    for dependency in env["dependencies"]:
        # remove channel prefix
        if "::" in dependency:
            dependency = dependency.split("::")[1]
        # split tool and version (ignore build if present)
        package, version = dependency.split("=")[0:2]
        versions[package] = version
    return versions