from pathlib import Path


def find_root_folder(start_file: Path):
    """
    Find the root package folder from a file within the package
    """
    # Get starting location
    package_path = start_file if start_file.is_dir() else start_file.parent

    # Check current location isn't a path
    if not (package_path / "__init__.py").exists():
        raise ValueError("File not part of a package")

    # Walk up folders to find top level package path
    while (package_path.parent / "__init__.py").exists():
        package_path = package_path.parent

    return package_path