PluginMetricsRadon.py

branch
eric7
changeset 94
725eaca7bc4b
parent 93
1ae73306422a
child 102
f7b964ea22a1
--- a/PluginMetricsRadon.py	Mon Sep 19 17:43:37 2022 +0200
+++ b/PluginMetricsRadon.py	Mon Sep 19 17:54:33 2022 +0200
@@ -49,7 +49,7 @@
 class RadonMetricsPlugin(QObject):
     """
     Class implementing the radon code metrics plug-in.
-    
+
     @signal metricsDone(str, dict) emitted when the code metrics were
         determined for a file
     @signal maintainabilityIndexDone(str, dict) emitted when the
@@ -59,54 +59,67 @@
     @signal error(str, str, str) emitted in case of an error
     @signal batchFinished(str) emitted when a code metrics batch is done
     """
+
     metricsDone = pyqtSignal(str, dict)
     maintainabilityIndexDone = pyqtSignal(str, dict)
     complexityDone = pyqtSignal(str, dict)
     error = pyqtSignal(str, str, str)
     batchFinished = pyqtSignal(str)
-    
+
     def __init__(self, ui):
         """
         Constructor
-        
+
         @param ui reference to the user interface object
         @type UserInterface
         """
         super().__init__(ui)
         self.__ui = ui
         self.__initialize()
-        
+
         self.backgroundService = ericApp().getObject("BackgroundService")
-        
+
         path = os.path.join(os.path.dirname(__file__), packageName)
-        
+
         # raw code metrics calculation
         self.backgroundService.serviceConnect(
-            'radon_raw', 'Python3', path, 'CodeMetricsCalculator',
+            "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))
-        
+                "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',
+            "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))
-        
+                "mi", fx, lang, fn, msg
+            ),
+            onBatchDone=lambda fx, lang: self.batchJobDone("mi", fx, lang),
+        )
+
         # cyclomatic complexity
         self.backgroundService.serviceConnect(
-            'radon_cc', 'Python3', path, 'CyclomaticComplexityCalculator',
+            "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))
-        
+                "cc", fx, lang, fn, msg
+            ),
+            onBatchDone=lambda fx, lang: self.batchJobDone("cc", fx, lang),
+        )
+
         self.queuedBatches = {
             "raw": [],
             "mi": [],
@@ -117,14 +130,14 @@
             "mi": True,
             "cc": True,
         }
-        
+
         self.__translator = None
         self.__loadTranslator()
-    
+
     def __serviceError(self, type_, fn, msg):
         """
         Private slot handling service errors.
-        
+
         @param type_ type of the calculated metrics
         @type str, one of ["raw", "mi", "cc"]
         @param fn file name
@@ -133,11 +146,11 @@
         @type str
         """
         self.error.emit(type_, fn, msg)
-    
+
     def serviceErrorPy3(self, type_, fx, lang, fn, msg):
         """
         Public slot handling service errors for Python 3.
-        
+
         @param type_ type of the calculated metrics
         @type str, one of ["raw", "mi", "cc"]
         @param fx service name
@@ -149,17 +162,17 @@
         @param msg message text
         @type str
         """
-        if fx in ['radon_' + type_, 'batch_radon_' + type_]:
-            if fx == 'radon_' + type_:
+        if fx in ["radon_" + type_, "batch_radon_" + type_]:
+            if fx == "radon_" + type_:
                 self.__serviceError(type_, fn, msg)
             else:
                 self.__serviceError(type_, self.tr("Python 3 batch job"), msg)
                 self.batchJobDone(type_, fx, lang)
-    
+
     def batchJobDone(self, type_, fx, lang):
         """
         Public slot handling the completion of a batch job.
-        
+
         @param type_ type of the calculated metrics
         @type str, one of ["raw", "mi", "cc"]
         @param fx service name
@@ -167,21 +180,18 @@
         @param lang language
         @type str
         """
-        if fx in ['radon_' + type_, 'batch_radon_' + type_]:
+        if fx in ["radon_" + type_, "batch_radon_" + type_]:
             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
-    
+
     def metricsCalculationDone(self, type_, filename, result):
         """
         Public slot to dispatch the result.
-        
+
         @param type_ type of the calculated metrics
         @type str, one of ["raw", "mi", "cc"]
         @param filename name of the file the results belong to
@@ -199,10 +209,9 @@
             self.error.emit(
                 type_,
                 filename,
-                self.tr("Unknown metrics result received ({0}).").format(
-                    type_)
+                self.tr("Unknown metrics result received ({0}).").format(type_),
             )
-    
+
     def __initialize(self):
         """
         Private slot to (re)initialize the plugin.
@@ -212,14 +221,14 @@
         self.__projectCCDialog = None
         self.__projectMetricsActs = []
         self.__projectSeparatorActs = []
