8
def check(codeString, filename):
10
tree = compiler.parse(codeString)
11
except (SyntaxError, IndentationError):
12
value = sys.exc_info()[1]
13
(lineno, offset, line) = value[1][1:]
14
if line.endswith("\n"):
16
print >> sys.stderr, 'could not compile %r:%d:' % (filename, lineno)
17
print >> sys.stderr, line
18
print >> sys.stderr, " " * (offset-2), "^"
20
w = pyflakes.Checker(tree, filename)
21
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
22
for warning in w.messages:
26
def checkPath(filename):
27
return check(file(filename).read(), filename)
32
if os.path.isdir(arg):
33
for dirpath, dirnames, filenames in os.walk(arg):
34
for filename in filenames:
35
if filename.endswith('.py'):
36
checkPath(os.path.join(dirpath, filename))
40
check(sys.stdin.read(), '<stdin>')