RadonMetrics/MaintainabilityIndexCalculator.py

branch
eric7
changeset 94
725eaca7bc4b
parent 90
1405e41edc0b
child 104
6eac83394939
--- a/RadonMetrics/MaintainabilityIndexCalculator.py	Mon Sep 19 17:43:37 2022 +0200
+++ b/RadonMetrics/MaintainabilityIndexCalculator.py	Mon Sep 19 17:54:33 2022 +0200
@@ -14,7 +14,7 @@
 def initService():
     """
     Initialize the service and return the entry point.
-    
+
     @return the entry point for the background client (function)
     """
     return maintainabilityIndex
@@ -23,7 +23,7 @@
 def initBatchService():
     """
     Initialize the batch service and return the entry point.
-    
+
     @return the entry point for the background client (function)
     """
     return batchMaintainabilityIndex
@@ -32,7 +32,7 @@
 def maintainabilityIndex(file, text=""):
     """
     Private function to calculate the maintainability index of one file.
-    
+
     @param file source filename
     @type str
     @param text source text
@@ -43,12 +43,11 @@
     return __maintainabilityIndex(file, text)
 
 
-def batchMaintainabilityIndex(argumentsList, send, fx, cancelled,
-                              maxProcesses=0):
+def batchMaintainabilityIndex(argumentsList, send, fx, cancelled, maxProcesses=0):
     """
     Module function to calculate the maintainability index for a batch of
     files.
-    
+
     @param argumentsList list of arguments tuples as given for
         maintainabilityIndex
     @type list
@@ -83,9 +82,8 @@
 
     # Start worker processes
     workers = [
-        multiprocessing.Process(
-            target=workerTask, args=(taskQueue, doneQueue)
-        ) for _ in range(NumberOfProcesses)
+        multiprocessing.Process(target=workerTask, args=(taskQueue, doneQueue))
+        for _ in range(NumberOfProcesses)
     ]
     for worker in workers:
         worker.start()
@@ -95,7 +93,7 @@
     for i in range(len(argumentsList)):
         resultSent = False
         wasCancelled = False
-        
+
         while not resultSent:
             try:
                 # get result (waiting max. 3 seconds and send it to frontend
@@ -107,18 +105,18 @@
                 if cancelled():
                     wasCancelled = True
                     break
-        
+
         if wasCancelled or cancelled():
             # just exit the loop ignoring the results of queued tasks
             break
-        
+
         if i < endIndex:
             taskQueue.put(argumentsList[i + initialTasks])
 
     # Tell child processes to stop
     for _ in range(NumberOfProcesses):
-        taskQueue.put('STOP')
-    
+        taskQueue.put("STOP")
+
     for worker in workers:
         worker.join()
         worker.close()
@@ -128,13 +126,13 @@
     """
     Module function acting as the parallel worker for the maintainability
     index calculation.
-    
+
     @param inputQueue input queue
     @type multiprocessing.Queue
     @param outputQueue output queue
     @type multiprocessing.Queue
     """
-    for filename, source in iter(inputQueue.get, 'STOP'):
+    for filename, source in iter(inputQueue.get, "STOP"):
         result = __maintainabilityIndex(filename, source)
         outputQueue.put((filename, result))
 
@@ -143,7 +141,7 @@
     """
     Private function to calculate the maintainability index for one Python
     file.
-    
+
     @param file source filename
     @type str
     @param text source text
@@ -152,11 +150,11 @@
     @rtype (tuple of dict)
     """
     from radon.metrics import mi_visit, mi_rank
-    
+
     try:
         mi = mi_visit(text, True)
         rank = mi_rank(mi)
         res = {"mi": mi, "rank": rank}
     except Exception as err:
         res = {"error": str(err)}
-    return (res, )
+    return (res,)

eric ide

mercurial