UtilitiesPython2/Pep8Checker.py

changeset 2929
28ab0bc63d69
parent 2917
fe82710d02cb
child 2958
ed0a8d4304a8
equal deleted inserted replaced
2928:4f74d3f595ce 2929:28ab0bc63d69
60 select = "" 60 select = ""
61 ignore = "" 61 ignore = ""
62 filename = "" 62 filename = ""
63 max_line_length = 79 63 max_line_length = 79
64 hang_closing = False 64 hang_closing = False
65 docType = "pep257"
65 66
66 if "-f" not in sys.argv: 67 if "-f" not in sys.argv:
67 print "ERROR" 68 print "ERROR"
68 print "" 69 print ""
69 print "No file name given." 70 print "No file name given."
70 else: 71 else:
71 try: 72 try:
72 optlist, args = getopt.getopt(sys.argv[1:], "f:hi:m:rs:") 73 optlist, args = getopt.getopt(sys.argv[1:], "d:f:hi:m:rs:")
73 except getopt.GetoptError: 74 except getopt.GetoptError:
74 print "ERROR" 75 print "ERROR"
75 print "" 76 print ""
76 print "Wrong arguments given" 77 print "Wrong arguments given"
77 sys.exit(1) 78 sys.exit(1)
91 except ValueError: 92 except ValueError:
92 # ignore silently 93 # ignore silently
93 pass 94 pass
94 elif opt == "-h": 95 elif opt == "-h":
95 hang_closing = True 96 hang_closing = True
97 elif opt == "-d":
98 if arg in ("pep257", "eric"):
99 docType = arg
96 100
97 try: 101 try:
98 source = readEncodedFile(filename)[0] 102 source = readEncodedFile(filename)[0]
99 source = normalizeCode(source) 103 source = normalizeCode(source)
100 source = source.splitlines(True) 104 source = source.splitlines(True)
126 ) 130 )
127 report = styleGuide.check_files([filename]) 131 report = styleGuide.check_files([filename])
128 132
129 # check PEP-257 133 # check PEP-257
130 pep257Checker = Pep257Checker( 134 pep257Checker = Pep257Checker(
131 source, file, select, ignore, [], repeat, 135 source, filename, select, ignore, [], repeat,
132 maxLineLength=max_line_length) 136 maxLineLength=max_line_length, docType=docType)
133 pep257Checker.run() 137 pep257Checker.run()
134 138
135 139
136 errors = report.errors + pep257Checker.errors 140 errors = report.errors + pep257Checker.errors
137 141
146 print code 150 print code
147 print len(args) 151 print len(args)
148 for a in args: 152 for a in args:
149 print a 153 print a
150 print "PEP8_STATISTICS" 154 print "PEP8_STATISTICS"
155 # TODO: add statistics for D
151 for key in report.counters: 156 for key in report.counters:
152 if key.startswith(("E", "N", "W")): 157 if key.startswith(("E", "N", "W")):
153 print key, report.counters[key] 158 print key, report.counters[key]
154 else: 159 else:
155 print "NO_PEP8" 160 print "NO_PEP8"

eric ide

mercurial