Skip to content

Commit

Permalink
sort imports
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Jan 14, 2021
1 parent f76f6f8 commit 2887396
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.pytest_cache/
__pycache__/
/venvs/
/.task/
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ tasks:
- task: flit:install
vars:
ENV: "{{.ISORT_ENV}}"
EXTRA: plugins,dev
EXTRA: dev
cmds:
- "{{.ISORT_ENV}}/bin/isort ."
2 changes: 2 additions & 0 deletions flake8_codes/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# app
from ._cli import entrypoint


entrypoint()
5 changes: 4 additions & 1 deletion flake8_codes/_cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# built-in
import sys
from argparse import ArgumentParser
from typing import Iterator, List, NamedTuple, NoReturn, TextIO

# external
from flake8.main.application import Application

# app
from ._codes import extract
from ._plugins import get_installed, Plugin
from ._plugins import Plugin, get_installed


TEMPLATE = '{c.plugin.name:20} | {c.code:8} | {c.message}'
Expand Down
2 changes: 2 additions & 0 deletions flake8_codes/_codes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# app
from ._extract import extract


__all__ = ['extract']
30 changes: 28 additions & 2 deletions flake8_codes/_codes/_adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,45 @@
from pathlib import Path
from typing import Dict

from ._registry import registry
# app
from ._default import extract_default
from ._registry import registry


@registry.add
def extract_flake8_commas() -> Dict[str, str]:
# external
from flake8_commas._base import ERRORS

return dict(ERRORS.values())


@registry.add
def extract_flake8_debugger() -> Dict[str, str]:
# external
from flake8_debugger import DEBUGGER_ERROR_CODE
return {DEBUGGER_ERROR_CODE: 'trace found'}


@registry.add
def extract_flake8_mutable() -> Dict[str, str]:
# external
from mutable_defaults import MutableDefaultChecker

return {MutableDefaultChecker._code: MutableDefaultChecker._error_tmpl}


@registry.add
def extract_flake8_fixme() -> Dict[str, str]:
# external
from flake8_fixme import WORD_CODES

return {code: 'fixme found ({})'.format(word) for word, code in WORD_CODES.items()}


@registry.add
def extract_pep8_naming() -> Dict[str, str]:
# external
import pep8ext_naming

codes = dict()
Expand All @@ -53,6 +59,7 @@ def extract_pep8_naming() -> Dict[str, str]:

@registry.add
def extract_flake8_pyi() -> Dict[str, str]:
# external
import pyi
codes = dict()
for name, value in vars(pyi).items():
Expand All @@ -63,6 +70,7 @@ def extract_flake8_pyi() -> Dict[str, str]:

@registry.add
def extract_flake8_pytest_style() -> Dict[str, str]:
# external
from flake8_pytest_style import errors
codes = dict()
for error in vars(errors).values():
Expand All @@ -78,6 +86,7 @@ def extract_flake8_pytest_style() -> Dict[str, str]:

@registry.add
def extract_flake8_annotations_complexity() -> Dict[str, str]:
# external
from flake8_annotations_complexity.checker import AnnotationsComplexityChecker

with suppress(ImportError):
Expand All @@ -91,6 +100,7 @@ def extract_flake8_annotations_complexity() -> Dict[str, str]:

@registry.add
def extract_flake8_future_import() -> Dict[str, str]:
# external
from flake8_future_import import ALL_FEATURES
codes = dict()
tmpl = 'FI{}'
Expand All @@ -105,13 +115,15 @@ def extract_flake8_future_import() -> Dict[str, str]:

@registry.add
def extract_flake8_string_format() -> Dict[str, str]:
# external
from flake8_string_format import StringFormatChecker

return {'P{}'.format(c): m for c, m in StringFormatChecker.ERRORS.items()}


@registry.add
def extract_flake8_bandit() -> Dict[str, str]:
# external
from bandit.core.extension_loader import MANAGER

codes = dict()
Expand All @@ -127,10 +139,13 @@ def extract_flake8_bandit() -> Dict[str, str]:

@registry.add
def extract_pylint() -> Dict[str, str]:
# external
import pylint.checkers
try:
# external
from pylint.lint import MSGS
except ImportError:
# external
from pylint.lint.pylinter import MSGS

codes = dict()
Expand All @@ -155,6 +170,7 @@ def extract_pylint() -> Dict[str, str]:

@registry.add
def extract_pyflakes() -> Dict[str, str]:
# external
from flake8.plugins.pyflakes import FLAKE8_PYFLAKES_CODES
from pyflakes import messages

Expand All @@ -166,6 +182,7 @@ def extract_pyflakes() -> Dict[str, str]:

