diff --git a/IPython/Logger.py b/IPython/Logger.py index d854425..b2defcd 100644 --- a/IPython/Logger.py +++ b/IPython/Logger.py @@ -2,7 +2,7 @@ """ Logger class for IPython's logging facilities. -$Id: Logger.py 974 2005-12-29 19:48:33Z fperez $ +$Id: Logger.py 984 2005-12-31 08:40:31Z fperez $ """ #***************************************************************************** @@ -181,6 +181,7 @@ which already exists. But you must first start the logging process with self._i00 = line+'\n' #print 'Logging input:<%s>' % line # dbg input_hist.append(self._i00) + #print '---[%s]' % (len(input_hist)-1,) # dbg # hackish access to top-level namespace to create _i1,_i2... dynamically to_main = {'_i':self._i,'_ii':self._ii,'_iii':self._iii} @@ -191,6 +192,12 @@ which already exists. But you must first start the logging process with # get resumed. while in_num >= len(input_hist): input_hist.append('\n') + # but if the opposite is true (a macro can produce multiple inputs + # with no output display called), then bring the output counter in + # sync: + last_num = len(input_hist)-1 + if in_num != last_num: + in_num = self.shell.outputcache.prompt_count = last_num new_i = '_i%s' % in_num if continuation: self._i00 = '%s%s\n' % (self.shell.user_ns[new_i],line) diff --git a/IPython/Magic.py b/IPython/Magic.py index 14cd5ce..8c969ad 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 975 2005-12-29 23:50:22Z fperez $""" +$Id: Magic.py 984 2005-12-31 08:40:31Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -451,17 +451,19 @@ Currently the magic system has the following functions:\n""" This feature is only available if numbered prompts are in use.""" - if not self.shell.outputcache.do_full_cache: + shell = self.shell + if not shell.outputcache.do_full_cache: print 'This feature is only available if numbered prompts are in use.' return opts,args = self.parse_options(parameter_s,'n',mode='list') + input_hist = shell.input_hist default_length = 40 if len(args) == 0: - final = self.shell.outputcache.prompt_count + final = len(input_hist) init = max(1,final-default_length) elif len(args) == 1: - final = self.shell.outputcache.prompt_count + final = len(input_hist) init = max(1,final-int(args[0])) elif len(args) == 2: init,final = map(int,args) @@ -471,18 +473,13 @@ Currently the magic system has the following functions:\n""" return width = len(str(final)) line_sep = ['','\n'] - input_hist = self.shell.input_hist print_nums = not opts.has_key('n') for in_num in range(init,final): inline = input_hist[in_num] - multiline = inline.count('\n') > 1 + multiline = int(inline.count('\n') > 1) if print_nums: - print str(in_num).ljust(width)+':'+ line_sep[multiline], - if inline.startswith('#'+self.shell.ESC_MAGIC) or \ - inline.startswith('#!'): - print inline[1:], - else: - print inline, + print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]), + print inline, def magic_hist(self, parameter_s=''): """Alternate name for %history.""" @@ -1356,7 +1353,13 @@ Currently the magic system has the following functions:\n""" name = '__main__' prog_ns = {'__name__':name} - # pickle fix. See iplib for an explanation + # pickle fix. See iplib for an explanation. But we need to make sure + # that, if we overwrite __main__, we replace it at the end + if prog_ns['__name__'] == '__main__': + restore_main = sys.modules['__main__'] + else: + restore_main = False + sys.modules[prog_ns['__name__']] = FakeModule(prog_ns) stats = None @@ -1444,6 +1447,8 @@ Currently the magic system has the following functions:\n""" self.shell.user_ns.update(prog_ns) finally: sys.argv = save_argv + if restore_main: + sys.modules['__main__'] = restore_main return stats def magic_runlog(self, parameter_s =''): diff --git a/IPython/Release.py b/IPython/Release.py index dc075d5..692da90 100644 --- a/IPython/Release.py +++ b/IPython/Release.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Release data for the IPython project. -$Id: Release.py 982 2005-12-30 23:57:07Z fperez $""" +$Id: Release.py 984 2005-12-31 08:40:31Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2005 Fernando Perez @@ -22,9 +22,9 @@ name = 'ipython' # because bdist_rpm does not accept dashes (an RPM) convention, and # bdist_deb does not accept underscores (a Debian convention). -version = '0.7.0.rc3' +version = '0.7.0.rc4' -revision = '$Revision: 982 $' +revision = '$Revision: 984 $' description = "An enhanced interactive Python shell." diff --git a/IPython/iplib.py b/IPython/iplib.py index fe24d2e..e2e92f4 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.1 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 983 2005-12-31 00:04:25Z fperez $ +$Id: iplib.py 984 2005-12-31 08:40:31Z fperez $ """ #***************************************************************************** @@ -237,7 +237,7 @@ class SyntaxTB(ultraTB.ListTB): # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell', # 'self.value'] -class InteractiveShell(Magic): +class InteractiveShell(object,Magic): """An enhanced console for Python.""" # class attribute to indicate whether the class supports threads or not. @@ -388,6 +388,7 @@ class InteractiveShell(Magic): raise KeyError,'user_ns dictionary MUST have a "__name__" key' else: #print "pickle hack in place" # dbg + #print 'main_name:',main_name # dbg sys.modules[main_name] = FakeModule(self.user_ns) # List of input with multi-line handling. @@ -717,10 +718,7 @@ class InteractiveShell(Magic): self.user_ns[key] = obj - - - - + def set_hook(self,name,hook): """set_hook(name,hook) -> sets an internal IPython hook. diff --git a/doc/ChangeLog b/doc/ChangeLog index 4c7ec9a..21159a0 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,31 @@ +2005-12-31 Fernando Perez + + * IPython/Logger.py (Logger.log): fix a history handling bug. I + don't know if this is the end of it, but the behavior now is + certainly much more correct. Note that coupled with macros, + slightly surprising (at first) behavior may occur: a macro will in + general expand to multiple lines of input, so upon exiting, the + in/out counters will both be bumped by the corresponding amount + (as if the macro's contents had been typed interactively). Typing + %hist will reveal the intermediate (silently processed) lines. + + * IPython/Magic.py (magic_run): fix a subtle bug which could cause + pickle to fail (%run was overwriting __main__ and not restoring + it, but pickle relies on __main__ to operate). + + * IPython/iplib.py (InteractiveShell): fix pdb calling: I'm now + using properties, but forgot to make the main InteractiveShell + class a new-style class. Properties fail silently, and + misteriously, with old-style class (getters work, but + setters don't do anything). + 2005-12-30 Fernando Perez + * IPython/Magic.py (magic_history): fix history reporting bug (I + know some nasties are still there, I just can't seem to find a + reproducible test case to track them down; the input history is + falling out of sync...) + * IPython/iplib.py (handle_shell_escape): fix bug where both aliases and system accesses where broken for indented code (such as loops).