Skip to content

Commit 332cfd5

Browse files
Fixed #1771: Improved handling of skips against named streamed in content.
1 parent 034a5de commit 332cfd5

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
1010
- Fixed #1772: skip-gitignore will check files not in the git repository.
1111
- Fixed #1762: in some cases when skip-gitignore is set, isort fails to skip any files.
1212
- Fixed #1767: Encoding issues surfacing when invalid characters set in `__init__.py` files during placement.
13+
- Fixed #1771: Improved handling of skips against named streamed in content.
1314

1415
### 5.9.1 June 21st 2021 [hotfix]
1516
- Fixed #1758: projects with many files and skip_ignore set can lead to a command-line overload.

isort/main.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,10 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
10871087
if show_files:
10881088
sys.exit("Error: can't show files for streaming input.")
10891089

1090+
input_stream = sys.stdin if stdin is None else stdin
10901091
if check:
10911092
incorrectly_sorted = not api.check_stream(
1092-
input_stream=sys.stdin if stdin is None else stdin,
1093+
input_stream=input_stream,
10931094
config=config,
10941095
show_diff=show_diff,
10951096
file_path=file_path,
@@ -1098,15 +1099,18 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
10981099

10991100
wrong_sorted_files = incorrectly_sorted
11001101
else:
1101-
api.sort_stream(
1102-
input_stream=sys.stdin if stdin is None else stdin,
1103-
output_stream=sys.stdout,
1104-
config=config,
1105-
show_diff=show_diff,
1106-
file_path=file_path,
1107-
extension=ext_format,
1108-
raise_on_skip=False,
1109-
)
1102+
try:
1103+
api.sort_stream(
1104+
input_stream=input_stream,
1105+
output_stream=sys.stdout,
1106+
config=config,
1107+
show_diff=show_diff,
1108+
file_path=file_path,
1109+
extension=ext_format,
1110+
raise_on_skip=False,
1111+
)
1112+
except FileSkipped:
1113+
sys.stdout.write(input_stream.read())
11101114
elif "/" in file_names and not allow_root:
11111115
printer = create_terminal_printer(
11121116
color=config.color_output, error=config.format_error, success=config.format_success

tests/unit/test_main.py

+17
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,23 @@ def build_input_content():
370370
import b
371371
372372
373+
def function():
374+
pass
375+
"""
376+
)
377+
378+
# if file is skipped it should output unchanged.
379+
main.main(
380+
["-", "--filename", "x.py", "--skip", "x.py", "--filter-files"],
381+
stdin=build_input_content(),
382+
)
383+
out, error = capsys.readouterr()
384+
assert not error
385+
assert out == (
386+
"""
387+
import b
388+
import a
389+
373390
def function():
374391
pass
375392
"""

0 commit comments

Comments
 (0)