from pathlib import Path


def _parse_path_run_session_id(path_session):
    """Parse `path_run` and `session_id` from path_session

    Parameters
    ----------
    path_session : str

    Returns
    -------
    path_dir, session_id: tuple[Path, int | None]
        If the path is to a session_directory the `path_run` (its parent path)
        and the `session_id` will be returned. If not the input parameter will
        be returned as a path object unchanged, along with `None` instead
        of `session_id`.

    """
    path_session = Path(path_session).resolve()

    head, underscore, tail = path_session.name.partition("_")
    if head == "session" and underscore == "_" and tail.isdecimal():
        return path_session.parent, int(tail)
    else:
        return path_session, None