-        
+
         self.__projectBrowserRawMetricsDialog = None
         self.__projectBrowserMIDialog = None
         self.__projectBrowserCCDialog = None
         self.__projectBrowserMenu = None
         self.__projectBrowserMetricsActs = []
         self.__projectBrowserSeparatorActs = []
-        
+
         self.__editors = []
         self.__editorRawMetricsDialog = None
         self.__editorMIDialog = None
@@ -241,16 +250,15 @@
         @type str
         """
         if lang is None:
-            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
-        if lang == 'Python3':
-            self.backgroundService.enqueueRequest(
-                'radon_raw', lang, filename, [source])
+            lang = "Python{0}".format(determinePythonVersion(filename, source))
+        if lang == "Python3":
+            self.backgroundService.enqueueRequest("radon_raw", lang, filename, [source])
 
     def rawMetricsBatch(self, argumentsList):
         """
         Public method to prepare raw code metrics calculation on multiple
         Python source files.
-        
+
         @param argumentsList list of arguments tuples with each tuple
             containing filename and source
         @type (str, str)
@@ -259,22 +267,23 @@
             "Python3": [],
         }
         for filename, source in argumentsList:
-            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
-            if lang == 'Python3':
+            lang = "Python{0}".format(determinePythonVersion(filename, source))
+            if lang == "Python3":
                 data[lang].append((filename, source))
-        
+
         self.queuedBatches["raw"] = []
         if data[lang]:
-            self.queuedBatches["raw"].append('Python3')
+            self.queuedBatches["raw"].append("Python3")
             self.backgroundService.enqueueRequest(
-                'batch_radon_raw', 'Python3', "", data['Python3'])
+                "batch_radon_raw", "Python3", "", data["Python3"]
+            )
             self.batchesFinished["raw"] = False
-    
+
     def cancelRawMetricsBatch(self):
         """
         Public method to cancel all batch jobs.
         """
-        self.backgroundService.requestCancel('batch_radon_raw', 'Python3')
+        self.backgroundService.requestCancel("batch_radon_raw", "Python3")
 
     def maintainabilityIndex(self, lang, filename, source):
         """
@@ -290,16 +299,15 @@
         @type str
         """
         if lang is None:
-            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
-        if lang == 'Python3':
-            self.backgroundService.enqueueRequest(
-                'radon_mi', lang, filename, [source])
+            lang = "Python{0}".format(determinePythonVersion(filename, source))
+        if lang == "Python3":
+            self.backgroundService.enqueueRequest("radon_mi", lang, filename, [source])
 
     def maintainabilityIndexBatch(self, argumentsList):
         """
         Public method to prepare maintainability index calculation on multiple
         Python source files.
-        
+
         @param argumentsList list of arguments tuples with each tuple
             containing filename and source
         @type (str, str)
@@ -308,23 +316,24 @@
             "Python3": [],
         }
         for filename, source in argumentsList:
-            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
-            if lang == 'Python3':
+            lang = "Python{0}".format(determinePythonVersion(filename, source))
+            if lang == "Python3":
                 data[lang].append((filename, source))
-        
+
         self.queuedBatches["mi"] = []
-        if data['Python3']:
-            self.queuedBatches["mi"].append('Python3')
+        if data["Python3"]:
+            self.queuedBatches["mi"].append("Python3")
             self.backgroundService.enqueueRequest(
-                'batch_radon_mi', 'Python3', "", data['Python3'])
+                "batch_radon_mi", "Python3", "", data["Python3"]
+            )
             self.batchesFinished["mi"] = False
-    
+
     def cancelMaintainabilityIndexBatch(self):
         """
         Public method to cancel all batch jobs.
         """
-        self.backgroundService.requestCancel('batch_radon_mi', 'Python3')
-    
+        self.backgroundService.requestCancel("batch_radon_mi", "Python3")
+
     def cyclomaticComplexity(self, lang, filename, source):
         """
         Public method to prepare cyclomatic complexity calculation on one
@@ -339,16 +348,15 @@
         @type str
         """
         if lang is None:
-            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
-        if lang == 'Python3':
-            self.backgroundService.enqueueRequest(
-                'radon_cc', lang, filename, [source])
+            lang = "Python{0}".format(determinePythonVersion(filename, source))
+        if lang == "Python3":
+            self.backgroundService.enqueueRequest("radon_cc", lang, filename, [source])
 
     def cyclomaticComplexityBatch(self, argumentsList):
         """
         Public method to prepare cyclomatic complexity calculation on multiple
         Python source files.
-        
+
         @param argumentsList list of arguments tuples with each tuple
             containing filename and source
         @type (str, str)
@@ -357,40 +365,41 @@
             "Python3": [],
         }
         for filename, source in argumentsList:
