from pathlib import Path


def find_file_upwards(dirname: Path, basename: str) -> Path:
    """
    Returns the path of the first file with basename "basename", starting in "dirname" and looking upwards
    from there.
    """
    current = dirname.absolute()
    while True:
        file = current / basename
        if file.exists():
            return file
        if current.parent == current:
            raise FileNotFoundError(f"Cannot find {basename} in or above {dirname.absolute()}")  # pragma: no cover
        current = current.parent