-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Mystic-Mirage/isort_v5
Add support of isort>5
- Loading branch information
Showing
6 changed files
with
27 additions
and
26 deletions.
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