-            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
-            if lang == 'Python3':
+            lang = "Python{0}".format(determinePythonVersion(filename, source))
+            if lang == "Python3":
                 data[lang].append((filename, source))
-        
+
         self.queuedBatches["raw"] = []
-        if data['Python3']:
-            self.queuedBatches["cc"].append('Python3')
+        if data["Python3"]:
+            self.queuedBatches["cc"].append("Python3")
             self.backgroundService.enqueueRequest(
-                'batch_radon_cc', 'Python3', "", data['Python3'])
+                "batch_radon_cc", "Python3", "", data["Python3"]
+            )
             self.batchesFinished["cc"] = False
-    
+
     def cancelComplexityBatch(self):
         """
         Public method to cancel all batch jobs.
         """
-        self.backgroundService.requestCancel('batch_radon_cc', 'Python3')
+        self.backgroundService.requestCancel("batch_radon_cc", "Python3")
 
     def activate(self):
         """
         Public method to activate this plug-in.
-        
+
         @return tuple of None and activation status
         @rtype (None, bool)
         """
         global error
-        error = ""     # clear previous error
-        
+        error = ""  # clear previous error
+
         # Project menu actions
         menu = ericApp().getObject("Project").getMenu("Show")
         if menu:
             if not menu.isEmpty():
                 act = menu.addSeparator()
                 self.__projectSeparatorActs.append(act)
-            
+
             # header action
             act = QAction(self.tr("Radon"), self)
             font = act.font()
@@ -399,60 +408,78 @@
             act.triggered.connect(self.__showRadonVersion)
             menu.addAction(act)
             self.__projectMetricsActs.append(act)
-            
+
             act = EricAction(
-                self.tr('Code Metrics'),
-                self.tr('Code &Metrics...'), 0, 0,
-                self, 'project_show_radon_raw')
-            act.setStatusTip(
-                self.tr('Show raw code metrics.'))
-            act.setWhatsThis(self.tr(
-                """<b>Code Metrics...</b>"""
-                """<p>This calculates raw code metrics of Python files"""
-                """ and shows the amount of lines of code, logical lines"""
-                """ of code, source lines of code, comment lines,"""
-                """ multi-line strings and blank lines.</p>"""
-            ))
+                self.tr("Code Metrics"),
+                self.tr("Code &Metrics..."),
+                0,
+                0,
+                self,
+                "project_show_radon_raw",
+            )
+            act.setStatusTip(self.tr("Show raw code metrics."))
+            act.setWhatsThis(
+                self.tr(
+                    """<b>Code Metrics...</b>"""
+                    """<p>This calculates raw code metrics of Python files"""
+                    """ and shows the amount of lines of code, logical lines"""
+                    """ of code, source lines of code, comment lines,"""
+                    """ multi-line strings and blank lines.</p>"""
+                )
+            )
             act.triggered.connect(self.__projectRawMetrics)
             menu.addAction(act)
             self.__projectMetricsActs.append(act)
-            
+
             act = EricAction(
-                self.tr('Maintainability Index'),
-                self.tr('Maintainability &Index...'), 0, 0,
-                self, 'project_show_radon_mi')
+                self.tr("Maintainability Index"),
+                self.tr("Maintainability &Index..."),
+                0,
+                0,
+                self,
+                "project_show_radon_mi",
+            )
             act.setStatusTip(
-                self.tr('Show the maintainability index for Python files.'))
-            act.setWhatsThis(self.tr(
-                """<b>Maintainability Index...</b>"""
-                """<p>This calculates the maintainability index of Python"""
-                """ files and shows it together with a ranking.</p>"""
-            ))
+                self.tr("Show the maintainability index for Python files.")
+            )
+            act.setWhatsThis(
+                self.tr(
+                    """<b>Maintainability Index...</b>"""
+                    """<p>This calculates the maintainability index of Python"""
+                    """ files and shows it together with a ranking.</p>"""
+                )
+            )
             act.triggered.connect(self.__projectMaintainabilityIndex)
             menu.addAction(act)
             self.__projectMetricsActs.append(act)
-            
+
             act = EricAction(
-                self.tr('Cyclomatic Complexity'),
-                self.tr('Cyclomatic &Complexity...'), 0, 0,
-                self, 'project_show_radon_cc')
+                self.tr("Cyclomatic Complexity"),
+                self.tr("Cyclomatic &Complexity..."),
+                0,
+                0,
+                self,
+                "project_show_radon_cc",
+            )
             act.setStatusTip(
-                self.tr('Show the cyclomatic complexity for Python files.'))
-            act.setWhatsThis(self.tr(
-                """<b>Cyclomatic Complexity...</b>"""
-                """<p>This calculates the cyclomatic complexity of Python"""
-                """ files and shows it together with a ranking.</p>"""
-            ))
+                self.tr("Show the cyclomatic complexity for Python files.")
+            )
+            act.setWhatsThis(
+                self.tr(
+                    """<b>Cyclomatic Complexity...</b>"""
+                    """<p>This calculates the cyclomatic complexity of Python"""
+                    """ files and shows it together with a ranking.</p>"""
+                )
+            )
             act.triggered.connect(self.__projectCyclomaticComplexity)
             menu.addAction(act)
             self.__projectMetricsActs.append(act)
