mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 23:34:17 +00:00
Merge in flint-merge-noqa
This commit is contained in:
commit
24c39fa704
3 changed files with 23 additions and 22 deletions
|
|
@ -1,9 +1,13 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import re
|
||||||
|
|
||||||
import pep8
|
import pep8
|
||||||
|
|
||||||
from flake8 import __version__
|
from flake8 import __version__
|
||||||
from flake8.util import OrderedSet
|
from flake8.util import OrderedSet
|
||||||
|
|
||||||
|
_flake8_noqa = re.compile(r'flake8[:=]\s*noqa', re.I).search
|
||||||
|
|
||||||
|
|
||||||
def _register_extensions():
|
def _register_extensions():
|
||||||
"""Register all the extensions."""
|
"""Register all the extensions."""
|
||||||
|
|
@ -46,10 +50,26 @@ def get_parser():
|
||||||
return parser, options_hooks
|
return parser, options_hooks
|
||||||
|
|
||||||
|
|
||||||
|
class StyleGuide(pep8.StyleGuide):
|
||||||
|
# Backward compatibility pep8 <= 1.4.2
|
||||||
|
checker_class = pep8.Checker
|
||||||
|
|
||||||
|
def input_file(self, filename, lines=None, expected=None, line_offset=0):
|
||||||
|
"""Run all checks on a Python source file."""
|
||||||
|
if self.options.verbose:
|
||||||
|
print('checking %s' % filename)
|
||||||
|
fchecker = self.checker_class(
|
||||||
|
filename, lines=lines, options=self.options)
|
||||||
|
# Any "# flake8: noqa" line?
|
||||||
|
if any(_flake8_noqa(line) for line in fchecker.lines):
|
||||||
|
return 0
|
||||||
|
return fchecker.check_all(expected=expected, line_offset=line_offset)
|
||||||
|
|
||||||
|
|
||||||
def get_style_guide(**kwargs):
|
def get_style_guide(**kwargs):
|
||||||
"""Parse the options and configure the checker."""
|
"""Parse the options and configure the checker."""
|
||||||
kwargs['parser'], options_hooks = get_parser()
|
kwargs['parser'], options_hooks = get_parser()
|
||||||
styleguide = pep8.StyleGuide(**kwargs)
|
styleguide = StyleGuide(**kwargs)
|
||||||
options = styleguide.options
|
options = styleguide.options
|
||||||
for options_hook in options_hooks:
|
for options_hook in options_hooks:
|
||||||
options_hook(options)
|
options_hook(options)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ except ImportError: # Python 2
|
||||||
|
|
||||||
from flake8.engine import get_parser, get_style_guide
|
from flake8.engine import get_parser, get_style_guide
|
||||||
from flake8.main import DEFAULT_CONFIG
|
from flake8.main import DEFAULT_CONFIG
|
||||||
from flake8.util import skip_file
|
|
||||||
|
|
||||||
|
|
||||||
def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
||||||
|
|
@ -64,7 +63,7 @@ def _get_files(repo, **kwargs):
|
||||||
if file_ in seen or not os.path.exists(file_):
|
if file_ in seen or not os.path.exists(file_):
|
||||||
continue
|
continue
|
||||||
seen.add(file_)
|
seen.add(file_)
|
||||||
if file_.endswith('.py') and not skip_file(file_):
|
if file_.endswith('.py'):
|
||||||
yield file_
|
yield file_
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
import os.path
|
|
||||||
import re
|
|
||||||
|
|
||||||
__all__ = ['ast', 'iter_child_nodes', 'OrderedSet', 'skip_file']
|
__all__ = ['ast', 'iter_child_nodes', 'OrderedSet']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ast
|
import ast
|
||||||
|
|
@ -40,19 +38,3 @@ class OrderedSet(list):
|
||||||
def add(self, value):
|
def add(self, value):
|
||||||
if value not in self:
|
if value not in self:
|
||||||
self.append(value)
|
self.append(value)
|
||||||
|
|
||||||
_NOQA = re.compile(r'flake8[:=]\s*noqa', re.I | re.M)
|
|
||||||
|
|
||||||
|
|
||||||
def skip_file(path, source=None):
|
|
||||||
"""Returns True if this header is found in path
|
|
||||||
|
|
||||||
# flake8: noqa
|
|
||||||
"""
|
|
||||||
if os.path.isfile(path):
|
|
||||||
with open(path) as f:
|
|
||||||
source = f.read()
|
|
||||||
elif not source:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return _NOQA.search(source) is not None
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue