-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteractive.py
More file actions
executable file
·46 lines (39 loc) · 1.76 KB
/
Copy pathinteractive.py
File metadata and controls
executable file
·46 lines (39 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""Interactive front end for EnvDraw.
This was added by Tom Magrino (tmagrino@berkeley.edu)
"""
import ast, inspect
from code import InteractiveConsole, compile_command
from examine import *
from pprint import pprint
class EnvDrawConsole(InteractiveConsole):
"""InteractiveConsole for the EnvDraw program."""
def runsource(self, source, filename="<input>", symbol="single"):
"""Do the same thing as any InteractiveConsole, except if we run into a
completed statement, we first run the decoration code for envdraw on it
before passing it off to the execute part of the REPL.
"""
try:
if compile_command(source, filename, symbol):
tree = ast.parse(source, filename, symbol)
new_tree = ast.fix_missing_locations(AddFuncCall().visit(
AddFuncReturn().visit(
AddFuncDef().visit(tree))))
compiled_code = compile(new_tree, filename, symbol)
self.runcode(compiled_code)
TRACKER.insert_global_bindings(self.locals)
return False
else:
return InteractiveConsole.runsource(self, source, filename, symbol)
except (SyntaxError, OverflowError):
self.showsyntaxerror(filename)
return False
TRACKER = Tracker()
funcdef.tracker = TRACKER
funcreturn.tracker = TRACKER
funccall.tracker = TRACKER
if __name__ == "__main__":
# Add in bindings that we want to have "under the hood" in the interpreter
local_bindings = {v : globals()[v] for v in IGNORE_VARS if v in
globals().keys()}
EnvDrawConsole(locals=local_bindings).interact()