-            
+
             act = menu.addSeparator()
             self.__projectSeparatorActs.append(act)
-            
-            ericApp().getObject("Project").addEricActions(
-                self.__projectMetricsActs[1:])
-        
+
+            ericApp().getObject("Project").addEricActions(self.__projectMetricsActs[1:])
+
         # Editor menu actions (one separator each above and below)
         act = QAction(self)
         act.setSeparator(True)
@@ -460,7 +487,7 @@
         act = QAction(self)
         act.setSeparator(True)
         self.__editorSeparatorActs.append(act)
-        
+
         # header action
         act = QAction(self.tr("Radon"), self)
         font = act.font()
@@ -468,81 +495,90 @@
         act.setFont(font)
         act.triggered.connect(self.__showRadonVersion)
         self.__editorMetricsActs.append(act)
-        
+
         act = EricAction(
-            self.tr('Code Metrics'),
-            self.tr('Code &Metrics...'), 0, 0,
-            self, "")
-        act.setStatusTip(
-            self.tr('Show raw code metrics.'))
-        act.setWhatsThis(self.tr(
-            """<b>Code Metrics...</b>"""
-            """<p>This calculates raw code metrics of Python files"""
-            """ and shows the amount of lines of code, logical lines"""
-            """ of code, source lines of code, comment lines,"""
-            """ multi-line strings and blank lines.</p>"""
-        ))
+            self.tr("Code Metrics"), self.tr("Code &Metrics..."), 0, 0, self, ""
+        )
+        act.setStatusTip(self.tr("Show raw code metrics."))
+        act.setWhatsThis(
+            self.tr(
+                """<b>Code Metrics...</b>"""
+                """<p>This calculates raw code metrics of Python files"""
+                """ and shows the amount of lines of code, logical lines"""
+                """ of code, source lines of code, comment lines,"""
+                """ multi-line strings and blank lines.</p>"""
+            )
+        )
         act.triggered.connect(self.__editorRawMetrics)
         self.__editorMetricsActs.append(act)
-        
+
         act = EricAction(
-            self.tr('Maintainability Index'),
-            self.tr('Maintainability &Index...'), 0, 0,
-            self, "")
-        act.setStatusTip(
-            self.tr('Show the maintainability index for Python files.'))
-        act.setWhatsThis(self.tr(
-            """<b>Maintainability Index...</b>"""
-            """<p>This calculates the maintainability index of Python"""
-            """ files and shows it together with a ranking.</p>"""
-        ))
+            self.tr("Maintainability Index"),
+            self.tr("Maintainability &Index..."),
+            0,
+            0,
+            self,
+            "",
+        )
+        act.setStatusTip(self.tr("Show the maintainability index for Python files."))
+        act.setWhatsThis(
+            self.tr(
+                """<b>Maintainability Index...</b>"""
+                """<p>This calculates the maintainability index of Python"""
+                """ files and shows it together with a ranking.</p>"""
+            )
+        )
         act.triggered.connect(self.__editorMaintainabilityIndex)
         self.__editorMetricsActs.append(act)
-        
+
         act = EricAction(
-            self.tr('Cyclomatic Complexity'),
-            self.tr('Cyclomatic &Complexity...'), 0, 0,
-            self, '')
-        act.setStatusTip(
-            self.tr('Show the cyclomatic complexity for Python files.'))
-        act.setWhatsThis(self.tr(
-            """<b>Cyclomatic Complexity...</b>"""
-            """<p>This calculates the cyclomatic complexity of Python"""
-            """ files and shows it together with a ranking.</p>"""
-        ))
+            self.tr("Cyclomatic Complexity"),
+            self.tr("Cyclomatic &Complexity..."),
+            0,
+            0,
+            self,
+            "",
+        )
+        act.setStatusTip(self.tr("Show the cyclomatic complexity for Python files."))
+        act.setWhatsThis(
+            self.tr(
+                """<b>Cyclomatic Complexity...</b>"""
+                """<p>This calculates the cyclomatic complexity of Python"""
+                """ files and shows it together with a ranking.</p>"""
+            )
+        )
         act.triggered.connect(self.__editorCyclomaticComplexity)
         self.__editorMetricsActs.append(act)
