Commits

Ian Cordasco  committed b590a04 Merge

Merge in flint-merge-noqa

  • Participants
  • Parent commits 360dfb5, bc63ebe
  • Branches flint-merge

Comments (0)

Files changed (3)

File flake8/engine.py

 # -*- coding: utf-8 -*-
+import re
+
 import pep8
 
 from flake8 import __version__
 from flake8.util import OrderedSet
 
+_flake8_noqa = re.compile(r'flake8[:=]\s*noqa', re.I).search
+
 
 def _register_extensions():
     """Register all the extensions."""
     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):
     """Parse the options and configure the checker."""
     kwargs['parser'], options_hooks = get_parser()
-    styleguide = pep8.StyleGuide(**kwargs)
+    styleguide = StyleGuide(**kwargs)
     options = styleguide.options
     for options_hook in options_hooks:
         options_hook(options)

File flake8/hooks.py

 
 from flake8.engine import get_parser, get_style_guide
 from flake8.main import DEFAULT_CONFIG
-from flake8.util import skip_file
 
 
 def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
             if file_ in seen or not os.path.exists(file_):
                 continue
             seen.add(file_)
-            if file_.endswith('.py') and not skip_file(file_):
+            if file_.endswith('.py'):
                 yield file_
 
 

File flake8/util.py

 # -*- coding: utf-8 -*-
 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:
     import ast
     def add(self, value):
         if value not in self:
             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