import pathlib


def create_dirs(dirpath: pathlib.Path) -> pathlib.Path:
    """Create directories and populate with appropriate __init__.py.

    Args:
        dirpath: a pathlib Path.

    Returns:
        path to __init__.py

    """
    cwd = pathlib.Path.cwd()
    mod_init = dirpath / "__init__.py"
    dirpath.mkdir(parents=True, exist_ok=True)
    for directory in mod_init.parents:
        if directory == cwd:
            break
        (directory / "__init__.py").touch()
    return mod_init