import typing
import builtins
import pathlib


def split_filename(
    filepath: typing.Union[builtins.str, pathlib.Path]
) -> typing.Tuple[pathlib.Path, builtins.str, builtins.str]:
    """split a filepath into the directory, base, and extension"""
    filepath = pathlib.Path(filepath).resolve()
    path = filepath.parent
    _base = pathlib.Path(filepath.stem)
    ext = filepath.suffix
    if ext == ".gz":
        ext2 = _base.suffix
        base = str(_base.stem)
        ext = ext2 + ext
    else:
        base = str(_base)
    return pathlib.Path(path), base, ext