diff --git a/src/black/__init__.py b/src/black/__init__.py index 4c730a33d48..746a1deef51 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -425,11 +425,19 @@ def main( else: out(f"Identified `{root}` as project root.", fg="blue") - normalized_paths = [ - str(Path(source).resolve().relative_to(root)) for source in src + normalized = [ + (normalize_path_maybe_ignore(Path(source), root), source) + for source in src ] - srcs_string = '", "'.join(normalized_paths) - out(f'Sources to be formatted: "{srcs_string}"', fg="blue") + srcs_string = ", ".join( + [ + f'"{_norm}"' + if _norm + else f'\033[31m"{source} (skipping - invalid)"\033[34m' + for _norm, source in normalized + ] + ) + out(f"Sources to be formatted: {srcs_string}", fg="blue") if config: config_source = ctx.get_parameter_source("config") diff --git a/src/black/files.py b/src/black/files.py index bf6dad7b5df..32b10da0c18 100644 --- a/src/black/files.py +++ b/src/black/files.py @@ -137,7 +137,9 @@ def get_gitignore(root: Path) -> PathSpec: def normalize_path_maybe_ignore( - path: Path, root: Path, report: Report + path: Path, + root: Path, + report: Optional[Report] = None, ) -> Optional[str]: """Normalize `path`. May return `None` if `path` was ignored. @@ -147,12 +149,16 @@ def normalize_path_maybe_ignore( abspath = path if path.is_absolute() else Path.cwd() / path normalized_path = abspath.resolve().relative_to(root).as_posix() except OSError as e: - report.path_ignored(path, f"cannot be read because {e}") + if report: + report.path_ignored(path, f"cannot be read because {e}") return None except ValueError: if path.is_symlink(): - report.path_ignored(path, f"is a symbolic link that points outside {root}") + if report: + report.path_ignored( + path, f"is a symbolic link that points outside {root}" + ) return None raise