27 deactivateable = True |
27 deactivateable = True |
28 version = UI.Info.VersionOnly |
28 version = UI.Info.VersionOnly |
29 className = "CodeStyleCheckerPlugin" |
29 className = "CodeStyleCheckerPlugin" |
30 packageName = "__core__" |
30 packageName = "__core__" |
31 shortDescription = "Show the Python Code Style Checker dialog." |
31 shortDescription = "Show the Python Code Style Checker dialog." |
32 longDescription = """This plugin implements the Python Code Style""" \ |
32 longDescription = ( |
33 """ Checker dialog. A PEP-8 checker is used to check Python source""" \ |
33 """This plugin implements the Python Code Style""" |
34 """ files for compliance to the code style conventions given in PEP-8.""" \ |
34 """ Checker dialog. A PEP-8 checker is used to check Python source""" |
35 """ A PEP-257 checker is used to check Python source files for""" \ |
35 """ files for compliance to the code style conventions given in PEP-8.""" |
36 """ compliance to docstring conventions given in PEP-257 and an""" \ |
36 """ A PEP-257 checker is used to check Python source files for""" |
|
37 """ compliance to docstring conventions given in PEP-257 and an""" |
37 """ eric6 variant is used to check against eric conventions.""" |
38 """ eric6 variant is used to check against eric conventions.""" |
|
39 ) |
38 pyqtApi = 2 |
40 pyqtApi = 2 |
39 # End-Of-Header |
41 # End-Of-Header |
40 |
42 |
41 |
43 |
42 error = "" |
44 error = "" |
224 @param codeStyleCheckerStats stats of style and name check (dict) |
226 @param codeStyleCheckerStats stats of style and name check (dict) |
225 @param results tuple for each found violation of style (tuple of |
227 @param results tuple for each found violation of style (tuple of |
226 lineno (int), position (int), text (str), fixed (bool), |
228 lineno (int), position (int), text (str), fixed (bool), |
227 autofixing (bool), fixedMsg (str)) |
229 autofixing (bool), fixedMsg (str)) |
228 """ |
230 """ |
229 from CheckerPlugins.CodeStyleChecker.translations import \ |
231 from CheckerPlugins.CodeStyleChecker.translations import ( |
230 getTranslatedMessage |
232 getTranslatedMessage |
|
233 ) |
231 |
234 |
232 fixes = 0 |
235 fixes = 0 |
233 for result in results: |
236 for result in results: |
234 msg = getTranslatedMessage(result[2]) |
237 msg = getTranslatedMessage(result[2]) |
235 |
238 |
278 """ code style conventions given in various PEPs.</p>""" |
281 """ code style conventions given in various PEPs.</p>""" |
279 )) |
282 )) |
280 self.__editorAct.triggered.connect(self.__editorCodeStyleCheck) |
283 self.__editorAct.triggered.connect(self.__editorCodeStyleCheck) |
281 |
284 |
282 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
285 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
283 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
286 e5App().getObject("ProjectBrowser").getProjectBrowser( |
284 .showMenu.connect(self.__projectBrowserShowMenu) |
287 "sources").showMenu.connect(self.__projectBrowserShowMenu) |
285 e5App().getObject("ViewManager").editorOpenedEd.connect( |
288 e5App().getObject("ViewManager").editorOpenedEd.connect( |
286 self.__editorOpened) |
289 self.__editorOpened) |
287 e5App().getObject("ViewManager").editorClosedEd.connect( |
290 e5App().getObject("ViewManager").editorClosedEd.connect( |
288 self.__editorClosed) |
291 self.__editorClosed) |
289 |
292 |
296 """ |
299 """ |
297 Public method to deactivate this plugin. |
300 Public method to deactivate this plugin. |
298 """ |
301 """ |
299 e5App().getObject("Project").showMenu.disconnect( |
302 e5App().getObject("Project").showMenu.disconnect( |
300 self.__projectShowMenu) |
303 self.__projectShowMenu) |
301 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
304 e5App().getObject("ProjectBrowser").getProjectBrowser( |
302 .showMenu.disconnect(self.__projectBrowserShowMenu) |
305 "sources").showMenu.disconnect(self.__projectBrowserShowMenu) |
303 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
306 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
304 self.__editorOpened) |
307 self.__editorOpened) |
305 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
308 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
306 self.__editorClosed) |
309 self.__editorClosed) |
307 |
310 |
341 about to be shown. |
344 about to be shown. |
342 |
345 |
343 @param menuName name of the menu to be shown (string) |
346 @param menuName name of the menu to be shown (string) |
344 @param menu reference to the menu (QMenu) |
347 @param menu reference to the menu (QMenu) |
345 """ |
348 """ |
346 if menuName == "Checks" and \ |
349 if ( |
347 e5App().getObject("Project").getProjectLanguage() in \ |
350 menuName == "Checks" and |
348 ["Python3", "Python2", "Python", "MicroPython"]: |
351 e5App().getObject("Project").getProjectLanguage() in |
|
352 ["Python3", "Python2", "Python", "MicroPython"] |
|
353 ): |
349 self.__projectBrowserMenu = menu |
354 self.__projectBrowserMenu = menu |
350 if self.__projectBrowserAct is None: |
355 if self.__projectBrowserAct is None: |
351 self.__projectBrowserAct = E5Action( |
356 self.__projectBrowserAct = E5Action( |
352 self.tr('Check Code Style'), |
357 self.tr('Check Code Style'), |
353 self.tr('&Code Style...'), 0, 0, |
358 self.tr('&Code Style...'), 0, 0, |
373 for file in project.pdata["SOURCES"] |
378 for file in project.pdata["SOURCES"] |
374 if file.endswith( |
379 if file.endswith( |
375 tuple(Preferences.getPython("Python3Extensions")) + |
380 tuple(Preferences.getPython("Python3Extensions")) + |
376 tuple(Preferences.getPython("PythonExtensions")))] |
381 tuple(Preferences.getPython("PythonExtensions")))] |
377 |
382 |
378 from CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog import \ |
383 from CheckerPlugins.CodeStyleChecker import CodeStyleCheckerDialog |
379 CodeStyleCheckerDialog |
384 self.__projectCodeStyleCheckerDialog = ( |
380 self.__projectCodeStyleCheckerDialog = CodeStyleCheckerDialog(self) |
385 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
|
386 ) |
381 self.__projectCodeStyleCheckerDialog.show() |
387 self.__projectCodeStyleCheckerDialog.show() |
382 self.__projectCodeStyleCheckerDialog.prepare(files, project) |
388 self.__projectCodeStyleCheckerDialog.prepare(files, project) |
383 |
389 |
384 def __projectBrowserCodeStyleCheck(self): |
390 def __projectBrowserCodeStyleCheck(self): |
385 """ |
391 """ |
386 Private method to handle the code style check context menu action of |
392 Private method to handle the code style check context menu action of |
387 the project sources browser. |
393 the project sources browser. |
388 """ |
394 """ |
389 browser = e5App().getObject("ProjectBrowser")\ |
395 browser = ( |
390 .getProjectBrowser("sources") |
396 e5App().getObject("ProjectBrowser").getProjectBrowser("sources") |
|
397 ) |
391 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: |
398 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: |
392 fn = [] |
399 fn = [] |
393 for itm in browser.getSelectedItems([ProjectBrowserFileItem]): |
400 for itm in browser.getSelectedItems([ProjectBrowserFileItem]): |
394 fn.append(itm.fileName()) |
401 fn.append(itm.fileName()) |
395 isDir = False |
402 isDir = False |
400 isDir = False |
407 isDir = False |
401 except AttributeError: |
408 except AttributeError: |
402 fn = itm.dirName() |
409 fn = itm.dirName() |
403 isDir = True |
410 isDir = True |
404 |
411 |
405 from CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog import \ |
412 from CheckerPlugins.CodeStyleChecker import CodeStyleCheckerDialog |
406 CodeStyleCheckerDialog |
413 self.__projectBrowserCodeStyleCheckerDialog = ( |
407 self.__projectBrowserCodeStyleCheckerDialog = CodeStyleCheckerDialog( |
414 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
408 self) |
415 ) |
409 self.__projectBrowserCodeStyleCheckerDialog.show() |
416 self.__projectBrowserCodeStyleCheckerDialog.show() |
410 if isDir: |
417 if isDir: |
411 self.__projectBrowserCodeStyleCheckerDialog.start( |
418 self.__projectBrowserCodeStyleCheckerDialog.start( |
412 fn, save=True) |
419 fn, save=True) |
413 else: |
420 else: |
457 of the editors. |
464 of the editors. |
458 """ |
465 """ |
459 editor = e5App().getObject("ViewManager").activeWindow() |
466 editor = e5App().getObject("ViewManager").activeWindow() |
460 if editor is not None: |
467 if editor is not None: |
461 if editor.checkDirty() and editor.getFileName() is not None: |
468 if editor.checkDirty() and editor.getFileName() is not None: |
462 from CheckerPlugins.CodeStyleChecker.CodeStyleCheckerDialog \ |
469 from CheckerPlugins.CodeStyleChecker import ( |
463 import CodeStyleCheckerDialog |
470 CodeStyleCheckerDialog |
464 self.__editorCodeStyleCheckerDialog = CodeStyleCheckerDialog( |
471 ) |
465 self) |
472 self.__editorCodeStyleCheckerDialog = ( |
|
473 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
|
474 ) |
466 self.__editorCodeStyleCheckerDialog.show() |
475 self.__editorCodeStyleCheckerDialog.show() |
467 self.__editorCodeStyleCheckerDialog.start( |
476 self.__editorCodeStyleCheckerDialog.start( |
468 editor.getFileName(), |
477 editor.getFileName(), |
469 save=True, |
478 save=True, |
470 repeat=True) |
479 repeat=True) |