diff --git a/IPython/Shell.py b/IPython/Shell.py index 1ff03f0..462a85c 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -4,7 +4,7 @@ All the matplotlib support code was co-developed with John Hunter, matplotlib's author. -$Id: Shell.py 2151 2007-03-18 01:17:00Z fperez $""" +$Id: Shell.py 2156 2007-03-19 02:32:19Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez @@ -446,8 +446,7 @@ class MatplotlibShellBase: user_ns = IPython.ipapi.make_user_ns(user_ns) exec ("import matplotlib\n" - "import matplotlib.pylab as pylab\n" - "from matplotlib.pylab import *") in user_ns + "import matplotlib.pylab as pylab\n") in user_ns # Build matplotlib info banner b=""" @@ -931,6 +930,17 @@ class IPShellQt4(threading.Thread): # A set of matplotlib public IPython shell classes, for single-threaded # (Tk* and FLTK* backends) and multithreaded (GTK* and WX* backends) use. +def _load_pylab(user_ns): + """Allow users to disable pulling all of pylab into the top-level + namespace. + + This little utility must be called AFTER the actual ipython instance is + running, since only then will the options file have been fully parsed.""" + + ip = IPython.ipapi.get() + if ip.options.pylab_import_all: + exec "from matplotlib.pylab import *" in user_ns + class IPShellMatplotlib(IPShell): """Subclass IPShell with MatplotlibShell as the internal shell. @@ -941,6 +951,7 @@ class IPShellMatplotlib(IPShell): def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): IPShell.__init__(self,argv,user_ns,user_global_ns,debug, shell_class=MatplotlibShell) + _load_pylab(user_ns) class IPShellMatplotlibGTK(IPShellGTK): """Subclass IPShellGTK with MatplotlibMTShell as the internal shell. @@ -950,6 +961,7 @@ class IPShellMatplotlibGTK(IPShellGTK): def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): IPShellGTK.__init__(self,argv,user_ns,user_global_ns,debug, shell_class=MatplotlibMTShell) + _load_pylab(user_ns) class IPShellMatplotlibWX(IPShellWX): """Subclass IPShellWX with MatplotlibMTShell as the internal shell. @@ -959,6 +971,7 @@ class IPShellMatplotlibWX(IPShellWX): def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): IPShellWX.__init__(self,argv,user_ns,user_global_ns,debug, shell_class=MatplotlibMTShell) + _load_pylab(user_ns) class IPShellMatplotlibQt(IPShellQt): """Subclass IPShellQt with MatplotlibMTShell as the internal shell. @@ -968,6 +981,7 @@ class IPShellMatplotlibQt(IPShellQt): def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): IPShellQt.__init__(self,argv,user_ns,user_global_ns,debug, shell_class=MatplotlibMTShell) + _load_pylab(user_ns) class IPShellMatplotlibQt4(IPShellQt4): """Subclass IPShellQt4 with MatplotlibMTShell as the internal shell. @@ -977,6 +991,7 @@ class IPShellMatplotlibQt4(IPShellQt4): def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): IPShellQt4.__init__(self,argv,user_ns,user_global_ns,debug, shell_class=MatplotlibMTShell) + _load_pylab(user_ns) #----------------------------------------------------------------------------- # Factory functions to actually start the proper thread-aware shell diff --git a/IPython/UserConfig/ipythonrc b/IPython/UserConfig/ipythonrc index 0764828..6f2efb7 100644 --- a/IPython/UserConfig/ipythonrc +++ b/IPython/UserConfig/ipythonrc @@ -1,5 +1,5 @@ # -*- Mode: Shell-Script -*- Not really, but shows comments correctly -# $Id: ipythonrc 1979 2006-12-12 18:50:20Z vivainio $ +# $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $ #*************************************************************************** # @@ -258,6 +258,15 @@ prompt_out 'Out[\#]: ' # the output prompts will be unpadded (flush left). prompts_pad_left 1 +# Pylab support: when ipython is started with the -pylab switch, by default it +# executes 'from matplotlib.pylab import *'. Set this variable to false if you +# want to disable this behavior. + +# For details on pylab, see the matplotlib website: +# http://matplotlib.sf.net +pylab_import_all 1 + + # quick 1 -> same as ipython -quick quick 0 diff --git a/IPython/ipmaker.py b/IPython/ipmaker.py index d050579..204c8c6 100644 --- a/IPython/ipmaker.py +++ b/IPython/ipmaker.py @@ -6,7 +6,7 @@ Requires Python 2.1 or better. This file contains the main make_IPython() starter function. -$Id: ipmaker.py 2093 2007-02-09 21:28:58Z fperez $""" +$Id: ipmaker.py 2156 2007-03-19 02:32:19Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -159,6 +159,7 @@ object? -> Details about 'object'. ?object also works, ?? prints more. 'debug! deep_reload! editor=s log|l messages! nosep ' 'object_info_string_level=i pdb! ' 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s ' + 'pylab_import_all! ' 'quick screen_length|sl=i prompts_pad_left=i ' 'logfile|lf=s logplay|lp=s profile|p=s ' 'readline! readline_merge_completions! ' @@ -213,6 +214,7 @@ object? -> Details about 'object'. ?object also works, ?? prints more. prompt_in2 = ' .\\D.: ', prompt_out = 'Out[\\#]: ', prompts_pad_left = 1, + pylab_import_all = 1, quiet = 0, quick = 0, readline = 1, diff --git a/IPython/ultraTB.py b/IPython/ultraTB.py index f4945e1..61bf97e 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 2155 2007-03-19 00:45:51Z fperez $""" +$Id: ultraTB.py 2156 2007-03-19 02:32:19Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Nathaniel Gray @@ -103,7 +103,7 @@ INDENT_SIZE = 8 # formatter. When running in an actual IPython instance, the user's rc.colors # value is used, but havinga module global makes this functionality available # to users of ultraTB who are NOT running inside ipython. -DEFAULT_SCHEME = 'NoColors' +DEFAULT_SCHEME = 'NoColor' #--------------------------------------------------------------------------- # Code begins @@ -160,16 +160,17 @@ def _fixed_getinnerframes(etb, context=1,tb_offset=0): _parser = PyColorize.Parser() -def _formatTracebackLines(lnum, index, lines, Colors, lvals=None): +def _formatTracebackLines(lnum, index, lines, Colors, lvals=None,scheme=None): numbers_width = INDENT_SIZE - 1 res = [] i = lnum - index # This lets us get fully syntax-highlighted tracebacks. - try: - scheme = __IPYTHON__.rc.colors - except: - scheme = DEFAULT_SCHEME + if scheme is None: + try: + scheme = __IPYTHON__.rc.colors + except: + scheme = DEFAULT_SCHEME _line_format = _parser.format2 for line in lines: @@ -420,6 +421,7 @@ class VerboseTB(TBTools): # some locals Colors = self.Colors # just a shorthand + quicker name lookup ColorsNormal = Colors.Normal # used a lot + col_scheme = self.color_scheme_table.active_scheme_name indent = ' '*INDENT_SIZE exc = '%s%s%s' % (Colors.excName, str(etype), ColorsNormal) em_normal = '%s\n%s%s' % (Colors.valEm, indent,ColorsNormal) @@ -658,7 +660,8 @@ class VerboseTB(TBTools): frames.append(level) else: frames.append('%s%s' % (level,''.join( - _formatTracebackLines(lnum,index,lines,self.Colors,lvals)))) + _formatTracebackLines(lnum,index,lines,Colors,lvals, + col_scheme)))) # Get (safely) a string form of the exception info try: diff --git a/doc/ChangeLog b/doc/ChangeLog index 1293c51..1909f05 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,10 @@ 2007-03-18 Fernando Perez + * IPython/Shell.py (_load_pylab): Make the execution of 'from + pylab import *' when -pylab is given be optional. A new flag, + pylab_import_all controls this behavior, the default is True for + backwards compatibility. + * IPython/ultraTB.py (_formatTracebackLines): Added (slightly modified) R. Bernstein's patch for fully syntax highlighted tracebacks. The functionality is also available under ultraTB for