PK!u  flake8_plugin_utils/__init__.pyimport ast import re from typing import Iterable, List, Optional, 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 def get_error( # type: ignore plugin: Type[Plugin], tmpdir, src: str ) -> Optional[str]: """only for test with pytest""" path = tmpdir.join('code.py') path.write(src) errors = list(plugin(None, path).run()) # type: ignore if not errors: return None assert len(errors) == 1 return errors[0][2] PK!611+flake8_plugin_utils-0.1.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.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H~ˏ~$ ,flake8_plugin_utils-0.1.0.dist-info/METADATAVmo6_qC0Xb'C ˖, `f$]!-Zd6mmߑl7p<=kiJ5 ^3b8 WZ>hr^"kQ8G)K*&4y9ZǪbT)V)XsȄ`Rrͫ,J\ZQT5#}"tV)|E~aRT};Fυ4["go10N$70%a5\2LZTp|pfg8n/6aY#~ei+ZI$;Os϶L\obaP\ \ϛIGghgMΙJ$56Jp&**jk,f+adEHD?%}<jA.yF?𚥜ڬUr } ^M<_E` }yrꐐ{Z8pYa5sN=IkngtXѲ.! &Fͪcj;m$쀦nwء.҇ܞV>L:\v߳Ø>&{p 7h`%%Se 6׽;e0=iY)Vd>TC 95LͶ7yϽ: /cìu"6*Bݚ;sSW͔a`\>'9S !&|cR.1m}pz> \P{0(U24FXSŘo L>x[&~[wz'>sg+ɯI4O%4m`m3p