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