VultureChecker/VultureCheckerService.py

branch
eric7
changeset 90
6393ee6e7993
parent 85
6a17f25cefa1
child 97
6ec0844dafe7
--- a/VultureChecker/VultureCheckerService.py	Mon Sep 19 18:06:19 2022 +0200
+++ b/VultureChecker/VultureCheckerService.py	Mon Sep 19 18:11:49 2022 +0200
@@ -16,7 +16,7 @@
 def initService():
     """
     Initialize the service and return the entry point.
-    
+
     @return the entry point for the background client (function)
     """
     return vultureCheck
@@ -25,7 +25,7 @@
 def initBatchService():
     """
     Initialize the batch service and return the entry point.
-    
+
     @return the entry point for the background client (function)
     """
     return batchVultureCheck
@@ -34,7 +34,7 @@
 def vultureCheck(file, text=""):
     """
     Private function to analyze one file.
-    
+
     @param file source filename
     @type str
     @param text source text
@@ -48,7 +48,7 @@
 def batchVultureCheck(argumentsList, send, fx, cancelled, maxProcesses=0):
     """
     Module function to analyze a batch of files.
-    
+
     @param argumentsList list of arguments tuples as given for vultureCheck
     @type list
     @param send reference to send function
@@ -82,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()
@@ -94,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
@@ -106,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()
@@ -126,13 +125,13 @@
 def workerTask(inputQueue, outputQueue):
     """
     Module function acting as the parallel worker for the vulture check.
-    
+
     @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 = __analyze(filename, source)
         outputQueue.put((filename, result))
 
@@ -140,7 +139,7 @@
 def __analyze(filename, text=""):
     """
     Private function to analyze one Python file.
-    
+
     @param filename source file name
     @type str
     @param text source text
@@ -154,17 +153,18 @@
         res = v.getResults()
     except Exception as err:
         res = {"error": str(err)}
-    return (res, )
+    return (res,)
 
 
 class EricVulture(Vulture):
     """
     Class to adopt the Vulture class to the eric plug-in functionality.
     """
+
     def __item2Dict(self, item):
         """
         Private method to convert a vulture item to a dictionary.
-        
+
         @param item vulture item
         @type vulture.Item
         @return item dictionary
@@ -178,27 +178,20 @@
             "last_line": item.last_lineno,
             "confidence": item.confidence,
         }
-    
+
     def getResults(self):
         """
         Public method to get the scan results.
-        
+
         @return scan results
         @rtype dict
         """
         return {
-            "UnusedAttributes":
-                [self.__item2Dict(i) for i in self.unused_attrs],
-            "UnusedClasses":
-                [self.__item2Dict(i) for i in self.unused_classes],
-            "UnusedFunctions":
-                [self.__item2Dict(i) for i in self.unused_funcs],
-            "UnusedMethods":
-                [self.__item2Dict(i) for i in self.unused_methods],
-            "UnusedImports":
-                [self.__item2Dict(i) for i in self.unused_imports],
-            "UnusedProperties":
-                [self.__item2Dict(i) for i in self.unused_props],
-            "UnusedVariables":
-                [self.__item2Dict(i) for i in self.unused_vars],
+            "UnusedAttributes": [self.__item2Dict(i) for i in self.unused_attrs],
+            "UnusedClasses": [self.__item2Dict(i) for i in self.unused_classes],
+            "UnusedFunctions": [self.__item2Dict(i) for i in self.unused_funcs],
+            "UnusedMethods": [self.__item2Dict(i) for i in self.unused_methods],
+            "UnusedImports": [self.__item2Dict(i) for i in self.unused_imports],
+            "UnusedProperties": [self.__item2Dict(i) for i in self.unused_props],
+            "UnusedVariables": [self.__item2Dict(i) for i in self.unused_vars],
         }

eric ide

mercurial