fixed outputs

This commit is contained in:
Tarek Ziade 2010-08-12 15:02:26 +02:00
parent 0d0b77f79d
commit 9e283b063f
8 changed files with 108 additions and 107 deletions

7
README
View file

@ -5,10 +5,13 @@ Flake8
Flake8 is just a merge of the PyFlakes and the pep8 projects into one single
script.
It runs both tests by launching the single 'flake8' script, and also adds a
few features:
It runs both tests by launching the single 'flake8' script, but ignores pep8
options and just uses its defaults.
It also adds a few features:
- lines that contains a "# NOQA" comment at the end will not issue a warning
- merging pep8 and pyflakes options
- more things to come..
Original projects:

View file

@ -1,5 +1,5 @@
#!/usr/bin/python
from flake8.scripts.flake8 import main
from flake8 import main
if __name__ == '__main__':
main()

View file

@ -1 +1,99 @@
#
"""
Implementation of the command-line I{flake8} tool.
"""
import sys
import os
import _ast
import pep8
checker = __import__('flake8.checker').checker
def check(codeString, filename):
"""
Check the Python source given by C{codeString} for flakes.
@param codeString: The Python source to check.
@type codeString: C{str}
@param filename: The name of the file the source came from, used to report
errors.
@type filename: C{str}
@return: The number of warnings emitted.
@rtype: C{int}
"""
# First, compile into an AST and handle syntax errors.
try:
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
except SyntaxError, value:
msg = value.args[0]
(lineno, offset, text) = value.lineno, value.offset, value.text
# If there's an encoding problem with the file, the text is None.
if text is None:
# Avoid using msg, since for the only known case, it contains a
# bogus message that claims the encoding the file declared was
# unknown.
print >> sys.stderr, "%s: problem decoding source" % (filename, )
else:
line = text.splitlines()[-1]
if offset is not None:
offset = offset - (len(text) - len(line))
print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg)
print >> sys.stderr, line
if offset is not None:
print >> sys.stderr, " " * offset, "^"
return 1
else:
# Okay, it's syntactically valid. Now check it.
w = checker.Checker(tree, filename)
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
for warning in w.messages:
print warning
return len(w.messages)
def checkPath(filename):
"""
Check the given path, printing out any warnings detected.
@return: the number of warnings printed
"""
try:
return check(file(filename, 'U').read() + '\n', filename)
except IOError, msg:
print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
return 1
def main():
pep8.process_options()
warnings = 0
args = sys.argv[1:]
if args:
for arg in args:
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)
else:
warnings += checkPath(arg)
warnings += pep8.input_file(arg)
else:
stdin = sys.stdin.read()
warnings += check(stdin, '<stdin>')
raise SystemExit(warnings > 0)

View file

@ -6,8 +6,7 @@ import __builtin__
import os.path
import _ast
from pyflakes import messages
from flake8 import messages
# utility function to iterate over an AST node's children, adapted
# from Python 2.6's standard ast module

View file

@ -981,7 +981,7 @@ def input_file(filename):
count = options.counters.get(code, 0)
if count == 0 and 'not' not in basename:
message("%s: error %s not found" % (filename, code))
return len(errors)
return errors
def input_dir(dirname):
"""

View file

@ -1,99 +0,0 @@
"""
Implementation of the command-line I{flake8} tool.
"""
import sys
import os
import _ast
from flake8.pep8 import input_file
from flake8 import pep8
checker = __import__('flake8.checker').checker
def check(codeString, filename):
"""
Check the Python source given by C{codeString} for flakes.
@param codeString: The Python source to check.
@type codeString: C{str}
@param filename: The name of the file the source came from, used to report
errors.
@type filename: C{str}
@return: The number of warnings emitted.
@rtype: C{int}
"""
# First, compile into an AST and handle syntax errors.
try:
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
except SyntaxError, value:
msg = value.args[0]
(lineno, offset, text) = value.lineno, value.offset, value.text
# If there's an encoding problem with the file, the text is None.
if text is None:
# Avoid using msg, since for the only known case, it contains a
# bogus message that claims the encoding the file declared was
# unknown.
print >> sys.stderr, "%s: problem decoding source" % (filename, )
else:
line = text.splitlines()[-1]
if offset is not None:
offset = offset - (len(text) - len(line))
print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg)
print >> sys.stderr, line
if offset is not None:
print >> sys.stderr, " " * offset, "^"
return 1
else:
# Okay, it's syntactically valid. Now check it.
w = checker.Checker(tree, filename)
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
for warning in w.messages:
print warning
return len(w.messages)
def checkPath(filename):
"""
Check the given path, printing out any warnings detected.
@return: the number of warnings printed
"""
try:
return check(file(filename, 'U').read() + '\n', filename)
except IOError, msg:
print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
return 1
def main():
warnings = 0
args = sys.argv[1:]
if args:
for arg in args:
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 += input_file(fullpath)
else:
warnings += checkPath(arg)
warnings += input_file(arg)
else:
stdin = sys.stdin.read()
warnings += check(stdin, '<stdin>')
raise SystemExit(warnings > 0)

View file

@ -9,7 +9,7 @@ setup(
description="code checking",
author="Tarek Ziade",
url="http://bitbucket.org/tarek/flake8",
packages=["flake8", "flake8.scripts", "flake8.test"],
packages=["flake8", "flake8.test"],
scripts=["bin/flake8"],
long_description=README,
classifiers=[