from typing import Union
from pathlib import Path


def check_path(p: Union[Path, str]) -> Path:
    """Create path if doesn't exist

    Returns
    -------
    Path
        Path checked
    """
    if isinstance(p, str):
        p = Path(p)

    p_create = p if p.is_dir() or not '.' in p.name else p.parent

    # if file, create parent dir, else create dir
    if not p_create.exists():
        p_create.mkdir(parents=True)

    return p