mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 14:24:17 +00:00
make sure flake8 is clean
This commit is contained in:
parent
fc026a5e8a
commit
ff8a99cd62
5 changed files with 17 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
#!/home/tarek/dev/bitbucket.org/flake8-clean/bin/python
|
#!/home/tarek/dev/bitbucket.org/flk8/bin/python
|
||||||
from flake8.run import main
|
from flake8.run import main
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@
|
||||||
http://nedbatchelder.com/blog/200803/python_code_complexity_microtool.html
|
http://nedbatchelder.com/blog/200803/python_code_complexity_microtool.html
|
||||||
MIT License.
|
MIT License.
|
||||||
"""
|
"""
|
||||||
|
import compiler
|
||||||
import compiler, optparse, sys
|
import optparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class PathNode:
|
class PathNode:
|
||||||
|
|
@ -13,7 +14,8 @@ class PathNode:
|
||||||
self.look = look
|
self.look = look
|
||||||
|
|
||||||
def to_dot(self):
|
def to_dot(self):
|
||||||
print 'node [shape=%s,label="%s"] %d;' % (self.look, self.name, self.dot_id())
|
print 'node [shape=%s,label="%s"] %d;' % \
|
||||||
|
(self.look, self.name, self.dot_id())
|
||||||
|
|
||||||
def dot_id(self):
|
def dot_id(self):
|
||||||
return id(self)
|
return id(self)
|
||||||
|
|
@ -204,12 +206,15 @@ def get_module_complexity(module_path, min=7):
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
opar = optparse.OptionParser()
|
opar = optparse.OptionParser()
|
||||||
opar.add_option("-d", "--dot", dest="dot", help="output a graphviz dot file", action="store_true")
|
opar.add_option("-d", "--dot", dest="dot",
|
||||||
opar.add_option("-m", "--min", dest="min", help="minimum complexity for output", type="int", default=2)
|
help="output a graphviz dot file", action="store_true")
|
||||||
|
opar.add_option("-m", "--min", dest="min",
|
||||||
|
help="minimum complexity for output", type="int",
|
||||||
|
default=2)
|
||||||
|
|
||||||
options, args = opar.parse_args(argv)
|
options, args = opar.parse_args(argv)
|
||||||
|
|
||||||
text = open(args[0], "rU").read()+'\n\n'
|
text = open(args[0], "rU").read() + '\n\n'
|
||||||
ast = compiler.parse(text)
|
ast = compiler.parse(text)
|
||||||
visitor = PathGraphingAstVisitor()
|
visitor = PathGraphingAstVisitor()
|
||||||
visitor.preorder(ast, visitor)
|
visitor.preorder(ast, visitor)
|
||||||
|
|
|
||||||
|
|
@ -727,7 +727,7 @@ else:
|
||||||
# Python 3: decode to latin-1.
|
# Python 3: decode to latin-1.
|
||||||
# This function is lazy, it does not read the encoding declaration.
|
# This function is lazy, it does not read the encoding declaration.
|
||||||
# XXX: use tokenize.detect_encoding()
|
# XXX: use tokenize.detect_encoding()
|
||||||
def readlines(filename):
|
def readlines(filename): # NOQA
|
||||||
return open(filename, encoding='latin-1').readlines()
|
return open(filename, encoding='latin-1').readlines()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -619,6 +619,7 @@ class Checker(object):
|
||||||
importation.used = (self.scope, node.lineno)
|
importation.used = (self.scope, node.lineno)
|
||||||
self.addBinding(node.lineno, importation)
|
self.addBinding(node.lineno, importation)
|
||||||
|
|
||||||
|
|
||||||
def checkPath(filename):
|
def checkPath(filename):
|
||||||
"""
|
"""
|
||||||
Check the given path, printing out any warnings detected.
|
Check the given path, printing out any warnings detected.
|
||||||
|
|
@ -631,6 +632,7 @@ def checkPath(filename):
|
||||||
print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
|
print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def check(codeString, filename):
|
def check(codeString, filename):
|
||||||
"""
|
"""
|
||||||
Check the Python source given by C{codeString} for flakes.
|
Check the Python source given by C{codeString} for flakes.
|
||||||
|
|
@ -685,4 +687,3 @@ def check(codeString, filename):
|
||||||
valid_warnings += 1
|
valid_warnings += 1
|
||||||
|
|
||||||
return valid_warnings
|
return valid_warnings
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ import re
|
||||||
|
|
||||||
def skip_warning(warning):
|
def skip_warning(warning):
|
||||||
# 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
|
||||||
line = open(warning.filename).readlines()[warning.lineno-1]
|
line = open(warning.filename).readlines()[warning.lineno - 1]
|
||||||
return skip_line(line)
|
return skip_line(line)
|
||||||
|
|
||||||
|
|
||||||
def skip_line(line):
|
def skip_line(line):
|
||||||
return line.strip().lower().endswith('# noqa')
|
return line.strip().lower().endswith('# noqa')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue