src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheck.py

branch
eric7
changeset 9507
1f39839655ea
parent 9482
a2bc06a54d9d
equal deleted inserted replaced
9506:62397ab8df8c 9507:1f39839655ea
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the syntax check for Python 3. 7 Module implementing the syntax check for Python 3.
8 """ 8 """
9
10 # TODO: rename this module 'pyCheckSyntax'
9 11
10 import ast 12 import ast
11 import builtins 13 import builtins
12 import contextlib 14 import contextlib
13 import multiprocessing 15 import multiprocessing
42 Initialize the batch service and return the entry point. 44 Initialize the batch service and return the entry point.
43 45
44 @return the entry point for the background client (function) 46 @return the entry point for the background client (function)
45 """ 47 """
46 return syntaxAndPyflakesBatchCheck 48 return syntaxAndPyflakesBatchCheck
47
48
49 def normalizeCode(codestring):
50 """
51 Function to normalize the given code.
52
53 @param codestring code to be normalized (string)
54 @return normalized code (string)
55 """
56 codestring = codestring.replace("\r\n", "\n").replace("\r", "\n")
57
58 if codestring and codestring[-1] != "\n":
59 codestring += "\n"
60
61 return codestring
62 49
63 50
64 def extractLineFlags(line, startComment="#", endComment="", flagsLine=False): 51 def extractLineFlags(line, startComment="#", endComment="", flagsLine=False):
65 """ 52 """
66 Function to extract flags starting and ending with '__' from a line 53 Function to extract flags starting and ending with '__' from a line
91 f.strip().lower() for f in comment.split() if f in ("noqa", "NOQA") 78 f.strip().lower() for f in comment.split() if f in ("noqa", "NOQA")
92 ] 79 ]
93 return flags 80 return flags
94 81
95 82
83 # TODO: rename this function 'pySyntaxAndPyflakesCheck'
96 def syntaxAndPyflakesCheck( 84 def syntaxAndPyflakesCheck(
97 filename, codestring, checkFlakes=True, ignoreStarImportWarnings=False 85 filename, codestring, checkFlakes=True, ignoreStarImportWarnings=False
98 ): 86 ):
99 """ 87 """
100 Function to compile one Python source file to Python bytecode 88 Function to compile one Python source file to Python bytecode
113 return __syntaxAndPyflakesCheck( 101 return __syntaxAndPyflakesCheck(
114 filename, codestring, checkFlakes, ignoreStarImportWarnings 102 filename, codestring, checkFlakes, ignoreStarImportWarnings
115 ) 103 )
116 104
117 105
106 # TODO: rename this function 'pySyntaxAndPyflakesBatchCheck'
118 def syntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0): 107 def syntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0):
119 """ 108 """
120 Module function to check syntax for a batch of files. 109 Module function to check syntax for a batch of files.
121 110
122 @param argumentsList list of arguments tuples as given for 111 @param argumentsList list of arguments tuples as given for
232 (file name, line number, column, codestring (only at syntax 221 (file name, line number, column, codestring (only at syntax
233 errors), the message, a list with arguments for the message) 222 errors), the message, a list with arguments for the message)
234 @rtype dict 223 @rtype dict
235 """ 224 """
236 try: 225 try:
237 codestring = normalizeCode(codestring)
238
239 # Check for VCS conflict markers 226 # Check for VCS conflict markers
240 for conflictMarkerRe in VcsConflictMarkerRegExpList: 227 for conflictMarkerRe in VcsConflictMarkerRegExpList:
241 conflict = conflictMarkerRe.search(codestring) 228 conflict = conflictMarkerRe.search(codestring)
242 if conflict is not None: 229 if conflict is not None:
243 start, i = conflict.span() 230 start, i = conflict.span()

eric ide

mercurial