diff --git a/README b/README index 9412a4b..e890f05 100644 --- a/README +++ b/README @@ -10,6 +10,10 @@ options and just uses its defaults. 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 diff --git a/bin/flake8 b/bin/flake8 index 7150262..864c9ba 100755 --- a/bin/flake8 +++ b/bin/flake8 @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/home/tarek/dev/bitbucket.org/flake8-clean/bin/python from flake8 import main if __name__ == '__main__': diff --git a/flake8/__init__.py b/flake8/__init__.py index d9626cd..2f5574e 100644 --- a/flake8/__init__.py +++ b/flake8/__init__.py @@ -2,7 +2,7 @@ """ Implementation of the command-line I{flake8} tool. """ - +import re import sys import os import _ast @@ -73,6 +73,22 @@ def _noqa(warning): 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. @@ -96,11 +112,16 @@ def main(): 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) @@ -110,6 +131,7 @@ def main(): raise SystemExit(warnings > 0) + def hg_hook(ui, repo, **kwargs): pep8.process_options() warnings = 0 @@ -118,6 +140,8 @@ def hg_hook(ui, repo, **kwargs): 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_) diff --git a/flake8/test/harness.py b/flake8/test/harness.py index 546c48b..a8bc40d 100644 --- a/flake8/test/harness.py +++ b/flake8/test/harness.py @@ -25,4 +25,3 @@ expected outputs: but got: %s''' % (input, repr(expectedOutputs), '\n'.join(map(str, w.messages)))) return w - diff --git a/flake8/test/test_other.py b/flake8/test/test_other.py index 3c3864f..68e8710 100644 --- a/flake8/test/test_other.py +++ b/flake8/test/test_other.py @@ -413,7 +413,8 @@ class Python25Test(harness.Test): """ 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. """