Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py

branch
maintenance
changeset 5680
b93cb6353cc0
parent 5672
495b53f37f6c
child 5683
66b11f5171e8
diff -r 884cd9c9ce05 -r b93cb6353cc0 Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py
--- a/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Thu Mar 23 18:58:56 2017 +0100
+++ b/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py	Fri Apr 07 18:33:59 2017 +0200
@@ -13,6 +13,7 @@
 import sys
 import traceback
 import multiprocessing
+import queue
 
 try:
     from pyflakes.checker import Checker
@@ -65,7 +66,7 @@
     return codestring
 
 
-def extractLineFlags(line, startComment="#", endComment=""):
+def extractLineFlags(line, startComment="#", endComment="", flagsLine=False):
     """
     Function to extract flags starting and ending with '__' from a line
     comment.
@@ -73,17 +74,22 @@
     @param line line to extract flags from (string)
     @keyparam startComment string identifying the start of the comment (string)
     @keyparam endComment string identifying the end of a comment (string)
+    @keyparam flagsLine flag indicating to check for a flags only line (bool)
     @return list containing the extracted flags (list of strings)
     """
     flags = []
     
-    pos = line.rfind(startComment)
-    if pos >= 0:
-        comment = line[pos + len(startComment):].strip()
-        if endComment:
-            comment = comment.replace("endComment", "")
-        flags = [f.strip() for f in comment.split()
-                 if (f.startswith("__") and f.endswith("__"))]
+    if not flagsLine or (
+       flagsLine and line.strip().startswith(startComment)):
+        pos = line.rfind(startComment)
+        if pos >= 0:
+            comment = line[pos + len(startComment):].strip()
+            if endComment:
+                endPos = line.rfind(endComment)
+                if endPos >= 0:
+                    comment = comment[:endPos]
+            flags = [f.strip() for f in comment.split()
+                     if (f.startswith("__") and f.endswith("__"))]
     return flags
 
 
@@ -142,11 +148,25 @@
     # Get and send results
     endIndex = len(argumentsList) - initialTasks
     for i in range(len(argumentsList)):
-        filename, result = doneQueue.get()
-        send(fx, filename, result)
-        if cancelled():
+        resultSent = False
+        wasCancelled = False
+        
+        while not resultSent:
+            try:
+                # get result (waiting max. 3 seconds and send it to frontend
+                filename, result = doneQueue.get()
+                send(fx, filename, result)
+                resultSent = True
+            except queue.Empty:
+                # ignore empty queue, just carry on
+                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])
 
@@ -155,18 +175,18 @@
         taskQueue.put('STOP')
 
 
-def worker(input, output):
+def worker(inputQueue, outputQueue):
     """
     Module function acting as the parallel worker for the style check.
     
-    @param input input queue (multiprocessing.Queue)
-    @param output output queue (multiprocessing.Queue)
+    @param inputQueue input queue (multiprocessing.Queue)
+    @param outputQueue output queue (multiprocessing.Queue)
     """
-    for filename, args in iter(input.get, 'STOP'):
+    for filename, args in iter(inputQueue.get, 'STOP'):
         source, checkFlakes, ignoreStarImportWarnings = args
         result = __syntaxAndPyflakesCheck(filename, source, checkFlakes,
                                           ignoreStarImportWarnings)
-        output.put((filename, result))
+        outputQueue.put((filename, result))
 
 
 def __syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True,
@@ -262,7 +282,7 @@
             line = detail.lineno
             error = detail.msg
             return [{'error': (fn, line, 0, "", error)}]
-        except:         # __IGNORE_WARNING__
+        except Exception:
             pass
     
     # pyflakes
@@ -282,8 +302,13 @@
                 continue
             
             _fn, lineno, col, message, msg_args = warning.getMessageData()
-            if "__IGNORE_WARNING__" not in extractLineFlags(
-                    lines[lineno - 1].strip()):
+            lineFlags = extractLineFlags(lines[lineno - 1].strip())
+            try:
+                lineFlags += extractLineFlags(lines[lineno].strip(),
+                                              flagsLine=True)
+            except IndexError:
+                pass
+            if "__IGNORE_WARNING__" not in lineFlags:
                 results.append((_fn, lineno, col, "", message, msg_args))
     except SyntaxError as err:
         if err.text.strip():

eric ide

mercurial