Commits

Tarek Ziadé  committed fe62282

added a header to skip files

  • Participants
  • Parent commits eef0971

Comments (0)

Files changed (5)

 
 It also adds a few features:
 
+- files that starts with this header are skipped::
+
+    # flake8: noqa
+
 - lines that contains a "# NOQA" comment at the end will not issue a warning
 - merging pep8 and pyflakes options
 - a Mercurial hook
-#!/usr/bin/python
+#!/home/tarek/dev/bitbucket.org/flake8-clean/bin/python
 from flake8 import main
 
 if __name__ == '__main__':

File flake8/__init__.py

 """
 Implementation of the command-line I{flake8} tool.
 """
-
+import re
 import sys
 import os
 import _ast
     return line.strip().lower().endswith('# noqa')
 
 
+_NOQA = re.compile(r'^# flake8: noqa', re.I | re.M)
+
+
+def skip_file(path):
+    """Returns True if this header is found in path
+
+    # -*- flake8: noqa -*-
+    """
+    f = open(path)
+    try:
+        content = f.read()
+    finally:
+        f.close()
+    return _NOQA.match(content) is not None
+
+
 def checkPath(filename):
     """
     Check the given path, printing out any warnings detected.
             if os.path.isdir(arg):
                 for dirpath, dirnames, filenames in os.walk(arg):
                     for filename in filenames:
-                        if filename.endswith('.py'):
-                            fullpath = os.path.join(dirpath, filename)
-                            warnings += checkPath(fullpath)
-                            warnings += pep8.input_file(fullpath)
+                        if not filename.endswith('.py'):
+                            continue
+                        fullpath = os.path.join(dirpath, filename)
+                        if skip_file(fullpath):
+                            continue
+                        warnings += checkPath(fullpath)
+                        warnings += pep8.input_file(fullpath)
             else:
+                if skip_file(filename):
+                    continue
                 warnings += checkPath(arg)
                 warnings += pep8.input_file(arg)
 
 
     raise SystemExit(warnings > 0)
 
+
 def hg_hook(ui, repo, **kwargs):
     pep8.process_options()
     warnings = 0
         for file_ in repo[rev].files():
             if not file_.endswith('.py'):
                 continue
+            if skip_file(file_):
+                continue
             if file_ not in files:
                 files.append(file_)
 

File flake8/test/harness.py

 but got:
 %s''' % (input, repr(expectedOutputs), '\n'.join(map(str, w.messages))))
         return w
-

File flake8/test/test_other.py

         """
         If the target of a C{with} statement uses any or all of the valid forms
         for that part of the grammar (See
-        U{http://docs.python.org/reference/compound_stmts.html#the-with-statement}),
+        U{http://docs.python.org/reference/
+            compound_stmts.html#the-with-statement}),
         the names involved are checked both for definedness and any bindings
         created are respected in the suite of the statement and afterwards.
         """