--- a/PluginPyLint.py Wed Jun 02 17:36:34 2021 +0200 +++ b/PluginPyLint.py Wed Jun 02 18:27:07 2021 +0200 @@ -13,12 +13,12 @@ import platform import contextlib -from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QProcess -from PyQt5.QtWidgets import QDialog +from PyQt6.QtCore import QObject, QTranslator, QCoreApplication, QProcess +from PyQt6.QtWidgets import QDialog -from E5Gui.E5Application import e5App -from E5Gui.E5Action import E5Action -from E5Gui import E5MessageBox +from EricWidgets.EricApplication import ericApp +from EricGui.EricAction import EricAction +from EricWidgets import EricMessageBox from Project.ProjectBrowserModel import ProjectBrowserFileItem @@ -30,9 +30,9 @@ author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "7.1.3" +version = "1.0.0" className = "PyLintPlugin" -packageName = "PyLint" +packageName = "PyLintInterface" shortDescription = "Show the PyLint dialogs." longDescription = ( """This plug-in implements the PyLint dialogs. PyLint is used to check""" @@ -51,8 +51,9 @@ """ Public method to support the display of some executable info. - @return dictionary containing the data to query the presence of + @return list of dictionaries containing the data to query the presence of the executable + @rtype list of dict """ dataList = [] data = { @@ -81,11 +82,13 @@ """ Private method to generate a program entry. - @param exe name of the executable program (string) - @return version string of detected version (string) + @param exe name of the executable program + @type str + @return version string of detected version + @rtype str """ proc = QProcess() - proc.setProcessChannelMode(QProcess.MergedChannels) + proc.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels) proc.start(exe, ['--version']) finished = proc.waitForFinished(10000) if finished: @@ -104,8 +107,10 @@ """ Restricted function to determine the name and path of the executable. - @param majorVersion major python version of the executables (int) - @return path name of the executable (string) + @param majorVersion major python version of the executables + @type int + @return path name of the executable + @rtype str """ # Determine Python Version if majorVersion == 3: @@ -248,7 +253,8 @@ """ Restricted function to check the availability of pylint. - @return flag indicating availability (boolean) + @return flag indicating availability + @rtype bool """ global error, exePy3 @@ -257,10 +263,6 @@ error = QCoreApplication.translate( "PyLintPlugin", "The pylint executable could not be found.") return False - elif exePy3[1] < '0.23.0': - error = QCoreApplication.translate( - "PyLintPlugin", "PyLint version < 0.23.0.") - return False else: return True @@ -273,7 +275,8 @@ """ Constructor - @param ui reference to the user interface object (UI.UserInterface) + @param ui reference to the user interface object + @type UserInterface """ QObject.__init__(self, ui) self.__ui = ui @@ -304,7 +307,8 @@ """ Public method to activate this plugin. - @return tuple of None and activation status (boolean) + @return tuple of None and activation status + @rtype tuple of (None, bool) """ global error @@ -315,9 +319,9 @@ if not _checkProgram(): return None, False - menu = e5App().getObject("Project").getMenu("Checks") + menu = ericApp().getObject("Project").getMenu("Checks") if menu: - self.__projectAct = E5Action( + self.__projectAct = EricAction( self.tr('Run PyLint'), self.tr('Run &PyLint...'), 0, 0, self, 'project_check_pylint') @@ -329,10 +333,10 @@ """ pylint.</p>""" )) self.__projectAct.triggered.connect(self.__projectPylint) - e5App().getObject("Project").addE5Actions([self.__projectAct]) + ericApp().getObject("Project").addEricActions([self.__projectAct]) menu.addAction(self.__projectAct) - self.__projectShowAct = E5Action( + self.__projectShowAct = EricAction( self.tr('Show PyLint Dialog'), self.tr('Show Py&Lint Dialog...'), 0, 0, self, 'project_check_pylintshow') @@ -345,10 +349,11 @@ )) self.__projectShowAct.triggered.connect( self.__projectPylintShow) - e5App().getObject("Project").addE5Actions([self.__projectShowAct]) + ericApp().getObject("Project").addEricActions( + [self.__projectShowAct]) menu.addAction(self.__projectShowAct) - self.__editorAct = E5Action( + self.__editorAct = EricAction( self.tr('Run PyLint'), self.tr('Run &PyLint...'), 0, 0, self, "") @@ -358,15 +363,15 @@ )) self.__editorAct.triggered.connect(self.__editorPylint) - e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) - e5App().getObject("ProjectBrowser").getProjectBrowser( + ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) + ericApp().getObject("ProjectBrowser").getProjectBrowser( "sources").showMenu.connect(self.__projectBrowserShowMenu) - e5App().getObject("ViewManager").editorOpenedEd.connect( + ericApp().getObject("ViewManager").editorOpenedEd.connect( self.__editorOpened) - e5App().getObject("ViewManager").editorClosedEd.connect( + ericApp().getObject("ViewManager").editorClosedEd.connect( self.__editorClosed) - for editor in e5App().getObject("ViewManager").getOpenEditors(): + for editor in ericApp().getObject("ViewManager").getOpenEditors(): self.__editorOpened(editor) error = "" @@ -376,24 +381,24 @@ """ Public method to deactivate this plugin. """ - e5App().getObject("Project").showMenu.disconnect( + ericApp().getObject("Project").showMenu.disconnect( self.__projectShowMenu) - e5App().getObject("ProjectBrowser").getProjectBrowser( + ericApp().getObject("ProjectBrowser").getProjectBrowser( "sources").showMenu.disconnect(self.__projectBrowserShowMenu) - e5App().getObject("ViewManager").editorOpenedEd.disconnect( + ericApp().getObject("ViewManager").editorOpenedEd.disconnect( self.__editorOpened) - e5App().getObject("ViewManager").editorClosedEd.disconnect( + ericApp().getObject("ViewManager").editorClosedEd.disconnect( self.__editorClosed) - menu = e5App().getObject("Project").getMenu("Checks") + menu = ericApp().getObject("Project").getMenu("Checks") if menu: if self.__projectAct: menu.removeAction(self.__projectAct) - e5App().getObject("Project").removeE5Actions( + ericApp().getObject("Project").removeEricActions( [self.__projectAct]) if self.__projectShowAct: menu.removeAction(self.__projectShowAct) - e5App().getObject("Project").removeE5Actions( + ericApp().getObject("Project").removeEricActions( [self.__projectShowAct]) if self.__projectBrowserMenu: @@ -426,7 +431,7 @@ loaded = translator.load(translation, locale_dir) if loaded: self.__translator = translator - e5App().installTranslator(self.__translator) + ericApp().installTranslator(self.__translator) else: print("Warning: translation file '{0}' could not be" " loaded.".format(translation)) @@ -437,11 +442,13 @@ Private slot called, when the the project menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu """ if menuName == "Checks": - lang = e5App().getObject("Project").getProjectLanguage() + lang = ericApp().getObject("Project").getProjectLanguage() if self.__projectAct is not None: self.__projectAct.setEnabled(lang.startswith("Python")) if self.__projectShowAct is not None: @@ -453,17 +460,19 @@ Private slot called, when the the project browser menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu """ if ( menuName == "Checks" and - e5App().getObject("Project").getProjectLanguage() + ericApp().getObject("Project").getProjectLanguage() .startswith("Python") ): self.__projectBrowserMenu = menu if self.__projectBrowserAct is None: - self.__projectBrowserAct = E5Action( + self.__projectBrowserAct = EricAction( self.tr('Run PyLint'), self.tr('Run &PyLint...'), 0, 0, self, '') @@ -476,7 +485,7 @@ self.__projectBrowserPylint) if self.__projectBrowserShowAct is None: - self.__projectBrowserShowAct = E5Action( + self.__projectBrowserShowAct = EricAction( self.tr('Show PyLint Dialog'), self.tr('Show Py&Lint Dialog...'), 0, 0, self, '') @@ -494,7 +503,7 @@ menu.addAction(self.__projectBrowserShowAct) enable = ( - e5App().getObject("ProjectBrowser") + ericApp().getObject("ProjectBrowser") .getProjectBrowser("sources") .getSelectedItemsCount([ProjectBrowserFileItem]) == 1) self.__projectBrowserAct.setEnabled(enable) @@ -506,41 +515,39 @@ Private method used to perform a PyLint run. @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) + @type Project + @param mpName name of module or package to be checked + @type str + @param forProject flag indicating a run for the project + @type bool + @param forEditor flag indicating a run for an editor + @type bool """ if forEditor: parms = copy.deepcopy(self.__editorParms) - editor = e5App().getObject("ViewManager").getOpenEditor(mpName) + editor = ericApp().getObject("ViewManager").getOpenEditor(mpName) majorVersionStr = editor.getLanguage() else: parms = project.getData('CHECKERSPARMS', "PYLINT") majorVersionStr = project.getProjectLanguage() exe, version = {"Python3": exePy3}.get(majorVersionStr) if exe == '': - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr("pylint"), self.tr("""The pylint executable could not be found.""")) return - elif version < '0.23.0': - E5MessageBox.critical( - None, - self.tr("pylint"), - self.tr("PyLint version < 0.23.0.")) - return - from PyLint.PyLintConfigDialog import PyLintConfigDialog + from PyLintInterface.PyLintConfigDialog import PyLintConfigDialog dlg = PyLintConfigDialog(project.getProjectPath(), exe, parms, version) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: args, parms = dlg.generateParameters() self.__editorParms = copy.deepcopy(parms) if not forEditor: project.setData('CHECKERSPARMS', "PYLINT", parms) # now do the call - from PyLint.PyLintExecDialog import PyLintExecDialog + from PyLintInterface.PyLintExecDialog import PyLintExecDialog dlg2 = PyLintExecDialog() reportFile = parms.get('reportFile', None) res = dlg2.start(args, mpName, reportFile, @@ -558,7 +565,7 @@ """ Private slot used to check the project files with Pylint. """ - project = e5App().getObject("Project") + project = ericApp().getObject("Project") project.saveAllScripts() self.__pyLint(project, project.getProjectPath(), True) @@ -575,9 +582,9 @@ Private method to handle the Pylint context menu action of the project sources browser. """ - project = e5App().getObject("Project") + project = ericApp().getObject("Project") browser = ( - e5App().getObject("ProjectBrowser").getProjectBrowser("sources") + ericApp().getObject("ProjectBrowser").getProjectBrowser("sources") ) itm = browser.model().item(browser.currentIndex()) try: @@ -598,7 +605,8 @@ """ Private slot called, when a new editor was opened. - @param editor reference to the new editor (QScintilla.Editor) + @param editor reference to the new editor + @type Editor """ menu = editor.getMenu("Checks") if menu is not None: @@ -610,7 +618,8 @@ """ Private slot called, when an editor was closed. - @param editor reference to the editor (QScintilla.Editor) + @param editor reference to the editor + @type Editor """ with contextlib.suppress(ValueError): self.__editors.remove(editor) @@ -620,9 +629,12 @@ Private slot called, when the the editor context menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) - @param editor reference to the editor (QScintilla.Editor) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu + @param editor reference to the editor + @type Editor """ if menuName == "Checks": if self.__editorAct not in menu.actions(): @@ -633,7 +645,7 @@ """ Private slot to handle the Pylint context menu action of the editors. """ - editor = e5App().getObject("ViewManager").activeWindow() + editor = ericApp().getObject("ViewManager").activeWindow() if ( editor is not None and not editor.checkDirty() @@ -641,8 +653,21 @@ return fn = editor.getFileName() - project = e5App().getObject("Project") + project = ericApp().getObject("Project") self.__pyLint(project, fn, False, True) + +def installDependencies(pipInstall): + """ + Function to install dependencies of this plug-in. + + @param pipInstall function to be called with a list of package names. + @type function + """ + try: + import pylint # __IGNORE_WARNING__ + except ImportError: + pipInstall(["pylint"]) + # # eflag: noqa = M801