from pathlib import Path


def find_package_top(file: Path):
    """Find package top directory."""
    while True:
        if len(file.parts) == 1:
            raise ValueError('Package top was not found!')
        if not file.with_name('__init__.py').exists():
            break
        file = file.parent
    return file