3535# TODO: support incremental pushes to the OPT frontend for efficiency
3636# and better "snappiness"
3737
38- # TODO: keep global variables in the right order so that elements don't
39- # "jump" around
40-
4138# TODO: support line number adjustments for function definitions/calls
4239# (right now opt-ipy doesn't jump into function calls at all)
4340
@@ -83,7 +80,7 @@ def get_full_trace(self):
8380
8481
8582 def run_str (self , stmt_str , user_globals ):
86- opt_trace = pg_logger .exec_str_with_user_ns (stmt_str , user_globals , get_trace )
83+ opt_trace = pg_logger .exec_str_with_user_ns (stmt_str , user_globals , lambda cod , trace : trace )
8784
8885 # 'clean up' the trace a bit:
8986 if len (self .output_traces ):
@@ -92,6 +89,26 @@ def run_str(self, stmt_str, user_globals):
9289 end_of_last_trace = self .output_traces [- 1 ].pop ()
9390 #print 'END:', end_of_last_trace
9491 #print 'CUR:', opt_trace[0]
92+ last_ordered_globals = list (end_of_last_trace ['ordered_globals' ]) # copy just to be paranoid
93+
94+ # patch up ordered_globals with last_ordered_globals to
95+ # maintain continuity, i.e., prevent variable display from "jumping"
96+ for t in opt_trace :
97+ og = t ['ordered_globals' ]
98+ og_set = set (og )
99+
100+ # reorder og to use last_ordered_globals as a prefix to
101+ # maintain order
102+ new_og = [e for e in last_ordered_globals if e in og_set ]
103+ new_og_set = set (new_og )
104+
105+ # patch in leftovers
106+ leftovers = [e for e in og if e not in new_og_set ]
107+ new_og .extend (leftovers )
108+
109+ assert len (og ) == len (new_og )
110+ t ['ordered_globals' ] = new_og
111+
95112
96113 # clobber the last entry
97114 if self .last_exec_is_exception :
@@ -125,9 +142,6 @@ def run_str(self, stmt_str, user_globals):
125142 return json_output
126143
127144
128- def get_trace (input_code , output_trace ):
129- return output_trace
130-
131145
132146# called right before a statement gets executed
133147def opt_pre_run_code_hook (self ):
@@ -140,9 +154,8 @@ def opt_pre_run_code_hook(self):
140154 filtered_ns [k ] = v
141155
142156 last_cmd = self .history_manager .input_hist_parsed [- 1 ]
143- #print 'last_cmd:', last_cmd
144157 trace_json = self .meta .opt_history .run_str (last_cmd , filtered_ns )
145- print trace_json
158+ # print trace_json
146159 urllib2 .urlopen ("http://localhost:8888/post" , trace_json )
147160
148161
0 commit comments