PluginPyLint.py

changeset 38
bf234b8941d9
parent 35
c3ca6d580760
child 43
298822c933d8
equal deleted inserted replaced
35:c3ca6d580760 38:bf234b8941d9
16 import re 16 import re
17 import os 17 import os
18 import copy 18 import copy
19 import platform 19 import platform
20 20
21 from PyQt4.QtCore import QObject, QTranslator, QCoreApplication, QProcess 21 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QProcess
22 from PyQt4.QtGui import QDialog 22 from PyQt5.QtWidgets import QDialog
23 23
24 try: 24 from E5Gui.E5Application import e5App
25 from E5Gui.E5Application import e5App 25 from E5Gui.E5Action import E5Action
26 from E5Gui.E5Action import E5Action 26 from E5Gui import E5MessageBox
27 from E5Gui import E5MessageBox
28 error = ""
29 except ImportError:
30 error = QCoreApplication.translate(
31 "PyLintPlugin",
32 """Your version of Eric5 is not supported."""
33 """ At least version 5.1.0 of Eric5 is needed.""")
34 27
35 from Project.ProjectBrowserModel import ProjectBrowserFileItem 28 from Project.ProjectBrowserModel import ProjectBrowserFileItem
36 29
37 import Preferences 30 import Preferences
38 import Utilities 31 import Utilities
40 # Start-of-Header 33 # Start-of-Header
41 name = "PyLint Plugin" 34 name = "PyLint Plugin"
42 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 35 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
43 autoactivate = True 36 autoactivate = True
44 deactivateable = True 37 deactivateable = True
45 version = "5.4.1" 38 version = "6.0.0"
46 className = "PyLintPlugin" 39 className = "PyLintPlugin"
47 packageName = "PyLint" 40 packageName = "PyLint"
48 shortDescription = "Show the PyLint dialogs." 41 shortDescription = "Show the PyLint dialogs."
49 longDescription = """This plug-in implements the PyLint dialogs.""" \ 42 longDescription = """This plug-in implements the PyLint dialogs.""" \
50 """ PyLint is used to check Python source files according to various""" \ 43 """ PyLint is used to check Python source files according to various""" \
51 """ rules.""" 44 """ rules."""
52 needsRestart = False 45 needsRestart = False
53 pyqtApi = 2 46 pyqtApi = 2
54 python2Compatible = True 47 python2Compatible = True
55 # End-of-Header 48 # End-of-Header
49
50 error = ""
56 51
57 exePy2 = [] 52 exePy2 = []
58 exePy3 = [] 53 exePy3 = []
59 54
60 55
315 return None, False 310 return None, False
316 311
317 menu = e5App().getObject("Project").getMenu("Checks") 312 menu = e5App().getObject("Project").getMenu("Checks")
318 if menu: 313 if menu:
319 self.__projectAct = E5Action( 314 self.__projectAct = E5Action(
320 self.trUtf8('Run PyLint'), 315 self.tr('Run PyLint'),
321 self.trUtf8('Run &PyLint...'), 0, 0, 316 self.tr('Run &PyLint...'), 0, 0,
322 self, 'project_check_pylint') 317 self, 'project_check_pylint')
323 self.__projectAct.setStatusTip( 318 self.__projectAct.setStatusTip(
324 self.trUtf8('Check project, packages or modules with pylint.')) 319 self.tr('Check project, packages or modules with pylint.'))
325 self.__projectAct.setWhatsThis(self.trUtf8( 320 self.__projectAct.setWhatsThis(self.tr(
326 """<b>Run PyLint...</b>""" 321 """<b>Run PyLint...</b>"""
327 """<p>This checks the project, packages or modules using""" 322 """<p>This checks the project, packages or modules using"""
328 """ pylint.</p>""" 323 """ pylint.</p>"""
329 )) 324 ))
330 self.__projectAct.triggered[()].connect(self.__projectPylint) 325 self.__projectAct.triggered.connect(self.__projectPylint)
331 e5App().getObject("Project").addE5Actions([self.__projectAct]) 326 e5App().getObject("Project").addE5Actions([self.__projectAct])
332 menu.addAction(self.__projectAct) 327 menu.addAction(self.__projectAct)
333 328
334 self.__projectShowAct = E5Action( 329 self.__projectShowAct = E5Action(
335 self.trUtf8('Show PyLint Dialog'), 330 self.tr('Show PyLint Dialog'),
336 self.trUtf8('Show Py&Lint Dialog...'), 0, 0, 331 self.tr('Show Py&Lint Dialog...'), 0, 0,
337 self, 'project_check_pylintshow') 332 self, 'project_check_pylintshow')
338 self.__projectShowAct.setStatusTip(self.trUtf8( 333 self.__projectShowAct.setStatusTip(self.tr(
339 'Show the PyLint dialog with the results of the last run.')) 334 'Show the PyLint dialog with the results of the last run.'))
340 self.__projectShowAct.setWhatsThis(self.trUtf8( 335 self.__projectShowAct.setWhatsThis(self.tr(
341 """<b>Show PyLint Dialog...</b>""" 336 """<b>Show PyLint Dialog...</b>"""
342 """<p>This shows the PyLint dialog with the results""" 337 """<p>This shows the PyLint dialog with the results"""
343 """ of the last run.</p>""" 338 """ of the last run.</p>"""
344 )) 339 ))
345 self.__projectShowAct.triggered[()].connect( 340 self.__projectShowAct.triggered.connect(
346 self.__projectPylintShow) 341 self.__projectPylintShow)
347 e5App().getObject("Project").addE5Actions([self.__projectShowAct]) 342 e5App().getObject("Project").addE5Actions([self.__projectShowAct])
348 menu.addAction(self.__projectShowAct) 343 menu.addAction(self.__projectShowAct)
349 344
350 self.__editorAct = E5Action( 345 self.__editorAct = E5Action(
351 self.trUtf8('Run PyLint'), 346 self.tr('Run PyLint'),
352 self.trUtf8('Run &PyLint...'), 0, 0, 347 self.tr('Run &PyLint...'), 0, 0,
353 self, "") 348 self, "")
354 self.__editorAct.setWhatsThis(self.trUtf8( 349 self.__editorAct.setWhatsThis(self.tr(
355 """<b>Run PyLint...</b>""" 350 """<b>Run PyLint...</b>"""
356 """<p>This checks the loaded module using pylint.</p>""" 351 """<p>This checks the loaded module using pylint.</p>"""
357 )) 352 ))
358 self.__editorAct.triggered[()].connect(self.__editorPylint) 353 self.__editorAct.triggered.connect(self.__editorPylint)
359 354
360 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) 355 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu)
361 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ 356 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\
362 .showMenu.connect(self.__projectBrowserShowMenu) 357 .showMenu.connect(self.__projectBrowserShowMenu)
363 e5App().getObject("ViewManager").editorOpenedEd.connect( 358 e5App().getObject("ViewManager").editorOpenedEd.connect(
459 e5App().getObject("Project").getProjectLanguage()\ 454 e5App().getObject("Project").getProjectLanguage()\
460 .startswith("Python"): 455 .startswith("Python"):
461 self.__projectBrowserMenu = menu 456 self.__projectBrowserMenu = menu
462 if self.__projectBrowserAct is None: 457 if self.__projectBrowserAct is None:
463 self.__projectBrowserAct = E5Action( 458 self.__projectBrowserAct = E5Action(
464 self.trUtf8('Run PyLint'), 459 self.tr('Run PyLint'),
465 self.trUtf8('Run &PyLint...'), 0, 0, 460 self.tr('Run &PyLint...'), 0, 0,
466 self, '') 461 self, '')
467 self.__projectBrowserAct.setWhatsThis(self.trUtf8( 462 self.__projectBrowserAct.setWhatsThis(self.tr(
468 """<b>Run PyLint...</b>""" 463 """<b>Run PyLint...</b>"""
469 """<p>This checks the project, packages or modules""" 464 """<p>This checks the project, packages or modules"""
470 """ using pylint.</p>""" 465 """ using pylint.</p>"""
471 )) 466 ))
472 self.__projectBrowserAct.triggered[()].connect( 467 self.__projectBrowserAct.triggered.connect(
473 self.__projectBrowserPylint) 468 self.__projectBrowserPylint)
474 469
475 if self.__projectBrowserShowAct is None: 470 if self.__projectBrowserShowAct is None:
476 self.__projectBrowserShowAct = E5Action( 471 self.__projectBrowserShowAct = E5Action(
477 self.trUtf8('Show PyLint Dialog'), 472 self.tr('Show PyLint Dialog'),
478 self.trUtf8('Show Py&Lint Dialog...'), 0, 0, 473 self.tr('Show Py&Lint Dialog...'), 0, 0,
479 self, '') 474 self, '')
480 self.__projectBrowserShowAct.setWhatsThis(self.trUtf8( 475 self.__projectBrowserShowAct.setWhatsThis(self.tr(
481 """<b>Show PyLint Dialog...</b>""" 476 """<b>Show PyLint Dialog...</b>"""
482 """<p>This shows the PyLint dialog with the results""" 477 """<p>This shows the PyLint dialog with the results"""
483 """ of the last run.</p>""" 478 """ of the last run.</p>"""
484 )) 479 ))
485 self.__projectBrowserShowAct.triggered[()].connect( 480 self.__projectBrowserShowAct.triggered.connect(
486 self.__projectBrowserPylintShow) 481 self.__projectBrowserPylintShow)
487 482
488 if not self.__projectBrowserAct in menu.actions(): 483 if not self.__projectBrowserAct in menu.actions():
489 menu.addAction(self.__projectBrowserAct) 484 menu.addAction(self.__projectBrowserAct)
490 if not self.__projectBrowserShowAct in menu.actions(): 485 if not self.__projectBrowserShowAct in menu.actions():
516 exe, version = {"Python": exePy2, "Python2": exePy2, 511 exe, version = {"Python": exePy2, "Python2": exePy2,
517 "Python3": exePy3}.get(majorVersionStr) 512 "Python3": exePy3}.get(majorVersionStr)
518 if exe == '': 513 if exe == '':
519 E5MessageBox.critical( 514 E5MessageBox.critical(
520 None, 515 None,
521 self.trUtf8("pylint"), 516 self.tr("pylint"),
522 self.trUtf8("""The pylint executable could not be found.""")) 517 self.tr("""The pylint executable could not be found."""))
523 return 518 return
524 elif version < '0.23.0': 519 elif version < '0.23.0':
525 E5MessageBox.critical( 520 E5MessageBox.critical(
526 None, 521 None,
527 self.trUtf8("pylint"), 522 self.tr("pylint"),
528 self.trUtf8("PyLint version < 0.23.0.")) 523 self.tr("PyLint version < 0.23.0."))
529 return 524 return
530 525
531 from PyLint.PyLintConfigDialog import PyLintConfigDialog 526 from PyLint.PyLintConfigDialog import PyLintConfigDialog
532 dlg = PyLintConfigDialog(project.getProjectPath(), exe, parms, version) 527 dlg = PyLintConfigDialog(project.getProjectPath(), exe, parms, version)
533 if dlg.exec_() == QDialog.Accepted: 528 if dlg.exec_() == QDialog.Accepted:

eric ide

mercurial