##// END OF EJS Templates
Finish removing spurious calls to logger and runlines....
Fernando Perez -
Show More
@@ -250,7 +250,7 b' class DisplayHook(Configurable):'
250 250 def log_output(self, result):
251 251 """Log the output."""
252 252 if self.shell.logger.log_output:
253 self.shell.logger.log_write(repr(result),'output')
253 self.shell.logger.log_write(repr(result), 'output')
254 254
255 255 def finish_displayhook(self):
256 256 """Finish up all displayhook activities."""
@@ -36,6 +36,7 b' class HistoryManager(object):'
36 36 def __init__(self, shell):
37 37 """Create a new history manager associated with a shell instance.
38 38 """
39 # We need a pointer back to the shell for various tasks.
39 40 self.shell = shell
40 41
41 42 # List of input with multi-line handling.
@@ -64,6 +65,13 b' class HistoryManager(object):'
64 65 # Objects related to shadow history management
65 66 self._init_shadow_hist()
66 67
68 # Variables used to store the three last inputs from the user. On each
69 # new history update, we populate the user's namespace with these,
70 # shifted as necessary.
71 self._i00, self._i, self._ii, self._iii = '','','',''
72
73 # Object is fully initialized, we can now call methods on it.
74
67 75 # Fill the history zero entry, user counter starts at 1
68 76 self.store_inputs('\n', '\n')
69 77
@@ -158,8 +166,9 b' class HistoryManager(object):'
158 166 return hist
159 167
160 168 def store_inputs(self, source, source_raw=None):
161 """Store source and raw input in history.
162
169 """Store source and raw input in history and create input cache
170 variables _i*.
171
163 172 Parameters
164 173 ----------
165 174 source : str
@@ -175,6 +184,20 b' class HistoryManager(object):'
175 184 self.input_hist_raw.append(source_raw)
176 185 self.shadow_hist.add(source)
177 186
187 # update the auto _i variables
188 self._iii = self._ii
189 self._ii = self._i
190 self._i = self._i00
191 self._i00 = source_raw
192
193 # hackish access to user namespace to create _i1,_i2... dynamically
194 new_i = '_i%s' % self.shell.execution_count
195 to_main = {'_i': self._i,
196 '_ii': self._ii,
197 '_iii': self._iii,
198 new_i : self._i00 }
199 self.shell.user_ns.update(to_main)
200
178 201 def sync_inputs(self):
179 202 """Ensure raw and translated histories have same length."""
180 203 if len(self.input_hist) != len (self.input_hist_raw):
@@ -403,7 +426,7 b' def rep_f(self, arg):'
403 426 try:
404 427 lines = self.extract_input_slices(args, True)
405 428 print("lines", lines)
406 self.runlines(lines)
429 self.run_cell(lines)
407 430 except ValueError:
408 431 print("Not found in recent history:", args)
409 432
@@ -430,11 +430,12 b' class InteractiveShell(Configurable, Magic):'
430 430 self.dir_stack = []
431 431
432 432 def init_logger(self):
433 self.logger = Logger(self, logfname='ipython_log.py', logmode='rotate')
434 # local shortcut, this is used a LOT
435 self.log = self.logger.log
433 self.logger = Logger(self.home_dir, logfname='ipython_log.py',
434 logmode='rotate')
436 435
437 436 def init_logstart(self):
437 """Initialize logging in case it was requested at the command line.
438 """
438 439 if self.logappend:
439 440 self.magic_logstart(self.logappend + ' append')
440 441 elif self.logfile:
@@ -1839,7 +1840,6 b' class InteractiveShell(Configurable, Magic):'
1839 1840 # code out there that may rely on this).
1840 1841 self.prefilter = self.prefilter_manager.prefilter_lines
1841 1842
1842
1843 1843 def auto_rewrite_input(self, cmd):
1844 1844 """Print to the screen the rewritten form of the user's command.
1845 1845
@@ -2026,12 +2026,11 b' class InteractiveShell(Configurable, Magic):'
2026 2026 with prepended_to_syspath(dname):
2027 2027 try:
2028 2028 with open(fname) as thefile:
2029 script = thefile.read()
2030 # self.runlines currently captures all exceptions
2031 # raise in user code. It would be nice if there were
2029 # self.run_cell currently captures all exceptions
2030 # raised in user code. It would be nice if there were
2032 2031 # versions of runlines, execfile that did raise, so
2033 2032 # we could catch the errors.
2034 self.runlines(script, clean=True)
2033 self.run_cell(thefile.read())
2035 2034 except:
2036 2035 self.showtraceback()
2037 2036 warn('Unknown failure executing file: <%s>' % fname)
@@ -2099,6 +2098,7 b' class InteractiveShell(Configurable, Magic):'
2099 2098 # Store raw and processed history
2100 2099 self.history_manager.store_inputs(ipy_cell, cell)
2101 2100
2101 self.logger.log(ipy_cell, cell)
2102 2102 # dbg code!!!
2103 2103 if 0:
2104 2104 def myapp(self, val): # dbg
@@ -20,9 +20,7 b' class Macro(IPyAutocall):'
20 20 """
21 21
22 22 def __init__(self,data):
23
24 # store the macro value, as a single string which can be evaluated by
25 # runlines()
23 # store the macro value, as a single string which can be executed
26 24 self.value = ''.join(data).rstrip()+'\n'
27 25
28 26 def __str__(self):
@@ -34,7 +32,7 b' class Macro(IPyAutocall):'
34 32 def __call__(self,*args):
35 33 IPython.utils.io.Term.cout.flush()
36 34 self._ip.user_ns['_margv'] = args
37 self._ip.runlines(self.value)
35 self._ip.run_cell(self.value)
38 36
39 37 def __getstate__(self):
40 38 """ needed for safe pickling via %store """
@@ -41,11 +41,6 b' except ImportError:'
41 41 except ImportError:
42 42 profile = pstats = None
43 43
44 # print_function was added to __future__ in Python2.6, remove this when we drop
45 # 2.5 compatibility
46 if not hasattr(__future__,'CO_FUTURE_PRINT_FUNCTION'):
47 __future__.CO_FUTURE_PRINT_FUNCTION = 65536
48
49 44 import IPython
50 45 from IPython.core import debugger, oinspect
51 46 from IPython.core.error import TryNext
@@ -2331,7 +2326,7 b' Currently the magic system has the following functions:\\n"""'
2331 2326 else:
2332 2327 print 'done. Executing edited code...'
2333 2328 if opts_r:
2334 self.shell.runlines(file_read(filename))
2329 self.shell.run_cell(file_read(filename))
2335 2330 else:
2336 2331 self.shell.safe_execfile(filename,self.shell.user_ns,
2337 2332 self.shell.user_ns)
@@ -2992,7 +2987,7 b' Defaulting color scheme to \'NoColor\'"""'
2992 2987 (input.startswith(start) or input.startswith(start_magic)):
2993 2988 #print 'match',`input` # dbg
2994 2989 print 'Executing:',input,
2995 self.shell.runlines(input)
2990 self.shell.run_cell(input)
2996 2991 return
2997 2992 print 'No previous input matching `%s` found.' % start
2998 2993
@@ -373,10 +373,6 b' class PrefilterManager(Configurable):'
373 373 # print "prefilter_line: ", line, continue_prompt
374 374 # All handlers *must* return a value, even if it's blank ('').
375 375
376 # Lines are NOT logged here. Handlers should process the line as
377 # needed, update the cache AND log it (so that the input cache array
378 # stays synced).
379
380 376 # save the line away in case we crash, so the post-mortem handler can
381 377 # record it
382 378 self.shell._last_input_line = line
@@ -792,7 +788,6 b' class PrefilterHandler(Configurable):'
792 788 ):
793 789 line = ''
794 790
795 self.shell.log(line, line, continue_prompt)
796 791 return line
797 792
798 793 def __str__(self):
@@ -811,7 +806,6 b' class AliasHandler(PrefilterHandler):'
811 806 line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace,
812 807 make_quoted_expr(transformed))
813 808
814 self.shell.log(line_info.line, line_out, line_info.continue_prompt)
815 809 return line_out
816 810
817 811
@@ -840,8 +834,6 b' class ShellEscapeHandler(PrefilterHandler):'
840 834 cmd = line.lstrip().lstrip(ESC_SHELL)
841 835 line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace,
842 836 make_quoted_expr(cmd))
843 # update cache/log and return
844 self.shell.log(line, line_out, line_info.continue_prompt)
845 837 return line_out
846 838
847 839
@@ -856,7 +848,6 b' class MagicHandler(PrefilterHandler):'
856 848 the_rest = line_info.the_rest
857 849 cmd = '%sget_ipython().magic(%s)' % (line_info.pre_whitespace,
858 850 make_quoted_expr(ifun + " " + the_rest))
859 self.shell.log(line_info.line, cmd, line_info.continue_prompt)
860 851 return cmd
861 852
862 853
@@ -877,7 +868,6 b' class AutoHandler(PrefilterHandler):'
877 868
878 869 # This should only be active for single-line input!
879 870 if continue_prompt:
880 self.shell.log(line,line,continue_prompt)
881 871 return line
882 872
883 873 force_auto = isinstance(obj, IPyAutocall)
@@ -918,9 +908,6 b' class AutoHandler(PrefilterHandler):'
918 908 if auto_rewrite:
919 909 self.shell.auto_rewrite_input(newcmd)
920 910
921 # log what is now valid Python, not the actual user input (without the
922 # final newline)
923 self.shell.log(line,newcmd,continue_prompt)
924 911 return newcmd
925 912
926 913
@@ -947,7 +934,6 b' class HelpHandler(PrefilterHandler):'
947 934 line = line[1:]
948 935 elif line[-1]==ESC_HELP:
949 936 line = line[:-1]
950 self.shell.log(line, '#?'+line, line_info.continue_prompt)
951 937 if line:
952 938 #print 'line:<%r>' % line # dbg
953 939 self.shell.magic_pinfo(line)
@@ -571,7 +571,7 b' class IPythonApp(Application):'
571 571 try:
572 572 self.log.info("Running code in user namespace: %s" %
573 573 line)
574 self.shell.runlines(line)
574 self.shell.run_cell(line)
575 575 except:
576 576 self.log.warn("Error in executing line in user "
577 577 "namespace: %s" % line)
@@ -616,7 +616,7 b' class IPythonApp(Application):'
616 616 try:
617 617 self.log.info("Running code given at command line (-c): %s" %
618 618 line)
619 self.shell.runlines(line)
619 self.shell.run_cell(line)
620 620 except:
621 621 self.log.warn("Error in executing line in user namespace: %s" %
622 622 line)
@@ -248,7 +248,7 b' class Demo(object):'
248 248 self.ip_ns = ip.user_ns
249 249 self.ip_colorize = ip.pycolorize
250 250 self.ip_showtb = ip.showtraceback
251 self.ip_runlines = ip.runlines
251 self.ip_run_cell = ip.run_cell
252 252 self.shell = ip
253 253
254 254 # load user data and initialize data structures
@@ -411,7 +411,7 b' class Demo(object):'
411 411 print >>IPython.utils.io.Term.cout, block,
412 412 sys.stdout.flush()
413 413
414 def runlines(self,source):
414 def run_cell(self,source):
415 415 """Execute a string with one or more lines of code"""
416 416
417 417 exec source in self.user_ns
@@ -449,7 +449,7 b' class Demo(object):'
449 449 try:
450 450 save_argv = sys.argv
451 451 sys.argv = self.sys_argv
452 self.runlines(next_block)
452 self.run_cell(next_block)
453 453 self.post_cmd()
454 454 finally:
455 455 sys.argv = save_argv
@@ -496,10 +496,10 b' class IPythonDemo(Demo):'
496 496 class requires the input to be valid, pure Python code.
497 497 """
498 498
499 def runlines(self,source):
499 def run_cell(self,source):
500 500 """Execute a string with one or more lines of code"""
501 501
502 self.shell.runlines(source)
502 self.shell.run_cell(source)
503 503
504 504 class LineDemo(Demo):
505 505 """Demo where each line is executed as a separate block.
@@ -214,14 +214,8 b' class Kernel(Configurable):'
214 214 # statements in that code will obviously still execute.
215 215 shell.runcode(code)
216 216 else:
217 # FIXME: runlines calls the exception handler itself.
217 # FIXME: the shell calls the exception handler itself.
218 218 shell._reply_content = None
219
220 # For now leave this here until we're sure we can stop using it
221 #shell.runlines(code)
222
223 # Experimental: cell mode! Test more before turning into
224 # default and removing the hacks around runlines.
225 219 shell.run_cell(code)
226 220 except:
227 221 status = u'error'
General Comments 0
You need to be logged in to leave comments. Login now