From 82ea7edadc968b849f3df3bd827f3064e59e672c Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 8 Nov 2012 09:03:54 -0500 Subject: [PATCH] Fixes #14 and #19. @BackSeat contributed the patch. Signature changes are mentioned in README. --- README | 5 ++++- flake8/pyflakes.py | 8 ++++---- flake8/run.py | 6 +++--- flake8/util.py | 4 +++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README b/README index 064e3fd..6dcfffd 100644 --- a/README +++ b/README @@ -223,8 +223,11 @@ CHANGES ======= 1.6 +--- -XXX +- changed the signatures of the ``check_file`` function in flake8/run.py, + ``skip_warning`` in flake8/util.py and the ``check``, ``checkPath`` + functions in flake8/pyflakes.py. 1.5 - 2012-10-13 diff --git a/flake8/pyflakes.py b/flake8/pyflakes.py index 94e57f6..3d65e7d 100644 --- a/flake8/pyflakes.py +++ b/flake8/pyflakes.py @@ -649,21 +649,21 @@ class Checker(object): self.addBinding(node.lineno, importation) -def checkPath(filename): +def checkPath(filename, ignore=[]): """ Check the given path, printing out any warnings detected. @return: the number of warnings printed """ try: - return check(open(filename, 'U').read() + '\n', filename) + return check(open(filename, 'U').read() + '\n', ignore, filename) except IOError: msg = sys.exc_info()[1] sys.stderr.write("%s: %s\n" % (filename, msg.args[1])) return 1 -def check(codeString, filename='(code)'): +def check(codeString, ignore, filename='(code)'): """ Check the Python source given by C{codeString} for flakes. @@ -714,7 +714,7 @@ def check(codeString, filename='(code)'): valid_warnings = 0 for warning in w.messages: - if skip_warning(warning): + if skip_warning(warning, ignore): continue print(warning) valid_warnings += 1 diff --git a/flake8/run.py b/flake8/run.py index 75fb669..32249e5 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -20,10 +20,10 @@ from flake8 import mccabe pep8style = None -def check_file(path, complexity=-1): +def check_file(path, ignore=[], complexity=-1): if pep8style.excluded(path): return 0 - warnings = pyflakes.checkPath(path) + warnings = pyflakes.checkPath(path, ignore) warnings += pep8style.input_file(path) if complexity > -1: warnings += mccabe.get_module_complexity(path, complexity) @@ -68,7 +68,7 @@ def main(): if pep8style.paths and options.filename is not None: for path in _get_python_files(pep8style.paths): - warnings += check_file(path, complexity) + warnings += check_file(path, options.ignore, complexity) else: # wait for 1 second on the stdin fd reads, __, __ = select.select([sys.stdin], [], [], 1.) diff --git a/flake8/util.py b/flake8/util.py index bb3f4b6..6e9735b 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -3,8 +3,10 @@ import re import os -def skip_warning(warning): +def skip_warning(warning, ignore=[]): # XXX quick dirty hack, just need to keep the line in the warning + if warning.message.split()[0] in ignore: + return True if not os.path.isfile(warning.filename): return False