from typing import Optional
from pathlib import Path
from typing import Tuple


def _load_root_datadir(
    datadir_txt: Optional[Path],
) -> Tuple[Optional[Path], Optional[Path]]:
    """
    Locate the root and datadir, returning Paths if possible.

    Uses the location of the datadir.txt file to define the data directory
    and the 'root' directory.

    Parameters
    ----------
    datadir_txt: The location of the datadir.txt file, if loaded.

    Returns
    -------
    A tuple containing (rootdir, datadir). Each tuple component is None
    if the desired directory is not a accessible directory.
    """
    if datadir_txt is None:
        return (None, None)
    rootdir = datadir_txt.parent
    datadir = Path(datadir_txt.read_text())
    return (rootdir if rootdir.is_dir() else None, datadir if datadir.is_dir() else None)