-        
+
         ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu)
-        ericApp().getObject("Project").projectClosed.connect(
-            self.__projectClosed)
+        ericApp().getObject("Project").projectClosed.connect(self.__projectClosed)
         ericApp().getObject("ProjectBrowser").getProjectBrowser(
-            "sources").showMenu.connect(self.__projectBrowserShowMenu)
-        ericApp().getObject("ViewManager").editorOpenedEd.connect(
-            self.__editorOpened)
-        ericApp().getObject("ViewManager").editorClosedEd.connect(
-            self.__editorClosed)
-        
+            "sources"
+        ).showMenu.connect(self.__projectBrowserShowMenu)
+        ericApp().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened)
+        ericApp().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed)
+
         for editor in ericApp().getObject("ViewManager").getOpenEditors():
             self.__editorOpened(editor)
-        
+
         return None, True
-    
+
     def deactivate(self):
         """
         Public method to deactivate this plug-in.
         """
-        ericApp().getObject("Project").showMenu.disconnect(
-            self.__projectShowMenu)
-        ericApp().getObject("Project").projectClosed.disconnect(
-            self.__projectClosed)
+        ericApp().getObject("Project").showMenu.disconnect(self.__projectShowMenu)
+        ericApp().getObject("Project").projectClosed.disconnect(self.__projectClosed)
         ericApp().getObject("ProjectBrowser").getProjectBrowser(
-            "sources").showMenu.disconnect(self.__projectBrowserShowMenu)
+            "sources"
+        ).showMenu.disconnect(self.__projectBrowserShowMenu)
         ericApp().getObject("ViewManager").editorOpenedEd.disconnect(
-            self.__editorOpened)
+            self.__editorOpened
+        )
         ericApp().getObject("ViewManager").editorClosedEd.disconnect(
-            self.__editorClosed)
-        
+            self.__editorClosed
+        )
+
         menu = ericApp().getObject("Project").getMenu("Show")
         if menu:
             for sep in self.__projectSeparatorActs:
@@ -550,14 +586,15 @@
             for act in self.__projectMetricsActs:
                 menu.removeAction(act)
             ericApp().getObject("Project").removeEricActions(
-                self.__projectMetricsActs[1:])
-        
+                self.__projectMetricsActs[1:]
+            )
+
         if self.__projectBrowserMenu:
             for sep in self.__projectBrowserSeparatorActs:
                 self.__projectBrowserMenu.removeAction(sep)
             for act in self.__projectBrowserMetricsActs:
                 self.__projectBrowserMenu.removeAction(act)
-        
+
         for editor in self.__editors:
             editor.showMenu.disconnect(self.__editorShowMenu)
             menu = editor.getMenu("Show")
@@ -566,9 +603,9 @@
                     menu.removeAction(sep)
                 for act in self.__editorMetricsActs:
                     menu.removeAction(act)
-        
+
         self.__initialize()
-    
+
     def __loadTranslator(self):
         """
         Private method to load the translation file.
@@ -577,7 +614,8 @@
             loc = self.__ui.getLocale()
             if loc and loc != "C":
                 locale_dir = os.path.join(
-                    os.path.dirname(__file__), "RadonMetrics", "i18n")
+                    os.path.dirname(__file__), "RadonMetrics", "i18n"
+                )
                 translation = "radon_{0}".format(loc)
                 translator = QTranslator(None)
                 loaded = translator.load(translation, locale_dir)
@@ -585,15 +623,17 @@
                     self.__translator = translator
                     ericApp().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):
         """
         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
         @type str
         @param menu reference to the menu
@@ -602,30 +642,29 @@
         if menuName == "Show":
             for act in self.__projectMetricsActs[1:]:
                 act.setEnabled(
-                    ericApp().getObject("Project").getProjectLanguage() ==
-                    "Python3")
-    
+                    ericApp().getObject("Project").getProjectLanguage() == "Python3"
+                )
+
     def __projectBrowserShowMenu(self, menuName, menu):
         """
         Private slot called, when the the project browser context menu or a
         submenu is about to be shown.
-        
+
         @param menuName name of the menu to be shown
         @type str
         @param menu reference to the menu
         @type QMenu
         """
         if (
-            menuName == "Show" and
-            ericApp().getObject("Project").getProjectLanguage() ==
-            "Python3" and
-            self.__projectBrowserMenu is None
+            menuName == "Show"
+            and ericApp().getObject("Project").getProjectLanguage() == "Python3"
+            and self.__projectBrowserMenu is None
         ):
             self.__projectBrowserMenu = menu
-            
+
             act = menu.addSeparator()
             self.__projectBrowserSeparatorActs.append(act)
-            
+
             # header action
             act = QAction(self.tr("Radon"), self)
             font = act.font()
