def _update_versions_in_requirements(requirements: "list[str]", packages: dict) -> str:
    """Update the versions in requirements with the provided package to version mapping."""
    for i, package in enumerate(requirements.copy()):
        if package.startswith("#"):
            continue
        if not len(package.strip()):
            continue
        try:
            requirements[i] = package + "==" + packages[package.lower().replace("_", "-")]
        except KeyError:
            raise AttributeError(f"{package} could not be found in poetry.lock") from None
    return "\n".join(requirements)