##// END OF EJS Templates
deep_reload.py =? lib/deepreload.py and imports updated.
Brian Granger -
Show More
@@ -1,771 +1,771 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 9
10 10 #*****************************************************************************
11 11 # Copyright (C) 2008-2009 The IPython Development Team
12 12 # Copyright (C) 2001-2007 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 try:
19 19 credits._Printer__data = """
20 20 Python: %s
21 21
22 22 IPython: The IPython Development Team.
23 23 See http://ipython.scipy.org for more information.""" \
24 24 % credits._Printer__data
25 25
26 26 copyright._Printer__data += """
27 27
28 28 Copyright (c) 2008-2009 The IPython Development Team.
29 29 Copyright (c) 2001-2007 Fernando Perez, Janko Hauser, Nathan Gray.
30 30 All Rights Reserved."""
31 31 except NameError:
32 32 # Can happen if ipython was started with 'python -S', so that site.py is
33 33 # not loaded
34 34 pass
35 35
36 36 #****************************************************************************
37 37 # Required modules
38 38
39 39 # From the standard library
40 40 import __main__
41 41 import __builtin__
42 42 import os
43 43 import sys
44 44 from pprint import pprint
45 45
46 46 # Our own
47 47 from IPython import DPyGetOpt
48 48 from IPython import Release
49 49 from IPython.ipstruct import Struct
50 50 from IPython.OutputTrap import OutputTrap
51 51 from IPython.config.configloader import ConfigLoader
52 52 from IPython.iplib import InteractiveShell
53 53 from IPython.usage import cmd_line_usage,interactive_usage
54 54 from IPython.genutils import *
55 55
56 56 def force_import(modname,force_reload=False):
57 57 if modname in sys.modules and force_reload:
58 58 info("reloading: %s" % modname)
59 59 reload(sys.modules[modname])
60 60 else:
61 61 __import__(modname)
62 62
63 63
64 64 #-----------------------------------------------------------------------------
65 65 def make_IPython(argv=None,user_ns=None,user_global_ns=None,debug=1,
66 66 rc_override=None,shell_class=InteractiveShell,
67 67 embedded=False,**kw):
68 68 """This is a dump of IPython into a single function.
69 69
70 70 Later it will have to be broken up in a sensible manner.
71 71
72 72 Arguments:
73 73
74 74 - argv: a list similar to sys.argv[1:]. It should NOT contain the desired
75 75 script name, b/c DPyGetOpt strips the first argument only for the real
76 76 sys.argv.
77 77
78 78 - user_ns: a dict to be used as the user's namespace."""
79 79
80 80 #----------------------------------------------------------------------
81 81 # Defaults and initialization
82 82
83 83 # For developer debugging, deactivates crash handler and uses pdb.
84 84 DEVDEBUG = False
85 85
86 86 if argv is None:
87 87 argv = sys.argv
88 88
89 89 # __IP is the main global that lives throughout and represents the whole
90 90 # application. If the user redefines it, all bets are off as to what
91 91 # happens.
92 92
93 93 # __IP is the name of he global which the caller will have accessible as
94 94 # __IP.name. We set its name via the first parameter passed to
95 95 # InteractiveShell:
96 96
97 97 IP = shell_class('__IP',user_ns=user_ns,user_global_ns=user_global_ns,
98 98 embedded=embedded,**kw)
99 99
100 100 # Put 'help' in the user namespace
101 101 try:
102 102 from site import _Helper
103 103 IP.user_ns['help'] = _Helper()
104 104 except ImportError:
105 105 warn('help() not available - check site.py')
106 106
107 107 if DEVDEBUG:
108 108 # For developer debugging only (global flag)
109 109 from IPython import ultraTB
110 110 sys.excepthook = ultraTB.VerboseTB(call_pdb=1)
111 111
112 112 IP.BANNER_PARTS = ['Python %s\n'
113 113 'Type "copyright", "credits" or "license" '
114 114 'for more information.\n'
115 115 % (sys.version.split('\n')[0],),
116 116 "IPython %s -- An enhanced Interactive Python."
117 117 % (Release.version,),
118 118 """\
119 119 ? -> Introduction and overview of IPython's features.
120 120 %quickref -> Quick reference.
121 121 help -> Python's own help system.
122 122 object? -> Details about 'object'. ?object also works, ?? prints more.
123 123 """ ]
124 124
125 125 IP.usage = interactive_usage
126 126
127 127 # Platform-dependent suffix.
128 128 if os.name == 'posix':
129 129 rc_suffix = ''
130 130 else:
131 131 rc_suffix = '.ini'
132 132
133 133 # default directory for configuration
134 134 ipythondir_def = get_ipython_dir()
135 135
136 136 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
137 137
138 138 # we need the directory where IPython itself is installed
139 139 import IPython
140 140 IPython_dir = os.path.dirname(IPython.__file__)
141 141 del IPython
142 142
143 143 #-------------------------------------------------------------------------
144 144 # Command line handling
145 145
146 146 # Valid command line options (uses DPyGetOpt syntax, like Perl's
147 147 # GetOpt::Long)
148 148
149 149 # Any key not listed here gets deleted even if in the file (like session
150 150 # or profile). That's deliberate, to maintain the rc namespace clean.
151 151
152 152 # Each set of options appears twice: under _conv only the names are
153 153 # listed, indicating which type they must be converted to when reading the
154 154 # ipythonrc file. And under DPyGetOpt they are listed with the regular
155 155 # DPyGetOpt syntax (=s,=i,:f,etc).
156 156
157 157 # Make sure there's a space before each end of line (they get auto-joined!)
158 158 cmdline_opts = ('autocall=i autoindent! automagic! banner! cache_size|cs=i '
159 159 'c=s classic|cl color_info! colors=s confirm_exit! '
160 160 'debug! deep_reload! editor=s log|l messages! nosep '
161 161 'object_info_string_level=i pdb! '
162 162 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s '
163 163 'pydb! '
164 164 'pylab_import_all! '
165 165 'quick screen_length|sl=i prompts_pad_left=i '
166 166 'logfile|lf=s logplay|lp=s profile|p=s '
167 167 'readline! readline_merge_completions! '
168 168 'readline_omit__names! '
169 169 'rcfile=s separate_in|si=s separate_out|so=s '
170 170 'separate_out2|so2=s xmode=s wildcards_case_sensitive! '
171 171 'magic_docstrings system_verbose! '
172 172 'multi_line_specials! '
173 173 'term_title! wxversion=s '
174 174 'autoedit_syntax!')
175 175
176 176 # Options that can *only* appear at the cmd line (not in rcfiles).
177 177
178 178 cmdline_only = ('help interact|i ipythondir=s Version upgrade '
179 179 'gthread! qthread! q4thread! wthread! tkthread! pylab! tk! '
180 180 # 'twisted!' # disabled for now.
181 181 )
182 182
183 183 # Build the actual name list to be used by DPyGetOpt
184 184 opts_names = qw(cmdline_opts) + qw(cmdline_only)
185 185
186 186 # Set sensible command line defaults.
187 187 # This should have everything from cmdline_opts and cmdline_only
188 188 opts_def = Struct(autocall = 1,
189 189 autoedit_syntax = 0,
190 190 autoindent = 0,
191 191 automagic = 1,
192 192 autoexec = [],
193 193 banner = 1,
194 194 c = '',
195 195 cache_size = 1000,
196 196 classic = 0,
197 197 color_info = 0,
198 198 colors = 'NoColor',
199 199 confirm_exit = 1,
200 200 debug = 0,
201 201 deep_reload = 0,
202 202 editor = '0',
203 203 gthread = 0,
204 204 help = 0,
205 205 interact = 0,
206 206 ipythondir = ipythondir_def,
207 207 log = 0,
208 208 logfile = '',
209 209 logplay = '',
210 210 messages = 1,
211 211 multi_line_specials = 1,
212 212 nosep = 0,
213 213 object_info_string_level = 0,
214 214 pdb = 0,
215 215 pprint = 0,
216 216 profile = '',
217 217 prompt_in1 = 'In [\\#]: ',
218 218 prompt_in2 = ' .\\D.: ',
219 219 prompt_out = 'Out[\\#]: ',
220 220 prompts_pad_left = 1,
221 221 pydb = 0,
222 222 pylab = 0,
223 223 pylab_import_all = 1,
224 224 q4thread = 0,
225 225 qthread = 0,
226 226 quick = 0,
227 227 quiet = 0,
228 228 rcfile = 'ipythonrc' + rc_suffix,
229 229 readline = 1,
230 230 readline_merge_completions = 1,
231 231 readline_omit__names = 0,
232 232 screen_length = 0,
233 233 separate_in = '\n',
234 234 separate_out = '\n',
235 235 separate_out2 = '',
236 236 system_header = 'IPython system call: ',
237 237 system_verbose = 0,
238 238 term_title = 1,
239 239 tk = 0,
240 240 #twisted= 0, # disabled for now
241 241 upgrade = 0,
242 242 Version = 0,
243 243 wildcards_case_sensitive = 1,
244 244 wthread = 0,
245 245 wxversion = '0',
246 246 xmode = 'Context',
247 247 magic_docstrings = 0, # undocumented, for doc generation
248 248 )
249 249
250 250 # Things that will *only* appear in rcfiles (not at the command line).
251 251 # Make sure there's a space before each end of line (they get auto-joined!)
252 252 rcfile_opts = { qwflat: 'include import_mod import_all execfile ',
253 253 qw_lol: 'import_some ',
254 254 # for things with embedded whitespace:
255 255 list_strings:'execute alias readline_parse_and_bind ',
256 256 # Regular strings need no conversion:
257 257 None:'readline_remove_delims ',
258 258 }
259 259 # Default values for these
260 260 rc_def = Struct(include = [],
261 261 import_mod = [],
262 262 import_all = [],
263 263 import_some = [[]],
264 264 execute = [],
265 265 execfile = [],
266 266 alias = [],
267 267 readline_parse_and_bind = [],
268 268 readline_remove_delims = '',
269 269 )
270 270
271 271 # Build the type conversion dictionary from the above tables:
272 272 typeconv = rcfile_opts.copy()
273 273 typeconv.update(optstr2types(cmdline_opts))
274 274
275 275 # FIXME: the None key appears in both, put that back together by hand. Ugly!
276 276 typeconv[None] += ' ' + rcfile_opts[None]
277 277
278 278 # Remove quotes at ends of all strings (used to protect spaces)
279 279 typeconv[unquote_ends] = typeconv[None]
280 280 del typeconv[None]
281 281
282 282 # Build the list we'll use to make all config decisions with defaults:
283 283 opts_all = opts_def.copy()
284 284 opts_all.update(rc_def)
285 285
286 286 # Build conflict resolver for recursive loading of config files:
287 287 # - preserve means the outermost file maintains the value, it is not
288 288 # overwritten if an included file has the same key.
289 289 # - add_flip applies + to the two values, so it better make sense to add
290 290 # those types of keys. But it flips them first so that things loaded
291 291 # deeper in the inclusion chain have lower precedence.
292 292 conflict = {'preserve': ' '.join([ typeconv[int],
293 293 typeconv[unquote_ends] ]),
294 294 'add_flip': ' '.join([ typeconv[qwflat],
295 295 typeconv[qw_lol],
296 296 typeconv[list_strings] ])
297 297 }
298 298
299 299 # Now actually process the command line
300 300 getopt = DPyGetOpt.DPyGetOpt()
301 301 getopt.setIgnoreCase(0)
302 302
303 303 getopt.parseConfiguration(opts_names)
304 304
305 305 try:
306 306 getopt.processArguments(argv)
307 307 except DPyGetOpt.ArgumentError, exc:
308 308 print cmd_line_usage
309 309 warn('\nError in Arguments: "%s"' % exc)
310 310 sys.exit(1)
311 311
312 312 # convert the options dict to a struct for much lighter syntax later
313 313 opts = Struct(getopt.optionValues)
314 314 args = getopt.freeValues
315 315
316 316 # this is the struct (which has default values at this point) with which
317 317 # we make all decisions:
318 318 opts_all.update(opts)
319 319
320 320 # Options that force an immediate exit
321 321 if opts_all.help:
322 322 page(cmd_line_usage)
323 323 sys.exit()
324 324
325 325 if opts_all.Version:
326 326 print Release.version
327 327 sys.exit()
328 328
329 329 if opts_all.magic_docstrings:
330 330 IP.magic_magic('-latex')
331 331 sys.exit()
332 332
333 333 # add personal ipythondir to sys.path so that users can put things in
334 334 # there for customization
335 335 sys.path.append(os.path.abspath(opts_all.ipythondir))
336 336
337 337 # Create user config directory if it doesn't exist. This must be done
338 338 # *after* getting the cmd line options.
339 339 if not os.path.isdir(opts_all.ipythondir):
340 340 IP.user_setup(opts_all.ipythondir,rc_suffix,'install')
341 341
342 342 # upgrade user config files while preserving a copy of the originals
343 343 if opts_all.upgrade:
344 344 IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade')
345 345
346 346 # check mutually exclusive options in the *original* command line
347 347 mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'),
348 348 qw('classic profile'),qw('classic rcfile')])
349 349
350 350 #---------------------------------------------------------------------------
351 351 # Log replay
352 352
353 353 # if -logplay, we need to 'become' the other session. That basically means
354 354 # replacing the current command line environment with that of the old
355 355 # session and moving on.
356 356
357 357 # this is needed so that later we know we're in session reload mode, as
358 358 # opts_all will get overwritten:
359 359 load_logplay = 0
360 360
361 361 if opts_all.logplay:
362 362 load_logplay = opts_all.logplay
363 363 opts_debug_save = opts_all.debug
364 364 try:
365 365 logplay = open(opts_all.logplay)
366 366 except IOError:
367 367 if opts_all.debug: IP.InteractiveTB()
368 368 warn('Could not open logplay file '+`opts_all.logplay`)
369 369 # restore state as if nothing had happened and move on, but make
370 370 # sure that later we don't try to actually load the session file
371 371 logplay = None
372 372 load_logplay = 0
373 373 del opts_all.logplay
374 374 else:
375 375 try:
376 376 logplay.readline()
377 377 logplay.readline();
378 378 # this reloads that session's command line
379 379 cmd = logplay.readline()[6:]
380 380 exec cmd
381 381 # restore the true debug flag given so that the process of
382 382 # session loading itself can be monitored.
383 383 opts.debug = opts_debug_save
384 384 # save the logplay flag so later we don't overwrite the log
385 385 opts.logplay = load_logplay
386 386 # now we must update our own structure with defaults
387 387 opts_all.update(opts)
388 388 # now load args
389 389 cmd = logplay.readline()[6:]
390 390 exec cmd
391 391 logplay.close()
392 392 except:
393 393 logplay.close()
394 394 if opts_all.debug: IP.InteractiveTB()
395 395 warn("Logplay file lacking full configuration information.\n"
396 396 "I'll try to read it, but some things may not work.")
397 397
398 398 #-------------------------------------------------------------------------
399 399 # set up output traps: catch all output from files, being run, modules
400 400 # loaded, etc. Then give it to the user in a clean form at the end.
401 401
402 402 msg_out = 'Output messages. '
403 403 msg_err = 'Error messages. '
404 404 msg_sep = '\n'
405 405 msg = Struct(config = OutputTrap('Configuration Loader',msg_out,
406 406 msg_err,msg_sep,debug,
407 407 quiet_out=1),
408 408 user_exec = OutputTrap('User File Execution',msg_out,
409 409 msg_err,msg_sep,debug),
410 410 logplay = OutputTrap('Log Loader',msg_out,
411 411 msg_err,msg_sep,debug),
412 412 summary = ''
413 413 )
414 414
415 415 #-------------------------------------------------------------------------
416 416 # Process user ipythonrc-type configuration files
417 417
418 418 # turn on output trapping and log to msg.config
419 419 # remember that with debug on, trapping is actually disabled
420 420 msg.config.trap_all()
421 421
422 422 # look for rcfile in current or default directory
423 423 try:
424 424 opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir)
425 425 except IOError:
426 426 if opts_all.debug: IP.InteractiveTB()
427 427 warn('Configuration file %s not found. Ignoring request.'
428 428 % (opts_all.rcfile) )
429 429
430 430 # 'profiles' are a shorthand notation for config filenames
431 431 profile_handled_by_legacy = False
432 432 if opts_all.profile:
433 433
434 434 try:
435 435 opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile
436 436 + rc_suffix,
437 437 opts_all.ipythondir)
438 438 profile_handled_by_legacy = True
439 439 except IOError:
440 440 if opts_all.debug: IP.InteractiveTB()
441 441 opts.profile = '' # remove profile from options if invalid
442 442 # We won't warn anymore, primary method is ipy_profile_PROFNAME
443 443 # which does trigger a warning.
444 444
445 445 # load the config file
446 446 rcfiledata = None
447 447 if opts_all.quick:
448 448 print 'Launching IPython in quick mode. No config file read.'
449 449 elif opts_all.rcfile:
450 450 try:
451 451 cfg_loader = ConfigLoader(conflict)
452 452 rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv,
453 453 'include',opts_all.ipythondir,
454 454 purge = 1,
455 455 unique = conflict['preserve'])
456 456 except:
457 457 IP.InteractiveTB()
458 458 warn('Problems loading configuration file '+
459 459 `opts_all.rcfile`+
460 460 '\nStarting with default -bare bones- configuration.')
461 461 else:
462 462 warn('No valid configuration file found in either currrent directory\n'+
463 463 'or in the IPython config. directory: '+`opts_all.ipythondir`+
464 464 '\nProceeding with internal defaults.')
465 465
466 466 #------------------------------------------------------------------------
467 467 # Set exception handlers in mode requested by user.
468 468 otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode
469 469 IP.magic_xmode(opts_all.xmode)
470 470 otrap.release_out()
471 471
472 472 #------------------------------------------------------------------------
473 473 # Execute user config
474 474
475 475 # Create a valid config structure with the right precedence order:
476 476 # defaults < rcfile < command line. This needs to be in the instance, so
477 477 # that method calls below that rely on it find it.
478 478 IP.rc = rc_def.copy()
479 479
480 480 # Work with a local alias inside this routine to avoid unnecessary
481 481 # attribute lookups.
482 482 IP_rc = IP.rc
483 483
484 484 IP_rc.update(opts_def)
485 485 if rcfiledata:
486 486 # now we can update
487 487 IP_rc.update(rcfiledata)
488 488 IP_rc.update(opts)
489 489 IP_rc.update(rc_override)
490 490
491 491 # Store the original cmd line for reference:
492 492 IP_rc.opts = opts
493 493 IP_rc.args = args
494 494
495 495 # create a *runtime* Struct like rc for holding parameters which may be
496 496 # created and/or modified by runtime user extensions.
497 497 IP.runtime_rc = Struct()
498 498
499 499 # from this point on, all config should be handled through IP_rc,
500 500 # opts* shouldn't be used anymore.
501 501
502 502
503 503 # update IP_rc with some special things that need manual
504 504 # tweaks. Basically options which affect other options. I guess this
505 505 # should just be written so that options are fully orthogonal and we
506 506 # wouldn't worry about this stuff!
507 507
508 508 if IP_rc.classic:
509 509 IP_rc.quick = 1
510 510 IP_rc.cache_size = 0
511 511 IP_rc.pprint = 0
512 512 IP_rc.prompt_in1 = '>>> '
513 513 IP_rc.prompt_in2 = '... '
514 514 IP_rc.prompt_out = ''
515 515 IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0'
516 516 IP_rc.colors = 'NoColor'
517 517 IP_rc.xmode = 'Plain'
518 518
519 519 IP.pre_config_initialization()
520 520 # configure readline
521 521
522 522 # update exception handlers with rc file status
523 523 otrap.trap_out() # I don't want these messages ever.
524 524 IP.magic_xmode(IP_rc.xmode)
525 525 otrap.release_out()
526 526
527 527 # activate logging if requested and not reloading a log
528 528 if IP_rc.logplay:
529 529 IP.magic_logstart(IP_rc.logplay + ' append')
530 530 elif IP_rc.logfile:
531 531 IP.magic_logstart(IP_rc.logfile)
532 532 elif IP_rc.log:
533 533 IP.magic_logstart()
534 534
535 535 # find user editor so that it we don't have to look it up constantly
536 536 if IP_rc.editor.strip()=='0':
537 537 try:
538 538 ed = os.environ['EDITOR']
539 539 except KeyError:
540 540 if os.name == 'posix':
541 541 ed = 'vi' # the only one guaranteed to be there!
542 542 else:
543 543 ed = 'notepad' # same in Windows!
544 544 IP_rc.editor = ed
545 545
546 546 # Keep track of whether this is an embedded instance or not (useful for
547 547 # post-mortems).
548 548 IP_rc.embedded = IP.embedded
549 549
550 550 # Recursive reload
551 551 try:
552 from IPython import deep_reload
552 from IPython.lib import deepreload
553 553 if IP_rc.deep_reload:
554 __builtin__.reload = deep_reload.reload
554 __builtin__.reload = deepreload.reload
555 555 else:
556 __builtin__.dreload = deep_reload.reload
557 del deep_reload
556 __builtin__.dreload = deepreload.reload
557 del deepreload
558 558 except ImportError:
559 559 pass
560 560
561 561 # Save the current state of our namespace so that the interactive shell
562 562 # can later know which variables have been created by us from config files
563 563 # and loading. This way, loading a file (in any way) is treated just like
564 564 # defining things on the command line, and %who works as expected.
565 565
566 566 # DON'T do anything that affects the namespace beyond this point!
567 567 IP.internal_ns.update(__main__.__dict__)
568 568
569 569 #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who
570 570
571 571 # Now run through the different sections of the users's config
572 572 if IP_rc.debug:
573 573 print 'Trying to execute the following configuration structure:'
574 574 print '(Things listed first are deeper in the inclusion tree and get'
575 575 print 'loaded first).\n'
576 576 pprint(IP_rc.__dict__)
577 577
578 578 for mod in IP_rc.import_mod:
579 579 try:
580 580 exec 'import '+mod in IP.user_ns
581 581 except :
582 582 IP.InteractiveTB()
583 583 import_fail_info(mod)
584 584
585 585 for mod_fn in IP_rc.import_some:
586 586 if not mod_fn == []:
587 587 mod,fn = mod_fn[0],','.join(mod_fn[1:])
588 588 try:
589 589 exec 'from '+mod+' import '+fn in IP.user_ns
590 590 except :
591 591 IP.InteractiveTB()
592 592 import_fail_info(mod,fn)
593 593
594 594 for mod in IP_rc.import_all:
595 595 try:
596 596 exec 'from '+mod+' import *' in IP.user_ns
597 597 except :
598 598 IP.InteractiveTB()
599 599 import_fail_info(mod)
600 600
601 601 for code in IP_rc.execute:
602 602 try:
603 603 exec code in IP.user_ns
604 604 except:
605 605 IP.InteractiveTB()
606 606 warn('Failure executing code: ' + `code`)
607 607
608 608 # Execute the files the user wants in ipythonrc
609 609 for file in IP_rc.execfile:
610 610 try:
611 611 file = filefind(file,sys.path+[IPython_dir])
612 612 except IOError:
613 613 warn(itpl('File $file not found. Skipping it.'))
614 614 else:
615 615 IP.safe_execfile(os.path.expanduser(file),IP.user_ns)
616 616
617 617 # finally, try importing ipy_*_conf for final configuration
618 618 try:
619 619 import ipy_system_conf
620 620 except ImportError:
621 621 if opts_all.debug: IP.InteractiveTB()
622 622 warn("Could not import 'ipy_system_conf'")
623 623 except:
624 624 IP.InteractiveTB()
625 625 import_fail_info('ipy_system_conf')
626 626
627 627 # only import prof module if ipythonrc-PROF was not found
628 628 if opts_all.profile and not profile_handled_by_legacy:
629 629 profmodname = 'ipy_profile_' + opts_all.profile
630 630 try:
631 631 force_import(profmodname)
632 632 except:
633 633 IP.InteractiveTB()
634 634 print "Error importing",profmodname,\
635 635 "- perhaps you should run %upgrade?"
636 636 import_fail_info(profmodname)
637 637 else:
638 638 opts.profile = opts_all.profile
639 639 else:
640 640 force_import('ipy_profile_none')
641 641 # XXX - this is wrong: ipy_user_conf should not be loaded unconditionally,
642 642 # since the user could have specified a config file path by hand.
643 643 try:
644 644 force_import('ipy_user_conf')
645 645 except:
646 646 conf = opts_all.ipythondir + "/ipy_user_conf.py"
647 647 IP.InteractiveTB()
648 648 if not os.path.isfile(conf):
649 649 warn(conf + ' does not exist, please run %upgrade!')
650 650
651 651 import_fail_info("ipy_user_conf")
652 652
653 653 # Define the history file for saving commands in between sessions
654 654 try:
655 655 histfname = 'history-%s' % opts.profile
656 656 except AttributeError:
657 657 histfname = 'history'
658 658 IP.histfile = os.path.join(opts_all.ipythondir,histfname)
659 659
660 660 # finally, push the argv to options again to ensure highest priority
661 661 IP_rc.update(opts)
662 662
663 663 # release stdout and stderr and save config log into a global summary
664 664 msg.config.release_all()
665 665 if IP_rc.messages:
666 666 msg.summary += msg.config.summary_all()
667 667
668 668 #------------------------------------------------------------------------
669 669 # Setup interactive session
670 670
671 671 # Now we should be fully configured. We can then execute files or load
672 672 # things only needed for interactive use. Then we'll open the shell.
673 673
674 674 # Take a snapshot of the user namespace before opening the shell. That way
675 675 # we'll be able to identify which things were interactively defined and
676 676 # which were defined through config files.
677 677 IP.user_config_ns.update(IP.user_ns)
678 678
679 679 # Force reading a file as if it were a session log. Slower but safer.
680 680 if load_logplay:
681 681 print 'Replaying log...'
682 682 try:
683 683 if IP_rc.debug:
684 684 logplay_quiet = 0
685 685 else:
686 686 logplay_quiet = 1
687 687
688 688 msg.logplay.trap_all()
689 689 IP.safe_execfile(load_logplay,IP.user_ns,
690 690 islog = 1, quiet = logplay_quiet)
691 691 msg.logplay.release_all()
692 692 if IP_rc.messages:
693 693 msg.summary += msg.logplay.summary_all()
694 694 except:
695 695 warn('Problems replaying logfile %s.' % load_logplay)
696 696 IP.InteractiveTB()
697 697
698 698 # Load remaining files in command line
699 699 msg.user_exec.trap_all()
700 700
701 701 # Do NOT execute files named in the command line as scripts to be loaded
702 702 # by embedded instances. Doing so has the potential for an infinite
703 703 # recursion if there are exceptions thrown in the process.
704 704
705 705 # XXX FIXME: the execution of user files should be moved out to after
706 706 # ipython is fully initialized, just as if they were run via %run at the
707 707 # ipython prompt. This would also give them the benefit of ipython's
708 708 # nice tracebacks.
709 709
710 710 if (not embedded and IP_rc.args and
711 711 not IP_rc.args[0].lower().endswith('.ipy')):
712 712 name_save = IP.user_ns['__name__']
713 713 IP.user_ns['__name__'] = '__main__'
714 714 # Set our own excepthook in case the user code tries to call it
715 715 # directly. This prevents triggering the IPython crash handler.
716 716 old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook
717 717
718 718 save_argv = sys.argv[1:] # save it for later restoring
719 719
720 720 sys.argv = args
721 721
722 722 try:
723 723 IP.safe_execfile(args[0], IP.user_ns)
724 724 finally:
725 725 # Reset our crash handler in place
726 726 sys.excepthook = old_excepthook
727 727 sys.argv[:] = save_argv
728 728 IP.user_ns['__name__'] = name_save
729 729
730 730 msg.user_exec.release_all()
731 731
732 732 if IP_rc.messages:
733 733 msg.summary += msg.user_exec.summary_all()
734 734
735 735 # since we can't specify a null string on the cmd line, 0 is the equivalent:
736 736 if IP_rc.nosep:
737 737 IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0'
738 738 if IP_rc.separate_in == '0': IP_rc.separate_in = ''
739 739 if IP_rc.separate_out == '0': IP_rc.separate_out = ''
740 740 if IP_rc.separate_out2 == '0': IP_rc.separate_out2 = ''
741 741 IP_rc.separate_in = IP_rc.separate_in.replace('\\n','\n')
742 742 IP_rc.separate_out = IP_rc.separate_out.replace('\\n','\n')
743 743 IP_rc.separate_out2 = IP_rc.separate_out2.replace('\\n','\n')
744 744
745 745 # Determine how many lines at the bottom of the screen are needed for
746 746 # showing prompts, so we can know wheter long strings are to be printed or
747 747 # paged:
748 748 num_lines_bot = IP_rc.separate_in.count('\n')+1
749 749 IP_rc.screen_length = IP_rc.screen_length - num_lines_bot
750 750
751 751 # configure startup banner
752 752 if IP_rc.c: # regular python doesn't print the banner with -c
753 753 IP_rc.banner = 0
754 754 if IP_rc.banner:
755 755 BANN_P = IP.BANNER_PARTS
756 756 else:
757 757 BANN_P = []
758 758
759 759 if IP_rc.profile: BANN_P.append('IPython profile: %s\n' % IP_rc.profile)
760 760
761 761 # add message log (possibly empty)
762 762 if msg.summary: BANN_P.append(msg.summary)
763 763 # Final banner is a string
764 764 IP.BANNER = '\n'.join(BANN_P)
765 765
766 766 # Finalize the IPython instance. This assumes the rc structure is fully
767 767 # in place.
768 768 IP.post_config_initialization()
769 769
770 770 return IP
771 771 #************************ end of file <ipmaker.py> **************************
@@ -1,182 +1,182 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 A module to change reload() so that it acts recursively.
4 4 To enable it type:
5 >>> import __builtin__, deep_reload
6 >>> __builtin__.reload = deep_reload.reload
5 >>> import __builtin__, deepreload
6 >>> __builtin__.reload = deepreload.reload
7 7
8 8 You can then disable it with:
9 >>> __builtin__.reload = deep_reload.original_reload
9 >>> __builtin__.reload = deepreload.original_reload
10 10
11 11 Alternatively, you can add a dreload builtin alongside normal reload with:
12 >>> __builtin__.dreload = deep_reload.reload
12 >>> __builtin__.dreload = deepreload.reload
13 13
14 14 This code is almost entirely based on knee.py from the standard library.
15 15 """
16 16
17 17 #*****************************************************************************
18 18 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
19 19 #
20 20 # Distributed under the terms of the BSD License. The full license is in
21 21 # the file COPYING, distributed as part of this software.
22 22 #*****************************************************************************
23 23
24 24 import __builtin__
25 25 import imp
26 26 import sys
27 27
28 28 # Replacement for __import__()
29 29 def deep_import_hook(name, globals=None, locals=None, fromlist=None, level=-1):
30 30 # For now level is ignored, it's just there to prevent crash
31 31 # with from __future__ import absolute_import
32 32 parent = determine_parent(globals)
33 33 q, tail = find_head_package(parent, name)
34 34 m = load_tail(q, tail)
35 35 if not fromlist:
36 36 return q
37 37 if hasattr(m, "__path__"):
38 38 ensure_fromlist(m, fromlist)
39 39 return m
40 40
41 41 def determine_parent(globals):
42 42 if not globals or not globals.has_key("__name__"):
43 43 return None
44 44 pname = globals['__name__']
45 45 if globals.has_key("__path__"):
46 46 parent = sys.modules[pname]
47 47 assert globals is parent.__dict__
48 48 return parent
49 49 if '.' in pname:
50 50 i = pname.rfind('.')
51 51 pname = pname[:i]
52 52 parent = sys.modules[pname]
53 53 assert parent.__name__ == pname
54 54 return parent
55 55 return None
56 56
57 57 def find_head_package(parent, name):
58 58 # Import the first
59 59 if '.' in name:
60 60 # 'some.nested.package' -> head = 'some', tail = 'nested.package'
61 61 i = name.find('.')
62 62 head = name[:i]
63 63 tail = name[i+1:]
64 64 else:
65 65 # 'packagename' -> head = 'packagename', tail = ''
66 66 head = name
67 67 tail = ""
68 68 if parent:
69 69 # If this is a subpackage then qname = parent's name + head
70 70 qname = "%s.%s" % (parent.__name__, head)
71 71 else:
72 72 qname = head
73 73 q = import_module(head, qname, parent)
74 74 if q: return q, tail
75 75 if parent:
76 76 qname = head
77 77 parent = None
78 78 q = import_module(head, qname, parent)
79 79 if q: return q, tail
80 80 raise ImportError, "No module named " + qname
81 81
82 82 def load_tail(q, tail):
83 83 m = q
84 84 while tail:
85 85 i = tail.find('.')
86 86 if i < 0: i = len(tail)
87 87 head, tail = tail[:i], tail[i+1:]
88 88
89 89 # fperez: fix dotted.name reloading failures by changing:
90 90 #mname = "%s.%s" % (m.__name__, head)
91 91 # to:
92 92 mname = m.__name__
93 93 # This needs more testing!!! (I don't understand this module too well)
94 94
95 95 #print '** head,tail=|%s|->|%s|, mname=|%s|' % (head,tail,mname) # dbg
96 96 m = import_module(head, mname, m)
97 97 if not m:
98 98 raise ImportError, "No module named " + mname
99 99 return m
100 100
101 101 def ensure_fromlist(m, fromlist, recursive=0):
102 102 for sub in fromlist:
103 103 if sub == "*":
104 104 if not recursive:
105 105 try:
106 106 all = m.__all__
107 107 except AttributeError:
108 108 pass
109 109 else:
110 110 ensure_fromlist(m, all, 1)
111 111 continue
112 112 if sub != "*" and not hasattr(m, sub):
113 113 subname = "%s.%s" % (m.__name__, sub)
114 114 submod = import_module(sub, subname, m)
115 115 if not submod:
116 116 raise ImportError, "No module named " + subname
117 117
118 118 # Need to keep track of what we've already reloaded to prevent cyclic evil
119 119 found_now = {}
120 120
121 121 def import_module(partname, fqname, parent):
122 122 global found_now
123 123 if found_now.has_key(fqname):
124 124 try:
125 125 return sys.modules[fqname]
126 126 except KeyError:
127 127 pass
128 128
129 129 print 'Reloading', fqname #, sys.excepthook is sys.__excepthook__, \
130 130 #sys.displayhook is sys.__displayhook__
131 131
132 132 found_now[fqname] = 1
133 133 try:
134 134 fp, pathname, stuff = imp.find_module(partname,
135 135 parent and parent.__path__)
136 136 except ImportError:
137 137 return None
138 138
139 139 try:
140 140 m = imp.load_module(fqname, fp, pathname, stuff)
141 141 finally:
142 142 if fp: fp.close()
143 143
144 144 if parent:
145 145 setattr(parent, partname, m)
146 146
147 147 return m
148 148
149 149 def deep_reload_hook(module):
150 150 name = module.__name__
151 151 if '.' not in name:
152 152 return import_module(name, name, None)
153 153 i = name.rfind('.')
154 154 pname = name[:i]
155 155 parent = sys.modules[pname]
156 156 return import_module(name[i+1:], name, parent)
157 157
158 158 # Save the original hooks
159 159 original_reload = __builtin__.reload
160 160
161 161 # Replacement for reload()
162 162 def reload(module, exclude=['sys', '__builtin__', '__main__']):
163 163 """Recursively reload all modules used in the given module. Optionally
164 164 takes a list of modules to exclude from reloading. The default exclude
165 165 list contains sys, __main__, and __builtin__, to prevent, e.g., resetting
166 166 display, exception, and io hooks.
167 167 """
168 168 global found_now
169 169 for i in exclude:
170 170 found_now[i] = 1
171 171 original_import = __builtin__.__import__
172 172 __builtin__.__import__ = deep_import_hook
173 173 try:
174 174 ret = deep_reload_hook(module)
175 175 finally:
176 176 __builtin__.__import__ = original_import
177 177 found_now = {}
178 178 return ret
179 179
180 180 # Uncomment the following to automatically activate deep reloading whenever
181 181 # this module is imported
182 182 #__builtin__.reload = reload
@@ -1,6 +1,9 b''
1 1 #!/usr/bin/env python
2 2 # encoding: utf-8
3 3
4 4 def test_import_backgroundjobs():
5 5 from IPython.lib import backgroundjobs
6 6
7 def test_import_deepreload():
8 from IPython.lib import deepreload
9
@@ -1,300 +1,300 b''
1 1 # -*- coding: utf-8 -*-
2 2 """IPython Test Suite Runner.
3 3
4 4 This module provides a main entry point to a user script to test IPython
5 5 itself from the command line. There are two ways of running this script:
6 6
7 7 1. With the syntax `iptest all`. This runs our entire test suite by
8 8 calling this script (with different arguments) or trial recursively. This
9 9 causes modules and package to be tested in different processes, using nose
10 10 or trial where appropriate.
11 11 2. With the regular nose syntax, like `iptest -vvs IPython`. In this form
12 12 the script simply calls nose, but with special command line flags and
13 13 plugins loaded.
14 14
15 15 For now, this script requires that both nose and twisted are installed. This
16 16 will change in the future.
17 17 """
18 18
19 19 #-----------------------------------------------------------------------------
20 20 # Module imports
21 21 #-----------------------------------------------------------------------------
22 22
23 23 import os
24 24 import os.path as path
25 25 import sys
26 26 import subprocess
27 27 import time
28 28 import warnings
29 29
30 30 import nose.plugins.builtin
31 31 from nose.core import TestProgram
32 32
33 33 from IPython.platutils import find_cmd
34 34 from IPython.testing.plugin.ipdoctest import IPythonDoctest
35 35
36 36 pjoin = path.join
37 37
38 38 #-----------------------------------------------------------------------------
39 39 # Logic for skipping doctests
40 40 #-----------------------------------------------------------------------------
41 41
42 42 def test_for(mod):
43 43 """Test to see if mod is importable."""
44 44 try:
45 45 __import__(mod)
46 46 except ImportError:
47 47 return False
48 48 else:
49 49 return True
50 50
51 51 have_curses = test_for('_curses')
52 52 have_wx = test_for('wx')
53 53 have_zi = test_for('zope.interface')
54 54 have_twisted = test_for('twisted')
55 55 have_foolscap = test_for('foolscap')
56 56 have_objc = test_for('objc')
57 57 have_pexpect = test_for('pexpect')
58 58
59 59 # For the IPythonDoctest plugin, we need to exclude certain patterns that cause
60 60 # testing problems. We should strive to minimize the number of skipped
61 61 # modules, since this means untested code. As the testing machinery
62 62 # solidifies, this list should eventually become empty.
63 63 EXCLUDE = [pjoin('IPython', 'external'),
64 64 pjoin('IPython', 'frontend', 'process', 'winprocess.py'),
65 65 pjoin('IPython_doctest_plugin'),
66 66 pjoin('IPython', 'Gnuplot'),
67 67 pjoin('IPython', 'Extensions', 'ipy_'),
68 68 pjoin('IPython', 'Extensions', 'clearcmd'),
69 69 pjoin('IPython', 'Extensions', 'PhysicalQInteractive'),
70 70 pjoin('IPython', 'Extensions', 'scitedirector'),
71 71 pjoin('IPython', 'Extensions', 'numeric_formats'),
72 72 pjoin('IPython', 'testing', 'attic'),
73 73 pjoin('IPython', 'testing', 'tutils'),
74 74 pjoin('IPython', 'testing', 'tools'),
75 75 pjoin('IPython', 'testing', 'mkdoctests')
76 76 ]
77 77
78 78 if not have_wx:
79 79 EXCLUDE.append(pjoin('IPython', 'Extensions', 'igrid'))
80 80 EXCLUDE.append(pjoin('IPython', 'gui'))
81 81 EXCLUDE.append(pjoin('IPython', 'frontend', 'wx'))
82 82
83 83 if not have_objc:
84 84 EXCLUDE.append(pjoin('IPython', 'frontend', 'cocoa'))
85 85
86 86 if not have_curses:
87 87 EXCLUDE.append(pjoin('IPython', 'Extensions', 'ibrowse'))
88 88
89 89 if not sys.platform == 'win32':
90 90 EXCLUDE.append(pjoin('IPython', 'platutils_win32'))
91 91
92 92 # These have to be skipped on win32 because the use echo, rm, cd, etc.
93 93 # See ticket https://bugs.launchpad.net/bugs/366982
94 94 if sys.platform == 'win32':
95 95 EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'test_exampleip'))
96 96 EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'dtexample'))
97 97
98 98 if not os.name == 'posix':
99 99 EXCLUDE.append(pjoin('IPython', 'platutils_posix'))
100 100
101 101 if not have_pexpect:
102 102 EXCLUDE.append(pjoin('IPython', 'irunner'))
103 103
104 104 # This is needed for the reg-exp to match on win32 in the ipdoctest plugin.
105 105 if sys.platform == 'win32':
106 106 EXCLUDE = [s.replace('\\','\\\\') for s in EXCLUDE]
107 107
108 108
109 109 #-----------------------------------------------------------------------------
110 110 # Functions and classes
111 111 #-----------------------------------------------------------------------------
112 112
113 113 def run_iptest():
114 114 """Run the IPython test suite using nose.
115 115
116 116 This function is called when this script is **not** called with the form
117 117 `iptest all`. It simply calls nose with appropriate command line flags
118 118 and accepts all of the standard nose arguments.
119 119 """
120 120
121 121 warnings.filterwarnings('ignore',
122 122 'This will be removed soon. Use IPython.testing.util instead')
123 123
124 124 argv = sys.argv + [
125 125 # Loading ipdoctest causes problems with Twisted.
126 126 # I am removing this as a temporary fix to get the
127 127 # test suite back into working shape. Our nose
128 128 # plugin needs to be gone through with a fine
129 129 # toothed comb to find what is causing the problem.
130 130 '--with-ipdoctest',
131 131 '--ipdoctest-tests','--ipdoctest-extension=txt',
132 132 '--detailed-errors',
133 133
134 134 # We add --exe because of setuptools' imbecility (it
135 135 # blindly does chmod +x on ALL files). Nose does the
136 136 # right thing and it tries to avoid executables,
137 137 # setuptools unfortunately forces our hand here. This
138 138 # has been discussed on the distutils list and the
139 139 # setuptools devs refuse to fix this problem!
140 140 '--exe',
141 141 ]
142 142
143 143 # Detect if any tests were required by explicitly calling an IPython
144 144 # submodule or giving a specific path
145 145 has_tests = False
146 146 for arg in sys.argv:
147 147 if 'IPython' in arg or arg.endswith('.py') or \
148 148 (':' in arg and '.py' in arg):
149 149 has_tests = True
150 150 break
151 151
152 152 # If nothing was specifically requested, test full IPython
153 153 if not has_tests:
154 154 argv.append('IPython')
155 155
156 156 # Construct list of plugins, omitting the existing doctest plugin, which
157 157 # ours replaces (and extends).
158 158 plugins = [IPythonDoctest(EXCLUDE)]
159 159 for p in nose.plugins.builtin.plugins:
160 160 plug = p()
161 161 if plug.name == 'doctest':
162 162 continue
163 163
164 164 #print '*** adding plugin:',plug.name # dbg
165 165 plugins.append(plug)
166 166
167 167 TestProgram(argv=argv,plugins=plugins)
168 168
169 169
170 170 class IPTester(object):
171 171 """Call that calls iptest or trial in a subprocess.
172 172 """
173 173 def __init__(self,runner='iptest',params=None):
174 174 """ """
175 175 if runner == 'iptest':
176 176 self.runner = ['iptest','-v']
177 177 else:
178 178 self.runner = [find_cmd('trial')]
179 179 if params is None:
180 180 params = []
181 181 if isinstance(params,str):
182 182 params = [params]
183 183 self.params = params
184 184
185 185 # Assemble call
186 186 self.call_args = self.runner+self.params
187 187
188 188 def run(self):
189 189 """Run the stored commands"""
190 190 return subprocess.call(self.call_args)
191 191
192 192
193 193 def make_runners():
194 194 """Define the modules and packages that need to be tested.
195 195 """
196 196
197 197 # This omits additional top-level modules that should not be doctested.
198 198 # XXX: Shell.py is also ommited because of a bug in the skip_doctest
199 199 # decorator. See ticket https://bugs.launchpad.net/bugs/366209
200 200 top_mod = \
201 201 ['backgroundjobs.py', 'coloransi.py', 'completer.py', 'configloader.py',
202 'crashhandler.py', 'debugger.py', 'deep_reload.py', 'demo.py',
202 'crashhandler.py', 'debugger.py', 'deepreload.py', 'demo.py',
203 203 'DPyGetOpt.py', 'dtutils.py', 'excolors.py', 'FakeModule.py',
204 204 'generics.py', 'genutils.py', 'history.py', 'hooks.py', 'ipapi.py',
205 205 'iplib.py', 'ipmaker.py', 'ipstruct.py', 'Itpl.py',
206 206 'Logger.py', 'macro.py', 'Magic.py', 'OInspect.py',
207 207 'OutputTrap.py', 'platutils.py', 'prefilter.py', 'Prompts.py',
208 208 'PyColorize.py', 'Release.py', 'rlineimpl.py', 'shadowns.py',
209 209 'shellglobals.py', 'strdispatch.py', 'twshell.py',
210 210 'ultraTB.py', 'upgrade_dir.py', 'usage.py', 'wildcard.py',
211 211 # See note above for why this is skipped
212 212 # 'Shell.py',
213 213 'winconsole.py']
214 214
215 215 if have_pexpect:
216 216 top_mod.append('irunner.py')
217 217
218 218 if sys.platform == 'win32':
219 219 top_mod.append('platutils_win32.py')
220 220 elif os.name == 'posix':
221 221 top_mod.append('platutils_posix.py')
222 222 else:
223 223 top_mod.append('platutils_dummy.py')
224 224
225 225 # These are tested by nose, so skip IPython.kernel
226 226 top_pack = ['config','Extensions','frontend',
227 227 'testing','tests','tools','UserConfig']
228 228
229 229 if have_wx:
230 230 top_pack.append('gui')
231 231
232 232 modules = ['IPython.%s' % m[:-3] for m in top_mod ]
233 233 packages = ['IPython.%s' % m for m in top_pack ]
234 234
235 235 # Make runners
236 236 runners = dict(zip(top_pack, [IPTester(params=v) for v in packages]))
237 237
238 238 # Test IPython.kernel using trial if twisted is installed
239 239 if have_zi and have_twisted and have_foolscap:
240 240 runners['trial'] = IPTester('trial',['IPython'])
241 241
242 242 runners['modules'] = IPTester(params=modules)
243 243
244 244 return runners
245 245
246 246
247 247 def run_iptestall():
248 248 """Run the entire IPython test suite by calling nose and trial.
249 249
250 250 This function constructs :class:`IPTester` instances for all IPython
251 251 modules and package and then runs each of them. This causes the modules
252 252 and packages of IPython to be tested each in their own subprocess using
253 253 nose or twisted.trial appropriately.
254 254 """
255 255 runners = make_runners()
256 256 # Run all test runners, tracking execution time
257 257 failed = {}
258 258 t_start = time.time()
259 259 for name,runner in runners.iteritems():
260 260 print '*'*77
261 261 print 'IPython test set:',name
262 262 res = runner.run()
263 263 if res:
264 264 failed[name] = res
265 265 t_end = time.time()
266 266 t_tests = t_end - t_start
267 267 nrunners = len(runners)
268 268 nfail = len(failed)
269 269 # summarize results
270 270 print
271 271 print '*'*77
272 272 print 'Ran %s test sets in %.3fs' % (nrunners, t_tests)
273 273 print
274 274 if not failed:
275 275 print 'OK'
276 276 else:
277 277 # If anything went wrong, point out what command to rerun manually to
278 278 # see the actual errors and individual summary
279 279 print 'ERROR - %s out of %s test sets failed.' % (nfail, nrunners)
280 280 for name in failed:
281 281 failed_runner = runners[name]
282 282 print '-'*40
283 283 print 'Runner failed:',name
284 284 print 'You may wish to rerun this one individually, with:'
285 285 print ' '.join(failed_runner.call_args)
286 286 print
287 287
288 288
289 289 def main():
290 290 if len(sys.argv) == 1:
291 291 run_iptestall()
292 292 else:
293 293 if sys.argv[1] == 'all':
294 294 run_iptestall()
295 295 else:
296 296 run_iptest()
297 297
298 298
299 299 if __name__ == '__main__':
300 300 main() No newline at end of file
@@ -1,242 +1,246 b''
1 1 =============================
2 2 IPython module reorganization
3 3 =============================
4 4
5 5 Currently, IPython has many top-level modules that serve many different purposes.
6 6 The lack of organization make it very difficult for developers to work on IPython
7 7 and understand its design. This document contains notes about how we will reorganize
8 8 the modules into sub-packages.
9 9
10 10 .. warning::
11 11
12 12 This effort will possibly break third party packages that use IPython as
13 13 a library or hack on the IPython internals.
14 14
15 15 .. warning::
16 16
17 17 This effort will result in the removal from IPython of certain modules
18 18 that are not used anymore, don't currently work, are unmaintained, etc.
19 19
20 20
21 21 Current subpackges
22 22 ==================
23 23
24 24 IPython currently has the following sub-packages:
25 25
26 26 * :mod:`IPython.config`
27 27
28 28 * :mod:`IPython.Extensions`
29 29
30 30 * :mod:`IPython.external`
31 31
32 32 * :mod:`IPython.frontend`
33 33
34 34 * :mod:`IPython.gui`
35 35
36 36 * :mod:`IPython.kernel`
37 37
38 38 * :mod:`IPython.testing`
39 39
40 40 * :mod:`IPython.tests`
41 41
42 42 * :mod:`IPython.tools`
43 43
44 44 * :mod:`IPython.UserConfig`
45 45
46 46 New Subpackages to be created
47 47 =============================
48 48
49 49 We propose to create the following new sub-packages:
50 50
51 51 * :mod:`IPython.core`. This sub-package will contain the core of the IPython
52 52 interpreter, but none of its extended capabilities.
53 53
54 54 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
55 55 of the IPython core. These things will go here. Any better names than
56 56 :mod:`IPython.lib`?
57 57
58 58 * :mod:`IPython.utils`. This sub-package will contain anything that might
59 59 eventually be found in the Python standard library, like things in
60 60 :mod:`genutils`. Each sub-module in this sub-package should contain
61 61 functions and classes that serve a single purpose.
62 62
63 63 * :mod:`IPython.deathrow`. This is for code that is untested and/or rotting
64 64 and needs to be removed from IPython. Eventually all this code will either
65 65 i) be revived by someone willing to maintain it with tests and docs and
66 66 re-included into IPython or 2) be removed from IPython proper, but put into
67 67 a separate top-level (not IPython) package that we keep around. No new code
68 68 will be allowed here.
69 69
70 70 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
71 71 standards, but that we plan on keeping. To be moved out of this sub-package
72 72 a module needs to have a maintainer, tests and documentation.
73 73
74 74 Prodecure
75 75 =========
76 76
77 77 1. Move the file to its new location with its new name.
78 78 2. Rename all import statements to reflect the change.
79 79 3. Run PyFlakes on each changes module.
80 80 3. Add tests/test_imports.py to test it.
81 81
82 82 Need to modify iptests to properly skip modules that are no longer top
83 83 level modules.
84 84
85 Need to update the top level IPython/__init__.py file.
86
85 87 Where things will be moved
86 88 ==========================
87 89
88 90 * :file:`background_jobs.py`. Move to :file:`IPython/lib/backgroundjobs.py`.
89 91
90 92 * :file:`ColorANSI.py`. Move to :file:`IPython/utils/coloransi.py`.
91 93
92 94 * :file:`completer.py`. Move to :file:`IPython/core/completer.py`.
93 95
94
95 96 * :file:`ConfigLoader.py`. Move to :file:`IPython/config/configloader.py`.
96 97
97 98 * :file:`CrashHandler.py`. Move to :file:`IPython/core/crashhandler`.
98 99
99 * :file:`DPyGetOpt.py`. Move to :mod:`IPython.sandbox` and replace with newer options parser.
100
101 100 * :file:`Debugger.py`. Move to :file:`IPython/core/debugger.py`.
102 101
102 * :file:`deep_reload.py`. Move to :file:`IPython/lib/deepreload.py`.
103
104
105
106 * :file:`DPyGetOpt.py`. Move to :mod:`IPython.sandbox` and replace with newer options parser.
107
103 108 * :file:`Extensions`. This needs to be gone through separately. Minimally,
104 109 the package should be renamed to :file:`extensions`.
105 110
106 111 * :file:`FakeModule.py`. Move to :file:`IPython/core/fakemodule.py`.
107 112
108 113 * :file:`Gnuplot2.py`. Move to :file:`IPython.sandbox`.
109 114
110 115 * :file:`GnuplotInteractive.py`. Move to :file:`IPython.sandbox`.
111 116
112 117 * :file:`GnuplotRuntime.py`. Move to :file:`IPython.sandbox`.
113 118
114 119 * :file:`Itpl.py`. Remove. Version already in :file:`IPython.external`.
115 120
116 121 * :file:`Logger.py`. Move to :file:`IPython/core/logger.py`.
117 122
118 123 * :file:`Magic.py`. Move to :file:`IPython/core/magic.py`.
119 124
120 125 * :file:`OInspect.py`. Move to :file:`IPython/core/oinspect.py`.
121 126
122 127 * :file:`OutputTrap.py`. Move to :file:`IPython/core/outputtrap.py`.
123 128
124 129 * :file:`Prompts.py`. Move to :file:`IPython/core/prompts.py` or
125 130 :file:`IPython/frontend/prompts.py`.
126 131
127 132 * :file:`PyColorize.py`. Replace with pygments? If not, move to
128 133 :file:`IPython/core/pycolorize.py`. Maybe move to :mod:`IPython.lib` or
129 134 :mod:`IPython.python`?
130 135
131 136 * :file:`Release.py`. Move to ??? or remove?
132 137
133 138 * :file:`Shell.py`. Move to :file:`IPython.core.shell.py` or
134 139 :file:`IPython/frontend/shell.py`.
135 140
136 141 * :file:`UserConfig`. Move to a subdirectory of :file:`IPython.config`.
137 142
138 143
139 144
140 145
141 146 * :file:`config`. Good where it is!
142 147
143 * :file:`deep_reload.py`. Move to :file:`IPython/lib/deepreload.py`.
144 148
145 149 * :file:`demo.py`. Move to :file:`IPython/lib/demo.py`.
146 150
147 151 * :file:`dtutils.py`. Remove or move to :file:`IPython.testing` or
148 152 :file:`IPython.lib`.
149 153
150 154 * :file:`excolors.py`. Move to :file:`IPython.core` or :file:`IPython.config`.
151 155 Maybe move to :mod:`IPython.lib` or :mod:`IPython.python`?
152 156
153 157 * :file:`external`. Good where it is!
154 158
155 159 * :file:`frontend`. Good where it is!
156 160
157 161 * :file:`generics.py`. Move to :file:`IPython.python`.
158 162
159 163 * :file:`genutils.py`. Move to :file:`IPython.python` and break up into different
160 164 modules.
161 165
162 166 * :file:`gui`. Eventually this should be moved to a subdir of
163 167 :file:`IPython.frontend`.
164 168
165 169 * :file:`history.py`. Move to :file:`IPython.core`.
166 170
167 171 * :file:`hooks.py`. Move to :file:`IPython.core`.
168 172
169 173 * :file:`ipapi.py`. Move to :file:`IPython.core`.
170 174
171 175 * :file:`iplib.py`. Move to :file:`IPython.core`.
172 176
173 177 * :file:`ipmaker.py`: Move to :file:`IPython.core`.
174 178
175 179 * :file:`ipstruct.py`. Move to :file:`IPython.python`.
176 180
177 181 * :file:`irunner.py`. Move to :file:`IPython.scripts`.
178 182
179 183 * :file:`kernel`. Good where it is.
180 184
181 185 * :file:`macro.py`. Move to :file:`IPython.core`.
182 186
183 187 * :file:`numutils.py`. Move to :file:`IPython.sandbox`.
184 188
185 189 * :file:`platutils.py`. Move to :file:`IPython.python`.
186 190
187 191 * :file:`platutils_dummy.py`. Move to :file:`IPython.python`.
188 192
189 193 * :file:`platutils_posix.py`. Move to :file:`IPython.python`.
190 194
191 195 * :file:`platutils_win32.py`. Move to :file:`IPython.python`.
192 196
193 197 * :file:`prefilter.py`: Move to :file:`IPython.core`.
194 198
195 199 * :file:`rlineimpl.py`. Move to :file:`IPython.core`.
196 200
197 201 * :file:`shadowns.py`. Move to :file:`IPython.core`.
198 202
199 203 * :file:`shellglobals.py`. Move to :file:`IPython.core`.
200 204
201 205 * :file:`strdispatch.py`. Move to :file:`IPython.python`.
202 206
203 207 * :file:`testing`. Good where it is.
204 208
205 209 * :file:`tests`. Good where it is.
206 210
207 211 * :file:`tools`. Things in here need to be looked at and moved elsewhere like
208 212 :file:`IPython.python`.
209 213
210 214 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
211 215
212 216 * :file:`ultraTB.py`. Move to :file:`IPython/core/ultratb.py`.
213 217
214 218 * :file:`upgrade_dir.py`. Move to :file:`IPython/python/upgradedir.py`.
215 219
216 220 * :file:`usage.py`. Move to :file:`IPython.core`.
217 221
218 222 * :file:`wildcard.py`. Move to :file:`IPython.python` or :file:`IPython.core`.
219 223
220 224 * :file:`winconsole.py`. Move to :file:`IPython.lib`.
221 225
222 226 Other things
223 227 ============
224 228
225 229 When these files are moved around, a number of other things will happen at the same time:
226 230
227 231 1. Test files will be created for each module in IPython. Minimally, all
228 232 modules will be imported as a part of the test. This will serve as a
229 233 test of the module reorganization. These tests will be put into new
230 234 :file:`tests` subdirectories that each package will have.
231 235
232 236 2. PyFlakes and other code checkers will be run to look for problems.
233 237
234 238 3. Modules will be renamed to comply with PEP 8 naming conventions: all
235 239 lowercase and no special characters like ``-`` or ``_``.
236 240
237 241 4. Existing tests will be moved to the appropriate :file:`tests`
238 242 subdirectories.
239 243
240 244
241 245
242 246
General Comments 0
You need to be logged in to leave comments. Login now