from typing import Union
from pathlib import Path


def find_table_file(root_project_dir: Union[str, Path]) -> Path:
    """Find the EUPS table file for a project.

    Parameters
    ----------
    root_project_dir
        Path to the root directory of the main documentation project. This
        is the directory containing the ``conf.py`` file and a ``ups``
        directory.

    Returns
    -------
    table_path
        Path to the EUPS table file.
    """
    root_project_dir = Path(root_project_dir)
    ups_dir_path = root_project_dir / "ups"
    table_path = None
    for p in ups_dir_path.iterdir():
        if p.suffix == ".table" and p.is_file():
            table_path = p
    if table_path is None:
        raise RuntimeError(
            f"Could not find the EUPS table file for {root_project_dir}"
        )
    return table_path