diff --git a/CHANGES.md b/CHANGES.md index 262d42e3c01..cb71e3f4ec4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -45,6 +45,9 @@ +- Write unchanged content to stdout when excluding formating from stdin using pipes + (#4610) + ### _Blackd_ diff --git a/src/black/__init__.py b/src/black/__init__.py index 79541df2149..c88aa4ef6c7 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -11,7 +11,6 @@ Iterator, MutableMapping, Sequence, - Sized, ) from contextlib import contextmanager from dataclasses import replace @@ -681,13 +680,12 @@ def main( # noqa: C901 except GitWildMatchPatternError: ctx.exit(1) - path_empty( - sources, - "No Python files are present to be formatted. Nothing to do 😴", - quiet, - verbose, - ctx, - ) + if not sources: + if verbose or not quiet: + out("No Python files are present to be formatted. Nothing to do 😴") + if "-" in src: + sys.stdout.write(sys.stdin.read()) + ctx.exit(0) if len(sources) == 1: reformat_one( @@ -820,18 +818,6 @@ def get_sources( return sources -def path_empty( - src: Sized, msg: str, quiet: bool, verbose: bool, ctx: click.Context -) -> None: - """ - Exit if there is no `src` provided for formatting - """ - if not src: - if verbose or not quiet: - out(msg) - ctx.exit(0) - - def reformat_code( content: str, fast: bool,