UtilitiesPython2/Pep8Checker.py

changeset 2917
fe82710d02cb
parent 2896
9fa71ee50b3d
child 2929
28ab0bc63d69
equal deleted inserted replaced
2916:a8628dfdfe04 2917:fe82710d02cb
15 import pep8 15 import pep8
16 from Pep8NamingCheckerPy2 import Pep8NamingChecker 16 from Pep8NamingCheckerPy2 import Pep8NamingChecker
17 17
18 # register the name checker 18 # register the name checker
19 pep8.register_check(Pep8NamingChecker, Pep8NamingChecker.Codes) 19 pep8.register_check(Pep8NamingChecker, Pep8NamingChecker.Codes)
20
21 from Pep257CheckerPy2 import Pep257Checker
20 22
21 23
22 class Pep8Report(pep8.BaseReport): 24 class Pep8Report(pep8.BaseReport):
23 """ 25 """
24 Class implementing a special report to be used with our dialog. 26 Class implementing a special report to be used with our dialog.
91 pass 93 pass
92 elif opt == "-h": 94 elif opt == "-h":
93 hang_closing = True 95 hang_closing = True
94 96
95 try: 97 try:
96 codestring = readEncodedFile(filename)[0] 98 source = readEncodedFile(filename)[0]
97 codestring = normalizeCode(codestring) 99 source = normalizeCode(source)
98 codestring = codestring.splitlines(True) 100 source = source.splitlines(True)
99 except IOError, msg: 101 except IOError, msg:
100 print "ERROR" 102 print "ERROR"
101 print filename 103 print filename
102 print "I/O Error: %s" % unicode(msg) 104 print "I/O Error: %s" % unicode(msg)
103 sys.exit(1) 105 sys.exit(1)
110 if ignore: 112 if ignore:
111 ignore = [i.strip() for i in ignore.split(',') 113 ignore = [i.strip() for i in ignore.split(',')
112 if i.strip()] 114 if i.strip()]
113 else: 115 else:
114 ignore = [] 116 ignore = []
117
118 # check PEP-8
115 styleGuide = pep8.StyleGuide( 119 styleGuide = pep8.StyleGuide(
116 reporter=Pep8Report, 120 reporter=Pep8Report,
117 repeat=repeat, 121 repeat=repeat,
118 select=select, 122 select=select,
119 ignore=ignore, 123 ignore=ignore,
120 max_line_length=max_line_length, 124 max_line_length=max_line_length,
121 hang_closing=hang_closing, 125 hang_closing=hang_closing,
122 ) 126 )
123 report = styleGuide.check_files([filename]) 127 report = styleGuide.check_files([filename])
124 report.errors.sort(key=lambda a: a[1]) 128
125 if len(report.errors) > 0: 129 # check PEP-257
126 report.errors.sort(key=lambda a: a[1]) 130 pep257Checker = Pep257Checker(
127 for error in report.errors: 131 source, file, select, ignore, [], repeat,
132 maxLineLength=max_line_length)
133 pep257Checker.run()
134
135
136 errors = report.errors + pep257Checker.errors
137
138 if len(errors) > 0:
139 errors.sort(key=lambda a: a[1])
140 for error in errors:
128 fname, lineno, position, code, args = error 141 fname, lineno, position, code, args = error
129 print "PEP8" 142 print "PEP8"
130 print fname 143 print fname
131 print lineno 144 print lineno
132 print position 145 print position

eric ide

mercurial