63 def __resort(self): |
63 def __resort(self): |
64 """ |
64 """ |
65 Private method to resort the tree. |
65 Private method to resort the tree. |
66 """ |
66 """ |
67 self.resultList.sortItems(self.resultList.sortColumn(), |
67 self.resultList.sortItems(self.resultList.sortColumn(), |
68 self.resultList.header().sortIndicatorOrder()) |
68 self.resultList.header().sortIndicatorOrder() |
69 |
69 ) |
70 def __createResultItem(self, file, line, error, sourcecode, isWarning = False): |
70 |
|
71 def __createResultItem(self, file, line, error, sourcecode, |
|
72 isWarning = False): |
71 """ |
73 """ |
72 Private method to create an entry in the result list. |
74 Private method to create an entry in the result list. |
73 |
75 |
74 @param file filename of file (string) |
76 @param file filename of file (string) |
75 @param line linenumber of faulty source (integer or string) |
77 @param line linenumber of faulty source (integer or string) |
137 if isinstance(fn, list): |
139 if isinstance(fn, list): |
138 files = fn |
140 files = fn |
139 elif os.path.isdir(fn): |
141 elif os.path.isdir(fn): |
140 files = [] |
142 files = [] |
141 for ext in Preferences.getPython("Python3Extensions"): |
143 for ext in Preferences.getPython("Python3Extensions"): |
142 files.extend(Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
144 files.extend( |
|
145 Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
143 for ext in Preferences.getPython("PythonExtensions"): |
146 for ext in Preferences.getPython("PythonExtensions"): |
144 files.extend(Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
147 files.extend( |
|
148 Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
145 else: |
149 else: |
146 files = [fn] |
150 files = [fn] |
147 files = [f for f in files \ |
151 py3files = [f for f in files \ |
148 if f.endswith(tuple(Preferences.getPython("Python3Extensions")))] |
152 if f.endswith( |
|
153 tuple(Preferences.getPython("Python3Extensions")))] |
149 py2files = [f for f in files \ |
154 py2files = [f for f in files \ |
150 if f.endswith(tuple(Preferences.getPython("PythonExtensions")))] |
155 if f.endswith( |
151 |
156 tuple(Preferences.getPython("PythonExtensions")))] |
152 if (codestring and len(files) == 1) or \ |
157 |
|
158 if (codestring and len(py3files) == 1) or \ |
153 (codestring and len(py2files) == 1) or \ |
159 (codestring and len(py2files) == 1) or \ |
154 (not codestring and len(files) + len(py2files) > 0): |
160 (not codestring and len(py3files) + len(py2files) > 0): |
155 self.checkProgress.setMaximum(len(files) + len(py2files)) |
161 self.checkProgress.setMaximum(len(py3files) + len(py2files)) |
156 QApplication.processEvents() |
162 QApplication.processEvents() |
157 |
163 |
158 ignoreStarImportWarnings = Preferences.getFlakes("IgnoreStarImportWarnings") |
164 ignoreStarImportWarnings = \ |
|
165 Preferences.getFlakes("IgnoreStarImportWarnings") |
159 |
166 |
160 # now go through all the files |
167 # now go through all the files |
161 progress = 0 |
168 progress = 0 |
162 for file in files + py2files: |
169 for file in py3files + py2files: |
163 self.checkProgress.setValue(progress) |
170 self.checkProgress.setValue(progress) |
164 QApplication.processEvents() |
171 QApplication.processEvents() |
165 self.__resort() |
172 self.__resort() |
166 |
173 |
167 if self.cancelled: |
174 if self.cancelled: |
177 # convert eols |
184 # convert eols |
178 source = Utilities.convertLineEnds(source, "\n") |
185 source = Utilities.convertLineEnds(source, "\n") |
179 except (UnicodeError, IOError) as msg: |
186 except (UnicodeError, IOError) as msg: |
180 self.noResults = False |
187 self.noResults = False |
181 self.__createResultItem(file, "1", |
188 self.__createResultItem(file, "1", |
182 "Error: {0}".format(str(msg)).rstrip()[1:-1], "") |
189 self.trUtf8("Error: {0}").format(str(msg))\ |
|
190 .rstrip()[1:-1], "") |
183 progress += 1 |
191 progress += 1 |
184 continue |
192 continue |
185 |
193 |
186 flags = Utilities.extractFlags(source) |
194 flags = Utilities.extractFlags(source) |
187 ext = os.path.splitext(file)[1] |
195 ext = os.path.splitext(file)[1] |
190 file in py2files or \ |
198 file in py2files or \ |
191 (ext in [".py", ".pyw"] and \ |
199 (ext in [".py", ".pyw"] and \ |
192 Preferences.getProject("DeterminePyFromProject") and \ |
200 Preferences.getProject("DeterminePyFromProject") and \ |
193 self.__project.isOpen() and \ |
201 self.__project.isOpen() and \ |
194 self.__project.isProjectFile(file) and \ |
202 self.__project.isProjectFile(file) and \ |
195 self.__project.getProjectLanguage() in ["Python", "Python2"]): |
203 self.__project.getProjectLanguage() in ["Python", |
|
204 "Python2"]): |
196 isPy3 = False |
205 isPy3 = False |
197 nok, fname, line, code, error, warnings = \ |
206 nok, fname, line, code, error, warnings = \ |
198 Utilities.py2compile(file, |
207 Utilities.py2compile(file, |
199 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck")) |
208 checkFlakes = \ |
|
209 Preferences.getFlakes("IncludeInSyntaxCheck")) |
200 else: |
210 else: |
201 isPy3 = True |
211 isPy3 = True |
202 nok, fname, line, code, error = Utilities.compile(file, source) |
212 nok, fname, line, code, error = \ |
|
213 Utilities.compile(file, source) |
203 if nok: |
214 if nok: |
204 self.noResults = False |
215 self.noResults = False |
205 self.__createResultItem(fname, line, error, code) |
216 self.__createResultItem(fname, line, error, code) |
206 else: |
217 else: |
207 if Preferences.getFlakes("IncludeInSyntaxCheck"): |
218 if Preferences.getFlakes("IncludeInSyntaxCheck"): |
212 warnings.messages.sort(key = lambda a: a.lineno) |
223 warnings.messages.sort(key = lambda a: a.lineno) |
213 for warning in warnings.messages: |
224 for warning in warnings.messages: |
214 if ignoreStarImportWarnings and \ |
225 if ignoreStarImportWarnings and \ |
215 isinstance(warning, ImportStarUsed): |
226 isinstance(warning, ImportStarUsed): |
216 continue |
227 continue |
217 fname, lineno, message = warning.getMessageData() |
228 fname, lineno, message = \ |
|
229 warning.getMessageData() |
218 if not sourceLines[lineno - 1].strip()\ |
230 if not sourceLines[lineno - 1].strip()\ |
219 .endswith("__IGNORE_WARNING__"): |
231 .endswith("__IGNORE_WARNING__"): |
220 self.noResults = False |
232 self.noResults = False |
221 self.__createResultItem(fname, lineno, message, |
233 self.__createResultItem( |
222 "", isWarning = True) |
234 fname, lineno, message, "", |
|
235 isWarning = True) |
223 except SyntaxError as err: |
236 except SyntaxError as err: |
224 if err.text.strip(): |
237 if err.text.strip(): |
225 msg = err.text.strip() |
238 msg = err.text.strip() |
226 else: |
239 else: |
227 msg = err.msg |
240 msg = err.msg |
228 self.__createResultItem(err.filename, err.lineno, msg, "") |
241 self.__createResultItem( |
|
242 err.filename, err.lineno, msg, "") |
229 else: |
243 else: |
230 for warning in warnings: |
244 for warning in warnings: |
231 self.noResults = False |
245 self.noResults = False |
232 self.__createResultItem(warning[0], int(warning[1]), |
246 self.__createResultItem( |
233 warning[2], "", isWarning = True) |
247 warning[0], int(warning[1]), |
|
248 warning[2], "", isWarning = True) |
234 progress += 1 |
249 progress += 1 |
235 self.checkProgress.setValue(progress) |
250 self.checkProgress.setValue(progress) |
236 QApplication.processEvents() |
251 QApplication.processEvents() |
237 self.__resort() |
252 self.__resort() |
238 else: |
253 else: |
240 self.checkProgress.setValue(1) |
255 self.checkProgress.setValue(1) |
241 self.__finish() |
256 self.__finish() |
242 |
257 |
243 def __finish(self): |
258 def __finish(self): |
244 """ |
259 """ |
245 Private slot called when the syntax check finished or the user pressed the button. |
260 Private slot called when the syntax check finished or the user |
|
261 pressed the button. |
246 """ |
262 """ |
247 self.cancelled = True |
263 self.cancelled = True |
248 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
264 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
249 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
265 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
250 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
266 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
273 self.on_showButton_clicked() |
289 self.on_showButton_clicked() |
274 |
290 |
275 @pyqtSlot() |
291 @pyqtSlot() |
276 def on_startButton_clicked(self): |
292 def on_startButton_clicked(self): |
277 """ |
293 """ |
278 Private slot to start a code metrics run. |
294 Private slot to start a syntax check run. |
279 """ |
295 """ |
280 fileList = self.__fileList[:] |
296 fileList = self.__fileList[:] |
281 |
297 |
282 filterString = self.excludeFilesEdit.text() |
298 filterString = self.excludeFilesEdit.text() |
283 if "ExcludeFiles" not in self.__data or \ |
299 if "ExcludeFiles" not in self.__data or \ |
284 filterString != self.__data["ExcludeFiles"]: |
300 filterString != self.__data["ExcludeFiles"]: |
285 self.__data["ExcludeFiles"] = filterString |
301 self.__data["ExcludeFiles"] = filterString |
286 self.__project.setData("CHECKERSPARMS", "SyntaxChecker", self.__data) |
302 self.__project.setData("CHECKERSPARMS", "SyntaxChecker", |
|
303 self.__data) |
287 filterList = filterString.split(",") |
304 filterList = filterString.split(",") |
288 if filterList: |
305 if filterList: |
289 for filter in filterList: |
306 for filter in filterList: |
290 fileList = \ |
307 fileList = \ |
291 [f for f in fileList if not fnmatch.fnmatch(f, filter.strip())] |
308 [f for f in fileList |
|
309 if not fnmatch.fnmatch(f, filter.strip())] |
292 |
310 |
293 self.resultList.clear() |
311 self.resultList.clear() |
294 self.noResults = True |
312 self.noResults = True |
295 self.cancelled = False |
313 self.cancelled = False |
296 self.start(fileList) |
314 self.start(fileList) |
335 # py3flakes warning markers for files, that are ok |
353 # py3flakes warning markers for files, that are ok |
336 openFiles = vm.getOpenFilenames() |
354 openFiles = vm.getOpenFilenames() |
337 errorFiles = [] |
355 errorFiles = [] |
338 for index in range(self.resultList.topLevelItemCount()): |
356 for index in range(self.resultList.topLevelItemCount()): |
339 itm = self.resultList.topLevelItem(index) |
357 itm = self.resultList.topLevelItem(index) |
340 errorFiles.append(Utilities.normabspath(itm.data(0, self.filenameRole))) |
358 errorFiles.append( |
|
359 Utilities.normabspath(itm.data(0, self.filenameRole))) |
341 for file in openFiles: |
360 for file in openFiles: |
342 if not file in errorFiles: |
361 if not file in errorFiles: |
343 editor = vm.getOpenEditor(file) |
362 editor = vm.getOpenEditor(file) |
344 editor.clearSyntaxError() |
363 editor.clearSyntaxError() |
345 editor.clearFlakesWarnings() |
364 editor.clearFlakesWarnings() |