from pathlib import Path
import gzip
import shutil


def decompress_gz_file(gz_path: Path) -> Path:
    """
    Decompress a gzip-compressed file to disk, naming it by just removing the ".gz"
    suffix. If the output path already exists, assume it was already decompressed,
    and do not touch it.

    Args:
      gz_path : The path to the gzip-compressed file
    """
    if gz_path.suffix != ".gz":
        raise ValueError(f"Expected file suffix to be '.gz', got '{gz_path.suffix}'")
    out_path = gz_path.parent / gz_path.stem
    if not out_path.exists():
        with gzip.open(gz_path, "r") as f_in, open(out_path, "wb") as f_out:
            shutil.copyfileobj(f_in, f_out)
    return out_path