--- a/PluginMetricsRadon.py Wed Jan 01 11:58:55 2020 +0100 +++ b/PluginMetricsRadon.py Tue Jun 23 19:05:15 2020 +0200 @@ -7,8 +7,6 @@ Module implementing the radon code metrics plug-in. """ -from __future__ import unicode_literals - import os from PyQt5.QtCore import pyqtSignal, QObject, QTranslator @@ -28,7 +26,7 @@ author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "2.1.0" +version = "3.0.0" className = "RadonMetricsPlugin" packageName = "RadonMetrics" shortDescription = "Code metrics plugin using radon package" @@ -41,7 +39,6 @@ ) needsRestart = False pyqtApi = 2 -python2Compatible = True # End-Of-Header error = "" @@ -80,95 +77,33 @@ self.backgroundService = e5App().getObject("BackgroundService") path = os.path.join(os.path.dirname(__file__), packageName) - try: - # raw code metrics calculation - self.backgroundService.serviceConnect( - 'radon_raw', 'Python2', path, 'CodeMetricsCalculator', - lambda fn, res: self.metricsCalculationDone("raw", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( - "raw", fx, lang, fn, msg), - onBatchDone=lambda fx, lang: self.batchJobDone( - "raw", fx, lang)) - self.backgroundService.serviceConnect( - 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', - lambda fn, res: self.metricsCalculationDone("raw", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( - "raw", fx, lang, fn, msg), - onBatchDone=lambda fx, lang: self.batchJobDone( - "raw", fx, lang)) - - # maintainability index calculation - self.backgroundService.serviceConnect( - 'radon_mi', 'Python2', path, 'MaintainabilityIndexCalculator', - lambda fn, res: self.metricsCalculationDone("mi", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( - "mi", fx, lang, fn, msg), - onBatchDone=lambda fx, lang: self.batchJobDone( - "mi", fx, lang)) - self.backgroundService.serviceConnect( - 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', - lambda fn, res: self.metricsCalculationDone("mi", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( - "mi", fx, lang, fn, msg), - onBatchDone=lambda fx, lang: self.batchJobDone( - "mi", fx, lang)) - - # cyclomatic complexity - self.backgroundService.serviceConnect( - 'radon_cc', 'Python2', path, 'CyclomaticComplexityCalculator', - lambda fn, res: self.metricsCalculationDone("cc", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( - "cc", fx, lang, fn, msg), - onBatchDone=lambda fx, lang: self.batchJobDone( - "c", fx, lang)) - self.backgroundService.serviceConnect( - 'radon_cc', 'Python3', path, 'CyclomaticComplexityCalculator', - lambda fn, res: self.metricsCalculationDone("cc", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( - "cc", fx, lang, fn, msg), - onBatchDone=lambda fx, lang: self.batchJobDone( - "cc", fx, lang)) - - self.hasBatch = True - except TypeError: - # backward compatibility for eric 6.0 - # raw code metrics calculation - self.backgroundService.serviceConnect( - 'radon_raw', 'Python2', path, 'CodeMetricsCalculator', - lambda fn, res: self.metricsCalculationDone("raw", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( - "raw", fx, lang, fn, msg)) - self.backgroundService.serviceConnect( - 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', - lambda fn, res: self.metricsCalculationDone("raw", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( - "raw", fx, lang, fn, msg)) - - # maintainability index calculation - self.backgroundService.serviceConnect( - 'radon_mi', 'Python2', path, 'MaintainabilityIndexCalculator', - lambda fn, res: self.metricsCalculationDone("mi", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( - "mi", fx, lang, fn, msg)) - self.backgroundService.serviceConnect( - 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', - lambda fn, res: self.metricsCalculationDone("mi", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( - "mi", fx, lang, fn, msg)) - - # cyclomatic complexity - self.backgroundService.serviceConnect( - 'radon_cc', 'Python2', path, 'CyclomaticComplexityCalculator', - lambda fn, res: self.metricsCalculationDone("cc", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( - "cc", fx, lang, fn, msg)) - self.backgroundService.serviceConnect( - 'radon_cc', 'Python3', path, 'CyclomaticComplexityCalculator', - lambda fn, res: self.metricsCalculationDone("cc", fn, res), - onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( - "cc", fx, lang, fn, msg)) - - self.hasBatch = False + + # raw code metrics calculation + self.backgroundService.serviceConnect( + 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', + lambda fn, res: self.metricsCalculationDone("raw", fn, res), + onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( + "raw", fx, lang, fn, msg), + onBatchDone=lambda fx, lang: self.batchJobDone( + "raw", fx, lang)) + + # maintainability index calculation + self.backgroundService.serviceConnect( + 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', + lambda fn, res: self.metricsCalculationDone("mi", fn, res), + onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( + "mi", fx, lang, fn, msg), + onBatchDone=lambda fx, lang: self.batchJobDone( + "mi", fx, lang)) + + # cyclomatic complexity + self.backgroundService.serviceConnect( + 'radon_cc', 'Python3', path, 'CyclomaticComplexityCalculator', + lambda fn, res: self.metricsCalculationDone("cc", fn, res), + onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( + "cc", fx, lang, fn, msg), + onBatchDone=lambda fx, lang: self.batchJobDone( + "cc", fx, lang)) self.queuedBatches = { "raw": [], @@ -197,29 +132,6 @@ """ self.error.emit(type_, fn, msg) - def serviceErrorPy2(self, type_, fx, lang, fn, msg): - """ - Public slot handling service errors for Python 2. - - @param type_ type of the calculated metrics - @type str, one of ["raw", "mi", "cc"] - @param fx service name - @type str - @param lang language - @type str - @param fn file name - @type str - @param msg message text - @type str - """ - if fx in ['radon_' + type_, 'batch_radon_' + type_] and \ - lang == 'Python2': - if fx == 'radon_' + type_: - self.__serviceError(type_, fn, msg) - else: - self.__serviceError(type_, self.tr("Python 2 batch job"), msg) - self.batchJobDone(type_, fx, lang) - def serviceErrorPy3(self, type_, fx, lang, fn, msg): """ Public slot handling service errors for Python 3. @@ -235,8 +147,7 @@ @param msg message text @type str """ - if fx in ['radon_' + type_, 'batch_radon_' + type_] and \ - lang == 'Python3': + if fx in ['radon_' + type_, 'batch_radon_' + type_]: if fx == 'radon_' + type_: self.__serviceError(type_, fn, msg) else: @@ -258,8 +169,10 @@ if lang in self.queuedBatches[type_]: self.queuedBatches[type_].remove(lang) # prevent sending the signal multiple times - if len(self.queuedBatches[type_]) == 0 and \ - not self.batchesFinished[type_]: + if ( + len(self.queuedBatches[type_]) == 0 and + not self.batchesFinished[type_] + ): self.batchFinished.emit(type_) self.batchesFinished[type_] = True @@ -327,11 +240,9 @@ """ if lang is None: lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang not in ['Python2', 'Python3']: - return - - self.backgroundService.enqueueRequest( - 'radon_raw', lang, filename, [source]) + if lang == 'Python3': + self.backgroundService.enqueueRequest( + 'radon_raw', lang, filename, [source]) def rawMetricsBatch(self, argumentsList): """ @@ -343,30 +254,25 @@ @type (str, str) """ data = { - "Python2": [], "Python3": [], } for filename, source in argumentsList: lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang not in ['Python2', 'Python3']: - continue - else: + if lang == 'Python3': data[lang].append((filename, source)) self.queuedBatches["raw"] = [] - for lang in ['Python2', 'Python3']: - if data[lang]: - self.queuedBatches["raw"].append(lang) - self.backgroundService.enqueueRequest('batch_radon_raw', lang, - "", data[lang]) - self.batchesFinished["raw"] = False + if data[lang]: + self.queuedBatches["raw"].append('Python3') + self.backgroundService.enqueueRequest( + 'batch_radon_raw', 'Python3', "", data['Python3']) + self.batchesFinished["raw"] = False def cancelRawMetricsBatch(self): """ Public method to cancel all batch jobs. """ - for lang in ['Python2', 'Python3']: - self.backgroundService.requestCancel('batch_radon_raw', lang) + self.backgroundService.requestCancel('batch_radon_raw', 'Python3') def maintainabilityIndex(self, lang, filename, source): """ @@ -383,11 +289,9 @@ """ if lang is None: lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang not in ['Python2', 'Python3']: - return - - self.backgroundService.enqueueRequest( - 'radon_mi', lang, filename, [source]) + if lang == 'Python3': + self.backgroundService.enqueueRequest( + 'radon_mi', lang, filename, [source]) def maintainabilityIndexBatch(self, argumentsList): """ @@ -399,30 +303,25 @@ @type (str, str) """ data = { - "Python2": [], "Python3": [], } for filename, source in argumentsList: lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang not in ['Python2', 'Python3']: - continue - else: + if lang == 'Python3': data[lang].append((filename, source)) self.queuedBatches["mi"] = [] - for lang in ['Python2', 'Python3']: - if data[lang]: - self.queuedBatches["mi"].append(lang) - self.backgroundService.enqueueRequest('batch_radon_mi', lang, - "", data[lang]) - self.batchesFinished["mi"] = False + if data['Python3']: + self.queuedBatches["mi"].append('Python3') + self.backgroundService.enqueueRequest( + 'batch_radon_mi', 'Python3', "", data['Python3']) + self.batchesFinished["mi"] = False def cancelMaintainabilityIndexBatch(self): """ Public method to cancel all batch jobs. """ - for lang in ['Python2', 'Python3']: - self.backgroundService.requestCancel('batch_radon_mi', lang) + self.backgroundService.requestCancel('batch_radon_mi', 'Python3') def cyclomaticComplexity(self, lang, filename, source): """ @@ -439,11 +338,9 @@ """ if lang is None: lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang not in ['Python2', 'Python3']: - return - - self.backgroundService.enqueueRequest( - 'radon_cc', lang, filename, [source]) + if lang == 'Python3': + self.backgroundService.enqueueRequest( + 'radon_cc', lang, filename, [source]) def cyclomaticComplexityBatch(self, argumentsList): """ @@ -455,30 +352,25 @@ @type (str, str) """ data = { - "Python2": [], "Python3": [], } for filename, source in argumentsList: lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang not in ['Python2', 'Python3']: - continue - else: + if lang == 'Python3': data[lang].append((filename, source)) self.queuedBatches["raw"] = [] - for lang in ['Python2', 'Python3']: - if data[lang]: - self.queuedBatches["cc"].append(lang) - self.backgroundService.enqueueRequest('batch_radon_cc', lang, - "", data[lang]) - self.batchesFinished["cc"] = False + if data['Python3']: + self.queuedBatches["cc"].append('Python3') + self.backgroundService.enqueueRequest( + 'batch_radon_cc', 'Python3', "", data['Python3']) + self.batchesFinished["cc"] = False def cancelComplexityBatch(self): """ Public method to cancel all batch jobs. """ - for lang in ['Python2', 'Python3']: - self.backgroundService.requestCancel('batch_radon_cc', lang) + self.backgroundService.requestCancel('batch_radon_cc', 'Python3') def activate(self): """ @@ -622,8 +514,8 @@ e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) e5App().getObject("Project").projectClosed.connect( self.__projectClosed) - e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ - .showMenu.connect(self.__projectBrowserShowMenu) + e5App().getObject("ProjectBrowser").getProjectBrowser( + "sources").showMenu.connect(self.__projectBrowserShowMenu) e5App().getObject("ViewManager").editorOpenedEd.connect( self.__editorOpened) e5App().getObject("ViewManager").editorClosedEd.connect( @@ -642,8 +534,8 @@ self.__projectShowMenu) e5App().getObject("Project").projectClosed.disconnect( self.__projectClosed) - e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ - .showMenu.disconnect(self.__projectBrowserShowMenu) + e5App().getObject("ProjectBrowser").getProjectBrowser( + "sources").showMenu.disconnect(self.__projectBrowserShowMenu) e5App().getObject("ViewManager").editorOpenedEd.disconnect( self.__editorOpened) e5App().getObject("ViewManager").editorClosedEd.disconnect( @@ -708,8 +600,8 @@ if menuName == "Show": for act in self.__projectMetricsActs[1:]: act.setEnabled( - e5App().getObject("Project").getProjectLanguage() in - ["Python3", "Python2", "Python"]) + e5App().getObject("Project").getProjectLanguage() == + "Python3") def __projectBrowserShowMenu(self, menuName, menu): """ @@ -719,9 +611,10 @@ @param menuName name of the menu to be shown (string) @param menu reference to the menu (QMenu) """ - if menuName == "Show" and \ - e5App().getObject("Project").getProjectLanguage() in \ - ["Python3", "Python2", "Python"]: + if ( + menuName == "Show" and + e5App().getObject("Project").getProjectLanguage() == "Python3" + ): if self.__projectBrowserMenu is None: self.__projectBrowserMenu = menu @@ -925,8 +818,9 @@ tuple(Preferences.getPython("PythonExtensions")))] if self.__projectMIDialog is None: - from RadonMetrics.MaintainabilityIndexDialog import \ + from RadonMetrics.MaintainabilityIndexDialog import ( MaintainabilityIndexDialog + ) self.__projectMIDialog = MaintainabilityIndexDialog(self) self.__projectMIDialog.show() self.__projectMIDialog.prepare(files, project) @@ -950,8 +844,9 @@ fn = itm.dirName() if self.__projectBrowserMIDialog is None: - from RadonMetrics.MaintainabilityIndexDialog import \ + from RadonMetrics.MaintainabilityIndexDialog import ( MaintainabilityIndexDialog + ) self.__projectBrowserMIDialog = MaintainabilityIndexDialog(self) self.__projectBrowserMIDialog.show() self.__projectBrowserMIDialog.start(fn) @@ -965,8 +860,9 @@ if editor is not None: if editor.checkDirty() and editor.getFileName() is not None: if self.__editorMIDialog is None: - from RadonMetrics.MaintainabilityIndexDialog import \ + from RadonMetrics.MaintainabilityIndexDialog import ( MaintainabilityIndexDialog + ) self.__editorMIDialog = MaintainabilityIndexDialog(self) self.__editorMIDialog.show() self.__editorMIDialog.start(editor.getFileName()) @@ -990,8 +886,9 @@ tuple(Preferences.getPython("PythonExtensions")))] if self.__projectCCDialog is None: - from RadonMetrics.CyclomaticComplexityDialog import \ + from RadonMetrics.CyclomaticComplexityDialog import ( CyclomaticComplexityDialog + ) self.__projectCCDialog = CyclomaticComplexityDialog(self) self.__projectCCDialog.show() self.__projectCCDialog.prepare(files, project) @@ -1015,8 +912,9 @@ fn = itm.dirName() if self.__projectBrowserCCDialog is None: - from RadonMetrics.CyclomaticComplexityDialog import \ + from RadonMetrics.CyclomaticComplexityDialog import ( CyclomaticComplexityDialog + ) self.__projectBrowserCCDialog = CyclomaticComplexityDialog( self, isSingle=True) self.__projectBrowserCCDialog.show() @@ -1031,8 +929,9 @@ if editor is not None: if editor.checkDirty() and editor.getFileName() is not None: if self.__editorCCDialog is None: - from RadonMetrics.CyclomaticComplexityDialog import \ + from RadonMetrics.CyclomaticComplexityDialog import ( CyclomaticComplexityDialog + ) self.__editorCCDialog = CyclomaticComplexityDialog( self, isSingle=True) self.__editorCCDialog.show() @@ -1074,7 +973,7 @@ """ self.__projectCCDialog and self.__projectCCDialog.clear() self.__projectMIDialog and self.__projectMIDialog.clear() - self.__projectRawMetricsDialog and \ + if self.__projectRawMetricsDialog: self.__projectRawMetricsDialog.clear() #