Commits

Ian Cordasco committed b590a04 Merge

Merge in flint-merge-noqa

Comments (0)

Files changed (3)

 # -*- 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)
 
 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_
 
 
 # -*- 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.