from __future__ import annotations


def module_not_found_for(exc: ModuleNotFoundError, package: str) -> bool:
    """Return true when a ModuleNotFoundError belongs to an optional package."""

    missing = exc.name or ""
    return missing == package or missing.startswith(f"{package}.")


def reraise_unless_missing_package(exc: ModuleNotFoundError, package: str) -> None:
    if not module_not_found_for(exc, package):
        raise exc
