From 0c8bdf3c5fc8ebffe95cc07aca3ab164f4629c9a Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 9 Feb 2021 23:22:59 -0800 Subject: [PATCH 1/3] Add wemake profile --- CHANGELOG.md | 1 + docs/configuration/profiles.md | 8 +++ isort/profiles.py | 7 +++ tests/unit/profiles/test_wemake.py | 80 ++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 tests/unit/profiles/test_wemake.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 483a13928..710eccb1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/ - Fixed #1631: as import comments can in some cases be duplicated. - Implemented #1648: Export MyPY type hints. - Implemented #1641: Identified import statements now return runnable code. + - Implemented #1661: Added "wemake" profile. ### 5.7.0 December 30th 2020 - Fixed #1612: In rare circumstances an extra comma is added after import and before comment. diff --git a/docs/configuration/profiles.md b/docs/configuration/profiles.md index 9de48e0f7..073f7d60d 100644 --- a/docs/configuration/profiles.md +++ b/docs/configuration/profiles.md @@ -76,3 +76,11 @@ To use any of the listed profiles, use `isort --profile PROFILE_NAME` from the c - **force_grid_wrap**: `0` - **use_parentheses**: `True` - **line_length**: `100` + +#wemake + + + - **multi_line_output**: `3` + - **include_trailing_comma**: `True` + - **use_parentheses**: `True` + - **line_length**: `80` diff --git a/isort/profiles.py b/isort/profiles.py index cb8cb5688..00ebe418e 100644 --- a/isort/profiles.py +++ b/isort/profiles.py @@ -55,6 +55,12 @@ "use_parentheses": True, "line_length": 100, } +wemake = { + "multi_line_output": 3, + "include_trailing_comma": True, + "use_parentheses": True, + "line_length": 80, +} profiles: Dict[str, Dict[str, Any]] = { "black": black, @@ -65,4 +71,5 @@ "plone": plone, "attrs": attrs, "hug": hug, + "wemake": wemake, } diff --git a/tests/unit/profiles/test_wemake.py b/tests/unit/profiles/test_wemake.py new file mode 100644 index 000000000..5e17a6ad6 --- /dev/null +++ b/tests/unit/profiles/test_wemake.py @@ -0,0 +1,80 @@ +"""A set of test cases for the wemake isort profile. + +Snippets are taken directly from the wemake-python-styleguide project here: +https://github.com/wemake-services/wemake-python-styleguide +""" +from functools import partial + +from ..utils import isort_test + +wemake_isort_test = partial(isort_test, profile="wemake", known_first_party=["wemake_python_styleguide"]) + + +def test_wemake_snippet_one(): + wemake_isort_test(""" +import ast +import tokenize +import traceback +from typing import ClassVar, Iterator, Sequence, Type + +from flake8.options.manager import OptionManager +from typing_extensions import final + +from wemake_python_styleguide import constants, types +from wemake_python_styleguide import version as pkg_version +from wemake_python_styleguide.options.config import Configuration +from wemake_python_styleguide.options.validation import validate_options +from wemake_python_styleguide.presets.types import file_tokens as tokens_preset +from wemake_python_styleguide.presets.types import filename as filename_preset +from wemake_python_styleguide.presets.types import tree as tree_preset +from wemake_python_styleguide.transformations.ast_tree import transform +from wemake_python_styleguide.violations import system +from wemake_python_styleguide.visitors import base + +VisitorClass = Type[base.BaseVisitor] +""" + ) + + +def test_wemake_snippet_two(): + wemake_isort_test(""" +from collections import defaultdict +from typing import ClassVar, DefaultDict, List + +from flake8.formatting.base import BaseFormatter +from flake8.statistics import Statistics +from flake8.style_guide import Violation +from pygments import highlight +from pygments.formatters import TerminalFormatter +from pygments.lexers import PythonLexer +from typing_extensions import Final + +from wemake_python_styleguide.version import pkg_version + +#: That url is generated and hosted by Sphinx. +DOCS_URL_TEMPLATE: Final = ( + 'https://wemake-python-stylegui.de/en/{0}/pages/usage/violations/' +) +""") + + +def test_wemake_snippet_three(): + wemake_isort_test(""" +import ast + +from pep8ext_naming import NamingChecker +from typing_extensions import final + +from wemake_python_styleguide.transformations.ast.bugfixes import ( + fix_async_offset, + fix_line_number, +) +from wemake_python_styleguide.transformations.ast.enhancements import ( + set_if_chain, + set_node_context, +) + + +@final +class _ClassVisitor(ast.NodeVisitor): +""") From 146dfe6e9468a784c1177ae7fdce3235c8805d4f Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 9 Feb 2021 23:26:02 -0800 Subject: [PATCH 2/3] Fix formatting --- tests/unit/profiles/test_wemake.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/unit/profiles/test_wemake.py b/tests/unit/profiles/test_wemake.py index 5e17a6ad6..ad9530131 100644 --- a/tests/unit/profiles/test_wemake.py +++ b/tests/unit/profiles/test_wemake.py @@ -7,11 +7,14 @@ from ..utils import isort_test -wemake_isort_test = partial(isort_test, profile="wemake", known_first_party=["wemake_python_styleguide"]) +wemake_isort_test = partial( + isort_test, profile="wemake", known_first_party=["wemake_python_styleguide"] +) def test_wemake_snippet_one(): - wemake_isort_test(""" + wemake_isort_test( + """ import ast import tokenize import traceback @@ -37,7 +40,8 @@ def test_wemake_snippet_one(): def test_wemake_snippet_two(): - wemake_isort_test(""" + wemake_isort_test( + """ from collections import defaultdict from typing import ClassVar, DefaultDict, List @@ -55,11 +59,13 @@ def test_wemake_snippet_two(): DOCS_URL_TEMPLATE: Final = ( 'https://wemake-python-stylegui.de/en/{0}/pages/usage/violations/' ) -""") +""" + ) def test_wemake_snippet_three(): - wemake_isort_test(""" + wemake_isort_test( + """ import ast from pep8ext_naming import NamingChecker @@ -77,4 +83,5 @@ def test_wemake_snippet_three(): @final class _ClassVisitor(ast.NodeVisitor): -""") +""" + ) From 22d2cc776d19f188db7a223aa75507ba676b1f22 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 9 Feb 2021 23:33:24 -0800 Subject: [PATCH 3/3] Make last snippet valid code --- tests/unit/profiles/test_wemake.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/profiles/test_wemake.py b/tests/unit/profiles/test_wemake.py index ad9530131..2d1fb22df 100644 --- a/tests/unit/profiles/test_wemake.py +++ b/tests/unit/profiles/test_wemake.py @@ -82,6 +82,6 @@ def test_wemake_snippet_three(): @final -class _ClassVisitor(ast.NodeVisitor): +class _ClassVisitor(ast.NodeVisitor): ... """ )