diff --git a/IPython/Debugger.py b/IPython/Debugger.py index 7ff50b6..1afdc4e 100644 --- a/IPython/Debugger.py +++ b/IPython/Debugger.py @@ -15,7 +15,7 @@ details on the PSF (Python Software Foundation) standard license, see: http://www.python.org/2.2.3/license.html -$Id: Debugger.py 1786 2006-09-27 05:47:28Z fperez $""" +$Id: Debugger.py 1787 2006-09-27 06:56:29Z fperez $""" #***************************************************************************** # @@ -65,63 +65,14 @@ def _file_lines(fname): class Pdb(pdb.Pdb): """Modified Pdb class, does not load readline.""" - # Ugly hack: we can't call the parent constructor, because it binds - # readline and breaks tab-completion. This means we have to COPY the - # constructor here, and that requires tracking various python versions. - - if sys.version[:3] == '2.5': + if sys.version[:3] >= '2.5': def __init__(self,color_scheme='NoColor',completekey=None, stdin=None, stdout=None): - bdb.Bdb.__init__(self) - - # IPython change - # don't load readline - cmd.Cmd.__init__(self,completekey,stdin,stdout) - #cmd.Cmd.__init__(self, completekey, stdin, stdout) - # /IPython change - - if stdout: - self.use_rawinput = 0 - self.prompt = '(Pdb) ' - self.aliases = {} - self.mainpyfile = '' - self._wait_for_mainpyfile = 0 - # Try to load readline if it exists - try: - import readline - except ImportError: - pass - - # Read $HOME/.pdbrc and ./.pdbrc - self.rcLines = [] - if 'HOME' in os.environ: - envHome = os.environ['HOME'] - try: - rcFile = open(os.path.join(envHome, ".pdbrc")) - except IOError: - pass - else: - for line in rcFile.readlines(): - self.rcLines.append(line) - rcFile.close() - try: - rcFile = open(".pdbrc") - except IOError: - pass - else: - for line in rcFile.readlines(): - self.rcLines.append(line) - rcFile.close() - - self.commands = {} # associates a command list to breakpoint numbers - self.commands_doprompt = {} # for each bp num, tells if the prompt must be disp. after execing the cmd list - self.commands_silent = {} # for each bp num, tells if the stack trace must be disp. after execing the cmd list - self.commands_defining = False # True while in the process of defining a command list - self.commands_bnum = None # The breakpoint number for which we are defining a list - + # Parent constructor: + pdb.Pdb.__init__(self,completekey,stdin,stdout) + # IPython changes... - self.prompt = 'ipdb> ' # The default prompt is '(Pdb)' self.aliases = {} @@ -143,10 +94,11 @@ class Pdb(pdb.Pdb): cst['LightBG'].colors.breakpoint_disabled = C.Red self.set_colors(color_scheme) - else: - + # Ugly hack: for Python 2.3-2.4, we can't call the parent constructor, + # because it binds readline and breaks tab-completion. This means we + # have to COPY the constructor here. def __init__(self,color_scheme='NoColor'): bdb.Bdb.__init__(self) cmd.Cmd.__init__(self,completekey=None) # don't load readline diff --git a/IPython/Magic.py b/IPython/Magic.py index ae5c2b2..4500c53 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 1386 2006-07-08 09:32:30Z vivainio $""" +$Id: Magic.py 1787 2006-09-27 06:56:29Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -2198,11 +2198,12 @@ Currently the magic system has the following functions:\n""" import IPython.rlineimpl as readline if not readline.have_readline: msg = """\ -Proper color support under MS Windows requires Gary Bishop's readline library. +Proper color support under MS Windows requires the pyreadline library. You can find it at: -http://sourceforge.net/projects/uncpythontools +http://ipython.scipy.org/moin/PyReadline/Intro Gary's readline needs the ctypes module, from: http://starship.python.net/crew/theller/ctypes +(Note that ctypes is already part of Python versions 2.5 and newer). Defaulting color scheme to 'NoColor'""" new_scheme = 'NoColor' diff --git a/IPython/iplib.py b/IPython/iplib.py index 8b5ab46..d379b4e 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 1786 2006-09-27 05:47:28Z fperez $ +$Id: iplib.py 1787 2006-09-27 06:56:29Z fperez $ """ #***************************************************************************** @@ -219,6 +219,12 @@ class InteractiveShell(object,Magic): # Default name given in compilation of code self.filename = '' + # Install our own quitter instead of the builtins. For python2.3-2.4, + # this brings in behavior more like 2.5, and for 2.5 it's almost + # identical to Python's official behavior (except we lack the message, + # but with autocall the need for that is much less). + __builtin__.exit = __builtin__.quit = self.exit + # Make an empty namespace, which extension writers can rely on both # existing and NEVER being used by ipython itself. This gives them a # convenient location for storing additional information and state @@ -1801,14 +1807,7 @@ want to merge them back into the new files.""" % locals() continuation in a sequence of inputs. """ - try: - line = raw_input_original(prompt) - except ValueError: - # python 2.5 closes stdin on exit -> ValueError - # xxx should we delete 'exit' and 'quit' from builtin? - self.exit_now = True - return '' - + line = raw_input_original(prompt) # Try to be reasonably smart about not re-indenting pasted input more # than necessary. We do this by trimming out the auto-indent initial @@ -2252,7 +2251,6 @@ want to merge them back into the new files.""" % locals() self.exit_now = True else: self.exit_now = True - return self.exit_now def safe_execfile(self,fname,*where,**kw): fname = os.path.expanduser(fname) diff --git a/IPython/irunner.py b/IPython/irunner.py index 5ebc6ea..6b38780 100755 --- a/IPython/irunner.py +++ b/IPython/irunner.py @@ -235,28 +235,6 @@ class PythonRunner(InteractiveRunner): InteractiveRunner.__init__(self,program,prompts,args) -class DocTestRunner(PythonRunner): - """A python runner customized for doctest usage.""" - - def run_source(self,source,interact=False): - """Run the given source code interactively. - - See the parent docstring for details. - """ - - # if the source is a string, chop it up in lines so we can iterate - # over it just as if it were an open file. - if not isinstance(source,file): - source = source.splitlines(True) - - - for line in source: - pass - # finish by calling the parent run_source method - super(DocTestRunner,self).run_source(dsource,interact) - - - class SAGERunner(InteractiveRunner): """Interactive SAGE runner. diff --git a/IPython/ultraTB.py b/IPython/ultraTB.py index 2cf0a24..5455086 100644 --- a/IPython/ultraTB.py +++ b/IPython/ultraTB.py @@ -60,7 +60,7 @@ You can implement other color schemes easily, the syntax is fairly self-explanatory. Please send back new schemes you develop to the author for possible inclusion in future releases. -$Id: ultraTB.py 1786 2006-09-27 05:47:28Z fperez $""" +$Id: ultraTB.py 1787 2006-09-27 06:56:29Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Nathaniel Gray @@ -204,10 +204,14 @@ class TBTools: def set_colors(self,*args,**kw): """Shorthand access to the color table scheme selector method.""" - + + # Set own color table self.color_scheme_table.set_active_scheme(*args,**kw) # for convenience, set Colors to the active scheme self.Colors = self.color_scheme_table.active_colors + # Also set colors of debugger + if hasattr(self,'pdb') and self.pdb is not None: + self.pdb.set_colors(*args,**kw) def color_toggle(self): """Toggle between the currently active color scheme and NoColor.""" @@ -692,7 +696,7 @@ class VerboseTB(TBTools): etb = etb.tb_next self.pdb.botframe = etb.tb_frame self.pdb.interaction(self.tb.tb_frame, self.tb) - except 'ha': # dbg + except: print '*** ERROR ***' print 'This version of pdb has a bug and crashed.' print 'Returning to IPython...' diff --git a/doc/ChangeLog b/doc/ChangeLog index bd826ef..a2bbe9f 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,21 @@ +2006-09-27 Fernando Perez + + * IPython/irunner.py (InteractiveRunner.run_source): small fixes + to help in handling doctests. irunner is now pretty useful for + running standalone scripts and simulate a full interactive session + in a format that can be then pasted as a doctest. + + * IPython/iplib.py (InteractiveShell.__init__): Install exit/quit + on top of the default (useless) ones. This also fixes the nasty + way in which 2.5's Quitter() exits (reverted [1785]). + + * IPython/Debugger.py (Pdb.__init__): Fix ipdb to work with python + 2.5. + + * IPython/ultraTB.py (TBTools.set_colors): Make sure that ipdb + color scheme is updated as well when color scheme is changed + interactively. + 2006-09-27 Ville Vainio * iplib.py (raw_input): python 2.5 closes stdin on quit -> avoid