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

branch
eric7
changeset 9924
b41c9a7bcbbb
parent 9653
e67609152c5e
child 10111
049fbbd2253d
equal deleted inserted replaced
9923:f706be800097 9924:b41c9a7bcbbb
84 ] 84 ]
85 return flags 85 return flags
86 86
87 87
88 def pySyntaxAndPyflakesCheck( 88 def pySyntaxAndPyflakesCheck(
89 filename, codestring, checkFlakes=True, ignoreStarImportWarnings=False 89 filename,
90 codestring,
91 checkFlakes=True,
92 ignoreStarImportWarnings=False,
93 additionalBuiltins=None,
90 ): 94 ):
91 """ 95 """
92 Function to compile one Python source file to Python bytecode 96 Function to compile one Python source file to Python bytecode
93 and to perform a pyflakes check. 97 and to perform a pyflakes check.
94 98
98 @type str 102 @type str
99 @param checkFlakes flag indicating to do a pyflakes check 103 @param checkFlakes flag indicating to do a pyflakes check
100 @type bool 104 @type bool
101 @param ignoreStarImportWarnings flag indicating to ignore 'star import' warnings 105 @param ignoreStarImportWarnings flag indicating to ignore 'star import' warnings
102 @type bool 106 @type bool
107 @param additionalBuiltins list of names pyflakes should consider as builtins
108 @type list of str
103 @return dictionary with the keys 'error' and 'warnings' which 109 @return dictionary with the keys 'error' and 'warnings' which
104 hold a list containing details about the error/warnings 110 hold a list containing details about the error/warnings
105 (file name, line number, column, codestring (only at syntax 111 (file name, line number, column, codestring (only at syntax
106 errors), the message, a list with arguments for the message) 112 errors), the message, a list with arguments for the message)
107 @rtype dict 113 @rtype dict
108 """ 114 """
109 return __pySyntaxAndPyflakesCheck( 115 return __pySyntaxAndPyflakesCheck(
110 filename, codestring, checkFlakes, ignoreStarImportWarnings 116 filename, codestring, checkFlakes, ignoreStarImportWarnings, additionalBuiltins
111 ) 117 )
112 118
113 119
114 def pySyntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0): 120 def pySyntaxAndPyflakesBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0):
115 """ 121 """
199 @type multiprocessing.Queue 205 @type multiprocessing.Queue
200 @param outputQueue output queue 206 @param outputQueue output queue
201 @type multiprocessing.Queue 207 @type multiprocessing.Queue
202 """ 208 """
203 for filename, args in iter(inputQueue.get, "STOP"): 209 for filename, args in iter(inputQueue.get, "STOP"):
204 source, checkFlakes, ignoreStarImportWarnings = args 210 source, checkFlakes, ignoreStarImportWarnings, additionalBuiltins = args
205 result = __pySyntaxAndPyflakesCheck( 211 result = __pySyntaxAndPyflakesCheck(
206 filename, source, checkFlakes, ignoreStarImportWarnings 212 filename, source, checkFlakes, ignoreStarImportWarnings, additionalBuiltins
207 ) 213 )
208 outputQueue.put((filename, result)) 214 outputQueue.put((filename, result))
209 215
210 216
211 def __pySyntaxAndPyflakesCheck( 217 def __pySyntaxAndPyflakesCheck(
212 filename, codestring, checkFlakes=True, ignoreStarImportWarnings=False 218 filename,
219 codestring,
220 checkFlakes=True,
221 ignoreStarImportWarnings=False,
222 additionalBuiltins=None,
213 ): 223 ):
214 """ 224 """
215 Function to compile one Python source file to Python bytecode 225 Function to compile one Python source file to Python bytecode
216 and to perform a pyflakes check. 226 and to perform a pyflakes check.
217 227
222 @param checkFlakes flag indicating to do a pyflakes check 232 @param checkFlakes flag indicating to do a pyflakes check
223 @type bool 233 @type bool
224 @param ignoreStarImportWarnings flag indicating to 234 @param ignoreStarImportWarnings flag indicating to
225 ignore 'star import' warnings 235 ignore 'star import' warnings
226 @type bool 236 @type bool
237 @param additionalBuiltins list of names pyflakes should consider as builtins
238 @type list of str
227 @return dictionary with the keys 'error' and 'warnings' which 239 @return dictionary with the keys 'error' and 'warnings' which
228 hold a list containing details about the error/ warnings 240 hold a list containing details about the error/ warnings
229 (file name, line number, column, codestring (only at syntax 241 (file name, line number, column, codestring (only at syntax
230 errors), the message, a list with arguments for the message) 242 errors), the message, a list with arguments for the message)
231 @rtype dict 243 @rtype dict
296 return [{}] 308 return [{}]
297 309
298 results = [] 310 results = []
299 lines = codestring.splitlines() 311 lines = codestring.splitlines()
300 try: 312 try:
301 warnings = Checker(module, filename, withDoctest=True) 313 warnings = Checker(
314 module, filename, builtins=additionalBuiltins, withDoctest=True
315 )
302 warnings.messages.sort(key=lambda a: a.lineno) 316 warnings.messages.sort(key=lambda a: a.lineno)
303 for warning in warnings.messages: 317 for warning in warnings.messages:
304 if ignoreStarImportWarnings and isinstance( 318 if ignoreStarImportWarnings and isinstance(
305 warning, (ImportStarUsed, ImportStarUsage) 319 warning, (ImportStarUsed, ImportStarUsage)
306 ): 320 ):

eric ide

mercurial