fixed syntax checking

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-23 02:37:30 +00:00
parent eefc8c6086
commit 1d2f8db085
1 changed files with 11 additions and 16 deletions

View File

@ -1,4 +1,4 @@
import commands, os.path, sets, string import commands, os.path, sets, string, sys, traceback
import color, completer, default, mode2, method, regex, tab2 import color, completer, default, mode2, method, regex, tab2
from point2 import Point from point2 import Point
from lex3 import Grammar, PatternRule, RegionRule, OverridePatternRule from lex3 import Grammar, PatternRule, RegionRule, OverridePatternRule
@ -212,21 +212,16 @@ class PythonSetLib(method.Method):
class PythonCheckSyntax(method.Method): class PythonCheckSyntax(method.Method):
'''Check the syntax of the current python file''' '''Check the syntax of the current python file'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
mod = os.path.splitext(w.buffer.path)[0] syspath = list(sys.path)
cwd = os.getcwd() + '/' sys.path.insert(0, w.mode.pythonlib)
if mod.startswith(cwd): source = w.buffer.make_string()
mod = mod.replace(cwd, '', 1) try:
else: code = compile(source, w.buffer.path, 'exec')
mod = os.path.basename(mod) w.set_error("Syntax OK")
mod = mod.replace('/', '.') except Exception, e:
cmd = "PYTHONPATH=%s python -c 'import %s'" % (w.mode.pythonlib, mod) output = traceback.format_exc()
(status, output) = commands.getstatusoutput(cmd) w.application.data_buffer("*PythonSyntax*", output, switch_to=True)
if status == 0: sys.path = syspath
w.application.set_error("Syntax OK")
w.application.data_buffer("python-syntax", output, switch_to=False)
else:
output = output + "\ncommand exit status: %d" % (status)
w.application.data_buffer("python-syntax", output, switch_to=True)
class PythonDictCleanup(method.Method): class PythonDictCleanup(method.Method):
'''Align assignment blocks and literal dictionaries''' '''Align assignment blocks and literal dictionaries'''