Skip to content

Commit

Permalink
don't use flake8 Application
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Feb 9, 2021
1 parent 33394cc commit 5d9901e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ tasks:

mypy:run:
sources:
- deal/**/*.py
- flake8_codes/**/*.py
deps:
- task: flit:install
vars:
ENV: "{{.MYPY_ENV}}"
EXTRA: dev
cmds:
- "{{.MYPY_ENV}}/bin/mypy --ignore-missing-imports --allow-redefinition deal/"
- "{{.MYPY_ENV}}/bin/mypy --ignore-missing-imports --allow-redefinition flake8_codes/"

pytest:run:
deps:
Expand Down
6 changes: 1 addition & 5 deletions flake8_codes/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
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 Plugin, get_installed
Expand All @@ -25,8 +22,7 @@ def normalize(name: str) -> str:


def get_codes(lookup_name: str) -> Iterator[Code]:
app = Application()
plugins = sorted(get_installed(app=app), key=lambda p: p.name)
plugins = sorted(get_installed(), key=lambda p: p.name)
if not plugins:
return

Expand Down
12 changes: 4 additions & 8 deletions flake8_codes/_plugins/_discover.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# built-in
import re
from collections import defaultdict
from typing import DefaultDict, Dict, Iterable, Iterator, List, NamedTuple, Tuple
from typing import DefaultDict, Iterable, Iterator, List, NamedTuple, Tuple

from flake8.main.application import Application
# external
from flake8.plugins.manager import Plugin as Flake8Plugin
from flake8._compat import importlib_metadata

# app
from ._plugin import get_plugin_name

try:
import importlib.metadata as importlib_metadata
except ImportError:
import importlib_metadata # type: ignore


REX_CODE = re.compile(r'^[A-Z]{1,5}[0-9]{0,5}$')

Expand All @@ -38,7 +34,7 @@ class Plugin(NamedTuple):
version: str


def get_installed(app: Application) -> Iterator[Plugin]:
def get_installed() -> Iterator[Plugin]:
plugins_codes: DefaultDict[str, List[str]]
plugins_codes = defaultdict(list)
versions = dict()
Expand Down
4 changes: 1 addition & 3 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

# external
import pytest
from flake8.main.application import Application

# project
from flake8_codes._codes import extract
Expand All @@ -16,8 +15,7 @@
@patch('sys.argv', ['flake8'])
@pytest.mark.parametrize('plugin_name', KNOWN_PLUGINS)
def test_smoke_prefixes(plugin_name):
app = Application()
plugins = {plugin.name: plugin for plugin in get_installed(app=app)}
plugins = {plugin.name: plugin for plugin in get_installed()}
plugin = plugins[plugin_name]

codes = extract(plugin_name)
Expand Down

0 comments on commit 5d9901e

Please sign in to comment.