PluginPyLint.py

changeset 28
1dae294006e8
parent 24
b01348dd84d5
child 30
de4b620a6e88
--- a/PluginPyLint.py	Sun Oct 13 18:33:34 2013 +0200
+++ b/PluginPyLint.py	Thu Oct 24 18:56:00 2013 +0200
@@ -27,7 +27,8 @@
     from E5Gui import E5MessageBox
     error = ""
 except ImportError:
-    error = QCoreApplication.translate("PyLintPlugin",
+    error = QCoreApplication.translate(
+        "PyLintPlugin",
         """Your version of Eric5 is not supported."""
         """ At least version 5.1.0 of Eric5 is needed.""")
 
@@ -39,12 +40,13 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "5.3.0"
+version = "5.3.1"
 className = "PyLintPlugin"
 packageName = "PyLint"
 shortDescription = "Show the PyLint dialogs."
 longDescription = """This plug-in implements the PyLint dialogs.""" \
- """ PyLint is used to check Python source files according to various rules."""
+    """ PyLint is used to check Python source files according to various""" \
+    """ rules."""
 needsRestart = False
 pyqtApi = 2
 # End-of-Header
@@ -52,6 +54,7 @@
 exePy2 = []
 exePy3 = []
 
+
 def exeDisplayDataList():
     """
     Public method to support the display of some executable info.
@@ -62,8 +65,8 @@
     dataList = []
     data = {
         "programEntry": True,
-        "header": QCoreApplication.translate("PyLintPlugin",
-                                "Checkers - Pylint"),
+        "header": QCoreApplication.translate(
+            "PyLintPlugin", "Checkers - Pylint"),
         "exe": 'dummypylint',
         "versionCommand": '--version',
         "versionStartsWith": 'dummypylint',
@@ -80,6 +83,7 @@
         dataList.append(data)
     return dataList
 
+
 def __getProgramVersion(exe):
     """
     Private method to generate a program entry.
@@ -93,8 +97,8 @@
     finished = proc.waitForFinished(10000)
     if finished:
         output = str(proc.readAllStandardOutput(),
-                        Preferences.getSystem("IOEncoding"),
-                        'replace')
+                     Preferences.getSystem("IOEncoding"),
+                     'replace')
         versionRe = re.compile('^pylint', re.UNICODE)
         for line in output.splitlines():
             if versionRe.search(line):
@@ -105,6 +109,7 @@
             version = '0.0.0'
     return version
 
+
 def _findExecutable(majorVersion):
     """
     Restricted function to determine the name and path of the executable.
@@ -146,24 +151,28 @@
         
         for minorVersion in minorVersions:
             versionStr = '{0}.{1}'.format(majorVersion, minorVersion)
-            exePath = getExePath(winreg.HKEY_CURRENT_USER,
+            exePath = getExePath(
+                winreg.HKEY_CURRENT_USER,
                 winreg.KEY_WOW64_32KEY | winreg.KEY_READ, versionStr)
                 
             if exePath is not None:
                 executables.add(exePath)
-            exePath = getExePath(winreg.HKEY_LOCAL_MACHINE,
+            exePath = getExePath(
+                winreg.HKEY_LOCAL_MACHINE,
                 winreg.KEY_WOW64_32KEY | winreg.KEY_READ, versionStr)
             
             # Even on Intel 64-bit machines it's 'AMD64'
             if platform.machine() == 'AMD64':
                 if exePath is not None:
                     executables.add(exePath)
-                exePath = getExePath(winreg.HKEY_CURRENT_USER,
+                exePath = getExePath(
+                    winreg.HKEY_CURRENT_USER,
                     winreg.KEY_WOW64_64KEY | winreg.KEY_READ, versionStr)
                 
                 if exePath is not None:
                     executables.add(exePath)
-                exePath = getExePath(winreg.HKEY_LOCAL_MACHINE,
+                exePath = getExePath(
+                    winreg.HKEY_LOCAL_MACHINE,
                     winreg.KEY_WOW64_64KEY | winreg.KEY_READ, versionStr)
                 
                 if exePath is not None:
@@ -173,10 +182,10 @@
         # Linux, Unix ...
         pylintScript = 'pylint'
         scriptSuffixes = ["",
-                    "-python{0}".format(majorVersion)]
+                          "-python{0}".format(majorVersion)]
         for minorVersion in minorVersions:
             scriptSuffixes.append(
-                    "-python{0}.{1}".format(majorVersion, minorVersion))
+                "-python{0}.{1}".format(majorVersion, minorVersion))
         # There could be multiple pylint executables in the path
         # e.g. for different python variants
         path = Utilities.getEnvironmentEntry('PATH')
@@ -228,6 +237,7 @@
 
     return maxExe, maxVersion
 
+
 def _checkProgram():
     """
     Restricted function to check the availability of pylint.