@@ -634,65 +673,77 @@
             act.triggered.connect(self.__showRadonVersion)
             menu.addAction(act)
             self.__projectBrowserMetricsActs.append(act)
-            
+
             act = EricAction(
-                self.tr('Code Metrics'),
-                self.tr('Code &Metrics...'), 0, 0,
-                self, '')
-            act.setStatusTip(self.tr(
-                'Show raw code metrics.'))
-            act.setWhatsThis(self.tr(
-                """<b>Code Metrics...</b>"""
-                """<p>This calculates raw code metrics of Python files"""
-                """ and shows the amount of lines of code, logical lines"""
-                """ of code, source lines of code, comment lines,"""
-                """ multi-line strings and blank lines.</p>"""
-            ))
+                self.tr("Code Metrics"), self.tr("Code &Metrics..."), 0, 0, self, ""
+            )
+            act.setStatusTip(self.tr("Show raw code metrics."))
+            act.setWhatsThis(
+                self.tr(
+                    """<b>Code Metrics...</b>"""
+                    """<p>This calculates raw code metrics of Python files"""
+                    """ and shows the amount of lines of code, logical lines"""
+                    """ of code, source lines of code, comment lines,"""
+                    """ multi-line strings and blank lines.</p>"""
+                )
+            )
             act.triggered.connect(self.__projectBrowserRawMetrics)
             menu.addAction(act)
             self.__projectBrowserMetricsActs.append(act)
-            
+
             act = EricAction(
-                self.tr('Maintainability Index'),
-                self.tr('Maintainability &Index...'), 0, 0,
-                self, '')
-            act.setStatusTip(self.tr(
-                'Show the maintainability index for Python files.'))
-            act.setWhatsThis(self.tr(
-                """<b>Maintainability Index...</b>"""
-                """<p>This calculates the maintainability index of"""
-                """ Python files and shows it together with a ranking."""
-                """</p>"""
-            ))
-            act.triggered.connect(
-                self.__projectBrowserMaintainabilityIndex)
+                self.tr("Maintainability Index"),
+                self.tr("Maintainability &Index..."),
+                0,
+                0,
+                self,
+                "",
+            )
+            act.setStatusTip(
+                self.tr("Show the maintainability index for Python files.")
+            )
+            act.setWhatsThis(
+                self.tr(
+                    """<b>Maintainability Index...</b>"""
+                    """<p>This calculates the maintainability index of"""
+                    """ Python files and shows it together with a ranking."""
+                    """</p>"""
+                )
+            )
+            act.triggered.connect(self.__projectBrowserMaintainabilityIndex)
             menu.addAction(act)
             self.__projectBrowserMetricsActs.append(act)
-            
+
             act = EricAction(
-                self.tr('Cyclomatic Complexity'),
-                self.tr('Cyclomatic &Complexity...'), 0, 0,
-                self, '')
-            act.setStatusTip(self.tr(
-                'Show the cyclomatic complexity for Python files.'))
-            act.setWhatsThis(self.tr(
-                """<b>Cyclomatic Complexity...</b>"""
-                """<p>This calculates the cyclomatic complexity of"""
-                """ Python files and shows it together with a ranking."""
-                """</p>"""
-            ))
-            act.triggered.connect(
-                self.__projectBrowserCyclomaticComplexity)
+                self.tr("Cyclomatic Complexity"),
+                self.tr("Cyclomatic &Complexity..."),
+                0,
+                0,
+                self,
+                "",
+            )
+            act.setStatusTip(
+                self.tr("Show the cyclomatic complexity for Python files.")
+            )
+            act.setWhatsThis(
+                self.tr(
+                    """<b>Cyclomatic Complexity...</b>"""
+                    """<p>This calculates the cyclomatic complexity of"""
+                    """ Python files and shows it together with a ranking."""
+                    """</p>"""
+                )
+            )
+            act.triggered.connect(self.__projectBrowserCyclomaticComplexity)
             menu.addAction(act)
             self.__projectBrowserMetricsActs.append(act)
-            
+
             act = menu.addSeparator()
             self.__projectBrowserSeparatorActs.append(act)
-    
+
     def __editorOpened(self, editor):
         """
         Private slot called, when a new editor was opened.
-        
+
         @param editor reference to the new editor
         @type Editor
         """
@@ -704,21 +755,21 @@
             editor.showMenu.connect(self.__editorShowMenu)
             editor.editorRenamed.connect(lambda: self.__editorRenamed(editor))
             self.__editors.append(editor)
-    
+
     def __editorClosed(self, editor):
         """
         Private slot called, when an editor was closed.
-        
+
         @param editor reference to the editor
         @type Editor
         """
         with contextlib.suppress(ValueError):
             self.__editors.remove(editor)
