Commit 722d4d95 authored by Jérome Perrin's avatar Jérome Perrin Committed by Jérome Perrin

check source code: only use compile for failures and pyflakes for warning

parent 20d2e959
...@@ -434,6 +434,40 @@ def checkPythonSourceCode(source_code_str): ...@@ -434,6 +434,40 @@ def checkPythonSourceCode(source_code_str):
if not source_code_str: if not source_code_str:
return [] return []
try:
compile(source_code_str, '<string>', 'exec')
except Exception, error:
if isinstance(error, SyntaxError):
message = {'type': 'F',
'row': error.lineno,
'column': error.offset,
'text': error.message}
else:
message = {'type': 'F',
'row': -1,
'column': -1,
'text': str(error)}
return [message]
import pyflakes.reporter
import pyflakes.api
message_list = []
class ERP5FlakesReporter(pyflakes.reporter.Reporter):
__init__ = unexpectedError = syntaxError = lambda *args, **kw: None # errors are handled by compile
def flake(self, message):
message_list.append(
{'type': 'W',
'row': message.lineno,
'column': message.col,
'text': message.message % message.message_args })
pyflakes.api.check(source_code_str, '<string>', ERP5FlakesReporter())
return message_list
# XXX pylint disabled because it is slow
try: try:
from pylint.lint import Run from pylint.lint import Run
from pylint.reporters.text import TextReporter from pylint.reporters.text import TextReporter
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment