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