-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add support of isort>5 #16
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import List, cast | ||
|
||
try: | ||
from isort import SortImports | ||
import isort | ||
except ImportError: | ||
SortImports = None | ||
isort = None | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def apply_isort(content: str) -> str: | ||
logger.debug( | ||
"SortImports(file_contents=..., check=True, multi_line_output=3, " | ||
"include_trailing_comma=True, force_grid_wrap=0, use_parentheses=True, " | ||
"line_length=88, quiet=True)" | ||
) | ||
result = SortImports( | ||
file_contents=content, | ||
check=True, | ||
isort.check_code(code=content) | ||
isort_config_kwargs = dict( | ||
multi_line_output=3, | ||
include_trailing_comma=True, | ||
force_grid_wrap=0, | ||
use_parentheses=True, | ||
line_length=88, | ||
quiet=True, | ||
) | ||
return cast(str, result.output) | ||
logger.debug( | ||
"isort.code(code=..., {})".format( | ||
", ".join(f"{k}={v!r}" for k, v in isort_config_kwargs.items()) | ||
) | ||
) | ||
result: str = isort.code(code=content, **isort_config_kwargs) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this call needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replaces
check=True
and writes error messages tostdout
. See changes intest_main
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the error messages?
And if we do, is there a cleaner way to capture them than
stdout
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know... Some tests depend on error messages. Probably, we could raise an exception if
check_code
isFalse
Hm...
isort
has hardcoded prints to write tostdout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I had to include those error messages in the test assertions, because in
isort<5
there was no way to get rid of the messages.Now that we can run
isort
without pollutingstdout
with error messages, I think we should do that for simplicity's sake, and fix the tests as well – unless we get some benefit from having those error messages.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought
check=False
inisort<5
was for this?I vote to get rid of error messages in another PR in order to keep this PR clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created another PR: #17