import pathlib
import tarfile
import toml


def extract_manifest(filename: pathlib.Path, manifest_name: str = "package.toml"):
    """Return the manifest as a dictionary from .tar.gz package."""
    with tarfile.open(filename, "r:gz") as tar:
        manifest = tar.extractfile(manifest_name)
        if manifest is None:
            raise ValueError(f"Missing manifest file: {manifest_name}")
        return toml.loads(manifest.read().decode())