Don't write back stdin to stdout when --check is passed
This commit is contained in:
parent
5bc40707af
commit
d1e0d79e38
11
black.py
11
black.py
@ -102,7 +102,9 @@ def main(
|
|||||||
report = Report()
|
report = Report()
|
||||||
try:
|
try:
|
||||||
if not p.is_file() and str(p) == '-':
|
if not p.is_file() and str(p) == '-':
|
||||||
changed = format_stdin_to_stdout(line_length=line_length, fast=fast)
|
changed = format_stdin_to_stdout(
|
||||||
|
line_length=line_length, fast=fast, write_back=not check
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
changed = format_file_in_place(
|
changed = format_file_in_place(
|
||||||
p, line_length=line_length, fast=fast, write_back=not check
|
p, line_length=line_length, fast=fast, write_back=not check
|
||||||
@ -178,7 +180,9 @@ def format_file_in_place(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def format_stdin_to_stdout(line_length: int, fast: bool) -> bool:
|
def format_stdin_to_stdout(
|
||||||
|
line_length: int, fast: bool, write_back: bool = False
|
||||||
|
) -> bool:
|
||||||
"""Format file on stdin and pipe output to stdout. Return True if changed."""
|
"""Format file on stdin and pipe output to stdout. Return True if changed."""
|
||||||
contents = sys.stdin.read()
|
contents = sys.stdin.read()
|
||||||
try:
|
try:
|
||||||
@ -189,7 +193,8 @@ def format_stdin_to_stdout(line_length: int, fast: bool) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
sys.stdout.write(contents)
|
if write_back:
|
||||||
|
sys.stdout.write(contents)
|
||||||
|
|
||||||
|
|
||||||
def format_file_contents(
|
def format_file_contents(
|
||||||
|
@ -89,7 +89,7 @@ def test_piping(self) -> None:
|
|||||||
try:
|
try:
|
||||||
sys.stdin, sys.stdout = StringIO(source), StringIO()
|
sys.stdin, sys.stdout = StringIO(source), StringIO()
|
||||||
sys.stdin.name = '<stdin>'
|
sys.stdin.name = '<stdin>'
|
||||||
black.format_stdin_to_stdout(line_length=ll, fast=True)
|
black.format_stdin_to_stdout(line_length=ll, fast=True, write_back=True)
|
||||||
sys.stdout.seek(0)
|
sys.stdout.seek(0)
|
||||||
actual = sys.stdout.read()
|
actual = sys.stdout.read()
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user