import shutil
import subprocess
import tarfile
import tempfile

import yaml


def load_yaml(raw: str):
    return yaml.safe_load(raw)


def run_command(parts: list[str]):
    return subprocess.run(parts, shell=False, check=True)


def unpack(archive_path: str, target: str):
    with tarfile.open(archive_path) as archive:
        archive.extractall(target, filter="data")


def make_temp_copy(data: bytes):
    path = tempfile.mkdtemp()
    try:
        return path
    finally:
        shutil.rmtree(path)