-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve #1353: Added support for output format plugin
- Loading branch information
1 parent
ca19112
commit b40e584
Showing
15 changed files
with
509 additions
and
184 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
22 changes: 22 additions & 0 deletions
22
example_isort_formatting_plugin/example_isort_formatting_plugin.py
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import black | ||
|
||
import isort | ||
|
||
|
||
def black_format_import_section( | ||
contents: str, extension: str, config: isort.settings.Config | ||
) -> str: | ||
"""Formats the given import section using black.""" | ||
if extension.lower() not in ("pyi", "py"): | ||
return contents | ||
|
||
try: | ||
return black.format_file_contents( | ||
contents, | ||
fast=True, | ||
mode=black.FileMode( | ||
is_pyi=extension.lower() == "pyi", line_length=config.line_length, | ||
), | ||
) | ||
except black.NothingChanged: | ||
return contents |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[tool.poetry] | ||
name = "example_isort_formatting_plugin" | ||
version = "0.0.1" | ||
description = "An example plugin that modifies isort formatting using black." | ||
authors = ["Timothy Crosley <[email protected]>"] | ||
license = "MIT" | ||
|
||
[tool.poetry.plugins."isort.formatters"] | ||
example = "example_isort_formatting_plugin:black_format_import_section" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.6" | ||
isort = "^5.1.4" | ||
black = "^19.10b0" | ||
|
||
[tool.poetry.dev-dependencies] | ||
|
||
[build-system] | ||
requires = ["poetry>=0.12"] | ||
build-backend = "poetry.masonry.api" |
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
Oops, something went wrong.