from pathlib import Path
import string


def kernelspec_dir(kernelspec_store: Path, kernel_id: str) -> Path:
    """Return path to the kernelspec directory for a kernel with a given ID

    Parameters
    ----------
    kernelspec_store
        Path to the place kernelspec store where kernelspec dir should be
        placed.
    kernel_id
        Internal identifier of the kernel to instal. Should be short and
        URL-friendly. Must contain only ASCII numbers, ASCII letters, hyphen,
        period, underscore.

    Raises
    ------
    ValueError
        If `kernel_id` contains improper characters.

    Returns
    -------
    Path
        Path object to the directory where kernelspec should be installed.
    """
    allowed_characters = set(string.ascii_letters + string.digits + '_.-')
    if not set(kernel_id) <= allowed_characters:
        raise ValueError("kernel_id contains forbidden characters")

    return kernelspec_store / kernel_id