def minimal_watch_directories(to_watch: Path, to_exclude: Iterable[Path]):
    'Determine which subdirectory to watch recursively'
    try:
        to_watch = Path(to_watch)
    except TypeError:
        assert False, 'Please watch one directory at a time.'
    directories_to_exclude: List[Path] = [to_watch.joinpath(directory_to_exclude) for directory_to_exclude in to_exclude if to_watch.joinpath(directory_to_exclude).is_dir()]
    exclude_dir_parents = {to_watch}
    for directory_to_exclude in directories_to_exclude:
        parts = list(Path(directory_to_exclude).relative_to(to_watch).parts)[:(- 1)]
        dir_tmp = to_watch
        for part in parts:
            dir_tmp = Path(dir_tmp, part)
            exclude_dir_parents.add(dir_tmp)
    for directory in exclude_dir_parents:
        dir_path = Path(directory)
        (yield (dir_path, False))
        for item in Path(directory).iterdir():
            if (item.is_dir() and (item not in exclude_dir_parents) and (item not in directories_to_exclude)):
                (yield (item, True))
Determine which subdirectory to watch recursively
def minimal_watch_directories(to_watch: Path, to_exclude: Iterable[Path]):
    
    try:
        to_watch = Path(to_watch)
    except TypeError:
        assert False, 'Please watch one directory at a time.'
    directories_to_exclude: List[Path] = [to_watch.joinpath(directory_to_exclude) for directory_to_exclude in to_exclude if to_watch.joinpath(directory_to_exclude).is_dir()]
    exclude_dir_parents = {to_watch}
    for directory_to_exclude in directories_to_exclude:
        parts = list(Path(directory_to_exclude).relative_to(to_watch).parts)[:(- 1)]
        dir_tmp = to_watch
        for part in parts:
            dir_tmp = Path(dir_tmp, part)
            exclude_dir_parents.add(dir_tmp)
    for directory in exclude_dir_parents:
        dir_path = Path(directory)
        (yield (dir_path, False))
        for item in Path(directory).iterdir():
            if (item.is_dir() and (item not in exclude_dir_parents) and (item not in directories_to_exclude)):
                (yield (item, True))