def get_sources(
    *,
    root: Path,
    src: tuple[str, ...],
    quiet: bool,
    verbose: bool,
    include: Pattern[str],
    exclude: Optional[Pattern[str]],
    extend_exclude: Optional[Pattern[str]],
    force_exclude: Optional[Pattern[str]],
    report: "Report",
    stdin_filename: Optional[str],
) -> set[Path]:
    """Compute the set of files to be formatted."""
    sources: set[Path] = set()

    assert root.is_absolute(), f"INTERNAL ERROR: `root` must be absolute but is {root}"
    using_default_exclude = exclude is None
    exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES) if exclude is None else exclude
    gitignore: Optional[dict[Path, PathSpec]] = None
    root_gitignore = get_gitignore(root)

    for s in src:
        if s == "-" and stdin_filename:
            path = Path(stdin_filename)
            if path_is_excluded(stdin_filename, force_exclude):
                report.path_ignored(
                    path,
                    "--stdin-filename matches the --force-exclude regular expression",
                )
                continue
            is_stdin = True
        else:
            path = Path(s)
            is_stdin = False

        # Compare the logic here to the logic in `gen_python_files`.
        if is_stdin or path.is_file():
            if resolves_outside_root_or_cannot_stat(path, root, report):
                if verbose:
                    out(f'Skipping invalid source: "{path}"', fg="red")
                continue

            root_relative_path = best_effort_relative_path(path, root).as_posix()
            root_relative_path = "/" + root_relative_path

            # Hard-exclude any files that matches the `--force-exclude` regex.
            if path_is_excluded(root_relative_path, force_exclude):
                report.path_ignored(
                    path, "matches the --force-exclude regular expression"
                )
                continue

            if is_stdin:
                path = Path(f"{STDIN_PLACEHOLDER}{str(path)}")

            if path.suffix == ".ipynb" and not jupyter_dependencies_are_installed(
                warn=verbose or not quiet
            ):
                continue

            if verbose:
                out(f'Found input source: "{path}"', fg="blue")
            sources.add(path)
        elif path.is_dir():
            path = root / (path.resolve().relative_to(root))
            if verbose:
                out(f'Found input source directory: "{path}"', fg="blue")

            if using_default_exclude:
                gitignore = {
                    root: root_gitignore,
                    path: get_gitignore(path),
                }
            sources.update(
                gen_python_files(
                    path.iterdir(),
                    root,
                    include,
                    exclude,
                    extend_exclude,
                    force_exclude,
                    report,
                    gitignore,
                    verbose=verbose,
                    quiet=quiet,
                )
            )
        elif s == "-":
            if verbose:
                out("Found input source stdin", fg="blue")
            sources.add(path)
        else:
            err(f"invalid path: {s}")

    return sources
Compute the set of files to be formatted.
src/black/__init__.py