def get_package_names_and_versions()

in src/reqfile-to-artifact/reqfile-to-artifact.py [0:0]


def get_package_names_and_versions(requirements_file: str) -> list:
    """
    Strip the requirements file to packages with versions and those without.
    Obtain the latest version if needed.
    """
    with_ver_reqlist = {}

    for package in requirements_file:
        split_location = package.find("==")
        if split_location > 0:
            package_name = package[:split_location].lower()
            pakcage_version = package[split_location+2:]

            with_ver_reqlist[package_name] = pakcage_version
        else:
            latest_version = get_latest_version_number(package)
            with_ver_reqlist[package] = latest_version

    return with_ver_reqlist