Utilities/SyntaxCheck.py

branch
Py2 comp.
changeset 3065
070b35dde35e
parent 2571
e6bb19eb87ea
child 3161
06f57a834adf
diff -r 1c0ea3a87390 -r 070b35dde35e Utilities/SyntaxCheck.py
--- a/Utilities/SyntaxCheck.py	Sun Nov 03 16:23:07 2013 +0100
+++ b/Utilities/SyntaxCheck.py	Tue Nov 05 22:23:38 2013 +0100
@@ -93,7 +93,8 @@
             try:
                 import ThirdParty.CharDet.chardet
                 guess = ThirdParty.CharDet.chardet.detect(text)
-                if guess and guess['confidence'] > 0.95 and guess['encoding'] is not None:
+                if guess and guess['confidence'] > 0.95 \
+                        and guess['encoding'] is not None:
                     codec = guess['encoding'].lower()
                     return str(text, codec), '{0}-guessed'.format(codec)
             except (UnicodeError, LookupError, ImportError):
@@ -165,7 +166,8 @@
 
 def extractLineFlags(line, startComment="#", endComment=""):
     """
-    Function to extract flags starting and ending with '__' from a line comment.
+    Function to extract flags starting and ending with '__' from a line
+    comment.
     
     @param line line to extract flags from (string)
     @keyparam startComment string identifying the start of the comment (string)
@@ -184,7 +186,8 @@
     return flags
 
 
-def compile_and_check(file_, codestring="", checkFlakes=True, ignoreStarImportWarnings=False):
+def compile_and_check(file_, codestring="", checkFlakes=True,
+                      ignoreStarImportWarnings=False):
     """
     Function to compile one Python source file to Python bytecode
     and to perform a pyflakes check.
@@ -201,7 +204,6 @@
         warnings (marker, file name, line number, message)
         The values are only valid, if the status is True.
     """
- 
     try:
         import builtins
     except ImportError:
@@ -237,7 +239,7 @@
         error = ""
         lines = traceback.format_exception_only(SyntaxError, detail)
         match = re.match('\s*File "(.+)", line (\d+)',
-            lines[0].replace('<string>', '{0}'.format(file_)))
+                         lines[0].replace('<string>', '{0}'.format(file_)))
         if match is not None:
             fn, line = match.group(1, 2)
             if lines[1].startswith('SyntaxError:'):
@@ -288,12 +290,14 @@
         warnings.messages.sort(key=lambda a: a.lineno)
         for warning in warnings.messages:
             if ignoreStarImportWarnings and \
-                isinstance(warning, ImportStarUsed):
-                    continue
+                    isinstance(warning, ImportStarUsed):
+                continue
             
             _fn, lineno, message, msg_args = warning.getMessageData()
-            if "__IGNORE_WARNING__" not in extractLineFlags(lines[lineno - 1].strip()):
-                strings.append(["FLAKES_WARNING", _fn, lineno, message, msg_args])
+            if "__IGNORE_WARNING__" not in extractLineFlags(
+                    lines[lineno - 1].strip()):
+                strings.append([
+                    "FLAKES_WARNING", _fn, lineno, message, msg_args])
     except SyntaxError as err:
         if err.text.strip():
             msg = err.text.strip()
@@ -317,13 +321,15 @@
     else:
         filename = sys.argv[-1]
         checkFlakes = len(sys.argv) == 3
-        ignoreStarImportWarnings = sys.argv[1] == "-fi"     # Setting is ignored if checkFlakes is False
+        # Setting is ignored if checkFlakes is False
+        ignoreStarImportWarnings = sys.argv[1] == "-fi"
         
         try:
             codestring = readEncodedFile(filename)[0]
             
             syntaxerror, fname, line, index, code, error, warnings = \
-                compile_and_check(filename, codestring, checkFlakes, ignoreStarImportWarnings)
+                compile_and_check(filename, codestring, checkFlakes,
+                                  ignoreStarImportWarnings)
         except IOError as msg:
             # fake a syntax error
             syntaxerror, fname, line, index, code, error, warnings = \

eric ide

mercurial