Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception raised on sorting stdin with isort:skip_file #1705

Closed
epage opened this issue Apr 14, 2021 · 1 comment
Closed

Exception raised on sorting stdin with isort:skip_file #1705

epage opened this issue Apr 14, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@epage
Copy link

epage commented Apr 14, 2021

isort version 5.8.0

We put isort:skip_file in some of our code-gen files. When we run isort across the entire repo, it works.

Recently, we've integrated isort into something like a pre-commit hook (arc diff). Since we were combining it with Black, we pipe things through stdin/stdout but we are hitting errors with isort:skip_file.

Traceback (most recent call last):
  File "/Users/edpage/.cache/venv/lib/python3.9/site-packages/isort/api.py", line 185, in sort_stream
    changed = core.process(
  File "/Users/edpage/.cache/venv/lib/python3.9/site-packages/isort/core.py", line 151, in process
    raise FileSkipComment("Passed in content")
isort.exceptions.FileSkipComment: Passed in content contains an file skip comment and was skipped.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/edpage/.cache/venv/bin/isort", line 8, in <module>
    sys.exit(main())
  File "/Users/edpage/.cache/venv/lib/python3.9/site-packages/isort/main.py", line 1085, in main
    api.sort_stream(
  File "/Users/edpage/.cache/venv/lib/python3.9/site-packages/isort/api.py", line 192, in sort_stream
    raise FileSkipComment(content_source)
isort.exceptions.FileSkipComment: Passed in content contains an file skip comment and was skipped.

When processing files, isort catches this and records it as a skip. When processing streams, nothing catches the exception and continues to stream out the content, as I would expect.

There are various changes we can make to our hook but they seem like we'd be re-implementing logic in isort and that addressing this in isort in some way would be more correct.

@timothycrosley
Copy link
Member

I agree this is not ideal! I've done my best to address this here: #1706. When streaming (from the commandline utility), if isort encounters a skip file comment, instead of raising an exception - it will now stream the remainder of the file without modification.

@timothycrosley timothycrosley added the bug Something isn't working label Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants