Skip to content

Commit

Permalink
Fixed #1771: Improved handling of skips against named streamed in con…
Browse files Browse the repository at this point in the history
…tent.
  • Loading branch information
timothycrosley committed Jul 8, 2021
1 parent 034a5de commit 332cfd5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
- Fixed #1772: skip-gitignore will check files not in the git repository.
- Fixed #1762: in some cases when skip-gitignore is set, isort fails to skip any files.
- Fixed #1767: Encoding issues surfacing when invalid characters set in `__init__.py` files during placement.
- Fixed #1771: Improved handling of skips against named streamed in content.

### 5.9.1 June 21st 2021 [hotfix]
- Fixed #1758: projects with many files and skip_ignore set can lead to a command-line overload.
Expand Down
24 changes: 14 additions & 10 deletions isort/main.py
Expand Up @@ -1087,9 +1087,10 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
if show_files:
sys.exit("Error: can't show files for streaming input.")

input_stream = sys.stdin if stdin is None else stdin
if check:
incorrectly_sorted = not api.check_stream(
input_stream=sys.stdin if stdin is None else stdin,
input_stream=input_stream,
config=config,
show_diff=show_diff,
file_path=file_path,
Expand All @@ -1098,15 +1099,18 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =

wrong_sorted_files = incorrectly_sorted
else:
api.sort_stream(
input_stream=sys.stdin if stdin is None else stdin,
output_stream=sys.stdout,
config=config,
show_diff=show_diff,
file_path=file_path,
extension=ext_format,
raise_on_skip=False,
)
try:
api.sort_stream(
input_stream=input_stream,
output_stream=sys.stdout,
config=config,
show_diff=show_diff,
file_path=file_path,
extension=ext_format,
raise_on_skip=False,
)
except FileSkipped:
sys.stdout.write(input_stream.read())
elif "/" in file_names and not allow_root:
printer = create_terminal_printer(
color=config.color_output, error=config.format_error, success=config.format_success
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_main.py
Expand Up @@ -370,6 +370,23 @@ def build_input_content():
import b
def function():
pass
"""
)

# if file is skipped it should output unchanged.
main.main(
["-", "--filename", "x.py", "--skip", "x.py", "--filter-files"],
stdin=build_input_content(),
)
out, error = capsys.readouterr()
assert not error
assert out == (
"""
import b
import a
def function():
pass
"""
Expand Down

0 comments on commit 332cfd5

Please sign in to comment.