@@ -239,12 +249,12 @@
     exePy2 = _findExecutable(2)
     exePy3 = _findExecutable(3)
     if exePy2[0] == '' and exePy3[0] == '':
-        error = QCoreApplication.translate("PyLintPlugin",
-            "The pylint executable could not be found.")
+        error = QCoreApplication.translate(
+            "PyLintPlugin", "The pylint executable could not be found.")
         return False
     elif exePy2[1] < '0.23.0' and exePy3[1] < '0.23.0':
-        error = QCoreApplication.translate("PyLintPlugin",
-            "PyLint version < 0.23.0.")
+        error = QCoreApplication.translate(
+            "PyLintPlugin", "PyLint version < 0.23.0.")
         return False
     else:
         return True
@@ -302,47 +312,54 @@
         
         menu = e5App().getObject("Project").getMenu("Checks")
         if menu:
-            self.__projectAct = E5Action(self.trUtf8('Run PyLint'),
-                    self.trUtf8('Run &PyLint...'), 0, 0,
-                    self, 'project_check_pylint')
+            self.__projectAct = E5Action(
+                self.trUtf8('Run PyLint'),
+                self.trUtf8('Run &PyLint...'), 0, 0,
+                self, 'project_check_pylint')
             self.__projectAct.setStatusTip(
                 self.trUtf8('Check project, packages or modules with pylint.'))
             self.__projectAct.setWhatsThis(self.trUtf8(
                 """<b>Run PyLint...</b>"""
-                """<p>This checks the project, packages or modules using pylint.</p>"""
+                """<p>This checks the project, packages or modules using"""
+                """ pylint.</p>"""
             ))
             self.__projectAct.triggered[()].connect(self.__projectPylint)
             e5App().getObject("Project").addE5Actions([self.__projectAct])
             menu.addAction(self.__projectAct)
             
-            self.__projectShowAct = E5Action(self.trUtf8('Show PyLint Dialog'),
-                    self.trUtf8('Show Py&Lint Dialog...'), 0, 0,
-                    self, 'project_check_pylintshow')
-            self.__projectShowAct.setStatusTip(
-                self.trUtf8('Show the PyLint dialog with the results of the last run.'))
+            self.__projectShowAct = E5Action(
+                self.trUtf8('Show PyLint Dialog'),
+                self.trUtf8('Show Py&Lint Dialog...'), 0, 0,
+                self, 'project_check_pylintshow')
+            self.__projectShowAct.setStatusTip(self.trUtf8(
+                'Show the PyLint dialog with the results of the last run.'))
             self.__projectShowAct.setWhatsThis(self.trUtf8(
                 """<b>Show PyLint Dialog...</b>"""
                 """<p>This shows the PyLint dialog with the results"""
                 """ of the last run.</p>"""
             ))
-            self.__projectShowAct.triggered[()].connect(self.__projectPylintShow)
+            self.__projectShowAct.triggered[()].connect(
+                self.__projectPylintShow)
             e5App().getObject("Project").addE5Actions([self.__projectShowAct])
             menu.addAction(self.__projectShowAct)
         
-        self.__editorAct = E5Action(self.trUtf8('Run PyLint'),
-                self.trUtf8('Run &PyLint...'), 0, 0,
-                self, "")
+        self.__editorAct = E5Action(
+            self.trUtf8('Run PyLint'),
+            self.trUtf8('Run &PyLint...'), 0, 0,
+            self, "")
         self.__editorAct.setWhatsThis(self.trUtf8(
-                """<b>Run PyLint...</b>"""
-                """<p>This checks the loaded module using pylint.</p>"""
+            """<b>Run PyLint...</b>"""
+            """<p>This checks the loaded module using pylint.</p>"""
         ))
         self.__editorAct.triggered[()].connect(self.__editorPylint)
         
         e5App().getObject("Project").showMenu.connect(self.__projectShowMenu)
         e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\
             .showMenu.connect(self.__projectBrowserShowMenu)
-        e5App().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened)
-        e5App().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed)
+        e5App().getObject("ViewManager").editorOpenedEd.connect(
+            self.__editorOpened)
+        e5App().getObject("ViewManager").editorClosedEd.connect(
+            self.__editorClosed)
         
         for editor in e5App().getObject("ViewManager").getOpenEditors():
             self.__editorOpened(editor)
@@ -354,26 +371,33 @@
         """
         Public method to deactivate this plugin.
         """
-        e5App().getObject("Project").showMenu.disconnect(self.__projectShowMenu)
+        e5App().getObject("Project").showMenu.disconnect(
+            self.__projectShowMenu)
         e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\
             .showMenu.disconnect(self.__projectBrowserShowMenu)
-        e5App().getObject("ViewManager").editorOpenedEd.disconnect(self.__editorOpened)
-        e5App().getObject("ViewManager").editorClosedEd.disconnect(self.__editorClosed)
+        e5App().getObject("ViewManager").editorOpenedEd.disconnect(
+            self.__editorOpened)
+        e5App().getObject("ViewManager").editorClosedEd.disconnect(
+            self.__editorClosed)
         
         menu = e5App().getObject("Project").getMenu("Checks")
         if menu:
             if self.__projectAct:
                 menu.removeAction(self.__projectAct)
-                e5App().getObject("Project").removeE5Actions([self.__projectAct])
+                e5App().getObject("Project").removeE5Actions(
+                    [self.__projectAct])
             if self.__projectShowAct:
                 menu.removeAction(self.__projectShowAct)
-                e5App().getObject("Project").removeE5Actions([self.__projectShowAct])
+                e5App().getObject("Project").removeE5Actions(
+                    [self.__projectShowAct])
         
         if self.__projectBrowserMenu:
             if self.__projectBrowserAct:
-                self.__projectBrowserMenu.removeAction(self.__projectBrowserAct)
+                self.__projectBrowserMenu.removeAction(
+                    self.__projectBrowserAct)
             if self.__projectBrowserShowAct:
-                self.__projectBrowserMenu.removeAction(self.__projectBrowserShowAct)
+                self.__projectBrowserMenu.removeAction(
+                    self.__projectBrowserShowAct)
         
         for editor in self.__editors:
             editor.showMenu.disconnect(self.__editorShowMenu)
@@ -399,8 +423,8 @@
                     self.__translator = translator
                     e5App().installTranslator(self.__translator)
                 else:
-                    print("Warning: translation file '{0}' could not be loaded."\
-                        .format(translation))
+                    print("Warning: translation file '{0}' could not be"
+                          " loaded.".format(translation))
                     print("Using default.")
     
     def __projectShowMenu(self, menuName, menu):
@@ -428,12 +452,14 @@
         @param menu reference to the menu (QMenu)
         """
         if menuName == "Checks" and \
-           e5App().getObject("Project").getProjectLanguage().startswith("Python"):
+           e5App().getObject("Project").getProjectLanguage()\
+                .startswith("Python"):
             self.__projectBrowserMenu = menu
             if self.__projectBrowserAct is None:
-                self.__projectBrowserAct = E5Action(self.trUtf8('Run PyLint'),
-                        self.trUtf8('Run &PyLint...'), 0, 0,
-                        self, '')
+                self.__projectBrowserAct = E5Action(
+                    self.trUtf8('Run PyLint'),
+                    self.trUtf8('Run &PyLint...'), 0, 0,
+                    self, '')
                 self.__projectBrowserAct.setWhatsThis(self.trUtf8(
                     """<b>Run PyLint...</b>"""
                     """<p>This checks the project, packages or modules"""
@@ -443,10 +469,10 @@
                     self.__projectBrowserPylint)
             
             if self.__projectBrowserShowAct is None:
-                self.__projectBrowserShowAct = \
-                        E5Action(self.trUtf8('Show PyLint Dialog'),
-                        self.trUtf8('Show Py&Lint Dialog...'), 0, 0,
-                        self, '')
+                self.__projectBrowserShowAct = E5Action(
+                    self.trUtf8('Show PyLint Dialog'),
+                    self.trUtf8('Show Py&Lint Dialog...'), 0, 0,
+                    self, '')
                 self.__projectBrowserShowAct.setWhatsThis(self.trUtf8(
                     """<b>Show PyLint Dialog...</b>"""
                     """<p>This shows the PyLint dialog with the results"""
@@ -459,7 +485,8 @@
                 menu.addAction(self.__projectBrowserAct)
             if not self.__projectBrowserShowAct in menu.actions():
                 menu.addAction(self.__projectBrowserShowAct)
-            self.__projectBrowserShowAct.setEnabled(self.__pylintPsbDialog is not None)
+            self.__projectBrowserShowAct.setEnabled(
+                self.__pylintPsbDialog is not None)
     
     def __pyLint(self, project, mpName, forProject, forEditor=False):
         """
@@ -468,6 +495,7 @@
         @param project reference to the Project object
         @param mpName name of module or package to be checked (string)
         @param forProject flag indicating a run for the project (boolean)
+        @param forEditor flag indicating a run for an editor (boolean)
         """
         if forEditor:
             parms = copy.deepcopy(self.__editorParms)
@@ -477,14 +505,16 @@
             parms = project.getData('CHECKERSPARMS', "PYLINT")
             majorVersionStr = project.getProjectLanguage()
         exe, version = {"Python": exePy2, "Python2": exePy2,
-                              "Python3": exePy3}.get(majorVersionStr)
+                        "Python3": exePy3}.get(majorVersionStr)
         if exe == '':
-            E5MessageBox.critical(None,
+            E5MessageBox.critical(
+                None,
                 self.trUtf8("pylint"),
                 self.trUtf8("""The pylint executable could not be found."""))
             return
         elif version < '0.23.0':
-            E5MessageBox.critical(None,
+            E5MessageBox.critical(
+                None,
                 self.trUtf8("pylint"),
                 self.trUtf8("PyLint version < 0.23.0."))
             return
@@ -501,7 +531,8 @@
             from PyLint.PyLintExecDialog import PyLintExecDialog
             dlg2 = PyLintExecDialog()
             reportFile = parms.get('reportFile', None)
-            res = dlg2.start(args, mpName, reportFile, project.getProjectPath())
+            res = dlg2.start(args, mpName, reportFile,
+                             project.getProjectPath())
             if res:
                 dlg2.show()
             if forProject:
@@ -532,7 +563,8 @@
         sources browser.
         """
         project = e5App().getObject("Project")
-        browser = e5App().getObject("ProjectBrowser").getProjectBrowser("sources")
+        browser = e5App().getObject("ProjectBrowser")\
+            .getProjectBrowser("sources")
         itm = browser.model().item(browser.currentIndex())
         try:
             fn = itm.fileName()
@@ -582,7 +614,8 @@
         if menuName == "Checks":
             if not self.__editorAct in menu.actions():
                 menu.addAction(self.__editorAct)
-            self.__editorAct.setEnabled(editor.isPy3File() or editor.isPy2File())
+            self.__editorAct.setEnabled(
+                editor.isPy3File() or editor.isPy2File())
     
     def __editorPylint(self):
         """

eric ide

mercurial