##// END OF EJS Templates
Manual updates
fperez -
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,725 +1,727 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 IPython -- An enhanced Interactive Python
3 IPython -- An enhanced Interactive Python
4
4
5 Requires Python 2.1 or better.
5 Requires Python 2.1 or better.
6
6
7 This file contains the main make_IPython() starter function.
7 This file contains the main make_IPython() starter function.
8
8
9 $Id: ipmaker.py 802 2005-09-06 03:49:12Z fperez $"""
9 $Id: ipmaker.py 911 2005-10-08 07:59:40Z fperez $"""
10
10
11 #*****************************************************************************
11 #*****************************************************************************
12 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
12 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
13 #
13 #
14 # Distributed under the terms of the BSD License. The full license is in
14 # Distributed under the terms of the BSD License. The full license is in
15 # the file COPYING, distributed as part of this software.
15 # the file COPYING, distributed as part of this software.
16 #*****************************************************************************
16 #*****************************************************************************
17
17
18 from IPython import Release
18 from IPython import Release
19 __author__ = '%s <%s>' % Release.authors['Fernando']
19 __author__ = '%s <%s>' % Release.authors['Fernando']
20 __license__ = Release.license
20 __license__ = Release.license
21 __version__ = Release.version
21 __version__ = Release.version
22
22
23 credits._Printer__data = """
23 credits._Printer__data = """
24 Python: %s
24 Python: %s
25
25
26 IPython: Fernando Perez, Janko Hauser, Nathan Gray, and many users.
26 IPython: Fernando Perez, Janko Hauser, Nathan Gray, and many users.
27 See http://ipython.scipy.org for more information.""" \
27 See http://ipython.scipy.org for more information.""" \
28 % credits._Printer__data
28 % credits._Printer__data
29
29
30 copyright._Printer__data += """
30 copyright._Printer__data += """
31
31
32 Copyright (c) 2001-2004 Fernando Perez, Janko Hauser, Nathan Gray.
32 Copyright (c) 2001-2004 Fernando Perez, Janko Hauser, Nathan Gray.
33 All Rights Reserved."""
33 All Rights Reserved."""
34
34
35 #****************************************************************************
35 #****************************************************************************
36 # Required modules
36 # Required modules
37
37
38 # From the standard library
38 # From the standard library
39 import __main__, __builtin__
39 import __main__, __builtin__
40 import os,sys,types,re
40 import os,sys,types,re
41 from pprint import pprint,pformat
41 from pprint import pprint,pformat
42
42
43 # Our own
43 # Our own
44 from IPython import DPyGetOpt
44 from IPython import DPyGetOpt
45 from IPython.Struct import Struct
45 from IPython.Struct import Struct
46 from IPython.OutputTrap import OutputTrap
46 from IPython.OutputTrap import OutputTrap
47 from IPython.ConfigLoader import ConfigLoader
47 from IPython.ConfigLoader import ConfigLoader
48 from IPython.iplib import InteractiveShell,qw_lol,import_fail_info
48 from IPython.iplib import InteractiveShell,qw_lol,import_fail_info
49 from IPython.usage import cmd_line_usage,interactive_usage
49 from IPython.usage import cmd_line_usage,interactive_usage
50 from IPython.Prompts import CachedOutput
50 from IPython.Prompts import CachedOutput
51 from IPython.genutils import *
51 from IPython.genutils import *
52
52
53 #-----------------------------------------------------------------------------
53 #-----------------------------------------------------------------------------
54 def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None,
54 def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None,
55 shell_class=InteractiveShell,embedded=False,**kw):
55 shell_class=InteractiveShell,embedded=False,**kw):
56 """This is a dump of IPython into a single function.
56 """This is a dump of IPython into a single function.
57
57
58 Later it will have to be broken up in a sensible manner.
58 Later it will have to be broken up in a sensible manner.
59
59
60 Arguments:
60 Arguments:
61
61
62 - argv: a list similar to sys.argv[1:]. It should NOT contain the desired
62 - argv: a list similar to sys.argv[1:]. It should NOT contain the desired
63 script name, b/c DPyGetOpt strips the first argument only for the real
63 script name, b/c DPyGetOpt strips the first argument only for the real
64 sys.argv.
64 sys.argv.
65
65
66 - user_ns: a dict to be used as the user's namespace."""
66 - user_ns: a dict to be used as the user's namespace."""
67
67
68 #----------------------------------------------------------------------
68 #----------------------------------------------------------------------
69 # Defaults and initialization
69 # Defaults and initialization
70
70
71 # For developer debugging, deactivates crash handler and uses pdb.
71 # For developer debugging, deactivates crash handler and uses pdb.
72 DEVDEBUG = False
72 DEVDEBUG = False
73
73
74 if argv is None:
74 if argv is None:
75 argv = sys.argv
75 argv = sys.argv
76
76
77 # __IP is the main global that lives throughout and represents the whole
77 # __IP is the main global that lives throughout and represents the whole
78 # application. If the user redefines it, all bets are off as to what
78 # application. If the user redefines it, all bets are off as to what
79 # happens.
79 # happens.
80
80
81 # __IP is the name of he global which the caller will have accessible as
81 # __IP is the name of he global which the caller will have accessible as
82 # __IP.name. We set its name via the first parameter passed to
82 # __IP.name. We set its name via the first parameter passed to
83 # InteractiveShell:
83 # InteractiveShell:
84
84
85 IP = shell_class('__IP',user_ns=user_ns,**kw)
85 IP = shell_class('__IP',user_ns=user_ns,**kw)
86
86
87 # Put 'help' in the user namespace
87 # Put 'help' in the user namespace
88 from site import _Helper
88 from site import _Helper
89 IP.user_ns['help'] = _Helper()
89 IP.user_ns['help'] = _Helper()
90
90
91 if DEVDEBUG:
91 if DEVDEBUG:
92 # For developer debugging only (global flag)
92 # For developer debugging only (global flag)
93 from IPython import ultraTB
93 from IPython import ultraTB
94 sys.excepthook = ultraTB.VerboseTB(call_pdb=1)
94 sys.excepthook = ultraTB.VerboseTB(call_pdb=1)
95 else:
95 else:
96 # IPython itself shouldn't crash. This will produce a detailed
96 # IPython itself shouldn't crash. This will produce a detailed
97 # post-mortem if it does
97 # post-mortem if it does
98 from IPython import CrashHandler
98 from IPython import CrashHandler
99 sys.excepthook = CrashHandler.CrashHandler(IP)
99 sys.excepthook = CrashHandler.CrashHandler(IP)
100
100
101 IP.BANNER_PARTS = ['Python %s\n'
101 IP.BANNER_PARTS = ['Python %s\n'
102 'Type "copyright", "credits" or "license" '
102 'Type "copyright", "credits" or "license" '
103 'for more information.\n'
103 'for more information.\n'
104 % (sys.version.split('\n')[0],),
104 % (sys.version.split('\n')[0],),
105 "IPython %s -- An enhanced Interactive Python."
105 "IPython %s -- An enhanced Interactive Python."
106 % (__version__,),
106 % (__version__,),
107 """? -> Introduction to IPython's features.
107 """? -> Introduction to IPython's features.
108 %magic -> Information about IPython's 'magic' % functions.
108 %magic -> Information about IPython's 'magic' % functions.
109 help -> Python's own help system.
109 help -> Python's own help system.
110 object? -> Details about 'object'. ?object also works, ?? prints more.
110 object? -> Details about 'object'. ?object also works, ?? prints more.
111 """ ]
111 """ ]
112
112
113 IP.usage = interactive_usage
113 IP.usage = interactive_usage
114
114
115 # Platform-dependent suffix and directory names
115 # Platform-dependent suffix and directory names. We use _ipython instead
116 # of .ipython under win32 b/c there's software that breaks with .named
117 # directories on that platform.
116 if os.name == 'posix':
118 if os.name == 'posix':
117 rc_suffix = ''
119 rc_suffix = ''
118 ipdir_def = '.ipython'
120 ipdir_def = '.ipython'
119 else:
121 else:
120 rc_suffix = '.ini'
122 rc_suffix = '.ini'
121 ipdir_def = '_ipython'
123 ipdir_def = '_ipython'
122
124
123 # default directory for configuration
125 # default directory for configuration
124 ipythondir = os.path.abspath(os.environ.get('IPYTHONDIR',
126 ipythondir = os.path.abspath(os.environ.get('IPYTHONDIR',
125 os.path.join(IP.home_dir,ipdir_def)))
127 os.path.join(IP.home_dir,ipdir_def)))
126
128
127 # we need the directory where IPython itself is installed
129 # we need the directory where IPython itself is installed
128 import IPython
130 import IPython
129 IPython_dir = os.path.dirname(IPython.__file__)
131 IPython_dir = os.path.dirname(IPython.__file__)
130 del IPython
132 del IPython
131
133
132 #-------------------------------------------------------------------------
134 #-------------------------------------------------------------------------
133 # Command line handling
135 # Command line handling
134
136
135 # Valid command line options (uses DPyGetOpt syntax, like Perl's
137 # Valid command line options (uses DPyGetOpt syntax, like Perl's
136 # GetOpt::Long)
138 # GetOpt::Long)
137
139
138 # Any key not listed here gets deleted even if in the file (like session
140 # Any key not listed here gets deleted even if in the file (like session
139 # or profile). That's deliberate, to maintain the rc namespace clean.
141 # or profile). That's deliberate, to maintain the rc namespace clean.
140
142
141 # Each set of options appears twice: under _conv only the names are
143 # Each set of options appears twice: under _conv only the names are
142 # listed, indicating which type they must be converted to when reading the
144 # listed, indicating which type they must be converted to when reading the
143 # ipythonrc file. And under DPyGetOpt they are listed with the regular
145 # ipythonrc file. And under DPyGetOpt they are listed with the regular
144 # DPyGetOpt syntax (=s,=i,:f,etc).
146 # DPyGetOpt syntax (=s,=i,:f,etc).
145
147
146 # Make sure there's a space before each end of line (they get auto-joined!)
148 # Make sure there's a space before each end of line (they get auto-joined!)
147 cmdline_opts = ('autocall! autoindent! automagic! banner! cache_size|cs=i '
149 cmdline_opts = ('autocall! autoindent! automagic! banner! cache_size|cs=i '
148 'c=s classic|cl color_info! colors=s confirm_exit! '
150 'c=s classic|cl color_info! colors=s confirm_exit! '
149 'debug! deep_reload! editor=s log|l messages! nosep pdb! '
151 'debug! deep_reload! editor=s log|l messages! nosep pdb! '
150 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s '
152 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s '
151 'quick screen_length|sl=i prompts_pad_left=i '
153 'quick screen_length|sl=i prompts_pad_left=i '
152 'logfile|lf=s logplay|lp=s profile|p=s '
154 'logfile|lf=s logplay|lp=s profile|p=s '
153 'readline! readline_merge_completions! '
155 'readline! readline_merge_completions! '
154 'readline_omit__names! '
156 'readline_omit__names! '
155 'rcfile=s separate_in|si=s separate_out|so=s '
157 'rcfile=s separate_in|si=s separate_out|so=s '
156 'separate_out2|so2=s xmode=s '
158 'separate_out2|so2=s xmode=s '
157 'magic_docstrings system_verbose! '
159 'magic_docstrings system_verbose! '
158 'multi_line_specials!')
160 'multi_line_specials!')
159
161
160 # Options that can *only* appear at the cmd line (not in rcfiles).
162 # Options that can *only* appear at the cmd line (not in rcfiles).
161
163
162 # The "ignore" option is a kludge so that Emacs buffers don't crash, since
164 # The "ignore" option is a kludge so that Emacs buffers don't crash, since
163 # the 'C-c !' command in emacs automatically appends a -i option at the end.
165 # the 'C-c !' command in emacs automatically appends a -i option at the end.
164 cmdline_only = ('help ignore|i ipythondir=s Version upgrade '
166 cmdline_only = ('help ignore|i ipythondir=s Version upgrade '
165 'gthread! qthread! wthread! pylab! tk!')
167 'gthread! qthread! wthread! pylab! tk!')
166
168
167 # Build the actual name list to be used by DPyGetOpt
169 # Build the actual name list to be used by DPyGetOpt
168 opts_names = qw(cmdline_opts) + qw(cmdline_only)
170 opts_names = qw(cmdline_opts) + qw(cmdline_only)
169
171
170 # Set sensible command line defaults.
172 # Set sensible command line defaults.
171 # This should have everything from cmdline_opts and cmdline_only
173 # This should have everything from cmdline_opts and cmdline_only
172 opts_def = Struct(autocall = 1,
174 opts_def = Struct(autocall = 1,
173 autoindent=0,
175 autoindent=0,
174 automagic = 1,
176 automagic = 1,
175 banner = 1,
177 banner = 1,
176 cache_size = 1000,
178 cache_size = 1000,
177 c = '',
179 c = '',
178 classic = 0,
180 classic = 0,
179 colors = 'NoColor',
181 colors = 'NoColor',
180 color_info = 0,
182 color_info = 0,
181 confirm_exit = 1,
183 confirm_exit = 1,
182 debug = 0,
184 debug = 0,
183 deep_reload = 0,
185 deep_reload = 0,
184 editor = '0',
186 editor = '0',
185 help = 0,
187 help = 0,
186 ignore = 0,
188 ignore = 0,
187 ipythondir = ipythondir,
189 ipythondir = ipythondir,
188 log = 0,
190 log = 0,
189 logfile = '',
191 logfile = '',
190 logplay = '',
192 logplay = '',
191 multi_line_specials = 1,
193 multi_line_specials = 1,
192 messages = 1,
194 messages = 1,
193 nosep = 0,
195 nosep = 0,
194 pdb = 0,
196 pdb = 0,
195 pprint = 0,
197 pprint = 0,
196 profile = '',
198 profile = '',
197 prompt_in1 = 'In [\\#]: ',
199 prompt_in1 = 'In [\\#]: ',
198 prompt_in2 = ' .\\D.: ',
200 prompt_in2 = ' .\\D.: ',
199 prompt_out = 'Out[\\#]: ',
201 prompt_out = 'Out[\\#]: ',
200 prompts_pad_left = 1,
202 prompts_pad_left = 1,
201 quick = 0,
203 quick = 0,
202 readline = 1,
204 readline = 1,
203 readline_merge_completions = 1,
205 readline_merge_completions = 1,
204 readline_omit__names = 0,
206 readline_omit__names = 0,
205 rcfile = 'ipythonrc' + rc_suffix,
207 rcfile = 'ipythonrc' + rc_suffix,
206 screen_length = 0,
208 screen_length = 0,
207 separate_in = '\n',
209 separate_in = '\n',
208 separate_out = '\n',
210 separate_out = '\n',
209 separate_out2 = '',
211 separate_out2 = '',
210 system_verbose = 0,
212 system_verbose = 0,
211 gthread = 0,
213 gthread = 0,
212 qthread = 0,
214 qthread = 0,
213 wthread = 0,
215 wthread = 0,
214 pylab = 0,
216 pylab = 0,
215 tk = 0,
217 tk = 0,
216 upgrade = 0,
218 upgrade = 0,
217 Version = 0,
219 Version = 0,
218 xmode = 'Verbose',
220 xmode = 'Verbose',
219 magic_docstrings = 0, # undocumented, for doc generation
221 magic_docstrings = 0, # undocumented, for doc generation
220 )
222 )
221
223
222 # Things that will *only* appear in rcfiles (not at the command line).
224 # Things that will *only* appear in rcfiles (not at the command line).
223 # Make sure there's a space before each end of line (they get auto-joined!)
225 # Make sure there's a space before each end of line (they get auto-joined!)
224 rcfile_opts = { qwflat: 'include import_mod import_all execfile ',
226 rcfile_opts = { qwflat: 'include import_mod import_all execfile ',
225 qw_lol: 'import_some ',
227 qw_lol: 'import_some ',
226 # for things with embedded whitespace:
228 # for things with embedded whitespace:
227 list_strings:'execute alias readline_parse_and_bind ',
229 list_strings:'execute alias readline_parse_and_bind ',
228 # Regular strings need no conversion:
230 # Regular strings need no conversion:
229 None:'readline_remove_delims ',
231 None:'readline_remove_delims ',
230 }
232 }
231 # Default values for these
233 # Default values for these
232 rc_def = Struct(include = [],
234 rc_def = Struct(include = [],
233 import_mod = [],
235 import_mod = [],
234 import_all = [],
236 import_all = [],
235 import_some = [[]],
237 import_some = [[]],
236 execute = [],
238 execute = [],
237 execfile = [],
239 execfile = [],
238 alias = [],
240 alias = [],
239 readline_parse_and_bind = [],
241 readline_parse_and_bind = [],
240 readline_remove_delims = '',
242 readline_remove_delims = '',
241 )
243 )
242
244
243 # Build the type conversion dictionary from the above tables:
245 # Build the type conversion dictionary from the above tables:
244 typeconv = rcfile_opts.copy()
246 typeconv = rcfile_opts.copy()
245 typeconv.update(optstr2types(cmdline_opts))
247 typeconv.update(optstr2types(cmdline_opts))
246
248
247 # FIXME: the None key appears in both, put that back together by hand. Ugly!
249 # FIXME: the None key appears in both, put that back together by hand. Ugly!
248 typeconv[None] += ' ' + rcfile_opts[None]
250 typeconv[None] += ' ' + rcfile_opts[None]
249
251
250 # Remove quotes at ends of all strings (used to protect spaces)
252 # Remove quotes at ends of all strings (used to protect spaces)
251 typeconv[unquote_ends] = typeconv[None]
253 typeconv[unquote_ends] = typeconv[None]
252 del typeconv[None]
254 del typeconv[None]
253
255
254 # Build the list we'll use to make all config decisions with defaults:
256 # Build the list we'll use to make all config decisions with defaults:
255 opts_all = opts_def.copy()
257 opts_all = opts_def.copy()
256 opts_all.update(rc_def)
258 opts_all.update(rc_def)
257
259
258 # Build conflict resolver for recursive loading of config files:
260 # Build conflict resolver for recursive loading of config files:
259 # - preserve means the outermost file maintains the value, it is not
261 # - preserve means the outermost file maintains the value, it is not
260 # overwritten if an included file has the same key.
262 # overwritten if an included file has the same key.
261 # - add_flip applies + to the two values, so it better make sense to add
263 # - add_flip applies + to the two values, so it better make sense to add
262 # those types of keys. But it flips them first so that things loaded
264 # those types of keys. But it flips them first so that things loaded
263 # deeper in the inclusion chain have lower precedence.
265 # deeper in the inclusion chain have lower precedence.
264 conflict = {'preserve': ' '.join([ typeconv[int],
266 conflict = {'preserve': ' '.join([ typeconv[int],
265 typeconv[unquote_ends] ]),
267 typeconv[unquote_ends] ]),
266 'add_flip': ' '.join([ typeconv[qwflat],
268 'add_flip': ' '.join([ typeconv[qwflat],
267 typeconv[qw_lol],
269 typeconv[qw_lol],
268 typeconv[list_strings] ])
270 typeconv[list_strings] ])
269 }
271 }
270
272
271 # Now actually process the command line
273 # Now actually process the command line
272 getopt = DPyGetOpt.DPyGetOpt()
274 getopt = DPyGetOpt.DPyGetOpt()
273 getopt.setIgnoreCase(0)
275 getopt.setIgnoreCase(0)
274
276
275 getopt.parseConfiguration(opts_names)
277 getopt.parseConfiguration(opts_names)
276
278
277 try:
279 try:
278 getopt.processArguments(argv)
280 getopt.processArguments(argv)
279 except:
281 except:
280 print cmd_line_usage
282 print cmd_line_usage
281 warn('\nError in Arguments: ' + `sys.exc_value`)
283 warn('\nError in Arguments: ' + `sys.exc_value`)
282 sys.exit()
284 sys.exit()
283
285
284 # convert the options dict to a struct for much lighter syntax later
286 # convert the options dict to a struct for much lighter syntax later
285 opts = Struct(getopt.optionValues)
287 opts = Struct(getopt.optionValues)
286 args = getopt.freeValues
288 args = getopt.freeValues
287
289
288 # this is the struct (which has default values at this point) with which
290 # this is the struct (which has default values at this point) with which
289 # we make all decisions:
291 # we make all decisions:
290 opts_all.update(opts)
292 opts_all.update(opts)
291
293
292 # Options that force an immediate exit
294 # Options that force an immediate exit
293 if opts_all.help:
295 if opts_all.help:
294 page(cmd_line_usage)
296 page(cmd_line_usage)
295 sys.exit()
297 sys.exit()
296
298
297 if opts_all.Version:
299 if opts_all.Version:
298 print __version__
300 print __version__
299 sys.exit()
301 sys.exit()
300
302
301 if opts_all.magic_docstrings:
303 if opts_all.magic_docstrings:
302 IP.magic_magic('-latex')
304 IP.magic_magic('-latex')
303 sys.exit()
305 sys.exit()
304
306
305 # Create user config directory if it doesn't exist. This must be done
307 # Create user config directory if it doesn't exist. This must be done
306 # *after* getting the cmd line options.
308 # *after* getting the cmd line options.
307 if not os.path.isdir(opts_all.ipythondir):
309 if not os.path.isdir(opts_all.ipythondir):
308 IP.user_setup(opts_all.ipythondir,rc_suffix,'install')
310 IP.user_setup(opts_all.ipythondir,rc_suffix,'install')
309
311
310 # upgrade user config files while preserving a copy of the originals
312 # upgrade user config files while preserving a copy of the originals
311 if opts_all.upgrade:
313 if opts_all.upgrade:
312 IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade')
314 IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade')
313
315
314 # check mutually exclusive options in the *original* command line
316 # check mutually exclusive options in the *original* command line
315 mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'),
317 mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'),
316 qw('classic profile'),qw('classic rcfile')])
318 qw('classic profile'),qw('classic rcfile')])
317
319
318 # default logfilename used when -log is called.
320 # default logfilename used when -log is called.
319 IP.LOGDEF = 'ipython.log'
321 IP.LOGDEF = 'ipython.log'
320
322
321 #---------------------------------------------------------------------------
323 #---------------------------------------------------------------------------
322 # Log replay
324 # Log replay
323
325
324 # if -logplay, we need to 'become' the other session. That basically means
326 # if -logplay, we need to 'become' the other session. That basically means
325 # replacing the current command line environment with that of the old
327 # replacing the current command line environment with that of the old
326 # session and moving on.
328 # session and moving on.
327
329
328 # this is needed so that later we know we're in session reload mode, as
330 # this is needed so that later we know we're in session reload mode, as
329 # opts_all will get overwritten:
331 # opts_all will get overwritten:
330 load_logplay = 0
332 load_logplay = 0
331
333
332 if opts_all.logplay:
334 if opts_all.logplay:
333 load_logplay = opts_all.logplay
335 load_logplay = opts_all.logplay
334 opts_debug_save = opts_all.debug
336 opts_debug_save = opts_all.debug
335 try:
337 try:
336 logplay = open(opts_all.logplay)
338 logplay = open(opts_all.logplay)
337 except IOError:
339 except IOError:
338 if opts_all.debug: IP.InteractiveTB()
340 if opts_all.debug: IP.InteractiveTB()
339 warn('Could not open logplay file '+`opts_all.logplay`)
341 warn('Could not open logplay file '+`opts_all.logplay`)
340 # restore state as if nothing had happened and move on, but make
342 # restore state as if nothing had happened and move on, but make
341 # sure that later we don't try to actually load the session file
343 # sure that later we don't try to actually load the session file
342 logplay = None
344 logplay = None
343 load_logplay = 0
345 load_logplay = 0
344 del opts_all.logplay
346 del opts_all.logplay
345 else:
347 else:
346 try:
348 try:
347 logplay.readline()
349 logplay.readline()
348 logplay.readline();
350 logplay.readline();
349 # this reloads that session's command line
351 # this reloads that session's command line
350 cmd = logplay.readline()[6:]
352 cmd = logplay.readline()[6:]
351 exec cmd
353 exec cmd
352 # restore the true debug flag given so that the process of
354 # restore the true debug flag given so that the process of
353 # session loading itself can be monitored.
355 # session loading itself can be monitored.
354 opts.debug = opts_debug_save
356 opts.debug = opts_debug_save
355 # save the logplay flag so later we don't overwrite the log
357 # save the logplay flag so later we don't overwrite the log
356 opts.logplay = load_logplay
358 opts.logplay = load_logplay
357 # now we must update our own structure with defaults
359 # now we must update our own structure with defaults
358 opts_all.update(opts)
360 opts_all.update(opts)
359 # now load args
361 # now load args
360 cmd = logplay.readline()[6:]
362 cmd = logplay.readline()[6:]
361 exec cmd
363 exec cmd
362 logplay.close()
364 logplay.close()
363 except:
365 except:
364 logplay.close()
366 logplay.close()
365 if opts_all.debug: IP.InteractiveTB()
367 if opts_all.debug: IP.InteractiveTB()
366 warn("Logplay file lacking full configuration information.\n"
368 warn("Logplay file lacking full configuration information.\n"
367 "I'll try to read it, but some things may not work.")
369 "I'll try to read it, but some things may not work.")
368
370
369 #-------------------------------------------------------------------------
371 #-------------------------------------------------------------------------
370 # set up output traps: catch all output from files, being run, modules
372 # set up output traps: catch all output from files, being run, modules
371 # loaded, etc. Then give it to the user in a clean form at the end.
373 # loaded, etc. Then give it to the user in a clean form at the end.
372
374
373 msg_out = 'Output messages. '
375 msg_out = 'Output messages. '
374 msg_err = 'Error messages. '
376 msg_err = 'Error messages. '
375 msg_sep = '\n'
377 msg_sep = '\n'
376 msg = Struct(config = OutputTrap('Configuration Loader',msg_out,
378 msg = Struct(config = OutputTrap('Configuration Loader',msg_out,
377 msg_err,msg_sep,debug,
379 msg_err,msg_sep,debug,
378 quiet_out=1),
380 quiet_out=1),
379 user_exec = OutputTrap('User File Execution',msg_out,
381 user_exec = OutputTrap('User File Execution',msg_out,
380 msg_err,msg_sep,debug),
382 msg_err,msg_sep,debug),
381 logplay = OutputTrap('Log Loader',msg_out,
383 logplay = OutputTrap('Log Loader',msg_out,
382 msg_err,msg_sep,debug),
384 msg_err,msg_sep,debug),
383 summary = ''
385 summary = ''
384 )
386 )
385
387
386 #-------------------------------------------------------------------------
388 #-------------------------------------------------------------------------
387 # Process user ipythonrc-type configuration files
389 # Process user ipythonrc-type configuration files
388
390
389 # turn on output trapping and log to msg.config
391 # turn on output trapping and log to msg.config
390 # remember that with debug on, trapping is actually disabled
392 # remember that with debug on, trapping is actually disabled
391 msg.config.trap_all()
393 msg.config.trap_all()
392
394
393 # look for rcfile in current or default directory
395 # look for rcfile in current or default directory
394 try:
396 try:
395 opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir)
397 opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir)
396 except IOError:
398 except IOError:
397 if opts_all.debug: IP.InteractiveTB()
399 if opts_all.debug: IP.InteractiveTB()
398 warn('Configuration file %s not found. Ignoring request.'
400 warn('Configuration file %s not found. Ignoring request.'
399 % (opts_all.rcfile) )
401 % (opts_all.rcfile) )
400
402
401 # 'profiles' are a shorthand notation for config filenames
403 # 'profiles' are a shorthand notation for config filenames
402 if opts_all.profile:
404 if opts_all.profile:
403 try:
405 try:
404 opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile
406 opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile
405 + rc_suffix,
407 + rc_suffix,
406 opts_all.ipythondir)
408 opts_all.ipythondir)
407 except IOError:
409 except IOError:
408 if opts_all.debug: IP.InteractiveTB()
410 if opts_all.debug: IP.InteractiveTB()
409 opts.profile = '' # remove profile from options if invalid
411 opts.profile = '' # remove profile from options if invalid
410 warn('Profile configuration file %s not found. Ignoring request.'
412 warn('Profile configuration file %s not found. Ignoring request.'
411 % (opts_all.profile) )
413 % (opts_all.profile) )
412
414
413 # load the config file
415 # load the config file
414 rcfiledata = None
416 rcfiledata = None
415 if opts_all.quick:
417 if opts_all.quick:
416 print 'Launching IPython in quick mode. No config file read.'
418 print 'Launching IPython in quick mode. No config file read.'
417 elif opts_all.classic:
419 elif opts_all.classic:
418 print 'Launching IPython in classic mode. No config file read.'
420 print 'Launching IPython in classic mode. No config file read.'
419 elif opts_all.rcfile:
421 elif opts_all.rcfile:
420 try:
422 try:
421 cfg_loader = ConfigLoader(conflict)
423 cfg_loader = ConfigLoader(conflict)
422 rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv,
424 rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv,
423 'include',opts_all.ipythondir,
425 'include',opts_all.ipythondir,
424 purge = 1,
426 purge = 1,
425 unique = conflict['preserve'])
427 unique = conflict['preserve'])
426 except:
428 except:
427 IP.InteractiveTB()
429 IP.InteractiveTB()
428 warn('Problems loading configuration file '+
430 warn('Problems loading configuration file '+
429 `opts_all.rcfile`+
431 `opts_all.rcfile`+
430 '\nStarting with default -bare bones- configuration.')
432 '\nStarting with default -bare bones- configuration.')
431 else:
433 else:
432 warn('No valid configuration file found in either currrent directory\n'+
434 warn('No valid configuration file found in either currrent directory\n'+
433 'or in the IPython config. directory: '+`opts_all.ipythondir`+
435 'or in the IPython config. directory: '+`opts_all.ipythondir`+
434 '\nProceeding with internal defaults.')
436 '\nProceeding with internal defaults.')
435
437
436 #------------------------------------------------------------------------
438 #------------------------------------------------------------------------
437 # Set exception handlers in mode requested by user.
439 # Set exception handlers in mode requested by user.
438 otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode
440 otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode
439 IP.magic_xmode(opts_all.xmode)
441 IP.magic_xmode(opts_all.xmode)
440 otrap.release_out()
442 otrap.release_out()
441
443
442 #------------------------------------------------------------------------
444 #------------------------------------------------------------------------
443 # Execute user config
445 # Execute user config
444
446
445 # first, create a valid config structure with the right precedence order:
447 # first, create a valid config structure with the right precedence order:
446 # defaults < rcfile < command line
448 # defaults < rcfile < command line
447 IP.rc = rc_def.copy()
449 IP.rc = rc_def.copy()
448 IP.rc.update(opts_def)
450 IP.rc.update(opts_def)
449 if rcfiledata:
451 if rcfiledata:
450 # now we can update
452 # now we can update
451 IP.rc.update(rcfiledata)
453 IP.rc.update(rcfiledata)
452 IP.rc.update(opts)
454 IP.rc.update(opts)
453 IP.rc.update(rc_override)
455 IP.rc.update(rc_override)
454
456
455 # Store the original cmd line for reference:
457 # Store the original cmd line for reference:
456 IP.rc.opts = opts
458 IP.rc.opts = opts
457 IP.rc.args = args
459 IP.rc.args = args
458
460
459 # create a *runtime* Struct like rc for holding parameters which may be
461 # create a *runtime* Struct like rc for holding parameters which may be
460 # created and/or modified by runtime user extensions.
462 # created and/or modified by runtime user extensions.
461 IP.runtime_rc = Struct()
463 IP.runtime_rc = Struct()
462
464
463 # from this point on, all config should be handled through IP.rc,
465 # from this point on, all config should be handled through IP.rc,
464 # opts* shouldn't be used anymore.
466 # opts* shouldn't be used anymore.
465
467
466 # add personal .ipython dir to sys.path so that users can put things in
468 # add personal .ipython dir to sys.path so that users can put things in
467 # there for customization
469 # there for customization
468 sys.path.append(IP.rc.ipythondir)
470 sys.path.append(IP.rc.ipythondir)
469 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
471 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
470
472
471 # update IP.rc with some special things that need manual
473 # update IP.rc with some special things that need manual
472 # tweaks. Basically options which affect other options. I guess this
474 # tweaks. Basically options which affect other options. I guess this
473 # should just be written so that options are fully orthogonal and we
475 # should just be written so that options are fully orthogonal and we
474 # wouldn't worry about this stuff!
476 # wouldn't worry about this stuff!
475
477
476 if IP.rc.classic:
478 if IP.rc.classic:
477 IP.rc.quick = 1
479 IP.rc.quick = 1
478 IP.rc.cache_size = 0
480 IP.rc.cache_size = 0
479 IP.rc.pprint = 0
481 IP.rc.pprint = 0
480 IP.rc.prompt_in1 = '>>> '
482 IP.rc.prompt_in1 = '>>> '
481 IP.rc.prompt_in2 = '... '
483 IP.rc.prompt_in2 = '... '
482 IP.rc.prompt_out = ''
484 IP.rc.prompt_out = ''
483 IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0'
485 IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0'
484 IP.rc.colors = 'NoColor'
486 IP.rc.colors = 'NoColor'
485 IP.rc.xmode = 'Plain'
487 IP.rc.xmode = 'Plain'
486
488
487 # configure readline
489 # configure readline
488 # Define the history file for saving commands in between sessions
490 # Define the history file for saving commands in between sessions
489 if IP.rc.profile:
491 if IP.rc.profile:
490 histfname = 'history-%s' % IP.rc.profile
492 histfname = 'history-%s' % IP.rc.profile
491 else:
493 else:
492 histfname = 'history'
494 histfname = 'history'
493 IP.histfile = os.path.join(opts_all.ipythondir,histfname)
495 IP.histfile = os.path.join(opts_all.ipythondir,histfname)
494 # Load readline proper
496 # Load readline proper
495 if IP.rc.readline:
497 if IP.rc.readline:
496 IP.init_readline()
498 IP.init_readline()
497
499
498 # update exception handlers with rc file status
500 # update exception handlers with rc file status
499 otrap.trap_out() # I don't want these messages ever.
501 otrap.trap_out() # I don't want these messages ever.
500 IP.magic_xmode(IP.rc.xmode)
502 IP.magic_xmode(IP.rc.xmode)
501 otrap.release_out()
503 otrap.release_out()
502
504
503 # activate logging if requested and not reloading a log
505 # activate logging if requested and not reloading a log
504 if IP.rc.logplay:
506 if IP.rc.logplay:
505 IP.magic_logstart(IP.rc.logplay + ' append')
507 IP.magic_logstart(IP.rc.logplay + ' append')
506 elif IP.rc.logfile:
508 elif IP.rc.logfile:
507 IP.magic_logstart(IP.rc.logfile)
509 IP.magic_logstart(IP.rc.logfile)
508 elif IP.rc.log:
510 elif IP.rc.log:
509 IP.magic_logstart()
511 IP.magic_logstart()
510
512
511 # find user editor so that it we don't have to look it up constantly
513 # find user editor so that it we don't have to look it up constantly
512 if IP.rc.editor.strip()=='0':
514 if IP.rc.editor.strip()=='0':
513 try:
515 try:
514 ed = os.environ['EDITOR']
516 ed = os.environ['EDITOR']
515 except KeyError:
517 except KeyError:
516 if os.name == 'posix':
518 if os.name == 'posix':
517 ed = 'vi' # the only one guaranteed to be there!
519 ed = 'vi' # the only one guaranteed to be there!
518 else:
520 else:
519 ed = 'notepad' # same in Windows!
521 ed = 'notepad' # same in Windows!
520 IP.rc.editor = ed
522 IP.rc.editor = ed
521
523
522 # Recursive reload
524 # Recursive reload
523 try:
525 try:
524 from IPython import deep_reload
526 from IPython import deep_reload
525 if IP.rc.deep_reload:
527 if IP.rc.deep_reload:
526 __builtin__.reload = deep_reload.reload
528 __builtin__.reload = deep_reload.reload
527 else:
529 else:
528 __builtin__.dreload = deep_reload.reload
530 __builtin__.dreload = deep_reload.reload
529 del deep_reload
531 del deep_reload
530 except ImportError:
532 except ImportError:
531 pass
533 pass
532
534
533 # Save the current state of our namespace so that the interactive shell
535 # Save the current state of our namespace so that the interactive shell
534 # can later know which variables have been created by us from config files
536 # can later know which variables have been created by us from config files
535 # and loading. This way, loading a file (in any way) is treated just like
537 # and loading. This way, loading a file (in any way) is treated just like
536 # defining things on the command line, and %who works as expected.
538 # defining things on the command line, and %who works as expected.
537
539
538 # DON'T do anything that affects the namespace beyond this point!
540 # DON'T do anything that affects the namespace beyond this point!
539 IP.internal_ns = __main__.__dict__.copy()
541 IP.internal_ns = __main__.__dict__.copy()
540
542
541 #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who
543 #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who
542
544
543 # Now run through the different sections of the users's config
545 # Now run through the different sections of the users's config
544 if IP.rc.debug:
546 if IP.rc.debug:
545 print 'Trying to execute the following configuration structure:'
547 print 'Trying to execute the following configuration structure:'
546 print '(Things listed first are deeper in the inclusion tree and get'
548 print '(Things listed first are deeper in the inclusion tree and get'
547 print 'loaded first).\n'
549 print 'loaded first).\n'
548 pprint(IP.rc.__dict__)
550 pprint(IP.rc.__dict__)
549
551
550 for mod in IP.rc.import_mod:
552 for mod in IP.rc.import_mod:
551 try:
553 try:
552 exec 'import '+mod in IP.user_ns
554 exec 'import '+mod in IP.user_ns
553 except :
555 except :
554 IP.InteractiveTB()
556 IP.InteractiveTB()
555 import_fail_info(mod)
557 import_fail_info(mod)
556
558
557 for mod_fn in IP.rc.import_some:
559 for mod_fn in IP.rc.import_some:
558 if mod_fn == []: break
560 if mod_fn == []: break
559 mod,fn = mod_fn[0],','.join(mod_fn[1:])
561 mod,fn = mod_fn[0],','.join(mod_fn[1:])
560 try:
562 try:
561 exec 'from '+mod+' import '+fn in IP.user_ns
563 exec 'from '+mod+' import '+fn in IP.user_ns
562 except :
564 except :
563 IP.InteractiveTB()
565 IP.InteractiveTB()
564 import_fail_info(mod,fn)
566 import_fail_info(mod,fn)
565
567
566 for mod in IP.rc.import_all:
568 for mod in IP.rc.import_all:
567 try:
569 try:
568 exec 'from '+mod+' import *' in IP.user_ns
570 exec 'from '+mod+' import *' in IP.user_ns
569 except :
571 except :
570 IP.InteractiveTB()
572 IP.InteractiveTB()
571 import_fail_info(mod)
573 import_fail_info(mod)
572
574
573 for code in IP.rc.execute:
575 for code in IP.rc.execute:
574 try:
576 try:
575 exec code in IP.user_ns
577 exec code in IP.user_ns
576 except:
578 except:
577 IP.InteractiveTB()
579 IP.InteractiveTB()
578 warn('Failure executing code: ' + `code`)
580 warn('Failure executing code: ' + `code`)
579
581
580 # Execute the files the user wants in ipythonrc
582 # Execute the files the user wants in ipythonrc
581 for file in IP.rc.execfile:
583 for file in IP.rc.execfile:
582 try:
584 try:
583 file = filefind(file,sys.path+[IPython_dir])
585 file = filefind(file,sys.path+[IPython_dir])
584 except IOError:
586 except IOError:
585 warn(itpl('File $file not found. Skipping it.'))
587 warn(itpl('File $file not found. Skipping it.'))
586 else:
588 else:
587 IP.safe_execfile(os.path.expanduser(file),IP.user_ns)
589 IP.safe_execfile(os.path.expanduser(file),IP.user_ns)
588
590
589 # Load user aliases
591 # Load user aliases
590 for alias in IP.rc.alias:
592 for alias in IP.rc.alias:
591 IP.magic_alias(alias)
593 IP.magic_alias(alias)
592
594
593 # release stdout and stderr and save config log into a global summary
595 # release stdout and stderr and save config log into a global summary
594 msg.config.release_all()
596 msg.config.release_all()
595 if IP.rc.messages:
597 if IP.rc.messages:
596 msg.summary += msg.config.summary_all()
598 msg.summary += msg.config.summary_all()
597
599
598 #------------------------------------------------------------------------
600 #------------------------------------------------------------------------
599 # Setup interactive session
601 # Setup interactive session
600
602
601 # Now we should be fully configured. We can then execute files or load
603 # Now we should be fully configured. We can then execute files or load
602 # things only needed for interactive use. Then we'll open the shell.
604 # things only needed for interactive use. Then we'll open the shell.
603
605
604 # Take a snapshot of the user namespace before opening the shell. That way
606 # Take a snapshot of the user namespace before opening the shell. That way
605 # we'll be able to identify which things were interactively defined and
607 # we'll be able to identify which things were interactively defined and
606 # which were defined through config files.
608 # which were defined through config files.
607 IP.user_config_ns = IP.user_ns.copy()
609 IP.user_config_ns = IP.user_ns.copy()
608
610
609 # Force reading a file as if it were a session log. Slower but safer.
611 # Force reading a file as if it were a session log. Slower but safer.
610 if load_logplay:
612 if load_logplay:
611 print 'Replaying log...'
613 print 'Replaying log...'
612 try:
614 try:
613 if IP.rc.debug:
615 if IP.rc.debug:
614 logplay_quiet = 0
616 logplay_quiet = 0
615 else:
617 else:
616 logplay_quiet = 1
618 logplay_quiet = 1
617
619
618 msg.logplay.trap_all()
620 msg.logplay.trap_all()
619 IP.safe_execfile(load_logplay,IP.user_ns,
621 IP.safe_execfile(load_logplay,IP.user_ns,
620 islog = 1, quiet = logplay_quiet)
622 islog = 1, quiet = logplay_quiet)
621 msg.logplay.release_all()
623 msg.logplay.release_all()
622 if IP.rc.messages:
624 if IP.rc.messages:
623 msg.summary += msg.logplay.summary_all()
625 msg.summary += msg.logplay.summary_all()
624 except:
626 except:
625 warn('Problems replaying logfile %s.' % load_logplay)
627 warn('Problems replaying logfile %s.' % load_logplay)
626 IP.InteractiveTB()
628 IP.InteractiveTB()
627
629
628 # Load remaining files in command line
630 # Load remaining files in command line
629 msg.user_exec.trap_all()
631 msg.user_exec.trap_all()
630
632
631 # Do NOT execute files named in the command line as scripts to be loaded
633 # Do NOT execute files named in the command line as scripts to be loaded
632 # by embedded instances. Doing so has the potential for an infinite
634 # by embedded instances. Doing so has the potential for an infinite
633 # recursion if there are exceptions thrown in the process.
635 # recursion if there are exceptions thrown in the process.
634
636
635 # XXX FIXME: the execution of user files should be moved out to after
637 # XXX FIXME: the execution of user files should be moved out to after
636 # ipython is fully initialized, just as if they were run via %run at the
638 # ipython is fully initialized, just as if they were run via %run at the
637 # ipython prompt. This would also give them the benefit of ipython's
639 # ipython prompt. This would also give them the benefit of ipython's
638 # nice tracebacks.
640 # nice tracebacks.
639
641
640 if not embedded and IP.rc.args:
642 if not embedded and IP.rc.args:
641 name_save = IP.user_ns['__name__']
643 name_save = IP.user_ns['__name__']
642 IP.user_ns['__name__'] = '__main__'
644 IP.user_ns['__name__'] = '__main__'
643 try:
645 try:
644 # Set our own excepthook in case the user code tries to call it
646 # Set our own excepthook in case the user code tries to call it
645 # directly. This prevents triggering the IPython crash handler.
647 # directly. This prevents triggering the IPython crash handler.
646 old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook
648 old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook
647 for run in args:
649 for run in args:
648 IP.safe_execfile(run,IP.user_ns)
650 IP.safe_execfile(run,IP.user_ns)
649 finally:
651 finally:
650 # Reset our crash handler in place
652 # Reset our crash handler in place
651 sys.excepthook = old_excepthook
653 sys.excepthook = old_excepthook
652
654
653 IP.user_ns['__name__'] = name_save
655 IP.user_ns['__name__'] = name_save
654
656
655 msg.user_exec.release_all()
657 msg.user_exec.release_all()
656 if IP.rc.messages:
658 if IP.rc.messages:
657 msg.summary += msg.user_exec.summary_all()
659 msg.summary += msg.user_exec.summary_all()
658
660
659 # since we can't specify a null string on the cmd line, 0 is the equivalent:
661 # since we can't specify a null string on the cmd line, 0 is the equivalent:
660 if IP.rc.nosep:
662 if IP.rc.nosep:
661 IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0'
663 IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0'
662 if IP.rc.separate_in == '0': IP.rc.separate_in = ''
664 if IP.rc.separate_in == '0': IP.rc.separate_in = ''
663 if IP.rc.separate_out == '0': IP.rc.separate_out = ''
665 if IP.rc.separate_out == '0': IP.rc.separate_out = ''
664 if IP.rc.separate_out2 == '0': IP.rc.separate_out2 = ''
666 if IP.rc.separate_out2 == '0': IP.rc.separate_out2 = ''
665 IP.rc.separate_in = IP.rc.separate_in.replace('\\n','\n')
667 IP.rc.separate_in = IP.rc.separate_in.replace('\\n','\n')
666 IP.rc.separate_out = IP.rc.separate_out.replace('\\n','\n')
668 IP.rc.separate_out = IP.rc.separate_out.replace('\\n','\n')
667 IP.rc.separate_out2 = IP.rc.separate_out2.replace('\\n','\n')
669 IP.rc.separate_out2 = IP.rc.separate_out2.replace('\\n','\n')
668
670
669 # Determine how many lines at the bottom of the screen are needed for
671 # Determine how many lines at the bottom of the screen are needed for
670 # showing prompts, so we can know wheter long strings are to be printed or
672 # showing prompts, so we can know wheter long strings are to be printed or
671 # paged:
673 # paged:
672 num_lines_bot = IP.rc.separate_in.count('\n')+1
674 num_lines_bot = IP.rc.separate_in.count('\n')+1
673 IP.rc.screen_length = IP.rc.screen_length - num_lines_bot
675 IP.rc.screen_length = IP.rc.screen_length - num_lines_bot
674 # Initialize cache, set in/out prompts and printing system
676 # Initialize cache, set in/out prompts and printing system
675 IP.outputcache = CachedOutput(IP.rc.cache_size,
677 IP.outputcache = CachedOutput(IP.rc.cache_size,
676 IP.rc.pprint,
678 IP.rc.pprint,
677 input_sep = IP.rc.separate_in,
679 input_sep = IP.rc.separate_in,
678 output_sep = IP.rc.separate_out,
680 output_sep = IP.rc.separate_out,
679 output_sep2 = IP.rc.separate_out2,
681 output_sep2 = IP.rc.separate_out2,
680 ps1 = IP.rc.prompt_in1,
682 ps1 = IP.rc.prompt_in1,
681 ps2 = IP.rc.prompt_in2,
683 ps2 = IP.rc.prompt_in2,
682 ps_out = IP.rc.prompt_out,
684 ps_out = IP.rc.prompt_out,
683 user_ns = IP.user_ns,
685 user_ns = IP.user_ns,
684 input_hist = IP.input_hist,
686 input_hist = IP.input_hist,
685 pad_left = IP.rc.prompts_pad_left)
687 pad_left = IP.rc.prompts_pad_left)
686
688
687 # Set user colors (don't do it in the constructor above so that it doesn't
689 # Set user colors (don't do it in the constructor above so that it doesn't
688 # crash if colors option is invalid)
690 # crash if colors option is invalid)
689 IP.magic_colors(IP.rc.colors)
691 IP.magic_colors(IP.rc.colors)
690
692
691 # user may have over-ridden the default print hook:
693 # user may have over-ridden the default print hook:
692 try:
694 try:
693 IP.outputcache.__class__.display = IP.hooks.display
695 IP.outputcache.__class__.display = IP.hooks.display
694 except AttributeError:
696 except AttributeError:
695 pass
697 pass
696
698
697 # Set calling of pdb on exceptions
699 # Set calling of pdb on exceptions
698 IP.InteractiveTB.call_pdb = IP.rc.pdb
700 IP.InteractiveTB.call_pdb = IP.rc.pdb
699
701
700 # I don't like assigning globally to sys, because it means when embedding
702 # I don't like assigning globally to sys, because it means when embedding
701 # instances, each embedded instance overrides the previous choice. But
703 # instances, each embedded instance overrides the previous choice. But
702 # sys.displayhook seems to be called internally by exec, so I don't see a
704 # sys.displayhook seems to be called internally by exec, so I don't see a
703 # way around it.
705 # way around it.
704 sys.displayhook = IP.outputcache
706 sys.displayhook = IP.outputcache
705
707
706 # we need to know globally if we're caching i/o or not
708 # we need to know globally if we're caching i/o or not
707 IP.do_full_cache = IP.outputcache.do_full_cache
709 IP.do_full_cache = IP.outputcache.do_full_cache
708
710
709 # configure startup banner
711 # configure startup banner
710 if IP.rc.c: # regular python doesn't print the banner with -c
712 if IP.rc.c: # regular python doesn't print the banner with -c
711 IP.rc.banner = 0
713 IP.rc.banner = 0
712 if IP.rc.banner:
714 if IP.rc.banner:
713 IP.BANNER = '\n'.join(IP.BANNER_PARTS)
715 IP.BANNER = '\n'.join(IP.BANNER_PARTS)
714 else:
716 else:
715 IP.BANNER = ''
717 IP.BANNER = ''
716
718
717 if IP.rc.profile: IP.BANNER += '\nIPython profile: '+IP.rc.profile+'\n'
719 if IP.rc.profile: IP.BANNER += '\nIPython profile: '+IP.rc.profile+'\n'
718
720
719 # add message log (possibly empty)
721 # add message log (possibly empty)
720 IP.BANNER += msg.summary
722 IP.BANNER += msg.summary
721
723
722 IP.post_config_initialization()
724 IP.post_config_initialization()
723
725
724 return IP
726 return IP
725 #************************ end of file <ipmaker.py> **************************
727 #************************ end of file <ipmaker.py> **************************
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now