@registry.add
def extract_flake8_rst_docstrings() -> Dict[str, str]:
# external
from flake8_rst_docstrings import code_mappings_by_level

codes = dict()
Expand All @@ -178,6 +195,7 @@ def extract_flake8_rst_docstrings() -> Dict[str, str]:

@registry.add
def extract_flake8_django() -> Dict[str, str]:
# external
import flake8_django.checkers

codes = dict()
Expand All @@ -195,6 +213,7 @@ def extract_flake8_django() -> Dict[str, str]:

@registry.add
def extract_flake8_scrapy() -> Dict[str, str]:
# external
from flake8_scrapy import ScrapyStyleIssueFinder

codes = dict()
Expand All @@ -206,6 +225,7 @@ def extract_flake8_scrapy() -> Dict[str, str]:

@registry.add
def extract_flake8_executable() -> Dict[str, str]:
# external
import flake8_executable

path = Path(flake8_executable.__file__)
Expand All @@ -218,6 +238,7 @@ def extract_flake8_executable() -> Dict[str, str]:

@registry.add
def extract_flake8_strict() -> Dict[str, str]:
# external
from flake8_strict import ErrorCode

codes = dict()
Expand All @@ -228,6 +249,7 @@ def extract_flake8_strict() -> Dict[str, str]:

@registry.add
def extract_flake8_docstrings() -> Dict[str, str]:
# external
from pydocstyle.violations import ErrorRegistry

codes = dict()
Expand All @@ -239,6 +261,7 @@ def extract_flake8_docstrings() -> Dict[str, str]:

@registry.add
def extract_dlint() -> Dict[str, str]:
# external
from dlint.linters import ALL

codes = dict()
Expand All @@ -250,21 +273,24 @@ def extract_dlint() -> Dict[str, str]:

@registry.add
def extract_flake8_mock() -> Dict[str, str]:
from flake8_mock import MOCK_ERROR_CODE, ERROR_MESSAGE
# external
from flake8_mock import ERROR_MESSAGE, MOCK_ERROR_CODE

message = ERROR_MESSAGE.split(' ', maxsplit=1)[1]
return {MOCK_ERROR_CODE: message}


@registry.add
def extract_flake8_pytest() -> Dict[str, str]:
# external
from flake8_pytest import PYTEST_ERROR_CODE, PYTEST_ERROR_MESSAGE

return {PYTEST_ERROR_CODE: PYTEST_ERROR_MESSAGE}


@registry.add
def extract_wemake_python_styleguide() -> Dict[str, str]:
# external
from wemake_python_styleguide import violations

codes = dict()
Expand Down
3 changes: 2 additions & 1 deletion flake8_codes/_codes/_extract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# built-in
from typing import Dict
from importlib import import_module
from typing import Dict

# app
from ._default import extract_default
from ._registry import registry

Expand Down
3 changes: 3 additions & 0 deletions flake8_codes/_codes/_hardcoded.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# built-in
from typing import Dict

# app
from ._registry import registry


Expand All @@ -24,6 +26,7 @@ def extract_flake8_import_order() -> Dict[str, str]:

@registry.add
def extract_flake8_black() -> Dict[str, str]:
# external
from flake8_black import black_prefix

return {
Expand Down
2 changes: 2 additions & 0 deletions flake8_codes/_codes/_registry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@


# built-in
from typing import Callable, Dict, Optional


ExtractorType = Callable[[], Dict[str, str]]


Expand Down
4 changes: 3 additions & 1 deletion flake8_codes/_codes/_renamed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# built-in
from typing import Dict
from ._default import extract_default

# app
from ._default import extract_default
from ._registry import registry


Expand Down
3 changes: 2 additions & 1 deletion flake8_codes/_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ._discover import get_installed, Plugin
# app
from ._discover import Plugin, get_installed


__all__ = ['get_installed', 'Plugin']
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ line_length = 90
combine_as_imports = true
balanced_wrapping = true
lines_after_imports = 2
skip = "venvs/"
not_skip = "__init__.py"
multi_line_output = 5
include_trailing_comma = true
Expand Down
4 changes: 3 additions & 1 deletion tests/test_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import pytest

# project
from ._constants import KNOWN_PLUGINS
from flake8_codes._codes import extract
from flake8_codes._codes._default import extract_default
from flake8_codes._codes._registry import registry

# app
from ._constants import KNOWN_PLUGINS


@pytest.mark.parametrize('plugin_name', KNOWN_PLUGINS)
def test_smoke_extract(plugin_name):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import pytest
from flake8.main.application import Application

# project
from flake8_codes._codes import extract
from flake8_codes._plugins import get_installed

# app
from ._constants import KNOWN_PLUGINS


Expand Down

0 comments on commit 2887396

Please sign in to comment.