Plugins/CheckerPlugins/Pep8/Pep8Checker.py

changeset 843
522c8befcf49
parent 832
eb5ff61f927b
child 847
cc18fbcde9fc
equal deleted inserted replaced
842:984b5535cd26 843:522c8befcf49
5 5
6 """ 6 """
7 Module implementing the PEP 8 checker. 7 Module implementing the PEP 8 checker.
8 """ 8 """
9 9
10 import os
10 import optparse 11 import optparse
11 12
13 from PyQt4.QtCore import QProcess
14
12 from . import pep8 15 from . import pep8
16
17 import Preferences
18 import Utilities
19
20 from eric5config import getConfig
13 21
14 22
15 class Pep8Checker(pep8.Checker): 23 class Pep8Checker(pep8.Checker):
16 """ 24 """
17 Class implementing the PEP 8 checker. 25 Class implementing the PEP 8 checker.
104 if pep8.options.counters[code] == 1 or pep8.options.repeat: 112 if pep8.options.counters[code] == 1 or pep8.options.repeat:
105 self.messages.append( 113 self.messages.append(
106 (self.filename, self.line_offset + line_number, 114 (self.filename, self.line_offset + line_number,
107 offset + 1, text) 115 offset + 1, text)
108 ) 116 )
117
118 class Pep8Py2Checker(object):
119 """
120 Class implementing the PEP 8 checker interface for Python 2.
121 """
122 def __init__(self, filename, lines, repeat=False,
123 select="", ignore=""):
124 """
125 Constructor
126
127 @param filename name of the file to check (string)
128 @param lines source of the file (list of strings) (ignored)
129 @keyparam repeat flag indicating to repeat message categories (boolean)
130 @keyparam select list of message IDs to check for
131 (comma separated string)
132 @keyparam ignore list of message IDs to ignore
133 (comma separated string)
134 """
135 self.messages = []
136
137 interpreter = Preferences.getDebugger("PythonInterpreter")
138 if interpreter == "" or not Utilities.isExecutable(interpreter):
139 self.messages.append(filename, "1", "1",
140 self.trUtf8("Python2 interpreter not configured."))
141 return
142
143 checker = os.path.join(getConfig('ericDir'),
144 "UtilitiesPython2", "Pep8Checker.py")
145
146 args = [checker]
147 if repeat:
148 args.append("-r")
149 if select:
150 args.append("-s")
151 args.append(select)
152 if ignore:
153 args.append("-i")
154 args.append(ignore)
155 args.append("-f")
156 args.append(filename)
157
158 proc = QProcess()
159 proc.setProcessChannelMode(QProcess.MergedChannels)
160 proc.start(interpreter, args)
161 finished = proc.waitForFinished(15000)
162 if finished:
163 output = \
164 str(proc.readAllStandardOutput(),
165 Preferences.getSystem("IOEncoding"),
166 'replace').splitlines()
167 if output[0] == "ERROR":
168 self.messages.append(filename, "1", "1", output[2])
169 return
170
171 if output[0] == "NO_PEP8":
172 return
173
174 index = 0
175 while index < len(output):
176 fname = output[index + 1]
177 lineno = int(output[index + 2])
178 position = int(output[index + 3])
179 code = output[index + 4]
180 arglen = int(output[index + 5])
181 args = []
182 argindex = 0
183 while argindex < arglen:
184 args.append(output[index + 6 + argindex])
185 argindex += 1
186 index += 6 + arglen
187
188 text = pep8.getMessage(code, *args)
189 self.messages.append((fname, lineno, position, text))
190 else:
191 self.messages.append(filename, "1", "1",
192 self.trUtf8("Python2 interpreter did not finish within 15s."))

eric ide

mercurial