mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
@BackSeat contributed the patch. Signature changes are mentioned in README.
This commit is contained in:
parent
cc1d7c5385
commit
82ea7edadc
4 changed files with 14 additions and 9 deletions
5
README
5
README
|
|
@ -223,8 +223,11 @@ CHANGES
|
||||||
=======
|
=======
|
||||||
|
|
||||||
1.6
|
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
|
1.5 - 2012-10-13
|
||||||
|
|
|
||||||
|
|
@ -649,21 +649,21 @@ class Checker(object):
|
||||||
self.addBinding(node.lineno, importation)
|
self.addBinding(node.lineno, importation)
|
||||||
|
|
||||||
|
|
||||||
def checkPath(filename):
|
def checkPath(filename, ignore=[]):
|
||||||
"""
|
"""
|
||||||
Check the given path, printing out any warnings detected.
|
Check the given path, printing out any warnings detected.
|
||||||
|
|
||||||
@return: the number of warnings printed
|
@return: the number of warnings printed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return check(open(filename, 'U').read() + '\n', filename)
|
return check(open(filename, 'U').read() + '\n', ignore, filename)
|
||||||
except IOError:
|
except IOError:
|
||||||
msg = sys.exc_info()[1]
|
msg = sys.exc_info()[1]
|
||||||
sys.stderr.write("%s: %s\n" % (filename, msg.args[1]))
|
sys.stderr.write("%s: %s\n" % (filename, msg.args[1]))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def check(codeString, filename='(code)'):
|
def check(codeString, ignore, filename='(code)'):
|
||||||
"""
|
"""
|
||||||
Check the Python source given by C{codeString} for flakes.
|
Check the Python source given by C{codeString} for flakes.
|
||||||
|
|
||||||
|
|
@ -714,7 +714,7 @@ def check(codeString, filename='(code)'):
|
||||||
valid_warnings = 0
|
valid_warnings = 0
|
||||||
|
|
||||||
for warning in w.messages:
|
for warning in w.messages:
|
||||||
if skip_warning(warning):
|
if skip_warning(warning, ignore):
|
||||||
continue
|
continue
|
||||||
print(warning)
|
print(warning)
|
||||||
valid_warnings += 1
|
valid_warnings += 1
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ from flake8 import mccabe
|
||||||
pep8style = None
|
pep8style = None
|
||||||
|
|
||||||
|
|
||||||
def check_file(path, complexity=-1):
|
def check_file(path, ignore=[], complexity=-1):
|
||||||
if pep8style.excluded(path):
|
if pep8style.excluded(path):
|
||||||
return 0
|
return 0
|
||||||
warnings = pyflakes.checkPath(path)
|
warnings = pyflakes.checkPath(path, ignore)
|
||||||
warnings += pep8style.input_file(path)
|
warnings += pep8style.input_file(path)
|
||||||
if complexity > -1:
|
if complexity > -1:
|
||||||
warnings += mccabe.get_module_complexity(path, complexity)
|
warnings += mccabe.get_module_complexity(path, complexity)
|
||||||
|
|
@ -68,7 +68,7 @@ def main():
|
||||||
|
|
||||||
if pep8style.paths and options.filename is not None:
|
if pep8style.paths and options.filename is not None:
|
||||||
for path in _get_python_files(pep8style.paths):
|
for path in _get_python_files(pep8style.paths):
|
||||||
warnings += check_file(path, complexity)
|
warnings += check_file(path, options.ignore, complexity)
|
||||||
else:
|
else:
|
||||||
# wait for 1 second on the stdin fd
|
# wait for 1 second on the stdin fd
|
||||||
reads, __, __ = select.select([sys.stdin], [], [], 1.)
|
reads, __, __ = select.select([sys.stdin], [], [], 1.)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@ import re
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def skip_warning(warning):
|
def skip_warning(warning, ignore=[]):
|
||||||
# XXX quick dirty hack, just need to keep the line in the warning
|
# 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):
|
if not os.path.isfile(warning.filename):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue