PluginPyLint.py

changeset 95
50eba81e4a9f
parent 94
45d226917534
child 98
ab4aabca55ec
equal deleted inserted replaced
94:45d226917534 95:50eba81e4a9f
9 9
10 import re 10 import re
11 import os 11 import os
12 import copy 12 import copy
13 import platform 13 import platform
14 import contextlib
14 15
15 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QProcess 16 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QProcess
16 from PyQt5.QtWidgets import QDialog 17 from PyQt5.QtWidgets import QDialog
17 18
18 from E5Gui.E5Application import e5App 19 from E5Gui.E5Application import e5App
27 # Start-of-Header 28 # Start-of-Header
28 name = "PyLint Plugin" 29 name = "PyLint Plugin"
29 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 30 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
30 autoactivate = True 31 autoactivate = True
31 deactivateable = True 32 deactivateable = True
32 version = "7.1.2" 33 version = "7.1.3"
33 className = "PyLintPlugin" 34 className = "PyLintPlugin"
34 packageName = "PyLint" 35 packageName = "PyLint"
35 shortDescription = "Show the PyLint dialogs." 36 shortDescription = "Show the PyLint dialogs."
36 longDescription = ( 37 longDescription = (
37 """This plug-in implements the PyLint dialogs. PyLint is used to check""" 38 """This plug-in implements the PyLint dialogs. PyLint is used to check"""
122 except ImportError: 123 except ImportError:
123 import _winreg as winreg # __IGNORE_WARNING__ 124 import _winreg as winreg # __IGNORE_WARNING__
124 125
125 def getExePath(branch, access, versionStr): 126 def getExePath(branch, access, versionStr):
126 exes = [] 127 exes = []
127 try: 128 with contextlib.suppress(WindowsError, OSError):
128 software = winreg.OpenKey(branch, 'Software', 0, access) 129 software = winreg.OpenKey(branch, 'Software', 0, access)
129 python = winreg.OpenKey(software, 'Python', 0, access) 130 python = winreg.OpenKey(software, 'Python', 0, access)
130 pcore = winreg.OpenKey(python, 'PythonCore', 0, access) 131 pcore = winreg.OpenKey(python, 'PythonCore', 0, access)
131 version = winreg.OpenKey(pcore, versionStr, 0, access) 132 version = winreg.OpenKey(pcore, versionStr, 0, access)
132 installpath = winreg.QueryValue(version, 'InstallPath') 133 installpath = winreg.QueryValue(version, 'InstallPath')
136 exes.append(exe) 137 exes.append(exe)
137 # Look for the executable variant 138 # Look for the executable variant
138 exe = os.path.join(installpath, 'Scripts', 'pylint.exe') 139 exe = os.path.join(installpath, 'Scripts', 'pylint.exe')
139 if os.access(exe, os.X_OK): 140 if os.access(exe, os.X_OK):
140 exes.append(exe) 141 exes.append(exe)
141 except (WindowsError, OSError): # __IGNORE_WARNING__
142 pass
143 return exes 142 return exes
144 143
145 versionSuffixes = ["", "-32", "-64"] 144 versionSuffixes = ["", "-32", "-64"]
146 for minorVersion in minorVersions: 145 for minorVersion in minorVersions:
147 for versionSuffix in versionSuffixes: 146 for versionSuffix in versionSuffixes:
611 """ 610 """
612 Private slot called, when an editor was closed. 611 Private slot called, when an editor was closed.
613 612
614 @param editor reference to the editor (QScintilla.Editor) 613 @param editor reference to the editor (QScintilla.Editor)
615 """ 614 """
616 try: 615 with contextlib.suppress(ValueError):
617 self.__editors.remove(editor) 616 self.__editors.remove(editor)
618 except ValueError:
619 pass
620 617
621 def __editorShowMenu(self, menuName, menu, editor): 618 def __editorShowMenu(self, menuName, menu, editor):
622 """ 619 """
623 Private slot called, when the the editor context menu or a submenu is 620 Private slot called, when the the editor context menu or a submenu is
624 about to be shown. 621 about to be shown.
635 def __editorPylint(self): 632 def __editorPylint(self):
636 """ 633 """
637 Private slot to handle the Pylint context menu action of the editors. 634 Private slot to handle the Pylint context menu action of the editors.
638 """ 635 """
639 editor = e5App().getObject("ViewManager").activeWindow() 636 editor = e5App().getObject("ViewManager").activeWindow()
640 if editor is not None: 637 if (
641 if not editor.checkDirty(): 638 editor is not None and
642 return 639 not editor.checkDirty()
640 ):
641 return
643 642
644 fn = editor.getFileName() 643 fn = editor.getFileName()
645 project = e5App().getObject("Project") 644 project = e5App().getObject("Project")
646 self.__pyLint(project, fn, False, True) 645 self.__pyLint(project, fn, False, True)
647 646

eric ide

mercurial