def all_files(path, ignore=None):
    """Find all files in a directory recursively, optionally ignoring some paths.

    :param path: The path to the directory to search. Can be a string or a `Path` object.
    :param ignore: A callable similar to `ignore` parameter of `shutil.copytree`.
        E.g. `shutil.ignore_patterns('__pycache__')`.
    :return: A generator of `Path` objects.
    """
    for member in Path(path).iterdir():
        ignored = ignore(path, [member.name]) if ignore else set()
        if member.name in ignored:
            continue
        if member.is_dir():
            yield from all_files(member, ignore)
        else:
            yield member
Find all files in a directory recursively, optionally ignoring some paths.

    :param path: The path to the directory to search. Can be a string or a `Path` object.
    :param ignore: A callable similar to `ignore` parameter of `shutil.copytree`.
        E.g. `shutil.ignore_patterns('__pycache__')`.
    :return: A generator of `Path` objects.
    
olive/common/utils.py