PK!l\wwflake8_plugin_utils/__init__.pyfrom .plugin import Error, Plugin, Visitor # noqa:F401 from .utils import assert_error, assert_not_error # noqa:F401 PK!Oflake8_plugin_utils/plugin.pyimport ast import re from typing import Iterable, List, Tuple, Type FLAKE8_ERROR = Tuple[int, int, str, 'Plugin'] NOQA_REGEXP = re.compile(r'#.*noqa\s*($|[^:\s])', re.I) NOQA_ERROR_CODE_REGEXP = re.compile(r'#.*noqa\s*:\s*(\w+)', re.I) class Error: code: str message: str lineno: int col_offset: int def __init__(self, lineno: int, col_offset: int) -> None: self.lineno = lineno self.col_offset = col_offset class Visitor(ast.NodeVisitor): def __init__(self) -> None: self.errors: List[Error] = [] def error_from_node(self, error: Type[Error], node: ast.AST) -> None: self.errors.append(error(node.lineno, node.col_offset)) class Plugin: name: str version: str visitors: List[Type[Visitor]] def __init__(self, tree: ast.AST, filename: str) -> None: self._tree: ast.AST = tree self._filename: str = filename self._lines: List[str] = [] def run(self) -> Iterable[FLAKE8_ERROR]: if not self._tree or not self._lines: self._load_file() for visitor in self.visitors: _visitor = visitor() _visitor.visit(self._tree) for error in _visitor.errors: line = self._lines[error.lineno - 1] if not check_noqa(line, error.code): yield self._error(error) def _load_file(self) -> None: with open(self._filename) as f: self._lines = f.readlines() self._tree = ast.parse(''.join(self._lines)) def _error(self, error: Error) -> FLAKE8_ERROR: return ( error.lineno, error.col_offset, f'{error.code} {error.message}', self, ) def check_noqa(line: str, code: str) -> bool: if NOQA_REGEXP.search(line): return True match = NOQA_ERROR_CODE_REGEXP.search(line) if match: return match.groups()[0].lower() == code.lower() return False PK!a<<flake8_plugin_utils/utils.pyimport ast from textwrap import dedent from typing import Optional, Type from .plugin import Error, Visitor def _error_from_src(visitor_cls: Type[Visitor], src: str) -> Optional[Error]: visitor = visitor_cls() tree = ast.parse(dedent(src.strip())) visitor.visit(tree) if not visitor.errors: return None assert len(visitor.errors) == 1 return visitor.errors[0] def assert_error( visitor_cls: Type[Visitor], src: str, expected: Type[Error] ) -> None: err = _error_from_src(visitor_cls, src) assert err, f'Error "{expected.message}" not found in\n{src}' assert isinstance(err, expected) def assert_not_error(visitor_cls: Type[Visitor], src: str) -> None: err = _error_from_src(visitor_cls, src) assert not err, f'Error "{err.message}" found in\n{src}' # type: ignore PK!611+flake8_plugin_utils-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2019 Afonasev Evgeniy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTU)flake8_plugin_utils-0.2.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HVɠ^ ,flake8_plugin_utils-0.2.0.dist-info/METADATAVmo6_qC0E ˶, `f$]!(Z:\$Q#);;N M:}s=|x|*-d$x,*~EmՕ:#*Ͷ4)ꚫ>)x*œkZa!UO k%hJ1j"1Β[KU&D&'Bhʺ<~~-U7G:,x!UD5Uc?6fWo'h ez+rĮS,yY_qkŽIfQTR&7eg$d{\|߲9"+lF~ݐRe7v$)\PD'1ؘm&7 u]! c{{|uc`Sx΋EXH}Uc*4V'y.]eBےN@⡑EF/-yJ$/GYNmѾ?DU5%tWBG+ˣkj%4Nˉ"ӡH%0E 򓍖x!P+Mz:NLKhDȨT)wBp%̝՜Wj$uKR|PၭA:{ 5^Uq{%%kE =݄sgn+dO ; u[N[(Yyu 3;nL[\n~3X顋Ԩuh;@=RV62s7).`(gv)3;=xWʋW iclmfۉ4a!+/QSf+Am@XScLxmDzaazb9g-ga)[}#8;އͶ Qex|OVۮ|`'K"\`${(BP zh)cPK!Hx`W*flake8_plugin_utils-0.2.0.dist-info/RECORDOo0^KqPFG;0?j(,|K˓.obw}hWKI=s5v]-wlUXs\ƒ!VOh7#K=4] g\[!ejCߪ(jtW{$4DعbWxkϨilQ!]}N<yrm'*?=/lx%`m5[dhꯍ3޸ūbS*u(Pcc ~bJx>on*vӲd @]S#6n *oEvOK6@/1̏%N<86*~Q!1p PK!l\wwflake8_plugin_utils/__init__.pyPK!Oflake8_plugin_utils/plugin.pyPK!a<<flake8_plugin_utils/utils.pyPK!611+ flake8_plugin_utils-0.2.0.dist-info/LICENSEPK!HڽTU)flake8_plugin_utils-0.2.0.dist-info/WHEELPK!HVɠ^ ,4flake8_plugin_utils-0.2.0.dist-info/METADATAPK!Hx`W*&flake8_plugin_utils-0.2.0.dist-info/RECORDPKD