-    
+
     def __editorRenamed(self, editor):
         """
         Private slot called, when an editor was renamed.
-        
+
         @param editor reference to the renamed editor
         @type Editor
         """
@@ -727,12 +778,12 @@
             menu.addAction(self.__editorSeparatorActs[0])
             menu.addActions(self.__editorMetricsActs)
             menu.addAction(self.__editorSeparatorActs[1])
-        
+
     def __editorShowMenu(self, menuName, menu, editor):
         """
         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
         @type str
         @param menu reference to the menu
@@ -744,11 +795,11 @@
             enable = editor.isPyFile()
             for act in self.__editorMetricsActs:
                 act.setEnabled(enable)
-    
+
     ##################################################################
     ## Raw code metrics calculations
     ##################################################################
-    
+
     def __projectRawMetrics(self):
         """
         Private slot used to calculate raw code metrics for the project.
@@ -761,21 +812,20 @@
             for file in project.getSources()
             if file.endswith(tuple(Preferences.getPython("Python3Extensions")))
         ]
-        
+
         if self.__projectRawMetricsDialog is None:
             from RadonMetrics.RawMetricsDialog import RawMetricsDialog
+
             self.__projectRawMetricsDialog = RawMetricsDialog(self)
         self.__projectRawMetricsDialog.show()
         self.__projectRawMetricsDialog.prepare(files, project)
-    
+
     def __projectBrowserRawMetrics(self):
         """
         Private method to handle the code metrics context menu action of the
         project sources browser.
         """
-        browser = (
-            ericApp().getObject("ProjectBrowser").getProjectBrowser("sources")
-        )
+        browser = ericApp().getObject("ProjectBrowser").getProjectBrowser("sources")
         if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1:
             fn = []
             for itm in browser.getSelectedItems([ProjectBrowserFileItem]):
@@ -786,13 +836,14 @@
                 fn = itm.fileName()
             except AttributeError:
                 fn = itm.dirName()
-        
+
         if self.__projectBrowserRawMetricsDialog is None:
             from RadonMetrics.RawMetricsDialog import RawMetricsDialog
+
             self.__projectBrowserRawMetricsDialog = RawMetricsDialog(self)
         self.__projectBrowserRawMetricsDialog.show()
         self.__projectBrowserRawMetricsDialog.start(fn)
-    
+
     def __editorRawMetrics(self):
         """
         Private slot to handle the raw code metrics action of the editor show
@@ -800,20 +851,21 @@
         """
         editor = ericApp().getObject("ViewManager").activeWindow()
         if (
-            editor is not None and
-            editor.checkDirty() and
-            editor.getFileName() is not None
+            editor is not None
+            and editor.checkDirty()
+            and editor.getFileName() is not None
         ):
             if self.__editorRawMetricsDialog is None:
                 from RadonMetrics.RawMetricsDialog import RawMetricsDialog
+
                 self.__editorRawMetricsDialog = RawMetricsDialog(self)
             self.__editorRawMetricsDialog.show()
             self.__editorRawMetricsDialog.start(editor.getFileName())
-    
+
     ##################################################################
     ## Maintainability index calculations
     ##################################################################
-    
+
     def __projectMaintainabilityIndex(self):
         """
         Private slot used to calculate the maintainability indexes for the
@@ -827,22 +879,22 @@
             for file in project.getSources()
             if file.endswith(tuple(Preferences.getPython("Python3Extensions")))
         ]
-        
+
         if self.__projectMIDialog is None:
             from RadonMetrics.MaintainabilityIndexDialog import (
-                MaintainabilityIndexDialog
+                MaintainabilityIndexDialog,
             )
+
             self.__projectMIDialog = MaintainabilityIndexDialog(self)
         self.__projectMIDialog.show()
         self.__projectMIDialog.prepare(files, project)
-    
+
     def __projectBrowserMaintainabilityIndex(self):
         """
         Private method to handle the maintainability index context menu action
         of the project sources browser.
         """
-        browser = ericApp().getObject("ProjectBrowser").getProjectBrowser(
-            "sources")
+        browser = ericApp().getObject("ProjectBrowser").getProjectBrowser("sources")
         if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1:
             fn = []
             for itm in browser.getSelectedItems([ProjectBrowserFileItem]):
@@ -853,15 +905,16 @@
                 fn = itm.fileName()
             except AttributeError:
                 fn = itm.dirName()
-        
+
         if self.__projectBrowserMIDialog is None:
             from RadonMetrics.MaintainabilityIndexDialog import (
-                MaintainabilityIndexDialog
+                MaintainabilityIndexDialog,
             )
+
             self.__projectBrowserMIDialog = MaintainabilityIndexDialog(self)
         self.__projectBrowserMIDialog.show()
         self.__projectBrowserMIDialog.start(fn)
-    
+
     def __editorMaintainabilityIndex(self):
         """
         Private slot to handle the maintainability index action of the editor
@@ -869,22 +922,23 @@
         """
         editor = ericApp().getObject("ViewManager").activeWindow()
         if (
-            editor is not None and
-            editor.checkDirty() and
-            editor.getFileName() is not None
+            editor is not None
+            and editor.checkDirty()
+            and editor.getFileName() is not None
         ):
             if self.__editorMIDialog is None:
                 from RadonMetrics.MaintainabilityIndexDialog import (
-                    MaintainabilityIndexDialog
+                    MaintainabilityIndexDialog,
                 )
+
                 self.__editorMIDialog = MaintainabilityIndexDialog(self)
             self.__editorMIDialog.show()
             self.__editorMIDialog.start(editor.getFileName())
-    
+
     ##################################################################
     ## Cyclomatic complexity calculations
     ##################################################################
-    
+
     def __projectCyclomaticComplexity(self):
         """
         Private slot used to calculate the cyclomatic complexity for the
@@ -898,22 +952,22 @@
             for file in project.getSources()
             if file.endswith(tuple(Preferences.getPython("Python3Extensions")))
         ]
-        
+
         if self.__projectCCDialog is None:
             from RadonMetrics.CyclomaticComplexityDialog import (
-                CyclomaticComplexityDialog
+                CyclomaticComplexityDialog,
             )
+
             self.__projectCCDialog = CyclomaticComplexityDialog(self)
         self.__projectCCDialog.show()
         self.__projectCCDialog.prepare(files, project)
-    
+
     def __projectBrowserCyclomaticComplexity(self):
         """
         Private method to handle the cyclomatic complexity context menu action
         of the project sources browser.
         """
-        browser = ericApp().getObject("ProjectBrowser").getProjectBrowser(
-            "sources")
+        browser = ericApp().getObject("ProjectBrowser").getProjectBrowser("sources")
         if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1:
             fn = []
             for itm in browser.getSelectedItems([ProjectBrowserFileItem]):
@@ -924,16 +978,18 @@
                 fn = itm.fileName()
             except AttributeError:
                 fn = itm.dirName()
-        
+
         if self.__projectBrowserCCDialog is None:
             from RadonMetrics.CyclomaticComplexityDialog import (
-                CyclomaticComplexityDialog
+                CyclomaticComplexityDialog,
             )
+
             self.__projectBrowserCCDialog = CyclomaticComplexityDialog(
-                self, isSingle=True)
+                self, isSingle=True
+            )
         self.__projectBrowserCCDialog.show()
         self.__projectBrowserCCDialog.start(fn)
-    
+
     def __editorCyclomaticComplexity(self):
         """
         Private slot to handle the cyclomatic complexity action of the editor
@@ -941,28 +997,29 @@
         """
         editor = ericApp().getObject("ViewManager").activeWindow()
         if (
-            editor is not None and
-            editor.checkDirty() and
-            editor.getFileName() is not None
+            editor is not None
+            and editor.checkDirty()
+            and editor.getFileName() is not None
         ):
             if self.__editorCCDialog is None:
                 from RadonMetrics.CyclomaticComplexityDialog import (
-                    CyclomaticComplexityDialog
+                    CyclomaticComplexityDialog,
                 )
-                self.__editorCCDialog = CyclomaticComplexityDialog(
-                    self, isSingle=True)
+
+                self.__editorCCDialog = CyclomaticComplexityDialog(self, isSingle=True)
             self.__editorCCDialog.show()
             self.__editorCCDialog.start(editor.getFileName())
-    
+
     ##################################################################
     ## Radon info display
     ##################################################################
-    
+
     def __showRadonVersion(self):
         """
         Private slot to show the version number of the used radon library.
         """
         from radon import __version__
+
         EricMessageBox.information(
             None,
             self.tr("Radon"),
@@ -978,12 +1035,13 @@
                 """<li><b>McCabe's complexity</b>, i.e. cyclomatic"""
                 """ complexity</li>"""
                 """</ul></p>"""
-            ).format(__version__))
-    
+            ).format(__version__),
+        )
+
     ##################################################################
     ## Project handling methods
     ##################################################################
-    
+
     def __projectClosed(self):
         """
         Private slot to handle closing a project.
@@ -997,18 +1055,20 @@
 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:
         from radon import __version__ as radon_version
         import Globals
+
         if Globals.versionToTuple(radon_version) < (4, 5, 0):
             # force an upgrade
             pipInstall(["radon>=4.5.0"])
     except ImportError:
         pipInstall(["radon>=4.5.0"])
 
+
 #
 # eflag: noqa = M801

eric ide

mercurial