diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2020-07-27 01:53:15 -0700 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2020-07-27 01:53:15 -0700 |
commit | b40e584d0742a52fc061f4dd55a4e8469d19c34f (patch) | |
tree | 31a29a1a5afc1cd44f32c97b8f9e20d397465ac7 /example_isort_formatting_plugin/example_isort_formatting_plugin.py | |
parent | ca19112f21a4862d855485f1dfaf12f8ca6a52ea (diff) | |
download | isort-b40e584d0742a52fc061f4dd55a4e8469d19c34f.tar.gz |
Resolve #1353: Added support for output format plugin
Diffstat (limited to 'example_isort_formatting_plugin/example_isort_formatting_plugin.py')
-rw-r--r-- | example_isort_formatting_plugin/example_isort_formatting_plugin.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/example_isort_formatting_plugin/example_isort_formatting_plugin.py b/example_isort_formatting_plugin/example_isort_formatting_plugin.py new file mode 100644 index 00000000..ff65412f --- /dev/null +++ b/example_isort_formatting_plugin/example_isort_formatting_plugin.py @@ -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 |