from importlib.metadata import version

from packaging.version import Version


def has_minimal_version(distribution: str, minimal_version: str) -> bool:
    """Check if the installed version of a distribution meets or exceeds min_version."""
    return Version(version(distribution)) >= Version(minimal_version)


def assert_has_minimal_version(distribution: str, minimal_version: str) -> None:
    """Raise RuntimeError if the installed version of a distribution is below min_version."""
    if not has_minimal_version(distribution, minimal_version):
        raise RuntimeError(f"Requires {distribution!r} >= {minimal_version}")
