from pathlib import Path
from typing import Dict
from typing import Any
import jinja2


def get_final_script(script_path: Path, variables: Dict[str, Any]) -> str:
    """Return the script with replaced placeholders.

    Args:
        script_path: Path to the script.
        variables: Placeholders to be replaced.

    Returns:
        The final script.

    Raises:
        TypeError if the script cannot be processed.
    """
    try:
        template = jinja2.Template(script_path.read_text())
    except UnicodeDecodeError:
        raise TypeError(f"can't read the script {script_path}") from None
    return template.render(**variables)