##// END OF EJS Templates
Turn quit/exit into magics instead of special-cased strings
fperez -
Show More
@@ -1,2579 +1,2592 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 960 2005-12-28 06:51:01Z fperez $"""
4 $Id: Magic.py 962 2005-12-28 18:04:59Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
8 8 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
9 9 #
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #*****************************************************************************
13 13
14 14 #****************************************************************************
15 15 # Modules and globals
16 16
17 17 from IPython import Release
18 18 __author__ = '%s <%s>\n%s <%s>' % \
19 19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
20 20 __license__ = Release.license
21 21
22 22 # Python standard modules
23 23 import __builtin__
24 24 import bdb
25 25 import inspect
26 26 import os
27 27 import pdb
28 28 import pydoc
29 29 import sys
30 30 import re
31 31 import tempfile
32 32 import time
33 33 from cStringIO import StringIO
34 34 from getopt import getopt
35 35 from pprint import pprint, pformat
36 36
37 37 # profile isn't bundled by default in Debian for license reasons
38 38 try:
39 39 import profile,pstats
40 40 except ImportError:
41 41 profile = pstats = None
42 42
43 43 # Homebrewed
44 44 from IPython import Debugger, OInspect, wildcard
45 45 from IPython.FakeModule import FakeModule
46 46 from IPython.Itpl import Itpl, itpl, printpl,itplns
47 47 from IPython.PyColorize import Parser
48 48 from IPython.Struct import Struct
49 49 from IPython.genutils import *
50 50
51 51 # Globals to be set later by Magic constructor
52 52 MAGIC_PREFIX = ''
53 53 MAGIC_ESCAPE = ''
54 54
55 55 #***************************************************************************
56 56 # Utility functions
57 57 def magic2python(cmd):
58 58 """Convert a command string of magic syntax to valid Python code."""
59 59
60 60 if cmd.startswith('#'+MAGIC_ESCAPE) or \
61 61 cmd.startswith(MAGIC_ESCAPE):
62 62 if cmd[0]=='#':
63 63 cmd = cmd[1:]
64 64 # we need to return the proper line end later
65 65 if cmd[-1] == '\n':
66 66 endl = '\n'
67 67 else:
68 68 endl = ''
69 69 try:
70 70 func,args = cmd[1:].split(' ',1)
71 71 except:
72 72 func,args = cmd[1:].rstrip(),''
73 73 args = args.replace('"','\\"').replace("'","\\'").rstrip()
74 74 return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl)
75 75 else:
76 76 return cmd
77 77
78 78 def on_off(tag):
79 79 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
80 80 return ['OFF','ON'][tag]
81 81
82 82
83 83 #****************************************************************************
84 84 # Utility classes
85 85 class Macro:
86 86 """Simple class to store the value of macros as strings.
87 87
88 88 This allows us to later exec them by checking when something is an
89 89 instance of this class."""
90 90
91 91 def __init__(self,cmds):
92 92 """Build a macro from a list of commands."""
93 93
94 94 # Since the list may include multi-line entries, first make sure that
95 95 # they've been all broken up before passing it to magic2python
96 96 cmdlist = map(magic2python,''.join(cmds).split('\n'))
97 97 self.value = '\n'.join(cmdlist)
98 98
99 99 def __str__(self):
100 100 return self.value
101 101
102 102 #***************************************************************************
103 103 # Main class implementing Magic functionality
104 104 class Magic:
105 105 """Magic functions for InteractiveShell.
106 106
107 107 Shell functions which can be reached as %function_name. All magic
108 108 functions should accept a string, which they can parse for their own
109 109 needs. This can make some functions easier to type, eg `%cd ../`
110 110 vs. `%cd("../")`
111 111
112 112 ALL definitions MUST begin with the prefix magic_. The user won't need it
113 113 at the command line, but it is is needed in the definition. """
114 114
115 115 # class globals
116 116 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
117 117 'Automagic is ON, % prefix NOT needed for magic functions.']
118 118
119 119 #......................................................................
120 120 # some utility functions
121 121
122 122 def __init__(self,shell):
123 123 # XXX This is hackish, clean up later to avoid these messy globals
124 124 global MAGIC_PREFIX, MAGIC_ESCAPE
125 125
126 126 self.options_table = {}
127 127 MAGIC_PREFIX = shell.name+'.magic_'
128 128 MAGIC_ESCAPE = shell.ESC_MAGIC
129 129 if profile is None:
130 130 self.magic_prun = self.profile_missing_notice
131 131
132 132 def profile_missing_notice(self, *args, **kwargs):
133 133 error("""\
134 134 The profile module could not be found. If you are a Debian user,
135 135 it has been removed from the standard Debian package because of its non-free
136 136 license. To use profiling, please install"python2.3-profiler" from non-free.""")
137 137
138 138 def default_option(self,fn,optstr):
139 139 """Make an entry in the options_table for fn, with value optstr"""
140 140
141 141 if fn not in self.lsmagic():
142 142 error("%s is not a magic function" % fn)
143 143 self.options_table[fn] = optstr
144 144
145 145 def lsmagic(self):
146 146 """Return a list of currently available magic functions.
147 147
148 148 Gives a list of the bare names after mangling (['ls','cd', ...], not
149 149 ['magic_ls','magic_cd',...]"""
150 150
151 151 # FIXME. This needs a cleanup, in the way the magics list is built.
152 152
153 153 # magics in class definition
154 154 class_magic = lambda fn: fn.startswith('magic_') and \
155 155 callable(Magic.__dict__[fn])
156 156 # in instance namespace (run-time user additions)
157 157 inst_magic = lambda fn: fn.startswith('magic_') and \
158 158 callable(self.__dict__[fn])
159 159 # and bound magics by user (so they can access self):
160 160 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
161 161 callable(self.__class__.__dict__[fn])
162 162 magics = filter(class_magic,Magic.__dict__.keys()) + \
163 163 filter(inst_magic,self.__dict__.keys()) + \
164 164 filter(inst_bound_magic,self.__class__.__dict__.keys())
165 165 out = []
166 166 for fn in magics:
167 167 out.append(fn.replace('magic_','',1))
168 168 out.sort()
169 169 return out
170 170
171 171 def set_shell(self,shell):
172 172 self.shell = shell
173 173 self.alias_table = shell.alias_table
174 174
175 175 def extract_input_slices(self,slices):
176 176 """Return as a string a set of input history slices.
177 177
178 178 The set of slices is given as a list of strings (like ['1','4:8','9'],
179 179 since this function is for use by magic functions which get their
180 180 arguments as strings."""
181 181
182 182 cmds = []
183 183 for chunk in slices:
184 184 if ':' in chunk:
185 185 ini,fin = map(int,chunk.split(':'))
186 186 else:
187 187 ini = int(chunk)
188 188 fin = ini+1
189 189 cmds.append(self.shell.input_hist[ini:fin])
190 190 return cmds
191 191
192 192 def _ofind(self,oname):
193 193 """Find an object in the available namespaces.
194 194
195 195 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
196 196
197 197 Has special code to detect magic functions.
198 198 """
199 199
200 200 oname = oname.strip()
201 201
202 202 # Namespaces to search in:
203 203 user_ns = self.shell.user_ns
204 204 internal_ns = self.shell.internal_ns
205 205 builtin_ns = __builtin__.__dict__
206 206 alias_ns = self.shell.alias_table
207 207
208 208 # Put them in a list. The order is important so that we find things in
209 209 # the same order that Python finds them.
210 210 namespaces = [ ('Interactive',user_ns),
211 211 ('IPython internal',internal_ns),
212 212 ('Python builtin',builtin_ns),
213 213 ('Alias',alias_ns),
214 214 ]
215 215
216 216 # initialize results to 'null'
217 217 found = 0; obj = None; ospace = None; ds = None;
218 218 ismagic = 0; isalias = 0
219 219
220 220 # Look for the given name by splitting it in parts. If the head is
221 221 # found, then we look for all the remaining parts as members, and only
222 222 # declare success if we can find them all.
223 223 oname_parts = oname.split('.')
224 224 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
225 225 for nsname,ns in namespaces:
226 226 try:
227 227 obj = ns[oname_head]
228 228 except KeyError:
229 229 continue
230 230 else:
231 231 for part in oname_rest:
232 232 try:
233 233 obj = getattr(obj,part)
234 234 except:
235 235 # Blanket except b/c some badly implemented objects
236 236 # allow __getattr__ to raise exceptions other than
237 237 # AttributeError, which then crashes IPython.
238 238 break
239 239 else:
240 240 # If we finish the for loop (no break), we got all members
241 241 found = 1
242 242 ospace = nsname
243 243 if ns == alias_ns:
244 244 isalias = 1
245 245 break # namespace loop
246 246
247 247 # Try to see if it's magic
248 248 if not found:
249 249 if oname.startswith(self.shell.ESC_MAGIC):
250 250 oname = oname[1:]
251 251 obj = getattr(self,'magic_'+oname,None)
252 252 if obj is not None:
253 253 found = 1
254 254 ospace = 'IPython internal'
255 255 ismagic = 1
256 256
257 257 # Last try: special-case some literals like '', [], {}, etc:
258 258 if not found and oname_head in ["''",'""','[]','{}','()']:
259 259 obj = eval(oname_head)
260 260 found = 1
261 261 ospace = 'Interactive'
262 262
263 263 return {'found':found, 'obj':obj, 'namespace':ospace,
264 264 'ismagic':ismagic, 'isalias':isalias}
265 265
266 266 def arg_err(self,func):
267 267 """Print docstring if incorrect arguments were passed"""
268 268 print 'Error in arguments:'
269 269 print OInspect.getdoc(func)
270 270
271 271
272 272 def format_latex(self,str):
273 273 """Format a string for latex inclusion."""
274 274
275 275 # Characters that need to be escaped for latex:
276 276 escape_re = re.compile(r'(%|_|\$)',re.MULTILINE)
277 277 # Magic command names as headers:
278 278 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
279 279 re.MULTILINE)
280 280 # Magic commands
281 281 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
282 282 re.MULTILINE)
283 283 # Paragraph continue
284 284 par_re = re.compile(r'\\$',re.MULTILINE)
285 285
286 286 str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str)
287 287 str = cmd_re.sub(r'\\texttt{\g<cmd>}',str)
288 288 str = par_re.sub(r'\\\\',str)
289 289 str = escape_re.sub(r'\\\1',str)
290 290 return str
291 291
292 292 def format_screen(self,str):
293 293 """Format a string for screen printing.
294 294
295 295 This removes some latex-type format codes."""
296 296 # Paragraph continue
297 297 par_re = re.compile(r'\\$',re.MULTILINE)
298 298 str = par_re.sub('',str)
299 299 return str
300 300
301 301 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
302 302 """Parse options passed to an argument string.
303 303
304 304 The interface is similar to that of getopt(), but it returns back a
305 305 Struct with the options as keys and the stripped argument string still
306 306 as a string.
307 307
308 308 arg_str is quoted as a true sys.argv vector by using shlex.split.
309 309 This allows us to easily expand variables, glob files, quote
310 310 arguments, etc.
311 311
312 312 Options:
313 313 -mode: default 'string'. If given as 'list', the argument string is
314 314 returned as a list (split on whitespace) instead of a string.
315 315
316 316 -list_all: put all option values in lists. Normally only options
317 317 appearing more than once are put in a list."""
318 318
319 319 # inject default options at the beginning of the input line
320 320 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
321 321 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
322 322
323 323 mode = kw.get('mode','string')
324 324 if mode not in ['string','list']:
325 325 raise ValueError,'incorrect mode given: %s' % mode
326 326 # Get options
327 327 list_all = kw.get('list_all',0)
328 328
329 329 # Check if we have more than one argument to warrant extra processing:
330 330 odict = {} # Dictionary with options
331 331 args = arg_str.split()
332 332 if len(args) >= 1:
333 333 # If the list of inputs only has 0 or 1 thing in it, there's no
334 334 # need to look for options
335 335 argv = shlex_split(arg_str)
336 336 # Do regular option processing
337 337 opts,args = getopt(argv,opt_str,*long_opts)
338 338 for o,a in opts:
339 339 if o.startswith('--'):
340 340 o = o[2:]
341 341 else:
342 342 o = o[1:]
343 343 try:
344 344 odict[o].append(a)
345 345 except AttributeError:
346 346 odict[o] = [odict[o],a]
347 347 except KeyError:
348 348 if list_all:
349 349 odict[o] = [a]
350 350 else:
351 351 odict[o] = a
352 352
353 353 # Prepare opts,args for return
354 354 opts = Struct(odict)
355 355 if mode == 'string':
356 356 args = ' '.join(args)
357 357
358 358 return opts,args
359 359
360 360 #......................................................................
361 361 # And now the actual magic functions
362 362
363 363 # Functions for IPython shell work (vars,funcs, config, etc)
364 364 def magic_lsmagic(self, parameter_s = ''):
365 365 """List currently available magic functions."""
366 366 mesc = self.shell.ESC_MAGIC
367 367 print 'Available magic functions:\n'+mesc+\
368 368 (' '+mesc).join(self.lsmagic())
369 369 print '\n' + Magic.auto_status[self.shell.rc.automagic]
370 370 return None
371 371
372 372 def magic_magic(self, parameter_s = ''):
373 373 """Print information about the magic function system."""
374 374
375 375 mode = ''
376 376 try:
377 377 if parameter_s.split()[0] == '-latex':
378 378 mode = 'latex'
379 379 except:
380 380 pass
381 381
382 382 magic_docs = []
383 383 for fname in self.lsmagic():
384 384 mname = 'magic_' + fname
385 385 for space in (Magic,self,self.__class__):
386 386 try:
387 387 fn = space.__dict__[mname]
388 388 except KeyError:
389 389 pass
390 390 else:
391 391 break
392 392 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
393 393 fname,fn.__doc__))
394 394 magic_docs = ''.join(magic_docs)
395 395
396 396 if mode == 'latex':
397 397 print self.format_latex(magic_docs)
398 398 return
399 399 else:
400 400 magic_docs = self.format_screen(magic_docs)
401 401
402 402 outmsg = """
403 403 IPython's 'magic' functions
404 404 ===========================
405 405
406 406 The magic function system provides a series of functions which allow you to
407 407 control the behavior of IPython itself, plus a lot of system-type
408 408 features. All these functions are prefixed with a % character, but parameters
409 409 are given without parentheses or quotes.
410 410
411 411 NOTE: If you have 'automagic' enabled (via the command line option or with the
412 412 %automagic function), you don't need to type in the % explicitly. By default,
413 413 IPython ships with automagic on, so you should only rarely need the % escape.
414 414
415 415 Example: typing '%cd mydir' (without the quotes) changes you working directory
416 416 to 'mydir', if it exists.
417 417
418 418 You can define your own magic functions to extend the system. See the supplied
419 419 ipythonrc and example-magic.py files for details (in your ipython
420 420 configuration directory, typically $HOME/.ipython/).
421 421
422 422 You can also define your own aliased names for magic functions. In your
423 423 ipythonrc file, placing a line like:
424 424
425 425 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
426 426
427 427 will define %pf as a new name for %profile.
428 428
429 429 You can also call magics in code using the ipmagic() function, which IPython
430 430 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
431 431
432 432 For a list of the available magic functions, use %lsmagic. For a description
433 433 of any of them, type %magic_name?, e.g. '%cd?'.
434 434
435 435 Currently the magic system has the following functions:\n"""
436 436
437 437 mesc = self.shell.ESC_MAGIC
438 438 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
439 439 "\n\n%s%s\n\n%s" % (outmsg,
440 440 magic_docs,mesc,mesc,
441 441 (' '+mesc).join(self.lsmagic()),
442 442 Magic.auto_status[self.shell.rc.automagic] ) )
443 443
444 444 page(outmsg,screen_lines=self.shell.rc.screen_length)
445 445
446 446 def magic_automagic(self, parameter_s = ''):
447 447 """Make magic functions callable without having to type the initial %.
448 448
449 449 Toggles on/off (when off, you must call it as %automagic, of
450 450 course). Note that magic functions have lowest priority, so if there's
451 451 a variable whose name collides with that of a magic fn, automagic
452 452 won't work for that function (you get the variable instead). However,
453 453 if you delete the variable (del var), the previously shadowed magic
454 454 function becomes visible to automagic again."""
455 455
456 456 rc = self.shell.rc
457 457 rc.automagic = not rc.automagic
458 458 print '\n' + Magic.auto_status[rc.automagic]
459 459
460 460 def magic_autocall(self, parameter_s = ''):
461 461 """Make functions callable without having to type parentheses.
462 462
463 463 This toggles the autocall command line option on and off."""
464 464
465 465 rc = self.shell.rc
466 466 rc.autocall = not rc.autocall
467 467 print "Automatic calling is:",['OFF','ON'][rc.autocall]
468 468
469 469 def magic_autoindent(self, parameter_s = ''):
470 470 """Toggle autoindent on/off (if available)."""
471 471
472 472 self.shell.set_autoindent()
473 473 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
474 474
475 475 def magic_system_verbose(self, parameter_s = ''):
476 476 """Toggle verbose printing of system calls on/off."""
477 477
478 478 self.shell.rc_set_toggle('system_verbose')
479 479 print "System verbose printing is:",\
480 480 ['OFF','ON'][self.shell.rc.system_verbose]
481 481
482 482 def magic_history(self, parameter_s = ''):
483 483 """Print input history (_i<n> variables), with most recent last.
484 484
485 485 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
486 486 %history [-n] n -> print at most n inputs\\
487 487 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
488 488
489 489 Each input's number <n> is shown, and is accessible as the
490 490 automatically generated variable _i<n>. Multi-line statements are
491 491 printed starting at a new line for easy copy/paste.
492 492
493 493 If option -n is used, input numbers are not printed. This is useful if
494 494 you want to get a printout of many lines which can be directly pasted
495 495 into a text editor.
496 496
497 497 This feature is only available if numbered prompts are in use."""
498 498
499 499 if not self.do_full_cache:
500 500 print 'This feature is only available if numbered prompts are in use.'
501 501 return
502 502 opts,args = self.parse_options(parameter_s,'n',mode='list')
503 503
504 504 default_length = 40
505 505 if len(args) == 0:
506 506 final = self.outputcache.prompt_count
507 507 init = max(1,final-default_length)
508 508 elif len(args) == 1:
509 509 final = self.outputcache.prompt_count
510 510 init = max(1,final-int(args[0]))
511 511 elif len(args) == 2:
512 512 init,final = map(int,args)
513 513 else:
514 514 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
515 515 print self.magic_hist.__doc__
516 516 return
517 517 width = len(str(final))
518 518 line_sep = ['','\n']
519 519 input_hist = self.shell.input_hist
520 520 print_nums = not opts.has_key('n')
521 521 for in_num in range(init,final):
522 522 inline = input_hist[in_num]
523 523 multiline = inline.count('\n') > 1
524 524 if print_nums:
525 525 print str(in_num).ljust(width)+':'+ line_sep[multiline],
526 526 if inline.startswith('#'+self.shell.ESC_MAGIC) or \
527 527 inline.startswith('#!'):
528 528 print inline[1:],
529 529 else:
530 530 print inline,
531 531
532 532 def magic_hist(self, parameter_s=''):
533 533 """Alternate name for %history."""
534 534 return self.magic_history(parameter_s)
535 535
536 536 def magic_p(self, parameter_s=''):
537 537 """Just a short alias for Python's 'print'."""
538 538 exec 'print ' + parameter_s in self.shell.user_ns
539 539
540 540 def magic_r(self, parameter_s=''):
541 541 """Repeat previous input.
542 542
543 543 If given an argument, repeats the previous command which starts with
544 544 the same string, otherwise it just repeats the previous input.
545 545
546 546 Shell escaped commands (with ! as first character) are not recognized
547 547 by this system, only pure python code and magic commands.
548 548 """
549 549
550 550 start = parameter_s.strip()
551 551 esc_magic = self.shell.ESC_MAGIC
552 552 # Identify magic commands even if automagic is on (which means
553 553 # the in-memory version is different from that typed by the user).
554 554 if self.shell.rc.automagic:
555 555 start_magic = esc_magic+start
556 556 else:
557 557 start_magic = start
558 558 # Look through the input history in reverse
559 559 for n in range(len(self.shell.input_hist)-2,0,-1):
560 560 input = self.shell.input_hist[n]
561 561 # skip plain 'r' lines so we don't recurse to infinity
562 562 if input != 'ipmagic("r")\n' and \
563 563 (input.startswith(start) or input.startswith(start_magic)):
564 564 #print 'match',`input` # dbg
565 565 if input.startswith(esc_magic):
566 566 input = magic2python(input)
567 567 #print 'modified',`input` # dbg
568 568 print 'Executing:',input,
569 569 exec input in self.shell.user_ns
570 570 return
571 571 print 'No previous input matching `%s` found.' % start
572 572
573 573 def magic_page(self, parameter_s=''):
574 574 """Pretty print the object and display it through a pager.
575 575
576 576 If no parameter is given, use _ (last output)."""
577 577 # After a function contributed by Olivier Aubert, slightly modified.
578 578
579 579 oname = parameter_s and parameter_s or '_'
580 580 info = self._ofind(oname)
581 581 if info['found']:
582 582 page(pformat(info['obj']))
583 583 else:
584 584 print 'Object `%s` not found' % oname
585 585
586 586 def magic_profile(self, parameter_s=''):
587 587 """Print your currently active IPyhton profile."""
588 588 if self.shell.rc.profile:
589 589 printpl('Current IPython profile: $self.shell.rc.profile.')
590 590 else:
591 591 print 'No profile active.'
592 592
593 593 def _inspect(self,meth,oname,**kw):
594 594 """Generic interface to the inspector system.
595 595
596 596 This function is meant to be called by pdef, pdoc & friends."""
597 597
598 598 oname = oname.strip()
599 599 info = Struct(self._ofind(oname))
600 600 if info.found:
601 601 pmethod = getattr(self.shell.inspector,meth)
602 602 formatter = info.ismagic and self.format_screen or None
603 603 if meth == 'pdoc':
604 604 pmethod(info.obj,oname,formatter)
605 605 elif meth == 'pinfo':
606 606 pmethod(info.obj,oname,formatter,info,**kw)
607 607 else:
608 608 pmethod(info.obj,oname)
609 609 else:
610 610 print 'Object `%s` not found.' % oname
611 611 return 'not found' # so callers can take other action
612 612
613 613 def magic_pdef(self, parameter_s=''):
614 614 """Print the definition header for any callable object.
615 615
616 616 If the object is a class, print the constructor information."""
617 617 self._inspect('pdef',parameter_s)
618 618
619 619 def magic_pdoc(self, parameter_s=''):
620 620 """Print the docstring for an object.
621 621
622 622 If the given object is a class, it will print both the class and the
623 623 constructor docstrings."""
624 624 self._inspect('pdoc',parameter_s)
625 625
626 626 def magic_psource(self, parameter_s=''):
627 627 """Print (or run through pager) the source code for an object."""
628 628 self._inspect('psource',parameter_s)
629 629
630 630 def magic_pfile(self, parameter_s=''):
631 631 """Print (or run through pager) the file where an object is defined.
632 632
633 633 The file opens at the line where the object definition begins. IPython
634 634 will honor the environment variable PAGER if set, and otherwise will
635 635 do its best to print the file in a convenient form.
636 636
637 637 If the given argument is not an object currently defined, IPython will
638 638 try to interpret it as a filename (automatically adding a .py extension
639 639 if needed). You can thus use %pfile as a syntax highlighting code
640 640 viewer."""
641 641
642 642 # first interpret argument as an object name
643 643 out = self._inspect('pfile',parameter_s)
644 644 # if not, try the input as a filename
645 645 if out == 'not found':
646 646 try:
647 647 filename = get_py_filename(parameter_s)
648 648 except IOError,msg:
649 649 print msg
650 650 return
651 651 page(self.shell.inspector.format(file(filename).read()))
652 652
653 653 def magic_pinfo(self, parameter_s=''):
654 654 """Provide detailed information about an object.
655 655
656 656 '%pinfo object' is just a synonym for object? or ?object."""
657 657
658 658 #print 'pinfo par: <%s>' % parameter_s # dbg
659 659
660 660 # detail_level: 0 -> obj? , 1 -> obj??
661 661 detail_level = 0
662 662 # We need to detect if we got called as 'pinfo pinfo foo', which can
663 663 # happen if the user types 'pinfo foo?' at the cmd line.
664 664 pinfo,qmark1,oname,qmark2 = \
665 665 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
666 666 if pinfo or qmark1 or qmark2:
667 667 detail_level = 1
668 668 if "*" in oname:
669 669 self.magic_psearch(oname)
670 670 else:
671 671 self._inspect('pinfo',oname,detail_level=detail_level)
672 672
673 673 def magic_psearch(self, parameter_s=''):
674 674 """Search for object in namespaces by wildcard.
675 675
676 676 %psearch [options] PATTERN [OBJECT TYPE]
677 677
678 678 Note: ? can be used as a synonym for %psearch, at the beginning or at
679 679 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
680 680 rest of the command line must be unchanged (options come first), so
681 681 for example the following forms are equivalent
682 682
683 683 %psearch -i a* function
684 684 -i a* function?
685 685 ?-i a* function
686 686
687 687 Arguments:
688 688
689 689 PATTERN
690 690
691 691 where PATTERN is a string containing * as a wildcard similar to its
692 692 use in a shell. The pattern is matched in all namespaces on the
693 693 search path. By default objects starting with a single _ are not
694 694 matched, many IPython generated objects have a single
695 695 underscore. The default is case insensitive matching. Matching is
696 696 also done on the attributes of objects and not only on the objects
697 697 in a module.
698 698
699 699 [OBJECT TYPE]
700 700
701 701 Is the name of a python type from the types module. The name is
702 702 given in lowercase without the ending type, ex. StringType is
703 703 written string. By adding a type here only objects matching the
704 704 given type are matched. Using all here makes the pattern match all
705 705 types (this is the default).
706 706
707 707 Options:
708 708
709 709 -a: makes the pattern match even objects whose names start with a
710 710 single underscore. These names are normally ommitted from the
711 711 search.
712 712
713 713 -i/-c: make the pattern case insensitive/sensitive. If neither of
714 714 these options is given, the default is read from your ipythonrc
715 715 file. The option name which sets this value is
716 716 'wildcards_case_sensitive'. If this option is not specified in your
717 717 ipythonrc file, IPython's internal default is to do a case sensitive
718 718 search.
719 719
720 720 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
721 721 specifiy can be searched in any of the following namespaces:
722 722 'builtin', 'user', 'user_global','internal', 'alias', where
723 723 'builtin' and 'user' are the search defaults. Note that you should
724 724 not use quotes when specifying namespaces.
725 725
726 726 'Builtin' contains the python module builtin, 'user' contains all
727 727 user data, 'alias' only contain the shell aliases and no python
728 728 objects, 'internal' contains objects used by IPython. The
729 729 'user_global' namespace is only used by embedded IPython instances,
730 730 and it contains module-level globals. You can add namespaces to the
731 731 search with -s or exclude them with -e (these options can be given
732 732 more than once).
733 733
734 734 Examples:
735 735
736 736 %psearch a* -> objects beginning with an a
737 737 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
738 738 %psearch a* function -> all functions beginning with an a
739 739 %psearch re.e* -> objects beginning with an e in module re
740 740 %psearch r*.e* -> objects that start with e in modules starting in r
741 741 %psearch r*.* string -> all strings in modules beginning with r
742 742
743 743 Case sensitve search:
744 744
745 745 %psearch -c a* list all object beginning with lower case a
746 746
747 747 Show objects beginning with a single _:
748 748
749 749 %psearch -a _* list objects beginning with a single underscore"""
750 750
751 751 # default namespaces to be searched
752 752 def_search = ['user','builtin']
753 753
754 754 # Process options/args
755 755 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
756 756 opt = opts.get
757 757 shell = self.shell
758 758 psearch = shell.inspector.psearch
759 759
760 760 # select case options
761 761 if opts.has_key('i'):
762 762 ignore_case = True
763 763 elif opts.has_key('c'):
764 764 ignore_case = False
765 765 else:
766 766 ignore_case = not shell.rc.wildcards_case_sensitive
767 767
768 768 # Build list of namespaces to search from user options
769 769 def_search.extend(opt('s',[]))
770 770 ns_exclude = ns_exclude=opt('e',[])
771 771 ns_search = [nm for nm in def_search if nm not in ns_exclude]
772 772
773 773 # Call the actual search
774 774 try:
775 775 psearch(args,shell.ns_table,ns_search,
776 776 show_all=opt('a'),ignore_case=ignore_case)
777 777 except:
778 778 shell.showtraceback()
779 779
780 780 def magic_who_ls(self, parameter_s=''):
781 781 """Return a sorted list of all interactive variables.
782 782
783 783 If arguments are given, only variables of types matching these
784 784 arguments are returned."""
785 785
786 786 user_ns = self.shell.user_ns
787 787 out = []
788 788 typelist = parameter_s.split()
789 789 for i in self.shell.user_ns.keys():
790 790 if not (i.startswith('_') or i.startswith('_i')) \
791 791 and not (self.internal_ns.has_key(i) or
792 792 self.user_config_ns.has_key(i)):
793 793 if typelist:
794 794 if type(user_ns[i]).__name__ in typelist:
795 795 out.append(i)
796 796 else:
797 797 out.append(i)
798 798 out.sort()
799 799 return out
800 800
801 801 def magic_who(self, parameter_s=''):
802 802 """Print all interactive variables, with some minimal formatting.
803 803
804 804 If any arguments are given, only variables whose type matches one of
805 805 these are printed. For example:
806 806
807 807 %who function str
808 808
809 809 will only list functions and strings, excluding all other types of
810 810 variables. To find the proper type names, simply use type(var) at a
811 811 command line to see how python prints type names. For example:
812 812
813 813 In [1]: type('hello')\\
814 814 Out[1]: <type 'str'>
815 815
816 816 indicates that the type name for strings is 'str'.
817 817
818 818 %who always excludes executed names loaded through your configuration
819 819 file and things which are internal to IPython.
820 820
821 821 This is deliberate, as typically you may load many modules and the
822 822 purpose of %who is to show you only what you've manually defined."""
823 823
824 824 varlist = self.magic_who_ls(parameter_s)
825 825 if not varlist:
826 826 print 'Interactive namespace is empty.'
827 827 return
828 828
829 829 # if we have variables, move on...
830 830
831 831 # stupid flushing problem: when prompts have no separators, stdout is
832 832 # getting lost. I'm starting to think this is a python bug. I'm having
833 833 # to force a flush with a print because even a sys.stdout.flush
834 834 # doesn't seem to do anything!
835 835
836 836 count = 0
837 837 for i in varlist:
838 838 print i+'\t',
839 839 count += 1
840 840 if count > 8:
841 841 count = 0
842 842 print
843 843 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
844 844
845 845 print # well, this does force a flush at the expense of an extra \n
846 846
847 847 def magic_whos(self, parameter_s=''):
848 848 """Like %who, but gives some extra information about each variable.
849 849
850 850 The same type filtering of %who can be applied here.
851 851
852 852 For all variables, the type is printed. Additionally it prints:
853 853
854 854 - For {},[],(): their length.
855 855
856 856 - For Numeric arrays, a summary with shape, number of elements,
857 857 typecode and size in memory.
858 858
859 859 - Everything else: a string representation, snipping their middle if
860 860 too long."""
861 861
862 862 varnames = self.magic_who_ls(parameter_s)
863 863 if not varnames:
864 864 print 'Interactive namespace is empty.'
865 865 return
866 866
867 867 # if we have variables, move on...
868 868
869 869 # for these types, show len() instead of data:
870 870 seq_types = [types.DictType,types.ListType,types.TupleType]
871 871
872 872 # for Numeric arrays, display summary info
873 873 try:
874 874 import Numeric
875 875 except ImportError:
876 876 array_type = None
877 877 else:
878 878 array_type = Numeric.ArrayType.__name__
879 879
880 880 # Find all variable names and types so we can figure out column sizes
881 881 get_vars = lambda i: self.shell.user_ns[i]
882 882 type_name = lambda v: type(v).__name__
883 883 varlist = map(get_vars,varnames)
884 884 typelist = map(type_name,varlist)
885 885 # column labels and # of spaces as separator
886 886 varlabel = 'Variable'
887 887 typelabel = 'Type'
888 888 datalabel = 'Data/Info'
889 889 colsep = 3
890 890 # variable format strings
891 891 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
892 892 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
893 893 aformat = "%s: %s elems, type `%s`, %s bytes"
894 894 # find the size of the columns to format the output nicely
895 895 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
896 896 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
897 897 # table header
898 898 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
899 899 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
900 900 # and the table itself
901 901 kb = 1024
902 902 Mb = 1048576 # kb**2
903 903 for vname,var,vtype in zip(varnames,varlist,typelist):
904 904 print itpl(vformat),
905 905 if vtype in seq_types:
906 906 print len(var)
907 907 elif vtype==array_type:
908 908 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
909 909 vsize = Numeric.size(var)
910 910 vbytes = vsize*var.itemsize()
911 911 if vbytes < 100000:
912 912 print aformat % (vshape,vsize,var.typecode(),vbytes)
913 913 else:
914 914 print aformat % (vshape,vsize,var.typecode(),vbytes),
915 915 if vbytes < Mb:
916 916 print '(%s kb)' % (vbytes/kb,)
917 917 else:
918 918 print '(%s Mb)' % (vbytes/Mb,)
919 919 else:
920 920 vstr = str(var)
921 921 if len(vstr) < 50:
922 922 print vstr
923 923 else:
924 924 printpl(vfmt_short)
925 925
926 926 def magic_reset(self, parameter_s=''):
927 927 """Resets the namespace by removing all names defined by the user.
928 928
929 929 Input/Output history are left around in case you need them."""
930 930
931 931 ans = raw_input(
932 932 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
933 933 if not ans.lower() == 'y':
934 934 print 'Nothing done.'
935 935 return
936 936 user_ns = self.shell.user_ns
937 937 for i in self.magic_who_ls():
938 938 del(user_ns[i])
939 939
940 940 def magic_config(self,parameter_s=''):
941 941 """Show IPython's internal configuration."""
942 942
943 943 page('Current configuration structure:\n'+
944 944 pformat(self.shell.rc.dict()))
945 945
946 946 def magic_logstart(self,parameter_s=''):
947 947 """Start logging anywhere in a session.
948 948
949 949 %logstart [log_name [log_mode]]
950 950
951 951 If no name is given, it defaults to a file named 'ipython.log' in your
952 952 current directory, in 'rotate' mode (see below).
953 953
954 954 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
955 955 history up to that point and then continues logging.
956 956
957 957 %logstart takes a second optional parameter: logging mode. This can be one
958 958 of (note that the modes are given unquoted):\\
959 959 over: overwrite existing log.\\
960 960 backup: rename (if exists) to name~ and start name.\\
961 961 append: well, that says it.\\
962 962 rotate: create rotating logs name.1~, name.2~, etc.
963 963 """
964 964
965 965 #FIXME. This function should all be moved to the Logger class.
966 966
967 967 valid_modes = qw('over backup append rotate')
968 968 if self.LOG:
969 969 print 'Logging is already in place. Logfile:',self.LOG
970 970 return
971 971
972 972 par = parameter_s.strip()
973 973 if not par:
974 974 logname = self.LOGDEF
975 975 logmode = 'rotate' # use rotate for the auto-generated logs
976 976 else:
977 977 try:
978 978 logname,logmode = par.split()
979 979 except:
980 980 try:
981 981 logname = par
982 982 logmode = 'backup'
983 983 except:
984 984 warn('Usage: %log [log_name [log_mode]]')
985 985 return
986 986 if not logmode in valid_modes:
987 987 warn('Logging NOT activated.\n'
988 988 'Usage: %log [log_name [log_mode]]\n'
989 989 'Valid modes: '+str(valid_modes))
990 990 return
991 991
992 992 # If we made it this far, I think we're ok:
993 993 print 'Activating auto-logging.'
994 994 print 'Current session state plus future input saved to:',logname
995 995 print 'Logging mode: ',logmode
996 996 # put logname into rc struct as if it had been called on the command line,
997 997 # so it ends up saved in the log header
998 998 # Save it in case we need to restore it...
999 999 old_logfile = self.shell.rc.opts.get('logfile','')
1000 1000 logname = os.path.expanduser(logname)
1001 1001 self.shell.rc.opts.logfile = logname
1002 1002 self.LOGMODE = logmode # FIXME: this should be set through a function.
1003 1003 try:
1004 1004 header = str(self.LOGHEAD)
1005 1005 self.create_log(header,logname)
1006 1006 self.logstart(header,logname)
1007 1007 except:
1008 1008 self.LOG = '' # we are NOT logging, something went wrong
1009 1009 self.shell.rc.opts.logfile = old_logfile
1010 1010 warn("Couldn't start log: "+str(sys.exc_info()[1]))
1011 1011 else: # log input history up to this point
1012 1012 self.logfile.write(self.shell.user_ns['_ih'][1:])
1013 1013 self.logfile.flush()
1014 1014
1015 1015 def magic_logoff(self,parameter_s=''):
1016 1016 """Temporarily stop logging.
1017 1017
1018 1018 You must have previously started logging."""
1019 1019 self.switch_log(0)
1020 1020
1021 1021 def magic_logon(self,parameter_s=''):
1022 1022 """Restart logging.
1023 1023
1024 1024 This function is for restarting logging which you've temporarily
1025 1025 stopped with %logoff. For starting logging for the first time, you
1026 1026 must use the %logstart function, which allows you to specify an
1027 1027 optional log filename."""
1028 1028
1029 1029 self.switch_log(1)
1030 1030
1031 1031 def magic_logstate(self,parameter_s=''):
1032 1032 """Print the status of the logging system."""
1033 1033
1034 1034 self.logstate()
1035 1035
1036 1036 def magic_pdb(self, parameter_s=''):
1037 1037 """Control the calling of the pdb interactive debugger.
1038 1038
1039 1039 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1040 1040 argument it works as a toggle.
1041 1041
1042 1042 When an exception is triggered, IPython can optionally call the
1043 1043 interactive pdb debugger after the traceback printout. %pdb toggles
1044 1044 this feature on and off."""
1045 1045
1046 1046 par = parameter_s.strip().lower()
1047 1047
1048 1048 if par:
1049 1049 try:
1050 1050 pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1051 1051 except KeyError:
1052 1052 print 'Incorrect argument. Use on/1, off/0 or nothing for a toggle.'
1053 1053 return
1054 1054 else:
1055 1055 self.shell.InteractiveTB.call_pdb = pdb
1056 1056 else:
1057 1057 self.shell.InteractiveTB.call_pdb = 1 - self.shell.InteractiveTB.call_pdb
1058 1058 print 'Automatic pdb calling has been turned',\
1059 1059 on_off(self.shell.InteractiveTB.call_pdb)
1060 1060
1061 1061
1062 1062 def magic_prun(self, parameter_s ='',user_mode=1,
1063 1063 opts=None,arg_lst=None,prog_ns=None):
1064 1064
1065 1065 """Run a statement through the python code profiler.
1066 1066
1067 1067 Usage:\\
1068 1068 %prun [options] statement
1069 1069
1070 1070 The given statement (which doesn't require quote marks) is run via the
1071 1071 python profiler in a manner similar to the profile.run() function.
1072 1072 Namespaces are internally managed to work correctly; profile.run
1073 1073 cannot be used in IPython because it makes certain assumptions about
1074 1074 namespaces which do not hold under IPython.
1075 1075
1076 1076 Options:
1077 1077
1078 1078 -l <limit>: you can place restrictions on what or how much of the
1079 1079 profile gets printed. The limit value can be:
1080 1080
1081 1081 * A string: only information for function names containing this string
1082 1082 is printed.
1083 1083
1084 1084 * An integer: only these many lines are printed.
1085 1085
1086 1086 * A float (between 0 and 1): this fraction of the report is printed
1087 1087 (for example, use a limit of 0.4 to see the topmost 40% only).
1088 1088
1089 1089 You can combine several limits with repeated use of the option. For
1090 1090 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1091 1091 information about class constructors.
1092 1092
1093 1093 -r: return the pstats.Stats object generated by the profiling. This
1094 1094 object has all the information about the profile in it, and you can
1095 1095 later use it for further analysis or in other functions.
1096 1096
1097 1097 Since magic functions have a particular form of calling which prevents
1098 1098 you from writing something like:\\
1099 1099 In [1]: p = %prun -r print 4 # invalid!\\
1100 1100 you must instead use IPython's automatic variables to assign this:\\
1101 1101 In [1]: %prun -r print 4 \\
1102 1102 Out[1]: <pstats.Stats instance at 0x8222cec>\\
1103 1103 In [2]: stats = _
1104 1104
1105 1105 If you really need to assign this value via an explicit function call,
1106 1106 you can always tap directly into the true name of the magic function
1107 1107 by using the ipmagic function (which IPython automatically adds to the
1108 1108 builtins):\\
1109 1109 In [3]: stats = ipmagic('prun','-r print 4')
1110 1110
1111 1111 You can type ipmagic? for more details on ipmagic.
1112 1112
1113 1113 -s <key>: sort profile by given key. You can provide more than one key
1114 1114 by using the option several times: '-s key1 -s key2 -s key3...'. The
1115 1115 default sorting key is 'time'.
1116 1116
1117 1117 The following is copied verbatim from the profile documentation
1118 1118 referenced below:
1119 1119
1120 1120 When more than one key is provided, additional keys are used as
1121 1121 secondary criteria when the there is equality in all keys selected
1122 1122 before them.
1123 1123
1124 1124 Abbreviations can be used for any key names, as long as the
1125 1125 abbreviation is unambiguous. The following are the keys currently
1126 1126 defined:
1127 1127
1128 1128 Valid Arg Meaning\\
1129 1129 "calls" call count\\
1130 1130 "cumulative" cumulative time\\
1131 1131 "file" file name\\
1132 1132 "module" file name\\
1133 1133 "pcalls" primitive call count\\
1134 1134 "line" line number\\
1135 1135 "name" function name\\
1136 1136 "nfl" name/file/line\\
1137 1137 "stdname" standard name\\
1138 1138 "time" internal time
1139 1139
1140 1140 Note that all sorts on statistics are in descending order (placing
1141 1141 most time consuming items first), where as name, file, and line number
1142 1142 searches are in ascending order (i.e., alphabetical). The subtle
1143 1143 distinction between "nfl" and "stdname" is that the standard name is a
1144 1144 sort of the name as printed, which means that the embedded line
1145 1145 numbers get compared in an odd way. For example, lines 3, 20, and 40
1146 1146 would (if the file names were the same) appear in the string order
1147 1147 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1148 1148 line numbers. In fact, sort_stats("nfl") is the same as
1149 1149 sort_stats("name", "file", "line").
1150 1150
1151 1151 -T <filename>: save profile results as shown on screen to a text
1152 1152 file. The profile is still shown on screen.
1153 1153
1154 1154 -D <filename>: save (via dump_stats) profile statistics to given
1155 1155 filename. This data is in a format understod by the pstats module, and
1156 1156 is generated by a call to the dump_stats() method of profile
1157 1157 objects. The profile is still shown on screen.
1158 1158
1159 1159 If you want to run complete programs under the profiler's control, use
1160 1160 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1161 1161 contains profiler specific options as described here.
1162 1162
1163 1163 You can read the complete documentation for the profile module with:\\
1164 1164 In [1]: import profile; profile.help() """
1165 1165
1166 1166 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1167 1167 # protect user quote marks
1168 1168 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1169 1169
1170 1170 if user_mode: # regular user call
1171 1171 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1172 1172 list_all=1)
1173 1173 namespace = self.shell.user_ns
1174 1174 else: # called to run a program by %run -p
1175 1175 try:
1176 1176 filename = get_py_filename(arg_lst[0])
1177 1177 except IOError,msg:
1178 1178 error(msg)
1179 1179 return
1180 1180
1181 1181 arg_str = 'execfile(filename,prog_ns)'
1182 1182 namespace = locals()
1183 1183
1184 1184 opts.merge(opts_def)
1185 1185
1186 1186 prof = profile.Profile()
1187 1187 try:
1188 1188 prof = prof.runctx(arg_str,namespace,namespace)
1189 1189 sys_exit = ''
1190 1190 except SystemExit:
1191 1191 sys_exit = """*** SystemExit exception caught in code being profiled."""
1192 1192
1193 1193 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1194 1194
1195 1195 lims = opts.l
1196 1196 if lims:
1197 1197 lims = [] # rebuild lims with ints/floats/strings
1198 1198 for lim in opts.l:
1199 1199 try:
1200 1200 lims.append(int(lim))
1201 1201 except ValueError:
1202 1202 try:
1203 1203 lims.append(float(lim))
1204 1204 except ValueError:
1205 1205 lims.append(lim)
1206 1206
1207 1207 # trap output
1208 1208 sys_stdout = sys.stdout
1209 1209 stdout_trap = StringIO()
1210 1210 try:
1211 1211 sys.stdout = stdout_trap
1212 1212 stats.print_stats(*lims)
1213 1213 finally:
1214 1214 sys.stdout = sys_stdout
1215 1215 output = stdout_trap.getvalue()
1216 1216 output = output.rstrip()
1217 1217
1218 1218 page(output,screen_lines=self.shell.rc.screen_length)
1219 1219 print sys_exit,
1220 1220
1221 1221 dump_file = opts.D[0]
1222 1222 text_file = opts.T[0]
1223 1223 if dump_file:
1224 1224 prof.dump_stats(dump_file)
1225 1225 print '\n*** Profile stats marshalled to file',\
1226 1226 `dump_file`+'.',sys_exit
1227 1227 if text_file:
1228 1228 file(text_file,'w').write(output)
1229 1229 print '\n*** Profile printout saved to text file',\
1230 1230 `text_file`+'.',sys_exit
1231 1231
1232 1232 if opts.has_key('r'):
1233 1233 return stats
1234 1234 else:
1235 1235 return None
1236 1236
1237 1237 def magic_run(self, parameter_s ='',runner=None):
1238 1238 """Run the named file inside IPython as a program.
1239 1239
1240 1240 Usage:\\
1241 1241 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1242 1242
1243 1243 Parameters after the filename are passed as command-line arguments to
1244 1244 the program (put in sys.argv). Then, control returns to IPython's
1245 1245 prompt.
1246 1246
1247 1247 This is similar to running at a system prompt:\\
1248 1248 $ python file args\\
1249 1249 but with the advantage of giving you IPython's tracebacks, and of
1250 1250 loading all variables into your interactive namespace for further use
1251 1251 (unless -p is used, see below).
1252 1252
1253 1253 The file is executed in a namespace initially consisting only of
1254 1254 __name__=='__main__' and sys.argv constructed as indicated. It thus
1255 1255 sees its environment as if it were being run as a stand-alone
1256 1256 program. But after execution, the IPython interactive namespace gets
1257 1257 updated with all variables defined in the program (except for __name__
1258 1258 and sys.argv). This allows for very convenient loading of code for
1259 1259 interactive work, while giving each program a 'clean sheet' to run in.
1260 1260
1261 1261 Options:
1262 1262
1263 1263 -n: __name__ is NOT set to '__main__', but to the running file's name
1264 1264 without extension (as python does under import). This allows running
1265 1265 scripts and reloading the definitions in them without calling code
1266 1266 protected by an ' if __name__ == "__main__" ' clause.
1267 1267
1268 1268 -i: run the file in IPython's namespace instead of an empty one. This
1269 1269 is useful if you are experimenting with code written in a text editor
1270 1270 which depends on variables defined interactively.
1271 1271
1272 1272 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1273 1273 being run. This is particularly useful if IPython is being used to
1274 1274 run unittests, which always exit with a sys.exit() call. In such
1275 1275 cases you are interested in the output of the test results, not in
1276 1276 seeing a traceback of the unittest module.
1277 1277
1278 1278 -t: print timing information at the end of the run. IPython will give
1279 1279 you an estimated CPU time consumption for your script, which under
1280 1280 Unix uses the resource module to avoid the wraparound problems of
1281 1281 time.clock(). Under Unix, an estimate of time spent on system tasks
1282 1282 is also given (for Windows platforms this is reported as 0.0).
1283 1283
1284 1284 If -t is given, an additional -N<N> option can be given, where <N>
1285 1285 must be an integer indicating how many times you want the script to
1286 1286 run. The final timing report will include total and per run results.
1287 1287
1288 1288 For example (testing the script uniq_stable.py):
1289 1289
1290 1290 In [1]: run -t uniq_stable
1291 1291
1292 1292 IPython CPU timings (estimated):\\
1293 1293 User : 0.19597 s.\\
1294 1294 System: 0.0 s.\\
1295 1295
1296 1296 In [2]: run -t -N5 uniq_stable
1297 1297
1298 1298 IPython CPU timings (estimated):\\
1299 1299 Total runs performed: 5\\
1300 1300 Times : Total Per run\\
1301 1301 User : 0.910862 s, 0.1821724 s.\\
1302 1302 System: 0.0 s, 0.0 s.
1303 1303
1304 1304 -d: run your program under the control of pdb, the Python debugger.
1305 1305 This allows you to execute your program step by step, watch variables,
1306 1306 etc. Internally, what IPython does is similar to calling:
1307 1307
1308 1308 pdb.run('execfile("YOURFILENAME")')
1309 1309
1310 1310 with a breakpoint set on line 1 of your file. You can change the line
1311 1311 number for this automatic breakpoint to be <N> by using the -bN option
1312 1312 (where N must be an integer). For example:
1313 1313
1314 1314 %run -d -b40 myscript
1315 1315
1316 1316 will set the first breakpoint at line 40 in myscript.py. Note that
1317 1317 the first breakpoint must be set on a line which actually does
1318 1318 something (not a comment or docstring) for it to stop execution.
1319 1319
1320 1320 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1321 1321 first enter 'c' (without qoutes) to start execution up to the first
1322 1322 breakpoint.
1323 1323
1324 1324 Entering 'help' gives information about the use of the debugger. You
1325 1325 can easily see pdb's full documentation with "import pdb;pdb.help()"
1326 1326 at a prompt.
1327 1327
1328 1328 -p: run program under the control of the Python profiler module (which
1329 1329 prints a detailed report of execution times, function calls, etc).
1330 1330
1331 1331 You can pass other options after -p which affect the behavior of the
1332 1332 profiler itself. See the docs for %prun for details.
1333 1333
1334 1334 In this mode, the program's variables do NOT propagate back to the
1335 1335 IPython interactive namespace (because they remain in the namespace
1336 1336 where the profiler executes them).
1337 1337
1338 1338 Internally this triggers a call to %prun, see its documentation for
1339 1339 details on the options available specifically for profiling."""
1340 1340
1341 1341 # get arguments and set sys.argv for program to be run.
1342 1342 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1343 1343 mode='list',list_all=1)
1344 1344
1345 1345 try:
1346 1346 filename = get_py_filename(arg_lst[0])
1347 1347 except IndexError:
1348 1348 warn('you must provide at least a filename.')
1349 1349 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1350 1350 return
1351 1351 except IOError,msg:
1352 1352 error(msg)
1353 1353 return
1354 1354
1355 1355 # Control the response to exit() calls made by the script being run
1356 1356 exit_ignore = opts.has_key('e')
1357 1357
1358 1358 # Make sure that the running script gets a proper sys.argv as if it
1359 1359 # were run from a system shell.
1360 1360 save_argv = sys.argv # save it for later restoring
1361 1361 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1362 1362
1363 1363 if opts.has_key('i'):
1364 1364 prog_ns = self.shell.user_ns
1365 1365 __name__save = self.shell.user_ns['__name__']
1366 1366 prog_ns['__name__'] = '__main__'
1367 1367 else:
1368 1368 if opts.has_key('n'):
1369 1369 name = os.path.splitext(os.path.basename(filename))[0]
1370 1370 else:
1371 1371 name = '__main__'
1372 1372 prog_ns = {'__name__':name}
1373 1373
1374 1374 # pickle fix. See iplib for an explanation
1375 1375 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1376 1376
1377 1377 stats = None
1378 1378 try:
1379 1379 if opts.has_key('p'):
1380 1380 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1381 1381 else:
1382 1382 if opts.has_key('d'):
1383 1383 deb = Debugger.Pdb(self.shell.rc.colors)
1384 1384 # reset Breakpoint state, which is moronically kept
1385 1385 # in a class
1386 1386 bdb.Breakpoint.next = 1
1387 1387 bdb.Breakpoint.bplist = {}
1388 1388 bdb.Breakpoint.bpbynumber = [None]
1389 1389 # Set an initial breakpoint to stop execution
1390 1390 maxtries = 10
1391 1391 bp = int(opts.get('b',[1])[0])
1392 1392 checkline = deb.checkline(filename,bp)
1393 1393 if not checkline:
1394 1394 for bp in range(bp+1,bp+maxtries+1):
1395 1395 if deb.checkline(filename,bp):
1396 1396 break
1397 1397 else:
1398 1398 msg = ("\nI failed to find a valid line to set "
1399 1399 "a breakpoint\n"
1400 1400 "after trying up to line: %s.\n"
1401 1401 "Please set a valid breakpoint manually "
1402 1402 "with the -b option." % bp)
1403 1403 error(msg)
1404 1404 return
1405 1405 # if we find a good linenumber, set the breakpoint
1406 1406 deb.do_break('%s:%s' % (filename,bp))
1407 1407 # Start file run
1408 1408 print "NOTE: Enter 'c' at the",
1409 1409 print "ipdb> prompt to start your script."
1410 1410 try:
1411 1411 deb.run('execfile("%s")' % filename,prog_ns)
1412 1412 except:
1413 1413 etype, value, tb = sys.exc_info()
1414 1414 # Skip three frames in the traceback: the %run one,
1415 1415 # one inside bdb.py, and the command-line typed by the
1416 1416 # user (run by exec in pdb itself).
1417 1417 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1418 1418 else:
1419 1419 if runner is None:
1420 1420 runner = self.shell.safe_execfile
1421 1421 if opts.has_key('t'):
1422 1422 try:
1423 1423 nruns = int(opts['N'][0])
1424 1424 if nruns < 1:
1425 1425 error('Number of runs must be >=1')
1426 1426 return
1427 1427 except (KeyError):
1428 1428 nruns = 1
1429 1429 if nruns == 1:
1430 1430 t0 = clock2()
1431 1431 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1432 1432 t1 = clock2()
1433 1433 t_usr = t1[0]-t0[0]
1434 1434 t_sys = t1[1]-t1[1]
1435 1435 print "\nIPython CPU timings (estimated):"
1436 1436 print " User : %10s s." % t_usr
1437 1437 print " System: %10s s." % t_sys
1438 1438 else:
1439 1439 runs = range(nruns)
1440 1440 t0 = clock2()
1441 1441 for nr in runs:
1442 1442 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1443 1443 t1 = clock2()
1444 1444 t_usr = t1[0]-t0[0]
1445 1445 t_sys = t1[1]-t1[1]
1446 1446 print "\nIPython CPU timings (estimated):"
1447 1447 print "Total runs performed:",nruns
1448 1448 print " Times : %10s %10s" % ('Total','Per run')
1449 1449 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1450 1450 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1451 1451
1452 1452 else:
1453 1453 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1454 1454 if opts.has_key('i'):
1455 1455 self.shell.user_ns['__name__'] = __name__save
1456 1456 else:
1457 1457 # update IPython interactive namespace
1458 1458 del prog_ns['__name__']
1459 1459 self.shell.user_ns.update(prog_ns)
1460 1460 finally:
1461 1461 sys.argv = save_argv
1462 1462 return stats
1463 1463
1464 1464 def magic_runlog(self, parameter_s =''):
1465 1465 """Run files as logs.
1466 1466
1467 1467 Usage:\\
1468 1468 %runlog file1 file2 ...
1469 1469
1470 1470 Run the named files (treating them as log files) in sequence inside
1471 1471 the interpreter, and return to the prompt. This is much slower than
1472 1472 %run because each line is executed in a try/except block, but it
1473 1473 allows running files with syntax errors in them.
1474 1474
1475 1475 Normally IPython will guess when a file is one of its own logfiles, so
1476 1476 you can typically use %run even for logs. This shorthand allows you to
1477 1477 force any file to be treated as a log file."""
1478 1478
1479 1479 for f in parameter_s.split():
1480 1480 self.shell.safe_execfile(f,self.shell.user_ns,
1481 1481 self.shell.user_ns,islog=1)
1482 1482
1483 1483 def magic_time(self,parameter_s = ''):
1484 1484 """Time execution of a Python statement or expression.
1485 1485
1486 1486 The CPU and wall clock times are printed, and the value of the
1487 1487 expression (if any) is returned. Note that under Win32, system time
1488 1488 is always reported as 0, since it can not be measured.
1489 1489
1490 1490 This function provides very basic timing functionality. In Python
1491 1491 2.3, the timeit module offers more control and sophistication, but for
1492 1492 now IPython supports Python 2.2, so we can not rely on timeit being
1493 1493 present.
1494 1494
1495 1495 Some examples:
1496 1496
1497 1497 In [1]: time 2**128
1498 1498 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1499 1499 Wall time: 0.00
1500 1500 Out[1]: 340282366920938463463374607431768211456L
1501 1501
1502 1502 In [2]: n = 1000000
1503 1503
1504 1504 In [3]: time sum(range(n))
1505 1505 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1506 1506 Wall time: 1.37
1507 1507 Out[3]: 499999500000L
1508 1508
1509 1509 In [4]: time print 'hello world'
1510 1510 hello world
1511 1511 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1512 1512 Wall time: 0.00
1513 1513 """
1514 1514
1515 1515 # fail immediately if the given expression can't be compiled
1516 1516 try:
1517 1517 mode = 'eval'
1518 1518 code = compile(parameter_s,'<timed eval>',mode)
1519 1519 except SyntaxError:
1520 1520 mode = 'exec'
1521 1521 code = compile(parameter_s,'<timed exec>',mode)
1522 1522 # skew measurement as little as possible
1523 1523 glob = self.shell.user_ns
1524 1524 clk = clock2
1525 1525 wtime = time.time
1526 1526 # time execution
1527 1527 wall_st = wtime()
1528 1528 if mode=='eval':
1529 1529 st = clk()
1530 1530 out = eval(code,glob)
1531 1531 end = clk()
1532 1532 else:
1533 1533 st = clk()
1534 1534 exec code in glob
1535 1535 end = clk()
1536 1536 out = None
1537 1537 wall_end = wtime()
1538 1538 # Compute actual times and report
1539 1539 wall_time = wall_end-wall_st
1540 1540 cpu_user = end[0]-st[0]
1541 1541 cpu_sys = end[1]-st[1]
1542 1542 cpu_tot = cpu_user+cpu_sys
1543 1543 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1544 1544 (cpu_user,cpu_sys,cpu_tot)
1545 1545 print "Wall time: %.2f" % wall_time
1546 1546 return out
1547 1547
1548 1548 def magic_macro(self,parameter_s = ''):
1549 1549 """Define a set of input lines as a macro for future re-execution.
1550 1550
1551 1551 Usage:\\
1552 1552 %macro name n1:n2 n3:n4 ... n5 .. n6 ...
1553 1553
1554 1554 This will define a global variable called `name` which is a string
1555 1555 made of joining the slices and lines you specify (n1,n2,... numbers
1556 1556 above) from your input history into a single string. This variable
1557 1557 acts like an automatic function which re-executes those lines as if
1558 1558 you had typed them. You just type 'name' at the prompt and the code
1559 1559 executes.
1560 1560
1561 1561 Note that the slices use the standard Python slicing notation (5:8
1562 1562 means include lines numbered 5,6,7).
1563 1563
1564 1564 For example, if your history contains (%hist prints it):
1565 1565
1566 1566 44: x=1\\
1567 1567 45: y=3\\
1568 1568 46: z=x+y\\
1569 1569 47: print x\\
1570 1570 48: a=5\\
1571 1571 49: print 'x',x,'y',y\\
1572 1572
1573 1573 you can create a macro with lines 44 through 47 (included) and line 49
1574 1574 called my_macro with:
1575 1575
1576 1576 In [51]: %macro my_macro 44:48 49
1577 1577
1578 1578 Now, typing `my_macro` (without quotes) will re-execute all this code
1579 1579 in one pass.
1580 1580
1581 1581 You don't need to give the line-numbers in order, and any given line
1582 1582 number can appear multiple times. You can assemble macros with any
1583 1583 lines from your input history in any order.
1584 1584
1585 1585 The macro is a simple object which holds its value in an attribute,
1586 1586 but IPython's display system checks for macros and executes them as
1587 1587 code instead of printing them when you type their name.
1588 1588
1589 1589 You can view a macro's contents by explicitly printing it with:
1590 1590
1591 1591 'print macro_name'.
1592 1592
1593 1593 For one-off cases which DON'T contain magic function calls in them you
1594 1594 can obtain similar results by explicitly executing slices from your
1595 1595 input history with:
1596 1596
1597 1597 In [60]: exec In[44:48]+In[49]"""
1598 1598
1599 1599 args = parameter_s.split()
1600 1600 name,ranges = args[0], args[1:]
1601 1601 #print 'rng',ranges # dbg
1602 1602 cmds = self.extract_input_slices(ranges)
1603 1603 macro = Macro(cmds)
1604 1604 self.shell.user_ns.update({name:macro})
1605 1605 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1606 1606 print 'Macro contents:'
1607 1607 print str(macro).rstrip(),
1608 1608
1609 1609 def magic_save(self,parameter_s = ''):
1610 1610 """Save a set of lines to a given filename.
1611 1611
1612 1612 Usage:\\
1613 1613 %save filename n1:n2 n3:n4 ... n5 .. n6 ...
1614 1614
1615 1615 This function uses the same syntax as %macro for line extraction, but
1616 1616 instead of creating a macro it saves the resulting string to the
1617 1617 filename you specify.
1618 1618
1619 1619 It adds a '.py' extension to the file if you don't do so yourself, and
1620 1620 it asks for confirmation before overwriting existing files."""
1621 1621
1622 1622 args = parameter_s.split()
1623 1623 fname,ranges = args[0], args[1:]
1624 1624 if not fname.endswith('.py'):
1625 1625 fname += '.py'
1626 1626 if os.path.isfile(fname):
1627 1627 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1628 1628 if ans.lower() not in ['y','yes']:
1629 1629 print 'Operation cancelled.'
1630 1630 return
1631 1631 cmds = ''.join(self.extract_input_slices(ranges))
1632 1632 f = file(fname,'w')
1633 1633 f.write(cmds)
1634 1634 f.close()
1635 1635 print 'The following commands were written to file `%s`:' % fname
1636 1636 print cmds
1637 1637
1638 1638 def magic_ed(self,parameter_s = ''):
1639 1639 """Alias to %edit."""
1640 1640 return self.magic_edit(parameter_s)
1641 1641
1642 1642 def magic_edit(self,parameter_s = '',last_call=['','']):
1643 1643 """Bring up an editor and execute the resulting code.
1644 1644
1645 1645 Usage:
1646 1646 %edit [options] [args]
1647 1647
1648 1648 %edit runs IPython's editor hook. The default version of this hook is
1649 1649 set to call the __IPYTHON__.rc.editor command. This is read from your
1650 1650 environment variable $EDITOR. If this isn't found, it will default to
1651 1651 vi under Linux/Unix and to notepad under Windows. See the end of this
1652 1652 docstring for how to change the editor hook.
1653 1653
1654 1654 You can also set the value of this editor via the command line option
1655 1655 '-editor' or in your ipythonrc file. This is useful if you wish to use
1656 1656 specifically for IPython an editor different from your typical default
1657 1657 (and for Windows users who typically don't set environment variables).
1658 1658
1659 1659 This command allows you to conveniently edit multi-line code right in
1660 1660 your IPython session.
1661 1661
1662 1662 If called without arguments, %edit opens up an empty editor with a
1663 1663 temporary file and will execute the contents of this file when you
1664 1664 close it (don't forget to save it!).
1665 1665
1666 1666 Options:
1667 1667
1668 1668 -p: this will call the editor with the same data as the previous time
1669 1669 it was used, regardless of how long ago (in your current session) it
1670 1670 was.
1671 1671
1672 1672 -x: do not execute the edited code immediately upon exit. This is
1673 1673 mainly useful if you are editing programs which need to be called with
1674 1674 command line arguments, which you can then do using %run.
1675 1675
1676 1676 Arguments:
1677 1677
1678 1678 If arguments are given, the following possibilites exist:
1679 1679
1680 1680 - The arguments are numbers or pairs of colon-separated numbers (like
1681 1681 1 4:8 9). These are interpreted as lines of previous input to be
1682 1682 loaded into the editor. The syntax is the same of the %macro command.
1683 1683
1684 1684 - If the argument doesn't start with a number, it is evaluated as a
1685 1685 variable and its contents loaded into the editor. You can thus edit
1686 1686 any string which contains python code (including the result of
1687 1687 previous edits).
1688 1688
1689 1689 - If the argument is the name of an object (other than a string),
1690 1690 IPython will try to locate the file where it was defined and open the
1691 1691 editor at the point where it is defined. You can use `%edit function`
1692 1692 to load an editor exactly at the point where 'function' is defined,
1693 1693 edit it and have the file be executed automatically.
1694 1694
1695 1695 Note: opening at an exact line is only supported under Unix, and some
1696 1696 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1697 1697 '+NUMBER' parameter necessary for this feature. Good editors like
1698 1698 (X)Emacs, vi, jed, pico and joe all do.
1699 1699
1700 1700 - If the argument is not found as a variable, IPython will look for a
1701 1701 file with that name (adding .py if necessary) and load it into the
1702 1702 editor. It will execute its contents with execfile() when you exit,
1703 1703 loading any code in the file into your interactive namespace.
1704 1704
1705 1705 After executing your code, %edit will return as output the code you
1706 1706 typed in the editor (except when it was an existing file). This way
1707 1707 you can reload the code in further invocations of %edit as a variable,
1708 1708 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1709 1709 the output.
1710 1710
1711 1711 Note that %edit is also available through the alias %ed.
1712 1712
1713 1713 This is an example of creating a simple function inside the editor and
1714 1714 then modifying it. First, start up the editor:
1715 1715
1716 1716 In [1]: ed\\
1717 1717 Editing... done. Executing edited code...\\
1718 1718 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1719 1719
1720 1720 We can then call the function foo():
1721 1721
1722 1722 In [2]: foo()\\
1723 1723 foo() was defined in an editing session
1724 1724
1725 1725 Now we edit foo. IPython automatically loads the editor with the
1726 1726 (temporary) file where foo() was previously defined:
1727 1727
1728 1728 In [3]: ed foo\\
1729 1729 Editing... done. Executing edited code...
1730 1730
1731 1731 And if we call foo() again we get the modified version:
1732 1732
1733 1733 In [4]: foo()\\
1734 1734 foo() has now been changed!
1735 1735
1736 1736 Here is an example of how to edit a code snippet successive
1737 1737 times. First we call the editor:
1738 1738
1739 1739 In [8]: ed\\
1740 1740 Editing... done. Executing edited code...\\
1741 1741 hello\\
1742 1742 Out[8]: "print 'hello'\\n"
1743 1743
1744 1744 Now we call it again with the previous output (stored in _):
1745 1745
1746 1746 In [9]: ed _\\
1747 1747 Editing... done. Executing edited code...\\
1748 1748 hello world\\
1749 1749 Out[9]: "print 'hello world'\\n"
1750 1750
1751 1751 Now we call it with the output #8 (stored in _8, also as Out[8]):
1752 1752
1753 1753 In [10]: ed _8\\
1754 1754 Editing... done. Executing edited code...\\
1755 1755 hello again\\
1756 1756 Out[10]: "print 'hello again'\\n"
1757 1757
1758 1758
1759 1759 Changing the default editor hook:
1760 1760
1761 1761 If you wish to write your own editor hook, you can put it in a
1762 1762 configuration file which you load at startup time. The default hook
1763 1763 is defined in the IPython.hooks module, and you can use that as a
1764 1764 starting example for further modifications. That file also has
1765 1765 general instructions on how to set a new hook for use once you've
1766 1766 defined it."""
1767 1767
1768 1768 # FIXME: This function has become a convoluted mess. It needs a
1769 1769 # ground-up rewrite with clean, simple logic.
1770 1770
1771 1771 def make_filename(arg):
1772 1772 "Make a filename from the given args"
1773 1773 try:
1774 1774 filename = get_py_filename(arg)
1775 1775 except IOError:
1776 1776 if args.endswith('.py'):
1777 1777 filename = arg
1778 1778 else:
1779 1779 filename = None
1780 1780 return filename
1781 1781
1782 1782 # custom exceptions
1783 1783 class DataIsObject(Exception): pass
1784 1784
1785 1785 opts,args = self.parse_options(parameter_s,'px')
1786 1786
1787 1787 # Default line number value
1788 1788 lineno = None
1789 1789 if opts.has_key('p'):
1790 1790 args = '_%s' % last_call[0]
1791 1791 if not self.shell.user_ns.has_key(args):
1792 1792 args = last_call[1]
1793 1793
1794 1794 # use last_call to remember the state of the previous call, but don't
1795 1795 # let it be clobbered by successive '-p' calls.
1796 1796 try:
1797 1797 last_call[0] = self.shell.outputcache.prompt_count
1798 1798 if not opts.has_key('p'):
1799 1799 last_call[1] = parameter_s
1800 1800 except:
1801 1801 pass
1802 1802
1803 1803 # by default this is done with temp files, except when the given
1804 1804 # arg is a filename
1805 1805 use_temp = 1
1806 1806
1807 1807 if re.match(r'\d',args):
1808 1808 # Mode where user specifies ranges of lines, like in %macro.
1809 1809 # This means that you can't edit files whose names begin with
1810 1810 # numbers this way. Tough.
1811 1811 ranges = args.split()
1812 1812 data = ''.join(self.extract_input_slices(ranges))
1813 1813 elif args.endswith('.py'):
1814 1814 filename = make_filename(args)
1815 1815 data = ''
1816 1816 use_temp = 0
1817 1817 elif args:
1818 1818 try:
1819 1819 # Load the parameter given as a variable. If not a string,
1820 1820 # process it as an object instead (below)
1821 1821
1822 1822 #print '*** args',args,'type',type(args) # dbg
1823 1823 data = eval(args,self.shell.user_ns)
1824 1824 if not type(data) in StringTypes:
1825 1825 raise DataIsObject
1826 1826 except (NameError,SyntaxError):
1827 1827 # given argument is not a variable, try as a filename
1828 1828 filename = make_filename(args)
1829 1829 if filename is None:
1830 1830 warn("Argument given (%s) can't be found as a variable "
1831 1831 "or as a filename." % args)
1832 1832 return
1833 1833 data = ''
1834 1834 use_temp = 0
1835 1835 except DataIsObject:
1836 1836 # For objects, try to edit the file where they are defined
1837 1837 try:
1838 1838 filename = inspect.getabsfile(data)
1839 1839 datafile = 1
1840 1840 except TypeError:
1841 1841 filename = make_filename(args)
1842 1842 datafile = 1
1843 1843 warn('Could not find file where `%s` is defined.\n'
1844 1844 'Opening a file named `%s`' % (args,filename))
1845 1845 # Now, make sure we can actually read the source (if it was in
1846 1846 # a temp file it's gone by now).
1847 1847 if datafile:
1848 1848 try:
1849 1849 lineno = inspect.getsourcelines(data)[1]
1850 1850 except IOError:
1851 1851 filename = make_filename(args)
1852 1852 if filename is None:
1853 1853 warn('The file `%s` where `%s` was defined cannot '
1854 1854 'be read.' % (filename,data))
1855 1855 return
1856 1856 use_temp = 0
1857 1857 else:
1858 1858 data = ''
1859 1859
1860 1860 if use_temp:
1861 1861 filename = tempfile.mktemp('.py')
1862 1862 self.shell.tempfiles.append(filename)
1863 1863
1864 1864 if data and use_temp:
1865 1865 tmp_file = open(filename,'w')
1866 1866 tmp_file.write(data)
1867 1867 tmp_file.close()
1868 1868
1869 1869 # do actual editing here
1870 1870 print 'Editing...',
1871 1871 sys.stdout.flush()
1872 1872 self.shell.hooks.editor(filename,lineno)
1873 1873 if opts.has_key('x'): # -x prevents actual execution
1874 1874 print
1875 1875 else:
1876 1876 print 'done. Executing edited code...'
1877 1877 try:
1878 1878 self.shell.safe_execfile(filename,self.shell.user_ns)
1879 1879 except IOError,msg:
1880 1880 if msg.filename == filename:
1881 1881 warn('File not found. Did you forget to save?')
1882 1882 return
1883 1883 else:
1884 1884 self.shell.showtraceback()
1885 1885 except:
1886 1886 self.shell.showtraceback()
1887 1887 if use_temp:
1888 1888 contents = open(filename).read()
1889 1889 return contents
1890 1890
1891 1891 def magic_xmode(self,parameter_s = ''):
1892 1892 """Switch modes for the exception handlers.
1893 1893
1894 1894 Valid modes: Plain, Context and Verbose.
1895 1895
1896 1896 If called without arguments, acts as a toggle."""
1897 1897
1898 1898 new_mode = parameter_s.strip().capitalize()
1899 1899 try:
1900 1900 self.InteractiveTB.set_mode(mode = new_mode)
1901 1901 print 'Exception reporting mode:',self.InteractiveTB.mode
1902 1902 except:
1903 1903 warn('Error changing exception modes.\n' + str(sys.exc_info()[1]))
1904 1904
1905 1905 def magic_colors(self,parameter_s = ''):
1906 1906 """Switch color scheme for prompts, info system and exception handlers.
1907 1907
1908 1908 Currently implemented schemes: NoColor, Linux, LightBG.
1909 1909
1910 1910 Color scheme names are not case-sensitive."""
1911 1911
1912 1912 new_scheme = parameter_s.strip()
1913 1913 if not new_scheme:
1914 1914 print 'You must specify a color scheme.'
1915 1915 return
1916 1916 # Under Windows, check for Gary Bishop's readline, which is necessary
1917 1917 # for ANSI coloring
1918 1918 if os.name in ['nt','dos']:
1919 1919 try:
1920 1920 import readline
1921 1921 except ImportError:
1922 1922 has_readline = 0
1923 1923 else:
1924 1924 try:
1925 1925 readline.GetOutputFile()
1926 1926 except AttributeError:
1927 1927 has_readline = 0
1928 1928 else:
1929 1929 has_readline = 1
1930 1930 if not has_readline:
1931 1931 msg = """\
1932 1932 Proper color support under MS Windows requires Gary Bishop's readline library.
1933 1933 You can find it at:
1934 1934 http://sourceforge.net/projects/uncpythontools
1935 1935 Gary's readline needs the ctypes module, from:
1936 1936 http://starship.python.net/crew/theller/ctypes
1937 1937
1938 1938 Defaulting color scheme to 'NoColor'"""
1939 1939 new_scheme = 'NoColor'
1940 1940 warn(msg)
1941 1941
1942 1942 # Set prompt colors
1943 1943 try:
1944 1944 self.shell.outputcache.set_colors(new_scheme)
1945 1945 except:
1946 1946 warn('Error changing prompt color schemes.\n'
1947 1947 + str(sys.exc_info()[1]))
1948 1948 else:
1949 1949 self.shell.rc.colors = \
1950 1950 self.shell.outputcache.color_table.active_scheme_name
1951 1951 # Set exception colors
1952 1952 try:
1953 1953 self.shell.InteractiveTB.set_colors(scheme = new_scheme)
1954 1954 self.shell.SyntaxTB.set_colors(scheme = new_scheme)
1955 1955 except:
1956 1956 warn('Error changing exception color schemes.\n'
1957 1957 + str(sys.exc_info()[1]))
1958 1958 # Set info (for 'object?') colors
1959 1959 if self.shell.rc.color_info:
1960 1960 try:
1961 1961 self.shell.inspector.set_active_scheme(new_scheme)
1962 1962 except:
1963 1963 warn('Error changing object inspector color schemes.\n'
1964 1964 + str(sys.exc_info()[1]))
1965 1965 else:
1966 1966 self.shell.inspector.set_active_scheme('NoColor')
1967 1967
1968 1968 def magic_color_info(self,parameter_s = ''):
1969 1969 """Toggle color_info.
1970 1970
1971 1971 The color_info configuration parameter controls whether colors are
1972 1972 used for displaying object details (by things like %psource, %pfile or
1973 1973 the '?' system). This function toggles this value with each call.
1974 1974
1975 1975 Note that unless you have a fairly recent pager (less works better
1976 1976 than more) in your system, using colored object information displays
1977 1977 will not work properly. Test it and see."""
1978 1978
1979 1979 self.shell.rc.color_info = 1 - self.shell.rc.color_info
1980 1980 self.magic_colors(self.shell.rc.colors)
1981 1981 print 'Object introspection functions have now coloring:',
1982 1982 print ['OFF','ON'][self.shell.rc.color_info]
1983 1983
1984 1984 def magic_Pprint(self, parameter_s=''):
1985 1985 """Toggle pretty printing on/off."""
1986 1986
1987 1987 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
1988 1988 print 'Pretty printing has been turned', \
1989 1989 ['OFF','ON'][self.shell.outputcache.Pprint]
1990 1990
1991 def magic_exit(self, parameter_s=''):
1992 """Exit IPython, confirming if configured to do so.
1993
1994 You can configure whether IPython asks for confirmation upon exit by
1995 setting the confirm_exit flag in the ipythonrc file."""
1996
1997 self.shell.exit()
1998
1999 def magic_quit(self, parameter_s=''):
2000 """Exit IPython, confirming if configured to do so (like %exit)"""
2001
2002 self.shell.exit()
2003
1991 2004 def magic_Exit(self, parameter_s=''):
1992 2005 """Exit IPython without confirmation."""
1993 2006
1994 2007 self.shell.exit_now = True
1995 2008
1996 2009 def magic_Quit(self, parameter_s=''):
1997 2010 """Exit IPython without confirmation (like %Exit)."""
1998 2011
1999 2012 self.shell.exit_now = True
2000 2013
2001 2014 #......................................................................
2002 2015 # Functions to implement unix shell-type things
2003 2016
2004 2017 def magic_alias(self, parameter_s = ''):
2005 2018 """Define an alias for a system command.
2006 2019
2007 2020 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2008 2021
2009 2022 Then, typing 'alias_name params' will execute the system command 'cmd
2010 2023 params' (from your underlying operating system).
2011 2024
2012 2025 Aliases have lower precedence than magic functions and Python normal
2013 2026 variables, so if 'foo' is both a Python variable and an alias, the
2014 2027 alias can not be executed until 'del foo' removes the Python variable.
2015 2028
2016 2029 You can use the %l specifier in an alias definition to represent the
2017 2030 whole line when the alias is called. For example:
2018 2031
2019 2032 In [2]: alias all echo "Input in brackets: <%l>"\\
2020 2033 In [3]: all hello world\\
2021 2034 Input in brackets: <hello world>
2022 2035
2023 2036 You can also define aliases with parameters using %s specifiers (one
2024 2037 per parameter):
2025 2038
2026 2039 In [1]: alias parts echo first %s second %s\\
2027 2040 In [2]: %parts A B\\
2028 2041 first A second B\\
2029 2042 In [3]: %parts A\\
2030 2043 Incorrect number of arguments: 2 expected.\\
2031 2044 parts is an alias to: 'echo first %s second %s'
2032 2045
2033 2046 Note that %l and %s are mutually exclusive. You can only use one or
2034 2047 the other in your aliases.
2035 2048
2036 2049 Aliases expand Python variables just like system calls using ! or !!
2037 2050 do: all expressions prefixed with '$' get expanded. For details of
2038 2051 the semantic rules, see PEP-215:
2039 2052 http://www.python.org/peps/pep-0215.html. This is the library used by
2040 2053 IPython for variable expansion. If you want to access a true shell
2041 2054 variable, an extra $ is necessary to prevent its expansion by IPython:
2042 2055
2043 2056 In [6]: alias show echo\\
2044 2057 In [7]: PATH='A Python string'\\
2045 2058 In [8]: show $PATH\\
2046 2059 A Python string\\
2047 2060 In [9]: show $$PATH\\
2048 2061 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2049 2062
2050 2063 You can use the alias facility to acess all of $PATH. See the %rehash
2051 2064 and %rehashx functions, which automatically create aliases for the
2052 2065 contents of your $PATH.
2053 2066
2054 2067 If called with no parameters, %alias prints the current alias table."""
2055 2068
2056 2069 par = parameter_s.strip()
2057 2070 if not par:
2058 2071 if self.shell.rc.automagic:
2059 2072 prechar = ''
2060 2073 else:
2061 2074 prechar = self.shell.ESC_MAGIC
2062 2075 print 'Alias\t\tSystem Command\n'+'-'*30
2063 2076 atab = self.shell.alias_table
2064 2077 aliases = atab.keys()
2065 2078 aliases.sort()
2066 2079 for alias in aliases:
2067 2080 print prechar+alias+'\t\t'+atab[alias][1]
2068 2081 print '-'*30+'\nTotal number of aliases:',len(aliases)
2069 2082 return
2070 2083 try:
2071 2084 alias,cmd = par.split(None,1)
2072 2085 except:
2073 2086 print OInspect.getdoc(self.magic_alias)
2074 2087 else:
2075 2088 nargs = cmd.count('%s')
2076 2089 if nargs>0 and cmd.find('%l')>=0:
2077 2090 error('The %s and %l specifiers are mutually exclusive '
2078 2091 'in alias definitions.')
2079 2092 else: # all looks OK
2080 2093 self.shell.alias_table[alias] = (nargs,cmd)
2081 2094 self.shell.alias_table_validate(verbose=1)
2082 2095 # end magic_alias
2083 2096
2084 2097 def magic_unalias(self, parameter_s = ''):
2085 2098 """Remove an alias"""
2086 2099
2087 2100 aname = parameter_s.strip()
2088 2101 if aname in self.shell.alias_table:
2089 2102 del self.shell.alias_table[aname]
2090 2103
2091 2104 def magic_rehash(self, parameter_s = ''):
2092 2105 """Update the alias table with all entries in $PATH.
2093 2106
2094 2107 This version does no checks on execute permissions or whether the
2095 2108 contents of $PATH are truly files (instead of directories or something
2096 2109 else). For such a safer (but slower) version, use %rehashx."""
2097 2110
2098 2111 # This function (and rehashx) manipulate the alias_table directly
2099 2112 # rather than calling magic_alias, for speed reasons. A rehash on a
2100 2113 # typical Linux box involves several thousand entries, so efficiency
2101 2114 # here is a top concern.
2102 2115
2103 2116 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2104 2117 alias_table = self.shell.alias_table
2105 2118 for pdir in path:
2106 2119 for ff in os.listdir(pdir):
2107 2120 # each entry in the alias table must be (N,name), where
2108 2121 # N is the number of positional arguments of the alias.
2109 2122 alias_table[ff] = (0,ff)
2110 2123 # Make sure the alias table doesn't contain keywords or builtins
2111 2124 self.shell.alias_table_validate()
2112 2125 # Call again init_auto_alias() so we get 'rm -i' and other modified
2113 2126 # aliases since %rehash will probably clobber them
2114 2127 self.shell.init_auto_alias()
2115 2128
2116 2129 def magic_rehashx(self, parameter_s = ''):
2117 2130 """Update the alias table with all executable files in $PATH.
2118 2131
2119 2132 This version explicitly checks that every entry in $PATH is a file
2120 2133 with execute access (os.X_OK), so it is much slower than %rehash.
2121 2134
2122 2135 Under Windows, it checks executability as a match agains a
2123 2136 '|'-separated string of extensions, stored in the IPython config
2124 2137 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2125 2138
2126 2139 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2127 2140 alias_table = self.shell.alias_table
2128 2141
2129 2142 if os.name == 'posix':
2130 2143 isexec = lambda fname:os.path.isfile(fname) and \
2131 2144 os.access(fname,os.X_OK)
2132 2145 else:
2133 2146
2134 2147 try:
2135 2148 winext = os.environ['pathext'].replace(';','|').replace('.','')
2136 2149 except KeyError:
2137 2150 winext = 'exe|com|bat'
2138 2151
2139 2152 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2140 2153 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2141 2154 savedir = os.getcwd()
2142 2155 try:
2143 2156 # write the whole loop for posix/Windows so we don't have an if in
2144 2157 # the innermost part
2145 2158 if os.name == 'posix':
2146 2159 for pdir in path:
2147 2160 os.chdir(pdir)
2148 2161 for ff in os.listdir(pdir):
2149 2162 if isexec(ff):
2150 2163 # each entry in the alias table must be (N,name),
2151 2164 # where N is the number of positional arguments of the
2152 2165 # alias.
2153 2166 alias_table[ff] = (0,ff)
2154 2167 else:
2155 2168 for pdir in path:
2156 2169 os.chdir(pdir)
2157 2170 for ff in os.listdir(pdir):
2158 2171 if isexec(ff):
2159 2172 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2160 2173 # Make sure the alias table doesn't contain keywords or builtins
2161 2174 self.shell.alias_table_validate()
2162 2175 # Call again init_auto_alias() so we get 'rm -i' and other
2163 2176 # modified aliases since %rehashx will probably clobber them
2164 2177 self.shell.init_auto_alias()
2165 2178 finally:
2166 2179 os.chdir(savedir)
2167 2180
2168 2181 def magic_pwd(self, parameter_s = ''):
2169 2182 """Return the current working directory path."""
2170 2183 return os.getcwd()
2171 2184
2172 2185 def magic_cd(self, parameter_s=''):
2173 2186 """Change the current working directory.
2174 2187
2175 2188 This command automatically maintains an internal list of directories
2176 2189 you visit during your IPython session, in the variable _dh. The
2177 2190 command %dhist shows this history nicely formatted.
2178 2191
2179 2192 Usage:
2180 2193
2181 2194 cd 'dir': changes to directory 'dir'.
2182 2195
2183 2196 cd -: changes to the last visited directory.
2184 2197
2185 2198 cd -<n>: changes to the n-th directory in the directory history.
2186 2199
2187 2200 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2188 2201 (note: cd <bookmark_name> is enough if there is no
2189 2202 directory <bookmark_name>, but a bookmark with the name exists.)
2190 2203
2191 2204 Options:
2192 2205
2193 2206 -q: quiet. Do not print the working directory after the cd command is
2194 2207 executed. By default IPython's cd command does print this directory,
2195 2208 since the default prompts do not display path information.
2196 2209
2197 2210 Note that !cd doesn't work for this purpose because the shell where
2198 2211 !command runs is immediately discarded after executing 'command'."""
2199 2212
2200 2213 parameter_s = parameter_s.strip()
2201 2214 bkms = self.shell.persist.get("bookmarks",{})
2202 2215
2203 2216 numcd = re.match(r'(-)(\d+)$',parameter_s)
2204 2217 # jump in directory history by number
2205 2218 if numcd:
2206 2219 nn = int(numcd.group(2))
2207 2220 try:
2208 2221 ps = self.shell.user_ns['_dh'][nn]
2209 2222 except IndexError:
2210 2223 print 'The requested directory does not exist in history.'
2211 2224 return
2212 2225 else:
2213 2226 opts = {}
2214 2227 else:
2215 2228 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2216 2229 # jump to previous
2217 2230 if ps == '-':
2218 2231 try:
2219 2232 ps = self.shell.user_ns['_dh'][-2]
2220 2233 except IndexError:
2221 2234 print 'No previous directory to change to.'
2222 2235 return
2223 2236 # jump to bookmark
2224 2237 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2225 2238 if bkms.has_key(ps):
2226 2239 target = bkms[ps]
2227 2240 print '(bookmark:%s) -> %s' % (ps,target)
2228 2241 ps = target
2229 2242 else:
2230 2243 if bkms:
2231 2244 error("Bookmark '%s' not found. "
2232 2245 "Use '%bookmark -l' to see your bookmarks." % ps)
2233 2246 else:
2234 2247 print "Bookmarks not set - use %bookmark <bookmarkname>"
2235 2248 return
2236 2249
2237 2250 # at this point ps should point to the target dir
2238 2251 if ps:
2239 2252 try:
2240 2253 os.chdir(os.path.expanduser(ps))
2241 2254 except OSError:
2242 2255 print sys.exc_info()[1]
2243 2256 else:
2244 2257 self.shell.user_ns['_dh'].append(os.getcwd())
2245 2258 else:
2246 2259 os.chdir(self.home_dir)
2247 2260 self.shell.user_ns['_dh'].append(os.getcwd())
2248 2261 if not 'q' in opts:
2249 2262 print self.shell.user_ns['_dh'][-1]
2250 2263
2251 2264 def magic_dhist(self, parameter_s=''):
2252 2265 """Print your history of visited directories.
2253 2266
2254 2267 %dhist -> print full history\\
2255 2268 %dhist n -> print last n entries only\\
2256 2269 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2257 2270
2258 2271 This history is automatically maintained by the %cd command, and
2259 2272 always available as the global list variable _dh. You can use %cd -<n>
2260 2273 to go to directory number <n>."""
2261 2274
2262 2275 dh = self.shell.user_ns['_dh']
2263 2276 if parameter_s:
2264 2277 try:
2265 2278 args = map(int,parameter_s.split())
2266 2279 except:
2267 2280 self.arg_err(Magic.magic_dhist)
2268 2281 return
2269 2282 if len(args) == 1:
2270 2283 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2271 2284 elif len(args) == 2:
2272 2285 ini,fin = args
2273 2286 else:
2274 2287 self.arg_err(Magic.magic_dhist)
2275 2288 return
2276 2289 else:
2277 2290 ini,fin = 0,len(dh)
2278 2291 nlprint(dh,
2279 2292 header = 'Directory history (kept in _dh)',
2280 2293 start=ini,stop=fin)
2281 2294
2282 2295 def magic_env(self, parameter_s=''):
2283 2296 """List environment variables."""
2284 2297
2285 2298 # environ is an instance of UserDict
2286 2299 return os.environ.data
2287 2300
2288 2301 def magic_pushd(self, parameter_s=''):
2289 2302 """Place the current dir on stack and change directory.
2290 2303
2291 2304 Usage:\\
2292 2305 %pushd ['dirname']
2293 2306
2294 2307 %pushd with no arguments does a %pushd to your home directory.
2295 2308 """
2296 2309 if parameter_s == '': parameter_s = '~'
2297 2310 if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \
2298 2311 os.path.expanduser(self.dir_stack[0]):
2299 2312 try:
2300 2313 self.magic_cd(parameter_s)
2301 2314 self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~'))
2302 2315 self.magic_dirs()
2303 2316 except:
2304 2317 print 'Invalid directory'
2305 2318 else:
2306 2319 print 'You are already there!'
2307 2320
2308 2321 def magic_popd(self, parameter_s=''):
2309 2322 """Change to directory popped off the top of the stack.
2310 2323 """
2311 2324 if len (self.dir_stack) > 1:
2312 2325 self.dir_stack.pop(0)
2313 2326 self.magic_cd(self.dir_stack[0])
2314 2327 print self.dir_stack[0]
2315 2328 else:
2316 2329 print "You can't remove the starting directory from the stack:",\
2317 2330 self.dir_stack
2318 2331
2319 2332 def magic_dirs(self, parameter_s=''):
2320 2333 """Return the current directory stack."""
2321 2334
2322 2335 return self.dir_stack[:]
2323 2336
2324 2337 def magic_sc(self, parameter_s=''):
2325 2338 """Shell capture - execute a shell command and capture its output.
2326 2339
2327 2340 %sc [options] varname=command
2328 2341
2329 2342 IPython will run the given command using commands.getoutput(), and
2330 2343 will then update the user's interactive namespace with a variable
2331 2344 called varname, containing the value of the call. Your command can
2332 2345 contain shell wildcards, pipes, etc.
2333 2346
2334 2347 The '=' sign in the syntax is mandatory, and the variable name you
2335 2348 supply must follow Python's standard conventions for valid names.
2336 2349
2337 2350 Options:
2338 2351
2339 2352 -l: list output. Split the output on newlines into a list before
2340 2353 assigning it to the given variable. By default the output is stored
2341 2354 as a single string.
2342 2355
2343 2356 -v: verbose. Print the contents of the variable.
2344 2357
2345 2358 In most cases you should not need to split as a list, because the
2346 2359 returned value is a special type of string which can automatically
2347 2360 provide its contents either as a list (split on newlines) or as a
2348 2361 space-separated string. These are convenient, respectively, either
2349 2362 for sequential processing or to be passed to a shell command.
2350 2363
2351 2364 For example:
2352 2365
2353 2366 # Capture into variable a
2354 2367 In [9]: sc a=ls *py
2355 2368
2356 2369 # a is a string with embedded newlines
2357 2370 In [10]: a
2358 2371 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2359 2372
2360 2373 # which can be seen as a list:
2361 2374 In [11]: a.l
2362 2375 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2363 2376
2364 2377 # or as a whitespace-separated string:
2365 2378 In [12]: a.s
2366 2379 Out[12]: 'setup.py win32_manual_post_install.py'
2367 2380
2368 2381 # a.s is useful to pass as a single command line:
2369 2382 In [13]: !wc -l $a.s
2370 2383 146 setup.py
2371 2384 130 win32_manual_post_install.py
2372 2385 276 total
2373 2386
2374 2387 # while the list form is useful to loop over:
2375 2388 In [14]: for f in a.l:
2376 2389 ....: !wc -l $f
2377 2390 ....:
2378 2391 146 setup.py
2379 2392 130 win32_manual_post_install.py
2380 2393
2381 2394 Similiarly, the lists returned by the -l option are also special, in
2382 2395 the sense that you can equally invoke the .s attribute on them to
2383 2396 automatically get a whitespace-separated string from their contents:
2384 2397
2385 2398 In [1]: sc -l b=ls *py
2386 2399
2387 2400 In [2]: b
2388 2401 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2389 2402
2390 2403 In [3]: b.s
2391 2404 Out[3]: 'setup.py win32_manual_post_install.py'
2392 2405
2393 2406 In summary, both the lists and strings used for ouptut capture have
2394 2407 the following special attributes:
2395 2408
2396 2409 .l (or .list) : value as list.
2397 2410 .n (or .nlstr): value as newline-separated string.
2398 2411 .s (or .spstr): value as space-separated string.
2399 2412 """
2400 2413
2401 2414 opts,args = self.parse_options(parameter_s,'lv')
2402 2415 # Try to get a variable name and command to run
2403 2416 try:
2404 2417 # the variable name must be obtained from the parse_options
2405 2418 # output, which uses shlex.split to strip options out.
2406 2419 var,_ = args.split('=',1)
2407 2420 var = var.strip()
2408 2421 # But the the command has to be extracted from the original input
2409 2422 # parameter_s, not on what parse_options returns, to avoid the
2410 2423 # quote stripping which shlex.split performs on it.
2411 2424 _,cmd = parameter_s.split('=',1)
2412 2425 except ValueError:
2413 2426 var,cmd = '',''
2414 2427 if not var:
2415 2428 error('you must specify a variable to assign the command to.')
2416 2429 return
2417 2430 # If all looks ok, proceed
2418 2431 out,err = self.shell.getoutputerror(cmd)
2419 2432 if err:
2420 2433 print >> Term.cerr,err
2421 2434 if opts.has_key('l'):
2422 2435 out = SList(out.split('\n'))
2423 2436 else:
2424 2437 out = LSString(out)
2425 2438 if opts.has_key('v'):
2426 2439 print '%s ==\n%s' % (var,pformat(out))
2427 2440 self.shell.user_ns.update({var:out})
2428 2441
2429 2442 def magic_sx(self, parameter_s=''):
2430 2443 """Shell execute - run a shell command and capture its output.
2431 2444
2432 2445 %sx command
2433 2446
2434 2447 IPython will run the given command using commands.getoutput(), and
2435 2448 return the result formatted as a list (split on '\\n'). Since the
2436 2449 output is _returned_, it will be stored in ipython's regular output
2437 2450 cache Out[N] and in the '_N' automatic variables.
2438 2451
2439 2452 Notes:
2440 2453
2441 2454 1) If an input line begins with '!!', then %sx is automatically
2442 2455 invoked. That is, while:
2443 2456 !ls
2444 2457 causes ipython to simply issue system('ls'), typing
2445 2458 !!ls
2446 2459 is a shorthand equivalent to:
2447 2460 %sx ls
2448 2461
2449 2462 2) %sx differs from %sc in that %sx automatically splits into a list,
2450 2463 like '%sc -l'. The reason for this is to make it as easy as possible
2451 2464 to process line-oriented shell output via further python commands.
2452 2465 %sc is meant to provide much finer control, but requires more
2453 2466 typing.
2454 2467
2455 2468 3) Just like %sc -l, this is a list with special attributes:
2456 2469
2457 2470 .l (or .list) : value as list.
2458 2471 .n (or .nlstr): value as newline-separated string.
2459 2472 .s (or .spstr): value as whitespace-separated string.
2460 2473
2461 2474 This is very useful when trying to use such lists as arguments to
2462 2475 system commands."""
2463 2476
2464 2477 if parameter_s:
2465 2478 out,err = self.shell.getoutputerror(parameter_s)
2466 2479 if err:
2467 2480 print >> Term.cerr,err
2468 2481 return SList(out.split('\n'))
2469 2482
2470 2483 def magic_bg(self, parameter_s=''):
2471 2484 """Run a job in the background, in a separate thread.
2472 2485
2473 2486 For example,
2474 2487
2475 2488 %bg myfunc(x,y,z=1)
2476 2489
2477 2490 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2478 2491 execution starts, a message will be printed indicating the job
2479 2492 number. If your job number is 5, you can use
2480 2493
2481 2494 myvar = jobs.result(5) or myvar = jobs[5].result
2482 2495
2483 2496 to assign this result to variable 'myvar'.
2484 2497
2485 2498 IPython has a job manager, accessible via the 'jobs' object. You can
2486 2499 type jobs? to get more information about it, and use jobs.<TAB> to see
2487 2500 its attributes. All attributes not starting with an underscore are
2488 2501 meant for public use.
2489 2502
2490 2503 In particular, look at the jobs.new() method, which is used to create
2491 2504 new jobs. This magic %bg function is just a convenience wrapper
2492 2505 around jobs.new(), for expression-based jobs. If you want to create a
2493 2506 new job with an explicit function object and arguments, you must call
2494 2507 jobs.new() directly.
2495 2508
2496 2509 The jobs.new docstring also describes in detail several important
2497 2510 caveats associated with a thread-based model for background job
2498 2511 execution. Type jobs.new? for details.
2499 2512
2500 2513 You can check the status of all jobs with jobs.status().
2501 2514
2502 2515 The jobs variable is set by IPython into the Python builtin namespace.
2503 2516 If you ever declare a variable named 'jobs', you will shadow this
2504 2517 name. You can either delete your global jobs variable to regain
2505 2518 access to the job manager, or make a new name and assign it manually
2506 2519 to the manager (stored in IPython's namespace). For example, to
2507 2520 assign the job manager to the Jobs name, use:
2508 2521
2509 2522 Jobs = __builtins__.jobs"""
2510 2523
2511 2524 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2512 2525
2513 2526 def magic_bookmark(self, parameter_s=''):
2514 2527 """Manage IPython's bookmark system.
2515 2528
2516 2529 %bookmark <name> - set bookmark to current dir
2517 2530 %bookmark <name> <dir> - set bookmark to <dir>
2518 2531 %bookmark -l - list all bookmarks
2519 2532 %bookmark -d <name> - remove bookmark
2520 2533 %bookmark -r - remove all bookmarks
2521 2534
2522 2535 You can later on access a bookmarked folder with:
2523 2536 %cd -b <name>
2524 2537 or simply '%cd <name>' if there is no directory called <name> AND
2525 2538 there is such a bookmark defined.
2526 2539
2527 2540 Your bookmarks persist through IPython sessions, but they are
2528 2541 associated with each profile."""
2529 2542
2530 2543 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2531 2544 if len(args) > 2:
2532 2545 error('You can only give at most two arguments')
2533 2546 return
2534 2547
2535 2548 bkms = self.shell.persist.get('bookmarks',{})
2536 2549
2537 2550 if opts.has_key('d'):
2538 2551 try:
2539 2552 todel = args[0]
2540 2553 except IndexError:
2541 2554 error('You must provide a bookmark to delete')
2542 2555 else:
2543 2556 try:
2544 2557 del bkms[todel]
2545 2558 except:
2546 2559 error("Can't delete bookmark '%s'" % todel)
2547 2560 elif opts.has_key('r'):
2548 2561 bkms = {}
2549 2562 elif opts.has_key('l'):
2550 2563 bks = bkms.keys()
2551 2564 bks.sort()
2552 2565 if bks:
2553 2566 size = max(map(len,bks))
2554 2567 else:
2555 2568 size = 0
2556 2569 fmt = '%-'+str(size)+'s -> %s'
2557 2570 print 'Current bookmarks:'
2558 2571 for bk in bks:
2559 2572 print fmt % (bk,bkms[bk])
2560 2573 else:
2561 2574 if not args:
2562 2575 error("You must specify the bookmark name")
2563 2576 elif len(args)==1:
2564 2577 bkms[args[0]] = os.getcwd()
2565 2578 elif len(args)==2:
2566 2579 bkms[args[0]] = args[1]
2567 2580 self.persist['bookmarks'] = bkms
2568 2581
2569 2582 def magic_pycat(self, parameter_s=''):
2570 2583 """Show a syntax-highlighted file through a pager.
2571 2584
2572 2585 This magic is similar to the cat utility, but it will assume the file
2573 2586 to be Python source and will show it with syntax highlighting. """
2574 2587
2575 2588 filename = get_py_filename(parameter_s)
2576 2589 page(self.shell.colorize(file_read(filename)),
2577 2590 screen_lines=self.shell.rc.screen_length)
2578 2591
2579 2592 # end Magic
@@ -1,1964 +1,1958 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 IPython -- An enhanced Interactive Python
4 4
5 5 Requires Python 2.1 or newer.
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 960 2005-12-28 06:51:01Z fperez $
9 $Id: iplib.py 962 2005-12-28 18:04:59Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
13 13 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
14 14 # Copyright (C) 2001-2005 Fernando Perez. <fperez@colorado.edu>
15 15 #
16 16 # Distributed under the terms of the BSD License. The full license is in
17 17 # the file COPYING, distributed as part of this software.
18 18 #
19 19 # Note: this code originally subclassed code.InteractiveConsole from the
20 20 # Python standard library. Over time, all of that class has been copied
21 21 # verbatim here for modifications which could not be accomplished by
22 22 # subclassing. At this point, there are no dependencies at all on the code
23 23 # module anymore (it is not even imported). The Python License (sec. 2)
24 24 # allows for this, but it's always nice to acknowledge credit where credit is
25 25 # due.
26 26 #*****************************************************************************
27 27
28 28 #****************************************************************************
29 29 # Modules and globals
30 30
31 31 from __future__ import generators # for 2.2 backwards-compatibility
32 32
33 33 from IPython import Release
34 34 __author__ = '%s <%s>\n%s <%s>' % \
35 35 ( Release.authors['Janko'] + Release.authors['Fernando'] )
36 36 __license__ = Release.license
37 37 __version__ = Release.version
38 38
39 39 # Python standard modules
40 40 import __main__
41 41 import __builtin__
42 42 import StringIO
43 43 import bdb
44 44 import cPickle as pickle
45 45 import codeop
46 46 import exceptions
47 47 import glob
48 48 import inspect
49 49 import keyword
50 50 import new
51 51 import os
52 52 import pdb
53 53 import pydoc
54 54 import re
55 55 import shutil
56 56 import string
57 57 import sys
58 58 import traceback
59 59 import types
60 60
61 61 from pprint import pprint, pformat
62 62
63 63 # IPython's own modules
64 64 import IPython
65 65 from IPython import OInspect,PyColorize,ultraTB
66 66 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
67 67 from IPython.FakeModule import FakeModule
68 68 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
69 69 from IPython.Logger import Logger
70 70 from IPython.Magic import Magic,magic2python
71 71 from IPython.Struct import Struct
72 72 from IPython.background_jobs import BackgroundJobManager
73 73 from IPython.usage import cmd_line_usage,interactive_usage
74 74 from IPython.genutils import *
75 75
76 76 # store the builtin raw_input globally, and use this always, in case user code
77 77 # overwrites it (like wx.py.PyShell does)
78 78 raw_input_original = raw_input
79 79
80 80 #****************************************************************************
81 81 # Some utility function definitions
82 82
83 83 # This can be replaced with an isspace() call once we drop 2.2 compatibility
84 84 _isspace_match = re.compile(r'^\s+$').match
85 85 def isspace(s):
86 86 return bool(_isspace_match(s))
87 87
88 88 def esc_quotes(strng):
89 89 """Return the input string with single and double quotes escaped out"""
90 90
91 91 return strng.replace('"','\\"').replace("'","\\'")
92 92
93 93 def import_fail_info(mod_name,fns=None):
94 94 """Inform load failure for a module."""
95 95
96 96 if fns == None:
97 97 warn("Loading of %s failed.\n" % (mod_name,))
98 98 else:
99 99 warn("Loading of %s from %s failed.\n" % (fns,mod_name))
100 100
101 101 def qw_lol(indata):
102 102 """qw_lol('a b') -> [['a','b']],
103 103 otherwise it's just a call to qw().
104 104
105 105 We need this to make sure the modules_some keys *always* end up as a
106 106 list of lists."""
107 107
108 108 if type(indata) in StringTypes:
109 109 return [qw(indata)]
110 110 else:
111 111 return qw(indata)
112 112
113 113 def ipmagic(arg_s):
114 114 """Call a magic function by name.
115 115
116 116 Input: a string containing the name of the magic function to call and any
117 117 additional arguments to be passed to the magic.
118 118
119 119 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
120 120 prompt:
121 121
122 122 In[1]: %name -opt foo bar
123 123
124 124 To call a magic without arguments, simply use ipmagic('name').
125 125
126 126 This provides a proper Python function to call IPython's magics in any
127 127 valid Python code you can type at the interpreter, including loops and
128 128 compound statements. It is added by IPython to the Python builtin
129 129 namespace upon initialization."""
130 130
131 131 args = arg_s.split(' ',1)
132 132 magic_name = args[0]
133 133 if magic_name.startswith(__IPYTHON__.ESC_MAGIC):
134 134 magic_name = magic_name[1:]
135 135 try:
136 136 magic_args = args[1]
137 137 except IndexError:
138 138 magic_args = ''
139 139 fn = getattr(__IPYTHON__,'magic_'+magic_name,None)
140 140 if fn is None:
141 141 error("Magic function `%s` not found." % magic_name)
142 142 else:
143 143 magic_args = __IPYTHON__.var_expand(magic_args)
144 144 return fn(magic_args)
145 145
146 146 def ipalias(arg_s):
147 147 """Call an alias by name.
148 148
149 149 Input: a string containing the name of the alias to call and any
150 150 additional arguments to be passed to the magic.
151 151
152 152 ipalias('name -opt foo bar') is equivalent to typing at the ipython
153 153 prompt:
154 154
155 155 In[1]: name -opt foo bar
156 156
157 157 To call an alias without arguments, simply use ipalias('name').
158 158
159 159 This provides a proper Python function to call IPython's aliases in any
160 160 valid Python code you can type at the interpreter, including loops and
161 161 compound statements. It is added by IPython to the Python builtin
162 162 namespace upon initialization."""
163 163
164 164 args = arg_s.split(' ',1)
165 165 alias_name = args[0]
166 166 try:
167 167 alias_args = args[1]
168 168 except IndexError:
169 169 alias_args = ''
170 170 if alias_name in __IPYTHON__.alias_table:
171 171 __IPYTHON__.call_alias(alias_name,alias_args)
172 172 else:
173 173 error("Alias `%s` not found." % alias_name)
174 174
175 175 def softspace(file, newvalue):
176 176 """Copied from code.py, to remove the dependency"""
177 177 oldvalue = 0
178 178 try:
179 179 oldvalue = file.softspace
180 180 except AttributeError:
181 181 pass
182 182 try:
183 183 file.softspace = newvalue
184 184 except (AttributeError, TypeError):
185 185 # "attribute-less object" or "read-only attributes"
186 186 pass
187 187 return oldvalue
188 188
189 189
190 190 #****************************************************************************
191 191 # Local use exceptions
192 192 class SpaceInInput(exceptions.Exception): pass
193 193
194 class IPythonExit(exceptions.Exception): pass
195
196 194 #****************************************************************************
197 195 # Local use classes
198 196 class Bunch: pass
199 197
200 198 class InputList(list):
201 199 """Class to store user input.
202 200
203 201 It's basically a list, but slices return a string instead of a list, thus
204 202 allowing things like (assuming 'In' is an instance):
205 203
206 204 exec In[4:7]
207 205
208 206 or
209 207
210 208 exec In[5:9] + In[14] + In[21:25]"""
211 209
212 210 def __getslice__(self,i,j):
213 211 return ''.join(list.__getslice__(self,i,j))
214 212
215 213 class SyntaxTB(ultraTB.ListTB):
216 214 """Extension which holds some state: the last exception value"""
217 215
218 216 def __init__(self,color_scheme = 'NoColor'):
219 217 ultraTB.ListTB.__init__(self,color_scheme)
220 218 self.last_syntax_error = None
221 219
222 220 def __call__(self, etype, value, elist):
223 221 self.last_syntax_error = value
224 222 ultraTB.ListTB.__call__(self,etype,value,elist)
225 223
226 224 def clear_err_state(self):
227 225 """Return the current error state and clear it"""
228 226 e = self.last_syntax_error
229 227 self.last_syntax_error = None
230 228 return e
231 229
232 230 #****************************************************************************
233 231 # Main IPython class
234 232 class InteractiveShell(Logger, Magic):
235 233 """An enhanced console for Python."""
236 234
237 235 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
238 236 user_ns = None,user_global_ns=None,banner2='',
239 237 custom_exceptions=((),None),embedded=False):
240 238
241 239 # Put a reference to self in builtins so that any form of embedded or
242 240 # imported code can test for being inside IPython.
243 241 __builtin__.__IPYTHON__ = self
244 242
245 243 # And load into builtins ipmagic/ipalias as well
246 244 __builtin__.ipmagic = ipmagic
247 245 __builtin__.ipalias = ipalias
248 246
249 247 # Add to __builtin__ other parts of IPython's public API
250 248 __builtin__.ip_set_hook = self.set_hook
251 249
252 250 # Keep in the builtins a flag for when IPython is active. We set it
253 251 # with setdefault so that multiple nested IPythons don't clobber one
254 252 # another. Each will increase its value by one upon being activated,
255 253 # which also gives us a way to determine the nesting level.
256 254 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
257 255
258 256 # Do the intuitively correct thing for quit/exit: we remove the
259 257 # builtins if they exist, and our own prefilter routine will handle
260 258 # these special cases
261 259 try:
262 260 del __builtin__.exit, __builtin__.quit
263 261 except AttributeError:
264 262 pass
265 263
266 264 # We need to know whether the instance is meant for embedding, since
267 265 # global/local namespaces need to be handled differently in that case
268 266 self.embedded = embedded
269 267
270 268 # command compiler
271 269 self.compile = codeop.CommandCompiler()
272 270
273 271 # User input buffer
274 272 self.buffer = []
275 273
276 274 # Default name given in compilation of code
277 275 self.filename = '<ipython console>'
278 276
279 277 # Create the namespace where the user will operate. user_ns is
280 278 # normally the only one used, and it is passed to the exec calls as
281 279 # the locals argument. But we do carry a user_global_ns namespace
282 280 # given as the exec 'globals' argument, This is useful in embedding
283 281 # situations where the ipython shell opens in a context where the
284 282 # distinction between locals and globals is meaningful.
285 283
286 284 # FIXME. For some strange reason, __builtins__ is showing up at user
287 285 # level as a dict instead of a module. This is a manual fix, but I
288 286 # should really track down where the problem is coming from. Alex
289 287 # Schmolck reported this problem first.
290 288
291 289 # A useful post by Alex Martelli on this topic:
292 290 # Re: inconsistent value from __builtins__
293 291 # Von: Alex Martelli <aleaxit@yahoo.com>
294 292 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
295 293 # Gruppen: comp.lang.python
296 294 # Referenzen: 1
297 295
298 296 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
299 297 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
300 298 # > <type 'dict'>
301 299 # > >>> print type(__builtins__)
302 300 # > <type 'module'>
303 301 # > Is this difference in return value intentional?
304 302
305 303 # Well, it's documented that '__builtins__' can be either a dictionary
306 304 # or a module, and it's been that way for a long time. Whether it's
307 305 # intentional (or sensible), I don't know. In any case, the idea is
308 306 # that if you need to access the built-in namespace directly, you
309 307 # should start with "import __builtin__" (note, no 's') which will
310 308 # definitely give you a module. Yeah, it's somewhat confusing:-(.
311 309
312 310 if user_ns is None:
313 311 # Set __name__ to __main__ to better match the behavior of the
314 312 # normal interpreter.
315 313 user_ns = {'__name__' :'__main__',
316 314 '__builtins__' : __builtin__,
317 315 }
318 316
319 317 if user_global_ns is None:
320 318 user_global_ns = {}
321 319
322 320 # Assign namespaces
323 321 # This is the namespace where all normal user variables live
324 322 self.user_ns = user_ns
325 323 # Embedded instances require a separate namespace for globals.
326 324 # Normally this one is unused by non-embedded instances.
327 325 self.user_global_ns = user_global_ns
328 326 # A namespace to keep track of internal data structures to prevent
329 327 # them from cluttering user-visible stuff. Will be updated later
330 328 self.internal_ns = {}
331 329
332 330 # Namespace of system aliases. Each entry in the alias
333 331 # table must be a 2-tuple of the form (N,name), where N is the number
334 332 # of positional arguments of the alias.
335 333 self.alias_table = {}
336 334
337 335 # A table holding all the namespaces IPython deals with, so that
338 336 # introspection facilities can search easily.
339 337 self.ns_table = {'user':user_ns,
340 338 'user_global':user_global_ns,
341 339 'alias':self.alias_table,
342 340 'internal':self.internal_ns,
343 341 'builtin':__builtin__.__dict__
344 342 }
345 343
346 344 # The user namespace MUST have a pointer to the shell itself.
347 345 self.user_ns[name] = self
348 346
349 347 # We need to insert into sys.modules something that looks like a
350 348 # module but which accesses the IPython namespace, for shelve and
351 349 # pickle to work interactively. Normally they rely on getting
352 350 # everything out of __main__, but for embedding purposes each IPython
353 351 # instance has its own private namespace, so we can't go shoving
354 352 # everything into __main__.
355 353
356 354 # note, however, that we should only do this for non-embedded
357 355 # ipythons, which really mimic the __main__.__dict__ with their own
358 356 # namespace. Embedded instances, on the other hand, should not do
359 357 # this because they need to manage the user local/global namespaces
360 358 # only, but they live within a 'normal' __main__ (meaning, they
361 359 # shouldn't overtake the execution environment of the script they're
362 360 # embedded in).
363 361
364 362 if not embedded:
365 363 try:
366 364 main_name = self.user_ns['__name__']
367 365 except KeyError:
368 366 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
369 367 else:
370 368 #print "pickle hack in place" # dbg
371 369 sys.modules[main_name] = FakeModule(self.user_ns)
372 370
373 371 # List of input with multi-line handling.
374 372 # Fill its zero entry, user counter starts at 1
375 373 self.input_hist = InputList(['\n'])
376 374
377 375 # list of visited directories
378 376 try:
379 377 self.dir_hist = [os.getcwd()]
380 378 except IOError, e:
381 379 self.dir_hist = []
382 380
383 381 # dict of output history
384 382 self.output_hist = {}
385 383
386 384 # dict of things NOT to alias (keywords, builtins and some magics)
387 385 no_alias = {}
388 386 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
389 387 for key in keyword.kwlist + no_alias_magics:
390 388 no_alias[key] = 1
391 389 no_alias.update(__builtin__.__dict__)
392 390 self.no_alias = no_alias
393 391
394 392 # make global variables for user access to these
395 393 self.user_ns['_ih'] = self.input_hist
396 394 self.user_ns['_oh'] = self.output_hist
397 395 self.user_ns['_dh'] = self.dir_hist
398 396
399 397 # user aliases to input and output histories
400 398 self.user_ns['In'] = self.input_hist
401 399 self.user_ns['Out'] = self.output_hist
402 400
403 401 # Store the actual shell's name
404 402 self.name = name
405 403
406 404 # Object variable to store code object waiting execution. This is
407 405 # used mainly by the multithreaded shells, but it can come in handy in
408 406 # other situations. No need to use a Queue here, since it's a single
409 407 # item which gets cleared once run.
410 408 self.code_to_run = None
411 409
412 410 # Job manager (for jobs run as background threads)
413 411 self.jobs = BackgroundJobManager()
414 412 # Put the job manager into builtins so it's always there.
415 413 __builtin__.jobs = self.jobs
416 414
417 415 # escapes for automatic behavior on the command line
418 416 self.ESC_SHELL = '!'
419 417 self.ESC_HELP = '?'
420 418 self.ESC_MAGIC = '%'
421 419 self.ESC_QUOTE = ','
422 420 self.ESC_QUOTE2 = ';'
423 421 self.ESC_PAREN = '/'
424 422
425 423 # And their associated handlers
426 424 self.esc_handlers = {self.ESC_PAREN:self.handle_auto,
427 425 self.ESC_QUOTE:self.handle_auto,
428 426 self.ESC_QUOTE2:self.handle_auto,
429 427 self.ESC_MAGIC:self.handle_magic,
430 428 self.ESC_HELP:self.handle_help,
431 429 self.ESC_SHELL:self.handle_shell_escape,
432 430 }
433 431
434 432 # class initializations
435 433 Logger.__init__(self,log_ns = self.user_ns)
436 434 Magic.__init__(self,self)
437 435
438 436 # an ugly hack to get a pointer to the shell, so I can start writing
439 437 # magic code via this pointer instead of the current mixin salad.
440 438 Magic.set_shell(self,self)
441 439
442 440 # Python source parser/formatter for syntax highlighting
443 441 pyformat = PyColorize.Parser().format
444 442 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
445 443
446 444 # hooks holds pointers used for user-side customizations
447 445 self.hooks = Struct()
448 446
449 447 # Set all default hooks, defined in the IPython.hooks module.
450 448 hooks = IPython.hooks
451 449 for hook_name in hooks.__all__:
452 450 self.set_hook(hook_name,getattr(hooks,hook_name))
453 451
454 452 # Flag to mark unconditional exit
455 453 self.exit_now = False
456 454
457 455 self.usage_min = """\
458 456 An enhanced console for Python.
459 457 Some of its features are:
460 458 - Readline support if the readline library is present.
461 459 - Tab completion in the local namespace.
462 460 - Logging of input, see command-line options.
463 461 - System shell escape via ! , eg !ls.
464 462 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
465 463 - Keeps track of locally defined variables via %who, %whos.
466 464 - Show object information with a ? eg ?x or x? (use ?? for more info).
467 465 """
468 466 if usage: self.usage = usage
469 467 else: self.usage = self.usage_min
470 468
471 469 # Storage
472 470 self.rc = rc # This will hold all configuration information
473 471 self.inputcache = []
474 472 self._boundcache = []
475 473 self.pager = 'less'
476 474 # temporary files used for various purposes. Deleted at exit.
477 475 self.tempfiles = []
478 476
479 477 # Keep track of readline usage (later set by init_readline)
480 478 self.has_readline = False
481 479
482 480 # for pushd/popd management
483 481 try:
484 482 self.home_dir = get_home_dir()
485 483 except HomeDirError,msg:
486 484 fatal(msg)
487 485
488 486 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
489 487
490 488 # Functions to call the underlying shell.
491 489
492 490 # utility to expand user variables via Itpl
493 491 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
494 492 self.user_ns))
495 493 # The first is similar to os.system, but it doesn't return a value,
496 494 # and it allows interpolation of variables in the user's namespace.
497 495 self.system = lambda cmd: shell(self.var_expand(cmd),
498 496 header='IPython system call: ',
499 497 verbose=self.rc.system_verbose)
500 498 # These are for getoutput and getoutputerror:
501 499 self.getoutput = lambda cmd: \
502 500 getoutput(self.var_expand(cmd),
503 501 header='IPython system call: ',
504 502 verbose=self.rc.system_verbose)
505 503 self.getoutputerror = lambda cmd: \
506 504 getoutputerror(str(ItplNS(cmd.replace('#','\#'),
507 505 self.user_ns)),
508 506 header='IPython system call: ',
509 507 verbose=self.rc.system_verbose)
510 508
511 509 # RegExp for splitting line contents into pre-char//first
512 510 # word-method//rest. For clarity, each group in on one line.
513 511
514 512 # WARNING: update the regexp if the above escapes are changed, as they
515 513 # are hardwired in.
516 514
517 515 # Don't get carried away with trying to make the autocalling catch too
518 516 # much: it's better to be conservative rather than to trigger hidden
519 517 # evals() somewhere and end up causing side effects.
520 518
521 519 self.line_split = re.compile(r'^([\s*,;/])'
522 520 r'([\?\w\.]+\w*\s*)'
523 521 r'(\(?.*$)')
524 522
525 523 # Original re, keep around for a while in case changes break something
526 524 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
527 525 # r'(\s*[\?\w\.]+\w*\s*)'
528 526 # r'(\(?.*$)')
529 527
530 528 # RegExp to identify potential function names
531 529 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
532 530 # RegExp to exclude strings with this start from autocalling
533 531 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
534 532
535 533 # try to catch also methods for stuff in lists/tuples/dicts: off
536 534 # (experimental). For this to work, the line_split regexp would need
537 535 # to be modified so it wouldn't break things at '['. That line is
538 536 # nasty enough that I shouldn't change it until I can test it _well_.
539 537 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
540 538
541 539 # keep track of where we started running (mainly for crash post-mortem)
542 540 self.starting_dir = os.getcwd()
543 541
544 542 # Attributes for Logger mixin class, make defaults here
545 543 self._dolog = False
546 544 self.LOG = ''
547 545 self.LOGDEF = '.InteractiveShell.log'
548 546 self.LOGMODE = 'over'
549 547 self.LOGHEAD = Itpl(
550 548 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
551 549 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
552 550 #log# opts = $self.rc.opts
553 551 #log# args = $self.rc.args
554 552 #log# It is safe to make manual edits below here.
555 553 #log#-----------------------------------------------------------------------
556 554 """)
557 555 # Various switches which can be set
558 556 self.CACHELENGTH = 5000 # this is cheap, it's just text
559 557 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
560 558 self.banner2 = banner2
561 559
562 560 # TraceBack handlers:
563 561 # Need two, one for syntax errors and one for other exceptions.
564 562 self.SyntaxTB = SyntaxTB(color_scheme='NoColor')
565 563 # The interactive one is initialized with an offset, meaning we always
566 564 # want to remove the topmost item in the traceback, which is our own
567 565 # internal code. Valid modes: ['Plain','Context','Verbose']
568 566 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
569 567 color_scheme='NoColor',
570 568 tb_offset = 1)
571 569 # and add any custom exception handlers the user may have specified
572 570 self.set_custom_exc(*custom_exceptions)
573 571
574 572 # Object inspector
575 573 self.inspector = OInspect.Inspector(OInspect.InspectColors,
576 574 PyColorize.ANSICodeColors,
577 575 'NoColor')
578 576 # indentation management
579 577 self.autoindent = False
580 578 self.indent_current_nsp = 0
581 579 self.indent_current = '' # actual indent string
582 580
583 581 # Make some aliases automatically
584 582 # Prepare list of shell aliases to auto-define
585 583 if os.name == 'posix':
586 584 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
587 585 'mv mv -i','rm rm -i','cp cp -i',
588 586 'cat cat','less less','clear clear',
589 587 # a better ls
590 588 'ls ls -F',
591 589 # long ls
592 590 'll ls -lF',
593 591 # color ls
594 592 'lc ls -F -o --color',
595 593 # ls normal files only
596 594 'lf ls -F -o --color %l | grep ^-',
597 595 # ls symbolic links
598 596 'lk ls -F -o --color %l | grep ^l',
599 597 # directories or links to directories,
600 598 'ldir ls -F -o --color %l | grep /$',
601 599 # things which are executable
602 600 'lx ls -F -o --color %l | grep ^-..x',
603 601 )
604 602 elif os.name in ['nt','dos']:
605 603 auto_alias = ('dir dir /on', 'ls dir /on',
606 604 'ddir dir /ad /on', 'ldir dir /ad /on',
607 605 'mkdir mkdir','rmdir rmdir','echo echo',
608 606 'ren ren','cls cls','copy copy')
609 607 else:
610 608 auto_alias = ()
611 609 self.auto_alias = map(lambda s:s.split(None,1),auto_alias)
612 610 # Call the actual (public) initializer
613 611 self.init_auto_alias()
614 612 # end __init__
615 613
616 614 def set_hook(self,name,hook):
617 615 """set_hook(name,hook) -> sets an internal IPython hook.
618 616
619 617 IPython exposes some of its internal API as user-modifiable hooks. By
620 618 resetting one of these hooks, you can modify IPython's behavior to
621 619 call at runtime your own routines."""
622 620
623 621 # At some point in the future, this should validate the hook before it
624 622 # accepts it. Probably at least check that the hook takes the number
625 623 # of args it's supposed to.
626 624 setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
627 625
628 626 def set_custom_exc(self,exc_tuple,handler):
629 627 """set_custom_exc(exc_tuple,handler)
630 628
631 629 Set a custom exception handler, which will be called if any of the
632 630 exceptions in exc_tuple occur in the mainloop (specifically, in the
633 631 runcode() method.
634 632
635 633 Inputs:
636 634
637 635 - exc_tuple: a *tuple* of valid exceptions to call the defined
638 636 handler for. It is very important that you use a tuple, and NOT A
639 637 LIST here, because of the way Python's except statement works. If
640 638 you only want to trap a single exception, use a singleton tuple:
641 639
642 640 exc_tuple == (MyCustomException,)
643 641
644 642 - handler: this must be defined as a function with the following
645 643 basic interface: def my_handler(self,etype,value,tb).
646 644
647 645 This will be made into an instance method (via new.instancemethod)
648 646 of IPython itself, and it will be called if any of the exceptions
649 647 listed in the exc_tuple are caught. If the handler is None, an
650 648 internal basic one is used, which just prints basic info.
651 649
652 650 WARNING: by putting in your own exception handler into IPython's main
653 651 execution loop, you run a very good chance of nasty crashes. This
654 652 facility should only be used if you really know what you are doing."""
655 653
656 654 assert type(exc_tuple)==type(()) , \
657 655 "The custom exceptions must be given AS A TUPLE."
658 656
659 657 def dummy_handler(self,etype,value,tb):
660 658 print '*** Simple custom exception handler ***'
661 659 print 'Exception type :',etype
662 660 print 'Exception value:',value
663 661 print 'Traceback :',tb
664 662 print 'Source code :','\n'.join(self.buffer)
665 663
666 664 if handler is None: handler = dummy_handler
667 665
668 666 self.CustomTB = new.instancemethod(handler,self,self.__class__)
669 667 self.custom_exceptions = exc_tuple
670 668
671 669 def set_custom_completer(self,completer,pos=0):
672 670 """set_custom_completer(completer,pos=0)
673 671
674 672 Adds a new custom completer function.
675 673
676 674 The position argument (defaults to 0) is the index in the completers
677 675 list where you want the completer to be inserted."""
678 676
679 677 newcomp = new.instancemethod(completer,self.Completer,
680 678 self.Completer.__class__)
681 679 self.Completer.matchers.insert(pos,newcomp)
682 680
683 681 def complete(self,text):
684 682 """Return a sorted list of all possible completions on text.
685 683
686 684 Inputs:
687 685
688 686 - text: a string of text to be completed on.
689 687
690 688 This is a wrapper around the completion mechanism, similar to what
691 689 readline does at the command line when the TAB key is hit. By
692 690 exposing it as a method, it can be used by other non-readline
693 691 environments (such as GUIs) for text completion.
694 692
695 693 Simple usage example:
696 694
697 695 In [1]: x = 'hello'
698 696
699 697 In [2]: __IP.complete('x.l')
700 698 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
701 699
702 700 complete = self.Completer.complete
703 701 state = 0
704 702 # use a dict so we get unique keys, since ipyhton's multiple
705 703 # completers can return duplicates.
706 704 comps = {}
707 705 while True:
708 706 newcomp = complete(text,state)
709 707 if newcomp is None:
710 708 break
711 709 comps[newcomp] = 1
712 710 state += 1
713 711 outcomps = comps.keys()
714 712 outcomps.sort()
715 713 return outcomps
716 714
717 715 def set_completer_frame(self, frame):
718 716 if frame:
719 717 self.Completer.namespace = frame.f_locals
720 718 self.Completer.global_namespace = frame.f_globals
721 719 else:
722 720 self.Completer.namespace = self.user_ns
723 721 self.Completer.global_namespace = self.user_global_ns
724 722
725 723 def post_config_initialization(self):
726 724 """Post configuration init method
727 725
728 726 This is called after the configuration files have been processed to
729 727 'finalize' the initialization."""
730 728
731 729 rc = self.rc
732 730
733 731 # Load readline proper
734 732 if rc.readline:
735 733 self.init_readline()
736 734
737 735 # Set user colors (don't do it in the constructor above so that it
738 736 # doesn't crash if colors option is invalid)
739 737 self.magic_colors(rc.colors)
740 738
741 739 # Load user aliases
742 740 for alias in rc.alias:
743 741 self.magic_alias(alias)
744 742
745 743 # dynamic data that survives through sessions
746 744 # XXX make the filename a config option?
747 745 persist_base = 'persist'
748 746 if rc.profile:
749 747 persist_base += '_%s' % rc.profile
750 748 self.persist_fname = os.path.join(rc.ipythondir,persist_base)
751 749
752 750 try:
753 751 self.persist = pickle.load(file(self.persist_fname))
754 752 except:
755 753 self.persist = {}
756 754
757 755 def init_auto_alias(self):
758 756 """Define some aliases automatically.
759 757
760 758 These are ALL parameter-less aliases"""
761 759 for alias,cmd in self.auto_alias:
762 760 self.alias_table[alias] = (0,cmd)
763 761
764 762 def alias_table_validate(self,verbose=0):
765 763 """Update information about the alias table.
766 764
767 765 In particular, make sure no Python keywords/builtins are in it."""
768 766
769 767 no_alias = self.no_alias
770 768 for k in self.alias_table.keys():
771 769 if k in no_alias:
772 770 del self.alias_table[k]
773 771 if verbose:
774 772 print ("Deleting alias <%s>, it's a Python "
775 773 "keyword or builtin." % k)
776 774
777 775 def set_autoindent(self,value=None):
778 776 """Set the autoindent flag, checking for readline support.
779 777
780 778 If called with no arguments, it acts as a toggle."""
781 779
782 780 if not self.has_readline:
783 781 if os.name == 'posix':
784 782 warn("The auto-indent feature requires the readline library")
785 783 self.autoindent = 0
786 784 return
787 785 if value is None:
788 786 self.autoindent = not self.autoindent
789 787 else:
790 788 self.autoindent = value
791 789
792 790 def rc_set_toggle(self,rc_field,value=None):
793 791 """Set or toggle a field in IPython's rc config. structure.
794 792
795 793 If called with no arguments, it acts as a toggle.
796 794
797 795 If called with a non-existent field, the resulting AttributeError
798 796 exception will propagate out."""
799 797
800 798 rc_val = getattr(self.rc,rc_field)
801 799 if value is None:
802 800 value = not rc_val
803 801 setattr(self.rc,rc_field,value)
804 802
805 803 def user_setup(self,ipythondir,rc_suffix,mode='install'):
806 804 """Install the user configuration directory.
807 805
808 806 Can be called when running for the first time or to upgrade the user's
809 807 .ipython/ directory with the mode parameter. Valid modes are 'install'
810 808 and 'upgrade'."""
811 809
812 810 def wait():
813 811 try:
814 812 raw_input("Please press <RETURN> to start IPython.")
815 813 except EOFError:
816 814 print >> Term.cout
817 815 print '*'*70
818 816
819 817 cwd = os.getcwd() # remember where we started
820 818 glb = glob.glob
821 819 print '*'*70
822 820 if mode == 'install':
823 821 print \
824 822 """Welcome to IPython. I will try to create a personal configuration directory
825 823 where you can customize many aspects of IPython's functionality in:\n"""
826 824 else:
827 825 print 'I am going to upgrade your configuration in:'
828 826
829 827 print ipythondir
830 828
831 829 rcdirend = os.path.join('IPython','UserConfig')
832 830 cfg = lambda d: os.path.join(d,rcdirend)
833 831 try:
834 832 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
835 833 except IOError:
836 834 warning = """
837 835 Installation error. IPython's directory was not found.
838 836
839 837 Check the following:
840 838
841 839 The ipython/IPython directory should be in a directory belonging to your
842 840 PYTHONPATH environment variable (that is, it should be in a directory
843 841 belonging to sys.path). You can copy it explicitly there or just link to it.
844 842
845 843 IPython will proceed with builtin defaults.
846 844 """
847 845 warn(warning)
848 846 wait()
849 847 return
850 848
851 849 if mode == 'install':
852 850 try:
853 851 shutil.copytree(rcdir,ipythondir)
854 852 os.chdir(ipythondir)
855 853 rc_files = glb("ipythonrc*")
856 854 for rc_file in rc_files:
857 855 os.rename(rc_file,rc_file+rc_suffix)
858 856 except:
859 857 warning = """
860 858
861 859 There was a problem with the installation:
862 860 %s
863 861 Try to correct it or contact the developers if you think it's a bug.
864 862 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
865 863 warn(warning)
866 864 wait()
867 865 return
868 866
869 867 elif mode == 'upgrade':
870 868 try:
871 869 os.chdir(ipythondir)
872 870 except:
873 871 print """
874 872 Can not upgrade: changing to directory %s failed. Details:
875 873 %s
876 874 """ % (ipythondir,sys.exc_info()[1])
877 875 wait()
878 876 return
879 877 else:
880 878 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
881 879 for new_full_path in sources:
882 880 new_filename = os.path.basename(new_full_path)
883 881 if new_filename.startswith('ipythonrc'):
884 882 new_filename = new_filename + rc_suffix
885 883 # The config directory should only contain files, skip any
886 884 # directories which may be there (like CVS)
887 885 if os.path.isdir(new_full_path):
888 886 continue
889 887 if os.path.exists(new_filename):
890 888 old_file = new_filename+'.old'
891 889 if os.path.exists(old_file):
892 890 os.remove(old_file)
893 891 os.rename(new_filename,old_file)
894 892 shutil.copy(new_full_path,new_filename)
895 893 else:
896 894 raise ValueError,'unrecognized mode for install:',`mode`
897 895
898 896 # Fix line-endings to those native to each platform in the config
899 897 # directory.
900 898 try:
901 899 os.chdir(ipythondir)
902 900 except:
903 901 print """
904 902 Problem: changing to directory %s failed.
905 903 Details:
906 904 %s
907 905
908 906 Some configuration files may have incorrect line endings. This should not
909 907 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
910 908 wait()
911 909 else:
912 910 for fname in glb('ipythonrc*'):
913 911 try:
914 912 native_line_ends(fname,backup=0)
915 913 except IOError:
916 914 pass
917 915
918 916 if mode == 'install':
919 917 print """
920 918 Successful installation!
921 919
922 920 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
923 921 IPython manual (there are both HTML and PDF versions supplied with the
924 922 distribution) to make sure that your system environment is properly configured
925 923 to take advantage of IPython's features."""
926 924 else:
927 925 print """
928 926 Successful upgrade!
929 927
930 928 All files in your directory:
931 929 %(ipythondir)s
932 930 which would have been overwritten by the upgrade were backed up with a .old
933 931 extension. If you had made particular customizations in those files you may
934 932 want to merge them back into the new files.""" % locals()
935 933 wait()
936 934 os.chdir(cwd)
937 935 # end user_setup()
938 936
939 937 def atexit_operations(self):
940 938 """This will be executed at the time of exit.
941 939
942 940 Saving of persistent data should be performed here. """
943 941
944 942 # input history
945 943 self.savehist()
946 944
947 945 # Cleanup all tempfiles left around
948 946 for tfile in self.tempfiles:
949 947 try:
950 948 os.unlink(tfile)
951 949 except OSError:
952 950 pass
953 951
954 952 # save the "persistent data" catch-all dictionary
955 953 try:
956 954 pickle.dump(self.persist, open(self.persist_fname,"w"))
957 955 except:
958 956 print "*** ERROR *** persistent data saving failed."
959 957
960 958 def savehist(self):
961 959 """Save input history to a file (via readline library)."""
962 960 try:
963 961 self.readline.write_history_file(self.histfile)
964 962 except:
965 963 print 'Unable to save IPython command history to file: ' + \
966 964 `self.histfile`
967 965
968 966 def pre_readline(self):
969 967 """readline hook to be used at the start of each line.
970 968
971 969 Currently it handles auto-indent only."""
972 970
973 971 self.readline.insert_text(self.indent_current)
974 972
975 973 def init_readline(self):
976 974 """Command history completion/saving/reloading."""
977 975 try:
978 976 import readline
979 977 except ImportError:
980 978 self.has_readline = 0
981 979 self.readline = None
982 980 # no point in bugging windows users with this every time:
983 981 if os.name == 'posix':
984 982 warn('Readline services not available on this platform.')
985 983 else:
986 984 import atexit
987 985 from IPython.completer import IPCompleter
988 986 self.Completer = IPCompleter(self,
989 987 self.user_ns,
990 988 self.user_global_ns,
991 989 self.rc.readline_omit__names,
992 990 self.alias_table)
993 991
994 992 # Platform-specific configuration
995 993 if os.name == 'nt':
996 994 self.readline_startup_hook = readline.set_pre_input_hook
997 995 else:
998 996 self.readline_startup_hook = readline.set_startup_hook
999 997
1000 998 # Load user's initrc file (readline config)
1001 999 inputrc_name = os.environ.get('INPUTRC')
1002 1000 if inputrc_name is None:
1003 1001 home_dir = get_home_dir()
1004 1002 if home_dir is not None:
1005 1003 inputrc_name = os.path.join(home_dir,'.inputrc')
1006 1004 if os.path.isfile(inputrc_name):
1007 1005 try:
1008 1006 readline.read_init_file(inputrc_name)
1009 1007 except:
1010 1008 warn('Problems reading readline initialization file <%s>'
1011 1009 % inputrc_name)
1012 1010
1013 1011 self.has_readline = 1
1014 1012 self.readline = readline
1015 1013 # save this in sys so embedded copies can restore it properly
1016 1014 sys.ipcompleter = self.Completer.complete
1017 1015 readline.set_completer(self.Completer.complete)
1018 1016
1019 1017 # Configure readline according to user's prefs
1020 1018 for rlcommand in self.rc.readline_parse_and_bind:
1021 1019 readline.parse_and_bind(rlcommand)
1022 1020
1023 1021 # remove some chars from the delimiters list
1024 1022 delims = readline.get_completer_delims()
1025 1023 delims = delims.translate(string._idmap,
1026 1024 self.rc.readline_remove_delims)
1027 1025 readline.set_completer_delims(delims)
1028 1026 # otherwise we end up with a monster history after a while:
1029 1027 readline.set_history_length(1000)
1030 1028 try:
1031 1029 #print '*** Reading readline history' # dbg
1032 1030 readline.read_history_file(self.histfile)
1033 1031 except IOError:
1034 1032 pass # It doesn't exist yet.
1035 1033
1036 1034 atexit.register(self.atexit_operations)
1037 1035 del atexit
1038 1036
1039 1037 # Configure auto-indent for all platforms
1040 1038 self.set_autoindent(self.rc.autoindent)
1041 1039
1042 1040 def _should_recompile(self,e):
1043 1041 """Utility routine for edit_syntax_error"""
1044 1042
1045 1043 if e.filename in ('<ipython console>','<input>','<string>',
1046 1044 '<console>'):
1047 1045 return False
1048 1046 try:
1049 1047 if not ask_yes_no('Return to editor to correct syntax error? '
1050 1048 '[Y/n] ','y'):
1051 1049 return False
1052 1050 except EOFError:
1053 1051 return False
1054 1052 self.hooks.fix_error_editor(e.filename,e.lineno,e.offset,e.msg)
1055 1053 return True
1056 1054
1057 1055 def edit_syntax_error(self):
1058 1056 """The bottom half of the syntax error handler called in the main loop.
1059 1057
1060 1058 Loop until syntax error is fixed or user cancels.
1061 1059 """
1062 1060
1063 1061 while self.SyntaxTB.last_syntax_error:
1064 1062 # copy and clear last_syntax_error
1065 1063 err = self.SyntaxTB.clear_err_state()
1066 1064 if not self._should_recompile(err):
1067 1065 return
1068 1066 try:
1069 1067 # may set last_syntax_error again if a SyntaxError is raised
1070 1068 self.safe_execfile(err.filename,self.shell.user_ns)
1071 1069 except:
1072 1070 self.showtraceback()
1073 1071 else:
1074 1072 f = file(err.filename)
1075 1073 try:
1076 1074 sys.displayhook(f.read())
1077 1075 finally:
1078 1076 f.close()
1079 1077
1080 1078 def showsyntaxerror(self, filename=None):
1081 1079 """Display the syntax error that just occurred.
1082 1080
1083 1081 This doesn't display a stack trace because there isn't one.
1084 1082
1085 1083 If a filename is given, it is stuffed in the exception instead
1086 1084 of what was there before (because Python's parser always uses
1087 1085 "<string>" when reading from a string).
1088 1086 """
1089 1087 type, value, sys.last_traceback = sys.exc_info()
1090 1088 sys.last_type = type
1091 1089 sys.last_value = value
1092 1090 if filename and type is SyntaxError:
1093 1091 # Work hard to stuff the correct filename in the exception
1094 1092 try:
1095 1093 msg, (dummy_filename, lineno, offset, line) = value
1096 1094 except:
1097 1095 # Not the format we expect; leave it alone
1098 1096 pass
1099 1097 else:
1100 1098 # Stuff in the right filename
1101 1099 try:
1102 1100 # Assume SyntaxError is a class exception
1103 1101 value = SyntaxError(msg, (filename, lineno, offset, line))
1104 1102 except:
1105 1103 # If that failed, assume SyntaxError is a string
1106 1104 value = msg, (filename, lineno, offset, line)
1107 1105 self.SyntaxTB(type,value,[])
1108 1106
1109 1107 def debugger(self):
1110 1108 """Call the pdb debugger."""
1111 1109
1112 1110 if not self.rc.pdb:
1113 1111 return
1114 1112 pdb.pm()
1115 1113
1116 1114 def showtraceback(self,exc_tuple = None,filename=None):
1117 1115 """Display the exception that just occurred."""
1118 1116
1119 1117 # Though this won't be called by syntax errors in the input line,
1120 1118 # there may be SyntaxError cases whith imported code.
1121 1119 if exc_tuple is None:
1122 1120 type, value, tb = sys.exc_info()
1123 1121 else:
1124 1122 type, value, tb = exc_tuple
1125 1123 if type is SyntaxError:
1126 1124 self.showsyntaxerror(filename)
1127 1125 else:
1128 1126 sys.last_type = type
1129 1127 sys.last_value = value
1130 1128 sys.last_traceback = tb
1131 1129 self.InteractiveTB()
1132 1130 if self.InteractiveTB.call_pdb and self.has_readline:
1133 1131 # pdb mucks up readline, fix it back
1134 1132 self.readline.set_completer(self.Completer.complete)
1135 1133
1136 1134 def update_cache(self, line):
1137 1135 """puts line into cache"""
1138 1136 self.inputcache.insert(0, line) # This copies the cache every time ... :-(
1139 1137 if len(self.inputcache) >= self.CACHELENGTH:
1140 1138 self.inputcache.pop() # This doesn't :-)
1141 1139
1142 1140 def mainloop(self,banner=None):
1143 1141 """Creates the local namespace and starts the mainloop.
1144 1142
1145 1143 If an optional banner argument is given, it will override the
1146 1144 internally created default banner."""
1147 1145
1148 1146 if self.rc.c: # Emulate Python's -c option
1149 1147 self.exec_init_cmd()
1150 1148 if banner is None:
1151 1149 if self.rc.banner:
1152 1150 banner = self.BANNER+self.banner2
1153 1151 else:
1154 1152 banner = ''
1155 1153 self.interact(banner)
1156 1154
1157 1155 def exec_init_cmd(self):
1158 1156 """Execute a command given at the command line.
1159 1157
1160 1158 This emulates Python's -c option."""
1161 1159
1162 1160 sys.argv = ['-c']
1163 1161 self.push(self.rc.c)
1164 1162
1165 1163 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1166 1164 """Embeds IPython into a running python program.
1167 1165
1168 1166 Input:
1169 1167
1170 1168 - header: An optional header message can be specified.
1171 1169
1172 1170 - local_ns, global_ns: working namespaces. If given as None, the
1173 1171 IPython-initialized one is updated with __main__.__dict__, so that
1174 1172 program variables become visible but user-specific configuration
1175 1173 remains possible.
1176 1174
1177 1175 - stack_depth: specifies how many levels in the stack to go to
1178 1176 looking for namespaces (when local_ns and global_ns are None). This
1179 1177 allows an intermediate caller to make sure that this function gets
1180 1178 the namespace from the intended level in the stack. By default (0)
1181 1179 it will get its locals and globals from the immediate caller.
1182 1180
1183 1181 Warning: it's possible to use this in a program which is being run by
1184 1182 IPython itself (via %run), but some funny things will happen (a few
1185 1183 globals get overwritten). In the future this will be cleaned up, as
1186 1184 there is no fundamental reason why it can't work perfectly."""
1187 1185
1188 1186 # Get locals and globals from caller
1189 1187 if local_ns is None or global_ns is None:
1190 1188 call_frame = sys._getframe(stack_depth).f_back
1191 1189
1192 1190 if local_ns is None:
1193 1191 local_ns = call_frame.f_locals
1194 1192 if global_ns is None:
1195 1193 global_ns = call_frame.f_globals
1196 1194
1197 1195 # Update namespaces and fire up interpreter
1198 1196 self.user_ns = local_ns
1199 1197 self.user_global_ns = global_ns
1200 1198
1201 1199 # Patch for global embedding to make sure that things don't overwrite
1202 1200 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1203 1201 # FIXME. Test this a bit more carefully (the if.. is new)
1204 1202 if local_ns is None and global_ns is None:
1205 1203 self.user_global_ns.update(__main__.__dict__)
1206 1204
1207 1205 # make sure the tab-completer has the correct frame information, so it
1208 1206 # actually completes using the frame's locals/globals
1209 1207 self.set_completer_frame(call_frame)
1210 1208
1211 1209 self.interact(header)
1212 1210
1213 1211 def interact(self, banner=None):
1214 1212 """Closely emulate the interactive Python console.
1215 1213
1216 1214 The optional banner argument specify the banner to print
1217 1215 before the first interaction; by default it prints a banner
1218 1216 similar to the one printed by the real Python interpreter,
1219 1217 followed by the current class name in parentheses (so as not
1220 1218 to confuse this with the real interpreter -- since it's so
1221 1219 close!).
1222 1220
1223 1221 """
1224 1222 cprt = 'Type "copyright", "credits" or "license" for more information.'
1225 1223 if banner is None:
1226 1224 self.write("Python %s on %s\n%s\n(%s)\n" %
1227 1225 (sys.version, sys.platform, cprt,
1228 1226 self.__class__.__name__))
1229 1227 else:
1230 1228 self.write(banner)
1231 1229
1232 1230 more = 0
1233 1231
1234 1232 # Mark activity in the builtins
1235 1233 __builtin__.__dict__['__IPYTHON__active'] += 1
1236 1234
1237 1235 # compiled regexps for autoindent management
1238 1236 ini_spaces_re = re.compile(r'^(\s+)')
1239 1237 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
1240 1238
1241 1239 # exit_now is set by a call to %Exit or %Quit
1242 1240 while not self.exit_now:
1243 1241 try:
1244 1242 if more:
1245 1243 prompt = self.outputcache.prompt2
1246 1244 if self.autoindent:
1247 1245 self.readline_startup_hook(self.pre_readline)
1248 1246 else:
1249 1247 prompt = self.outputcache.prompt1
1250 1248 try:
1251 1249 line = self.raw_input(prompt,more)
1252 1250 if self.autoindent:
1253 1251 self.readline_startup_hook(None)
1254 1252 except EOFError:
1255 1253 if self.autoindent:
1256 1254 self.readline_startup_hook(None)
1257 1255 self.write("\n")
1258 1256 self.exit()
1259 except IPythonExit:
1260 self.exit()
1261 1257 else:
1262 1258 more = self.push(line)
1263 1259 # Auto-indent management
1264 1260 if self.autoindent:
1265 1261 if line:
1266 1262 ini_spaces = ini_spaces_re.match(line)
1267 1263 if ini_spaces:
1268 1264 nspaces = ini_spaces.end()
1269 1265 else:
1270 1266 nspaces = 0
1271 1267 self.indent_current_nsp = nspaces
1272 1268
1273 1269 if line[-1] == ':':
1274 1270 self.indent_current_nsp += 4
1275 1271 elif dedent_re.match(line):
1276 1272 self.indent_current_nsp -= 4
1277 1273 else:
1278 1274 self.indent_current_nsp = 0
1279 1275
1280 1276 # indent_current is the actual string to be inserted
1281 1277 # by the readline hooks for indentation
1282 1278 self.indent_current = ' '* self.indent_current_nsp
1283 1279
1284 1280 if (self.SyntaxTB.last_syntax_error and
1285 1281 self.rc.autoedit_syntax):
1286 1282 self.edit_syntax_error()
1287 1283
1288 1284 except KeyboardInterrupt:
1289 1285 self.write("\nKeyboardInterrupt\n")
1290 1286 self.resetbuffer()
1291 1287 more = 0
1292 1288 # keep cache in sync with the prompt counter:
1293 1289 self.outputcache.prompt_count -= 1
1294 1290
1295 1291 if self.autoindent:
1296 1292 self.indent_current_nsp = 0
1297 1293 self.indent_current = ' '* self.indent_current_nsp
1298 1294
1299 1295 except bdb.BdbQuit:
1300 1296 warn("The Python debugger has exited with a BdbQuit exception.\n"
1301 1297 "Because of how pdb handles the stack, it is impossible\n"
1302 1298 "for IPython to properly format this particular exception.\n"
1303 1299 "IPython will resume normal operation.")
1304 1300
1305 1301 # We are off again...
1306 1302 __builtin__.__dict__['__IPYTHON__active'] -= 1
1307 1303
1308 1304 def excepthook(self, type, value, tb):
1309 1305 """One more defense for GUI apps that call sys.excepthook.
1310 1306
1311 1307 GUI frameworks like wxPython trap exceptions and call
1312 1308 sys.excepthook themselves. I guess this is a feature that
1313 1309 enables them to keep running after exceptions that would
1314 1310 otherwise kill their mainloop. This is a bother for IPython
1315 1311 which excepts to catch all of the program exceptions with a try:
1316 1312 except: statement.
1317 1313
1318 1314 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1319 1315 any app directly invokes sys.excepthook, it will look to the user like
1320 1316 IPython crashed. In order to work around this, we can disable the
1321 1317 CrashHandler and replace it with this excepthook instead, which prints a
1322 1318 regular traceback using our InteractiveTB. In this fashion, apps which
1323 1319 call sys.excepthook will generate a regular-looking exception from
1324 1320 IPython, and the CrashHandler will only be triggered by real IPython
1325 1321 crashes.
1326 1322
1327 1323 This hook should be used sparingly, only in places which are not likely
1328 1324 to be true IPython errors.
1329 1325 """
1330 1326
1331 1327 self.InteractiveTB(type, value, tb, tb_offset=0)
1332 1328 if self.InteractiveTB.call_pdb and self.has_readline:
1333 1329 self.readline.set_completer(self.Completer.complete)
1334 1330
1335 1331 def call_alias(self,alias,rest=''):
1336 1332 """Call an alias given its name and the rest of the line.
1337 1333
1338 1334 This function MUST be given a proper alias, because it doesn't make
1339 1335 any checks when looking up into the alias table. The caller is
1340 1336 responsible for invoking it only with a valid alias."""
1341 1337
1342 1338 #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg
1343 1339 nargs,cmd = self.alias_table[alias]
1344 1340 # Expand the %l special to be the user's input line
1345 1341 if cmd.find('%l') >= 0:
1346 1342 cmd = cmd.replace('%l',rest)
1347 1343 rest = ''
1348 1344 if nargs==0:
1349 1345 # Simple, argument-less aliases
1350 1346 cmd = '%s %s' % (cmd,rest)
1351 1347 else:
1352 1348 # Handle aliases with positional arguments
1353 1349 args = rest.split(None,nargs)
1354 1350 if len(args)< nargs:
1355 1351 error('Alias <%s> requires %s arguments, %s given.' %
1356 1352 (alias,nargs,len(args)))
1357 1353 return
1358 1354 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1359 1355 # Now call the macro, evaluating in the user's namespace
1360 1356 try:
1361 1357 self.system(cmd)
1362 1358 except:
1363 1359 self.showtraceback()
1364 1360
1365 1361 def runlines(self,lines):
1366 1362 """Run a string of one or more lines of source.
1367 1363
1368 1364 This method is capable of running a string containing multiple source
1369 1365 lines, as if they had been entered at the IPython prompt. Since it
1370 1366 exposes IPython's processing machinery, the given strings can contain
1371 1367 magic calls (%magic), special shell access (!cmd), etc."""
1372 1368
1373 1369 # We must start with a clean buffer, in case this is run from an
1374 1370 # interactive IPython session (via a magic, for example).
1375 1371 self.resetbuffer()
1376 1372 lines = lines.split('\n')
1377 1373 more = 0
1378 1374 for line in lines:
1379 1375 # skip blank lines so we don't mess up the prompt counter, but do
1380 1376 # NOT skip even a blank line if we are in a code block (more is
1381 1377 # true)
1382 1378 if line or more:
1383 1379 more = self.push((self.prefilter(line,more)))
1384 1380 # IPython's runsource returns None if there was an error
1385 1381 # compiling the code. This allows us to stop processing right
1386 1382 # away, so the user gets the error message at the right place.
1387 1383 if more is None:
1388 1384 break
1389 1385 # final newline in case the input didn't have it, so that the code
1390 1386 # actually does get executed
1391 1387 if more:
1392 1388 self.push('\n')
1393 1389
1394 1390 def runsource(self, source, filename='<input>', symbol='single'):
1395 1391 """Compile and run some source in the interpreter.
1396 1392
1397 1393 Arguments are as for compile_command().
1398 1394
1399 1395 One several things can happen:
1400 1396
1401 1397 1) The input is incorrect; compile_command() raised an
1402 1398 exception (SyntaxError or OverflowError). A syntax traceback
1403 1399 will be printed by calling the showsyntaxerror() method.
1404 1400
1405 1401 2) The input is incomplete, and more input is required;
1406 1402 compile_command() returned None. Nothing happens.
1407 1403
1408 1404 3) The input is complete; compile_command() returned a code
1409 1405 object. The code is executed by calling self.runcode() (which
1410 1406 also handles run-time exceptions, except for SystemExit).
1411 1407
1412 1408 The return value is:
1413 1409
1414 1410 - True in case 2
1415 1411
1416 1412 - False in the other cases, unless an exception is raised, where
1417 1413 None is returned instead. This can be used by external callers to
1418 1414 know whether to continue feeding input or not.
1419 1415
1420 1416 The return value can be used to decide whether to use sys.ps1 or
1421 1417 sys.ps2 to prompt the next line."""
1422 1418
1423 1419 try:
1424 1420 code = self.compile(source,filename,symbol)
1425 1421 except (OverflowError, SyntaxError, ValueError):
1426 1422 # Case 1
1427 1423 self.showsyntaxerror(filename)
1428 1424 return None
1429 1425
1430 1426 if code is None:
1431 1427 # Case 2
1432 1428 return True
1433 1429
1434 1430 # Case 3
1435 1431 # We store the code object so that threaded shells and
1436 1432 # custom exception handlers can access all this info if needed.
1437 1433 # The source corresponding to this can be obtained from the
1438 1434 # buffer attribute as '\n'.join(self.buffer).
1439 1435 self.code_to_run = code
1440 1436 # now actually execute the code object
1441 1437 if self.runcode(code) == 0:
1442 1438 return False
1443 1439 else:
1444 1440 return None
1445 1441
1446 1442 def runcode(self,code_obj):
1447 1443 """Execute a code object.
1448 1444
1449 1445 When an exception occurs, self.showtraceback() is called to display a
1450 1446 traceback.
1451 1447
1452 1448 Return value: a flag indicating whether the code to be run completed
1453 1449 successfully:
1454 1450
1455 1451 - 0: successful execution.
1456 1452 - 1: an error occurred.
1457 1453 """
1458 1454
1459 1455 # Set our own excepthook in case the user code tries to call it
1460 1456 # directly, so that the IPython crash handler doesn't get triggered
1461 1457 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1462 1458 outflag = 1 # happens in more places, so it's easier as default
1463 1459 try:
1464 1460 try:
1465 1461 # Embedded instances require separate global/local namespaces
1466 1462 # so they can see both the surrounding (local) namespace and
1467 1463 # the module-level globals when called inside another function.
1468 1464 if self.embedded:
1469 1465 exec code_obj in self.user_global_ns, self.user_ns
1470 1466 # Normal (non-embedded) instances should only have a single
1471 1467 # namespace for user code execution, otherwise functions won't
1472 1468 # see interactive top-level globals.
1473 1469 else:
1474 1470 exec code_obj in self.user_ns
1475 1471 finally:
1476 1472 # Reset our crash handler in place
1477 1473 sys.excepthook = old_excepthook
1478 1474 except SystemExit:
1479 1475 self.resetbuffer()
1480 1476 self.showtraceback()
1481 1477 warn("Type exit or quit to exit IPython "
1482 1478 "(%Exit or %Quit do so unconditionally).",level=1)
1483 1479 except self.custom_exceptions:
1484 1480 etype,value,tb = sys.exc_info()
1485 1481 self.CustomTB(etype,value,tb)
1486 1482 except:
1487 1483 self.showtraceback()
1488 1484 else:
1489 1485 outflag = 0
1490 1486 if softspace(sys.stdout, 0):
1491 1487 print
1492 1488 # Flush out code object which has been run (and source)
1493 1489 self.code_to_run = None
1494 1490 return outflag
1495 1491
1496 1492 def push(self, line):
1497 1493 """Push a line to the interpreter.
1498 1494
1499 1495 The line should not have a trailing newline; it may have
1500 1496 internal newlines. The line is appended to a buffer and the
1501 1497 interpreter's runsource() method is called with the
1502 1498 concatenated contents of the buffer as source. If this
1503 1499 indicates that the command was executed or invalid, the buffer
1504 1500 is reset; otherwise, the command is incomplete, and the buffer
1505 1501 is left as it was after the line was appended. The return
1506 1502 value is 1 if more input is required, 0 if the line was dealt
1507 1503 with in some way (this is the same as runsource()).
1508 1504
1509 1505 """
1510 1506 self.buffer.append(line)
1511 1507 more = self.runsource('\n'.join(self.buffer), self.filename)
1512 1508 if not more:
1513 1509 self.resetbuffer()
1514 1510 return more
1515 1511
1516 1512 def resetbuffer(self):
1517 1513 """Reset the input buffer."""
1518 1514 self.buffer[:] = []
1519 1515
1520 1516 def raw_input(self,prompt='',continue_prompt=False):
1521 1517 """Write a prompt and read a line.
1522 1518
1523 1519 The returned line does not include the trailing newline.
1524 1520 When the user enters the EOF key sequence, EOFError is raised.
1525 1521
1526 1522 Optional inputs:
1527 1523
1528 1524 - prompt(''): a string to be printed to prompt the user.
1529 1525
1530 1526 - continue_prompt(False): whether this line is the first one or a
1531 1527 continuation in a sequence of inputs.
1532 1528 """
1533 1529
1534 1530 line = raw_input_original(prompt)
1535 1531 # Try to be reasonably smart about not re-indenting pasted input more
1536 1532 # than necessary. We do this by trimming out the auto-indent initial
1537 1533 # spaces, if the user's actual input started itself with whitespace.
1538 1534 if self.autoindent:
1539 1535 line2 = line[self.indent_current_nsp:]
1540 1536 if line2[0:1] in (' ','\t'):
1541 1537 line = line2
1542 1538 return self.prefilter(line,continue_prompt)
1543 1539
1544 1540 def split_user_input(self,line):
1545 1541 """Split user input into pre-char, function part and rest."""
1546 1542
1547 1543 lsplit = self.line_split.match(line)
1548 1544 if lsplit is None: # no regexp match returns None
1549 1545 try:
1550 1546 iFun,theRest = line.split(None,1)
1551 1547 except ValueError:
1552 1548 iFun,theRest = line,''
1553 1549 pre = re.match('^(\s*)(.*)',line).groups()[0]
1554 1550 else:
1555 1551 pre,iFun,theRest = lsplit.groups()
1556 1552
1557 1553 #print 'line:<%s>' % line # dbg
1558 1554 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
1559 1555 return pre,iFun.strip(),theRest
1560 1556
1561 1557 def _prefilter(self, line, continue_prompt):
1562 1558 """Calls different preprocessors, depending on the form of line."""
1563 1559
1564 1560 # All handlers *must* return a value, even if it's blank ('').
1565 1561
1566 1562 # Lines are NOT logged here. Handlers should process the line as
1567 1563 # needed, update the cache AND log it (so that the input cache array
1568 1564 # stays synced).
1569 1565
1570 1566 # This function is _very_ delicate, and since it's also the one which
1571 1567 # determines IPython's response to user input, it must be as efficient
1572 1568 # as possible. For this reason it has _many_ returns in it, trying
1573 1569 # always to exit as quickly as it can figure out what it needs to do.
1574 1570
1575 1571 # This function is the main responsible for maintaining IPython's
1576 1572 # behavior respectful of Python's semantics. So be _very_ careful if
1577 1573 # making changes to anything here.
1578 1574
1579 1575 #.....................................................................
1580 1576 # Code begins
1581 1577
1582 1578 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
1583 1579
1584 1580 # save the line away in case we crash, so the post-mortem handler can
1585 1581 # record it
1586 1582 self._last_input_line = line
1587 1583
1588 1584 #print '***line: <%s>' % line # dbg
1589 1585
1590 1586 # the input history needs to track even empty lines
1591 1587 if not line.strip():
1592 1588 if not continue_prompt:
1593 1589 self.outputcache.prompt_count -= 1
1594 1590 return self.handle_normal(line,continue_prompt)
1595 1591 #return self.handle_normal('',continue_prompt)
1596 1592
1597 1593 # print '***cont',continue_prompt # dbg
1598 1594 # special handlers are only allowed for single line statements
1599 1595 if continue_prompt and not self.rc.multi_line_specials:
1600 1596 return self.handle_normal(line,continue_prompt)
1601 1597
1602 1598 # For the rest, we need the structure of the input
1603 1599 pre,iFun,theRest = self.split_user_input(line)
1604 1600 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1605 1601
1606 1602 # First check for explicit escapes in the last/first character
1607 1603 handler = None
1608 1604 if line[-1] == self.ESC_HELP:
1609 1605 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
1610 1606 if handler is None:
1611 1607 # look at the first character of iFun, NOT of line, so we skip
1612 1608 # leading whitespace in multiline input
1613 1609 handler = self.esc_handlers.get(iFun[0:1])
1614 1610 if handler is not None:
1615 1611 return handler(line,continue_prompt,pre,iFun,theRest)
1616 1612 # Emacs ipython-mode tags certain input lines
1617 1613 if line.endswith('# PYTHON-MODE'):
1618 1614 return self.handle_emacs(line,continue_prompt)
1619 1615
1620 1616 # Next, check if we can automatically execute this thing
1621 1617
1622 1618 # Allow ! in multi-line statements if multi_line_specials is on:
1623 1619 if continue_prompt and self.rc.multi_line_specials and \
1624 1620 iFun.startswith(self.ESC_SHELL):
1625 1621 return self.handle_shell_escape(line,continue_prompt,
1626 1622 pre=pre,iFun=iFun,
1627 1623 theRest=theRest)
1628 1624
1629 1625 # Let's try to find if the input line is a magic fn
1630 1626 oinfo = None
1631 1627 if hasattr(self,'magic_'+iFun):
1632 1628 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1633 1629 if oinfo['ismagic']:
1634 1630 # Be careful not to call magics when a variable assignment is
1635 1631 # being made (ls='hi', for example)
1636 1632 if self.rc.automagic and \
1637 1633 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
1638 1634 (self.rc.multi_line_specials or not continue_prompt):
1639 1635 return self.handle_magic(line,continue_prompt,
1640 1636 pre,iFun,theRest)
1641 1637 else:
1642 1638 return self.handle_normal(line,continue_prompt)
1643 1639
1644 1640 # If the rest of the line begins with an (in)equality, assginment or
1645 1641 # function call, we should not call _ofind but simply execute it.
1646 1642 # This avoids spurious geattr() accesses on objects upon assignment.
1647 1643 #
1648 1644 # It also allows users to assign to either alias or magic names true
1649 1645 # python variables (the magic/alias systems always take second seat to
1650 1646 # true python code).
1651 1647 if theRest and theRest[0] in '!=()':
1652 1648 return self.handle_normal(line,continue_prompt)
1653 1649
1654 1650 if oinfo is None:
1655 1651 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1656 1652
1657 1653 if not oinfo['found']:
1658 if iFun in ('quit','exit'):
1659 raise IPythonExit
1660 1654 return self.handle_normal(line,continue_prompt)
1661 1655 else:
1662 1656 #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg
1663 1657 if oinfo['isalias']:
1664 1658 return self.handle_alias(line,continue_prompt,
1665 1659 pre,iFun,theRest)
1666 1660
1667 1661 if self.rc.autocall and \
1668 1662 not self.re_exclude_auto.match(theRest) and \
1669 1663 self.re_fun_name.match(iFun) and \
1670 1664 callable(oinfo['obj']) :
1671 1665 #print 'going auto' # dbg
1672 1666 return self.handle_auto(line,continue_prompt,pre,iFun,theRest)
1673 1667 else:
1674 1668 #print 'was callable?', callable(oinfo['obj']) # dbg
1675 1669 return self.handle_normal(line,continue_prompt)
1676 1670
1677 1671 # If we get here, we have a normal Python line. Log and return.
1678 1672 return self.handle_normal(line,continue_prompt)
1679 1673
1680 1674 def _prefilter_dumb(self, line, continue_prompt):
1681 1675 """simple prefilter function, for debugging"""
1682 1676 return self.handle_normal(line,continue_prompt)
1683 1677
1684 1678 # Set the default prefilter() function (this can be user-overridden)
1685 1679 prefilter = _prefilter
1686 1680
1687 1681 def handle_normal(self,line,continue_prompt=None,
1688 1682 pre=None,iFun=None,theRest=None):
1689 1683 """Handle normal input lines. Use as a template for handlers."""
1690 1684
1691 1685 # With autoindent on, we need some way to exit the input loop, and I
1692 1686 # don't want to force the user to have to backspace all the way to
1693 1687 # clear the line. The rule will be in this case, that either two
1694 1688 # lines of pure whitespace in a row, or a line of pure whitespace but
1695 1689 # of a size different to the indent level, will exit the input loop.
1696 1690 if (continue_prompt and self.autoindent and isspace(line) and
1697 1691 (line != self.indent_current or isspace(self.buffer[-1]))):
1698 1692 line = ''
1699 1693
1700 1694 self.log(line,continue_prompt)
1701 1695 self.update_cache(line)
1702 1696 return line
1703 1697
1704 1698 def handle_alias(self,line,continue_prompt=None,
1705 1699 pre=None,iFun=None,theRest=None):
1706 1700 """Handle alias input lines. """
1707 1701
1708 1702 theRest = esc_quotes(theRest)
1709 1703 line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1710 1704 self.log(line_out,continue_prompt)
1711 1705 self.update_cache(line_out)
1712 1706 return line_out
1713 1707
1714 1708 def handle_shell_escape(self, line, continue_prompt=None,
1715 1709 pre=None,iFun=None,theRest=None):
1716 1710 """Execute the line in a shell, empty return value"""
1717 1711
1718 1712 #print 'line in :', `line` # dbg
1719 1713 # Example of a special handler. Others follow a similar pattern.
1720 1714 if continue_prompt: # multi-line statements
1721 1715 if iFun.startswith('!!'):
1722 1716 print 'SyntaxError: !! is not allowed in multiline statements'
1723 1717 return pre
1724 1718 else:
1725 1719 cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"')
1726 1720 line_out = '%s%s.system("%s")' % (pre,self.name,cmd)
1727 1721 #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')'
1728 1722 else: # single-line input
1729 1723 if line.startswith('!!'):
1730 1724 # rewrite iFun/theRest to properly hold the call to %sx and
1731 1725 # the actual command to be executed, so handle_magic can work
1732 1726 # correctly
1733 1727 theRest = '%s %s' % (iFun[2:],theRest)
1734 1728 iFun = 'sx'
1735 1729 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]),
1736 1730 continue_prompt,pre,iFun,theRest)
1737 1731 else:
1738 1732 cmd = esc_quotes(line[1:])
1739 1733 line_out = '%s.system("%s")' % (self.name,cmd)
1740 1734 #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')'
1741 1735 # update cache/log and return
1742 1736 self.log(line_out,continue_prompt)
1743 1737 self.update_cache(line_out) # readline cache gets normal line
1744 1738 #print 'line out r:', `line_out` # dbg
1745 1739 #print 'line out s:', line_out # dbg
1746 1740 return line_out
1747 1741
1748 1742 def handle_magic(self, line, continue_prompt=None,
1749 1743 pre=None,iFun=None,theRest=None):
1750 1744 """Execute magic functions.
1751 1745
1752 1746 Also log them with a prepended # so the log is clean Python."""
1753 1747
1754 1748 cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest)))
1755 1749 self.log(cmd,continue_prompt)
1756 1750 self.update_cache(line)
1757 1751 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
1758 1752 return cmd
1759 1753
1760 1754 def handle_auto(self, line, continue_prompt=None,
1761 1755 pre=None,iFun=None,theRest=None):
1762 1756 """Hande lines which can be auto-executed, quoting if requested."""
1763 1757
1764 1758 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1765 1759
1766 1760 # This should only be active for single-line input!
1767 1761 if continue_prompt:
1768 1762 return line
1769 1763
1770 1764 if pre == self.ESC_QUOTE:
1771 1765 # Auto-quote splitting on whitespace
1772 1766 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
1773 1767 elif pre == self.ESC_QUOTE2:
1774 1768 # Auto-quote whole string
1775 1769 newcmd = '%s("%s")' % (iFun,theRest)
1776 1770 else:
1777 1771 # Auto-paren
1778 1772 if theRest[0:1] in ('=','['):
1779 1773 # Don't autocall in these cases. They can be either
1780 1774 # rebindings of an existing callable's name, or item access
1781 1775 # for an object which is BOTH callable and implements
1782 1776 # __getitem__.
1783 1777 return '%s %s' % (iFun,theRest)
1784 1778 if theRest.endswith(';'):
1785 1779 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
1786 1780 else:
1787 1781 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1788 1782
1789 1783 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
1790 1784 # log what is now valid Python, not the actual user input (without the
1791 1785 # final newline)
1792 1786 self.log(newcmd,continue_prompt)
1793 1787 return newcmd
1794 1788
1795 1789 def handle_help(self, line, continue_prompt=None,
1796 1790 pre=None,iFun=None,theRest=None):
1797 1791 """Try to get some help for the object.
1798 1792
1799 1793 obj? or ?obj -> basic information.
1800 1794 obj?? or ??obj -> more details.
1801 1795 """
1802 1796
1803 1797 # We need to make sure that we don't process lines which would be
1804 1798 # otherwise valid python, such as "x=1 # what?"
1805 1799 try:
1806 1800 codeop.compile_command(line)
1807 1801 except SyntaxError:
1808 1802 # We should only handle as help stuff which is NOT valid syntax
1809 1803 if line[0]==self.ESC_HELP:
1810 1804 line = line[1:]
1811 1805 elif line[-1]==self.ESC_HELP:
1812 1806 line = line[:-1]
1813 1807 self.log('#?'+line)
1814 1808 self.update_cache(line)
1815 1809 if line:
1816 1810 self.magic_pinfo(line)
1817 1811 else:
1818 1812 page(self.usage,screen_lines=self.rc.screen_length)
1819 1813 return '' # Empty string is needed here!
1820 1814 except:
1821 1815 # Pass any other exceptions through to the normal handler
1822 1816 return self.handle_normal(line,continue_prompt)
1823 1817 else:
1824 1818 # If the code compiles ok, we should handle it normally
1825 1819 return self.handle_normal(line,continue_prompt)
1826 1820
1827 1821 def handle_emacs(self,line,continue_prompt=None,
1828 1822 pre=None,iFun=None,theRest=None):
1829 1823 """Handle input lines marked by python-mode."""
1830 1824
1831 1825 # Currently, nothing is done. Later more functionality can be added
1832 1826 # here if needed.
1833 1827
1834 1828 # The input cache shouldn't be updated
1835 1829
1836 1830 return line
1837 1831
1838 1832 def write(self,data):
1839 1833 """Write a string to the default output"""
1840 1834 Term.cout.write(data)
1841 1835
1842 1836 def write_err(self,data):
1843 1837 """Write a string to the default error output"""
1844 1838 Term.cerr.write(data)
1845 1839
1846 1840 def exit(self):
1847 1841 """Handle interactive exit.
1848 1842
1849 1843 This method sets the exit_now attribute."""
1850 1844
1851 1845 if self.rc.confirm_exit:
1852 1846 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
1853 1847 self.exit_now = True
1854 1848 else:
1855 1849 self.exit_now = True
1856 1850 return self.exit_now
1857 1851
1858 1852 def safe_execfile(self,fname,*where,**kw):
1859 1853 fname = os.path.expanduser(fname)
1860 1854
1861 1855 # find things also in current directory
1862 1856 dname = os.path.dirname(fname)
1863 1857 if not sys.path.count(dname):
1864 1858 sys.path.append(dname)
1865 1859
1866 1860 try:
1867 1861 xfile = open(fname)
1868 1862 except:
1869 1863 print >> Term.cerr, \
1870 1864 'Could not open file <%s> for safe execution.' % fname
1871 1865 return None
1872 1866
1873 1867 kw.setdefault('islog',0)
1874 1868 kw.setdefault('quiet',1)
1875 1869 kw.setdefault('exit_ignore',0)
1876 1870 first = xfile.readline()
1877 1871 _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip()
1878 1872 xfile.close()
1879 1873 # line by line execution
1880 1874 if first.startswith(_LOGHEAD) or kw['islog']:
1881 1875 print 'Loading log file <%s> one line at a time...' % fname
1882 1876 if kw['quiet']:
1883 1877 stdout_save = sys.stdout
1884 1878 sys.stdout = StringIO.StringIO()
1885 1879 try:
1886 1880 globs,locs = where[0:2]
1887 1881 except:
1888 1882 try:
1889 1883 globs = locs = where[0]
1890 1884 except:
1891 1885 globs = locs = globals()
1892 1886 badblocks = []
1893 1887
1894 1888 # we also need to identify indented blocks of code when replaying
1895 1889 # logs and put them together before passing them to an exec
1896 1890 # statement. This takes a bit of regexp and look-ahead work in the
1897 1891 # file. It's easiest if we swallow the whole thing in memory
1898 1892 # first, and manually walk through the lines list moving the
1899 1893 # counter ourselves.
1900 1894 indent_re = re.compile('\s+\S')
1901 1895 xfile = open(fname)
1902 1896 filelines = xfile.readlines()
1903 1897 xfile.close()
1904 1898 nlines = len(filelines)
1905 1899 lnum = 0
1906 1900 while lnum < nlines:
1907 1901 line = filelines[lnum]
1908 1902 lnum += 1
1909 1903 # don't re-insert logger status info into cache
1910 1904 if line.startswith('#log#'):
1911 1905 continue
1912 1906 elif line.startswith('#%s'% self.ESC_MAGIC):
1913 1907 self.update_cache(line[1:])
1914 1908 line = magic2python(line)
1915 1909 elif line.startswith('#!'):
1916 1910 self.update_cache(line[1:])
1917 1911 else:
1918 1912 # build a block of code (maybe a single line) for execution
1919 1913 block = line
1920 1914 try:
1921 1915 next = filelines[lnum] # lnum has already incremented
1922 1916 except:
1923 1917 next = None
1924 1918 while next and indent_re.match(next):
1925 1919 block += next
1926 1920 lnum += 1
1927 1921 try:
1928 1922 next = filelines[lnum]
1929 1923 except:
1930 1924 next = None
1931 1925 # now execute the block of one or more lines
1932 1926 try:
1933 1927 exec block in globs,locs
1934 1928 self.update_cache(block.rstrip())
1935 1929 except SystemExit:
1936 1930 pass
1937 1931 except:
1938 1932 badblocks.append(block.rstrip())
1939 1933 if kw['quiet']: # restore stdout
1940 1934 sys.stdout.close()
1941 1935 sys.stdout = stdout_save
1942 1936 print 'Finished replaying log file <%s>' % fname
1943 1937 if badblocks:
1944 1938 print >> sys.stderr, ('\nThe following lines/blocks in file '
1945 1939 '<%s> reported errors:' % fname)
1946 1940
1947 1941 for badline in badblocks:
1948 1942 print >> sys.stderr, badline
1949 1943 else: # regular file execution
1950 1944 try:
1951 1945 execfile(fname,*where)
1952 1946 except SyntaxError:
1953 1947 etype, evalue = sys.exc_info()[0:2]
1954 1948 self.SyntaxTB(etype,evalue,[])
1955 1949 warn('Failure executing file: <%s>' % fname)
1956 1950 except SystemExit,status:
1957 1951 if not kw['exit_ignore']:
1958 1952 self.InteractiveTB()
1959 1953 warn('Failure executing file: <%s>' % fname)
1960 1954 except:
1961 1955 self.InteractiveTB()
1962 1956 warn('Failure executing file: <%s>' % fname)
1963 1957
1964 1958 #************************* end of file <iplib.py> *****************************
@@ -1,4568 +1,4575 b''
1 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
4 of the previous special-casing of input in the eval loop. I think
5 this is cleaner, as they really are commands and shouldn't have
6 a special role in the middle of the core code.
7
1 8 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
2 9
3 10 * IPython/iplib.py (edit_syntax_error): added support for
4 11 automatically reopening the editor if the file had a syntax error
5 12 in it. Thanks to scottt who provided the patch at:
6 13 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
7 14 version committed).
8 15
9 16 * IPython/iplib.py (handle_normal): add suport for multi-line
10 17 input with emtpy lines. This fixes
11 18 http://www.scipy.net/roundup/ipython/issue43 and a similar
12 19 discussion on the user list.
13 20
14 21 WARNING: a behavior change is necessarily introduced to support
15 22 blank lines: now a single blank line with whitespace does NOT
16 23 break the input loop, which means that when autoindent is on, by
17 24 default hitting return on the next (indented) line does NOT exit.
18 25
19 26 Instead, to exit a multiline input you can either have:
20 27
21 28 - TWO whitespace lines (just hit return again), or
22 29 - a single whitespace line of a different length than provided
23 30 by the autoindent (add or remove a space).
24 31
25 32 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
26 33 module to better organize all readline-related functionality.
27 34 I've deleted FlexCompleter and put all completion clases here.
28 35
29 36 * IPython/iplib.py (raw_input): improve indentation management.
30 37 It is now possible to paste indented code with autoindent on, and
31 38 the code is interpreted correctly (though it still looks bad on
32 39 screen, due to the line-oriented nature of ipython).
33 40 (MagicCompleter.complete): change behavior so that a TAB key on an
34 41 otherwise empty line actually inserts a tab, instead of completing
35 42 on the entire global namespace. This makes it easier to use the
36 43 TAB key for indentation. After a request by Hans Meine
37 44 <hans_meine-AT-gmx.net>
38 45 (_prefilter): add support so that typing plain 'exit' or 'quit'
39 46 does a sensible thing. Originally I tried to deviate as little as
40 47 possible from the default python behavior, but even that one may
41 48 change in this direction (thread on python-dev to that effect).
42 49 Regardless, ipython should do the right thing even if CPython's
43 50 '>>>' prompt doesn't.
44 51 (InteractiveShell): removed subclassing code.InteractiveConsole
45 52 class. By now we'd overridden just about all of its methods: I've
46 53 copied the remaining two over, and now ipython is a standalone
47 54 class. This will provide a clearer picture for the chainsaw
48 55 branch refactoring.
49 56
50 57 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
51 58
52 59 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
53 60 failures for objects which break when dir() is called on them.
54 61
55 62 * IPython/FlexCompleter.py (Completer.__init__): Added support for
56 63 distinct local and global namespaces in the completer API. This
57 64 change allows us top properly handle completion with distinct
58 65 scopes, including in embedded instances (this had never really
59 66 worked correctly).
60 67
61 68 Note: this introduces a change in the constructor for
62 69 MagicCompleter, as a new global_namespace parameter is now the
63 70 second argument (the others were bumped one position).
64 71
65 72 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
66 73
67 74 * IPython/iplib.py (embed_mainloop): fix tab-completion in
68 75 embedded instances (which can be done now thanks to Vivian's
69 76 frame-handling fixes for pdb).
70 77 (InteractiveShell.__init__): Fix namespace handling problem in
71 78 embedded instances. We were overwriting __main__ unconditionally,
72 79 and this should only be done for 'full' (non-embedded) IPython;
73 80 embedded instances must respect the caller's __main__. Thanks to
74 81 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
75 82
76 83 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
77 84
78 85 * setup.py: added download_url to setup(). This registers the
79 86 download address at PyPI, which is not only useful to humans
80 87 browsing the site, but is also picked up by setuptools (the Eggs
81 88 machinery). Thanks to Ville and R. Kern for the info/discussion
82 89 on this.
83 90
84 91 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
85 92
86 93 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
87 94 This brings a lot of nice functionality to the pdb mode, which now
88 95 has tab-completion, syntax highlighting, and better stack handling
89 96 than before. Many thanks to Vivian De Smedt
90 97 <vivian-AT-vdesmedt.com> for the original patches.
91 98
92 99 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
93 100
94 101 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
95 102 sequence to consistently accept the banner argument. The
96 103 inconsistency was tripping SAGE, thanks to Gary Zablackis
97 104 <gzabl-AT-yahoo.com> for the report.
98 105
99 106 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
100 107
101 108 * IPython/iplib.py (InteractiveShell.post_config_initialization):
102 109 Fix bug where a naked 'alias' call in the ipythonrc file would
103 110 cause a crash. Bug reported by Jorgen Stenarson.
104 111
105 112 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
106 113
107 114 * IPython/ipmaker.py (make_IPython): cleanups which should improve
108 115 startup time.
109 116
110 117 * IPython/iplib.py (runcode): my globals 'fix' for embedded
111 118 instances had introduced a bug with globals in normal code. Now
112 119 it's working in all cases.
113 120
114 121 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
115 122 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
116 123 has been introduced to set the default case sensitivity of the
117 124 searches. Users can still select either mode at runtime on a
118 125 per-search basis.
119 126
120 127 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
121 128
122 129 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
123 130 attributes in wildcard searches for subclasses. Modified version
124 131 of a patch by Jorgen.
125 132
126 133 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
127 134
128 135 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
129 136 embedded instances. I added a user_global_ns attribute to the
130 137 InteractiveShell class to handle this.
131 138
132 139 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
133 140
134 141 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
135 142 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
136 143 (reported under win32, but may happen also in other platforms).
137 144 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
138 145
139 146 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
140 147
141 148 * IPython/Magic.py (magic_psearch): new support for wildcard
142 149 patterns. Now, typing ?a*b will list all names which begin with a
143 150 and end in b, for example. The %psearch magic has full
144 151 docstrings. Many thanks to Jörgen Stenarson
145 152 <jorgen.stenarson-AT-bostream.nu>, author of the patches
146 153 implementing this functionality.
147 154
148 155 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
149 156
150 157 * Manual: fixed long-standing annoyance of double-dashes (as in
151 158 --prefix=~, for example) being stripped in the HTML version. This
152 159 is a latex2html bug, but a workaround was provided. Many thanks
153 160 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
154 161 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
155 162 rolling. This seemingly small issue had tripped a number of users
156 163 when first installing, so I'm glad to see it gone.
157 164
158 165 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
159 166
160 167 * IPython/Extensions/numeric_formats.py: fix missing import,
161 168 reported by Stephen Walton.
162 169
163 170 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
164 171
165 172 * IPython/demo.py: finish demo module, fully documented now.
166 173
167 174 * IPython/genutils.py (file_read): simple little utility to read a
168 175 file and ensure it's closed afterwards.
169 176
170 177 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
171 178
172 179 * IPython/demo.py (Demo.__init__): added support for individually
173 180 tagging blocks for automatic execution.
174 181
175 182 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
176 183 syntax-highlighted python sources, requested by John.
177 184
178 185 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
179 186
180 187 * IPython/demo.py (Demo.again): fix bug where again() blocks after
181 188 finishing.
182 189
183 190 * IPython/genutils.py (shlex_split): moved from Magic to here,
184 191 where all 2.2 compatibility stuff lives. I needed it for demo.py.
185 192
186 193 * IPython/demo.py (Demo.__init__): added support for silent
187 194 blocks, improved marks as regexps, docstrings written.
188 195 (Demo.__init__): better docstring, added support for sys.argv.
189 196
190 197 * IPython/genutils.py (marquee): little utility used by the demo
191 198 code, handy in general.
192 199
193 200 * IPython/demo.py (Demo.__init__): new class for interactive
194 201 demos. Not documented yet, I just wrote it in a hurry for
195 202 scipy'05. Will docstring later.
196 203
197 204 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
198 205
199 206 * IPython/Shell.py (sigint_handler): Drastic simplification which
200 207 also seems to make Ctrl-C work correctly across threads! This is
201 208 so simple, that I can't beleive I'd missed it before. Needs more
202 209 testing, though.
203 210 (KBINT): Never mind, revert changes. I'm sure I'd tried something
204 211 like this before...
205 212
206 213 * IPython/genutils.py (get_home_dir): add protection against
207 214 non-dirs in win32 registry.
208 215
209 216 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
210 217 bug where dict was mutated while iterating (pysh crash).
211 218
212 219 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
213 220
214 221 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
215 222 spurious newlines added by this routine. After a report by
216 223 F. Mantegazza.
217 224
218 225 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
219 226
220 227 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
221 228 calls. These were a leftover from the GTK 1.x days, and can cause
222 229 problems in certain cases (after a report by John Hunter).
223 230
224 231 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
225 232 os.getcwd() fails at init time. Thanks to patch from David Remahl
226 233 <chmod007-AT-mac.com>.
227 234 (InteractiveShell.__init__): prevent certain special magics from
228 235 being shadowed by aliases. Closes
229 236 http://www.scipy.net/roundup/ipython/issue41.
230 237
231 238 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
232 239
233 240 * IPython/iplib.py (InteractiveShell.complete): Added new
234 241 top-level completion method to expose the completion mechanism
235 242 beyond readline-based environments.
236 243
237 244 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
238 245
239 246 * tools/ipsvnc (svnversion): fix svnversion capture.
240 247
241 248 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
242 249 attribute to self, which was missing. Before, it was set by a
243 250 routine which in certain cases wasn't being called, so the
244 251 instance could end up missing the attribute. This caused a crash.
245 252 Closes http://www.scipy.net/roundup/ipython/issue40.
246 253
247 254 2005-08-16 Fernando Perez <fperez@colorado.edu>
248 255
249 256 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
250 257 contains non-string attribute. Closes
251 258 http://www.scipy.net/roundup/ipython/issue38.
252 259
253 260 2005-08-14 Fernando Perez <fperez@colorado.edu>
254 261
255 262 * tools/ipsvnc: Minor improvements, to add changeset info.
256 263
257 264 2005-08-12 Fernando Perez <fperez@colorado.edu>
258 265
259 266 * IPython/iplib.py (runsource): remove self.code_to_run_src
260 267 attribute. I realized this is nothing more than
261 268 '\n'.join(self.buffer), and having the same data in two different
262 269 places is just asking for synchronization bugs. This may impact
263 270 people who have custom exception handlers, so I need to warn
264 271 ipython-dev about it (F. Mantegazza may use them).
265 272
266 273 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
267 274
268 275 * IPython/genutils.py: fix 2.2 compatibility (generators)
269 276
270 277 2005-07-18 Fernando Perez <fperez@colorado.edu>
271 278
272 279 * IPython/genutils.py (get_home_dir): fix to help users with
273 280 invalid $HOME under win32.
274 281
275 282 2005-07-17 Fernando Perez <fperez@colorado.edu>
276 283
277 284 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
278 285 some old hacks and clean up a bit other routines; code should be
279 286 simpler and a bit faster.
280 287
281 288 * IPython/iplib.py (interact): removed some last-resort attempts
282 289 to survive broken stdout/stderr. That code was only making it
283 290 harder to abstract out the i/o (necessary for gui integration),
284 291 and the crashes it could prevent were extremely rare in practice
285 292 (besides being fully user-induced in a pretty violent manner).
286 293
287 294 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
288 295 Nothing major yet, but the code is simpler to read; this should
289 296 make it easier to do more serious modifications in the future.
290 297
291 298 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
292 299 which broke in .15 (thanks to a report by Ville).
293 300
294 301 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
295 302 be quite correct, I know next to nothing about unicode). This
296 303 will allow unicode strings to be used in prompts, amongst other
297 304 cases. It also will prevent ipython from crashing when unicode
298 305 shows up unexpectedly in many places. If ascii encoding fails, we
299 306 assume utf_8. Currently the encoding is not a user-visible
300 307 setting, though it could be made so if there is demand for it.
301 308
302 309 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
303 310
304 311 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
305 312
306 313 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
307 314
308 315 * IPython/genutils.py: Add 2.2 compatibility here, so all other
309 316 code can work transparently for 2.2/2.3.
310 317
311 318 2005-07-16 Fernando Perez <fperez@colorado.edu>
312 319
313 320 * IPython/ultraTB.py (ExceptionColors): Make a global variable
314 321 out of the color scheme table used for coloring exception
315 322 tracebacks. This allows user code to add new schemes at runtime.
316 323 This is a minimally modified version of the patch at
317 324 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
318 325 for the contribution.
319 326
320 327 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
321 328 slightly modified version of the patch in
322 329 http://www.scipy.net/roundup/ipython/issue34, which also allows me
323 330 to remove the previous try/except solution (which was costlier).
324 331 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
325 332
326 333 2005-06-08 Fernando Perez <fperez@colorado.edu>
327 334
328 335 * IPython/iplib.py (write/write_err): Add methods to abstract all
329 336 I/O a bit more.
330 337
331 338 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
332 339 warning, reported by Aric Hagberg, fix by JD Hunter.
333 340
334 341 2005-06-02 *** Released version 0.6.15
335 342
336 343 2005-06-01 Fernando Perez <fperez@colorado.edu>
337 344
338 345 * IPython/iplib.py (MagicCompleter.file_matches): Fix
339 346 tab-completion of filenames within open-quoted strings. Note that
340 347 this requires that in ~/.ipython/ipythonrc, users change the
341 348 readline delimiters configuration to read:
342 349
343 350 readline_remove_delims -/~
344 351
345 352
346 353 2005-05-31 *** Released version 0.6.14
347 354
348 355 2005-05-29 Fernando Perez <fperez@colorado.edu>
349 356
350 357 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
351 358 with files not on the filesystem. Reported by Eliyahu Sandler
352 359 <eli@gondolin.net>
353 360
354 361 2005-05-22 Fernando Perez <fperez@colorado.edu>
355 362
356 363 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
357 364 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
358 365
359 366 2005-05-19 Fernando Perez <fperez@colorado.edu>
360 367
361 368 * IPython/iplib.py (safe_execfile): close a file which could be
362 369 left open (causing problems in win32, which locks open files).
363 370 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
364 371
365 372 2005-05-18 Fernando Perez <fperez@colorado.edu>
366 373
367 374 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
368 375 keyword arguments correctly to safe_execfile().
369 376
370 377 2005-05-13 Fernando Perez <fperez@colorado.edu>
371 378
372 379 * ipython.1: Added info about Qt to manpage, and threads warning
373 380 to usage page (invoked with --help).
374 381
375 382 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
376 383 new matcher (it goes at the end of the priority list) to do
377 384 tab-completion on named function arguments. Submitted by George
378 385 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
379 386 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
380 387 for more details.
381 388
382 389 * IPython/Magic.py (magic_run): Added new -e flag to ignore
383 390 SystemExit exceptions in the script being run. Thanks to a report
384 391 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
385 392 producing very annoying behavior when running unit tests.
386 393
387 394 2005-05-12 Fernando Perez <fperez@colorado.edu>
388 395
389 396 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
390 397 which I'd broken (again) due to a changed regexp. In the process,
391 398 added ';' as an escape to auto-quote the whole line without
392 399 splitting its arguments. Thanks to a report by Jerry McRae
393 400 <qrs0xyc02-AT-sneakemail.com>.
394 401
395 402 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
396 403 possible crashes caused by a TokenError. Reported by Ed Schofield
397 404 <schofield-AT-ftw.at>.
398 405
399 406 2005-05-06 Fernando Perez <fperez@colorado.edu>
400 407
401 408 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
402 409
403 410 2005-04-29 Fernando Perez <fperez@colorado.edu>
404 411
405 412 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
406 413 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
407 414 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
408 415 which provides support for Qt interactive usage (similar to the
409 416 existing one for WX and GTK). This had been often requested.
410 417
411 418 2005-04-14 *** Released version 0.6.13
412 419
413 420 2005-04-08 Fernando Perez <fperez@colorado.edu>
414 421
415 422 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
416 423 from _ofind, which gets called on almost every input line. Now,
417 424 we only try to get docstrings if they are actually going to be
418 425 used (the overhead of fetching unnecessary docstrings can be
419 426 noticeable for certain objects, such as Pyro proxies).
420 427
421 428 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
422 429 for completers. For some reason I had been passing them the state
423 430 variable, which completers never actually need, and was in
424 431 conflict with the rlcompleter API. Custom completers ONLY need to
425 432 take the text parameter.
426 433
427 434 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
428 435 work correctly in pysh. I've also moved all the logic which used
429 436 to be in pysh.py here, which will prevent problems with future
430 437 upgrades. However, this time I must warn users to update their
431 438 pysh profile to include the line
432 439
433 440 import_all IPython.Extensions.InterpreterExec
434 441
435 442 because otherwise things won't work for them. They MUST also
436 443 delete pysh.py and the line
437 444
438 445 execfile pysh.py
439 446
440 447 from their ipythonrc-pysh.
441 448
442 449 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
443 450 robust in the face of objects whose dir() returns non-strings
444 451 (which it shouldn't, but some broken libs like ITK do). Thanks to
445 452 a patch by John Hunter (implemented differently, though). Also
446 453 minor improvements by using .extend instead of + on lists.
447 454
448 455 * pysh.py:
449 456
450 457 2005-04-06 Fernando Perez <fperez@colorado.edu>
451 458
452 459 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
453 460 by default, so that all users benefit from it. Those who don't
454 461 want it can still turn it off.
455 462
456 463 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
457 464 config file, I'd forgotten about this, so users were getting it
458 465 off by default.
459 466
460 467 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
461 468 consistency. Now magics can be called in multiline statements,
462 469 and python variables can be expanded in magic calls via $var.
463 470 This makes the magic system behave just like aliases or !system
464 471 calls.
465 472
466 473 2005-03-28 Fernando Perez <fperez@colorado.edu>
467 474
468 475 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
469 476 expensive string additions for building command. Add support for
470 477 trailing ';' when autocall is used.
471 478
472 479 2005-03-26 Fernando Perez <fperez@colorado.edu>
473 480
474 481 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
475 482 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
476 483 ipython.el robust against prompts with any number of spaces
477 484 (including 0) after the ':' character.
478 485
479 486 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
480 487 continuation prompt, which misled users to think the line was
481 488 already indented. Closes debian Bug#300847, reported to me by
482 489 Norbert Tretkowski <tretkowski-AT-inittab.de>.
483 490
484 491 2005-03-23 Fernando Perez <fperez@colorado.edu>
485 492
486 493 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
487 494 properly aligned if they have embedded newlines.
488 495
489 496 * IPython/iplib.py (runlines): Add a public method to expose
490 497 IPython's code execution machinery, so that users can run strings
491 498 as if they had been typed at the prompt interactively.
492 499 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
493 500 methods which can call the system shell, but with python variable
494 501 expansion. The three such methods are: __IPYTHON__.system,
495 502 .getoutput and .getoutputerror. These need to be documented in a
496 503 'public API' section (to be written) of the manual.
497 504
498 505 2005-03-20 Fernando Perez <fperez@colorado.edu>
499 506
500 507 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
501 508 for custom exception handling. This is quite powerful, and it
502 509 allows for user-installable exception handlers which can trap
503 510 custom exceptions at runtime and treat them separately from
504 511 IPython's default mechanisms. At the request of Frédéric
505 512 Mantegazza <mantegazza-AT-ill.fr>.
506 513 (InteractiveShell.set_custom_completer): public API function to
507 514 add new completers at runtime.
508 515
509 516 2005-03-19 Fernando Perez <fperez@colorado.edu>
510 517
511 518 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
512 519 allow objects which provide their docstrings via non-standard
513 520 mechanisms (like Pyro proxies) to still be inspected by ipython's
514 521 ? system.
515 522
516 523 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
517 524 automatic capture system. I tried quite hard to make it work
518 525 reliably, and simply failed. I tried many combinations with the
519 526 subprocess module, but eventually nothing worked in all needed
520 527 cases (not blocking stdin for the child, duplicating stdout
521 528 without blocking, etc). The new %sc/%sx still do capture to these
522 529 magical list/string objects which make shell use much more
523 530 conveninent, so not all is lost.
524 531
525 532 XXX - FIX MANUAL for the change above!
526 533
527 534 (runsource): I copied code.py's runsource() into ipython to modify
528 535 it a bit. Now the code object and source to be executed are
529 536 stored in ipython. This makes this info accessible to third-party
530 537 tools, like custom exception handlers. After a request by Frédéric
531 538 Mantegazza <mantegazza-AT-ill.fr>.
532 539
533 540 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
534 541 history-search via readline (like C-p/C-n). I'd wanted this for a
535 542 long time, but only recently found out how to do it. For users
536 543 who already have their ipythonrc files made and want this, just
537 544 add:
538 545
539 546 readline_parse_and_bind "\e[A": history-search-backward
540 547 readline_parse_and_bind "\e[B": history-search-forward
541 548
542 549 2005-03-18 Fernando Perez <fperez@colorado.edu>
543 550
544 551 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
545 552 LSString and SList classes which allow transparent conversions
546 553 between list mode and whitespace-separated string.
547 554 (magic_r): Fix recursion problem in %r.
548 555
549 556 * IPython/genutils.py (LSString): New class to be used for
550 557 automatic storage of the results of all alias/system calls in _o
551 558 and _e (stdout/err). These provide a .l/.list attribute which
552 559 does automatic splitting on newlines. This means that for most
553 560 uses, you'll never need to do capturing of output with %sc/%sx
554 561 anymore, since ipython keeps this always done for you. Note that
555 562 only the LAST results are stored, the _o/e variables are
556 563 overwritten on each call. If you need to save their contents
557 564 further, simply bind them to any other name.
558 565
559 566 2005-03-17 Fernando Perez <fperez@colorado.edu>
560 567
561 568 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
562 569 prompt namespace handling.
563 570
564 571 2005-03-16 Fernando Perez <fperez@colorado.edu>
565 572
566 573 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
567 574 classic prompts to be '>>> ' (final space was missing, and it
568 575 trips the emacs python mode).
569 576 (BasePrompt.__str__): Added safe support for dynamic prompt
570 577 strings. Now you can set your prompt string to be '$x', and the
571 578 value of x will be printed from your interactive namespace. The
572 579 interpolation syntax includes the full Itpl support, so
573 580 ${foo()+x+bar()} is a valid prompt string now, and the function
574 581 calls will be made at runtime.
575 582
576 583 2005-03-15 Fernando Perez <fperez@colorado.edu>
577 584
578 585 * IPython/Magic.py (magic_history): renamed %hist to %history, to
579 586 avoid name clashes in pylab. %hist still works, it just forwards
580 587 the call to %history.
581 588
582 589 2005-03-02 *** Released version 0.6.12
583 590
584 591 2005-03-02 Fernando Perez <fperez@colorado.edu>
585 592
586 593 * IPython/iplib.py (handle_magic): log magic calls properly as
587 594 ipmagic() function calls.
588 595
589 596 * IPython/Magic.py (magic_time): Improved %time to support
590 597 statements and provide wall-clock as well as CPU time.
591 598
592 599 2005-02-27 Fernando Perez <fperez@colorado.edu>
593 600
594 601 * IPython/hooks.py: New hooks module, to expose user-modifiable
595 602 IPython functionality in a clean manner. For now only the editor
596 603 hook is actually written, and other thigns which I intend to turn
597 604 into proper hooks aren't yet there. The display and prefilter
598 605 stuff, for example, should be hooks. But at least now the
599 606 framework is in place, and the rest can be moved here with more
600 607 time later. IPython had had a .hooks variable for a long time for
601 608 this purpose, but I'd never actually used it for anything.
602 609
603 610 2005-02-26 Fernando Perez <fperez@colorado.edu>
604 611
605 612 * IPython/ipmaker.py (make_IPython): make the default ipython
606 613 directory be called _ipython under win32, to follow more the
607 614 naming peculiarities of that platform (where buggy software like
608 615 Visual Sourcesafe breaks with .named directories). Reported by
609 616 Ville Vainio.
610 617
611 618 2005-02-23 Fernando Perez <fperez@colorado.edu>
612 619
613 620 * IPython/iplib.py (InteractiveShell.__init__): removed a few
614 621 auto_aliases for win32 which were causing problems. Users can
615 622 define the ones they personally like.
616 623
617 624 2005-02-21 Fernando Perez <fperez@colorado.edu>
618 625
619 626 * IPython/Magic.py (magic_time): new magic to time execution of
620 627 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
621 628
622 629 2005-02-19 Fernando Perez <fperez@colorado.edu>
623 630
624 631 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
625 632 into keys (for prompts, for example).
626 633
627 634 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
628 635 prompts in case users want them. This introduces a small behavior
629 636 change: ipython does not automatically add a space to all prompts
630 637 anymore. To get the old prompts with a space, users should add it
631 638 manually to their ipythonrc file, so for example prompt_in1 should
632 639 now read 'In [\#]: ' instead of 'In [\#]:'.
633 640 (BasePrompt.__init__): New option prompts_pad_left (only in rc
634 641 file) to control left-padding of secondary prompts.
635 642
636 643 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
637 644 the profiler can't be imported. Fix for Debian, which removed
638 645 profile.py because of License issues. I applied a slightly
639 646 modified version of the original Debian patch at
640 647 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
641 648
642 649 2005-02-17 Fernando Perez <fperez@colorado.edu>
643 650
644 651 * IPython/genutils.py (native_line_ends): Fix bug which would
645 652 cause improper line-ends under win32 b/c I was not opening files
646 653 in binary mode. Bug report and fix thanks to Ville.
647 654
648 655 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
649 656 trying to catch spurious foo[1] autocalls. My fix actually broke
650 657 ',/' autoquote/call with explicit escape (bad regexp).
651 658
652 659 2005-02-15 *** Released version 0.6.11
653 660
654 661 2005-02-14 Fernando Perez <fperez@colorado.edu>
655 662
656 663 * IPython/background_jobs.py: New background job management
657 664 subsystem. This is implemented via a new set of classes, and
658 665 IPython now provides a builtin 'jobs' object for background job
659 666 execution. A convenience %bg magic serves as a lightweight
660 667 frontend for starting the more common type of calls. This was
661 668 inspired by discussions with B. Granger and the BackgroundCommand
662 669 class described in the book Python Scripting for Computational
663 670 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
664 671 (although ultimately no code from this text was used, as IPython's
665 672 system is a separate implementation).
666 673
667 674 * IPython/iplib.py (MagicCompleter.python_matches): add new option
668 675 to control the completion of single/double underscore names
669 676 separately. As documented in the example ipytonrc file, the
670 677 readline_omit__names variable can now be set to 2, to omit even
671 678 single underscore names. Thanks to a patch by Brian Wong
672 679 <BrianWong-AT-AirgoNetworks.Com>.
673 680 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
674 681 be autocalled as foo([1]) if foo were callable. A problem for
675 682 things which are both callable and implement __getitem__.
676 683 (init_readline): Fix autoindentation for win32. Thanks to a patch
677 684 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
678 685
679 686 2005-02-12 Fernando Perez <fperez@colorado.edu>
680 687
681 688 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
682 689 which I had written long ago to sort out user error messages which
683 690 may occur during startup. This seemed like a good idea initially,
684 691 but it has proven a disaster in retrospect. I don't want to
685 692 change much code for now, so my fix is to set the internal 'debug'
686 693 flag to true everywhere, whose only job was precisely to control
687 694 this subsystem. This closes issue 28 (as well as avoiding all
688 695 sorts of strange hangups which occur from time to time).
689 696
690 697 2005-02-07 Fernando Perez <fperez@colorado.edu>
691 698
692 699 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
693 700 previous call produced a syntax error.
694 701
695 702 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
696 703 classes without constructor.
697 704
698 705 2005-02-06 Fernando Perez <fperez@colorado.edu>
699 706
700 707 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
701 708 completions with the results of each matcher, so we return results
702 709 to the user from all namespaces. This breaks with ipython
703 710 tradition, but I think it's a nicer behavior. Now you get all
704 711 possible completions listed, from all possible namespaces (python,
705 712 filesystem, magics...) After a request by John Hunter
706 713 <jdhunter-AT-nitace.bsd.uchicago.edu>.
707 714
708 715 2005-02-05 Fernando Perez <fperez@colorado.edu>
709 716
710 717 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
711 718 the call had quote characters in it (the quotes were stripped).
712 719
713 720 2005-01-31 Fernando Perez <fperez@colorado.edu>
714 721
715 722 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
716 723 Itpl.itpl() to make the code more robust against psyco
717 724 optimizations.
718 725
719 726 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
720 727 of causing an exception. Quicker, cleaner.
721 728
722 729 2005-01-28 Fernando Perez <fperez@colorado.edu>
723 730
724 731 * scripts/ipython_win_post_install.py (install): hardcode
725 732 sys.prefix+'python.exe' as the executable path. It turns out that
726 733 during the post-installation run, sys.executable resolves to the
727 734 name of the binary installer! I should report this as a distutils
728 735 bug, I think. I updated the .10 release with this tiny fix, to
729 736 avoid annoying the lists further.
730 737
731 738 2005-01-27 *** Released version 0.6.10
732 739
733 740 2005-01-27 Fernando Perez <fperez@colorado.edu>
734 741
735 742 * IPython/numutils.py (norm): Added 'inf' as optional name for
736 743 L-infinity norm, included references to mathworld.com for vector
737 744 norm definitions.
738 745 (amin/amax): added amin/amax for array min/max. Similar to what
739 746 pylab ships with after the recent reorganization of names.
740 747 (spike/spike_odd): removed deprecated spike/spike_odd functions.
741 748
742 749 * ipython.el: committed Alex's recent fixes and improvements.
743 750 Tested with python-mode from CVS, and it looks excellent. Since
744 751 python-mode hasn't released anything in a while, I'm temporarily
745 752 putting a copy of today's CVS (v 4.70) of python-mode in:
746 753 http://ipython.scipy.org/tmp/python-mode.el
747 754
748 755 * scripts/ipython_win_post_install.py (install): Win32 fix to use
749 756 sys.executable for the executable name, instead of assuming it's
750 757 called 'python.exe' (the post-installer would have produced broken
751 758 setups on systems with a differently named python binary).
752 759
753 760 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
754 761 references to os.linesep, to make the code more
755 762 platform-independent. This is also part of the win32 coloring
756 763 fixes.
757 764
758 765 * IPython/genutils.py (page_dumb): Remove attempts to chop long
759 766 lines, which actually cause coloring bugs because the length of
760 767 the line is very difficult to correctly compute with embedded
761 768 escapes. This was the source of all the coloring problems under
762 769 Win32. I think that _finally_, Win32 users have a properly
763 770 working ipython in all respects. This would never have happened
764 771 if not for Gary Bishop and Viktor Ransmayr's great help and work.
765 772
766 773 2005-01-26 *** Released version 0.6.9
767 774
768 775 2005-01-25 Fernando Perez <fperez@colorado.edu>
769 776
770 777 * setup.py: finally, we have a true Windows installer, thanks to
771 778 the excellent work of Viktor Ransmayr
772 779 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
773 780 Windows users. The setup routine is quite a bit cleaner thanks to
774 781 this, and the post-install script uses the proper functions to
775 782 allow a clean de-installation using the standard Windows Control
776 783 Panel.
777 784
778 785 * IPython/genutils.py (get_home_dir): changed to use the $HOME
779 786 environment variable under all OSes (including win32) if
780 787 available. This will give consistency to win32 users who have set
781 788 this variable for any reason. If os.environ['HOME'] fails, the
782 789 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
783 790
784 791 2005-01-24 Fernando Perez <fperez@colorado.edu>
785 792
786 793 * IPython/numutils.py (empty_like): add empty_like(), similar to
787 794 zeros_like() but taking advantage of the new empty() Numeric routine.
788 795
789 796 2005-01-23 *** Released version 0.6.8
790 797
791 798 2005-01-22 Fernando Perez <fperez@colorado.edu>
792 799
793 800 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
794 801 automatic show() calls. After discussing things with JDH, it
795 802 turns out there are too many corner cases where this can go wrong.
796 803 It's best not to try to be 'too smart', and simply have ipython
797 804 reproduce as much as possible the default behavior of a normal
798 805 python shell.
799 806
800 807 * IPython/iplib.py (InteractiveShell.__init__): Modified the
801 808 line-splitting regexp and _prefilter() to avoid calling getattr()
802 809 on assignments. This closes
803 810 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
804 811 readline uses getattr(), so a simple <TAB> keypress is still
805 812 enough to trigger getattr() calls on an object.
806 813
807 814 2005-01-21 Fernando Perez <fperez@colorado.edu>
808 815
809 816 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
810 817 docstring under pylab so it doesn't mask the original.
811 818
812 819 2005-01-21 *** Released version 0.6.7
813 820
814 821 2005-01-21 Fernando Perez <fperez@colorado.edu>
815 822
816 823 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
817 824 signal handling for win32 users in multithreaded mode.
818 825
819 826 2005-01-17 Fernando Perez <fperez@colorado.edu>
820 827
821 828 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
822 829 instances with no __init__. After a crash report by Norbert Nemec
823 830 <Norbert-AT-nemec-online.de>.
824 831
825 832 2005-01-14 Fernando Perez <fperez@colorado.edu>
826 833
827 834 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
828 835 names for verbose exceptions, when multiple dotted names and the
829 836 'parent' object were present on the same line.
830 837
831 838 2005-01-11 Fernando Perez <fperez@colorado.edu>
832 839
833 840 * IPython/genutils.py (flag_calls): new utility to trap and flag
834 841 calls in functions. I need it to clean up matplotlib support.
835 842 Also removed some deprecated code in genutils.
836 843
837 844 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
838 845 that matplotlib scripts called with %run, which don't call show()
839 846 themselves, still have their plotting windows open.
840 847
841 848 2005-01-05 Fernando Perez <fperez@colorado.edu>
842 849
843 850 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
844 851 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
845 852
846 853 2004-12-19 Fernando Perez <fperez@colorado.edu>
847 854
848 855 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
849 856 parent_runcode, which was an eyesore. The same result can be
850 857 obtained with Python's regular superclass mechanisms.
851 858
852 859 2004-12-17 Fernando Perez <fperez@colorado.edu>
853 860
854 861 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
855 862 reported by Prabhu.
856 863 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
857 864 sys.stderr) instead of explicitly calling sys.stderr. This helps
858 865 maintain our I/O abstractions clean, for future GUI embeddings.
859 866
860 867 * IPython/genutils.py (info): added new utility for sys.stderr
861 868 unified info message handling (thin wrapper around warn()).
862 869
863 870 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
864 871 composite (dotted) names on verbose exceptions.
865 872 (VerboseTB.nullrepr): harden against another kind of errors which
866 873 Python's inspect module can trigger, and which were crashing
867 874 IPython. Thanks to a report by Marco Lombardi
868 875 <mlombard-AT-ma010192.hq.eso.org>.
869 876
870 877 2004-12-13 *** Released version 0.6.6
871 878
872 879 2004-12-12 Fernando Perez <fperez@colorado.edu>
873 880
874 881 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
875 882 generated by pygtk upon initialization if it was built without
876 883 threads (for matplotlib users). After a crash reported by
877 884 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
878 885
879 886 * IPython/ipmaker.py (make_IPython): fix small bug in the
880 887 import_some parameter for multiple imports.
881 888
882 889 * IPython/iplib.py (ipmagic): simplified the interface of
883 890 ipmagic() to take a single string argument, just as it would be
884 891 typed at the IPython cmd line.
885 892 (ipalias): Added new ipalias() with an interface identical to
886 893 ipmagic(). This completes exposing a pure python interface to the
887 894 alias and magic system, which can be used in loops or more complex
888 895 code where IPython's automatic line mangling is not active.
889 896
890 897 * IPython/genutils.py (timing): changed interface of timing to
891 898 simply run code once, which is the most common case. timings()
892 899 remains unchanged, for the cases where you want multiple runs.
893 900
894 901 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
895 902 bug where Python2.2 crashes with exec'ing code which does not end
896 903 in a single newline. Python 2.3 is OK, so I hadn't noticed this
897 904 before.
898 905
899 906 2004-12-10 Fernando Perez <fperez@colorado.edu>
900 907
901 908 * IPython/Magic.py (Magic.magic_prun): changed name of option from
902 909 -t to -T, to accomodate the new -t flag in %run (the %run and
903 910 %prun options are kind of intermixed, and it's not easy to change
904 911 this with the limitations of python's getopt).
905 912
906 913 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
907 914 the execution of scripts. It's not as fine-tuned as timeit.py,
908 915 but it works from inside ipython (and under 2.2, which lacks
909 916 timeit.py). Optionally a number of runs > 1 can be given for
910 917 timing very short-running code.
911 918
912 919 * IPython/genutils.py (uniq_stable): new routine which returns a
913 920 list of unique elements in any iterable, but in stable order of
914 921 appearance. I needed this for the ultraTB fixes, and it's a handy
915 922 utility.
916 923
917 924 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
918 925 dotted names in Verbose exceptions. This had been broken since
919 926 the very start, now x.y will properly be printed in a Verbose
920 927 traceback, instead of x being shown and y appearing always as an
921 928 'undefined global'. Getting this to work was a bit tricky,
922 929 because by default python tokenizers are stateless. Saved by
923 930 python's ability to easily add a bit of state to an arbitrary
924 931 function (without needing to build a full-blown callable object).
925 932
926 933 Also big cleanup of this code, which had horrendous runtime
927 934 lookups of zillions of attributes for colorization. Moved all
928 935 this code into a few templates, which make it cleaner and quicker.
929 936
930 937 Printout quality was also improved for Verbose exceptions: one
931 938 variable per line, and memory addresses are printed (this can be
932 939 quite handy in nasty debugging situations, which is what Verbose
933 940 is for).
934 941
935 942 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
936 943 the command line as scripts to be loaded by embedded instances.
937 944 Doing so has the potential for an infinite recursion if there are
938 945 exceptions thrown in the process. This fixes a strange crash
939 946 reported by Philippe MULLER <muller-AT-irit.fr>.
940 947
941 948 2004-12-09 Fernando Perez <fperez@colorado.edu>
942 949
943 950 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
944 951 to reflect new names in matplotlib, which now expose the
945 952 matlab-compatible interface via a pylab module instead of the
946 953 'matlab' name. The new code is backwards compatible, so users of
947 954 all matplotlib versions are OK. Patch by J. Hunter.
948 955
949 956 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
950 957 of __init__ docstrings for instances (class docstrings are already
951 958 automatically printed). Instances with customized docstrings
952 959 (indep. of the class) are also recognized and all 3 separate
953 960 docstrings are printed (instance, class, constructor). After some
954 961 comments/suggestions by J. Hunter.
955 962
956 963 2004-12-05 Fernando Perez <fperez@colorado.edu>
957 964
958 965 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
959 966 warnings when tab-completion fails and triggers an exception.
960 967
961 968 2004-12-03 Fernando Perez <fperez@colorado.edu>
962 969
963 970 * IPython/Magic.py (magic_prun): Fix bug where an exception would
964 971 be triggered when using 'run -p'. An incorrect option flag was
965 972 being set ('d' instead of 'D').
966 973 (manpage): fix missing escaped \- sign.
967 974
968 975 2004-11-30 *** Released version 0.6.5
969 976
970 977 2004-11-30 Fernando Perez <fperez@colorado.edu>
971 978
972 979 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
973 980 setting with -d option.
974 981
975 982 * setup.py (docfiles): Fix problem where the doc glob I was using
976 983 was COMPLETELY BROKEN. It was giving the right files by pure
977 984 accident, but failed once I tried to include ipython.el. Note:
978 985 glob() does NOT allow you to do exclusion on multiple endings!
979 986
980 987 2004-11-29 Fernando Perez <fperez@colorado.edu>
981 988
982 989 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
983 990 the manpage as the source. Better formatting & consistency.
984 991
985 992 * IPython/Magic.py (magic_run): Added new -d option, to run
986 993 scripts under the control of the python pdb debugger. Note that
987 994 this required changing the %prun option -d to -D, to avoid a clash
988 995 (since %run must pass options to %prun, and getopt is too dumb to
989 996 handle options with string values with embedded spaces). Thanks
990 997 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
991 998 (magic_who_ls): added type matching to %who and %whos, so that one
992 999 can filter their output to only include variables of certain
993 1000 types. Another suggestion by Matthew.
994 1001 (magic_whos): Added memory summaries in kb and Mb for arrays.
995 1002 (magic_who): Improve formatting (break lines every 9 vars).
996 1003
997 1004 2004-11-28 Fernando Perez <fperez@colorado.edu>
998 1005
999 1006 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
1000 1007 cache when empty lines were present.
1001 1008
1002 1009 2004-11-24 Fernando Perez <fperez@colorado.edu>
1003 1010
1004 1011 * IPython/usage.py (__doc__): document the re-activated threading
1005 1012 options for WX and GTK.
1006 1013
1007 1014 2004-11-23 Fernando Perez <fperez@colorado.edu>
1008 1015
1009 1016 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
1010 1017 the -wthread and -gthread options, along with a new -tk one to try
1011 1018 and coordinate Tk threading with wx/gtk. The tk support is very
1012 1019 platform dependent, since it seems to require Tcl and Tk to be
1013 1020 built with threads (Fedora1/2 appears NOT to have it, but in
1014 1021 Prabhu's Debian boxes it works OK). But even with some Tk
1015 1022 limitations, this is a great improvement.
1016 1023
1017 1024 * IPython/Prompts.py (prompt_specials_color): Added \t for time
1018 1025 info in user prompts. Patch by Prabhu.
1019 1026
1020 1027 2004-11-18 Fernando Perez <fperez@colorado.edu>
1021 1028
1022 1029 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
1023 1030 EOFErrors and bail, to avoid infinite loops if a non-terminating
1024 1031 file is fed into ipython. Patch submitted in issue 19 by user,
1025 1032 many thanks.
1026 1033
1027 1034 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
1028 1035 autoquote/parens in continuation prompts, which can cause lots of
1029 1036 problems. Closes roundup issue 20.
1030 1037
1031 1038 2004-11-17 Fernando Perez <fperez@colorado.edu>
1032 1039
1033 1040 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
1034 1041 reported as debian bug #280505. I'm not sure my local changelog
1035 1042 entry has the proper debian format (Jack?).
1036 1043
1037 1044 2004-11-08 *** Released version 0.6.4
1038 1045
1039 1046 2004-11-08 Fernando Perez <fperez@colorado.edu>
1040 1047
1041 1048 * IPython/iplib.py (init_readline): Fix exit message for Windows
1042 1049 when readline is active. Thanks to a report by Eric Jones
1043 1050 <eric-AT-enthought.com>.
1044 1051
1045 1052 2004-11-07 Fernando Perez <fperez@colorado.edu>
1046 1053
1047 1054 * IPython/genutils.py (page): Add a trap for OSError exceptions,
1048 1055 sometimes seen by win2k/cygwin users.
1049 1056
1050 1057 2004-11-06 Fernando Perez <fperez@colorado.edu>
1051 1058
1052 1059 * IPython/iplib.py (interact): Change the handling of %Exit from
1053 1060 trying to propagate a SystemExit to an internal ipython flag.
1054 1061 This is less elegant than using Python's exception mechanism, but
1055 1062 I can't get that to work reliably with threads, so under -pylab
1056 1063 %Exit was hanging IPython. Cross-thread exception handling is
1057 1064 really a bitch. Thaks to a bug report by Stephen Walton
1058 1065 <stephen.walton-AT-csun.edu>.
1059 1066
1060 1067 2004-11-04 Fernando Perez <fperez@colorado.edu>
1061 1068
1062 1069 * IPython/iplib.py (raw_input_original): store a pointer to the
1063 1070 true raw_input to harden against code which can modify it
1064 1071 (wx.py.PyShell does this and would otherwise crash ipython).
1065 1072 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
1066 1073
1067 1074 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
1068 1075 Ctrl-C problem, which does not mess up the input line.
1069 1076
1070 1077 2004-11-03 Fernando Perez <fperez@colorado.edu>
1071 1078
1072 1079 * IPython/Release.py: Changed licensing to BSD, in all files.
1073 1080 (name): lowercase name for tarball/RPM release.
1074 1081
1075 1082 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
1076 1083 use throughout ipython.
1077 1084
1078 1085 * IPython/Magic.py (Magic._ofind): Switch to using the new
1079 1086 OInspect.getdoc() function.
1080 1087
1081 1088 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
1082 1089 of the line currently being canceled via Ctrl-C. It's extremely
1083 1090 ugly, but I don't know how to do it better (the problem is one of
1084 1091 handling cross-thread exceptions).
1085 1092
1086 1093 2004-10-28 Fernando Perez <fperez@colorado.edu>
1087 1094
1088 1095 * IPython/Shell.py (signal_handler): add signal handlers to trap
1089 1096 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
1090 1097 report by Francesc Alted.
1091 1098
1092 1099 2004-10-21 Fernando Perez <fperez@colorado.edu>
1093 1100
1094 1101 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
1095 1102 to % for pysh syntax extensions.
1096 1103
1097 1104 2004-10-09 Fernando Perez <fperez@colorado.edu>
1098 1105
1099 1106 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
1100 1107 arrays to print a more useful summary, without calling str(arr).
1101 1108 This avoids the problem of extremely lengthy computations which
1102 1109 occur if arr is large, and appear to the user as a system lockup
1103 1110 with 100% cpu activity. After a suggestion by Kristian Sandberg
1104 1111 <Kristian.Sandberg@colorado.edu>.
1105 1112 (Magic.__init__): fix bug in global magic escapes not being
1106 1113 correctly set.
1107 1114
1108 1115 2004-10-08 Fernando Perez <fperez@colorado.edu>
1109 1116
1110 1117 * IPython/Magic.py (__license__): change to absolute imports of
1111 1118 ipython's own internal packages, to start adapting to the absolute
1112 1119 import requirement of PEP-328.
1113 1120
1114 1121 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
1115 1122 files, and standardize author/license marks through the Release
1116 1123 module instead of having per/file stuff (except for files with
1117 1124 particular licenses, like the MIT/PSF-licensed codes).
1118 1125
1119 1126 * IPython/Debugger.py: remove dead code for python 2.1
1120 1127
1121 1128 2004-10-04 Fernando Perez <fperez@colorado.edu>
1122 1129
1123 1130 * IPython/iplib.py (ipmagic): New function for accessing magics
1124 1131 via a normal python function call.
1125 1132
1126 1133 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
1127 1134 from '@' to '%', to accomodate the new @decorator syntax of python
1128 1135 2.4.
1129 1136
1130 1137 2004-09-29 Fernando Perez <fperez@colorado.edu>
1131 1138
1132 1139 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
1133 1140 matplotlib.use to prevent running scripts which try to switch
1134 1141 interactive backends from within ipython. This will just crash
1135 1142 the python interpreter, so we can't allow it (but a detailed error
1136 1143 is given to the user).
1137 1144
1138 1145 2004-09-28 Fernando Perez <fperez@colorado.edu>
1139 1146
1140 1147 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
1141 1148 matplotlib-related fixes so that using @run with non-matplotlib
1142 1149 scripts doesn't pop up spurious plot windows. This requires
1143 1150 matplotlib >= 0.63, where I had to make some changes as well.
1144 1151
1145 1152 * IPython/ipmaker.py (make_IPython): update version requirement to
1146 1153 python 2.2.
1147 1154
1148 1155 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
1149 1156 banner arg for embedded customization.
1150 1157
1151 1158 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
1152 1159 explicit uses of __IP as the IPython's instance name. Now things
1153 1160 are properly handled via the shell.name value. The actual code
1154 1161 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
1155 1162 is much better than before. I'll clean things completely when the
1156 1163 magic stuff gets a real overhaul.
1157 1164
1158 1165 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
1159 1166 minor changes to debian dir.
1160 1167
1161 1168 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
1162 1169 pointer to the shell itself in the interactive namespace even when
1163 1170 a user-supplied dict is provided. This is needed for embedding
1164 1171 purposes (found by tests with Michel Sanner).
1165 1172
1166 1173 2004-09-27 Fernando Perez <fperez@colorado.edu>
1167 1174
1168 1175 * IPython/UserConfig/ipythonrc: remove []{} from
1169 1176 readline_remove_delims, so that things like [modname.<TAB> do
1170 1177 proper completion. This disables [].TAB, but that's a less common
1171 1178 case than module names in list comprehensions, for example.
1172 1179 Thanks to a report by Andrea Riciputi.
1173 1180
1174 1181 2004-09-09 Fernando Perez <fperez@colorado.edu>
1175 1182
1176 1183 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1177 1184 blocking problems in win32 and osx. Fix by John.
1178 1185
1179 1186 2004-09-08 Fernando Perez <fperez@colorado.edu>
1180 1187
1181 1188 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1182 1189 for Win32 and OSX. Fix by John Hunter.
1183 1190
1184 1191 2004-08-30 *** Released version 0.6.3
1185 1192
1186 1193 2004-08-30 Fernando Perez <fperez@colorado.edu>
1187 1194
1188 1195 * setup.py (isfile): Add manpages to list of dependent files to be
1189 1196 updated.
1190 1197
1191 1198 2004-08-27 Fernando Perez <fperez@colorado.edu>
1192 1199
1193 1200 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1194 1201 for now. They don't really work with standalone WX/GTK code
1195 1202 (though matplotlib IS working fine with both of those backends).
1196 1203 This will neeed much more testing. I disabled most things with
1197 1204 comments, so turning it back on later should be pretty easy.
1198 1205
1199 1206 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1200 1207 autocalling of expressions like r'foo', by modifying the line
1201 1208 split regexp. Closes
1202 1209 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1203 1210 Riley <ipythonbugs-AT-sabi.net>.
1204 1211 (InteractiveShell.mainloop): honor --nobanner with banner
1205 1212 extensions.
1206 1213
1207 1214 * IPython/Shell.py: Significant refactoring of all classes, so
1208 1215 that we can really support ALL matplotlib backends and threading
1209 1216 models (John spotted a bug with Tk which required this). Now we
1210 1217 should support single-threaded, WX-threads and GTK-threads, both
1211 1218 for generic code and for matplotlib.
1212 1219
1213 1220 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1214 1221 -pylab, to simplify things for users. Will also remove the pylab
1215 1222 profile, since now all of matplotlib configuration is directly
1216 1223 handled here. This also reduces startup time.
1217 1224
1218 1225 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1219 1226 shell wasn't being correctly called. Also in IPShellWX.
1220 1227
1221 1228 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1222 1229 fine-tune banner.
1223 1230
1224 1231 * IPython/numutils.py (spike): Deprecate these spike functions,
1225 1232 delete (long deprecated) gnuplot_exec handler.
1226 1233
1227 1234 2004-08-26 Fernando Perez <fperez@colorado.edu>
1228 1235
1229 1236 * ipython.1: Update for threading options, plus some others which
1230 1237 were missing.
1231 1238
1232 1239 * IPython/ipmaker.py (__call__): Added -wthread option for
1233 1240 wxpython thread handling. Make sure threading options are only
1234 1241 valid at the command line.
1235 1242
1236 1243 * scripts/ipython: moved shell selection into a factory function
1237 1244 in Shell.py, to keep the starter script to a minimum.
1238 1245
1239 1246 2004-08-25 Fernando Perez <fperez@colorado.edu>
1240 1247
1241 1248 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1242 1249 John. Along with some recent changes he made to matplotlib, the
1243 1250 next versions of both systems should work very well together.
1244 1251
1245 1252 2004-08-24 Fernando Perez <fperez@colorado.edu>
1246 1253
1247 1254 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1248 1255 tried to switch the profiling to using hotshot, but I'm getting
1249 1256 strange errors from prof.runctx() there. I may be misreading the
1250 1257 docs, but it looks weird. For now the profiling code will
1251 1258 continue to use the standard profiler.
1252 1259
1253 1260 2004-08-23 Fernando Perez <fperez@colorado.edu>
1254 1261
1255 1262 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1256 1263 threaded shell, by John Hunter. It's not quite ready yet, but
1257 1264 close.
1258 1265
1259 1266 2004-08-22 Fernando Perez <fperez@colorado.edu>
1260 1267
1261 1268 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1262 1269 in Magic and ultraTB.
1263 1270
1264 1271 * ipython.1: document threading options in manpage.
1265 1272
1266 1273 * scripts/ipython: Changed name of -thread option to -gthread,
1267 1274 since this is GTK specific. I want to leave the door open for a
1268 1275 -wthread option for WX, which will most likely be necessary. This
1269 1276 change affects usage and ipmaker as well.
1270 1277
1271 1278 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1272 1279 handle the matplotlib shell issues. Code by John Hunter
1273 1280 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1274 1281 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1275 1282 broken (and disabled for end users) for now, but it puts the
1276 1283 infrastructure in place.
1277 1284
1278 1285 2004-08-21 Fernando Perez <fperez@colorado.edu>
1279 1286
1280 1287 * ipythonrc-pylab: Add matplotlib support.
1281 1288
1282 1289 * matplotlib_config.py: new files for matplotlib support, part of
1283 1290 the pylab profile.
1284 1291
1285 1292 * IPython/usage.py (__doc__): documented the threading options.
1286 1293
1287 1294 2004-08-20 Fernando Perez <fperez@colorado.edu>
1288 1295
1289 1296 * ipython: Modified the main calling routine to handle the -thread
1290 1297 and -mpthread options. This needs to be done as a top-level hack,
1291 1298 because it determines which class to instantiate for IPython
1292 1299 itself.
1293 1300
1294 1301 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1295 1302 classes to support multithreaded GTK operation without blocking,
1296 1303 and matplotlib with all backends. This is a lot of still very
1297 1304 experimental code, and threads are tricky. So it may still have a
1298 1305 few rough edges... This code owes a lot to
1299 1306 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1300 1307 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1301 1308 to John Hunter for all the matplotlib work.
1302 1309
1303 1310 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1304 1311 options for gtk thread and matplotlib support.
1305 1312
1306 1313 2004-08-16 Fernando Perez <fperez@colorado.edu>
1307 1314
1308 1315 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1309 1316 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1310 1317 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1311 1318
1312 1319 2004-08-11 Fernando Perez <fperez@colorado.edu>
1313 1320
1314 1321 * setup.py (isfile): Fix build so documentation gets updated for
1315 1322 rpms (it was only done for .tgz builds).
1316 1323
1317 1324 2004-08-10 Fernando Perez <fperez@colorado.edu>
1318 1325
1319 1326 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1320 1327
1321 1328 * iplib.py : Silence syntax error exceptions in tab-completion.
1322 1329
1323 1330 2004-08-05 Fernando Perez <fperez@colorado.edu>
1324 1331
1325 1332 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1326 1333 'color off' mark for continuation prompts. This was causing long
1327 1334 continuation lines to mis-wrap.
1328 1335
1329 1336 2004-08-01 Fernando Perez <fperez@colorado.edu>
1330 1337
1331 1338 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1332 1339 for building ipython to be a parameter. All this is necessary
1333 1340 right now to have a multithreaded version, but this insane
1334 1341 non-design will be cleaned up soon. For now, it's a hack that
1335 1342 works.
1336 1343
1337 1344 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1338 1345 args in various places. No bugs so far, but it's a dangerous
1339 1346 practice.
1340 1347
1341 1348 2004-07-31 Fernando Perez <fperez@colorado.edu>
1342 1349
1343 1350 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1344 1351 fix completion of files with dots in their names under most
1345 1352 profiles (pysh was OK because the completion order is different).
1346 1353
1347 1354 2004-07-27 Fernando Perez <fperez@colorado.edu>
1348 1355
1349 1356 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1350 1357 keywords manually, b/c the one in keyword.py was removed in python
1351 1358 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1352 1359 This is NOT a bug under python 2.3 and earlier.
1353 1360
1354 1361 2004-07-26 Fernando Perez <fperez@colorado.edu>
1355 1362
1356 1363 * IPython/ultraTB.py (VerboseTB.text): Add another
1357 1364 linecache.checkcache() call to try to prevent inspect.py from
1358 1365 crashing under python 2.3. I think this fixes
1359 1366 http://www.scipy.net/roundup/ipython/issue17.
1360 1367
1361 1368 2004-07-26 *** Released version 0.6.2
1362 1369
1363 1370 2004-07-26 Fernando Perez <fperez@colorado.edu>
1364 1371
1365 1372 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1366 1373 fail for any number.
1367 1374 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1368 1375 empty bookmarks.
1369 1376
1370 1377 2004-07-26 *** Released version 0.6.1
1371 1378
1372 1379 2004-07-26 Fernando Perez <fperez@colorado.edu>
1373 1380
1374 1381 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1375 1382
1376 1383 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1377 1384 escaping '()[]{}' in filenames.
1378 1385
1379 1386 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1380 1387 Python 2.2 users who lack a proper shlex.split.
1381 1388
1382 1389 2004-07-19 Fernando Perez <fperez@colorado.edu>
1383 1390
1384 1391 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1385 1392 for reading readline's init file. I follow the normal chain:
1386 1393 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1387 1394 report by Mike Heeter. This closes
1388 1395 http://www.scipy.net/roundup/ipython/issue16.
1389 1396
1390 1397 2004-07-18 Fernando Perez <fperez@colorado.edu>
1391 1398
1392 1399 * IPython/iplib.py (__init__): Add better handling of '\' under
1393 1400 Win32 for filenames. After a patch by Ville.
1394 1401
1395 1402 2004-07-17 Fernando Perez <fperez@colorado.edu>
1396 1403
1397 1404 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1398 1405 autocalling would be triggered for 'foo is bar' if foo is
1399 1406 callable. I also cleaned up the autocall detection code to use a
1400 1407 regexp, which is faster. Bug reported by Alexander Schmolck.
1401 1408
1402 1409 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1403 1410 '?' in them would confuse the help system. Reported by Alex
1404 1411 Schmolck.
1405 1412
1406 1413 2004-07-16 Fernando Perez <fperez@colorado.edu>
1407 1414
1408 1415 * IPython/GnuplotInteractive.py (__all__): added plot2.
1409 1416
1410 1417 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1411 1418 plotting dictionaries, lists or tuples of 1d arrays.
1412 1419
1413 1420 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1414 1421 optimizations.
1415 1422
1416 1423 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1417 1424 the information which was there from Janko's original IPP code:
1418 1425
1419 1426 03.05.99 20:53 porto.ifm.uni-kiel.de
1420 1427 --Started changelog.
1421 1428 --make clear do what it say it does
1422 1429 --added pretty output of lines from inputcache
1423 1430 --Made Logger a mixin class, simplifies handling of switches
1424 1431 --Added own completer class. .string<TAB> expands to last history
1425 1432 line which starts with string. The new expansion is also present
1426 1433 with Ctrl-r from the readline library. But this shows, who this
1427 1434 can be done for other cases.
1428 1435 --Added convention that all shell functions should accept a
1429 1436 parameter_string This opens the door for different behaviour for
1430 1437 each function. @cd is a good example of this.
1431 1438
1432 1439 04.05.99 12:12 porto.ifm.uni-kiel.de
1433 1440 --added logfile rotation
1434 1441 --added new mainloop method which freezes first the namespace
1435 1442
1436 1443 07.05.99 21:24 porto.ifm.uni-kiel.de
1437 1444 --added the docreader classes. Now there is a help system.
1438 1445 -This is only a first try. Currently it's not easy to put new
1439 1446 stuff in the indices. But this is the way to go. Info would be
1440 1447 better, but HTML is every where and not everybody has an info
1441 1448 system installed and it's not so easy to change html-docs to info.
1442 1449 --added global logfile option
1443 1450 --there is now a hook for object inspection method pinfo needs to
1444 1451 be provided for this. Can be reached by two '??'.
1445 1452
1446 1453 08.05.99 20:51 porto.ifm.uni-kiel.de
1447 1454 --added a README
1448 1455 --bug in rc file. Something has changed so functions in the rc
1449 1456 file need to reference the shell and not self. Not clear if it's a
1450 1457 bug or feature.
1451 1458 --changed rc file for new behavior
1452 1459
1453 1460 2004-07-15 Fernando Perez <fperez@colorado.edu>
1454 1461
1455 1462 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1456 1463 cache was falling out of sync in bizarre manners when multi-line
1457 1464 input was present. Minor optimizations and cleanup.
1458 1465
1459 1466 (Logger): Remove old Changelog info for cleanup. This is the
1460 1467 information which was there from Janko's original code:
1461 1468
1462 1469 Changes to Logger: - made the default log filename a parameter
1463 1470
1464 1471 - put a check for lines beginning with !@? in log(). Needed
1465 1472 (even if the handlers properly log their lines) for mid-session
1466 1473 logging activation to work properly. Without this, lines logged
1467 1474 in mid session, which get read from the cache, would end up
1468 1475 'bare' (with !@? in the open) in the log. Now they are caught
1469 1476 and prepended with a #.
1470 1477
1471 1478 * IPython/iplib.py (InteractiveShell.init_readline): added check
1472 1479 in case MagicCompleter fails to be defined, so we don't crash.
1473 1480
1474 1481 2004-07-13 Fernando Perez <fperez@colorado.edu>
1475 1482
1476 1483 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1477 1484 of EPS if the requested filename ends in '.eps'.
1478 1485
1479 1486 2004-07-04 Fernando Perez <fperez@colorado.edu>
1480 1487
1481 1488 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1482 1489 escaping of quotes when calling the shell.
1483 1490
1484 1491 2004-07-02 Fernando Perez <fperez@colorado.edu>
1485 1492
1486 1493 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1487 1494 gettext not working because we were clobbering '_'. Fixes
1488 1495 http://www.scipy.net/roundup/ipython/issue6.
1489 1496
1490 1497 2004-07-01 Fernando Perez <fperez@colorado.edu>
1491 1498
1492 1499 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1493 1500 into @cd. Patch by Ville.
1494 1501
1495 1502 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1496 1503 new function to store things after ipmaker runs. Patch by Ville.
1497 1504 Eventually this will go away once ipmaker is removed and the class
1498 1505 gets cleaned up, but for now it's ok. Key functionality here is
1499 1506 the addition of the persistent storage mechanism, a dict for
1500 1507 keeping data across sessions (for now just bookmarks, but more can
1501 1508 be implemented later).
1502 1509
1503 1510 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1504 1511 persistent across sections. Patch by Ville, I modified it
1505 1512 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1506 1513 added a '-l' option to list all bookmarks.
1507 1514
1508 1515 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1509 1516 center for cleanup. Registered with atexit.register(). I moved
1510 1517 here the old exit_cleanup(). After a patch by Ville.
1511 1518
1512 1519 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1513 1520 characters in the hacked shlex_split for python 2.2.
1514 1521
1515 1522 * IPython/iplib.py (file_matches): more fixes to filenames with
1516 1523 whitespace in them. It's not perfect, but limitations in python's
1517 1524 readline make it impossible to go further.
1518 1525
1519 1526 2004-06-29 Fernando Perez <fperez@colorado.edu>
1520 1527
1521 1528 * IPython/iplib.py (file_matches): escape whitespace correctly in
1522 1529 filename completions. Bug reported by Ville.
1523 1530
1524 1531 2004-06-28 Fernando Perez <fperez@colorado.edu>
1525 1532
1526 1533 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1527 1534 the history file will be called 'history-PROFNAME' (or just
1528 1535 'history' if no profile is loaded). I was getting annoyed at
1529 1536 getting my Numerical work history clobbered by pysh sessions.
1530 1537
1531 1538 * IPython/iplib.py (InteractiveShell.__init__): Internal
1532 1539 getoutputerror() function so that we can honor the system_verbose
1533 1540 flag for _all_ system calls. I also added escaping of #
1534 1541 characters here to avoid confusing Itpl.
1535 1542
1536 1543 * IPython/Magic.py (shlex_split): removed call to shell in
1537 1544 parse_options and replaced it with shlex.split(). The annoying
1538 1545 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1539 1546 to backport it from 2.3, with several frail hacks (the shlex
1540 1547 module is rather limited in 2.2). Thanks to a suggestion by Ville
1541 1548 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1542 1549 problem.
1543 1550
1544 1551 (Magic.magic_system_verbose): new toggle to print the actual
1545 1552 system calls made by ipython. Mainly for debugging purposes.
1546 1553
1547 1554 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1548 1555 doesn't support persistence. Reported (and fix suggested) by
1549 1556 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1550 1557
1551 1558 2004-06-26 Fernando Perez <fperez@colorado.edu>
1552 1559
1553 1560 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1554 1561 continue prompts.
1555 1562
1556 1563 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1557 1564 function (basically a big docstring) and a few more things here to
1558 1565 speedup startup. pysh.py is now very lightweight. We want because
1559 1566 it gets execfile'd, while InterpreterExec gets imported, so
1560 1567 byte-compilation saves time.
1561 1568
1562 1569 2004-06-25 Fernando Perez <fperez@colorado.edu>
1563 1570
1564 1571 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1565 1572 -NUM', which was recently broken.
1566 1573
1567 1574 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1568 1575 in multi-line input (but not !!, which doesn't make sense there).
1569 1576
1570 1577 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1571 1578 It's just too useful, and people can turn it off in the less
1572 1579 common cases where it's a problem.
1573 1580
1574 1581 2004-06-24 Fernando Perez <fperez@colorado.edu>
1575 1582
1576 1583 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1577 1584 special syntaxes (like alias calling) is now allied in multi-line
1578 1585 input. This is still _very_ experimental, but it's necessary for
1579 1586 efficient shell usage combining python looping syntax with system
1580 1587 calls. For now it's restricted to aliases, I don't think it
1581 1588 really even makes sense to have this for magics.
1582 1589
1583 1590 2004-06-23 Fernando Perez <fperez@colorado.edu>
1584 1591
1585 1592 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1586 1593 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1587 1594
1588 1595 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1589 1596 extensions under Windows (after code sent by Gary Bishop). The
1590 1597 extensions considered 'executable' are stored in IPython's rc
1591 1598 structure as win_exec_ext.
1592 1599
1593 1600 * IPython/genutils.py (shell): new function, like system() but
1594 1601 without return value. Very useful for interactive shell work.
1595 1602
1596 1603 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1597 1604 delete aliases.
1598 1605
1599 1606 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1600 1607 sure that the alias table doesn't contain python keywords.
1601 1608
1602 1609 2004-06-21 Fernando Perez <fperez@colorado.edu>
1603 1610
1604 1611 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1605 1612 non-existent items are found in $PATH. Reported by Thorsten.
1606 1613
1607 1614 2004-06-20 Fernando Perez <fperez@colorado.edu>
1608 1615
1609 1616 * IPython/iplib.py (complete): modified the completer so that the
1610 1617 order of priorities can be easily changed at runtime.
1611 1618
1612 1619 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1613 1620 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1614 1621
1615 1622 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1616 1623 expand Python variables prepended with $ in all system calls. The
1617 1624 same was done to InteractiveShell.handle_shell_escape. Now all
1618 1625 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1619 1626 expansion of python variables and expressions according to the
1620 1627 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1621 1628
1622 1629 Though PEP-215 has been rejected, a similar (but simpler) one
1623 1630 seems like it will go into Python 2.4, PEP-292 -
1624 1631 http://www.python.org/peps/pep-0292.html.
1625 1632
1626 1633 I'll keep the full syntax of PEP-215, since IPython has since the
1627 1634 start used Ka-Ping Yee's reference implementation discussed there
1628 1635 (Itpl), and I actually like the powerful semantics it offers.
1629 1636
1630 1637 In order to access normal shell variables, the $ has to be escaped
1631 1638 via an extra $. For example:
1632 1639
1633 1640 In [7]: PATH='a python variable'
1634 1641
1635 1642 In [8]: !echo $PATH
1636 1643 a python variable
1637 1644
1638 1645 In [9]: !echo $$PATH
1639 1646 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1640 1647
1641 1648 (Magic.parse_options): escape $ so the shell doesn't evaluate
1642 1649 things prematurely.
1643 1650
1644 1651 * IPython/iplib.py (InteractiveShell.call_alias): added the
1645 1652 ability for aliases to expand python variables via $.
1646 1653
1647 1654 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1648 1655 system, now there's a @rehash/@rehashx pair of magics. These work
1649 1656 like the csh rehash command, and can be invoked at any time. They
1650 1657 build a table of aliases to everything in the user's $PATH
1651 1658 (@rehash uses everything, @rehashx is slower but only adds
1652 1659 executable files). With this, the pysh.py-based shell profile can
1653 1660 now simply call rehash upon startup, and full access to all
1654 1661 programs in the user's path is obtained.
1655 1662
1656 1663 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1657 1664 functionality is now fully in place. I removed the old dynamic
1658 1665 code generation based approach, in favor of a much lighter one
1659 1666 based on a simple dict. The advantage is that this allows me to
1660 1667 now have thousands of aliases with negligible cost (unthinkable
1661 1668 with the old system).
1662 1669
1663 1670 2004-06-19 Fernando Perez <fperez@colorado.edu>
1664 1671
1665 1672 * IPython/iplib.py (__init__): extended MagicCompleter class to
1666 1673 also complete (last in priority) on user aliases.
1667 1674
1668 1675 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1669 1676 call to eval.
1670 1677 (ItplNS.__init__): Added a new class which functions like Itpl,
1671 1678 but allows configuring the namespace for the evaluation to occur
1672 1679 in.
1673 1680
1674 1681 2004-06-18 Fernando Perez <fperez@colorado.edu>
1675 1682
1676 1683 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1677 1684 better message when 'exit' or 'quit' are typed (a common newbie
1678 1685 confusion).
1679 1686
1680 1687 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1681 1688 check for Windows users.
1682 1689
1683 1690 * IPython/iplib.py (InteractiveShell.user_setup): removed
1684 1691 disabling of colors for Windows. I'll test at runtime and issue a
1685 1692 warning if Gary's readline isn't found, as to nudge users to
1686 1693 download it.
1687 1694
1688 1695 2004-06-16 Fernando Perez <fperez@colorado.edu>
1689 1696
1690 1697 * IPython/genutils.py (Stream.__init__): changed to print errors
1691 1698 to sys.stderr. I had a circular dependency here. Now it's
1692 1699 possible to run ipython as IDLE's shell (consider this pre-alpha,
1693 1700 since true stdout things end up in the starting terminal instead
1694 1701 of IDLE's out).
1695 1702
1696 1703 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1697 1704 users who haven't # updated their prompt_in2 definitions. Remove
1698 1705 eventually.
1699 1706 (multiple_replace): added credit to original ASPN recipe.
1700 1707
1701 1708 2004-06-15 Fernando Perez <fperez@colorado.edu>
1702 1709
1703 1710 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1704 1711 list of auto-defined aliases.
1705 1712
1706 1713 2004-06-13 Fernando Perez <fperez@colorado.edu>
1707 1714
1708 1715 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1709 1716 install was really requested (so setup.py can be used for other
1710 1717 things under Windows).
1711 1718
1712 1719 2004-06-10 Fernando Perez <fperez@colorado.edu>
1713 1720
1714 1721 * IPython/Logger.py (Logger.create_log): Manually remove any old
1715 1722 backup, since os.remove may fail under Windows. Fixes bug
1716 1723 reported by Thorsten.
1717 1724
1718 1725 2004-06-09 Fernando Perez <fperez@colorado.edu>
1719 1726
1720 1727 * examples/example-embed.py: fixed all references to %n (replaced
1721 1728 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1722 1729 for all examples and the manual as well.
1723 1730
1724 1731 2004-06-08 Fernando Perez <fperez@colorado.edu>
1725 1732
1726 1733 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1727 1734 alignment and color management. All 3 prompt subsystems now
1728 1735 inherit from BasePrompt.
1729 1736
1730 1737 * tools/release: updates for windows installer build and tag rpms
1731 1738 with python version (since paths are fixed).
1732 1739
1733 1740 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1734 1741 which will become eventually obsolete. Also fixed the default
1735 1742 prompt_in2 to use \D, so at least new users start with the correct
1736 1743 defaults.
1737 1744 WARNING: Users with existing ipythonrc files will need to apply
1738 1745 this fix manually!
1739 1746
1740 1747 * setup.py: make windows installer (.exe). This is finally the
1741 1748 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1742 1749 which I hadn't included because it required Python 2.3 (or recent
1743 1750 distutils).
1744 1751
1745 1752 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1746 1753 usage of new '\D' escape.
1747 1754
1748 1755 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1749 1756 lacks os.getuid())
1750 1757 (CachedOutput.set_colors): Added the ability to turn coloring
1751 1758 on/off with @colors even for manually defined prompt colors. It
1752 1759 uses a nasty global, but it works safely and via the generic color
1753 1760 handling mechanism.
1754 1761 (Prompt2.__init__): Introduced new escape '\D' for continuation
1755 1762 prompts. It represents the counter ('\#') as dots.
1756 1763 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1757 1764 need to update their ipythonrc files and replace '%n' with '\D' in
1758 1765 their prompt_in2 settings everywhere. Sorry, but there's
1759 1766 otherwise no clean way to get all prompts to properly align. The
1760 1767 ipythonrc shipped with IPython has been updated.
1761 1768
1762 1769 2004-06-07 Fernando Perez <fperez@colorado.edu>
1763 1770
1764 1771 * setup.py (isfile): Pass local_icons option to latex2html, so the
1765 1772 resulting HTML file is self-contained. Thanks to
1766 1773 dryice-AT-liu.com.cn for the tip.
1767 1774
1768 1775 * pysh.py: I created a new profile 'shell', which implements a
1769 1776 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1770 1777 system shell, nor will it become one anytime soon. It's mainly
1771 1778 meant to illustrate the use of the new flexible bash-like prompts.
1772 1779 I guess it could be used by hardy souls for true shell management,
1773 1780 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1774 1781 profile. This uses the InterpreterExec extension provided by
1775 1782 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1776 1783
1777 1784 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1778 1785 auto-align itself with the length of the previous input prompt
1779 1786 (taking into account the invisible color escapes).
1780 1787 (CachedOutput.__init__): Large restructuring of this class. Now
1781 1788 all three prompts (primary1, primary2, output) are proper objects,
1782 1789 managed by the 'parent' CachedOutput class. The code is still a
1783 1790 bit hackish (all prompts share state via a pointer to the cache),
1784 1791 but it's overall far cleaner than before.
1785 1792
1786 1793 * IPython/genutils.py (getoutputerror): modified to add verbose,
1787 1794 debug and header options. This makes the interface of all getout*
1788 1795 functions uniform.
1789 1796 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1790 1797
1791 1798 * IPython/Magic.py (Magic.default_option): added a function to
1792 1799 allow registering default options for any magic command. This
1793 1800 makes it easy to have profiles which customize the magics globally
1794 1801 for a certain use. The values set through this function are
1795 1802 picked up by the parse_options() method, which all magics should
1796 1803 use to parse their options.
1797 1804
1798 1805 * IPython/genutils.py (warn): modified the warnings framework to
1799 1806 use the Term I/O class. I'm trying to slowly unify all of
1800 1807 IPython's I/O operations to pass through Term.
1801 1808
1802 1809 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1803 1810 the secondary prompt to correctly match the length of the primary
1804 1811 one for any prompt. Now multi-line code will properly line up
1805 1812 even for path dependent prompts, such as the new ones available
1806 1813 via the prompt_specials.
1807 1814
1808 1815 2004-06-06 Fernando Perez <fperez@colorado.edu>
1809 1816
1810 1817 * IPython/Prompts.py (prompt_specials): Added the ability to have
1811 1818 bash-like special sequences in the prompts, which get
1812 1819 automatically expanded. Things like hostname, current working
1813 1820 directory and username are implemented already, but it's easy to
1814 1821 add more in the future. Thanks to a patch by W.J. van der Laan
1815 1822 <gnufnork-AT-hetdigitalegat.nl>
1816 1823 (prompt_specials): Added color support for prompt strings, so
1817 1824 users can define arbitrary color setups for their prompts.
1818 1825
1819 1826 2004-06-05 Fernando Perez <fperez@colorado.edu>
1820 1827
1821 1828 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1822 1829 code to load Gary Bishop's readline and configure it
1823 1830 automatically. Thanks to Gary for help on this.
1824 1831
1825 1832 2004-06-01 Fernando Perez <fperez@colorado.edu>
1826 1833
1827 1834 * IPython/Logger.py (Logger.create_log): fix bug for logging
1828 1835 with no filename (previous fix was incomplete).
1829 1836
1830 1837 2004-05-25 Fernando Perez <fperez@colorado.edu>
1831 1838
1832 1839 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1833 1840 parens would get passed to the shell.
1834 1841
1835 1842 2004-05-20 Fernando Perez <fperez@colorado.edu>
1836 1843
1837 1844 * IPython/Magic.py (Magic.magic_prun): changed default profile
1838 1845 sort order to 'time' (the more common profiling need).
1839 1846
1840 1847 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1841 1848 so that source code shown is guaranteed in sync with the file on
1842 1849 disk (also changed in psource). Similar fix to the one for
1843 1850 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
1844 1851 <yann.ledu-AT-noos.fr>.
1845 1852
1846 1853 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
1847 1854 with a single option would not be correctly parsed. Closes
1848 1855 http://www.scipy.net/roundup/ipython/issue14. This bug had been
1849 1856 introduced in 0.6.0 (on 2004-05-06).
1850 1857
1851 1858 2004-05-13 *** Released version 0.6.0
1852 1859
1853 1860 2004-05-13 Fernando Perez <fperez@colorado.edu>
1854 1861
1855 1862 * debian/: Added debian/ directory to CVS, so that debian support
1856 1863 is publicly accessible. The debian package is maintained by Jack
1857 1864 Moffit <jack-AT-xiph.org>.
1858 1865
1859 1866 * Documentation: included the notes about an ipython-based system
1860 1867 shell (the hypothetical 'pysh') into the new_design.pdf document,
1861 1868 so that these ideas get distributed to users along with the
1862 1869 official documentation.
1863 1870
1864 1871 2004-05-10 Fernando Perez <fperez@colorado.edu>
1865 1872
1866 1873 * IPython/Logger.py (Logger.create_log): fix recently introduced
1867 1874 bug (misindented line) where logstart would fail when not given an
1868 1875 explicit filename.
1869 1876
1870 1877 2004-05-09 Fernando Perez <fperez@colorado.edu>
1871 1878
1872 1879 * IPython/Magic.py (Magic.parse_options): skip system call when
1873 1880 there are no options to look for. Faster, cleaner for the common
1874 1881 case.
1875 1882
1876 1883 * Documentation: many updates to the manual: describing Windows
1877 1884 support better, Gnuplot updates, credits, misc small stuff. Also
1878 1885 updated the new_design doc a bit.
1879 1886
1880 1887 2004-05-06 *** Released version 0.6.0.rc1
1881 1888
1882 1889 2004-05-06 Fernando Perez <fperez@colorado.edu>
1883 1890
1884 1891 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
1885 1892 operations to use the vastly more efficient list/''.join() method.
1886 1893 (FormattedTB.text): Fix
1887 1894 http://www.scipy.net/roundup/ipython/issue12 - exception source
1888 1895 extract not updated after reload. Thanks to Mike Salib
1889 1896 <msalib-AT-mit.edu> for pinning the source of the problem.
1890 1897 Fortunately, the solution works inside ipython and doesn't require
1891 1898 any changes to python proper.
1892 1899
1893 1900 * IPython/Magic.py (Magic.parse_options): Improved to process the
1894 1901 argument list as a true shell would (by actually using the
1895 1902 underlying system shell). This way, all @magics automatically get
1896 1903 shell expansion for variables. Thanks to a comment by Alex
1897 1904 Schmolck.
1898 1905
1899 1906 2004-04-04 Fernando Perez <fperez@colorado.edu>
1900 1907
1901 1908 * IPython/iplib.py (InteractiveShell.interact): Added a special
1902 1909 trap for a debugger quit exception, which is basically impossible
1903 1910 to handle by normal mechanisms, given what pdb does to the stack.
1904 1911 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
1905 1912
1906 1913 2004-04-03 Fernando Perez <fperez@colorado.edu>
1907 1914
1908 1915 * IPython/genutils.py (Term): Standardized the names of the Term
1909 1916 class streams to cin/cout/cerr, following C++ naming conventions
1910 1917 (I can't use in/out/err because 'in' is not a valid attribute
1911 1918 name).
1912 1919
1913 1920 * IPython/iplib.py (InteractiveShell.interact): don't increment
1914 1921 the prompt if there's no user input. By Daniel 'Dang' Griffith
1915 1922 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
1916 1923 Francois Pinard.
1917 1924
1918 1925 2004-04-02 Fernando Perez <fperez@colorado.edu>
1919 1926
1920 1927 * IPython/genutils.py (Stream.__init__): Modified to survive at
1921 1928 least importing in contexts where stdin/out/err aren't true file
1922 1929 objects, such as PyCrust (they lack fileno() and mode). However,
1923 1930 the recovery facilities which rely on these things existing will
1924 1931 not work.
1925 1932
1926 1933 2004-04-01 Fernando Perez <fperez@colorado.edu>
1927 1934
1928 1935 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
1929 1936 use the new getoutputerror() function, so it properly
1930 1937 distinguishes stdout/err.
1931 1938
1932 1939 * IPython/genutils.py (getoutputerror): added a function to
1933 1940 capture separately the standard output and error of a command.
1934 1941 After a comment from dang on the mailing lists. This code is
1935 1942 basically a modified version of commands.getstatusoutput(), from
1936 1943 the standard library.
1937 1944
1938 1945 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
1939 1946 '!!' as a special syntax (shorthand) to access @sx.
1940 1947
1941 1948 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
1942 1949 command and return its output as a list split on '\n'.
1943 1950
1944 1951 2004-03-31 Fernando Perez <fperez@colorado.edu>
1945 1952
1946 1953 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
1947 1954 method to dictionaries used as FakeModule instances if they lack
1948 1955 it. At least pydoc in python2.3 breaks for runtime-defined
1949 1956 functions without this hack. At some point I need to _really_
1950 1957 understand what FakeModule is doing, because it's a gross hack.
1951 1958 But it solves Arnd's problem for now...
1952 1959
1953 1960 2004-02-27 Fernando Perez <fperez@colorado.edu>
1954 1961
1955 1962 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
1956 1963 mode would behave erratically. Also increased the number of
1957 1964 possible logs in rotate mod to 999. Thanks to Rod Holland
1958 1965 <rhh@StructureLABS.com> for the report and fixes.
1959 1966
1960 1967 2004-02-26 Fernando Perez <fperez@colorado.edu>
1961 1968
1962 1969 * IPython/genutils.py (page): Check that the curses module really
1963 1970 has the initscr attribute before trying to use it. For some
1964 1971 reason, the Solaris curses module is missing this. I think this
1965 1972 should be considered a Solaris python bug, but I'm not sure.
1966 1973
1967 1974 2004-01-17 Fernando Perez <fperez@colorado.edu>
1968 1975
1969 1976 * IPython/genutils.py (Stream.__init__): Changes to try to make
1970 1977 ipython robust against stdin/out/err being closed by the user.
1971 1978 This is 'user error' (and blocks a normal python session, at least
1972 1979 the stdout case). However, Ipython should be able to survive such
1973 1980 instances of abuse as gracefully as possible. To simplify the
1974 1981 coding and maintain compatibility with Gary Bishop's Term
1975 1982 contributions, I've made use of classmethods for this. I think
1976 1983 this introduces a dependency on python 2.2.
1977 1984
1978 1985 2004-01-13 Fernando Perez <fperez@colorado.edu>
1979 1986
1980 1987 * IPython/numutils.py (exp_safe): simplified the code a bit and
1981 1988 removed the need for importing the kinds module altogether.
1982 1989
1983 1990 2004-01-06 Fernando Perez <fperez@colorado.edu>
1984 1991
1985 1992 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
1986 1993 a magic function instead, after some community feedback. No
1987 1994 special syntax will exist for it, but its name is deliberately
1988 1995 very short.
1989 1996
1990 1997 2003-12-20 Fernando Perez <fperez@colorado.edu>
1991 1998
1992 1999 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
1993 2000 new functionality, to automagically assign the result of a shell
1994 2001 command to a variable. I'll solicit some community feedback on
1995 2002 this before making it permanent.
1996 2003
1997 2004 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
1998 2005 requested about callables for which inspect couldn't obtain a
1999 2006 proper argspec. Thanks to a crash report sent by Etienne
2000 2007 Posthumus <etienne-AT-apple01.cs.vu.nl>.
2001 2008
2002 2009 2003-12-09 Fernando Perez <fperez@colorado.edu>
2003 2010
2004 2011 * IPython/genutils.py (page): patch for the pager to work across
2005 2012 various versions of Windows. By Gary Bishop.
2006 2013
2007 2014 2003-12-04 Fernando Perez <fperez@colorado.edu>
2008 2015
2009 2016 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
2010 2017 Gnuplot.py version 1.7, whose internal names changed quite a bit.
2011 2018 While I tested this and it looks ok, there may still be corner
2012 2019 cases I've missed.
2013 2020
2014 2021 2003-12-01 Fernando Perez <fperez@colorado.edu>
2015 2022
2016 2023 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
2017 2024 where a line like 'p,q=1,2' would fail because the automagic
2018 2025 system would be triggered for @p.
2019 2026
2020 2027 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
2021 2028 cleanups, code unmodified.
2022 2029
2023 2030 * IPython/genutils.py (Term): added a class for IPython to handle
2024 2031 output. In most cases it will just be a proxy for stdout/err, but
2025 2032 having this allows modifications to be made for some platforms,
2026 2033 such as handling color escapes under Windows. All of this code
2027 2034 was contributed by Gary Bishop, with minor modifications by me.
2028 2035 The actual changes affect many files.
2029 2036
2030 2037 2003-11-30 Fernando Perez <fperez@colorado.edu>
2031 2038
2032 2039 * IPython/iplib.py (file_matches): new completion code, courtesy
2033 2040 of Jeff Collins. This enables filename completion again under
2034 2041 python 2.3, which disabled it at the C level.
2035 2042
2036 2043 2003-11-11 Fernando Perez <fperez@colorado.edu>
2037 2044
2038 2045 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
2039 2046 for Numeric.array(map(...)), but often convenient.
2040 2047
2041 2048 2003-11-05 Fernando Perez <fperez@colorado.edu>
2042 2049
2043 2050 * IPython/numutils.py (frange): Changed a call from int() to
2044 2051 int(round()) to prevent a problem reported with arange() in the
2045 2052 numpy list.
2046 2053
2047 2054 2003-10-06 Fernando Perez <fperez@colorado.edu>
2048 2055
2049 2056 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
2050 2057 prevent crashes if sys lacks an argv attribute (it happens with
2051 2058 embedded interpreters which build a bare-bones sys module).
2052 2059 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
2053 2060
2054 2061 2003-09-24 Fernando Perez <fperez@colorado.edu>
2055 2062
2056 2063 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
2057 2064 to protect against poorly written user objects where __getattr__
2058 2065 raises exceptions other than AttributeError. Thanks to a bug
2059 2066 report by Oliver Sander <osander-AT-gmx.de>.
2060 2067
2061 2068 * IPython/FakeModule.py (FakeModule.__repr__): this method was
2062 2069 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
2063 2070
2064 2071 2003-09-09 Fernando Perez <fperez@colorado.edu>
2065 2072
2066 2073 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
2067 2074 unpacking a list whith a callable as first element would
2068 2075 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
2069 2076 Collins.
2070 2077
2071 2078 2003-08-25 *** Released version 0.5.0
2072 2079
2073 2080 2003-08-22 Fernando Perez <fperez@colorado.edu>
2074 2081
2075 2082 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
2076 2083 improperly defined user exceptions. Thanks to feedback from Mark
2077 2084 Russell <mrussell-AT-verio.net>.
2078 2085
2079 2086 2003-08-20 Fernando Perez <fperez@colorado.edu>
2080 2087
2081 2088 * IPython/OInspect.py (Inspector.pinfo): changed String Form
2082 2089 printing so that it would print multi-line string forms starting
2083 2090 with a new line. This way the formatting is better respected for
2084 2091 objects which work hard to make nice string forms.
2085 2092
2086 2093 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
2087 2094 autocall would overtake data access for objects with both
2088 2095 __getitem__ and __call__.
2089 2096
2090 2097 2003-08-19 *** Released version 0.5.0-rc1
2091 2098
2092 2099 2003-08-19 Fernando Perez <fperez@colorado.edu>
2093 2100
2094 2101 * IPython/deep_reload.py (load_tail): single tiny change here
2095 2102 seems to fix the long-standing bug of dreload() failing to work
2096 2103 for dotted names. But this module is pretty tricky, so I may have
2097 2104 missed some subtlety. Needs more testing!.
2098 2105
2099 2106 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
2100 2107 exceptions which have badly implemented __str__ methods.
2101 2108 (VerboseTB.text): harden against inspect.getinnerframes crashing,
2102 2109 which I've been getting reports about from Python 2.3 users. I
2103 2110 wish I had a simple test case to reproduce the problem, so I could
2104 2111 either write a cleaner workaround or file a bug report if
2105 2112 necessary.
2106 2113
2107 2114 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
2108 2115 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
2109 2116 a bug report by Tjabo Kloppenburg.
2110 2117
2111 2118 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
2112 2119 crashes. Wrapped the pdb call in a blanket try/except, since pdb
2113 2120 seems rather unstable. Thanks to a bug report by Tjabo
2114 2121 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
2115 2122
2116 2123 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
2117 2124 this out soon because of the critical fixes in the inner loop for
2118 2125 generators.
2119 2126
2120 2127 * IPython/Magic.py (Magic.getargspec): removed. This (and
2121 2128 _get_def) have been obsoleted by OInspect for a long time, I
2122 2129 hadn't noticed that they were dead code.
2123 2130 (Magic._ofind): restored _ofind functionality for a few literals
2124 2131 (those in ["''",'""','[]','{}','()']). But it won't work anymore
2125 2132 for things like "hello".capitalize?, since that would require a
2126 2133 potentially dangerous eval() again.
2127 2134
2128 2135 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
2129 2136 logic a bit more to clean up the escapes handling and minimize the
2130 2137 use of _ofind to only necessary cases. The interactive 'feel' of
2131 2138 IPython should have improved quite a bit with the changes in
2132 2139 _prefilter and _ofind (besides being far safer than before).
2133 2140
2134 2141 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
2135 2142 obscure, never reported). Edit would fail to find the object to
2136 2143 edit under some circumstances.
2137 2144 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
2138 2145 which were causing double-calling of generators. Those eval calls
2139 2146 were _very_ dangerous, since code with side effects could be
2140 2147 triggered. As they say, 'eval is evil'... These were the
2141 2148 nastiest evals in IPython. Besides, _ofind is now far simpler,
2142 2149 and it should also be quite a bit faster. Its use of inspect is
2143 2150 also safer, so perhaps some of the inspect-related crashes I've
2144 2151 seen lately with Python 2.3 might be taken care of. That will
2145 2152 need more testing.
2146 2153
2147 2154 2003-08-17 Fernando Perez <fperez@colorado.edu>
2148 2155
2149 2156 * IPython/iplib.py (InteractiveShell._prefilter): significant
2150 2157 simplifications to the logic for handling user escapes. Faster
2151 2158 and simpler code.
2152 2159
2153 2160 2003-08-14 Fernando Perez <fperez@colorado.edu>
2154 2161
2155 2162 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
2156 2163 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
2157 2164 but it should be quite a bit faster. And the recursive version
2158 2165 generated O(log N) intermediate storage for all rank>1 arrays,
2159 2166 even if they were contiguous.
2160 2167 (l1norm): Added this function.
2161 2168 (norm): Added this function for arbitrary norms (including
2162 2169 l-infinity). l1 and l2 are still special cases for convenience
2163 2170 and speed.
2164 2171
2165 2172 2003-08-03 Fernando Perez <fperez@colorado.edu>
2166 2173
2167 2174 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
2168 2175 exceptions, which now raise PendingDeprecationWarnings in Python
2169 2176 2.3. There were some in Magic and some in Gnuplot2.
2170 2177
2171 2178 2003-06-30 Fernando Perez <fperez@colorado.edu>
2172 2179
2173 2180 * IPython/genutils.py (page): modified to call curses only for
2174 2181 terminals where TERM=='xterm'. After problems under many other
2175 2182 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2176 2183
2177 2184 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2178 2185 would be triggered when readline was absent. This was just an old
2179 2186 debugging statement I'd forgotten to take out.
2180 2187
2181 2188 2003-06-20 Fernando Perez <fperez@colorado.edu>
2182 2189
2183 2190 * IPython/genutils.py (clock): modified to return only user time
2184 2191 (not counting system time), after a discussion on scipy. While
2185 2192 system time may be a useful quantity occasionally, it may much
2186 2193 more easily be skewed by occasional swapping or other similar
2187 2194 activity.
2188 2195
2189 2196 2003-06-05 Fernando Perez <fperez@colorado.edu>
2190 2197
2191 2198 * IPython/numutils.py (identity): new function, for building
2192 2199 arbitrary rank Kronecker deltas (mostly backwards compatible with
2193 2200 Numeric.identity)
2194 2201
2195 2202 2003-06-03 Fernando Perez <fperez@colorado.edu>
2196 2203
2197 2204 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2198 2205 arguments passed to magics with spaces, to allow trailing '\' to
2199 2206 work normally (mainly for Windows users).
2200 2207
2201 2208 2003-05-29 Fernando Perez <fperez@colorado.edu>
2202 2209
2203 2210 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2204 2211 instead of pydoc.help. This fixes a bizarre behavior where
2205 2212 printing '%s' % locals() would trigger the help system. Now
2206 2213 ipython behaves like normal python does.
2207 2214
2208 2215 Note that if one does 'from pydoc import help', the bizarre
2209 2216 behavior returns, but this will also happen in normal python, so
2210 2217 it's not an ipython bug anymore (it has to do with how pydoc.help
2211 2218 is implemented).
2212 2219
2213 2220 2003-05-22 Fernando Perez <fperez@colorado.edu>
2214 2221
2215 2222 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2216 2223 return [] instead of None when nothing matches, also match to end
2217 2224 of line. Patch by Gary Bishop.
2218 2225
2219 2226 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2220 2227 protection as before, for files passed on the command line. This
2221 2228 prevents the CrashHandler from kicking in if user files call into
2222 2229 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2223 2230 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2224 2231
2225 2232 2003-05-20 *** Released version 0.4.0
2226 2233
2227 2234 2003-05-20 Fernando Perez <fperez@colorado.edu>
2228 2235
2229 2236 * setup.py: added support for manpages. It's a bit hackish b/c of
2230 2237 a bug in the way the bdist_rpm distutils target handles gzipped
2231 2238 manpages, but it works. After a patch by Jack.
2232 2239
2233 2240 2003-05-19 Fernando Perez <fperez@colorado.edu>
2234 2241
2235 2242 * IPython/numutils.py: added a mockup of the kinds module, since
2236 2243 it was recently removed from Numeric. This way, numutils will
2237 2244 work for all users even if they are missing kinds.
2238 2245
2239 2246 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2240 2247 failure, which can occur with SWIG-wrapped extensions. After a
2241 2248 crash report from Prabhu.
2242 2249
2243 2250 2003-05-16 Fernando Perez <fperez@colorado.edu>
2244 2251
2245 2252 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2246 2253 protect ipython from user code which may call directly
2247 2254 sys.excepthook (this looks like an ipython crash to the user, even
2248 2255 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2249 2256 This is especially important to help users of WxWindows, but may
2250 2257 also be useful in other cases.
2251 2258
2252 2259 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2253 2260 an optional tb_offset to be specified, and to preserve exception
2254 2261 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2255 2262
2256 2263 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2257 2264
2258 2265 2003-05-15 Fernando Perez <fperez@colorado.edu>
2259 2266
2260 2267 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2261 2268 installing for a new user under Windows.
2262 2269
2263 2270 2003-05-12 Fernando Perez <fperez@colorado.edu>
2264 2271
2265 2272 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2266 2273 handler for Emacs comint-based lines. Currently it doesn't do
2267 2274 much (but importantly, it doesn't update the history cache). In
2268 2275 the future it may be expanded if Alex needs more functionality
2269 2276 there.
2270 2277
2271 2278 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2272 2279 info to crash reports.
2273 2280
2274 2281 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2275 2282 just like Python's -c. Also fixed crash with invalid -color
2276 2283 option value at startup. Thanks to Will French
2277 2284 <wfrench-AT-bestweb.net> for the bug report.
2278 2285
2279 2286 2003-05-09 Fernando Perez <fperez@colorado.edu>
2280 2287
2281 2288 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2282 2289 to EvalDict (it's a mapping, after all) and simplified its code
2283 2290 quite a bit, after a nice discussion on c.l.py where Gustavo
2284 2291 Córdova <gcordova-AT-sismex.com> suggested the new version.
2285 2292
2286 2293 2003-04-30 Fernando Perez <fperez@colorado.edu>
2287 2294
2288 2295 * IPython/genutils.py (timings_out): modified it to reduce its
2289 2296 overhead in the common reps==1 case.
2290 2297
2291 2298 2003-04-29 Fernando Perez <fperez@colorado.edu>
2292 2299
2293 2300 * IPython/genutils.py (timings_out): Modified to use the resource
2294 2301 module, which avoids the wraparound problems of time.clock().
2295 2302
2296 2303 2003-04-17 *** Released version 0.2.15pre4
2297 2304
2298 2305 2003-04-17 Fernando Perez <fperez@colorado.edu>
2299 2306
2300 2307 * setup.py (scriptfiles): Split windows-specific stuff over to a
2301 2308 separate file, in an attempt to have a Windows GUI installer.
2302 2309 That didn't work, but part of the groundwork is done.
2303 2310
2304 2311 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2305 2312 indent/unindent with 4 spaces. Particularly useful in combination
2306 2313 with the new auto-indent option.
2307 2314
2308 2315 2003-04-16 Fernando Perez <fperez@colorado.edu>
2309 2316
2310 2317 * IPython/Magic.py: various replacements of self.rc for
2311 2318 self.shell.rc. A lot more remains to be done to fully disentangle
2312 2319 this class from the main Shell class.
2313 2320
2314 2321 * IPython/GnuplotRuntime.py: added checks for mouse support so
2315 2322 that we don't try to enable it if the current gnuplot doesn't
2316 2323 really support it. Also added checks so that we don't try to
2317 2324 enable persist under Windows (where Gnuplot doesn't recognize the
2318 2325 option).
2319 2326
2320 2327 * IPython/iplib.py (InteractiveShell.interact): Added optional
2321 2328 auto-indenting code, after a patch by King C. Shu
2322 2329 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2323 2330 get along well with pasting indented code. If I ever figure out
2324 2331 how to make that part go well, it will become on by default.
2325 2332
2326 2333 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2327 2334 crash ipython if there was an unmatched '%' in the user's prompt
2328 2335 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2329 2336
2330 2337 * IPython/iplib.py (InteractiveShell.interact): removed the
2331 2338 ability to ask the user whether he wants to crash or not at the
2332 2339 'last line' exception handler. Calling functions at that point
2333 2340 changes the stack, and the error reports would have incorrect
2334 2341 tracebacks.
2335 2342
2336 2343 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2337 2344 pass through a peger a pretty-printed form of any object. After a
2338 2345 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2339 2346
2340 2347 2003-04-14 Fernando Perez <fperez@colorado.edu>
2341 2348
2342 2349 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2343 2350 all files in ~ would be modified at first install (instead of
2344 2351 ~/.ipython). This could be potentially disastrous, as the
2345 2352 modification (make line-endings native) could damage binary files.
2346 2353
2347 2354 2003-04-10 Fernando Perez <fperez@colorado.edu>
2348 2355
2349 2356 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2350 2357 handle only lines which are invalid python. This now means that
2351 2358 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2352 2359 for the bug report.
2353 2360
2354 2361 2003-04-01 Fernando Perez <fperez@colorado.edu>
2355 2362
2356 2363 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2357 2364 where failing to set sys.last_traceback would crash pdb.pm().
2358 2365 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2359 2366 report.
2360 2367
2361 2368 2003-03-25 Fernando Perez <fperez@colorado.edu>
2362 2369
2363 2370 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2364 2371 before printing it (it had a lot of spurious blank lines at the
2365 2372 end).
2366 2373
2367 2374 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2368 2375 output would be sent 21 times! Obviously people don't use this
2369 2376 too often, or I would have heard about it.
2370 2377
2371 2378 2003-03-24 Fernando Perez <fperez@colorado.edu>
2372 2379
2373 2380 * setup.py (scriptfiles): renamed the data_files parameter from
2374 2381 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2375 2382 for the patch.
2376 2383
2377 2384 2003-03-20 Fernando Perez <fperez@colorado.edu>
2378 2385
2379 2386 * IPython/genutils.py (error): added error() and fatal()
2380 2387 functions.
2381 2388
2382 2389 2003-03-18 *** Released version 0.2.15pre3
2383 2390
2384 2391 2003-03-18 Fernando Perez <fperez@colorado.edu>
2385 2392
2386 2393 * setupext/install_data_ext.py
2387 2394 (install_data_ext.initialize_options): Class contributed by Jack
2388 2395 Moffit for fixing the old distutils hack. He is sending this to
2389 2396 the distutils folks so in the future we may not need it as a
2390 2397 private fix.
2391 2398
2392 2399 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2393 2400 changes for Debian packaging. See his patch for full details.
2394 2401 The old distutils hack of making the ipythonrc* files carry a
2395 2402 bogus .py extension is gone, at last. Examples were moved to a
2396 2403 separate subdir under doc/, and the separate executable scripts
2397 2404 now live in their own directory. Overall a great cleanup. The
2398 2405 manual was updated to use the new files, and setup.py has been
2399 2406 fixed for this setup.
2400 2407
2401 2408 * IPython/PyColorize.py (Parser.usage): made non-executable and
2402 2409 created a pycolor wrapper around it to be included as a script.
2403 2410
2404 2411 2003-03-12 *** Released version 0.2.15pre2
2405 2412
2406 2413 2003-03-12 Fernando Perez <fperez@colorado.edu>
2407 2414
2408 2415 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2409 2416 long-standing problem with garbage characters in some terminals.
2410 2417 The issue was really that the \001 and \002 escapes must _only_ be
2411 2418 passed to input prompts (which call readline), but _never_ to
2412 2419 normal text to be printed on screen. I changed ColorANSI to have
2413 2420 two classes: TermColors and InputTermColors, each with the
2414 2421 appropriate escapes for input prompts or normal text. The code in
2415 2422 Prompts.py got slightly more complicated, but this very old and
2416 2423 annoying bug is finally fixed.
2417 2424
2418 2425 All the credit for nailing down the real origin of this problem
2419 2426 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2420 2427 *Many* thanks to him for spending quite a bit of effort on this.
2421 2428
2422 2429 2003-03-05 *** Released version 0.2.15pre1
2423 2430
2424 2431 2003-03-03 Fernando Perez <fperez@colorado.edu>
2425 2432
2426 2433 * IPython/FakeModule.py: Moved the former _FakeModule to a
2427 2434 separate file, because it's also needed by Magic (to fix a similar
2428 2435 pickle-related issue in @run).
2429 2436
2430 2437 2003-03-02 Fernando Perez <fperez@colorado.edu>
2431 2438
2432 2439 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2433 2440 the autocall option at runtime.
2434 2441 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2435 2442 across Magic.py to start separating Magic from InteractiveShell.
2436 2443 (Magic._ofind): Fixed to return proper namespace for dotted
2437 2444 names. Before, a dotted name would always return 'not currently
2438 2445 defined', because it would find the 'parent'. s.x would be found,
2439 2446 but since 'x' isn't defined by itself, it would get confused.
2440 2447 (Magic.magic_run): Fixed pickling problems reported by Ralf
2441 2448 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2442 2449 that I'd used when Mike Heeter reported similar issues at the
2443 2450 top-level, but now for @run. It boils down to injecting the
2444 2451 namespace where code is being executed with something that looks
2445 2452 enough like a module to fool pickle.dump(). Since a pickle stores
2446 2453 a named reference to the importing module, we need this for
2447 2454 pickles to save something sensible.
2448 2455
2449 2456 * IPython/ipmaker.py (make_IPython): added an autocall option.
2450 2457
2451 2458 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2452 2459 the auto-eval code. Now autocalling is an option, and the code is
2453 2460 also vastly safer. There is no more eval() involved at all.
2454 2461
2455 2462 2003-03-01 Fernando Perez <fperez@colorado.edu>
2456 2463
2457 2464 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2458 2465 dict with named keys instead of a tuple.
2459 2466
2460 2467 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2461 2468
2462 2469 * setup.py (make_shortcut): Fixed message about directories
2463 2470 created during Windows installation (the directories were ok, just
2464 2471 the printed message was misleading). Thanks to Chris Liechti
2465 2472 <cliechti-AT-gmx.net> for the heads up.
2466 2473
2467 2474 2003-02-21 Fernando Perez <fperez@colorado.edu>
2468 2475
2469 2476 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2470 2477 of ValueError exception when checking for auto-execution. This
2471 2478 one is raised by things like Numeric arrays arr.flat when the
2472 2479 array is non-contiguous.
2473 2480
2474 2481 2003-01-31 Fernando Perez <fperez@colorado.edu>
2475 2482
2476 2483 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2477 2484 not return any value at all (even though the command would get
2478 2485 executed).
2479 2486 (xsys): Flush stdout right after printing the command to ensure
2480 2487 proper ordering of commands and command output in the total
2481 2488 output.
2482 2489 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2483 2490 system/getoutput as defaults. The old ones are kept for
2484 2491 compatibility reasons, so no code which uses this library needs
2485 2492 changing.
2486 2493
2487 2494 2003-01-27 *** Released version 0.2.14
2488 2495
2489 2496 2003-01-25 Fernando Perez <fperez@colorado.edu>
2490 2497
2491 2498 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2492 2499 functions defined in previous edit sessions could not be re-edited
2493 2500 (because the temp files were immediately removed). Now temp files
2494 2501 are removed only at IPython's exit.
2495 2502 (Magic.magic_run): Improved @run to perform shell-like expansions
2496 2503 on its arguments (~users and $VARS). With this, @run becomes more
2497 2504 like a normal command-line.
2498 2505
2499 2506 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2500 2507 bugs related to embedding and cleaned up that code. A fairly
2501 2508 important one was the impossibility to access the global namespace
2502 2509 through the embedded IPython (only local variables were visible).
2503 2510
2504 2511 2003-01-14 Fernando Perez <fperez@colorado.edu>
2505 2512
2506 2513 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2507 2514 auto-calling to be a bit more conservative. Now it doesn't get
2508 2515 triggered if any of '!=()<>' are in the rest of the input line, to
2509 2516 allow comparing callables. Thanks to Alex for the heads up.
2510 2517
2511 2518 2003-01-07 Fernando Perez <fperez@colorado.edu>
2512 2519
2513 2520 * IPython/genutils.py (page): fixed estimation of the number of
2514 2521 lines in a string to be paged to simply count newlines. This
2515 2522 prevents over-guessing due to embedded escape sequences. A better
2516 2523 long-term solution would involve stripping out the control chars
2517 2524 for the count, but it's potentially so expensive I just don't
2518 2525 think it's worth doing.
2519 2526
2520 2527 2002-12-19 *** Released version 0.2.14pre50
2521 2528
2522 2529 2002-12-19 Fernando Perez <fperez@colorado.edu>
2523 2530
2524 2531 * tools/release (version): Changed release scripts to inform
2525 2532 Andrea and build a NEWS file with a list of recent changes.
2526 2533
2527 2534 * IPython/ColorANSI.py (__all__): changed terminal detection
2528 2535 code. Seems to work better for xterms without breaking
2529 2536 konsole. Will need more testing to determine if WinXP and Mac OSX
2530 2537 also work ok.
2531 2538
2532 2539 2002-12-18 *** Released version 0.2.14pre49
2533 2540
2534 2541 2002-12-18 Fernando Perez <fperez@colorado.edu>
2535 2542
2536 2543 * Docs: added new info about Mac OSX, from Andrea.
2537 2544
2538 2545 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2539 2546 allow direct plotting of python strings whose format is the same
2540 2547 of gnuplot data files.
2541 2548
2542 2549 2002-12-16 Fernando Perez <fperez@colorado.edu>
2543 2550
2544 2551 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2545 2552 value of exit question to be acknowledged.
2546 2553
2547 2554 2002-12-03 Fernando Perez <fperez@colorado.edu>
2548 2555
2549 2556 * IPython/ipmaker.py: removed generators, which had been added
2550 2557 by mistake in an earlier debugging run. This was causing trouble
2551 2558 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2552 2559 for pointing this out.
2553 2560
2554 2561 2002-11-17 Fernando Perez <fperez@colorado.edu>
2555 2562
2556 2563 * Manual: updated the Gnuplot section.
2557 2564
2558 2565 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2559 2566 a much better split of what goes in Runtime and what goes in
2560 2567 Interactive.
2561 2568
2562 2569 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2563 2570 being imported from iplib.
2564 2571
2565 2572 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2566 2573 for command-passing. Now the global Gnuplot instance is called
2567 2574 'gp' instead of 'g', which was really a far too fragile and
2568 2575 common name.
2569 2576
2570 2577 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2571 2578 bounding boxes generated by Gnuplot for square plots.
2572 2579
2573 2580 * IPython/genutils.py (popkey): new function added. I should
2574 2581 suggest this on c.l.py as a dict method, it seems useful.
2575 2582
2576 2583 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2577 2584 to transparently handle PostScript generation. MUCH better than
2578 2585 the previous plot_eps/replot_eps (which I removed now). The code
2579 2586 is also fairly clean and well documented now (including
2580 2587 docstrings).
2581 2588
2582 2589 2002-11-13 Fernando Perez <fperez@colorado.edu>
2583 2590
2584 2591 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2585 2592 (inconsistent with options).
2586 2593
2587 2594 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2588 2595 manually disabled, I don't know why. Fixed it.
2589 2596 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2590 2597 eps output.
2591 2598
2592 2599 2002-11-12 Fernando Perez <fperez@colorado.edu>
2593 2600
2594 2601 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2595 2602 don't propagate up to caller. Fixes crash reported by François
2596 2603 Pinard.
2597 2604
2598 2605 2002-11-09 Fernando Perez <fperez@colorado.edu>
2599 2606
2600 2607 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2601 2608 history file for new users.
2602 2609 (make_IPython): fixed bug where initial install would leave the
2603 2610 user running in the .ipython dir.
2604 2611 (make_IPython): fixed bug where config dir .ipython would be
2605 2612 created regardless of the given -ipythondir option. Thanks to Cory
2606 2613 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2607 2614
2608 2615 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2609 2616 type confirmations. Will need to use it in all of IPython's code
2610 2617 consistently.
2611 2618
2612 2619 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2613 2620 context to print 31 lines instead of the default 5. This will make
2614 2621 the crash reports extremely detailed in case the problem is in
2615 2622 libraries I don't have access to.
2616 2623
2617 2624 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2618 2625 line of defense' code to still crash, but giving users fair
2619 2626 warning. I don't want internal errors to go unreported: if there's
2620 2627 an internal problem, IPython should crash and generate a full
2621 2628 report.
2622 2629
2623 2630 2002-11-08 Fernando Perez <fperez@colorado.edu>
2624 2631
2625 2632 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2626 2633 otherwise uncaught exceptions which can appear if people set
2627 2634 sys.stdout to something badly broken. Thanks to a crash report
2628 2635 from henni-AT-mail.brainbot.com.
2629 2636
2630 2637 2002-11-04 Fernando Perez <fperez@colorado.edu>
2631 2638
2632 2639 * IPython/iplib.py (InteractiveShell.interact): added
2633 2640 __IPYTHON__active to the builtins. It's a flag which goes on when
2634 2641 the interaction starts and goes off again when it stops. This
2635 2642 allows embedding code to detect being inside IPython. Before this
2636 2643 was done via __IPYTHON__, but that only shows that an IPython
2637 2644 instance has been created.
2638 2645
2639 2646 * IPython/Magic.py (Magic.magic_env): I realized that in a
2640 2647 UserDict, instance.data holds the data as a normal dict. So I
2641 2648 modified @env to return os.environ.data instead of rebuilding a
2642 2649 dict by hand.
2643 2650
2644 2651 2002-11-02 Fernando Perez <fperez@colorado.edu>
2645 2652
2646 2653 * IPython/genutils.py (warn): changed so that level 1 prints no
2647 2654 header. Level 2 is now the default (with 'WARNING' header, as
2648 2655 before). I think I tracked all places where changes were needed in
2649 2656 IPython, but outside code using the old level numbering may have
2650 2657 broken.
2651 2658
2652 2659 * IPython/iplib.py (InteractiveShell.runcode): added this to
2653 2660 handle the tracebacks in SystemExit traps correctly. The previous
2654 2661 code (through interact) was printing more of the stack than
2655 2662 necessary, showing IPython internal code to the user.
2656 2663
2657 2664 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2658 2665 default. Now that the default at the confirmation prompt is yes,
2659 2666 it's not so intrusive. François' argument that ipython sessions
2660 2667 tend to be complex enough not to lose them from an accidental C-d,
2661 2668 is a valid one.
2662 2669
2663 2670 * IPython/iplib.py (InteractiveShell.interact): added a
2664 2671 showtraceback() call to the SystemExit trap, and modified the exit
2665 2672 confirmation to have yes as the default.
2666 2673
2667 2674 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2668 2675 this file. It's been gone from the code for a long time, this was
2669 2676 simply leftover junk.
2670 2677
2671 2678 2002-11-01 Fernando Perez <fperez@colorado.edu>
2672 2679
2673 2680 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2674 2681 added. If set, IPython now traps EOF and asks for
2675 2682 confirmation. After a request by François Pinard.
2676 2683
2677 2684 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2678 2685 of @abort, and with a new (better) mechanism for handling the
2679 2686 exceptions.
2680 2687
2681 2688 2002-10-27 Fernando Perez <fperez@colorado.edu>
2682 2689
2683 2690 * IPython/usage.py (__doc__): updated the --help information and
2684 2691 the ipythonrc file to indicate that -log generates
2685 2692 ./ipython.log. Also fixed the corresponding info in @logstart.
2686 2693 This and several other fixes in the manuals thanks to reports by
2687 2694 François Pinard <pinard-AT-iro.umontreal.ca>.
2688 2695
2689 2696 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2690 2697 refer to @logstart (instead of @log, which doesn't exist).
2691 2698
2692 2699 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2693 2700 AttributeError crash. Thanks to Christopher Armstrong
2694 2701 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2695 2702 introduced recently (in 0.2.14pre37) with the fix to the eval
2696 2703 problem mentioned below.
2697 2704
2698 2705 2002-10-17 Fernando Perez <fperez@colorado.edu>
2699 2706
2700 2707 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2701 2708 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2702 2709
2703 2710 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2704 2711 this function to fix a problem reported by Alex Schmolck. He saw
2705 2712 it with list comprehensions and generators, which were getting
2706 2713 called twice. The real problem was an 'eval' call in testing for
2707 2714 automagic which was evaluating the input line silently.
2708 2715
2709 2716 This is a potentially very nasty bug, if the input has side
2710 2717 effects which must not be repeated. The code is much cleaner now,
2711 2718 without any blanket 'except' left and with a regexp test for
2712 2719 actual function names.
2713 2720
2714 2721 But an eval remains, which I'm not fully comfortable with. I just
2715 2722 don't know how to find out if an expression could be a callable in
2716 2723 the user's namespace without doing an eval on the string. However
2717 2724 that string is now much more strictly checked so that no code
2718 2725 slips by, so the eval should only happen for things that can
2719 2726 really be only function/method names.
2720 2727
2721 2728 2002-10-15 Fernando Perez <fperez@colorado.edu>
2722 2729
2723 2730 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2724 2731 OSX information to main manual, removed README_Mac_OSX file from
2725 2732 distribution. Also updated credits for recent additions.
2726 2733
2727 2734 2002-10-10 Fernando Perez <fperez@colorado.edu>
2728 2735
2729 2736 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2730 2737 terminal-related issues. Many thanks to Andrea Riciputi
2731 2738 <andrea.riciputi-AT-libero.it> for writing it.
2732 2739
2733 2740 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2734 2741 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2735 2742
2736 2743 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2737 2744 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2738 2745 <syver-en-AT-online.no> who both submitted patches for this problem.
2739 2746
2740 2747 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2741 2748 global embedding to make sure that things don't overwrite user
2742 2749 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2743 2750
2744 2751 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2745 2752 compatibility. Thanks to Hayden Callow
2746 2753 <h.callow-AT-elec.canterbury.ac.nz>
2747 2754
2748 2755 2002-10-04 Fernando Perez <fperez@colorado.edu>
2749 2756
2750 2757 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2751 2758 Gnuplot.File objects.
2752 2759
2753 2760 2002-07-23 Fernando Perez <fperez@colorado.edu>
2754 2761
2755 2762 * IPython/genutils.py (timing): Added timings() and timing() for
2756 2763 quick access to the most commonly needed data, the execution
2757 2764 times. Old timing() renamed to timings_out().
2758 2765
2759 2766 2002-07-18 Fernando Perez <fperez@colorado.edu>
2760 2767
2761 2768 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2762 2769 bug with nested instances disrupting the parent's tab completion.
2763 2770
2764 2771 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2765 2772 all_completions code to begin the emacs integration.
2766 2773
2767 2774 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2768 2775 argument to allow titling individual arrays when plotting.
2769 2776
2770 2777 2002-07-15 Fernando Perez <fperez@colorado.edu>
2771 2778
2772 2779 * setup.py (make_shortcut): changed to retrieve the value of
2773 2780 'Program Files' directory from the registry (this value changes in
2774 2781 non-english versions of Windows). Thanks to Thomas Fanslau
2775 2782 <tfanslau-AT-gmx.de> for the report.
2776 2783
2777 2784 2002-07-10 Fernando Perez <fperez@colorado.edu>
2778 2785
2779 2786 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2780 2787 a bug in pdb, which crashes if a line with only whitespace is
2781 2788 entered. Bug report submitted to sourceforge.
2782 2789
2783 2790 2002-07-09 Fernando Perez <fperez@colorado.edu>
2784 2791
2785 2792 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2786 2793 reporting exceptions (it's a bug in inspect.py, I just set a
2787 2794 workaround).
2788 2795
2789 2796 2002-07-08 Fernando Perez <fperez@colorado.edu>
2790 2797
2791 2798 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2792 2799 __IPYTHON__ in __builtins__ to show up in user_ns.
2793 2800
2794 2801 2002-07-03 Fernando Perez <fperez@colorado.edu>
2795 2802
2796 2803 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2797 2804 name from @gp_set_instance to @gp_set_default.
2798 2805
2799 2806 * IPython/ipmaker.py (make_IPython): default editor value set to
2800 2807 '0' (a string), to match the rc file. Otherwise will crash when
2801 2808 .strip() is called on it.
2802 2809
2803 2810
2804 2811 2002-06-28 Fernando Perez <fperez@colorado.edu>
2805 2812
2806 2813 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2807 2814 of files in current directory when a file is executed via
2808 2815 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2809 2816
2810 2817 * setup.py (manfiles): fix for rpm builds, submitted by RA
2811 2818 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2812 2819
2813 2820 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2814 2821 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2815 2822 string!). A. Schmolck caught this one.
2816 2823
2817 2824 2002-06-27 Fernando Perez <fperez@colorado.edu>
2818 2825
2819 2826 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2820 2827 defined files at the cmd line. __name__ wasn't being set to
2821 2828 __main__.
2822 2829
2823 2830 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2824 2831 regular lists and tuples besides Numeric arrays.
2825 2832
2826 2833 * IPython/Prompts.py (CachedOutput.__call__): Added output
2827 2834 supression for input ending with ';'. Similar to Mathematica and
2828 2835 Matlab. The _* vars and Out[] list are still updated, just like
2829 2836 Mathematica behaves.
2830 2837
2831 2838 2002-06-25 Fernando Perez <fperez@colorado.edu>
2832 2839
2833 2840 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2834 2841 .ini extensions for profiels under Windows.
2835 2842
2836 2843 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2837 2844 string form. Fix contributed by Alexander Schmolck
2838 2845 <a.schmolck-AT-gmx.net>
2839 2846
2840 2847 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2841 2848 pre-configured Gnuplot instance.
2842 2849
2843 2850 2002-06-21 Fernando Perez <fperez@colorado.edu>
2844 2851
2845 2852 * IPython/numutils.py (exp_safe): new function, works around the
2846 2853 underflow problems in Numeric.
2847 2854 (log2): New fn. Safe log in base 2: returns exact integer answer
2848 2855 for exact integer powers of 2.
2849 2856
2850 2857 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
2851 2858 properly.
2852 2859
2853 2860 2002-06-20 Fernando Perez <fperez@colorado.edu>
2854 2861
2855 2862 * IPython/genutils.py (timing): new function like
2856 2863 Mathematica's. Similar to time_test, but returns more info.
2857 2864
2858 2865 2002-06-18 Fernando Perez <fperez@colorado.edu>
2859 2866
2860 2867 * IPython/Magic.py (Magic.magic_save): modified @save and @r
2861 2868 according to Mike Heeter's suggestions.
2862 2869
2863 2870 2002-06-16 Fernando Perez <fperez@colorado.edu>
2864 2871
2865 2872 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
2866 2873 system. GnuplotMagic is gone as a user-directory option. New files
2867 2874 make it easier to use all the gnuplot stuff both from external
2868 2875 programs as well as from IPython. Had to rewrite part of
2869 2876 hardcopy() b/c of a strange bug: often the ps files simply don't
2870 2877 get created, and require a repeat of the command (often several
2871 2878 times).
2872 2879
2873 2880 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
2874 2881 resolve output channel at call time, so that if sys.stderr has
2875 2882 been redirected by user this gets honored.
2876 2883
2877 2884 2002-06-13 Fernando Perez <fperez@colorado.edu>
2878 2885
2879 2886 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
2880 2887 IPShell. Kept a copy with the old names to avoid breaking people's
2881 2888 embedded code.
2882 2889
2883 2890 * IPython/ipython: simplified it to the bare minimum after
2884 2891 Holger's suggestions. Added info about how to use it in
2885 2892 PYTHONSTARTUP.
2886 2893
2887 2894 * IPython/Shell.py (IPythonShell): changed the options passing
2888 2895 from a string with funky %s replacements to a straight list. Maybe
2889 2896 a bit more typing, but it follows sys.argv conventions, so there's
2890 2897 less special-casing to remember.
2891 2898
2892 2899 2002-06-12 Fernando Perez <fperez@colorado.edu>
2893 2900
2894 2901 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
2895 2902 command. Thanks to a suggestion by Mike Heeter.
2896 2903 (Magic.magic_pfile): added behavior to look at filenames if given
2897 2904 arg is not a defined object.
2898 2905 (Magic.magic_save): New @save function to save code snippets. Also
2899 2906 a Mike Heeter idea.
2900 2907
2901 2908 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
2902 2909 plot() and replot(). Much more convenient now, especially for
2903 2910 interactive use.
2904 2911
2905 2912 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
2906 2913 filenames.
2907 2914
2908 2915 2002-06-02 Fernando Perez <fperez@colorado.edu>
2909 2916
2910 2917 * IPython/Struct.py (Struct.__init__): modified to admit
2911 2918 initialization via another struct.
2912 2919
2913 2920 * IPython/genutils.py (SystemExec.__init__): New stateful
2914 2921 interface to xsys and bq. Useful for writing system scripts.
2915 2922
2916 2923 2002-05-30 Fernando Perez <fperez@colorado.edu>
2917 2924
2918 2925 * MANIFEST.in: Changed docfile selection to exclude all the lyx
2919 2926 documents. This will make the user download smaller (it's getting
2920 2927 too big).
2921 2928
2922 2929 2002-05-29 Fernando Perez <fperez@colorado.edu>
2923 2930
2924 2931 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
2925 2932 fix problems with shelve and pickle. Seems to work, but I don't
2926 2933 know if corner cases break it. Thanks to Mike Heeter
2927 2934 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
2928 2935
2929 2936 2002-05-24 Fernando Perez <fperez@colorado.edu>
2930 2937
2931 2938 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
2932 2939 macros having broken.
2933 2940
2934 2941 2002-05-21 Fernando Perez <fperez@colorado.edu>
2935 2942
2936 2943 * IPython/Magic.py (Magic.magic_logstart): fixed recently
2937 2944 introduced logging bug: all history before logging started was
2938 2945 being written one character per line! This came from the redesign
2939 2946 of the input history as a special list which slices to strings,
2940 2947 not to lists.
2941 2948
2942 2949 2002-05-20 Fernando Perez <fperez@colorado.edu>
2943 2950
2944 2951 * IPython/Prompts.py (CachedOutput.__init__): made the color table
2945 2952 be an attribute of all classes in this module. The design of these
2946 2953 classes needs some serious overhauling.
2947 2954
2948 2955 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
2949 2956 which was ignoring '_' in option names.
2950 2957
2951 2958 * IPython/ultraTB.py (FormattedTB.__init__): Changed
2952 2959 'Verbose_novars' to 'Context' and made it the new default. It's a
2953 2960 bit more readable and also safer than verbose.
2954 2961
2955 2962 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
2956 2963 triple-quoted strings.
2957 2964
2958 2965 * IPython/OInspect.py (__all__): new module exposing the object
2959 2966 introspection facilities. Now the corresponding magics are dummy
2960 2967 wrappers around this. Having this module will make it much easier
2961 2968 to put these functions into our modified pdb.
2962 2969 This new object inspector system uses the new colorizing module,
2963 2970 so source code and other things are nicely syntax highlighted.
2964 2971
2965 2972 2002-05-18 Fernando Perez <fperez@colorado.edu>
2966 2973
2967 2974 * IPython/ColorANSI.py: Split the coloring tools into a separate
2968 2975 module so I can use them in other code easier (they were part of
2969 2976 ultraTB).
2970 2977
2971 2978 2002-05-17 Fernando Perez <fperez@colorado.edu>
2972 2979
2973 2980 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2974 2981 fixed it to set the global 'g' also to the called instance, as
2975 2982 long as 'g' was still a gnuplot instance (so it doesn't overwrite
2976 2983 user's 'g' variables).
2977 2984
2978 2985 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
2979 2986 global variables (aliases to _ih,_oh) so that users which expect
2980 2987 In[5] or Out[7] to work aren't unpleasantly surprised.
2981 2988 (InputList.__getslice__): new class to allow executing slices of
2982 2989 input history directly. Very simple class, complements the use of
2983 2990 macros.
2984 2991
2985 2992 2002-05-16 Fernando Perez <fperez@colorado.edu>
2986 2993
2987 2994 * setup.py (docdirbase): make doc directory be just doc/IPython
2988 2995 without version numbers, it will reduce clutter for users.
2989 2996
2990 2997 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
2991 2998 execfile call to prevent possible memory leak. See for details:
2992 2999 http://mail.python.org/pipermail/python-list/2002-February/088476.html
2993 3000
2994 3001 2002-05-15 Fernando Perez <fperez@colorado.edu>
2995 3002
2996 3003 * IPython/Magic.py (Magic.magic_psource): made the object
2997 3004 introspection names be more standard: pdoc, pdef, pfile and
2998 3005 psource. They all print/page their output, and it makes
2999 3006 remembering them easier. Kept old names for compatibility as
3000 3007 aliases.
3001 3008
3002 3009 2002-05-14 Fernando Perez <fperez@colorado.edu>
3003 3010
3004 3011 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
3005 3012 what the mouse problem was. The trick is to use gnuplot with temp
3006 3013 files and NOT with pipes (for data communication), because having
3007 3014 both pipes and the mouse on is bad news.
3008 3015
3009 3016 2002-05-13 Fernando Perez <fperez@colorado.edu>
3010 3017
3011 3018 * IPython/Magic.py (Magic._ofind): fixed namespace order search
3012 3019 bug. Information would be reported about builtins even when
3013 3020 user-defined functions overrode them.
3014 3021
3015 3022 2002-05-11 Fernando Perez <fperez@colorado.edu>
3016 3023
3017 3024 * IPython/__init__.py (__all__): removed FlexCompleter from
3018 3025 __all__ so that things don't fail in platforms without readline.
3019 3026
3020 3027 2002-05-10 Fernando Perez <fperez@colorado.edu>
3021 3028
3022 3029 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
3023 3030 it requires Numeric, effectively making Numeric a dependency for
3024 3031 IPython.
3025 3032
3026 3033 * Released 0.2.13
3027 3034
3028 3035 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
3029 3036 profiler interface. Now all the major options from the profiler
3030 3037 module are directly supported in IPython, both for single
3031 3038 expressions (@prun) and for full programs (@run -p).
3032 3039
3033 3040 2002-05-09 Fernando Perez <fperez@colorado.edu>
3034 3041
3035 3042 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
3036 3043 magic properly formatted for screen.
3037 3044
3038 3045 * setup.py (make_shortcut): Changed things to put pdf version in
3039 3046 doc/ instead of doc/manual (had to change lyxport a bit).
3040 3047
3041 3048 * IPython/Magic.py (Profile.string_stats): made profile runs go
3042 3049 through pager (they are long and a pager allows searching, saving,
3043 3050 etc.)
3044 3051
3045 3052 2002-05-08 Fernando Perez <fperez@colorado.edu>
3046 3053
3047 3054 * Released 0.2.12
3048 3055
3049 3056 2002-05-06 Fernando Perez <fperez@colorado.edu>
3050 3057
3051 3058 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
3052 3059 introduced); 'hist n1 n2' was broken.
3053 3060 (Magic.magic_pdb): added optional on/off arguments to @pdb
3054 3061 (Magic.magic_run): added option -i to @run, which executes code in
3055 3062 the IPython namespace instead of a clean one. Also added @irun as
3056 3063 an alias to @run -i.
3057 3064
3058 3065 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3059 3066 fixed (it didn't really do anything, the namespaces were wrong).
3060 3067
3061 3068 * IPython/Debugger.py (__init__): Added workaround for python 2.1
3062 3069
3063 3070 * IPython/__init__.py (__all__): Fixed package namespace, now
3064 3071 'import IPython' does give access to IPython.<all> as
3065 3072 expected. Also renamed __release__ to Release.
3066 3073
3067 3074 * IPython/Debugger.py (__license__): created new Pdb class which
3068 3075 functions like a drop-in for the normal pdb.Pdb but does NOT
3069 3076 import readline by default. This way it doesn't muck up IPython's
3070 3077 readline handling, and now tab-completion finally works in the
3071 3078 debugger -- sort of. It completes things globally visible, but the
3072 3079 completer doesn't track the stack as pdb walks it. That's a bit
3073 3080 tricky, and I'll have to implement it later.
3074 3081
3075 3082 2002-05-05 Fernando Perez <fperez@colorado.edu>
3076 3083
3077 3084 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
3078 3085 magic docstrings when printed via ? (explicit \'s were being
3079 3086 printed).
3080 3087
3081 3088 * IPython/ipmaker.py (make_IPython): fixed namespace
3082 3089 identification bug. Now variables loaded via logs or command-line
3083 3090 files are recognized in the interactive namespace by @who.
3084 3091
3085 3092 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
3086 3093 log replay system stemming from the string form of Structs.
3087 3094
3088 3095 * IPython/Magic.py (Macro.__init__): improved macros to properly
3089 3096 handle magic commands in them.
3090 3097 (Magic.magic_logstart): usernames are now expanded so 'logstart
3091 3098 ~/mylog' now works.
3092 3099
3093 3100 * IPython/iplib.py (complete): fixed bug where paths starting with
3094 3101 '/' would be completed as magic names.
3095 3102
3096 3103 2002-05-04 Fernando Perez <fperez@colorado.edu>
3097 3104
3098 3105 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
3099 3106 allow running full programs under the profiler's control.
3100 3107
3101 3108 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
3102 3109 mode to report exceptions verbosely but without formatting
3103 3110 variables. This addresses the issue of ipython 'freezing' (it's
3104 3111 not frozen, but caught in an expensive formatting loop) when huge
3105 3112 variables are in the context of an exception.
3106 3113 (VerboseTB.text): Added '--->' markers at line where exception was
3107 3114 triggered. Much clearer to read, especially in NoColor modes.
3108 3115
3109 3116 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
3110 3117 implemented in reverse when changing to the new parse_options().
3111 3118
3112 3119 2002-05-03 Fernando Perez <fperez@colorado.edu>
3113 3120
3114 3121 * IPython/Magic.py (Magic.parse_options): new function so that
3115 3122 magics can parse options easier.
3116 3123 (Magic.magic_prun): new function similar to profile.run(),
3117 3124 suggested by Chris Hart.
3118 3125 (Magic.magic_cd): fixed behavior so that it only changes if
3119 3126 directory actually is in history.
3120 3127
3121 3128 * IPython/usage.py (__doc__): added information about potential
3122 3129 slowness of Verbose exception mode when there are huge data
3123 3130 structures to be formatted (thanks to Archie Paulson).
3124 3131
3125 3132 * IPython/ipmaker.py (make_IPython): Changed default logging
3126 3133 (when simply called with -log) to use curr_dir/ipython.log in
3127 3134 rotate mode. Fixed crash which was occuring with -log before
3128 3135 (thanks to Jim Boyle).
3129 3136
3130 3137 2002-05-01 Fernando Perez <fperez@colorado.edu>
3131 3138
3132 3139 * Released 0.2.11 for these fixes (mainly the ultraTB one which
3133 3140 was nasty -- though somewhat of a corner case).
3134 3141
3135 3142 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
3136 3143 text (was a bug).
3137 3144
3138 3145 2002-04-30 Fernando Perez <fperez@colorado.edu>
3139 3146
3140 3147 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
3141 3148 a print after ^D or ^C from the user so that the In[] prompt
3142 3149 doesn't over-run the gnuplot one.
3143 3150
3144 3151 2002-04-29 Fernando Perez <fperez@colorado.edu>
3145 3152
3146 3153 * Released 0.2.10
3147 3154
3148 3155 * IPython/__release__.py (version): get date dynamically.
3149 3156
3150 3157 * Misc. documentation updates thanks to Arnd's comments. Also ran
3151 3158 a full spellcheck on the manual (hadn't been done in a while).
3152 3159
3153 3160 2002-04-27 Fernando Perez <fperez@colorado.edu>
3154 3161
3155 3162 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
3156 3163 starting a log in mid-session would reset the input history list.
3157 3164
3158 3165 2002-04-26 Fernando Perez <fperez@colorado.edu>
3159 3166
3160 3167 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
3161 3168 all files were being included in an update. Now anything in
3162 3169 UserConfig that matches [A-Za-z]*.py will go (this excludes
3163 3170 __init__.py)
3164 3171
3165 3172 2002-04-25 Fernando Perez <fperez@colorado.edu>
3166 3173
3167 3174 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
3168 3175 to __builtins__ so that any form of embedded or imported code can
3169 3176 test for being inside IPython.
3170 3177
3171 3178 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3172 3179 changed to GnuplotMagic because it's now an importable module,
3173 3180 this makes the name follow that of the standard Gnuplot module.
3174 3181 GnuplotMagic can now be loaded at any time in mid-session.
3175 3182
3176 3183 2002-04-24 Fernando Perez <fperez@colorado.edu>
3177 3184
3178 3185 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3179 3186 the globals (IPython has its own namespace) and the
3180 3187 PhysicalQuantity stuff is much better anyway.
3181 3188
3182 3189 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3183 3190 embedding example to standard user directory for
3184 3191 distribution. Also put it in the manual.
3185 3192
3186 3193 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3187 3194 instance as first argument (so it doesn't rely on some obscure
3188 3195 hidden global).
3189 3196
3190 3197 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3191 3198 delimiters. While it prevents ().TAB from working, it allows
3192 3199 completions in open (... expressions. This is by far a more common
3193 3200 case.
3194 3201
3195 3202 2002-04-23 Fernando Perez <fperez@colorado.edu>
3196 3203
3197 3204 * IPython/Extensions/InterpreterPasteInput.py: new
3198 3205 syntax-processing module for pasting lines with >>> or ... at the
3199 3206 start.
3200 3207
3201 3208 * IPython/Extensions/PhysicalQ_Interactive.py
3202 3209 (PhysicalQuantityInteractive.__int__): fixed to work with either
3203 3210 Numeric or math.
3204 3211
3205 3212 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3206 3213 provided profiles. Now we have:
3207 3214 -math -> math module as * and cmath with its own namespace.
3208 3215 -numeric -> Numeric as *, plus gnuplot & grace
3209 3216 -physics -> same as before
3210 3217
3211 3218 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3212 3219 user-defined magics wouldn't be found by @magic if they were
3213 3220 defined as class methods. Also cleaned up the namespace search
3214 3221 logic and the string building (to use %s instead of many repeated
3215 3222 string adds).
3216 3223
3217 3224 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3218 3225 of user-defined magics to operate with class methods (cleaner, in
3219 3226 line with the gnuplot code).
3220 3227
3221 3228 2002-04-22 Fernando Perez <fperez@colorado.edu>
3222 3229
3223 3230 * setup.py: updated dependency list so that manual is updated when
3224 3231 all included files change.
3225 3232
3226 3233 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3227 3234 the delimiter removal option (the fix is ugly right now).
3228 3235
3229 3236 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3230 3237 all of the math profile (quicker loading, no conflict between
3231 3238 g-9.8 and g-gnuplot).
3232 3239
3233 3240 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3234 3241 name of post-mortem files to IPython_crash_report.txt.
3235 3242
3236 3243 * Cleanup/update of the docs. Added all the new readline info and
3237 3244 formatted all lists as 'real lists'.
3238 3245
3239 3246 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3240 3247 tab-completion options, since the full readline parse_and_bind is
3241 3248 now accessible.
3242 3249
3243 3250 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3244 3251 handling of readline options. Now users can specify any string to
3245 3252 be passed to parse_and_bind(), as well as the delimiters to be
3246 3253 removed.
3247 3254 (InteractiveShell.__init__): Added __name__ to the global
3248 3255 namespace so that things like Itpl which rely on its existence
3249 3256 don't crash.
3250 3257 (InteractiveShell._prefilter): Defined the default with a _ so
3251 3258 that prefilter() is easier to override, while the default one
3252 3259 remains available.
3253 3260
3254 3261 2002-04-18 Fernando Perez <fperez@colorado.edu>
3255 3262
3256 3263 * Added information about pdb in the docs.
3257 3264
3258 3265 2002-04-17 Fernando Perez <fperez@colorado.edu>
3259 3266
3260 3267 * IPython/ipmaker.py (make_IPython): added rc_override option to
3261 3268 allow passing config options at creation time which may override
3262 3269 anything set in the config files or command line. This is
3263 3270 particularly useful for configuring embedded instances.
3264 3271
3265 3272 2002-04-15 Fernando Perez <fperez@colorado.edu>
3266 3273
3267 3274 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3268 3275 crash embedded instances because of the input cache falling out of
3269 3276 sync with the output counter.
3270 3277
3271 3278 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3272 3279 mode which calls pdb after an uncaught exception in IPython itself.
3273 3280
3274 3281 2002-04-14 Fernando Perez <fperez@colorado.edu>
3275 3282
3276 3283 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3277 3284 readline, fix it back after each call.
3278 3285
3279 3286 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3280 3287 method to force all access via __call__(), which guarantees that
3281 3288 traceback references are properly deleted.
3282 3289
3283 3290 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3284 3291 improve printing when pprint is in use.
3285 3292
3286 3293 2002-04-13 Fernando Perez <fperez@colorado.edu>
3287 3294
3288 3295 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3289 3296 exceptions aren't caught anymore. If the user triggers one, he
3290 3297 should know why he's doing it and it should go all the way up,
3291 3298 just like any other exception. So now @abort will fully kill the
3292 3299 embedded interpreter and the embedding code (unless that happens
3293 3300 to catch SystemExit).
3294 3301
3295 3302 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3296 3303 and a debugger() method to invoke the interactive pdb debugger
3297 3304 after printing exception information. Also added the corresponding
3298 3305 -pdb option and @pdb magic to control this feature, and updated
3299 3306 the docs. After a suggestion from Christopher Hart
3300 3307 (hart-AT-caltech.edu).
3301 3308
3302 3309 2002-04-12 Fernando Perez <fperez@colorado.edu>
3303 3310
3304 3311 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3305 3312 the exception handlers defined by the user (not the CrashHandler)
3306 3313 so that user exceptions don't trigger an ipython bug report.
3307 3314
3308 3315 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3309 3316 configurable (it should have always been so).
3310 3317
3311 3318 2002-03-26 Fernando Perez <fperez@colorado.edu>
3312 3319
3313 3320 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3314 3321 and there to fix embedding namespace issues. This should all be
3315 3322 done in a more elegant way.
3316 3323
3317 3324 2002-03-25 Fernando Perez <fperez@colorado.edu>
3318 3325
3319 3326 * IPython/genutils.py (get_home_dir): Try to make it work under
3320 3327 win9x also.
3321 3328
3322 3329 2002-03-20 Fernando Perez <fperez@colorado.edu>
3323 3330
3324 3331 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3325 3332 sys.displayhook untouched upon __init__.
3326 3333
3327 3334 2002-03-19 Fernando Perez <fperez@colorado.edu>
3328 3335
3329 3336 * Released 0.2.9 (for embedding bug, basically).
3330 3337
3331 3338 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3332 3339 exceptions so that enclosing shell's state can be restored.
3333 3340
3334 3341 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3335 3342 naming conventions in the .ipython/ dir.
3336 3343
3337 3344 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3338 3345 from delimiters list so filenames with - in them get expanded.
3339 3346
3340 3347 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3341 3348 sys.displayhook not being properly restored after an embedded call.
3342 3349
3343 3350 2002-03-18 Fernando Perez <fperez@colorado.edu>
3344 3351
3345 3352 * Released 0.2.8
3346 3353
3347 3354 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3348 3355 some files weren't being included in a -upgrade.
3349 3356 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3350 3357 on' so that the first tab completes.
3351 3358 (InteractiveShell.handle_magic): fixed bug with spaces around
3352 3359 quotes breaking many magic commands.
3353 3360
3354 3361 * setup.py: added note about ignoring the syntax error messages at
3355 3362 installation.
3356 3363
3357 3364 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3358 3365 streamlining the gnuplot interface, now there's only one magic @gp.
3359 3366
3360 3367 2002-03-17 Fernando Perez <fperez@colorado.edu>
3361 3368
3362 3369 * IPython/UserConfig/magic_gnuplot.py: new name for the
3363 3370 example-magic_pm.py file. Much enhanced system, now with a shell
3364 3371 for communicating directly with gnuplot, one command at a time.
3365 3372
3366 3373 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3367 3374 setting __name__=='__main__'.
3368 3375
3369 3376 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3370 3377 mini-shell for accessing gnuplot from inside ipython. Should
3371 3378 extend it later for grace access too. Inspired by Arnd's
3372 3379 suggestion.
3373 3380
3374 3381 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3375 3382 calling magic functions with () in their arguments. Thanks to Arnd
3376 3383 Baecker for pointing this to me.
3377 3384
3378 3385 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3379 3386 infinitely for integer or complex arrays (only worked with floats).
3380 3387
3381 3388 2002-03-16 Fernando Perez <fperez@colorado.edu>
3382 3389
3383 3390 * setup.py: Merged setup and setup_windows into a single script
3384 3391 which properly handles things for windows users.
3385 3392
3386 3393 2002-03-15 Fernando Perez <fperez@colorado.edu>
3387 3394
3388 3395 * Big change to the manual: now the magics are all automatically
3389 3396 documented. This information is generated from their docstrings
3390 3397 and put in a latex file included by the manual lyx file. This way
3391 3398 we get always up to date information for the magics. The manual
3392 3399 now also has proper version information, also auto-synced.
3393 3400
3394 3401 For this to work, an undocumented --magic_docstrings option was added.
3395 3402
3396 3403 2002-03-13 Fernando Perez <fperez@colorado.edu>
3397 3404
3398 3405 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3399 3406 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3400 3407
3401 3408 2002-03-12 Fernando Perez <fperez@colorado.edu>
3402 3409
3403 3410 * IPython/ultraTB.py (TermColors): changed color escapes again to
3404 3411 fix the (old, reintroduced) line-wrapping bug. Basically, if
3405 3412 \001..\002 aren't given in the color escapes, lines get wrapped
3406 3413 weirdly. But giving those screws up old xterms and emacs terms. So
3407 3414 I added some logic for emacs terms to be ok, but I can't identify old
3408 3415 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3409 3416
3410 3417 2002-03-10 Fernando Perez <fperez@colorado.edu>
3411 3418
3412 3419 * IPython/usage.py (__doc__): Various documentation cleanups and
3413 3420 updates, both in usage docstrings and in the manual.
3414 3421
3415 3422 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3416 3423 handling of caching. Set minimum acceptabe value for having a
3417 3424 cache at 20 values.
3418 3425
3419 3426 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3420 3427 install_first_time function to a method, renamed it and added an
3421 3428 'upgrade' mode. Now people can update their config directory with
3422 3429 a simple command line switch (-upgrade, also new).
3423 3430
3424 3431 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3425 3432 @file (convenient for automagic users under Python >= 2.2).
3426 3433 Removed @files (it seemed more like a plural than an abbrev. of
3427 3434 'file show').
3428 3435
3429 3436 * IPython/iplib.py (install_first_time): Fixed crash if there were
3430 3437 backup files ('~') in .ipython/ install directory.
3431 3438
3432 3439 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3433 3440 system. Things look fine, but these changes are fairly
3434 3441 intrusive. Test them for a few days.
3435 3442
3436 3443 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3437 3444 the prompts system. Now all in/out prompt strings are user
3438 3445 controllable. This is particularly useful for embedding, as one
3439 3446 can tag embedded instances with particular prompts.
3440 3447
3441 3448 Also removed global use of sys.ps1/2, which now allows nested
3442 3449 embeddings without any problems. Added command-line options for
3443 3450 the prompt strings.
3444 3451
3445 3452 2002-03-08 Fernando Perez <fperez@colorado.edu>
3446 3453
3447 3454 * IPython/UserConfig/example-embed-short.py (ipshell): added
3448 3455 example file with the bare minimum code for embedding.
3449 3456
3450 3457 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3451 3458 functionality for the embeddable shell to be activated/deactivated
3452 3459 either globally or at each call.
3453 3460
3454 3461 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3455 3462 rewriting the prompt with '--->' for auto-inputs with proper
3456 3463 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3457 3464 this is handled by the prompts class itself, as it should.
3458 3465
3459 3466 2002-03-05 Fernando Perez <fperez@colorado.edu>
3460 3467
3461 3468 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3462 3469 @logstart to avoid name clashes with the math log function.
3463 3470
3464 3471 * Big updates to X/Emacs section of the manual.
3465 3472
3466 3473 * Removed ipython_emacs. Milan explained to me how to pass
3467 3474 arguments to ipython through Emacs. Some day I'm going to end up
3468 3475 learning some lisp...
3469 3476
3470 3477 2002-03-04 Fernando Perez <fperez@colorado.edu>
3471 3478
3472 3479 * IPython/ipython_emacs: Created script to be used as the
3473 3480 py-python-command Emacs variable so we can pass IPython
3474 3481 parameters. I can't figure out how to tell Emacs directly to pass
3475 3482 parameters to IPython, so a dummy shell script will do it.
3476 3483
3477 3484 Other enhancements made for things to work better under Emacs'
3478 3485 various types of terminals. Many thanks to Milan Zamazal
3479 3486 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3480 3487
3481 3488 2002-03-01 Fernando Perez <fperez@colorado.edu>
3482 3489
3483 3490 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3484 3491 that loading of readline is now optional. This gives better
3485 3492 control to emacs users.
3486 3493
3487 3494 * IPython/ultraTB.py (__date__): Modified color escape sequences
3488 3495 and now things work fine under xterm and in Emacs' term buffers
3489 3496 (though not shell ones). Well, in emacs you get colors, but all
3490 3497 seem to be 'light' colors (no difference between dark and light
3491 3498 ones). But the garbage chars are gone, and also in xterms. It
3492 3499 seems that now I'm using 'cleaner' ansi sequences.
3493 3500
3494 3501 2002-02-21 Fernando Perez <fperez@colorado.edu>
3495 3502
3496 3503 * Released 0.2.7 (mainly to publish the scoping fix).
3497 3504
3498 3505 * IPython/Logger.py (Logger.logstate): added. A corresponding
3499 3506 @logstate magic was created.
3500 3507
3501 3508 * IPython/Magic.py: fixed nested scoping problem under Python
3502 3509 2.1.x (automagic wasn't working).
3503 3510
3504 3511 2002-02-20 Fernando Perez <fperez@colorado.edu>
3505 3512
3506 3513 * Released 0.2.6.
3507 3514
3508 3515 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3509 3516 option so that logs can come out without any headers at all.
3510 3517
3511 3518 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3512 3519 SciPy.
3513 3520
3514 3521 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3515 3522 that embedded IPython calls don't require vars() to be explicitly
3516 3523 passed. Now they are extracted from the caller's frame (code
3517 3524 snatched from Eric Jones' weave). Added better documentation to
3518 3525 the section on embedding and the example file.
3519 3526
3520 3527 * IPython/genutils.py (page): Changed so that under emacs, it just
3521 3528 prints the string. You can then page up and down in the emacs
3522 3529 buffer itself. This is how the builtin help() works.
3523 3530
3524 3531 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3525 3532 macro scoping: macros need to be executed in the user's namespace
3526 3533 to work as if they had been typed by the user.
3527 3534
3528 3535 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3529 3536 execute automatically (no need to type 'exec...'). They then
3530 3537 behave like 'true macros'. The printing system was also modified
3531 3538 for this to work.
3532 3539
3533 3540 2002-02-19 Fernando Perez <fperez@colorado.edu>
3534 3541
3535 3542 * IPython/genutils.py (page_file): new function for paging files
3536 3543 in an OS-independent way. Also necessary for file viewing to work
3537 3544 well inside Emacs buffers.
3538 3545 (page): Added checks for being in an emacs buffer.
3539 3546 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3540 3547 same bug in iplib.
3541 3548
3542 3549 2002-02-18 Fernando Perez <fperez@colorado.edu>
3543 3550
3544 3551 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3545 3552 of readline so that IPython can work inside an Emacs buffer.
3546 3553
3547 3554 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3548 3555 method signatures (they weren't really bugs, but it looks cleaner
3549 3556 and keeps PyChecker happy).
3550 3557
3551 3558 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3552 3559 for implementing various user-defined hooks. Currently only
3553 3560 display is done.
3554 3561
3555 3562 * IPython/Prompts.py (CachedOutput._display): changed display
3556 3563 functions so that they can be dynamically changed by users easily.
3557 3564
3558 3565 * IPython/Extensions/numeric_formats.py (num_display): added an
3559 3566 extension for printing NumPy arrays in flexible manners. It
3560 3567 doesn't do anything yet, but all the structure is in
3561 3568 place. Ultimately the plan is to implement output format control
3562 3569 like in Octave.
3563 3570
3564 3571 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3565 3572 methods are found at run-time by all the automatic machinery.
3566 3573
3567 3574 2002-02-17 Fernando Perez <fperez@colorado.edu>
3568 3575
3569 3576 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3570 3577 whole file a little.
3571 3578
3572 3579 * ToDo: closed this document. Now there's a new_design.lyx
3573 3580 document for all new ideas. Added making a pdf of it for the
3574 3581 end-user distro.
3575 3582
3576 3583 * IPython/Logger.py (Logger.switch_log): Created this to replace
3577 3584 logon() and logoff(). It also fixes a nasty crash reported by
3578 3585 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3579 3586
3580 3587 * IPython/iplib.py (complete): got auto-completion to work with
3581 3588 automagic (I had wanted this for a long time).
3582 3589
3583 3590 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3584 3591 to @file, since file() is now a builtin and clashes with automagic
3585 3592 for @file.
3586 3593
3587 3594 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3588 3595 of this was previously in iplib, which had grown to more than 2000
3589 3596 lines, way too long. No new functionality, but it makes managing
3590 3597 the code a bit easier.
3591 3598
3592 3599 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3593 3600 information to crash reports.
3594 3601
3595 3602 2002-02-12 Fernando Perez <fperez@colorado.edu>
3596 3603
3597 3604 * Released 0.2.5.
3598 3605
3599 3606 2002-02-11 Fernando Perez <fperez@colorado.edu>
3600 3607
3601 3608 * Wrote a relatively complete Windows installer. It puts
3602 3609 everything in place, creates Start Menu entries and fixes the
3603 3610 color issues. Nothing fancy, but it works.
3604 3611
3605 3612 2002-02-10 Fernando Perez <fperez@colorado.edu>
3606 3613
3607 3614 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3608 3615 os.path.expanduser() call so that we can type @run ~/myfile.py and
3609 3616 have thigs work as expected.
3610 3617
3611 3618 * IPython/genutils.py (page): fixed exception handling so things
3612 3619 work both in Unix and Windows correctly. Quitting a pager triggers
3613 3620 an IOError/broken pipe in Unix, and in windows not finding a pager
3614 3621 is also an IOError, so I had to actually look at the return value
3615 3622 of the exception, not just the exception itself. Should be ok now.
3616 3623
3617 3624 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3618 3625 modified to allow case-insensitive color scheme changes.
3619 3626
3620 3627 2002-02-09 Fernando Perez <fperez@colorado.edu>
3621 3628
3622 3629 * IPython/genutils.py (native_line_ends): new function to leave
3623 3630 user config files with os-native line-endings.
3624 3631
3625 3632 * README and manual updates.
3626 3633
3627 3634 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3628 3635 instead of StringType to catch Unicode strings.
3629 3636
3630 3637 * IPython/genutils.py (filefind): fixed bug for paths with
3631 3638 embedded spaces (very common in Windows).
3632 3639
3633 3640 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3634 3641 files under Windows, so that they get automatically associated
3635 3642 with a text editor. Windows makes it a pain to handle
3636 3643 extension-less files.
3637 3644
3638 3645 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3639 3646 warning about readline only occur for Posix. In Windows there's no
3640 3647 way to get readline, so why bother with the warning.
3641 3648
3642 3649 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3643 3650 for __str__ instead of dir(self), since dir() changed in 2.2.
3644 3651
3645 3652 * Ported to Windows! Tested on XP, I suspect it should work fine
3646 3653 on NT/2000, but I don't think it will work on 98 et al. That
3647 3654 series of Windows is such a piece of junk anyway that I won't try
3648 3655 porting it there. The XP port was straightforward, showed a few
3649 3656 bugs here and there (fixed all), in particular some string
3650 3657 handling stuff which required considering Unicode strings (which
3651 3658 Windows uses). This is good, but hasn't been too tested :) No
3652 3659 fancy installer yet, I'll put a note in the manual so people at
3653 3660 least make manually a shortcut.
3654 3661
3655 3662 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3656 3663 into a single one, "colors". This now controls both prompt and
3657 3664 exception color schemes, and can be changed both at startup
3658 3665 (either via command-line switches or via ipythonrc files) and at
3659 3666 runtime, with @colors.
3660 3667 (Magic.magic_run): renamed @prun to @run and removed the old
3661 3668 @run. The two were too similar to warrant keeping both.
3662 3669
3663 3670 2002-02-03 Fernando Perez <fperez@colorado.edu>
3664 3671
3665 3672 * IPython/iplib.py (install_first_time): Added comment on how to
3666 3673 configure the color options for first-time users. Put a <return>
3667 3674 request at the end so that small-terminal users get a chance to
3668 3675 read the startup info.
3669 3676
3670 3677 2002-01-23 Fernando Perez <fperez@colorado.edu>
3671 3678
3672 3679 * IPython/iplib.py (CachedOutput.update): Changed output memory
3673 3680 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3674 3681 input history we still use _i. Did this b/c these variable are
3675 3682 very commonly used in interactive work, so the less we need to
3676 3683 type the better off we are.
3677 3684 (Magic.magic_prun): updated @prun to better handle the namespaces
3678 3685 the file will run in, including a fix for __name__ not being set
3679 3686 before.
3680 3687
3681 3688 2002-01-20 Fernando Perez <fperez@colorado.edu>
3682 3689
3683 3690 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3684 3691 extra garbage for Python 2.2. Need to look more carefully into
3685 3692 this later.
3686 3693
3687 3694 2002-01-19 Fernando Perez <fperez@colorado.edu>
3688 3695
3689 3696 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3690 3697 display SyntaxError exceptions properly formatted when they occur
3691 3698 (they can be triggered by imported code).
3692 3699
3693 3700 2002-01-18 Fernando Perez <fperez@colorado.edu>
3694 3701
3695 3702 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3696 3703 SyntaxError exceptions are reported nicely formatted, instead of
3697 3704 spitting out only offset information as before.
3698 3705 (Magic.magic_prun): Added the @prun function for executing
3699 3706 programs with command line args inside IPython.
3700 3707
3701 3708 2002-01-16 Fernando Perez <fperez@colorado.edu>
3702 3709
3703 3710 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3704 3711 to *not* include the last item given in a range. This brings their
3705 3712 behavior in line with Python's slicing:
3706 3713 a[n1:n2] -> a[n1]...a[n2-1]
3707 3714 It may be a bit less convenient, but I prefer to stick to Python's
3708 3715 conventions *everywhere*, so users never have to wonder.
3709 3716 (Magic.magic_macro): Added @macro function to ease the creation of
3710 3717 macros.
3711 3718
3712 3719 2002-01-05 Fernando Perez <fperez@colorado.edu>
3713 3720
3714 3721 * Released 0.2.4.
3715 3722
3716 3723 * IPython/iplib.py (Magic.magic_pdef):
3717 3724 (InteractiveShell.safe_execfile): report magic lines and error
3718 3725 lines without line numbers so one can easily copy/paste them for
3719 3726 re-execution.
3720 3727
3721 3728 * Updated manual with recent changes.
3722 3729
3723 3730 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3724 3731 docstring printing when class? is called. Very handy for knowing
3725 3732 how to create class instances (as long as __init__ is well
3726 3733 documented, of course :)
3727 3734 (Magic.magic_doc): print both class and constructor docstrings.
3728 3735 (Magic.magic_pdef): give constructor info if passed a class and
3729 3736 __call__ info for callable object instances.
3730 3737
3731 3738 2002-01-04 Fernando Perez <fperez@colorado.edu>
3732 3739
3733 3740 * Made deep_reload() off by default. It doesn't always work
3734 3741 exactly as intended, so it's probably safer to have it off. It's
3735 3742 still available as dreload() anyway, so nothing is lost.
3736 3743
3737 3744 2002-01-02 Fernando Perez <fperez@colorado.edu>
3738 3745
3739 3746 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3740 3747 so I wanted an updated release).
3741 3748
3742 3749 2001-12-27 Fernando Perez <fperez@colorado.edu>
3743 3750
3744 3751 * IPython/iplib.py (InteractiveShell.interact): Added the original
3745 3752 code from 'code.py' for this module in order to change the
3746 3753 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3747 3754 the history cache would break when the user hit Ctrl-C, and
3748 3755 interact() offers no way to add any hooks to it.
3749 3756
3750 3757 2001-12-23 Fernando Perez <fperez@colorado.edu>
3751 3758
3752 3759 * setup.py: added check for 'MANIFEST' before trying to remove
3753 3760 it. Thanks to Sean Reifschneider.
3754 3761
3755 3762 2001-12-22 Fernando Perez <fperez@colorado.edu>
3756 3763
3757 3764 * Released 0.2.2.
3758 3765
3759 3766 * Finished (reasonably) writing the manual. Later will add the
3760 3767 python-standard navigation stylesheets, but for the time being
3761 3768 it's fairly complete. Distribution will include html and pdf
3762 3769 versions.
3763 3770
3764 3771 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3765 3772 (MayaVi author).
3766 3773
3767 3774 2001-12-21 Fernando Perez <fperez@colorado.edu>
3768 3775
3769 3776 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3770 3777 good public release, I think (with the manual and the distutils
3771 3778 installer). The manual can use some work, but that can go
3772 3779 slowly. Otherwise I think it's quite nice for end users. Next
3773 3780 summer, rewrite the guts of it...
3774 3781
3775 3782 * Changed format of ipythonrc files to use whitespace as the
3776 3783 separator instead of an explicit '='. Cleaner.
3777 3784
3778 3785 2001-12-20 Fernando Perez <fperez@colorado.edu>
3779 3786
3780 3787 * Started a manual in LyX. For now it's just a quick merge of the
3781 3788 various internal docstrings and READMEs. Later it may grow into a
3782 3789 nice, full-blown manual.
3783 3790
3784 3791 * Set up a distutils based installer. Installation should now be
3785 3792 trivially simple for end-users.
3786 3793
3787 3794 2001-12-11 Fernando Perez <fperez@colorado.edu>
3788 3795
3789 3796 * Released 0.2.0. First public release, announced it at
3790 3797 comp.lang.python. From now on, just bugfixes...
3791 3798
3792 3799 * Went through all the files, set copyright/license notices and
3793 3800 cleaned up things. Ready for release.
3794 3801
3795 3802 2001-12-10 Fernando Perez <fperez@colorado.edu>
3796 3803
3797 3804 * Changed the first-time installer not to use tarfiles. It's more
3798 3805 robust now and less unix-dependent. Also makes it easier for
3799 3806 people to later upgrade versions.
3800 3807
3801 3808 * Changed @exit to @abort to reflect the fact that it's pretty
3802 3809 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3803 3810 becomes significant only when IPyhton is embedded: in that case,
3804 3811 C-D closes IPython only, but @abort kills the enclosing program
3805 3812 too (unless it had called IPython inside a try catching
3806 3813 SystemExit).
3807 3814
3808 3815 * Created Shell module which exposes the actuall IPython Shell
3809 3816 classes, currently the normal and the embeddable one. This at
3810 3817 least offers a stable interface we won't need to change when
3811 3818 (later) the internals are rewritten. That rewrite will be confined
3812 3819 to iplib and ipmaker, but the Shell interface should remain as is.
3813 3820
3814 3821 * Added embed module which offers an embeddable IPShell object,
3815 3822 useful to fire up IPython *inside* a running program. Great for
3816 3823 debugging or dynamical data analysis.
3817 3824
3818 3825 2001-12-08 Fernando Perez <fperez@colorado.edu>
3819 3826
3820 3827 * Fixed small bug preventing seeing info from methods of defined
3821 3828 objects (incorrect namespace in _ofind()).
3822 3829
3823 3830 * Documentation cleanup. Moved the main usage docstrings to a
3824 3831 separate file, usage.py (cleaner to maintain, and hopefully in the
3825 3832 future some perlpod-like way of producing interactive, man and
3826 3833 html docs out of it will be found).
3827 3834
3828 3835 * Added @profile to see your profile at any time.
3829 3836
3830 3837 * Added @p as an alias for 'print'. It's especially convenient if
3831 3838 using automagic ('p x' prints x).
3832 3839
3833 3840 * Small cleanups and fixes after a pychecker run.
3834 3841
3835 3842 * Changed the @cd command to handle @cd - and @cd -<n> for
3836 3843 visiting any directory in _dh.
3837 3844
3838 3845 * Introduced _dh, a history of visited directories. @dhist prints
3839 3846 it out with numbers.
3840 3847
3841 3848 2001-12-07 Fernando Perez <fperez@colorado.edu>
3842 3849
3843 3850 * Released 0.1.22
3844 3851
3845 3852 * Made initialization a bit more robust against invalid color
3846 3853 options in user input (exit, not traceback-crash).
3847 3854
3848 3855 * Changed the bug crash reporter to write the report only in the
3849 3856 user's .ipython directory. That way IPython won't litter people's
3850 3857 hard disks with crash files all over the place. Also print on
3851 3858 screen the necessary mail command.
3852 3859
3853 3860 * With the new ultraTB, implemented LightBG color scheme for light
3854 3861 background terminals. A lot of people like white backgrounds, so I
3855 3862 guess we should at least give them something readable.
3856 3863
3857 3864 2001-12-06 Fernando Perez <fperez@colorado.edu>
3858 3865
3859 3866 * Modified the structure of ultraTB. Now there's a proper class
3860 3867 for tables of color schemes which allow adding schemes easily and
3861 3868 switching the active scheme without creating a new instance every
3862 3869 time (which was ridiculous). The syntax for creating new schemes
3863 3870 is also cleaner. I think ultraTB is finally done, with a clean
3864 3871 class structure. Names are also much cleaner (now there's proper
3865 3872 color tables, no need for every variable to also have 'color' in
3866 3873 its name).
3867 3874
3868 3875 * Broke down genutils into separate files. Now genutils only
3869 3876 contains utility functions, and classes have been moved to their
3870 3877 own files (they had enough independent functionality to warrant
3871 3878 it): ConfigLoader, OutputTrap, Struct.
3872 3879
3873 3880 2001-12-05 Fernando Perez <fperez@colorado.edu>
3874 3881
3875 3882 * IPython turns 21! Released version 0.1.21, as a candidate for
3876 3883 public consumption. If all goes well, release in a few days.
3877 3884
3878 3885 * Fixed path bug (files in Extensions/ directory wouldn't be found
3879 3886 unless IPython/ was explicitly in sys.path).
3880 3887
3881 3888 * Extended the FlexCompleter class as MagicCompleter to allow
3882 3889 completion of @-starting lines.
3883 3890
3884 3891 * Created __release__.py file as a central repository for release
3885 3892 info that other files can read from.
3886 3893
3887 3894 * Fixed small bug in logging: when logging was turned on in
3888 3895 mid-session, old lines with special meanings (!@?) were being
3889 3896 logged without the prepended comment, which is necessary since
3890 3897 they are not truly valid python syntax. This should make session
3891 3898 restores produce less errors.
3892 3899
3893 3900 * The namespace cleanup forced me to make a FlexCompleter class
3894 3901 which is nothing but a ripoff of rlcompleter, but with selectable
3895 3902 namespace (rlcompleter only works in __main__.__dict__). I'll try
3896 3903 to submit a note to the authors to see if this change can be
3897 3904 incorporated in future rlcompleter releases (Dec.6: done)
3898 3905
3899 3906 * More fixes to namespace handling. It was a mess! Now all
3900 3907 explicit references to __main__.__dict__ are gone (except when
3901 3908 really needed) and everything is handled through the namespace
3902 3909 dicts in the IPython instance. We seem to be getting somewhere
3903 3910 with this, finally...
3904 3911
3905 3912 * Small documentation updates.
3906 3913
3907 3914 * Created the Extensions directory under IPython (with an
3908 3915 __init__.py). Put the PhysicalQ stuff there. This directory should
3909 3916 be used for all special-purpose extensions.
3910 3917
3911 3918 * File renaming:
3912 3919 ipythonlib --> ipmaker
3913 3920 ipplib --> iplib
3914 3921 This makes a bit more sense in terms of what these files actually do.
3915 3922
3916 3923 * Moved all the classes and functions in ipythonlib to ipplib, so
3917 3924 now ipythonlib only has make_IPython(). This will ease up its
3918 3925 splitting in smaller functional chunks later.
3919 3926
3920 3927 * Cleaned up (done, I think) output of @whos. Better column
3921 3928 formatting, and now shows str(var) for as much as it can, which is
3922 3929 typically what one gets with a 'print var'.
3923 3930
3924 3931 2001-12-04 Fernando Perez <fperez@colorado.edu>
3925 3932
3926 3933 * Fixed namespace problems. Now builtin/IPyhton/user names get
3927 3934 properly reported in their namespace. Internal namespace handling
3928 3935 is finally getting decent (not perfect yet, but much better than
3929 3936 the ad-hoc mess we had).
3930 3937
3931 3938 * Removed -exit option. If people just want to run a python
3932 3939 script, that's what the normal interpreter is for. Less
3933 3940 unnecessary options, less chances for bugs.
3934 3941
3935 3942 * Added a crash handler which generates a complete post-mortem if
3936 3943 IPython crashes. This will help a lot in tracking bugs down the
3937 3944 road.
3938 3945
3939 3946 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
3940 3947 which were boud to functions being reassigned would bypass the
3941 3948 logger, breaking the sync of _il with the prompt counter. This
3942 3949 would then crash IPython later when a new line was logged.
3943 3950
3944 3951 2001-12-02 Fernando Perez <fperez@colorado.edu>
3945 3952
3946 3953 * Made IPython a package. This means people don't have to clutter
3947 3954 their sys.path with yet another directory. Changed the INSTALL
3948 3955 file accordingly.
3949 3956
3950 3957 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
3951 3958 sorts its output (so @who shows it sorted) and @whos formats the
3952 3959 table according to the width of the first column. Nicer, easier to
3953 3960 read. Todo: write a generic table_format() which takes a list of
3954 3961 lists and prints it nicely formatted, with optional row/column
3955 3962 separators and proper padding and justification.
3956 3963
3957 3964 * Released 0.1.20
3958 3965
3959 3966 * Fixed bug in @log which would reverse the inputcache list (a
3960 3967 copy operation was missing).
3961 3968
3962 3969 * Code cleanup. @config was changed to use page(). Better, since
3963 3970 its output is always quite long.
3964 3971
3965 3972 * Itpl is back as a dependency. I was having too many problems
3966 3973 getting the parametric aliases to work reliably, and it's just
3967 3974 easier to code weird string operations with it than playing %()s
3968 3975 games. It's only ~6k, so I don't think it's too big a deal.
3969 3976
3970 3977 * Found (and fixed) a very nasty bug with history. !lines weren't
3971 3978 getting cached, and the out of sync caches would crash
3972 3979 IPython. Fixed it by reorganizing the prefilter/handlers/logger
3973 3980 division of labor a bit better. Bug fixed, cleaner structure.
3974 3981
3975 3982 2001-12-01 Fernando Perez <fperez@colorado.edu>
3976 3983
3977 3984 * Released 0.1.19
3978 3985
3979 3986 * Added option -n to @hist to prevent line number printing. Much
3980 3987 easier to copy/paste code this way.
3981 3988
3982 3989 * Created global _il to hold the input list. Allows easy
3983 3990 re-execution of blocks of code by slicing it (inspired by Janko's
3984 3991 comment on 'macros').
3985 3992
3986 3993 * Small fixes and doc updates.
3987 3994
3988 3995 * Rewrote @history function (was @h). Renamed it to @hist, @h is
3989 3996 much too fragile with automagic. Handles properly multi-line
3990 3997 statements and takes parameters.
3991 3998
3992 3999 2001-11-30 Fernando Perez <fperez@colorado.edu>
3993 4000
3994 4001 * Version 0.1.18 released.
3995 4002
3996 4003 * Fixed nasty namespace bug in initial module imports.
3997 4004
3998 4005 * Added copyright/license notes to all code files (except
3999 4006 DPyGetOpt). For the time being, LGPL. That could change.
4000 4007
4001 4008 * Rewrote a much nicer README, updated INSTALL, cleaned up
4002 4009 ipythonrc-* samples.
4003 4010
4004 4011 * Overall code/documentation cleanup. Basically ready for
4005 4012 release. Only remaining thing: licence decision (LGPL?).
4006 4013
4007 4014 * Converted load_config to a class, ConfigLoader. Now recursion
4008 4015 control is better organized. Doesn't include the same file twice.
4009 4016
4010 4017 2001-11-29 Fernando Perez <fperez@colorado.edu>
4011 4018
4012 4019 * Got input history working. Changed output history variables from
4013 4020 _p to _o so that _i is for input and _o for output. Just cleaner
4014 4021 convention.
4015 4022
4016 4023 * Implemented parametric aliases. This pretty much allows the
4017 4024 alias system to offer full-blown shell convenience, I think.
4018 4025
4019 4026 * Version 0.1.17 released, 0.1.18 opened.
4020 4027
4021 4028 * dot_ipython/ipythonrc (alias): added documentation.
4022 4029 (xcolor): Fixed small bug (xcolors -> xcolor)
4023 4030
4024 4031 * Changed the alias system. Now alias is a magic command to define
4025 4032 aliases just like the shell. Rationale: the builtin magics should
4026 4033 be there for things deeply connected to IPython's
4027 4034 architecture. And this is a much lighter system for what I think
4028 4035 is the really important feature: allowing users to define quickly
4029 4036 magics that will do shell things for them, so they can customize
4030 4037 IPython easily to match their work habits. If someone is really
4031 4038 desperate to have another name for a builtin alias, they can
4032 4039 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
4033 4040 works.
4034 4041
4035 4042 2001-11-28 Fernando Perez <fperez@colorado.edu>
4036 4043
4037 4044 * Changed @file so that it opens the source file at the proper
4038 4045 line. Since it uses less, if your EDITOR environment is
4039 4046 configured, typing v will immediately open your editor of choice
4040 4047 right at the line where the object is defined. Not as quick as
4041 4048 having a direct @edit command, but for all intents and purposes it
4042 4049 works. And I don't have to worry about writing @edit to deal with
4043 4050 all the editors, less does that.
4044 4051
4045 4052 * Version 0.1.16 released, 0.1.17 opened.
4046 4053
4047 4054 * Fixed some nasty bugs in the page/page_dumb combo that could
4048 4055 crash IPython.
4049 4056
4050 4057 2001-11-27 Fernando Perez <fperez@colorado.edu>
4051 4058
4052 4059 * Version 0.1.15 released, 0.1.16 opened.
4053 4060
4054 4061 * Finally got ? and ?? to work for undefined things: now it's
4055 4062 possible to type {}.get? and get information about the get method
4056 4063 of dicts, or os.path? even if only os is defined (so technically
4057 4064 os.path isn't). Works at any level. For example, after import os,
4058 4065 os?, os.path?, os.path.abspath? all work. This is great, took some
4059 4066 work in _ofind.
4060 4067
4061 4068 * Fixed more bugs with logging. The sanest way to do it was to add
4062 4069 to @log a 'mode' parameter. Killed two in one shot (this mode
4063 4070 option was a request of Janko's). I think it's finally clean
4064 4071 (famous last words).
4065 4072
4066 4073 * Added a page_dumb() pager which does a decent job of paging on
4067 4074 screen, if better things (like less) aren't available. One less
4068 4075 unix dependency (someday maybe somebody will port this to
4069 4076 windows).
4070 4077
4071 4078 * Fixed problem in magic_log: would lock of logging out if log
4072 4079 creation failed (because it would still think it had succeeded).
4073 4080
4074 4081 * Improved the page() function using curses to auto-detect screen
4075 4082 size. Now it can make a much better decision on whether to print
4076 4083 or page a string. Option screen_length was modified: a value 0
4077 4084 means auto-detect, and that's the default now.
4078 4085
4079 4086 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
4080 4087 go out. I'll test it for a few days, then talk to Janko about
4081 4088 licences and announce it.
4082 4089
4083 4090 * Fixed the length of the auto-generated ---> prompt which appears
4084 4091 for auto-parens and auto-quotes. Getting this right isn't trivial,
4085 4092 with all the color escapes, different prompt types and optional
4086 4093 separators. But it seems to be working in all the combinations.
4087 4094
4088 4095 2001-11-26 Fernando Perez <fperez@colorado.edu>
4089 4096
4090 4097 * Wrote a regexp filter to get option types from the option names
4091 4098 string. This eliminates the need to manually keep two duplicate
4092 4099 lists.
4093 4100
4094 4101 * Removed the unneeded check_option_names. Now options are handled
4095 4102 in a much saner manner and it's easy to visually check that things
4096 4103 are ok.
4097 4104
4098 4105 * Updated version numbers on all files I modified to carry a
4099 4106 notice so Janko and Nathan have clear version markers.
4100 4107
4101 4108 * Updated docstring for ultraTB with my changes. I should send
4102 4109 this to Nathan.
4103 4110
4104 4111 * Lots of small fixes. Ran everything through pychecker again.
4105 4112
4106 4113 * Made loading of deep_reload an cmd line option. If it's not too
4107 4114 kosher, now people can just disable it. With -nodeep_reload it's
4108 4115 still available as dreload(), it just won't overwrite reload().
4109 4116
4110 4117 * Moved many options to the no| form (-opt and -noopt
4111 4118 accepted). Cleaner.
4112 4119
4113 4120 * Changed magic_log so that if called with no parameters, it uses
4114 4121 'rotate' mode. That way auto-generated logs aren't automatically
4115 4122 over-written. For normal logs, now a backup is made if it exists
4116 4123 (only 1 level of backups). A new 'backup' mode was added to the
4117 4124 Logger class to support this. This was a request by Janko.
4118 4125
4119 4126 * Added @logoff/@logon to stop/restart an active log.
4120 4127
4121 4128 * Fixed a lot of bugs in log saving/replay. It was pretty
4122 4129 broken. Now special lines (!@,/) appear properly in the command
4123 4130 history after a log replay.
4124 4131
4125 4132 * Tried and failed to implement full session saving via pickle. My
4126 4133 idea was to pickle __main__.__dict__, but modules can't be
4127 4134 pickled. This would be a better alternative to replaying logs, but
4128 4135 seems quite tricky to get to work. Changed -session to be called
4129 4136 -logplay, which more accurately reflects what it does. And if we
4130 4137 ever get real session saving working, -session is now available.
4131 4138
4132 4139 * Implemented color schemes for prompts also. As for tracebacks,
4133 4140 currently only NoColor and Linux are supported. But now the
4134 4141 infrastructure is in place, based on a generic ColorScheme
4135 4142 class. So writing and activating new schemes both for the prompts
4136 4143 and the tracebacks should be straightforward.
4137 4144
4138 4145 * Version 0.1.13 released, 0.1.14 opened.
4139 4146
4140 4147 * Changed handling of options for output cache. Now counter is
4141 4148 hardwired starting at 1 and one specifies the maximum number of
4142 4149 entries *in the outcache* (not the max prompt counter). This is
4143 4150 much better, since many statements won't increase the cache
4144 4151 count. It also eliminated some confusing options, now there's only
4145 4152 one: cache_size.
4146 4153
4147 4154 * Added 'alias' magic function and magic_alias option in the
4148 4155 ipythonrc file. Now the user can easily define whatever names he
4149 4156 wants for the magic functions without having to play weird
4150 4157 namespace games. This gives IPython a real shell-like feel.
4151 4158
4152 4159 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
4153 4160 @ or not).
4154 4161
4155 4162 This was one of the last remaining 'visible' bugs (that I know
4156 4163 of). I think if I can clean up the session loading so it works
4157 4164 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
4158 4165 about licensing).
4159 4166
4160 4167 2001-11-25 Fernando Perez <fperez@colorado.edu>
4161 4168
4162 4169 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
4163 4170 there's a cleaner distinction between what ? and ?? show.
4164 4171
4165 4172 * Added screen_length option. Now the user can define his own
4166 4173 screen size for page() operations.
4167 4174
4168 4175 * Implemented magic shell-like functions with automatic code
4169 4176 generation. Now adding another function is just a matter of adding
4170 4177 an entry to a dict, and the function is dynamically generated at
4171 4178 run-time. Python has some really cool features!
4172 4179
4173 4180 * Renamed many options to cleanup conventions a little. Now all
4174 4181 are lowercase, and only underscores where needed. Also in the code
4175 4182 option name tables are clearer.
4176 4183
4177 4184 * Changed prompts a little. Now input is 'In [n]:' instead of
4178 4185 'In[n]:='. This allows it the numbers to be aligned with the
4179 4186 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4180 4187 Python (it was a Mathematica thing). The '...' continuation prompt
4181 4188 was also changed a little to align better.
4182 4189
4183 4190 * Fixed bug when flushing output cache. Not all _p<n> variables
4184 4191 exist, so their deletion needs to be wrapped in a try:
4185 4192
4186 4193 * Figured out how to properly use inspect.formatargspec() (it
4187 4194 requires the args preceded by *). So I removed all the code from
4188 4195 _get_pdef in Magic, which was just replicating that.
4189 4196
4190 4197 * Added test to prefilter to allow redefining magic function names
4191 4198 as variables. This is ok, since the @ form is always available,
4192 4199 but whe should allow the user to define a variable called 'ls' if
4193 4200 he needs it.
4194 4201
4195 4202 * Moved the ToDo information from README into a separate ToDo.
4196 4203
4197 4204 * General code cleanup and small bugfixes. I think it's close to a
4198 4205 state where it can be released, obviously with a big 'beta'
4199 4206 warning on it.
4200 4207
4201 4208 * Got the magic function split to work. Now all magics are defined
4202 4209 in a separate class. It just organizes things a bit, and now
4203 4210 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4204 4211 was too long).
4205 4212
4206 4213 * Changed @clear to @reset to avoid potential confusions with
4207 4214 the shell command clear. Also renamed @cl to @clear, which does
4208 4215 exactly what people expect it to from their shell experience.
4209 4216
4210 4217 Added a check to the @reset command (since it's so
4211 4218 destructive, it's probably a good idea to ask for confirmation).
4212 4219 But now reset only works for full namespace resetting. Since the
4213 4220 del keyword is already there for deleting a few specific
4214 4221 variables, I don't see the point of having a redundant magic
4215 4222 function for the same task.
4216 4223
4217 4224 2001-11-24 Fernando Perez <fperez@colorado.edu>
4218 4225
4219 4226 * Updated the builtin docs (esp. the ? ones).
4220 4227
4221 4228 * Ran all the code through pychecker. Not terribly impressed with
4222 4229 it: lots of spurious warnings and didn't really find anything of
4223 4230 substance (just a few modules being imported and not used).
4224 4231
4225 4232 * Implemented the new ultraTB functionality into IPython. New
4226 4233 option: xcolors. This chooses color scheme. xmode now only selects
4227 4234 between Plain and Verbose. Better orthogonality.
4228 4235
4229 4236 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4230 4237 mode and color scheme for the exception handlers. Now it's
4231 4238 possible to have the verbose traceback with no coloring.
4232 4239
4233 4240 2001-11-23 Fernando Perez <fperez@colorado.edu>
4234 4241
4235 4242 * Version 0.1.12 released, 0.1.13 opened.
4236 4243
4237 4244 * Removed option to set auto-quote and auto-paren escapes by
4238 4245 user. The chances of breaking valid syntax are just too high. If
4239 4246 someone *really* wants, they can always dig into the code.
4240 4247
4241 4248 * Made prompt separators configurable.
4242 4249
4243 4250 2001-11-22 Fernando Perez <fperez@colorado.edu>
4244 4251
4245 4252 * Small bugfixes in many places.
4246 4253
4247 4254 * Removed the MyCompleter class from ipplib. It seemed redundant
4248 4255 with the C-p,C-n history search functionality. Less code to
4249 4256 maintain.
4250 4257
4251 4258 * Moved all the original ipython.py code into ipythonlib.py. Right
4252 4259 now it's just one big dump into a function called make_IPython, so
4253 4260 no real modularity has been gained. But at least it makes the
4254 4261 wrapper script tiny, and since ipythonlib is a module, it gets
4255 4262 compiled and startup is much faster.
4256 4263
4257 4264 This is a reasobably 'deep' change, so we should test it for a
4258 4265 while without messing too much more with the code.
4259 4266
4260 4267 2001-11-21 Fernando Perez <fperez@colorado.edu>
4261 4268
4262 4269 * Version 0.1.11 released, 0.1.12 opened for further work.
4263 4270
4264 4271 * Removed dependency on Itpl. It was only needed in one place. It
4265 4272 would be nice if this became part of python, though. It makes life
4266 4273 *a lot* easier in some cases.
4267 4274
4268 4275 * Simplified the prefilter code a bit. Now all handlers are
4269 4276 expected to explicitly return a value (at least a blank string).
4270 4277
4271 4278 * Heavy edits in ipplib. Removed the help system altogether. Now
4272 4279 obj?/?? is used for inspecting objects, a magic @doc prints
4273 4280 docstrings, and full-blown Python help is accessed via the 'help'
4274 4281 keyword. This cleans up a lot of code (less to maintain) and does
4275 4282 the job. Since 'help' is now a standard Python component, might as
4276 4283 well use it and remove duplicate functionality.
4277 4284
4278 4285 Also removed the option to use ipplib as a standalone program. By
4279 4286 now it's too dependent on other parts of IPython to function alone.
4280 4287
4281 4288 * Fixed bug in genutils.pager. It would crash if the pager was
4282 4289 exited immediately after opening (broken pipe).
4283 4290
4284 4291 * Trimmed down the VerboseTB reporting a little. The header is
4285 4292 much shorter now and the repeated exception arguments at the end
4286 4293 have been removed. For interactive use the old header seemed a bit
4287 4294 excessive.
4288 4295
4289 4296 * Fixed small bug in output of @whos for variables with multi-word
4290 4297 types (only first word was displayed).
4291 4298
4292 4299 2001-11-17 Fernando Perez <fperez@colorado.edu>
4293 4300
4294 4301 * Version 0.1.10 released, 0.1.11 opened for further work.
4295 4302
4296 4303 * Modified dirs and friends. dirs now *returns* the stack (not
4297 4304 prints), so one can manipulate it as a variable. Convenient to
4298 4305 travel along many directories.
4299 4306
4300 4307 * Fixed bug in magic_pdef: would only work with functions with
4301 4308 arguments with default values.
4302 4309
4303 4310 2001-11-14 Fernando Perez <fperez@colorado.edu>
4304 4311
4305 4312 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4306 4313 example with IPython. Various other minor fixes and cleanups.
4307 4314
4308 4315 * Version 0.1.9 released, 0.1.10 opened for further work.
4309 4316
4310 4317 * Added sys.path to the list of directories searched in the
4311 4318 execfile= option. It used to be the current directory and the
4312 4319 user's IPYTHONDIR only.
4313 4320
4314 4321 2001-11-13 Fernando Perez <fperez@colorado.edu>
4315 4322
4316 4323 * Reinstated the raw_input/prefilter separation that Janko had
4317 4324 initially. This gives a more convenient setup for extending the
4318 4325 pre-processor from the outside: raw_input always gets a string,
4319 4326 and prefilter has to process it. We can then redefine prefilter
4320 4327 from the outside and implement extensions for special
4321 4328 purposes.
4322 4329
4323 4330 Today I got one for inputting PhysicalQuantity objects
4324 4331 (from Scientific) without needing any function calls at
4325 4332 all. Extremely convenient, and it's all done as a user-level
4326 4333 extension (no IPython code was touched). Now instead of:
4327 4334 a = PhysicalQuantity(4.2,'m/s**2')
4328 4335 one can simply say
4329 4336 a = 4.2 m/s**2
4330 4337 or even
4331 4338 a = 4.2 m/s^2
4332 4339
4333 4340 I use this, but it's also a proof of concept: IPython really is
4334 4341 fully user-extensible, even at the level of the parsing of the
4335 4342 command line. It's not trivial, but it's perfectly doable.
4336 4343
4337 4344 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4338 4345 the problem of modules being loaded in the inverse order in which
4339 4346 they were defined in
4340 4347
4341 4348 * Version 0.1.8 released, 0.1.9 opened for further work.
4342 4349
4343 4350 * Added magics pdef, source and file. They respectively show the
4344 4351 definition line ('prototype' in C), source code and full python
4345 4352 file for any callable object. The object inspector oinfo uses
4346 4353 these to show the same information.
4347 4354
4348 4355 * Version 0.1.7 released, 0.1.8 opened for further work.
4349 4356
4350 4357 * Separated all the magic functions into a class called Magic. The
4351 4358 InteractiveShell class was becoming too big for Xemacs to handle
4352 4359 (de-indenting a line would lock it up for 10 seconds while it
4353 4360 backtracked on the whole class!)
4354 4361
4355 4362 FIXME: didn't work. It can be done, but right now namespaces are
4356 4363 all messed up. Do it later (reverted it for now, so at least
4357 4364 everything works as before).
4358 4365
4359 4366 * Got the object introspection system (magic_oinfo) working! I
4360 4367 think this is pretty much ready for release to Janko, so he can
4361 4368 test it for a while and then announce it. Pretty much 100% of what
4362 4369 I wanted for the 'phase 1' release is ready. Happy, tired.
4363 4370
4364 4371 2001-11-12 Fernando Perez <fperez@colorado.edu>
4365 4372
4366 4373 * Version 0.1.6 released, 0.1.7 opened for further work.
4367 4374
4368 4375 * Fixed bug in printing: it used to test for truth before
4369 4376 printing, so 0 wouldn't print. Now checks for None.
4370 4377
4371 4378 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4372 4379 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4373 4380 reaches by hand into the outputcache. Think of a better way to do
4374 4381 this later.
4375 4382
4376 4383 * Various small fixes thanks to Nathan's comments.
4377 4384
4378 4385 * Changed magic_pprint to magic_Pprint. This way it doesn't
4379 4386 collide with pprint() and the name is consistent with the command
4380 4387 line option.
4381 4388
4382 4389 * Changed prompt counter behavior to be fully like
4383 4390 Mathematica's. That is, even input that doesn't return a result
4384 4391 raises the prompt counter. The old behavior was kind of confusing
4385 4392 (getting the same prompt number several times if the operation
4386 4393 didn't return a result).
4387 4394
4388 4395 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4389 4396
4390 4397 * Fixed -Classic mode (wasn't working anymore).
4391 4398
4392 4399 * Added colored prompts using Nathan's new code. Colors are
4393 4400 currently hardwired, they can be user-configurable. For
4394 4401 developers, they can be chosen in file ipythonlib.py, at the
4395 4402 beginning of the CachedOutput class def.
4396 4403
4397 4404 2001-11-11 Fernando Perez <fperez@colorado.edu>
4398 4405
4399 4406 * Version 0.1.5 released, 0.1.6 opened for further work.
4400 4407
4401 4408 * Changed magic_env to *return* the environment as a dict (not to
4402 4409 print it). This way it prints, but it can also be processed.
4403 4410
4404 4411 * Added Verbose exception reporting to interactive
4405 4412 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4406 4413 traceback. Had to make some changes to the ultraTB file. This is
4407 4414 probably the last 'big' thing in my mental todo list. This ties
4408 4415 in with the next entry:
4409 4416
4410 4417 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4411 4418 has to specify is Plain, Color or Verbose for all exception
4412 4419 handling.
4413 4420
4414 4421 * Removed ShellServices option. All this can really be done via
4415 4422 the magic system. It's easier to extend, cleaner and has automatic
4416 4423 namespace protection and documentation.
4417 4424
4418 4425 2001-11-09 Fernando Perez <fperez@colorado.edu>
4419 4426
4420 4427 * Fixed bug in output cache flushing (missing parameter to
4421 4428 __init__). Other small bugs fixed (found using pychecker).
4422 4429
4423 4430 * Version 0.1.4 opened for bugfixing.
4424 4431
4425 4432 2001-11-07 Fernando Perez <fperez@colorado.edu>
4426 4433
4427 4434 * Version 0.1.3 released, mainly because of the raw_input bug.
4428 4435
4429 4436 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4430 4437 and when testing for whether things were callable, a call could
4431 4438 actually be made to certain functions. They would get called again
4432 4439 once 'really' executed, with a resulting double call. A disaster
4433 4440 in many cases (list.reverse() would never work!).
4434 4441
4435 4442 * Removed prefilter() function, moved its code to raw_input (which
4436 4443 after all was just a near-empty caller for prefilter). This saves
4437 4444 a function call on every prompt, and simplifies the class a tiny bit.
4438 4445
4439 4446 * Fix _ip to __ip name in magic example file.
4440 4447
4441 4448 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4442 4449 work with non-gnu versions of tar.
4443 4450
4444 4451 2001-11-06 Fernando Perez <fperez@colorado.edu>
4445 4452
4446 4453 * Version 0.1.2. Just to keep track of the recent changes.
4447 4454
4448 4455 * Fixed nasty bug in output prompt routine. It used to check 'if
4449 4456 arg != None...'. Problem is, this fails if arg implements a
4450 4457 special comparison (__cmp__) which disallows comparing to
4451 4458 None. Found it when trying to use the PhysicalQuantity module from
4452 4459 ScientificPython.
4453 4460
4454 4461 2001-11-05 Fernando Perez <fperez@colorado.edu>
4455 4462
4456 4463 * Also added dirs. Now the pushd/popd/dirs family functions
4457 4464 basically like the shell, with the added convenience of going home
4458 4465 when called with no args.
4459 4466
4460 4467 * pushd/popd slightly modified to mimic shell behavior more
4461 4468 closely.
4462 4469
4463 4470 * Added env,pushd,popd from ShellServices as magic functions. I
4464 4471 think the cleanest will be to port all desired functions from
4465 4472 ShellServices as magics and remove ShellServices altogether. This
4466 4473 will provide a single, clean way of adding functionality
4467 4474 (shell-type or otherwise) to IP.
4468 4475
4469 4476 2001-11-04 Fernando Perez <fperez@colorado.edu>
4470 4477
4471 4478 * Added .ipython/ directory to sys.path. This way users can keep
4472 4479 customizations there and access them via import.
4473 4480
4474 4481 2001-11-03 Fernando Perez <fperez@colorado.edu>
4475 4482
4476 4483 * Opened version 0.1.1 for new changes.
4477 4484
4478 4485 * Changed version number to 0.1.0: first 'public' release, sent to
4479 4486 Nathan and Janko.
4480 4487
4481 4488 * Lots of small fixes and tweaks.
4482 4489
4483 4490 * Minor changes to whos format. Now strings are shown, snipped if
4484 4491 too long.
4485 4492
4486 4493 * Changed ShellServices to work on __main__ so they show up in @who
4487 4494
4488 4495 * Help also works with ? at the end of a line:
4489 4496 ?sin and sin?
4490 4497 both produce the same effect. This is nice, as often I use the
4491 4498 tab-complete to find the name of a method, but I used to then have
4492 4499 to go to the beginning of the line to put a ? if I wanted more
4493 4500 info. Now I can just add the ? and hit return. Convenient.
4494 4501
4495 4502 2001-11-02 Fernando Perez <fperez@colorado.edu>
4496 4503
4497 4504 * Python version check (>=2.1) added.
4498 4505
4499 4506 * Added LazyPython documentation. At this point the docs are quite
4500 4507 a mess. A cleanup is in order.
4501 4508
4502 4509 * Auto-installer created. For some bizarre reason, the zipfiles
4503 4510 module isn't working on my system. So I made a tar version
4504 4511 (hopefully the command line options in various systems won't kill
4505 4512 me).
4506 4513
4507 4514 * Fixes to Struct in genutils. Now all dictionary-like methods are
4508 4515 protected (reasonably).
4509 4516
4510 4517 * Added pager function to genutils and changed ? to print usage
4511 4518 note through it (it was too long).
4512 4519
4513 4520 * Added the LazyPython functionality. Works great! I changed the
4514 4521 auto-quote escape to ';', it's on home row and next to '. But
4515 4522 both auto-quote and auto-paren (still /) escapes are command-line
4516 4523 parameters.
4517 4524
4518 4525
4519 4526 2001-11-01 Fernando Perez <fperez@colorado.edu>
4520 4527
4521 4528 * Version changed to 0.0.7. Fairly large change: configuration now
4522 4529 is all stored in a directory, by default .ipython. There, all
4523 4530 config files have normal looking names (not .names)
4524 4531
4525 4532 * Version 0.0.6 Released first to Lucas and Archie as a test
4526 4533 run. Since it's the first 'semi-public' release, change version to
4527 4534 > 0.0.6 for any changes now.
4528 4535
4529 4536 * Stuff I had put in the ipplib.py changelog:
4530 4537
4531 4538 Changes to InteractiveShell:
4532 4539
4533 4540 - Made the usage message a parameter.
4534 4541
4535 4542 - Require the name of the shell variable to be given. It's a bit
4536 4543 of a hack, but allows the name 'shell' not to be hardwire in the
4537 4544 magic (@) handler, which is problematic b/c it requires
4538 4545 polluting the global namespace with 'shell'. This in turn is
4539 4546 fragile: if a user redefines a variable called shell, things
4540 4547 break.
4541 4548
4542 4549 - magic @: all functions available through @ need to be defined
4543 4550 as magic_<name>, even though they can be called simply as
4544 4551 @<name>. This allows the special command @magic to gather
4545 4552 information automatically about all existing magic functions,
4546 4553 even if they are run-time user extensions, by parsing the shell
4547 4554 instance __dict__ looking for special magic_ names.
4548 4555
4549 4556 - mainloop: added *two* local namespace parameters. This allows
4550 4557 the class to differentiate between parameters which were there
4551 4558 before and after command line initialization was processed. This
4552 4559 way, later @who can show things loaded at startup by the
4553 4560 user. This trick was necessary to make session saving/reloading
4554 4561 really work: ideally after saving/exiting/reloading a session,
4555 4562 *everythin* should look the same, including the output of @who. I
4556 4563 was only able to make this work with this double namespace
4557 4564 trick.
4558 4565
4559 4566 - added a header to the logfile which allows (almost) full
4560 4567 session restoring.
4561 4568
4562 4569 - prepend lines beginning with @ or !, with a and log
4563 4570 them. Why? !lines: may be useful to know what you did @lines:
4564 4571 they may affect session state. So when restoring a session, at
4565 4572 least inform the user of their presence. I couldn't quite get
4566 4573 them to properly re-execute, but at least the user is warned.
4567 4574
4568 4575 * Started ChangeLog.
@@ -1,9168 +1,9151 b''
1 1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 2 \lyxformat 221
3 3 \textclass article
4 4 \begin_preamble
5 5 %\usepackage{ae,aecompl}
6 6 \usepackage{color}
7 7
8 8 % A few colors to replace the defaults for certain link types
9 9 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
10 10 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
11 11 \definecolor{darkred}{rgb}{.52,0.08,0.01}
12 12 \definecolor{darkgreen}{rgb}{.12,.54,.11}
13 13
14 14 % Use and configure listings package for nicely formatted code
15 15 \usepackage{listings}
16 16 \lstset{
17 17 language=Python,
18 18 basicstyle=\small\ttfamily,
19 19 commentstyle=\ttfamily\color{blue},
20 20 stringstyle=\ttfamily\color{darkorange},
21 21 showstringspaces=false,
22 22 breaklines=true,
23 23 postbreak = \space\dots
24 24 }
25 25
26 26 \usepackage[%pdftex, % needed for pdflatex
27 27 breaklinks=true, % so long urls are correctly broken across lines
28 28 colorlinks=true,
29 29 urlcolor=blue,
30 30 linkcolor=darkred,
31 31 citecolor=darkgreen,
32 32 ]{hyperref}
33 33
34 34 \usepackage{html}
35 35
36 36 % This helps prevent overly long lines that stretch beyond the margins
37 37 \sloppy
38 38
39 39 % Define a \codelist command which either uses listings for latex, or
40 40 % plain verbatim for html (since latex2html doesn't understand the
41 41 % listings package).
42 42 \usepackage{verbatim}
43 43 \newcommand{\codelist}[1] {
44 44 \latex{\lstinputlisting{#1}}
45 45 \html{\verbatiminput{#1}}
46 46 }
47 47 \end_preamble
48 48 \language english
49 49 \inputencoding latin1
50 50 \fontscheme palatino
51 51 \graphics default
52 52 \paperfontsize 10
53 53 \spacing single
54 54 \papersize Default
55 55 \paperpackage a4
56 56 \use_geometry 1
57 57 \use_amsmath 0
58 58 \use_natbib 0
59 59 \use_numerical_citations 0
60 60 \paperorientation portrait
61 61 \leftmargin 1.1in
62 62 \topmargin 1in
63 63 \rightmargin 1.1in
64 64 \bottommargin 1in
65 65 \secnumdepth 3
66 66 \tocdepth 3
67 67 \paragraph_separation skip
68 68 \defskip medskip
69 69 \quotes_language english
70 70 \quotes_times 2
71 71 \papercolumns 1
72 72 \papersides 1
73 73 \paperpagestyle fancy
74 74
75 75 \layout Title
76 76
77 77 IPython
78 78 \newline
79 79
80 80 \size larger
81 81 An enhanced Interactive Python
82 82 \size large
83 83
84 84 \newline
85 85 User Manual, v.
86 86 __version__
87 87 \layout Author
88 88
89 89 Fernando P�rez
90 90 \layout Standard
91 91
92 92
93 93 \begin_inset ERT
94 94 status Collapsed
95 95
96 96 \layout Standard
97 97
98 98 \backslash
99 99 latex{
100 100 \end_inset
101 101
102 102
103 103 \begin_inset LatexCommand \tableofcontents{}
104 104
105 105 \end_inset
106 106
107 107
108 108 \begin_inset ERT
109 109 status Collapsed
110 110
111 111 \layout Standard
112 112 }
113 113 \end_inset
114 114
115 115
116 116 \layout Standard
117 117
118 118
119 119 \begin_inset ERT
120 120 status Open
121 121
122 122 \layout Standard
123 123
124 124 \backslash
125 125 html{
126 126 \backslash
127 127 bodytext{bgcolor=#ffffff}}
128 128 \end_inset
129 129
130 130
131 131 \layout Section
132 132 \pagebreak_top
133 133 Overview
134 134 \layout Standard
135 135
136 136 One of Python's most useful features is its interactive interpreter.
137 137 This system allows very fast testing of ideas without the overhead of creating
138 138 test files as is typical in most programming languages.
139 139 However, the interpreter supplied with the standard Python distribution
140 140 is somewhat limited for extended interactive use.
141 141 \layout Standard
142 142
143 143 IPython is a free software project (released under the BSD license) which
144 144 tries to:
145 145 \layout Enumerate
146 146
147 147 Provide an interactive shell superior to Python's default.
148 148 IPython has many features for object introspection, system shell access,
149 149 and its own special command system for adding functionality when working
150 150 interactively.
151 151 It tries to be a very efficient environment both for Python code development
152 152 and for exploration of problems using Python objects (in situations like
153 153 data analysis).
154 154 \layout Enumerate
155 155
156 156 Serve as an embeddable, ready to use interpreter for your own programs.
157 157 IPython can be started with a single call from inside another program,
158 158 providing access to the current namespace.
159 159 This can be very useful both for debugging purposes and for situations
160 160 where a blend of batch-processing and interactive exploration are needed.
161 161 \layout Enumerate
162 162
163 163 Offer a flexible framework which can be used as the base environment for
164 164 other systems with Python as the underlying language.
165 165 Specifically scientific environments like Mathematica, IDL and Matlab inspired
166 166 its design, but similar ideas can be useful in many fields.
167 167 \layout Subsection
168 168
169 169 Main features
170 170 \layout Itemize
171 171
172 172 Dynamic object introspection.
173 173 One can access docstrings, function definition prototypes, source code,
174 174 source files and other details of any object accessible to the interpreter
175 175 with a single keystroke (`
176 176 \family typewriter
177 177 ?
178 178 \family default
179 179 ').
180 180 \layout Itemize
181 181
182 182 Completion in the local namespace, by typing TAB at the prompt.
183 183 This works for keywords, methods, variables and files in the current directory.
184 184 This is supported via the readline library, and full access to configuring
185 185 readline's behavior is provided.
186 186 \layout Itemize
187 187
188 188 Numbered input/output prompts with command history (persistent across sessions
189 189 and tied to each profile), full searching in this history and caching of
190 190 all input and output.
191 191 \layout Itemize
192 192
193 193 User-extensible `magic' commands.
194 194 A set of commands prefixed with
195 195 \family typewriter
196 196 %
197 197 \family default
198 198 is available for controlling IPython itself and provides directory control,
199 199 namespace information and many aliases to common system shell commands.
200 200 \layout Itemize
201 201
202 202 Alias facility for defining your own system aliases.
203 203 \layout Itemize
204 204
205 205 Complete system shell access.
206 206 Lines starting with ! are passed directly to the system shell, and using
207 207 !! captures shell output into python variables for further use.
208 208 \layout Itemize
209 209
210 210 All calls to the system (via aliases or via !) have their standard output/error
211 211 automatically stored as strings, and also available as lists.
212 212 \layout Itemize
213 213
214 214 Background execution of Python commands in a separate thread.
215 215 IPython has an internal job manager called
216 216 \family typewriter
217 217 jobs
218 218 \family default
219 219 , and a conveninence backgrounding magic function called
220 220 \family typewriter
221 221 %bg
222 222 \family default
223 223 .
224 224 \layout Itemize
225 225
226 226 The ability to expand python variables when calling the system shell.
227 227 In a shell command, any python variable prefixed with
228 228 \family typewriter
229 229 $
230 230 \family default
231 231 is expanded.
232 232 A double
233 233 \family typewriter
234 234 $$
235 235 \family default
236 236 allows passing a literal
237 237 \family typewriter
238 238 $
239 239 \family default
240 240 to the shell (for access to shell and environment variables like
241 241 \family typewriter
242 242 $PATH
243 243 \family default
244 244 ).
245 245 \layout Itemize
246 246
247 247 Filesystem navigation, via a magic
248 248 \family typewriter
249 249 %cd
250 250 \family default
251 251 command, along with a persistent bookmark system (using
252 252 \family typewriter
253 253 %bookmark
254 254 \family default
255 255 ) for fast access to frequently visited directories.
256 256 \layout Itemize
257 257
258 258 Automatic indentation (optional) of code as you type (through the readline
259 259 library).
260 260 \layout Itemize
261 261
262 262 Macro system for quickly re-executing multiple lines of previous input with
263 263 a single name.
264 264 \layout Itemize
265 265
266 266 Session logging (you can then later use these logs as code in your programs).
267 267 \layout Itemize
268 268
269 269 Session restoring: logs can be replayed to restore a previous session to
270 270 the state where you left it.
271 271 \layout Itemize
272 272
273 273 Verbose and colored exception traceback printouts.
274 274 Easier to parse visually, and in verbose mode they produce a lot of useful
275 275 debugging information (basically a terminal version of the cgitb module).
276 276 \layout Itemize
277 277
278 278 Auto-parentheses: callable objects can be executed without parentheses:
279 279
280 280 \family typewriter
281 281 `sin 3'
282 282 \family default
283 283 is automatically converted to
284 284 \family typewriter
285 285 `sin(3)
286 286 \family default
287 287 '.
288 288 \layout Itemize
289 289
290 290 Auto-quoting: using `
291 291 \family typewriter
292 292 ,
293 293 \family default
294 294 ' or `
295 295 \family typewriter
296 296 ;
297 297 \family default
298 298 ' as the first character forces auto-quoting of the rest of the line:
299 299 \family typewriter
300 300 `,my_function a\SpecialChar ~
301 301 b'
302 302 \family default
303 303 becomes automatically
304 304 \family typewriter
305 305 `my_function("a","b")'
306 306 \family default
307 307 , while
308 308 \family typewriter
309 309 `;my_function a\SpecialChar ~
310 310 b'
311 311 \family default
312 312 becomes
313 313 \family typewriter
314 314 `my_function("a b")'
315 315 \family default
316 316 .
317 317 \layout Itemize
318 318
319 319 Extensible input syntax.
320 320 You can define filters that pre-process user input to simplify input in
321 321 special situations.
322 322 This allows for example pasting multi-line code fragments which start with
323 323
324 324 \family typewriter
325 325 `>>>'
326 326 \family default
327 327 or
328 328 \family typewriter
329 329 `...'
330 330 \family default
331 331 such as those from other python sessions or the standard Python documentation.
332 332 \layout Itemize
333 333
334 334 Flexible configuration system.
335 335 It uses a configuration file which allows permanent setting of all command-line
336 336 options, module loading, code and file execution.
337 337 The system allows recursive file inclusion, so you can have a base file
338 338 with defaults and layers which load other customizations for particular
339 339 projects.
340 340 \layout Itemize
341 341
342 342 Embeddable.
343 343 You can call IPython as a python shell inside your own python programs.
344 344 This can be used both for debugging code or for providing interactive abilities
345 345 to your programs with knowledge about the local namespaces (very useful
346 346 in debugging and data analysis situations).
347 347 \layout Itemize
348 348
349 349 Easy debugger access.
350 350 You can set IPython to call up an enhanced version of the Python debugger
351 351 (
352 352 \family typewriter
353 353 pdb
354 354 \family default
355 355 ) every time there is an uncaught exception.
356 356 This drops you inside the code which triggered the exception with all the
357 357 data live and it is possible to navigate the stack to rapidly isolate the
358 358 source of a bug.
359 359 The
360 360 \family typewriter
361 361 %run
362 362 \family default
363 363 magic command --with the
364 364 \family typewriter
365 365 -d
366 366 \family default
367 367 option-- can run any script under
368 368 \family typewriter
369 369 pdb
370 370 \family default
371 371 's control, automatically setting initial breakpoints for you.
372 372 This version of
373 373 \family typewriter
374 374 pdb
375 375 \family default
376 376 has IPython-specific improvements, including tab-completion and traceback
377 377 coloring support.
378 378 \layout Itemize
379 379
380 380 Profiler support.
381 381 You can run single statements (similar to
382 382 \family typewriter
383 383 profile.run()
384 384 \family default
385 385 ) or complete programs under the profiler's control.
386 386 While this is possible with the standard
387 387 \family typewriter
388 388 profile
389 389 \family default
390 390 module, IPython wraps this functionality with magic commands (see
391 391 \family typewriter
392 392 `%prun'
393 393 \family default
394 394 and
395 395 \family typewriter
396 396 `%run -p
397 397 \family default
398 398 ') convenient for rapid interactive work.
399 399 \layout Subsection
400 400
401 401 Portability and Python requirements
402 402 \layout Standard
403 403
404 404
405 405 \series bold
406 406 Python requirements:
407 407 \series default
408 408 IPython works with Python version 2.2 or newer.
409 409 It has been tested with Python 2.4 and no problems have been reported.
410 410 Support for Python 2.1 hasn't been recently tested, since I don't have access
411 411 to it on any of my systems.
412 412 But I suspect there may be some problems with Python 2.1, because some of
413 413 the newer code may use 2.2 features.
414 414 \layout Standard
415 415
416 416 IPython is developed under
417 417 \series bold
418 418 Linux
419 419 \series default
420 420 , but it should work in any reasonable Unix-type system (tested OK under
421 421 Solaris and the *BSD family, for which a port exists thanks to Dryice Liu).
422 422 \layout Standard
423 423
424 424
425 425 \series bold
426 426 Mac OS X
427 427 \series default
428 428 : it works, apparently without any problems (thanks to Jim Boyle at Lawrence
429 429 Livermore for the information).
430 430 Thanks to Andrea Riciputi, Fink support is available.
431 431 \layout Standard
432 432
433 433
434 434 \series bold
435 435 CygWin
436 436 \series default
437 437 : it works mostly OK, though some users have reported problems with prompt
438 438 coloring.
439 439 No satisfactory solution to this has been found so far, you may want to
440 440 disable colors permanently in the
441 441 \family typewriter
442 442 ipythonrc
443 443 \family default
444 444 configuration file if you experience problems.
445 445 If you have proper color support under cygwin, please post to the IPython
446 446 mailing list so this issue can be resolved for all users.
447 447 \layout Standard
448 448
449 449
450 450 \series bold
451 451 Windows
452 452 \series default
453 453 : it works well under Windows XP/2k, and I suspect NT should behave similarly.
454 454 Section\SpecialChar ~
455 455
456 456 \begin_inset LatexCommand \ref{sub:Under-Windows}
457 457
458 458 \end_inset
459 459
460 460 describes installation details for Windows, including some additional tools
461 461 needed on this platform.
462 462 \layout Standard
463 463
464 464 Windows 9x support is present, and has been reported to work fine (at least
465 465 on WinME).
466 466 \layout Standard
467 467
468 468 Please note, however, that I have very little access to and experience with
469 469 Windows development.
470 470 For this reason, Windows-specific bugs tend to linger far longer than I
471 471 would like, and often I just can't find a satisfactory solution.
472 472 If any Windows user wants to join in with development help, all hands are
473 473 always welcome.
474 474 \layout Subsection
475 475
476 476 Location
477 477 \layout Standard
478 478
479 479 IPython is generously hosted at
480 480 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
481 481
482 482 \end_inset
483 483
484 484 by the SciPy project.
485 485 This site offers downloads, subversion access, mailing lists and a bug
486 486 tracking system.
487 487 I am very grateful to Enthought (
488 488 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
489 489
490 490 \end_inset
491 491
492 492 ) and all of the SciPy team for their contribution.
493 493 \layout Section
494 494
495 495
496 496 \begin_inset LatexCommand \label{sec:install}
497 497
498 498 \end_inset
499 499
500 500 Installation
501 501 \layout Subsection
502 502
503 503 Instant instructions
504 504 \layout Standard
505 505
506 506 If you are of the impatient kind, under Linux/Unix simply untar/unzip the
507 507 download, then install with
508 508 \family typewriter
509 509 `python setup.py install'
510 510 \family default
511 511 .
512 512 Under Windows, double-click on the provided
513 513 \family typewriter
514 514 .exe
515 515 \family default
516 516 binary installer.
517 517 \layout Standard
518 518
519 519 Then, take a look at Sections
520 520 \begin_inset LatexCommand \ref{sec:good_config}
521 521
522 522 \end_inset
523 523
524 524 for configuring things optimally and
525 525 \begin_inset LatexCommand \ref{sec:quick_tips}
526 526
527 527 \end_inset
528 528
529 529 for quick tips on efficient use of IPython.
530 530 You can later refer to the rest of the manual for all the gory details.
531 531 \layout Standard
532 532
533 533 See the notes in sec.
534 534
535 535 \begin_inset LatexCommand \ref{sec:upgrade}
536 536
537 537 \end_inset
538 538
539 539 for upgrading IPython versions.
540 540 \layout Subsection
541 541
542 542 Detailed Unix instructions (Linux, Mac OS X, etc.)
543 543 \layout Standard
544 544
545 545 For RPM based systems, simply install the supplied package in the usual
546 546 manner.
547 547 If you download the tar archive, the process is:
548 548 \layout Enumerate
549 549
550 550 Unzip/untar the
551 551 \family typewriter
552 552 ipython-XXX.tar.gz
553 553 \family default
554 554 file wherever you want (
555 555 \family typewriter
556 556 XXX
557 557 \family default
558 558 is the version number).
559 559 It will make a directory called
560 560 \family typewriter
561 561 ipython-XXX.
562 562
563 563 \family default
564 564 Change into that directory where you will find the files
565 565 \family typewriter
566 566 README
567 567 \family default
568 568 and
569 569 \family typewriter
570 570 setup.py
571 571 \family default
572 572 .
573 573
574 574 \family typewriter
575 575 O
576 576 \family default
577 577 nce you've completed the installation, you can safely remove this directory.
578 578
579 579 \layout Enumerate
580 580
581 581 If you are installing over a previous installation of version 0.2.0 or earlier,
582 582 first remove your
583 583 \family typewriter
584 584 $HOME/.ipython
585 585 \family default
586 586 directory, since the configuration file format has changed somewhat (the
587 587 '=' were removed from all option specifications).
588 588 Or you can call ipython with the
589 589 \family typewriter
590 590 -upgrade
591 591 \family default
592 592 option and it will do this automatically for you.
593 593 \layout Enumerate
594 594
595 595 IPython uses distutils, so you can install it by simply typing at the system
596 596 prompt (don't type the
597 597 \family typewriter
598 598 $
599 599 \family default
600 600 )
601 601 \newline
602 602
603 603 \family typewriter
604 604 $ python setup.py install
605 605 \family default
606 606
607 607 \newline
608 608 Note that this assumes you have root access to your machine.
609 609 If you don't have root access or don't want IPython to go in the default
610 610 python directories, you'll need to use the
611 611 \begin_inset ERT
612 612 status Collapsed
613 613
614 614 \layout Standard
615 615
616 616 \backslash
617 617 verb|--home|
618 618 \end_inset
619 619
620 620 option (or
621 621 \begin_inset ERT
622 622 status Collapsed
623 623
624 624 \layout Standard
625 625
626 626 \backslash
627 627 verb|--prefix|
628 628 \end_inset
629 629
630 630 ).
631 631 For example:
632 632 \newline
633 633
634 634 \begin_inset ERT
635 635 status Collapsed
636 636
637 637 \layout Standard
638 638
639 639 \backslash
640 640 verb|$ python setup.py install --home $HOME/local|
641 641 \end_inset
642 642
643 643
644 644 \newline
645 645 will install IPython into
646 646 \family typewriter
647 647 $HOME/local
648 648 \family default
649 649 and its subdirectories (creating them if necessary).
650 650 \newline
651 651 You can type
652 652 \newline
653 653
654 654 \begin_inset ERT
655 655 status Collapsed
656 656
657 657 \layout Standard
658 658
659 659 \backslash
660 660 verb|$ python setup.py --help|
661 661 \end_inset
662 662
663 663
664 664 \newline
665 665 for more details.
666 666 \newline
667 667 Note that if you change the default location for
668 668 \begin_inset ERT
669 669 status Collapsed
670 670
671 671 \layout Standard
672 672
673 673 \backslash
674 674 verb|--home|
675 675 \end_inset
676 676
677 677 at installation, IPython may end up installed at a location which is not
678 678 part of your
679 679 \family typewriter
680 680 $PYTHONPATH
681 681 \family default
682 682 environment variable.
683 683 In this case, you'll need to configure this variable to include the actual
684 684 directory where the
685 685 \family typewriter
686 686 IPython/
687 687 \family default
688 688 directory ended (typically the value you give to
689 689 \begin_inset ERT
690 690 status Collapsed
691 691
692 692 \layout Standard
693 693
694 694 \backslash
695 695 verb|--home|
696 696 \end_inset
697 697
698 698 plus
699 699 \family typewriter
700 700 /lib/python
701 701 \family default
702 702 ).
703 703 \layout Subsubsection
704 704
705 705 Mac OSX information
706 706 \layout Standard
707 707
708 708 Under OSX, there is a choice you need to make.
709 709 Apple ships its own build of Python, which lives in the core OSX filesystem
710 710 hierarchy.
711 711 You can also manually install a separate Python, either purely by hand
712 712 (typically in
713 713 \family typewriter
714 714 /usr/local
715 715 \family default
716 716 ) or by using Fink, which puts everything under
717 717 \family typewriter
718 718 /sw
719 719 \family default
720 720 .
721 721 Which route to follow is a matter of personal preference, as I've seen
722 722 users who favor each of the approaches.
723 723 Here I will simply list the known installation issues under OSX, along
724 724 with their solutions.
725 725 \layout Standard
726 726
727 727 This page:
728 728 \begin_inset LatexCommand \htmlurl{http://geosci.uchicago.edu/~tobis/pylab.html}
729 729
730 730 \end_inset
731 731
732 732 contains information on this topic, with additional details on how to make
733 733 IPython and matplotlib play nicely under OSX.
734 734 \layout Subsubsection*
735 735
736 736 GUI problems
737 737 \layout Standard
738 738
739 739 The following instructions apply to an install of IPython under OSX from
740 740 unpacking the
741 741 \family typewriter
742 742 .tar.gz
743 743 \family default
744 744 distribution and installing it for the default Python interpreter shipped
745 745 by Apple.
746 746 If you are using a fink install, fink will take care of these details for
747 747 you, by installing IPython against fink's Python.
748 748 \layout Standard
749 749
750 750 IPython offers various forms of support for interacting with graphical applicati
751 751 ons from the command line, from simple Tk apps (which are in principle always
752 752 supported by Python) to interactive control of WX, Qt and GTK apps.
753 753 Under OSX, however, this requires that ipython is installed by calling
754 754 the special
755 755 \family typewriter
756 756 pythonw
757 757 \family default
758 758 script at installation time, which takes care of coordinating things with
759 759 Apple's graphical environment.
760 760 \layout Standard
761 761
762 762 So when installing under OSX, it is best to use the following command:
763 763 \family typewriter
764 764
765 765 \newline
766 766
767 767 \family default
768 768
769 769 \begin_inset ERT
770 770 status Collapsed
771 771
772 772 \layout Standard
773 773
774 774 \backslash
775 775 verb| $ sudo pythonw setup.py install --install-scripts=/usr/local/bin|
776 776 \end_inset
777 777
778 778
779 779 \newline
780 780 or
781 781 \newline
782 782
783 783 \begin_inset ERT
784 784 status Open
785 785
786 786 \layout Standard
787 787
788 788 \backslash
789 789 verb| $ sudo pythonw setup.py install --install-scripts=/usr/bin|
790 790 \end_inset
791 791
792 792
793 793 \newline
794 794 depending on where you like to keep hand-installed executables.
795 795 \layout Standard
796 796
797 797 The resulting script will have an appropriate shebang line (the first line
798 798 in the script whic begins with
799 799 \family typewriter
800 800 #!...
801 801 \family default
802 802 ) such that the ipython interpreter can interact with the OS X GUI.
803 803 If the installed version does not work and has a shebang line that points
804 804 to, for example, just
805 805 \family typewriter
806 806 /usr/bin/python
807 807 \family default
808 808 , then you might have a stale, cached version in your
809 809 \family typewriter
810 810 build/scripts-<python-version>
811 811 \family default
812 812 directory.
813 813 Delete that directory and rerun the
814 814 \family typewriter
815 815 setup.py
816 816 \family default
817 817 .
818 818
819 819 \layout Standard
820 820
821 821 It is also a good idea to use the special flag
822 822 \begin_inset ERT
823 823 status Collapsed
824 824
825 825 \layout Standard
826 826
827 827 \backslash
828 828 verb|--install-scripts|
829 829 \end_inset
830 830
831 831 as indicated above, to ensure that the ipython scripts end up in a location
832 832 which is part of your
833 833 \family typewriter
834 834 $PATH
835 835 \family default
836 836 .
837 837 Otherwise Apple's Python will put the scripts in an internal directory
838 838 not available by default at the command line (if you use
839 839 \family typewriter
840 840 /usr/local/bin
841 841 \family default
842 842 , you need to make sure this is in your
843 843 \family typewriter
844 844 $PATH
845 845 \family default
846 846 , which may not be true by default).
847 847 \layout Subsubsection*
848 848
849 849 Readline problems
850 850 \layout Standard
851 851
852 852 By default, the Python version shipped by Apple does
853 853 \emph on
854 854 not
855 855 \emph default
856 856 include the readline library, so central to IPython's behavior.
857 857 If you install IPython against Apple's Python, you will not have arrow
858 858 keys, tab completion, etc.
859 859 For Mac OSX 10.3 (Panther), you can find a prebuilt readline library here:
860 860 \newline
861 861
862 862 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip}
863 863
864 864 \end_inset
865 865
866 866
867 867 \layout Standard
868 868
869 869 If you are using OSX 10.4 (Tiger), after installing this package you need
870 870 to either:
871 871 \layout Enumerate
872 872
873 873 move
874 874 \family typewriter
875 875 readline.so
876 876 \family default
877 877 from
878 878 \family typewriter
879 879 /Library/Python/2.3
880 880 \family default
881 881 to
882 882 \family typewriter
883 883 /Library/Python/2.3/site-packages
884 884 \family default
885 885 , or
886 886 \layout Enumerate
887 887
888 888 install
889 889 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/TigerPython23Compat.pkg.zip}
890 890
891 891 \end_inset
892 892
893 893
894 894 \layout Standard
895 895
896 896 Users installing against Fink's Python or a properly hand-built one should
897 897 not have this problem.
898 898 \layout Subsubsection*
899 899
900 900 DarwinPorts
901 901 \layout Standard
902 902
903 903 I report here a message from an OSX user, who suggests an alternative means
904 904 of using IPython under this operating system with good results.
905 905 Please let me know of any updates that may be useful for this section.
906 906 His message is reproduced verbatim below:
907 907 \layout Quote
908 908
909 909 From: Markus Banfi
910 910 \family typewriter
911 911 <markus.banfi-AT-mospheira.net>
912 912 \layout Quote
913 913
914 914 As a MacOS X (10.4.2) user I prefer to install software using DawinPorts instead
915 915 of Fink.
916 916 I had no problems installing ipython with DarwinPorts.
917 917 It's just:
918 918 \layout Quote
919 919
920 920
921 921 \family typewriter
922 922 sudo port install py-ipython
923 923 \layout Quote
924 924
925 925 It automatically resolved all dependencies (python24, readline, py-readline).
926 926 So far I did not encounter any problems with the DarwinPorts port of ipython.
927 927
928 928 \layout Subsection
929 929
930 930
931 931 \begin_inset LatexCommand \label{sub:Under-Windows}
932 932
933 933 \end_inset
934 934
935 935 Windows instructions
936 936 \layout Standard
937 937
938 While you can use IPython under Windows with only a stock Python installation,
939 there is one extension,
940 \family typewriter
941 readline
942 \family default
943 , which will make the whole experience a lot more pleasant.
944 It is almost a requirement, since IPython will complain in its absence
945 (though it will function).
946
938 Some of IPython's very useful features are:
939 \layout Itemize
940
941 Integrated readline support (Tab-based file, object and attribute completion,
942 input history across sessions, editable command line, etc.)
943 \layout Itemize
944
945 Coloring of prompts, code and tracebacks.
946 \layout Standard
947
948 These, by default, are only available under Unix-like operating systems.
949 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
950 from them.
951 His readline library implements both GNU readline functionality and color
952 support, so that IPython under Windows XP/2k can be as friendly and powerful
953 as under Unix-like environments.
947 954 \layout Standard
948 955
949 956 The
950 957 \family typewriter
951 958 readline
952 959 \family default
953 960 extension needs two other libraries to work, so in all you need:
954 961 \layout Enumerate
955 962
956 963
957 964 \family typewriter
958 965 PyWin32
959 966 \family default
960 967 from
961 968 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
962 969
963 970 \end_inset
964 971
965 972 .
966 973 \layout Enumerate
967 974
968 975
969 976 \family typewriter
970 977 CTypes
971 978 \family default
972 979 from
973 980 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
974 981
975 982 \end_inset
976 983
977 984 (you
978 985 \emph on
979 986 must
980 987 \emph default
981 988 use version 0.9.1 or newer).
982 989 \layout Enumerate
983 990
984 991
985 992 \family typewriter
986 993 Readline
987 994 \family default
988 995 for Windows from
989 996 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
990 997
991 998 \end_inset
992 999
993 1000 .
994 1001 \layout Standard
995 1002
996 1003
997 1004 \series bold
998 1005 Warning about a broken readline-like library:
999 1006 \series default
1000 1007 several users have reported problems stemming from using the pseudo-readline
1001 1008 library at
1002 1009 \begin_inset LatexCommand \htmlurl{http://newcenturycomputers.net/projects/readline.html}
1003 1010
1004 1011 \end_inset
1005 1012
1006 1013 .
1007 1014 This is a broken library which, while called readline, only implements
1008 1015 an incomplete subset of the readline API.
1009 1016 Since it is still called readline, it fools IPython's detection mechanisms
1010 1017 and causes unpredictable crashes later.
1011 1018 If you wish to use IPython under Windows, you must NOT use this library,
1012 1019 which for all purposes is (at least as of version 1.6) terminally broken.
1013 1020 \layout Subsubsection
1014 1021
1015 Gary Bishop's readline and color support for Windows
1016 \layout Standard
1017
1018 Some of IPython's very useful features are:
1019 \layout Itemize
1020
1021 Integrated readline support (Tab-based file, object and attribute completion,
1022 input history across sessions, editable command line, etc.)
1023 \layout Itemize
1024
1025 Coloring of prompts, code and tracebacks.
1026 \layout Standard
1027
1028 These, by default, are only available under Unix-like operating systems.
1029 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
1030 from them.
1031 His readline library implements both GNU readline functionality and color
1032 support, so that IPython under Windows XP/2k can be as friendly and powerful
1033 as under Unix-like environments.
1034 \layout Standard
1035
1036 You can find Gary's tools at
1037 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
1038
1039 \end_inset
1040
1041 ; Gary's
1042 \family typewriter
1043 readline
1044 \family default
1045 requires in turn the
1046 \family typewriter
1047 ctypes
1048 \family default
1049 library by Thomas Heller, available at
1050 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
1051
1052 \end_inset
1053
1054 , and Mark Hammond's
1055 \family typewriter
1056 PyWin32
1057 \family default
1058 from
1059 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
1060
1061 \end_inset
1062
1063 (
1064 \family typewriter
1065 PyWin32
1066 \family default
1067 is great for anything Windows-related anyway, so you might as well get
1068 it).
1069 \layout Standard
1070
1071 Under MS\SpecialChar ~
1072 Windows, IPython will complain if it can not find this
1073 \family typewriter
1074 readline
1075 \family default
1076 library at startup and any time the
1077 \family typewriter
1078 %colors
1079 \family default
1080 command is issued, so you can consider it to be a quasi-requirement.
1081 \layout Subsubsection
1082
1083 1022 Installation procedure
1084 1023 \layout Standard
1085 1024
1086 1025 Once you have the above installed, from the IPython download directory grab
1087 1026 the
1088 1027 \family typewriter
1089 1028 ipython-XXX.win32.exe
1090 1029 \family default
1091 1030 file, where
1092 1031 \family typewriter
1093 1032 XXX
1094 1033 \family default
1095 1034 represents the version number.
1096 1035 This is a regular windows executable installer, which you can simply double-cli
1097 1036 ck to install.
1098 1037 It will add an entry for IPython to your Start Menu, as well as registering
1099 1038 IPython in the Windows list of applications, so you can later uninstall
1100 1039 it from the Control Panel.
1101 1040
1102 1041 \layout Standard
1103 1042
1104 1043 IPython tries to install the configuration information in a directory named
1105 1044
1106 1045 \family typewriter
1107 1046 .ipython
1108 1047 \family default
1109 1048 (
1110 1049 \family typewriter
1111 1050 _ipython
1112 1051 \family default
1113 1052 under Windows) located in your `home' directory.
1114 1053 IPython sets this directory by looking for a
1115 1054 \family typewriter
1116 1055 HOME
1117 1056 \family default
1118 1057 environment variable; if such a variable does not exist, it uses
1119 1058 \family typewriter
1120 1059 HOMEDRIVE
1121 1060 \backslash
1122 1061 HOMEPATH
1123 1062 \family default
1124 1063 (these are always defined by Windows).
1125 1064 This typically gives something like
1126 1065 \family typewriter
1127 1066 C:
1128 1067 \backslash
1129 1068 Documents and Settings
1130 1069 \backslash
1131 1070 YourUserName
1132 1071 \family default
1133 1072 , but your local details may vary.
1134 1073 In this directory you will find all the files that configure IPython's
1135 1074 defaults, and you can put there your profiles and extensions.
1136 1075 This directory is automatically added by IPython to
1137 1076 \family typewriter
1138 1077 sys.path
1139 1078 \family default
1140 1079 , so anything you place there can be found by
1141 1080 \family typewriter
1142 1081 import
1143 1082 \family default
1144 1083 statements.
1145 1084 \layout Paragraph
1146 1085
1147 1086 Upgrading
1148 1087 \layout Standard
1149 1088
1150 1089 For an IPython upgrade, you should first uninstall the previous version.
1151 1090 This will ensure that all files and directories (such as the documentation)
1152 1091 which carry embedded version strings in their names are properly removed.
1153 1092 \layout Paragraph
1154 1093
1155 1094 Manual installation under Win32
1156 1095 \layout Standard
1157 1096
1158 1097 In case the automatic installer does not work for some reason, you can download
1159 1098 the
1160 1099 \family typewriter
1161 1100 ipython-XXX.tar.gz
1162 1101 \family default
1163 1102 file, which contains the full IPython source distribution (the popular
1164 1103 WinZip can read
1165 1104 \family typewriter
1166 1105 .tar.gz
1167 1106 \family default
1168 1107 files).
1169 1108 After uncompressing the archive, you can install it at a command terminal
1170 1109 just like any other Python module, by using
1171 1110 \family typewriter
1172 1111 `python setup.py install'
1173 1112 \family default
1174 1113 .
1175 1114
1176 1115 \layout Standard
1177 1116
1178 1117 After the installation, run the supplied
1179 1118 \family typewriter
1180 1119 win32_manual_post_install.py
1181 1120 \family default
1182 1121 script, which creates the necessary Start Menu shortcuts for you.
1183 1122 \layout Subsection
1184 1123
1185 1124
1186 1125 \begin_inset LatexCommand \label{sec:upgrade}
1187 1126
1188 1127 \end_inset
1189 1128
1190 1129 Upgrading from a previous version
1191 1130 \layout Standard
1192 1131
1193 1132 If you are upgrading from a previous version of IPython, after doing the
1194 1133 routine installation described above, you should call IPython with the
1195 1134
1196 1135 \family typewriter
1197 1136 -upgrade
1198 1137 \family default
1199 1138 option the first time you run your new copy.
1200 1139 This will automatically update your configuration directory while preserving
1201 1140 copies of your old files.
1202 1141 You can then later merge back any personal customizations you may have
1203 1142 made into the new files.
1204 1143 It is a good idea to do this as there may be new options available in the
1205 1144 new configuration files which you will not have.
1206 1145 \layout Standard
1207 1146
1208 1147 Under Windows, if you don't know how to call python scripts with arguments
1209 1148 from a command line, simply delete the old config directory and IPython
1210 1149 will make a new one.
1211 1150 Win2k and WinXP users will find it in
1212 1151 \family typewriter
1213 1152 C:
1214 1153 \backslash
1215 1154 Documents and Settings
1216 1155 \backslash
1217 1156 YourUserName
1218 1157 \backslash
1219 1158 _ipython
1220 1159 \family default
1221 1160 , and Win 9x users under
1222 1161 \family typewriter
1223 1162 C:
1224 1163 \backslash
1225 1164 Program Files
1226 1165 \backslash
1227 1166 IPython
1228 1167 \backslash
1229 1168 _ipython.
1230 1169 \layout Section
1231 1170
1232 1171
1233 1172 \begin_inset LatexCommand \label{sec:good_config}
1234 1173
1235 1174 \end_inset
1236 1175
1237 1176
1238 1177 \begin_inset OptArg
1239 1178 collapsed true
1240 1179
1241 1180 \layout Standard
1242 1181
1243 1182 Initial configuration
1244 1183 \begin_inset ERT
1245 1184 status Collapsed
1246 1185
1247 1186 \layout Standard
1248 1187
1249 1188 \backslash
1250 1189 ldots
1251 1190 \end_inset
1252 1191
1253 1192
1254 1193 \end_inset
1255 1194
1256 1195 Initial configuration of your environment
1257 1196 \layout Standard
1258 1197
1259 1198 This section will help you set various things in your environment for your
1260 1199 IPython sessions to be as efficient as possible.
1261 1200 All of IPython's configuration information, along with several example
1262 1201 files, is stored in a directory named by default
1263 1202 \family typewriter
1264 1203 $HOME/.ipython
1265 1204 \family default
1266 1205 .
1267 1206 You can change this by defining the environment variable
1268 1207 \family typewriter
1269 1208 IPYTHONDIR
1270 1209 \family default
1271 1210 , or at runtime with the command line option
1272 1211 \family typewriter
1273 1212 -ipythondir
1274 1213 \family default
1275 1214 .
1276 1215 \layout Standard
1277 1216
1278 1217 If all goes well, the first time you run IPython it should automatically
1279 1218 create a user copy of the config directory for you, based on its builtin
1280 1219 defaults.
1281 1220 You can look at the files it creates to learn more about configuring the
1282 1221 system.
1283 1222 The main file you will modify to configure IPython's behavior is called
1284 1223
1285 1224 \family typewriter
1286 1225 ipythonrc
1287 1226 \family default
1288 1227 (with a
1289 1228 \family typewriter
1290 1229 .ini
1291 1230 \family default
1292 1231 extension under Windows), included for reference in Sec.
1293 1232
1294 1233 \begin_inset LatexCommand \ref{sec:ipytonrc-sample}
1295 1234
1296 1235 \end_inset
1297 1236
1298 1237 .
1299 1238 This file is very commented and has many variables you can change to suit
1300 1239 your taste, you can find more details in Sec.
1301 1240
1302 1241 \begin_inset LatexCommand \ref{sec:customization}
1303 1242
1304 1243 \end_inset
1305 1244
1306 1245 .
1307 1246 Here we discuss the basic things you will want to make sure things are
1308 1247 working properly from the beginning.
1309 1248 \layout Subsection
1310 1249
1311 1250
1312 1251 \begin_inset LatexCommand \label{sec:help-access}
1313 1252
1314 1253 \end_inset
1315 1254
1316 1255 Access to the Python help system
1317 1256 \layout Standard
1318 1257
1319 1258 This is true for Python in general (not just for IPython): you should have
1320 1259 an environment variable called
1321 1260 \family typewriter
1322 1261 PYTHONDOCS
1323 1262 \family default
1324 1263 pointing to the directory where your HTML Python documentation lives.
1325 1264 In my system it's
1326 1265 \family typewriter
1327 1266 /usr/share/doc/python-docs-2.3.4/html
1328 1267 \family default
1329 1268 , check your local details or ask your systems administrator.
1330 1269
1331 1270 \layout Standard
1332 1271
1333 1272 This is the directory which holds the HTML version of the Python manuals.
1334 1273 Unfortunately it seems that different Linux distributions package these
1335 1274 files differently, so you may have to look around a bit.
1336 1275 Below I show the contents of this directory on my system for reference:
1337 1276 \layout Standard
1338 1277
1339 1278
1340 1279 \family typewriter
1341 1280 [html]> ls
1342 1281 \newline
1343 1282 about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/
1344 1283 about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
1345 1284 \layout Standard
1346 1285
1347 1286 You should really make sure this variable is correctly set so that Python's
1348 1287 pydoc-based help system works.
1349 1288 It is a powerful and convenient system with full access to the Python manuals
1350 1289 and all modules accessible to you.
1351 1290 \layout Standard
1352 1291
1353 1292 Under Windows it seems that pydoc finds the documentation automatically,
1354 1293 so no extra setup appears necessary.
1355 1294 \layout Subsection
1356 1295
1357 1296 Editor
1358 1297 \layout Standard
1359 1298
1360 1299 The
1361 1300 \family typewriter
1362 1301 %edit
1363 1302 \family default
1364 1303 command (and its alias
1365 1304 \family typewriter
1366 1305 %ed
1367 1306 \family default
1368 1307 ) will invoke the editor set in your environment as
1369 1308 \family typewriter
1370 1309 EDITOR
1371 1310 \family default
1372 1311 .
1373 1312 If this variable is not set, it will default to
1374 1313 \family typewriter
1375 1314 vi
1376 1315 \family default
1377 1316 under Linux/Unix and to
1378 1317 \family typewriter
1379 1318 notepad
1380 1319 \family default
1381 1320 under Windows.
1382 1321 You may want to set this variable properly and to a lightweight editor
1383 1322 which doesn't take too long to start (that is, something other than a new
1384 1323 instance of
1385 1324 \family typewriter
1386 1325 Emacs
1387 1326 \family default
1388 1327 ).
1389 1328 This way you can edit multi-line code quickly and with the power of a real
1390 1329 editor right inside IPython.
1391 1330
1392 1331 \layout Standard
1393 1332
1394 1333 If you are a dedicated
1395 1334 \family typewriter
1396 1335 Emacs
1397 1336 \family default
1398 1337 user, you should set up the
1399 1338 \family typewriter
1400 1339 Emacs
1401 1340 \family default
1402 1341 server so that new requests are handled by the original process.
1403 1342 This means that almost no time is spent in handling the request (assuming
1404 1343 an
1405 1344 \family typewriter
1406 1345 Emacs
1407 1346 \family default
1408 1347 process is already running).
1409 1348 For this to work, you need to set your
1410 1349 \family typewriter
1411 1350 EDITOR
1412 1351 \family default
1413 1352 environment variable to
1414 1353 \family typewriter
1415 1354 'emacsclient'
1416 1355 \family default
1417 1356 .
1418 1357
1419 1358 \family typewriter
1420 1359
1421 1360 \family default
1422 1361 The code below, supplied by Francois Pinard, can then be used in your
1423 1362 \family typewriter
1424 1363 .emacs
1425 1364 \family default
1426 1365 file to enable the server:
1427 1366 \layout Standard
1428 1367
1429 1368
1430 1369 \family typewriter
1431 1370 (defvar server-buffer-clients)
1432 1371 \newline
1433 1372 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
1434 1373 \newline
1435 1374
1436 1375 \begin_inset ERT
1437 1376 status Collapsed
1438 1377
1439 1378 \layout Standard
1440 1379
1441 1380 \backslash
1442 1381 hspace*{0mm}
1443 1382 \end_inset
1444 1383
1445 1384 \SpecialChar ~
1446 1385 \SpecialChar ~
1447 1386 (server-start)
1448 1387 \newline
1449 1388
1450 1389 \begin_inset ERT
1451 1390 status Collapsed
1452 1391
1453 1392 \layout Standard
1454 1393
1455 1394 \backslash
1456 1395 hspace*{0mm}
1457 1396 \end_inset
1458 1397
1459 1398 \SpecialChar ~
1460 1399 \SpecialChar ~
1461 1400 (defun fp-kill-server-with-buffer-routine ()
1462 1401 \newline
1463 1402
1464 1403 \begin_inset ERT
1465 1404 status Collapsed
1466 1405
1467 1406 \layout Standard
1468 1407
1469 1408 \backslash
1470 1409 hspace*{0mm}
1471 1410 \end_inset
1472 1411
1473 1412 \SpecialChar ~
1474 1413 \SpecialChar ~
1475 1414 \SpecialChar ~
1476 1415 \SpecialChar ~
1477 1416 (and server-buffer-clients (server-done)))
1478 1417 \newline
1479 1418
1480 1419 \begin_inset ERT
1481 1420 status Collapsed
1482 1421
1483 1422 \layout Standard
1484 1423
1485 1424 \backslash
1486 1425 hspace*{0mm}
1487 1426 \end_inset
1488 1427
1489 1428 \SpecialChar ~
1490 1429 \SpecialChar ~
1491 1430 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
1492 1431 \layout Standard
1493 1432
1494 1433 You can also set the value of this editor via the commmand-line option '-
1495 1434 \family typewriter
1496 1435 editor'
1497 1436 \family default
1498 1437 or in your
1499 1438 \family typewriter
1500 1439 ipythonrc
1501 1440 \family default
1502 1441 file.
1503 1442 This is useful if you wish to use specifically for IPython an editor different
1504 1443 from your typical default (and for Windows users who tend to use fewer
1505 1444 environment variables).
1506 1445 \layout Subsection
1507 1446
1508 1447 Color
1509 1448 \layout Standard
1510 1449
1511 1450 The default IPython configuration has most bells and whistles turned on
1512 1451 (they're pretty safe).
1513 1452 But there's one that
1514 1453 \emph on
1515 1454 may
1516 1455 \emph default
1517 1456 cause problems on some systems: the use of color on screen for displaying
1518 1457 information.
1519 1458 This is very useful, since IPython can show prompts and exception tracebacks
1520 1459 with various colors, display syntax-highlighted source code, and in general
1521 1460 make it easier to visually parse information.
1522 1461 \layout Standard
1523 1462
1524 1463 The following terminals seem to handle the color sequences fine:
1525 1464 \layout Itemize
1526 1465
1527 1466 Linux main text console, KDE Konsole, Gnome Terminal, E-term, rxvt, xterm.
1528 1467 \layout Itemize
1529 1468
1530 1469 CDE terminal (tested under Solaris).
1531 1470 This one boldfaces light colors.
1532 1471 \layout Itemize
1533 1472
1534 1473 (X)Emacs buffers.
1535 1474 See sec.
1536 1475 \begin_inset LatexCommand \ref{sec:emacs}
1537 1476
1538 1477 \end_inset
1539 1478
1540 1479 for more details on using IPython with (X)Emacs.
1541 1480 \layout Itemize
1542 1481
1543 1482 A Windows (XP/2k) command prompt
1544 1483 \emph on
1545 1484 with Gary Bishop's support extensions
1546 1485 \emph default
1547 1486 .
1548 1487 Gary's extensions are discussed in Sec.\SpecialChar ~
1549 1488
1550 1489 \begin_inset LatexCommand \ref{sub:Under-Windows}
1551 1490
1552 1491 \end_inset
1553 1492
1554 1493 .
1555 1494 \layout Itemize
1556 1495
1557 1496 A Windows (XP/2k) CygWin shell.
1558 1497 Although some users have reported problems; it is not clear whether there
1559 1498 is an issue for everyone or only under specific configurations.
1560 1499 If you have full color support under cygwin, please post to the IPython
1561 1500 mailing list so this issue can be resolved for all users.
1562 1501 \layout Standard
1563 1502
1564 1503 These have shown problems:
1565 1504 \layout Itemize
1566 1505
1567 1506 Windows command prompt in WinXP/2k logged into a Linux machine via telnet
1568 1507 or ssh.
1569 1508 \layout Itemize
1570 1509
1571 1510 Windows native command prompt in WinXP/2k,
1572 1511 \emph on
1573 1512 without
1574 1513 \emph default
1575 1514 Gary Bishop's extensions.
1576 1515 Once Gary's readline library is installed, the normal WinXP/2k command
1577 1516 prompt works perfectly.
1578 1517 \layout Standard
1579 1518
1580 1519 Currently the following color schemes are available:
1581 1520 \layout Itemize
1582 1521
1583 1522
1584 1523 \family typewriter
1585 1524 NoColor
1586 1525 \family default
1587 1526 : uses no color escapes at all (all escapes are empty
1588 1527 \begin_inset Quotes eld
1589 1528 \end_inset
1590 1529
1591 1530
1592 1531 \begin_inset Quotes eld
1593 1532 \end_inset
1594 1533
1595 1534 strings).
1596 1535 This 'scheme' is thus fully safe to use in any terminal.
1597 1536 \layout Itemize
1598 1537
1599 1538
1600 1539 \family typewriter
1601 1540 Linux
1602 1541 \family default
1603 1542 : works well in Linux console type environments: dark background with light
1604 1543 fonts.
1605 1544 It uses bright colors for information, so it is difficult to read if you
1606 1545 have a light colored background.
1607 1546 \layout Itemize
1608 1547
1609 1548
1610 1549 \family typewriter
1611 1550 LightBG
1612 1551 \family default
1613 1552 : the basic colors are similar to those in the
1614 1553 \family typewriter
1615 1554 Linux
1616 1555 \family default
1617 1556 scheme but darker.
1618 1557 It is easy to read in terminals with light backgrounds.
1619 1558 \layout Standard
1620 1559
1621 1560 IPython uses colors for two main groups of things: prompts and tracebacks
1622 1561 which are directly printed to the terminal, and the object introspection
1623 1562 system which passes large sets of data through a pager.
1624 1563 \layout Subsubsection
1625 1564
1626 1565 Input/Output prompts and exception tracebacks
1627 1566 \layout Standard
1628 1567
1629 1568 You can test whether the colored prompts and tracebacks work on your system
1630 1569 interactively by typing
1631 1570 \family typewriter
1632 1571 '%colors Linux'
1633 1572 \family default
1634 1573 at the prompt (use '
1635 1574 \family typewriter
1636 1575 %colors LightBG'
1637 1576 \family default
1638 1577 if your terminal has a light background).
1639 1578 If the input prompt shows garbage like:
1640 1579 \newline
1641 1580
1642 1581 \family typewriter
1643 1582 [0;32mIn [[1;32m1[0;32m]: [0;00m
1644 1583 \family default
1645 1584
1646 1585 \newline
1647 1586 instead of (in color) something like:
1648 1587 \newline
1649 1588
1650 1589 \family typewriter
1651 1590 In [1]:
1652 1591 \family default
1653 1592
1654 1593 \newline
1655 1594 this means that your terminal doesn't properly handle color escape sequences.
1656 1595 You can go to a 'no color' mode by typing '
1657 1596 \family typewriter
1658 1597 %colors NoColor
1659 1598 \family default
1660 1599 '.
1661 1600
1662 1601 \layout Standard
1663 1602
1664 1603 You can try using a different terminal emulator program.
1665 1604 To permanently set your color preferences, edit the file
1666 1605 \family typewriter
1667 1606 $HOME/.ipython/ipythonrc
1668 1607 \family default
1669 1608 and set the
1670 1609 \family typewriter
1671 1610 colors
1672 1611 \family default
1673 1612 option to the desired value.
1674 1613 \layout Subsubsection
1675 1614
1676 1615 Object details (types, docstrings, source code, etc.)
1677 1616 \layout Standard
1678 1617
1679 1618 IPython has a set of special functions for studying the objects you are
1680 1619 working with, discussed in detail in Sec.
1681 1620
1682 1621 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1683 1622
1684 1623 \end_inset
1685 1624
1686 1625 .
1687 1626 But this system relies on passing information which is longer than your
1688 1627 screen through a data pager, such as the common Unix
1689 1628 \family typewriter
1690 1629 less
1691 1630 \family default
1692 1631 and
1693 1632 \family typewriter
1694 1633 more
1695 1634 \family default
1696 1635 programs.
1697 1636 In order to be able to see this information in color, your pager needs
1698 1637 to be properly configured.
1699 1638 I strongly recommend using
1700 1639 \family typewriter
1701 1640 less
1702 1641 \family default
1703 1642 instead of
1704 1643 \family typewriter
1705 1644 more
1706 1645 \family default
1707 1646 , as it seems that
1708 1647 \family typewriter
1709 1648 more
1710 1649 \family default
1711 1650 simply can not understand colored text correctly.
1712 1651 \layout Standard
1713 1652
1714 1653 In order to configure
1715 1654 \family typewriter
1716 1655 less
1717 1656 \family default
1718 1657 as your default pager, do the following:
1719 1658 \layout Enumerate
1720 1659
1721 1660 Set the environment
1722 1661 \family typewriter
1723 1662 PAGER
1724 1663 \family default
1725 1664 variable to
1726 1665 \family typewriter
1727 1666 less
1728 1667 \family default
1729 1668 .
1730 1669 \layout Enumerate
1731 1670
1732 1671 Set the environment
1733 1672 \family typewriter
1734 1673 LESS
1735 1674 \family default
1736 1675 variable to
1737 1676 \family typewriter
1738 1677 -r
1739 1678 \family default
1740 1679 (plus any other options you always want to pass to
1741 1680 \family typewriter
1742 1681 less
1743 1682 \family default
1744 1683 by default).
1745 1684 This tells
1746 1685 \family typewriter
1747 1686 less
1748 1687 \family default
1749 1688 to properly interpret control sequences, which is how color information
1750 1689 is given to your terminal.
1751 1690 \layout Standard
1752 1691
1753 1692 For the
1754 1693 \family typewriter
1755 1694 csh
1756 1695 \family default
1757 1696 or
1758 1697 \family typewriter
1759 1698 tcsh
1760 1699 \family default
1761 1700 shells, add to your
1762 1701 \family typewriter
1763 1702 ~/.cshrc
1764 1703 \family default
1765 1704 file the lines:
1766 1705 \layout Standard
1767 1706
1768 1707
1769 1708 \family typewriter
1770 1709 setenv PAGER less
1771 1710 \newline
1772 1711 setenv LESS -r
1773 1712 \layout Standard
1774 1713
1775 1714 There is similar syntax for other Unix shells, look at your system documentation
1776 1715 for details.
1777 1716 \layout Standard
1778 1717
1779 1718 If you are on a system which lacks proper data pagers (such as Windows),
1780 1719 IPython will use a very limited builtin pager.
1781 1720 \layout Subsection
1782 1721
1783 1722
1784 1723 \begin_inset LatexCommand \label{sec:emacs}
1785 1724
1786 1725 \end_inset
1787 1726
1788 1727 (X)Emacs configuration
1789 1728 \layout Standard
1790 1729
1791 1730 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, currently
1792 1731 (X)Emacs and IPython get along very well.
1793 1732
1794 1733 \layout Standard
1795 1734
1796 1735
1797 1736 \series bold
1798 1737 Important note:
1799 1738 \series default
1800 1739 You will need to use a recent enough version of
1801 1740 \family typewriter
1802 1741 python-mode.el
1803 1742 \family default
1804 1743 , along with the file
1805 1744 \family typewriter
1806 1745 ipython.el
1807 1746 \family default
1808 1747 .
1809 1748 You can check that the version you have of
1810 1749 \family typewriter
1811 1750 python-mode.el
1812 1751 \family default
1813 1752 is new enough by either looking at the revision number in the file itself,
1814 1753 or asking for it in (X)Emacs via
1815 1754 \family typewriter
1816 1755 M-x py-version
1817 1756 \family default
1818 1757 .
1819 1758 Versions 4.68 and newer contain the necessary fixes for proper IPython support.
1820 1759 \layout Standard
1821 1760
1822 1761 The file
1823 1762 \family typewriter
1824 1763 ipython.el
1825 1764 \family default
1826 1765 is included with the IPython distribution, in the documentation directory
1827 1766 (where this manual resides in PDF and HTML formats).
1828 1767 \layout Standard
1829 1768
1830 1769 Once you put these files in your Emacs path, all you need in your
1831 1770 \family typewriter
1832 1771 .emacs
1833 1772 \family default
1834 1773 file is:
1835 1774 \layout Standard
1836 1775
1837 1776
1838 1777 \family typewriter
1839 1778 (require 'ipython)
1840 1779 \layout Standard
1841 1780
1842 1781 This should give you full support for executing code snippets via IPython,
1843 1782 opening IPython as your Python shell via
1844 1783 \family typewriter
1845 1784 C-c\SpecialChar ~
1846 1785 !
1847 1786 \family default
1848 1787 , etc.
1849 1788
1850 1789 \layout Subsubsection*
1851 1790
1852 1791 Notes
1853 1792 \layout Itemize
1854 1793
1855 1794 There is one caveat you should be aware of: you must start the IPython shell
1856 1795
1857 1796 \emph on
1858 1797 before
1859 1798 \emph default
1860 1799 attempting to execute any code regions via
1861 1800 \family typewriter
1862 1801 C-c\SpecialChar ~
1863 1802 |
1864 1803 \family default
1865 1804 .
1866 1805 Simply type
1867 1806 \family typewriter
1868 1807 C-c\SpecialChar ~
1869 1808 !
1870 1809 \family default
1871 1810 to start IPython before passing any code regions to the interpreter, and
1872 1811 you shouldn't experience any problems.
1873 1812 \newline
1874 1813 This is due to a bug in Python itself, which has been fixed for Python 2.3,
1875 1814 but exists as of Python 2.2.2 (reported as SF bug [ 737947 ]).
1876 1815 \layout Itemize
1877 1816
1878 1817 The (X)Emacs support is maintained by Alexander Schmolck, so all comments/reques
1879 1818 ts should be directed to him through the IPython mailing lists.
1880 1819
1881 1820 \layout Itemize
1882 1821
1883 1822 This code is still somewhat experimental so it's a bit rough around the
1884 1823 edges (although in practice, it works quite well).
1885 1824 \layout Itemize
1886 1825
1887 1826 Be aware that if you customize
1888 1827 \family typewriter
1889 1828 py-python-command
1890 1829 \family default
1891 1830 previously, this value will override what
1892 1831 \family typewriter
1893 1832 ipython.el
1894 1833 \family default
1895 1834 does (because loading the customization variables comes later).
1896 1835 \layout Section
1897 1836
1898 1837
1899 1838 \begin_inset LatexCommand \label{sec:quick_tips}
1900 1839
1901 1840 \end_inset
1902 1841
1903 1842 Quick tips
1904 1843 \layout Standard
1905 1844
1906 1845 IPython can be used as an improved replacement for the Python prompt, and
1907 1846 for that you don't really need to read any more of this manual.
1908 1847 But in this section we'll try to summarize a few tips on how to make the
1909 1848 most effective use of it for everyday Python development, highlighting
1910 1849 things you might miss in the rest of the manual (which is getting long).
1911 1850 We'll give references to parts in the manual which provide more detail
1912 1851 when appropriate.
1913 1852 \layout Standard
1914 1853
1915 1854 The following article by Jeremy Jones provides an introductory tutorial
1916 1855 about IPython:
1917 1856 \newline
1918 1857
1919 1858 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html}
1920 1859
1921 1860 \end_inset
1922 1861
1923 1862
1924 1863 \layout Itemize
1925 1864
1926 1865 The TAB key.
1927 1866 TAB-completion, especially for attributes, is a convenient way to explore
1928 1867 the structure of any object you're dealing with.
1929 1868 Simply type
1930 1869 \family typewriter
1931 1870 object_name.<TAB>
1932 1871 \family default
1933 1872 and a list of the object's attributes will be printed (see sec.
1934 1873
1935 1874 \begin_inset LatexCommand \ref{sec:readline}
1936 1875
1937 1876 \end_inset
1938 1877
1939 1878 for more).
1940 1879 Tab completion also works on file and directory names, which combined with
1941 1880 IPython's alias system allows you to do from within IPython many of the
1942 1881 things you normally would need the system shell for.
1943 1882
1944 1883 \layout Itemize
1945 1884
1946 1885 Explore your objects.
1947 1886 Typing
1948 1887 \family typewriter
1949 1888 object_name?
1950 1889 \family default
1951 1890 will print all sorts of details about any object, including docstrings,
1952 1891 function definition lines (for call arguments) and constructor details
1953 1892 for classes.
1954 1893 The magic commands
1955 1894 \family typewriter
1956 1895 %pdoc
1957 1896 \family default
1958 1897 ,
1959 1898 \family typewriter
1960 1899 %pdef
1961 1900 \family default
1962 1901 ,
1963 1902 \family typewriter
1964 1903 %psource
1965 1904 \family default
1966 1905 and
1967 1906 \family typewriter
1968 1907 %pfile
1969 1908 \family default
1970 1909 will respectively print the docstring, function definition line, full source
1971 1910 code and the complete file for any object (when they can be found).
1972 1911 If automagic is on (it is by default), you don't need to type the '
1973 1912 \family typewriter
1974 1913 %
1975 1914 \family default
1976 1915 ' explicitly.
1977 1916 See sec.
1978 1917
1979 1918 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1980 1919
1981 1920 \end_inset
1982 1921
1983 1922 for more.
1984 1923 \layout Itemize
1985 1924
1986 1925 The
1987 1926 \family typewriter
1988 1927 %run
1989 1928 \family default
1990 1929 magic command allows you to run any python script and load all of its data
1991 1930 directly into the interactive namespace.
1992 1931 Since the file is re-read from disk each time, changes you make to it are
1993 1932 reflected immediately (in contrast to the behavior of
1994 1933 \family typewriter
1995 1934 import
1996 1935 \family default
1997 1936 ).
1998 1937 I rarely use
1999 1938 \family typewriter
2000 1939 import
2001 1940 \family default
2002 1941 for code I am testing, relying on
2003 1942 \family typewriter
2004 1943 %run
2005 1944 \family default
2006 1945 instead.
2007 1946 See sec.
2008 1947
2009 1948 \begin_inset LatexCommand \ref{sec:magic}
2010 1949
2011 1950 \end_inset
2012 1951
2013 1952 for more on this and other magic commands, or type the name of any magic
2014 1953 command and ? to get details on it.
2015 1954 See also sec.
2016 1955
2017 1956 \begin_inset LatexCommand \ref{sec:dreload}
2018 1957
2019 1958 \end_inset
2020 1959
2021 1960 for a recursive reload command.
2022 1961 \newline
2023 1962
2024 1963 \family typewriter
2025 1964 %run
2026 1965 \family default
2027 1966 also has special flags for timing the execution of your scripts (
2028 1967 \family typewriter
2029 1968 -t
2030 1969 \family default
2031 1970 ) and for executing them under the control of either Python's
2032 1971 \family typewriter
2033 1972 pdb
2034 1973 \family default
2035 1974 debugger (
2036 1975 \family typewriter
2037 1976 -d
2038 1977 \family default
2039 1978 ) or profiler (
2040 1979 \family typewriter
2041 1980 -p
2042 1981 \family default
2043 1982 ).
2044 1983 With all of these,
2045 1984 \family typewriter
2046 1985 %run
2047 1986 \family default
2048 1987 can be used as the main tool for efficient interactive development of code
2049 1988 which you write in your editor of choice.
2050 1989 \layout Itemize
2051 1990
2052 1991 Use the Python debugger,
2053 1992 \family typewriter
2054 1993 pdb
2055 1994 \family default
2056 1995
2057 1996 \begin_inset Foot
2058 1997 collapsed true
2059 1998
2060 1999 \layout Standard
2061 2000
2062 2001 Thanks to Christian Hart and Matthew Arnison for the suggestions leading
2063 2002 to IPython's improved debugger and profiler support.
2064 2003 \end_inset
2065 2004
2066 2005 .
2067 2006 The
2068 2007 \family typewriter
2069 2008 %pdb
2070 2009 \family default
2071 2010 command allows you to toggle on and off the automatic invocation of an
2072 2011 IPython-enhanced
2073 2012 \family typewriter
2074 2013 pdb
2075 2014 \family default
2076 2015 debugger (with coloring, tab completion and more) at any uncaught exception.
2077 2016 The advantage of this is that
2078 2017 \family typewriter
2079 2018 pdb
2080 2019 \family default
2081 2020 starts
2082 2021 \emph on
2083 2022 inside
2084 2023 \emph default
2085 2024 the function where the exception occurred, with all data still available.
2086 2025 You can print variables, see code, execute statements and even walk up
2087 2026 and down the call stack to track down the true source of the problem (which
2088 2027 often is many layers in the stack above where the exception gets triggered).
2089 2028 \newline
2090 2029 Running programs with
2091 2030 \family typewriter
2092 2031 %run
2093 2032 \family default
2094 2033 and pdb active can be an efficient to develop and debug code, in many cases
2095 2034 eliminating the need for
2096 2035 \family typewriter
2097 2036 print
2098 2037 \family default
2099 2038 statements or external debugging tools.
2100 2039 I often simply put a
2101 2040 \family typewriter
2102 2041 1/0
2103 2042 \family default
2104 2043 in a place where I want to take a look so that pdb gets called, quickly
2105 2044 view whatever variables I need to or test various pieces of code and then
2106 2045 remove the
2107 2046 \family typewriter
2108 2047 1/0
2109 2048 \family default
2110 2049 .
2111 2050 \newline
2112 2051 Note also that `
2113 2052 \family typewriter
2114 2053 %run -d
2115 2054 \family default
2116 2055 ' activates
2117 2056 \family typewriter
2118 2057 pdb
2119 2058 \family default
2120 2059 and automatically sets initial breakpoints for you to step through your
2121 2060 code, watch variables, etc.
2122 2061 See Sec.\SpecialChar ~
2123 2062
2124 2063 \begin_inset LatexCommand \ref{sec:cache_output}
2125 2064
2126 2065 \end_inset
2127 2066
2128 2067 for details.
2129 2068 \layout Itemize
2130 2069
2131 2070 Use the output cache.
2132 2071 All output results are automatically stored in a global dictionary named
2133 2072
2134 2073 \family typewriter
2135 2074 Out
2136 2075 \family default
2137 2076 and variables named
2138 2077 \family typewriter
2139 2078 _1
2140 2079 \family default
2141 2080 ,
2142 2081 \family typewriter
2143 2082 _2
2144 2083 \family default
2145 2084 , etc.
2146 2085 alias them.
2147 2086 For example, the result of input line 4 is available either as
2148 2087 \family typewriter
2149 2088 Out[4]
2150 2089 \family default
2151 2090 or as
2152 2091 \family typewriter
2153 2092 _4
2154 2093 \family default
2155 2094 .
2156 2095 Additionally, three variables named
2157 2096 \family typewriter
2158 2097 _
2159 2098 \family default
2160 2099 ,
2161 2100 \family typewriter
2162 2101 __
2163 2102 \family default
2164 2103 and
2165 2104 \family typewriter
2166 2105 ___
2167 2106 \family default
2168 2107 are always kept updated with the for the last three results.
2169 2108 This allows you to recall any previous result and further use it for new
2170 2109 calculations.
2171 2110 See Sec.\SpecialChar ~
2172 2111
2173 2112 \begin_inset LatexCommand \ref{sec:cache_output}
2174 2113
2175 2114 \end_inset
2176 2115
2177 2116 for more.
2178 2117 \layout Itemize
2179 2118
2180 2119 Put a '
2181 2120 \family typewriter
2182 2121 ;
2183 2122 \family default
2184 2123 ' at the end of a line to supress the printing of output.
2185 2124 This is useful when doing calculations which generate long output you are
2186 2125 not interested in seeing.
2187 2126 The
2188 2127 \family typewriter
2189 2128 _*
2190 2129 \family default
2191 2130 variables and the
2192 2131 \family typewriter
2193 2132 Out[]
2194 2133 \family default
2195 2134 list do get updated with the contents of the output, even if it is not
2196 2135 printed.
2197 2136 You can thus still access the generated results this way for further processing.
2198 2137 \layout Itemize
2199 2138
2200 2139 A similar system exists for caching input.
2201 2140 All input is stored in a global list called
2202 2141 \family typewriter
2203 2142 In
2204 2143 \family default
2205 2144 , so you can re-execute lines 22 through 28 plus line 34 by typing
2206 2145 \family typewriter
2207 2146 'exec In[22:29]+In[34]'
2208 2147 \family default
2209 2148 (using Python slicing notation).
2210 2149 If you need to execute the same set of lines often, you can assign them
2211 2150 to a macro with the
2212 2151 \family typewriter
2213 2152 %macro
2214 2153 \family default
2215 2154
2216 2155 \family typewriter
2217 2156 function.
2218 2157
2219 2158 \family default
2220 2159 See sec.
2221 2160
2222 2161 \begin_inset LatexCommand \ref{sec:cache_input}
2223 2162
2224 2163 \end_inset
2225 2164
2226 2165 for more.
2227 2166 \layout Itemize
2228 2167
2229 2168 Use your input history.
2230 2169 The
2231 2170 \family typewriter
2232 2171 %hist
2233 2172 \family default
2234 2173 command can show you all previous input, without line numbers if desired
2235 2174 (option
2236 2175 \family typewriter
2237 2176 -n
2238 2177 \family default
2239 2178 ) so you can directly copy and paste code either back in IPython or in a
2240 2179 text editor.
2241 2180 You can also save all your history by turning on logging via
2242 2181 \family typewriter
2243 2182 %logstart
2244 2183 \family default
2245 2184 ; these logs can later be either reloaded as IPython sessions or used as
2246 2185 code for your programs.
2247 2186 \layout Itemize
2248 2187
2249 2188 Define your own macros with
2250 2189 \family typewriter
2251 2190 %macro
2252 2191 \family default
2253 2192 .
2254 2193 This can be useful for automating sequences of expressions when working
2255 2194 interactively.
2256 2195 \layout Itemize
2257 2196
2258 2197 Define your own system aliases.
2259 2198 Even though IPython gives you access to your system shell via the
2260 2199 \family typewriter
2261 2200 !
2262 2201 \family default
2263 2202 prefix, it is convenient to have aliases to the system commands you use
2264 2203 most often.
2265 2204 This allows you to work seamlessly from inside IPython with the same commands
2266 2205 you are used to in your system shell.
2267 2206 \newline
2268 2207 IPython comes with some pre-defined aliases and a complete system for changing
2269 2208 directories, both via a stack (see
2270 2209 \family typewriter
2271 2210 %pushd
2272 2211 \family default
2273 2212 ,
2274 2213 \family typewriter
2275 2214 %popd
2276 2215 \family default
2277 2216 and
2278 2217 \family typewriter
2279 2218 %ds
2280 2219 \family default
2281 2220 ) and via direct
2282 2221 \family typewriter
2283 2222 %cd
2284 2223 \family default
2285 2224 .
2286 2225 The latter keeps a history of visited directories and allows you to go
2287 2226 to any previously visited one.
2288 2227 \layout Itemize
2289 2228
2290 2229 Use Python to manipulate the results of system commands.
2291 2230 The `
2292 2231 \family typewriter
2293 2232 !!
2294 2233 \family default
2295 2234 ' special syntax, and the
2296 2235 \family typewriter
2297 2236 %sc
2298 2237 \family default
2299 2238 and
2300 2239 \family typewriter
2301 2240 %sx
2302 2241 \family default
2303 2242 magic commands allow you to capture system output into Python variables.
2304 2243 \layout Itemize
2305 2244
2306 2245 Expand python variables when calling the shell (either via
2307 2246 \family typewriter
2308 2247 `!'
2309 2248 \family default
2310 2249 and
2311 2250 \family typewriter
2312 2251 `!!'
2313 2252 \family default
2314 2253 or via aliases) by prepending a
2315 2254 \family typewriter
2316 2255 $
2317 2256 \family default
2318 2257 in front of them.
2319 2258 You can also expand complete python expressions.
2320 2259 See sec.\SpecialChar ~
2321 2260
2322 2261 \begin_inset LatexCommand \ref{sub:System-shell-access}
2323 2262
2324 2263 \end_inset
2325 2264
2326 2265 for more.
2327 2266 \layout Itemize
2328 2267
2329 2268 Use profiles to maintain different configurations (modules to load, function
2330 2269 definitions, option settings) for particular tasks.
2331 2270 You can then have customized versions of IPython for specific purposes.
2332 2271 See sec.\SpecialChar ~
2333 2272
2334 2273 \begin_inset LatexCommand \ref{sec:profiles}
2335 2274
2336 2275 \end_inset
2337 2276
2338 2277 for more.
2339 2278 \layout Itemize
2340 2279
2341 2280 Embed IPython in your programs.
2342 2281 A few lines of code are enough to load a complete IPython inside your own
2343 2282 programs, giving you the ability to work with your data interactively after
2344 2283 automatic processing has been completed.
2345 2284 See sec.\SpecialChar ~
2346 2285
2347 2286 \begin_inset LatexCommand \ref{sec:embed}
2348 2287
2349 2288 \end_inset
2350 2289
2351 2290 for more.
2352 2291 \layout Itemize
2353 2292
2354 2293 Use the Python profiler.
2355 2294 When dealing with performance issues, the
2356 2295 \family typewriter
2357 2296 %run
2358 2297 \family default
2359 2298 command with a
2360 2299 \family typewriter
2361 2300 -p
2362 2301 \family default
2363 2302 option allows you to run complete programs under the control of the Python
2364 2303 profiler.
2365 2304 The
2366 2305 \family typewriter
2367 2306 %prun
2368 2307 \family default
2369 2308 command does a similar job for single Python expressions (like function
2370 2309 calls).
2371 2310 \layout Itemize
2372 2311
2373 2312 Use
2374 2313 \family typewriter
2375 2314 %edit
2376 2315 \family default
2377 2316 to have almost multiline editing.
2378 2317 While IPython doesn't support true multiline editing, this command allows
2379 2318 you to call an editor on the spot, and IPython will execute the code you
2380 2319 type in there as if it were typed interactively.
2381 2320 \layout Itemize
2382 2321
2383 2322 Use the IPython.demo.Demo class to load any Python script as an interactive
2384 2323 demo.
2385 2324 With a minimal amount of simple markup, you can control the execution of
2386 2325 the script, stopping as needed.
2387 2326 See sec.\SpecialChar ~
2388 2327
2389 2328 \begin_inset LatexCommand \ref{sec:interactive-demos}
2390 2329
2391 2330 \end_inset
2392 2331
2393 2332 for more.
2394 2333 \layout Standard
2395 2334
2335
2336 \series bold
2337 Effective logging:
2338 \series default
2339 a very useful suggestion sent in by Robert Kern follows
2340 \layout Standard
2341
2342 I recently happened on a nifty way to keep tidy per-project log files.
2343 I made a profile for my project (which is called "parkfield").
2344 \layout LyX-Code
2345
2346 include ipythonrc
2347 \layout LyX-Code
2348
2349 logfile '' # cancel earlier logfile invocation
2350 \layout LyX-Code
2351
2352 execute import time
2353 \layout LyX-Code
2354
2355 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
2356 \layout LyX-Code
2357
2358 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
2359 \layout Standard
2360
2361 I also added a shell alias for convenience:
2362 \layout LyX-Code
2363
2364 alias parkfield="ipython -pylab -profile parkfield"
2365 \layout Standard
2366
2367 Now I have a nice little directory with everything I ever type in, organized
2368 by project and date.
2369 \layout Standard
2370
2371
2372 \series bold
2373 Contribute your own:
2374 \series default
2396 2375 If you have your own favorite tip on using IPython efficiently for a certain
2397 2376 task (especially things which can't be done in the normal Python interpreter),
2398 2377 don't hesitate to send it!
2399 2378 \layout Section
2400 2379
2401 2380 Command-line use
2402 2381 \layout Standard
2403 2382
2404 2383 You start IPython with the command:
2405 2384 \layout Standard
2406 2385
2407 2386
2408 2387 \family typewriter
2409 2388 $ ipython [options] files
2410 2389 \layout Standard
2411 2390
2412 2391 If invoked with no options, it executes all the files listed in sequence
2413 2392 and drops you into the interpreter while still acknowledging any options
2414 2393 you may have set in your ipythonrc file.
2415 2394 This behavior is different from standard Python, which when called as
2416 2395 \family typewriter
2417 2396 python -i
2418 2397 \family default
2419 2398 will only execute one file and ignore your configuration setup.
2420 2399 \layout Standard
2421 2400
2422 2401 Please note that some of the configuration options are not available at
2423 2402 the command line, simply because they are not practical here.
2424 2403 Look into your ipythonrc configuration file for details on those.
2425 2404 This file typically installed in the
2426 2405 \family typewriter
2427 2406 $HOME/.ipython
2428 2407 \family default
2429 2408 directory.
2430 2409 For Windows users,
2431 2410 \family typewriter
2432 2411 $HOME
2433 2412 \family default
2434 2413 resolves to
2435 2414 \family typewriter
2436 2415 C:
2437 2416 \backslash
2438 2417
2439 2418 \backslash
2440 2419 Documents and Settings
2441 2420 \backslash
2442 2421
2443 2422 \backslash
2444 2423 YourUserName
2445 2424 \family default
2446 2425 in most instances.
2447 2426 In the rest of this text, we will refer to this directory as
2448 2427 \family typewriter
2449 2428 IPYTHONDIR
2450 2429 \family default
2451 2430 .
2452 2431 \layout Subsection
2453 2432
2454 2433
2455 2434 \begin_inset LatexCommand \label{sec:threading-opts}
2456 2435
2457 2436 \end_inset
2458 2437
2459 2438 Special Threading Options
2460 2439 \layout Standard
2461 2440
2462 2441 The following special options are ONLY valid at the beginning of the command
2463 2442 line, and not later.
2464 2443 This is because they control the initial- ization of ipython itself, before
2465 2444 the normal option-handling mechanism is active.
2466 2445 \layout List
2467 2446 \labelwidthstring 00.00.0000
2468 2447
2469 2448
2470 2449 \family typewriter
2471 2450 \series bold
2472 2451 -gthread,\SpecialChar ~
2473 2452 -qthread,\SpecialChar ~
2474 2453 -wthread,\SpecialChar ~
2475 2454 -pylab:
2476 2455 \family default
2477 2456 \series default
2478 2457 Only
2479 2458 \emph on
2480 2459 one
2481 2460 \emph default
2482 2461 of these can be given, and it can only be given as the first option passed
2483 2462 to IPython (it will have no effect in any other position).
2484 2463 They provide threading support for the GTK Qt and WXPython toolkits, and
2485 2464 for the matplotlib library.
2486 2465 \layout List
2487 2466 \labelwidthstring 00.00.0000
2488 2467
2489 2468 \SpecialChar ~
2490 2469 With any of the first three options, IPython starts running a separate
2491 2470 thread for the graphical toolkit's operation, so that you can open and
2492 2471 control graphical elements from within an IPython command line, without
2493 2472 blocking.
2494 2473 All three provide essentially the same functionality, respectively for
2495 2474 GTK, QT and WXWidgets (via their Python interfaces).
2496 2475 \layout List
2497 2476 \labelwidthstring 00.00.0000
2498 2477
2499 2478 \SpecialChar ~
2500 2479 If
2501 2480 \family typewriter
2502 2481 -pylab
2503 2482 \family default
2504 2483 is given, IPython loads special support for the mat plotlib library (
2505 2484 \begin_inset LatexCommand \htmlurl{http://matplotlib.sourceforge.net}
2506 2485
2507 2486 \end_inset
2508 2487
2509 2488 ), allowing interactive usage of any of its backends as defined in the user's
2510 2489
2511 2490 \family typewriter
2512 2491 ~/.matplotlib/matplotlibrc
2513 2492 \family default
2514 2493 file.
2515 2494 It automatically activates GTK, Qt or WX threading for IPyhton if the choice
2516 2495 of matplotlib backend requires it.
2517 2496 It also modifies the
2518 2497 \family typewriter
2519 2498 %run
2520 2499 \family default
2521 2500 command to correctly execute (without blocking) any matplotlib-based script
2522 2501 which calls
2523 2502 \family typewriter
2524 2503 show()
2525 2504 \family default
2526 2505 at the end.
2527 2506
2528 2507 \layout List
2529 2508 \labelwidthstring 00.00.0000
2530 2509
2531 2510
2532 2511 \family typewriter
2533 2512 \series bold
2534 2513 -tk
2535 2514 \family default
2536 2515 \series default
2537 2516 The
2538 2517 \family typewriter
2539 2518 -g/q/wthread
2540 2519 \family default
2541 2520 options, and
2542 2521 \family typewriter
2543 2522 -pylab
2544 2523 \family default
2545 2524 (if matplotlib is configured to use GTK, Qt or WX), will normally block
2546 2525 Tk graphical interfaces.
2547 2526 This means that when either GTK, Qt or WX threading is active, any attempt
2548 2527 to open a Tk GUI will result in a dead window, and possibly cause the Python
2549 2528 interpreter to crash.
2550 2529 An extra option,
2551 2530 \family typewriter
2552 2531 -tk
2553 2532 \family default
2554 2533 , is available to address this issue.
2555 2534 It can
2556 2535 \emph on
2557 2536 only
2558 2537 \emph default
2559 2538 be given as a
2560 2539 \emph on
2561 2540 second
2562 2541 \emph default
2563 2542 option after any of the above (
2564 2543 \family typewriter
2565 2544 -gthread
2566 2545 \family default
2567 2546 ,
2568 2547 \family typewriter
2569 2548 -wthread
2570 2549 \family default
2571 2550 or
2572 2551 \family typewriter
2573 2552 -pylab
2574 2553 \family default
2575 2554 ).
2576 2555 \layout List
2577 2556 \labelwidthstring 00.00.0000
2578 2557
2579 2558 \SpecialChar ~
2580 2559 If
2581 2560 \family typewriter
2582 2561 -tk
2583 2562 \family default
2584 2563 is given, IPython will try to coordinate Tk threading with GTK, Qt or WX.
2585 2564 This is however potentially unreliable, and you will have to test on your
2586 2565 platform and Python configuration to determine whether it works for you.
2587 2566 Debian users have reported success, apparently due to the fact that Debian
2588 2567 builds all of Tcl, Tk, Tkinter and Python with pthreads support.
2589 2568 Under other Linux environments (such as Fedora Core 2/3), this option has
2590 2569 caused random crashes and lockups of the Python interpreter.
2591 2570 Under other operating systems (Mac OSX and Windows), you'll need to try
2592 2571 it to find out, since currently no user reports are available.
2593 2572 \layout List
2594 2573 \labelwidthstring 00.00.0000
2595 2574
2596 2575 \SpecialChar ~
2597 2576 There is unfortunately no way for IPython to determine at run time whether
2598 2577
2599 2578 \family typewriter
2600 2579 -tk
2601 2580 \family default
2602 2581 will work reliably or not, so you will need to do some experiments before
2603 2582 relying on it for regular work.
2604 2583
2605 2584 \layout Subsection
2606 2585
2607 2586
2608 2587 \begin_inset LatexCommand \label{sec:cmd-line-opts}
2609 2588
2610 2589 \end_inset
2611 2590
2612 2591 Regular Options
2613 2592 \layout Standard
2614 2593
2615 2594 After the above threading options have been given, regular options can follow
2616 2595 in any order.
2617 2596 All options can be abbreviated to their shortest non-ambiguous form and
2618 2597 are case-sensitive.
2619 2598 One or two dashes can be used.
2620 2599 Some options have an alternate short form, indicated after a
2621 2600 \family typewriter
2622 2601 |
2623 2602 \family default
2624 2603 .
2625 2604 \layout Standard
2626 2605
2627 2606 Most options can also be set from your ipythonrc configuration file.
2628 2607 See the provided example for more details on what the options do.
2629 2608 Options given at the command line override the values set in the ipythonrc
2630 2609 file.
2631 2610 \layout Standard
2632 2611
2633 2612 All options with a
2634 2613 \family typewriter
2635 2614 [no]
2636 2615 \family default
2637 2616 prepended can be specified in negated form (
2638 2617 \family typewriter
2639 2618 -nooption
2640 2619 \family default
2641 2620 instead of
2642 2621 \family typewriter
2643 2622 -option
2644 2623 \family default
2645 2624 ) to turn the feature off.
2646 2625 \layout List
2647 2626 \labelwidthstring 00.00.0000
2648 2627
2649 2628
2650 2629 \family typewriter
2651 2630 \series bold
2652 2631 -help
2653 2632 \family default
2654 2633 \series default
2655 2634 : print a help message and exit.
2656 2635 \layout List
2657 2636 \labelwidthstring 00.00.0000
2658 2637
2659 2638
2660 2639 \family typewriter
2661 2640 \series bold
2662 2641 -pylab:
2663 2642 \family default
2664 2643 \series default
2665 2644 this can
2666 2645 \emph on
2667 2646 only
2668 2647 \emph default
2669 2648 be given as the
2670 2649 \emph on
2671 2650 first
2672 2651 \emph default
2673 2652 option passed to IPython (it will have no effect in any other position).
2674 2653 It adds special support for the matplotlib library (
2675 2654 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
2676 2655
2677 2656 \end_inset
2678 2657
2679 2658 ), allowing interactive usage of any of its backends as defined in the user's
2680 2659
2681 2660 \family typewriter
2682 2661 .matplotlibrc
2683 2662 \family default
2684 2663 file.
2685 2664 It automatically activates GTK or WX threading for IPyhton if the choice
2686 2665 of matplotlib backend requires it.
2687 2666 It also modifies the
2688 2667 \family typewriter
2689 2668 %run
2690 2669 \family default
2691 2670 command to correctly execute (without blocking) any matplotlib-based script
2692 2671 which calls
2693 2672 \family typewriter
2694 2673 show()
2695 2674 \family default
2696 2675 at the end.
2697 2676 See Sec.\SpecialChar ~
2698 2677
2699 2678 \begin_inset LatexCommand \ref{sec:matplotlib-support}
2700 2679
2701 2680 \end_inset
2702 2681
2703 2682 for more details.
2704 2683 \layout List
2705 2684 \labelwidthstring 00.00.0000
2706 2685
2707 2686
2708 2687 \family typewriter
2709 2688 \series bold
2710 2689 -[no]autocall:
2711 2690 \family default
2712 2691 \series default
2713 2692 Make IPython automatically call any callable object even if you didn't
2714 2693 type explicit parentheses.
2715 2694 For example, `str 43' becomes `str(43)' automatically.
2716 2695 \layout List
2717 2696 \labelwidthstring 00.00.0000
2718 2697
2719 2698
2720 2699 \family typewriter
2721 2700 \series bold
2722 2701 -[no]autoindent:
2723 2702 \family default
2724 2703 \series default
2725 2704 Turn automatic indentation on/off.
2726 2705 \layout List
2727 2706 \labelwidthstring 00.00.0000
2728 2707
2729 2708
2730 2709 \family typewriter
2731 2710 \series bold
2732 2711 -[no]automagic
2733 2712 \series default
2734 2713 :
2735 2714 \family default
2736 2715 make magic commands automatic (without needing their first character to
2737 2716 be
2738 2717 \family typewriter
2739 2718 %
2740 2719 \family default
2741 2720 ).
2742 2721 Type
2743 2722 \family typewriter
2744 2723 %magic
2745 2724 \family default
2746 2725 at the IPython prompt for more information.
2747 2726 \layout List
2748 2727 \labelwidthstring 00.00.0000
2749 2728
2750 2729
2751 2730 \family typewriter
2752 2731 \series bold
2753 2732 -[no]autoedit_syntax:
2754 2733 \family default
2755 2734 \series default
2756 2735 When a syntax error occurs after editing a file, automatically open the
2757 2736 file to the trouble causing line for convenient fixing.
2758 2737
2759 2738 \layout List
2760 2739 \labelwidthstring 00.00.0000
2761 2740
2762 2741
2763 2742 \family typewriter
2764 2743 \series bold
2765 2744 -[no]banner
2766 2745 \series default
2767 2746 :
2768 2747 \family default
2769 2748 Print the initial information banner (default on).
2770 2749 \layout List
2771 2750 \labelwidthstring 00.00.0000
2772 2751
2773 2752
2774 2753 \family typewriter
2775 2754 \series bold
2776 2755 -c\SpecialChar ~
2777 2756 <command>:
2778 2757 \family default
2779 2758 \series default
2780 2759 execute the given command string, and set sys.argv to
2781 2760 \family typewriter
2782 2761 ['c']
2783 2762 \family default
2784 2763 .
2785 2764 This is similar to the
2786 2765 \family typewriter
2787 2766 -c
2788 2767 \family default
2789 2768 option in the normal Python interpreter.
2790 2769
2791 2770 \layout List
2792 2771 \labelwidthstring 00.00.0000
2793 2772
2794 2773
2795 2774 \family typewriter
2796 2775 \series bold
2797 2776 -cache_size|cs\SpecialChar ~
2798 2777 <n>
2799 2778 \series default
2800 2779 :
2801 2780 \family default
2802 2781 size of the output cache (maximum number of entries to hold in memory).
2803 2782 The default is 1000, you can change it permanently in your config file.
2804 2783 Setting it to 0 completely disables the caching system, and the minimum
2805 2784 value accepted is 20 (if you provide a value less than 20, it is reset
2806 2785 to 0 and a warning is issued) This limit is defined because otherwise you'll
2807 2786 spend more time re-flushing a too small cache than working.
2808 2787 \layout List
2809 2788 \labelwidthstring 00.00.0000
2810 2789
2811 2790
2812 2791 \family typewriter
2813 2792 \series bold
2814 2793 -classic|cl
2815 2794 \series default
2816 2795 :
2817 2796 \family default
2818 2797 Gives IPython a similar feel to the classic Python prompt.
2819 2798 \layout List
2820 2799 \labelwidthstring 00.00.0000
2821 2800
2822 2801
2823 2802 \family typewriter
2824 2803 \series bold
2825 2804 -colors\SpecialChar ~
2826 2805 <scheme>:
2827 2806 \family default
2828 2807 \series default
2829 2808 Color scheme for prompts and exception reporting.
2830 2809 Currently implemented: NoColor, Linux and LightBG.
2831 2810 \layout List
2832 2811 \labelwidthstring 00.00.0000
2833 2812
2834 2813
2835 2814 \family typewriter
2836 2815 \series bold
2837 2816 -[no]color_info:
2838 2817 \family default
2839 2818 \series default
2840 2819 IPython can display information about objects via a set of functions, and
2841 2820 optionally can use colors for this, syntax highlighting source code and
2842 2821 various other elements.
2843 2822 However, because this information is passed through a pager (like 'less')
2844 2823 and many pagers get confused with color codes, this option is off by default.
2845 2824 You can test it and turn it on permanently in your ipythonrc file if it
2846 2825 works for you.
2847 2826 As a reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
2848 2827 that in RedHat 7.2 doesn't.
2849 2828 \layout List
2850 2829 \labelwidthstring 00.00.0000
2851 2830
2852 2831 \SpecialChar ~
2853 2832 Test it and turn it on permanently if it works with your system.
2854 2833 The magic function
2855 2834 \family typewriter
2856 2835 %color_info
2857 2836 \family default
2858 2837 allows you to toggle this interactively for testing.
2859 2838 \layout List
2860 2839 \labelwidthstring 00.00.0000
2861 2840
2862 2841
2863 2842 \family typewriter
2864 2843 \series bold
2865 2844 -[no]debug
2866 2845 \family default
2867 2846 \series default
2868 2847 : Show information about the loading process.
2869 2848 Very useful to pin down problems with your configuration files or to get
2870 2849 details about session restores.
2871 2850 \layout List
2872 2851 \labelwidthstring 00.00.0000
2873 2852
2874 2853
2875 2854 \family typewriter
2876 2855 \series bold
2877 2856 -[no]deep_reload
2878 2857 \series default
2879 2858 :
2880 2859 \family default
2881 2860 IPython can use the
2882 2861 \family typewriter
2883 2862 deep_reload
2884 2863 \family default
2885 2864 module which reloads changes in modules recursively (it replaces the
2886 2865 \family typewriter
2887 2866 reload()
2888 2867 \family default
2889 2868 function, so you don't need to change anything to use it).
2890 2869
2891 2870 \family typewriter
2892 2871 deep_reload()
2893 2872 \family default
2894 2873 forces a full reload of modules whose code may have changed, which the
2895 2874 default
2896 2875 \family typewriter
2897 2876 reload()
2898 2877 \family default
2899 2878 function does not.
2900 2879 \layout List
2901 2880 \labelwidthstring 00.00.0000
2902 2881
2903 2882 \SpecialChar ~
2904 2883 When deep_reload is off, IPython will use the normal
2905 2884 \family typewriter
2906 2885 reload()
2907 2886 \family default
2908 2887 , but deep_reload will still be available as
2909 2888 \family typewriter
2910 2889 dreload()
2911 2890 \family default
2912 2891 .
2913 2892 This feature is off by default [which means that you have both normal
2914 2893 \family typewriter
2915 2894 reload()
2916 2895 \family default
2917 2896 and
2918 2897 \family typewriter
2919 2898 dreload()
2920 2899 \family default
2921 2900 ].
2922 2901 \layout List
2923 2902 \labelwidthstring 00.00.0000
2924 2903
2925 2904
2926 2905 \family typewriter
2927 2906 \series bold
2928 2907 -editor\SpecialChar ~
2929 2908 <name>
2930 2909 \family default
2931 2910 \series default
2932 2911 : Which editor to use with the
2933 2912 \family typewriter
2934 2913 %edit
2935 2914 \family default
2936 2915 command.
2937 2916 By default, IPython will honor your
2938 2917 \family typewriter
2939 2918 EDITOR
2940 2919 \family default
2941 2920 environment variable (if not set, vi is the Unix default and notepad the
2942 2921 Windows one).
2943 2922 Since this editor is invoked on the fly by IPython and is meant for editing
2944 2923 small code snippets, you may want to use a small, lightweight editor here
2945 2924 (in case your default
2946 2925 \family typewriter
2947 2926 EDITOR
2948 2927 \family default
2949 2928 is something like Emacs).
2950 2929 \layout List
2951 2930 \labelwidthstring 00.00.0000
2952 2931
2953 2932
2954 2933 \family typewriter
2955 2934 \series bold
2956 2935 -ipythondir\SpecialChar ~
2957 2936 <name>
2958 2937 \series default
2959 2938 :
2960 2939 \family default
2961 2940 name of your IPython configuration directory
2962 2941 \family typewriter
2963 2942 IPYTHONDIR
2964 2943 \family default
2965 2944 .
2966 2945 This can also be specified through the environment variable
2967 2946 \family typewriter
2968 2947 IPYTHONDIR
2969 2948 \family default
2970 2949 .
2971 2950 \layout List
2972 2951 \labelwidthstring 00.00.0000
2973 2952
2974 2953
2975 2954 \family typewriter
2976 2955 \series bold
2977 2956 -log|l
2978 2957 \family default
2979 2958 \series default
2980 2959 : generate a log file of all input.
2981 2960 Defaults to
2982 2961 \family typewriter
2983 2962 $IPYTHONDIR/log
2984 2963 \family default
2985 2964 .
2986 2965 You can use this to later restore a session by loading your logfile as
2987 2966 a file to be executed with option
2988 2967 \family typewriter
2989 2968 -logplay
2990 2969 \family default
2991 2970 (see below).
2992 2971 \layout List
2993 2972 \labelwidthstring 00.00.0000
2994 2973
2995 2974
2996 2975 \family typewriter
2997 2976 \series bold
2998 2977 -logfile|lf\SpecialChar ~
2999 2978 <name>
3000 2979 \series default
3001 2980 :
3002 2981 \family default
3003 2982 specify the name of your logfile.
3004 2983 \layout List
3005 2984 \labelwidthstring 00.00.0000
3006 2985
3007 2986
3008 2987 \family typewriter
3009 2988 \series bold
3010 2989 -logplay|lp\SpecialChar ~
3011 2990 <name>
3012 2991 \series default
3013 2992 :
3014 2993 \family default
3015 2994 you can replay a previous log.
3016 2995 For restoring a session as close as possible to the state you left it in,
3017 2996 use this option (don't just run the logfile).
3018 2997 With
3019 2998 \family typewriter
3020 2999 -logplay
3021 3000 \family default
3022 3001 , IPython will try to reconstruct the previous working environment in full,
3023 3002 not just execute the commands in the logfile.
3024 3003 \layout List
3025 3004 \labelwidthstring 00.00.0000
3026 3005
3027 3006 \SpecialChar ~
3028 3007 When a session is restored, logging is automatically turned on again with
3029 3008 the name of the logfile it was invoked with (it is read from the log header).
3030 3009 So once you've turned logging on for a session, you can quit IPython and
3031 3010 reload it as many times as you want and it will continue to log its history
3032 3011 and restore from the beginning every time.
3033 3012 \layout List
3034 3013 \labelwidthstring 00.00.0000
3035 3014
3036 3015 \SpecialChar ~
3037 3016 Caveats: there are limitations in this option.
3038 3017 The history variables
3039 3018 \family typewriter
3040 3019 _i*
3041 3020 \family default
3042 3021 ,
3043 3022 \family typewriter
3044 3023 _*
3045 3024 \family default
3046 3025 and
3047 3026 \family typewriter
3048 3027 _dh
3049 3028 \family default
3050 3029 don't get restored properly.
3051 3030 In the future we will try to implement full session saving by writing and
3052 3031 retrieving a 'snapshot' of the memory state of IPython.
3053 3032 But our first attempts failed because of inherent limitations of Python's
3054 3033 Pickle module, so this may have to wait.
3055 3034 \layout List
3056 3035 \labelwidthstring 00.00.0000
3057 3036
3058 3037
3059 3038 \family typewriter
3060 3039 \series bold
3061 3040 -[no]messages
3062 3041 \series default
3063 3042 :
3064 3043 \family default
3065 3044 Print messages which IPython collects about its startup process (default
3066 3045 on).
3067 3046 \layout List
3068 3047 \labelwidthstring 00.00.0000
3069 3048
3070 3049
3071 3050 \family typewriter
3072 3051 \series bold
3073 3052 -[no]pdb
3074 3053 \family default
3075 3054 \series default
3076 3055 : Automatically call the pdb debugger after every uncaught exception.
3077 3056 If you are used to debugging using pdb, this puts you automatically inside
3078 3057 of it after any call (either in IPython or in code called by it) which
3079 3058 triggers an exception which goes uncaught.
3080 3059 \layout List
3081 3060 \labelwidthstring 00.00.0000
3082 3061
3083 3062
3084 3063 \family typewriter
3085 3064 \series bold
3086 3065 -[no]pprint
3087 3066 \series default
3088 3067 :
3089 3068 \family default
3090 3069 ipython can optionally use the pprint (pretty printer) module for displaying
3091 3070 results.
3092 3071 pprint tends to give a nicer display of nested data structures.
3093 3072 If you like it, you can turn it on permanently in your config file (default
3094 3073 off).
3095 3074 \layout List
3096 3075 \labelwidthstring 00.00.0000
3097 3076
3098 3077
3099 3078 \family typewriter
3100 3079 \series bold
3101 3080 -profile|p <name>
3102 3081 \series default
3103 3082 :
3104 3083 \family default
3105 3084 assume that your config file is
3106 3085 \family typewriter
3107 3086 ipythonrc-<name>
3108 3087 \family default
3109 3088 (looks in current dir first, then in
3110 3089 \family typewriter
3111 3090 IPYTHONDIR
3112 3091 \family default
3113 3092 ).
3114 3093 This is a quick way to keep and load multiple config files for different
3115 3094 tasks, especially if you use the include option of config files.
3116 3095 You can keep a basic
3117 3096 \family typewriter
3118 3097 IPYTHONDIR/ipythonrc
3119 3098 \family default
3120 3099 file and then have other 'profiles' which include this one and load extra
3121 3100 things for particular tasks.
3122 3101 For example:
3123 3102 \layout List
3124 3103 \labelwidthstring 00.00.0000
3125 3104
3126 3105
3127 3106 \family typewriter
3128 3107 \SpecialChar ~
3129 3108
3130 3109 \family default
3131 3110 1.
3132 3111
3133 3112 \family typewriter
3134 3113 $HOME/.ipython/ipythonrc
3135 3114 \family default
3136 3115 : load basic things you always want.
3137 3116 \layout List
3138 3117 \labelwidthstring 00.00.0000
3139 3118
3140 3119
3141 3120 \family typewriter
3142 3121 \SpecialChar ~
3143 3122
3144 3123 \family default
3145 3124 2.
3146 3125
3147 3126 \family typewriter
3148 3127 $HOME/.ipython/ipythonrc-math
3149 3128 \family default
3150 3129 : load (1) and basic math-related modules.
3151 3130
3152 3131 \layout List
3153 3132 \labelwidthstring 00.00.0000
3154 3133
3155 3134
3156 3135 \family typewriter
3157 3136 \SpecialChar ~
3158 3137
3159 3138 \family default
3160 3139 3.
3161 3140
3162 3141 \family typewriter
3163 3142 $HOME/.ipython/ipythonrc-numeric
3164 3143 \family default
3165 3144 : load (1) and Numeric and plotting modules.
3166 3145 \layout List
3167 3146 \labelwidthstring 00.00.0000
3168 3147
3169 3148 \SpecialChar ~
3170 3149 Since it is possible to create an endless loop by having circular file
3171 3150 inclusions, IPython will stop if it reaches 15 recursive inclusions.
3172 3151 \layout List
3173 3152 \labelwidthstring 00.00.0000
3174 3153
3175 3154
3176 3155 \family typewriter
3177 3156 \series bold
3178 3157 -prompt_in1|pi1\SpecialChar ~
3179 3158 <string>:
3180 3159 \family default
3181 3160 \series default
3182 3161 Specify the string used for input prompts.
3183 3162 Note that if you are using numbered prompts, the number is represented
3184 3163 with a '
3185 3164 \backslash
3186 3165 #' in the string.
3187 3166 Don't forget to quote strings with spaces embedded in them.
3188 3167 Default: '
3189 3168 \family typewriter
3190 3169 In\SpecialChar ~
3191 3170 [
3192 3171 \backslash
3193 3172 #]:
3194 3173 \family default
3195 3174 '.
3196 3175 Sec.\SpecialChar ~
3197 3176
3198 3177 \begin_inset LatexCommand \ref{sec:prompts}
3199 3178
3200 3179 \end_inset
3201 3180
3202 3181 discusses in detail all the available escapes to customize your prompts.
3203 3182 \layout List
3204 3183 \labelwidthstring 00.00.0000
3205 3184
3206 3185
3207 3186 \family typewriter
3208 3187 \series bold
3209 3188 -prompt_in2|pi2\SpecialChar ~
3210 3189 <string>:
3211 3190 \family default
3212 3191 \series default
3213 3192 Similar to the previous option, but used for the continuation prompts.
3214 3193 The special sequence '
3215 3194 \family typewriter
3216 3195
3217 3196 \backslash
3218 3197 D
3219 3198 \family default
3220 3199 ' is similar to '
3221 3200 \family typewriter
3222 3201
3223 3202 \backslash
3224 3203 #
3225 3204 \family default
3226 3205 ', but with all digits replaced dots (so you can have your continuation
3227 3206 prompt aligned with your input prompt).
3228 3207 Default: '
3229 3208 \family typewriter
3230 3209 \SpecialChar ~
3231 3210 \SpecialChar ~
3232 3211 \SpecialChar ~
3233 3212 .
3234 3213 \backslash
3235 3214 D.:
3236 3215 \family default
3237 3216 ' (note three spaces at the start for alignment with '
3238 3217 \family typewriter
3239 3218 In\SpecialChar ~
3240 3219 [
3241 3220 \backslash
3242 3221 #]
3243 3222 \family default
3244 3223 ').
3245 3224 \layout List
3246 3225 \labelwidthstring 00.00.0000
3247 3226
3248 3227
3249 3228 \family typewriter
3250 3229 \series bold
3251 3230 -prompt_out|po\SpecialChar ~
3252 3231 <string>:
3253 3232 \family default
3254 3233 \series default
3255 3234 String used for output prompts, also uses numbers like
3256 3235 \family typewriter
3257 3236 prompt_in1
3258 3237 \family default
3259 3238 .
3260 3239 Default: '
3261 3240 \family typewriter
3262 3241 Out[
3263 3242 \backslash
3264 3243 #]:
3265 3244 \family default
3266 3245 '
3267 3246 \layout List
3268 3247 \labelwidthstring 00.00.0000
3269 3248
3270 3249
3271 3250 \family typewriter
3272 3251 \series bold
3273 3252 -quick
3274 3253 \family default
3275 3254 \series default
3276 3255 : start in bare bones mode (no config file loaded).
3277 3256 \layout List
3278 3257 \labelwidthstring 00.00.0000
3279 3258
3280 3259
3281 3260 \family typewriter
3282 3261 \series bold
3283 3262 -rcfile\SpecialChar ~
3284 3263 <name>
3285 3264 \series default
3286 3265 :
3287 3266 \family default
3288 3267 name of your IPython resource configuration file.
3289 3268 Normally IPython loads ipythonrc (from current directory) or
3290 3269 \family typewriter
3291 3270 IPYTHONDIR/ipythonrc
3292 3271 \family default
3293 3272 .
3294 3273 \layout List
3295 3274 \labelwidthstring 00.00.0000
3296 3275
3297 3276 \SpecialChar ~
3298 3277 If the loading of your config file fails, IPython starts with a bare bones
3299 3278 configuration (no modules loaded at all).
3300 3279 \layout List
3301 3280 \labelwidthstring 00.00.0000
3302 3281
3303 3282
3304 3283 \family typewriter
3305 3284 \series bold
3306 3285 -[no]readline
3307 3286 \family default
3308 3287 \series default
3309 3288 : use the readline library, which is needed to support name completion and
3310 3289 command history, among other things.
3311 3290 It is enabled by default, but may cause problems for users of X/Emacs in
3312 3291 Python comint or shell buffers.
3313 3292 \layout List
3314 3293 \labelwidthstring 00.00.0000
3315 3294
3316 3295 \SpecialChar ~
3317 3296 Note that X/Emacs 'eterm' buffers (opened with
3318 3297 \family typewriter
3319 3298 M-x\SpecialChar ~
3320 3299 term
3321 3300 \family default
3322 3301 ) support IPython's readline and syntax coloring fine, only 'emacs' (
3323 3302 \family typewriter
3324 3303 M-x\SpecialChar ~
3325 3304 shell
3326 3305 \family default
3327 3306 and
3328 3307 \family typewriter
3329 3308 C-c\SpecialChar ~
3330 3309 !
3331 3310 \family default
3332 3311 ) buffers do not.
3333 3312 \layout List
3334 3313 \labelwidthstring 00.00.0000
3335 3314
3336 3315
3337 3316 \family typewriter
3338 3317 \series bold
3339 3318 -screen_length|sl\SpecialChar ~
3340 3319 <n>
3341 3320 \series default
3342 3321 :
3343 3322 \family default
3344 3323 number of lines of your screen.
3345 3324 This is used to control printing of very long strings.
3346 3325 Strings longer than this number of lines will be sent through a pager instead
3347 3326 of directly printed.
3348 3327 \layout List
3349 3328 \labelwidthstring 00.00.0000
3350 3329
3351 3330 \SpecialChar ~
3352 3331 The default value for this is 0, which means IPython will auto-detect your
3353 3332 screen size every time it needs to print certain potentially long strings
3354 3333 (this doesn't change the behavior of the 'print' keyword, it's only triggered
3355 3334 internally).
3356 3335 If for some reason this isn't working well (it needs curses support), specify
3357 3336 it yourself.
3358 3337 Otherwise don't change the default.
3359 3338 \layout List
3360 3339 \labelwidthstring 00.00.0000
3361 3340
3362 3341
3363 3342 \family typewriter
3364 3343 \series bold
3365 3344 -separate_in|si\SpecialChar ~
3366 3345 <string>
3367 3346 \series default
3368 3347 :
3369 3348 \family default
3370 3349 separator before input prompts.
3371 3350 Default: '
3372 3351 \family typewriter
3373 3352
3374 3353 \backslash
3375 3354 n
3376 3355 \family default
3377 3356 '
3378 3357 \layout List
3379 3358 \labelwidthstring 00.00.0000
3380 3359
3381 3360
3382 3361 \family typewriter
3383 3362 \series bold
3384 3363 -separate_out|so\SpecialChar ~
3385 3364 <string>
3386 3365 \family default
3387 3366 \series default
3388 3367 : separator before output prompts.
3389 3368 Default: nothing.
3390 3369 \layout List
3391 3370 \labelwidthstring 00.00.0000
3392 3371
3393 3372
3394 3373 \family typewriter
3395 3374 \series bold
3396 3375 -separate_out2|so2\SpecialChar ~
3397 3376 <string>
3398 3377 \series default
3399 3378 :
3400 3379 \family default
3401 3380 separator after output prompts.
3402 3381 Default: nothing.
3403 3382 \layout List
3404 3383 \labelwidthstring 00.00.0000
3405 3384
3406 3385 \SpecialChar ~
3407 3386 For these three options, use the value 0 to specify no separator.
3408 3387 \layout List
3409 3388 \labelwidthstring 00.00.0000
3410 3389
3411 3390
3412 3391 \family typewriter
3413 3392 \series bold
3414 3393 -nosep
3415 3394 \series default
3416 3395 :
3417 3396 \family default
3418 3397 shorthand for
3419 3398 \family typewriter
3420 3399 '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'
3421 3400 \family default
3422 3401 .
3423 3402 Simply removes all input/output separators.
3424 3403 \layout List
3425 3404 \labelwidthstring 00.00.0000
3426 3405
3427 3406
3428 3407 \family typewriter
3429 3408 \series bold
3430 3409 -upgrade
3431 3410 \family default
3432 3411 \series default
3433 3412 : allows you to upgrade your
3434 3413 \family typewriter
3435 3414 IPYTHONDIR
3436 3415 \family default
3437 3416 configuration when you install a new version of IPython.
3438 3417 Since new versions may include new command line options or example files,
3439 3418 this copies updated ipythonrc-type files.
3440 3419 However, it backs up (with a
3441 3420 \family typewriter
3442 3421 .old
3443 3422 \family default
3444 3423 extension) all files which it overwrites so that you can merge back any
3445 3424 customizations you might have in your personal files.
3446 3425 \layout List
3447 3426 \labelwidthstring 00.00.0000
3448 3427
3449 3428
3450 3429 \family typewriter
3451 3430 \series bold
3452 3431 -Version
3453 3432 \series default
3454 3433 :
3455 3434 \family default
3456 3435 print version information and exit.
3457 3436 \layout List
3458 3437 \labelwidthstring 00.00.0000
3459 3438
3460 3439
3461 3440 \family typewriter
3462 3441 \series bold
3463 3442 -xmode <modename>
3464 3443 \series default
3465 3444 :
3466 3445 \family default
3467 3446 Mode for exception reporting.
3468 3447 \layout List
3469 3448 \labelwidthstring 00.00.0000
3470 3449
3471 3450 \SpecialChar ~
3472 3451 Valid modes: Plain, Context and Verbose.
3473 3452 \layout List
3474 3453 \labelwidthstring 00.00.0000
3475 3454
3476 3455 \SpecialChar ~
3477 3456 Plain: similar to python's normal traceback printing.
3478 3457 \layout List
3479 3458 \labelwidthstring 00.00.0000
3480 3459
3481 3460 \SpecialChar ~
3482 3461 Context: prints 5 lines of context source code around each line in the
3483 3462 traceback.
3484 3463 \layout List
3485 3464 \labelwidthstring 00.00.0000
3486 3465
3487 3466 \SpecialChar ~
3488 3467 Verbose: similar to Context, but additionally prints the variables currently
3489 3468 visible where the exception happened (shortening their strings if too long).
3490 3469 This can potentially be very slow, if you happen to have a huge data structure
3491 3470 whose string representation is complex to compute.
3492 3471 Your computer may appear to freeze for a while with cpu usage at 100%.
3493 3472 If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting
3494 3473 it more than once).
3495 3474 \layout Section
3496 3475
3497 3476 Interactive use
3498 3477 \layout Standard
3499 3478
3500 3479
3501 3480 \series bold
3502 3481 Warning
3503 3482 \series default
3504 3483 : IPython relies on the existence of a global variable called
3505 3484 \family typewriter
3506 3485 __IP
3507 3486 \family default
3508 3487 which controls the shell itself.
3509 3488 If you redefine
3510 3489 \family typewriter
3511 3490 __IP
3512 3491 \family default
3513 3492 to anything, bizarre behavior will quickly occur.
3514 3493 \layout Standard
3515 3494
3516 3495 Other than the above warning, IPython is meant to work as a drop-in replacement
3517 3496 for the standard interactive interpreter.
3518 3497 As such, any code which is valid python should execute normally under IPython
3519 3498 (cases where this is not true should be reported as bugs).
3520 3499 It does, however, offer many features which are not available at a standard
3521 3500 python prompt.
3522 3501 What follows is a list of these.
3523 3502 \layout Subsection
3524 3503
3525 3504 Caution for Windows users
3526 3505 \layout Standard
3527 3506
3528 3507 Windows, unfortunately, uses the `
3529 3508 \family typewriter
3530 3509
3531 3510 \backslash
3532 3511
3533 3512 \family default
3534 3513 ' character as a path separator.
3535 3514 This is a terrible choice, because `
3536 3515 \family typewriter
3537 3516
3538 3517 \backslash
3539 3518
3540 3519 \family default
3541 3520 ' also represents the escape character in most modern programming languages,
3542 3521 including Python.
3543 3522 For this reason, issuing many of the commands discussed below (especially
3544 3523 magics which affect the filesystem) with `
3545 3524 \family typewriter
3546 3525
3547 3526 \backslash
3548 3527
3549 3528 \family default
3550 3529 ' in them will cause strange errors.
3551 3530 \layout Standard
3552 3531
3553 3532 A partial solution is to use instead the `
3554 3533 \family typewriter
3555 3534 /
3556 3535 \family default
3557 3536 ' character as a path separator, which Windows recognizes in
3558 3537 \emph on
3559 3538 most
3560 3539 \emph default
3561 3540 situations.
3562 3541 However, in Windows commands `
3563 3542 \family typewriter
3564 3543 /
3565 3544 \family default
3566 3545 ' flags options, so you can not use it for the root directory.
3567 3546 This means that paths beginning at the root must be typed in a contrived
3568 3547 manner like:
3569 3548 \newline
3570 3549
3571 3550 \family typewriter
3572 3551 %copy
3573 3552 \backslash
3574 3553 opt/foo/bar.txt
3575 3554 \backslash
3576 3555 tmp
3577 3556 \layout Standard
3578 3557
3579 3558 There is no sensible thing IPython can do to truly work around this flaw
3580 3559 in Windows
3581 3560 \begin_inset Foot
3582 3561 collapsed true
3583 3562
3584 3563 \layout Standard
3585 3564
3586 3565 If anyone comes up with a
3587 3566 \emph on
3588 3567 clean
3589 3568 \emph default
3590 3569 solution which works consistently and does not negatively impact other
3591 3570 platforms at all, I'll gladly accept a patch.
3592 3571 \end_inset
3593 3572
3594 3573 .
3595 3574 \layout Subsection
3596 3575
3597 3576
3598 3577 \begin_inset LatexCommand \label{sec:magic}
3599 3578
3600 3579 \end_inset
3601 3580
3602 3581 Magic command system
3603 3582 \layout Standard
3604 3583
3605 3584 IPython will treat any line whose first character is a
3606 3585 \family typewriter
3607 3586 %
3608 3587 \family default
3609 3588 as a special call to a 'magic' function.
3610 3589 These allow you to control the behavior of IPython itself, plus a lot of
3611 3590 system-type features.
3612 3591 They are all prefixed with a
3613 3592 \family typewriter
3614 3593 %
3615 3594 \family default
3616 3595 character, but parameters are given without parentheses or quotes.
3617 3596 \layout Standard
3618 3597
3619 3598 Example: typing
3620 3599 \family typewriter
3621 3600 '%cd mydir'
3622 3601 \family default
3623 3602 (without the quotes) changes you working directory to
3624 3603 \family typewriter
3625 3604 'mydir'
3626 3605 \family default
3627 3606 , if it exists.
3628 3607 \layout Standard
3629 3608
3630 3609 If you have 'automagic' enabled (in your
3631 3610 \family typewriter
3632 3611 ipythonrc
3633 3612 \family default
3634 3613 file, via the command line option
3635 3614 \family typewriter
3636 3615 -automagic
3637 3616 \family default
3638 3617 or with the
3639 3618 \family typewriter
3640 3619 %automagic
3641 3620 \family default
3642 3621 function), you don't need to type in the
3643 3622 \family typewriter
3644 3623 %
3645 3624 \family default
3646 3625 explicitly.
3647 3626 IPython will scan its internal list of magic functions and call one if
3648 3627 it exists.
3649 3628 With automagic on you can then just type '
3650 3629 \family typewriter
3651 3630 cd mydir
3652 3631 \family default
3653 3632 ' to go to directory '
3654 3633 \family typewriter
3655 3634 mydir
3656 3635 \family default
3657 3636 '.
3658 3637 The automagic system has the lowest possible precedence in name searches,
3659 3638 so defining an identifier with the same name as an existing magic function
3660 3639 will shadow it for automagic use.
3661 3640 You can still access the shadowed magic function by explicitly using the
3662 3641
3663 3642 \family typewriter
3664 3643 %
3665 3644 \family default
3666 3645 character at the beginning of the line.
3667 3646 \layout Standard
3668 3647
3669 3648 An example (with automagic on) should clarify all this:
3670 3649 \layout LyX-Code
3671 3650
3672 3651 In [1]: cd ipython # %cd is called by automagic
3673 3652 \layout LyX-Code
3674 3653
3675 3654 /home/fperez/ipython
3676 3655 \layout LyX-Code
3677 3656
3678 3657 In [2]: cd=1 # now cd is just a variable
3679 3658 \layout LyX-Code
3680 3659
3681 3660 In [3]: cd ..
3682 3661 # and doesn't work as a function anymore
3683 3662 \layout LyX-Code
3684 3663
3685 3664 ------------------------------------------------------------
3686 3665 \layout LyX-Code
3687 3666
3688 3667 File "<console>", line 1
3689 3668 \layout LyX-Code
3690 3669
3691 3670 cd ..
3692 3671 \layout LyX-Code
3693 3672
3694 3673 ^
3695 3674 \layout LyX-Code
3696 3675
3697 3676 SyntaxError: invalid syntax
3698 3677 \layout LyX-Code
3699 3678
3700 3679 \layout LyX-Code
3701 3680
3702 3681 In [4]: %cd ..
3703 3682 # but %cd always works
3704 3683 \layout LyX-Code
3705 3684
3706 3685 /home/fperez
3707 3686 \layout LyX-Code
3708 3687
3709 3688 In [5]: del cd # if you remove the cd variable
3710 3689 \layout LyX-Code
3711 3690
3712 3691 In [6]: cd ipython # automagic can work again
3713 3692 \layout LyX-Code
3714 3693
3715 3694 /home/fperez/ipython
3716 3695 \layout Standard
3717 3696
3718 3697 You can define your own magic functions to extend the system.
3719 3698 The following is a snippet of code which shows how to do it.
3720 3699 It is provided as file
3721 3700 \family typewriter
3722 3701 example-magic.py
3723 3702 \family default
3724 3703 in the examples directory:
3725 3704 \layout Standard
3726 3705
3727 3706
3728 3707 \begin_inset ERT
3729 3708 status Open
3730 3709
3731 3710 \layout Standard
3732 3711
3733 3712 \backslash
3734 3713 codelist{examples/example-magic.py}
3735 3714 \end_inset
3736 3715
3737 3716
3738 3717 \layout Standard
3739 3718
3740 3719 You can also define your own aliased names for magic functions.
3741 3720 In your
3742 3721 \family typewriter
3743 3722 ipythonrc
3744 3723 \family default
3745 3724 file, placing a line like:
3746 3725 \layout Standard
3747 3726
3748 3727
3749 3728 \family typewriter
3750 3729 execute __IP.magic_cl = __IP.magic_clear
3751 3730 \layout Standard
3752 3731
3753 3732 will define
3754 3733 \family typewriter
3755 3734 %cl
3756 3735 \family default
3757 3736 as a new name for
3758 3737 \family typewriter
3759 3738 %clear
3760 3739 \family default
3761 3740 .
3762 3741 \layout Standard
3763 3742
3764 3743 Type
3765 3744 \family typewriter
3766 3745 %magic
3767 3746 \family default
3768 3747 for more information, including a list of all available magic functions
3769 3748 at any time and their docstrings.
3770 3749 You can also type
3771 3750 \family typewriter
3772 3751 %magic_function_name?
3773 3752 \family default
3774 3753 (see sec.
3775 3754
3776 3755 \begin_inset LatexCommand \ref{sec:dyn-object-info}
3777 3756
3778 3757 \end_inset
3779 3758
3780 3759 for information on the
3781 3760 \family typewriter
3782 3761 '?'
3783 3762 \family default
3784 3763 system) to get information about any particular magic function you are
3785 3764 interested in.
3786 3765 \layout Subsubsection
3787 3766
3788 3767 Magic commands
3789 3768 \layout Standard
3790 3769
3791 3770 The rest of this section is automatically generated for each release from
3792 3771 the docstrings in the IPython code.
3793 3772 Therefore the formatting is somewhat minimal, but this method has the advantage
3794 3773 of having information always in sync with the code.
3795 3774 \layout Standard
3796 3775
3797 3776 A list of all the magic commands available in IPython's
3798 3777 \emph on
3799 3778 default
3800 3779 \emph default
3801 3780 installation follows.
3802 3781 This is similar to what you'll see by simply typing
3803 3782 \family typewriter
3804 3783 %magic
3805 3784 \family default
3806 3785 at the prompt, but that will also give you information about magic commands
3807 3786 you may have added as part of your personal customizations.
3808 3787 \layout Standard
3809 3788
3810 3789
3811 3790 \begin_inset Include \input{magic.tex}
3812 3791 preview false
3813 3792
3814 3793 \end_inset
3815 3794
3816 3795
3817 3796 \layout Subsection
3818 3797
3819 3798 Access to the standard Python help
3820 3799 \layout Standard
3821 3800
3822 3801 As of Python 2.1, a help system is available with access to object docstrings
3823 3802 and the Python manuals.
3824 3803 Simply type
3825 3804 \family typewriter
3826 3805 'help'
3827 3806 \family default
3828 3807 (no quotes) to access it.
3829 3808 You can also type
3830 3809 \family typewriter
3831 3810 help(object)
3832 3811 \family default
3833 3812 to obtain information about a given object, and
3834 3813 \family typewriter
3835 3814 help('keyword')
3836 3815 \family default
3837 3816 for information on a keyword.
3838 3817 As noted in sec.
3839 3818
3840 3819 \begin_inset LatexCommand \ref{sec:help-access}
3841 3820
3842 3821 \end_inset
3843 3822
3844 3823 , you need to properly configure your environment variable
3845 3824 \family typewriter
3846 3825 PYTHONDOCS
3847 3826 \family default
3848 3827 for this feature to work correctly.
3849 3828 \layout Subsection
3850 3829
3851 3830
3852 3831 \begin_inset LatexCommand \label{sec:dyn-object-info}
3853 3832
3854 3833 \end_inset
3855 3834
3856 3835 Dynamic object information
3857 3836 \layout Standard
3858 3837
3859 3838 Typing
3860 3839 \family typewriter
3861 3840 ?word
3862 3841 \family default
3863 3842 or
3864 3843 \family typewriter
3865 3844 word?
3866 3845 \family default
3867 3846 prints detailed information about an object.
3868 3847 If certain strings in the object are too long (docstrings, code, etc.) they
3869 3848 get snipped in the center for brevity.
3870 3849 This system gives access variable types and values, full source code for
3871 3850 any object (if available), function prototypes and other useful information.
3872 3851 \layout Standard
3873 3852
3874 3853 Typing
3875 3854 \family typewriter
3876 3855 ??word
3877 3856 \family default
3878 3857 or
3879 3858 \family typewriter
3880 3859 word??
3881 3860 \family default
3882 3861 gives access to the full information without snipping long strings.
3883 3862 Long strings are sent to the screen through the
3884 3863 \family typewriter
3885 3864 less
3886 3865 \family default
3887 3866 pager if longer than the screen and printed otherwise.
3888 3867 On systems lacking the
3889 3868 \family typewriter
3890 3869 less
3891 3870 \family default
3892 3871 command, IPython uses a very basic internal pager.
3893 3872 \layout Standard
3894 3873
3895 3874 The following magic functions are particularly useful for gathering information
3896 3875 about your working environment.
3897 3876 You can get more details by typing
3898 3877 \family typewriter
3899 3878 %magic
3900 3879 \family default
3901 3880 or querying them individually (use
3902 3881 \family typewriter
3903 3882 %function_name?
3904 3883 \family default
3905 3884 with or without the
3906 3885 \family typewriter
3907 3886 %
3908 3887 \family default
3909 3888 ), this is just a summary:
3910 3889 \layout List
3911 3890 \labelwidthstring 00.00.0000
3912 3891
3913 3892
3914 3893 \family typewriter
3915 3894 \series bold
3916 3895 %pdoc\SpecialChar ~
3917 3896 <object>
3918 3897 \family default
3919 3898 \series default
3920 3899 : Print (or run through a pager if too long) the docstring for an object.
3921 3900 If the given object is a class, it will print both the class and the constructo
3922 3901 r docstrings.
3923 3902 \layout List
3924 3903 \labelwidthstring 00.00.0000
3925 3904
3926 3905
3927 3906 \family typewriter
3928 3907 \series bold
3929 3908 %pdef\SpecialChar ~
3930 3909 <object>
3931 3910 \family default
3932 3911 \series default
3933 3912 : Print the definition header for any callable object.
3934 3913 If the object is a class, print the constructor information.
3935 3914 \layout List
3936 3915 \labelwidthstring 00.00.0000
3937 3916
3938 3917
3939 3918 \family typewriter
3940 3919 \series bold
3941 3920 %psource\SpecialChar ~
3942 3921 <object>
3943 3922 \family default
3944 3923 \series default
3945 3924 : Print (or run through a pager if too long) the source code for an object.
3946 3925 \layout List
3947 3926 \labelwidthstring 00.00.0000
3948 3927
3949 3928
3950 3929 \family typewriter
3951 3930 \series bold
3952 3931 %pfile\SpecialChar ~
3953 3932 <object>
3954 3933 \family default
3955 3934 \series default
3956 3935 : Show the entire source file where an object was defined via a pager, opening
3957 3936 it at the line where the object definition begins.
3958 3937 \layout List
3959 3938 \labelwidthstring 00.00.0000
3960 3939
3961 3940
3962 3941 \family typewriter
3963 3942 \series bold
3964 3943 %who/%whos
3965 3944 \family default
3966 3945 \series default
3967 3946 : These functions give information about identifiers you have defined interactiv
3968 3947 ely (not things you loaded or defined in your configuration files).
3969 3948
3970 3949 \family typewriter
3971 3950 %who
3972 3951 \family default
3973 3952 just prints a list of identifiers and
3974 3953 \family typewriter
3975 3954 %whos
3976 3955 \family default
3977 3956 prints a table with some basic details about each identifier.
3978 3957 \layout Standard
3979 3958
3980 3959 Note that the dynamic object information functions (
3981 3960 \family typewriter
3982 3961 ?/??, %pdoc, %pfile, %pdef, %psource
3983 3962 \family default
3984 3963 ) give you access to documentation even on things which are not really defined
3985 3964 as separate identifiers.
3986 3965 Try for example typing
3987 3966 \family typewriter
3988 3967 {}.get?
3989 3968 \family default
3990 3969 or after doing
3991 3970 \family typewriter
3992 3971 import os
3993 3972 \family default
3994 3973 , type
3995 3974 \family typewriter
3996 3975 os.path.abspath??
3997 3976 \family default
3998 3977 .
3999 3978 \layout Subsection
4000 3979
4001 3980
4002 3981 \begin_inset LatexCommand \label{sec:readline}
4003 3982
4004 3983 \end_inset
4005 3984
4006 3985 Readline-based features
4007 3986 \layout Standard
4008 3987
4009 3988 These features require the GNU readline library, so they won't work if your
4010 3989 Python installation lacks readline support.
4011 3990 We will first describe the default behavior IPython uses, and then how
4012 3991 to change it to suit your preferences.
4013 3992 \layout Subsubsection
4014 3993
4015 3994 Command line completion
4016 3995 \layout Standard
4017 3996
4018 3997 At any time, hitting TAB will complete any available python commands or
4019 3998 variable names, and show you a list of the possible completions if there's
4020 3999 no unambiguous one.
4021 4000 It will also complete filenames in the current directory if no python names
4022 4001 match what you've typed so far.
4023 4002 \layout Subsubsection
4024 4003
4025 4004 Search command history
4026 4005 \layout Standard
4027 4006
4028 4007 IPython provides two ways for searching through previous input and thus
4029 4008 reduce the need for repetitive typing:
4030 4009 \layout Enumerate
4031 4010
4032 4011 Start typing, and then use
4033 4012 \family typewriter
4034 4013 Ctrl-p
4035 4014 \family default
4036 4015 (previous,up) and
4037 4016 \family typewriter
4038 4017 Ctrl-n
4039 4018 \family default
4040 4019 (next,down) to search through only the history items that match what you've
4041 4020 typed so far.
4042 4021 If you use
4043 4022 \family typewriter
4044 4023 Ctrl-p/Ctrl-n
4045 4024 \family default
4046 4025 at a blank prompt, they just behave like normal arrow keys.
4047 4026 \layout Enumerate
4048 4027
4049 4028 Hit
4050 4029 \family typewriter
4051 4030 Ctrl-r
4052 4031 \family default
4053 4032 : opens a search prompt.
4054 4033 Begin typing and the system searches your history for lines that contain
4055 4034 what you've typed so far, completing as much as it can.
4056 4035 \layout Subsubsection
4057 4036
4058 4037 Persistent command history across sessions
4059 4038 \layout Standard
4060 4039
4061 4040 IPython will save your input history when it leaves and reload it next time
4062 4041 you restart it.
4063 4042 By default, the history file is named
4064 4043 \family typewriter
4065 4044 $IPYTHONDIR/history
4066 4045 \family default
4067 4046 , but if you've loaded a named profile, '
4068 4047 \family typewriter
4069 4048 -PROFILE_NAME
4070 4049 \family default
4071 4050 ' is appended to the name.
4072 4051 This allows you to keep separate histories related to various tasks: commands
4073 4052 related to numerical work will not be clobbered by a system shell history,
4074 4053 for example.
4075 4054 \layout Subsubsection
4076 4055
4077 4056 Autoindent
4078 4057 \layout Standard
4079 4058
4080 4059 IPython can recognize lines ending in ':' and indent the next line, while
4081 4060 also un-indenting automatically after 'raise' or 'return'.
4082 4061
4083 4062 \layout Standard
4084 4063
4085 4064 This feature uses the readline library, so it will honor your
4086 4065 \family typewriter
4087 4066 ~/.inputrc
4088 4067 \family default
4089 4068 configuration (or whatever file your
4090 4069 \family typewriter
4091 4070 INPUTRC
4092 4071 \family default
4093 4072 variable points to).
4094 4073 Adding the following lines to your
4095 4074 \family typewriter
4096 4075 .inputrc
4097 4076 \family default
4098 4077 file can make indenting/unindenting more convenient (
4099 4078 \family typewriter
4100 4079 M-i
4101 4080 \family default
4102 4081 indents,
4103 4082 \family typewriter
4104 4083 M-u
4105 4084 \family default
4106 4085 unindents):
4107 4086 \layout Standard
4108 4087
4109 4088
4110 4089 \family typewriter
4111 4090 $if Python
4112 4091 \newline
4113 4092 "
4114 4093 \backslash
4115 4094 M-i": "\SpecialChar ~
4116 4095 \SpecialChar ~
4117 4096 \SpecialChar ~
4118 4097 \SpecialChar ~
4119 4098 "
4120 4099 \newline
4121 4100 "
4122 4101 \backslash
4123 4102 M-u": "
4124 4103 \backslash
4125 4104 d
4126 4105 \backslash
4127 4106 d
4128 4107 \backslash
4129 4108 d
4130 4109 \backslash
4131 4110 d"
4132 4111 \newline
4133 4112 $endif
4134 4113 \layout Standard
4135 4114
4136 4115 Note that there are 4 spaces between the quote marks after
4137 4116 \family typewriter
4138 4117 "M-i"
4139 4118 \family default
4140 4119 above.
4141 4120 \layout Standard
4142 4121
4143 4122
4144 4123 \series bold
4145 4124 Warning:
4146 4125 \series default
4147 4126 this feature is ON by default, but it can cause problems with the pasting
4148 4127 of multi-line indented code (the pasted code gets re-indented on each line).
4149 4128 A magic function
4150 4129 \family typewriter
4151 4130 %autoindent
4152 4131 \family default
4153 4132 allows you to toggle it on/off at runtime.
4154 4133 You can also disable it permanently on in your
4155 4134 \family typewriter
4156 4135 ipythonrc
4157 4136 \family default
4158 4137 file (set
4159 4138 \family typewriter
4160 4139 autoindent 0
4161 4140 \family default
4162 4141 ).
4163 4142 \layout Subsubsection
4164 4143
4165 4144 Customizing readline behavior
4166 4145 \layout Standard
4167 4146
4168 4147 All these features are based on the GNU readline library, which has an extremely
4169 4148 customizable interface.
4170 4149 Normally, readline is configured via a file which defines the behavior
4171 4150 of the library; the details of the syntax for this can be found in the
4172 4151 readline documentation available with your system or on the Internet.
4173 4152 IPython doesn't read this file (if it exists) directly, but it does support
4174 4153 passing to readline valid options via a simple interface.
4175 4154 In brief, you can customize readline by setting the following options in
4176 4155 your
4177 4156 \family typewriter
4178 4157 ipythonrc
4179 4158 \family default
4180 4159 configuration file (note that these options can
4181 4160 \emph on
4182 4161 not
4183 4162 \emph default
4184 4163 be specified at the command line):
4185 4164 \layout List
4186 4165 \labelwidthstring 00.00.0000
4187 4166
4188 4167
4189 4168 \family typewriter
4190 4169 \series bold
4191 4170 readline_parse_and_bind:
4192 4171 \family default
4193 4172 \series default
4194 4173 this option can appear as many times as you want, each time defining a
4195 4174 string to be executed via a
4196 4175 \family typewriter
4197 4176 readline.parse_and_bind()
4198 4177 \family default
4199 4178 command.
4200 4179 The syntax for valid commands of this kind can be found by reading the
4201 4180 documentation for the GNU readline library, as these commands are of the
4202 4181 kind which readline accepts in its configuration file.
4203 4182 \layout List
4204 4183 \labelwidthstring 00.00.0000
4205 4184
4206 4185
4207 4186 \family typewriter
4208 4187 \series bold
4209 4188 readline_remove_delims:
4210 4189 \family default
4211 4190 \series default
4212 4191 a string of characters to be removed from the default word-delimiters list
4213 4192 used by readline, so that completions may be performed on strings which
4214 4193 contain them.
4215 4194 Do not change the default value unless you know what you're doing.
4216 4195 \layout List
4217 4196 \labelwidthstring 00.00.0000
4218 4197
4219 4198
4220 4199 \family typewriter
4221 4200 \series bold
4222 4201 readline_omit__names
4223 4202 \family default
4224 4203 \series default
4225 4204 : when tab-completion is enabled, hitting
4226 4205 \family typewriter
4227 4206 <tab>
4228 4207 \family default
4229 4208 after a '
4230 4209 \family typewriter
4231 4210 .
4232 4211 \family default
4233 4212 ' in a name will complete all attributes of an object, including all the
4234 4213 special methods whose names include double underscores (like
4235 4214 \family typewriter
4236 4215 __getitem__
4237 4216 \family default
4238 4217 or
4239 4218 \family typewriter
4240 4219 __class__
4241 4220 \family default
4242 4221 ).
4243 4222 If you'd rather not see these names by default, you can set this option
4244 4223 to 1.
4245 4224 Note that even when this option is set, you can still see those names by
4246 4225 explicitly typing a
4247 4226 \family typewriter
4248 4227 _
4249 4228 \family default
4250 4229 after the period and hitting
4251 4230 \family typewriter
4252 4231 <tab>
4253 4232 \family default
4254 4233 : '
4255 4234 \family typewriter
4256 4235 name._<tab>
4257 4236 \family default
4258 4237 ' will always complete attribute names starting with '
4259 4238 \family typewriter
4260 4239 _
4261 4240 \family default
4262 4241 '.
4263 4242 \layout List
4264 4243 \labelwidthstring 00.00.0000
4265 4244
4266 4245 \SpecialChar ~
4267 4246 This option is off by default so that new users see all attributes of any
4268 4247 objects they are dealing with.
4269 4248 \layout Standard
4270 4249
4271 4250 You will find the default values along with a corresponding detailed explanation
4272 4251 in your
4273 4252 \family typewriter
4274 4253 ipythonrc
4275 4254 \family default
4276 4255 file.
4277 4256 \layout Subsection
4278 4257
4279 4258 Session logging and restoring
4280 4259 \layout Standard
4281 4260
4282 4261 You can log all input from a session either by starting IPython with the
4283 4262 command line switches
4284 4263 \family typewriter
4285 4264 -log
4286 4265 \family default
4287 4266 or
4288 4267 \family typewriter
4289 4268 -logfile
4290 4269 \family default
4291 4270 (see sec.
4292 4271
4293 4272 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
4294 4273
4295 4274 \end_inset
4296 4275
4297 4276 )or by activating the logging at any moment with the magic function
4298 4277 \family typewriter
4299 4278 %logstart
4300 4279 \family default
4301 4280 .
4302 4281
4303 4282 \layout Standard
4304 4283
4305 4284 Log files can later be reloaded with the
4306 4285 \family typewriter
4307 4286 -logplay
4308 4287 \family default
4309 4288 option and IPython will attempt to 'replay' the log by executing all the
4310 4289 lines in it, thus restoring the state of a previous session.
4311 4290 This feature is not quite perfect, but can still be useful in many cases.
4312 4291 \layout Standard
4313 4292
4314 4293 The log files can also be used as a way to have a permanent record of any
4315 4294 code you wrote while experimenting.
4316 4295 Log files are regular text files which you can later open in your favorite
4317 4296 text editor to extract code or to 'clean them up' before using them to
4318 4297 replay a session.
4319 4298 \layout Standard
4320 4299
4321 4300 The
4322 4301 \family typewriter
4323 4302 %logstart
4324 4303 \family default
4325 4304 function for activating logging in mid-session is used as follows:
4326 4305 \layout Standard
4327 4306
4328 4307
4329 4308 \family typewriter
4330 4309 %logstart [log_name [log_mode]]
4331 4310 \layout Standard
4332 4311
4333 4312 If no name is given, it defaults to a file named
4334 4313 \family typewriter
4335 4314 'log'
4336 4315 \family default
4337 4316 in your IPYTHONDIR directory, in
4338 4317 \family typewriter
4339 4318 'rotate'
4340 4319 \family default
4341 4320 mode (see below).
4342 4321 \layout Standard
4343 4322
4344 4323 '
4345 4324 \family typewriter
4346 4325 %logstart name
4347 4326 \family default
4348 4327 ' saves to file
4349 4328 \family typewriter
4350 4329 'name'
4351 4330 \family default
4352 4331 in
4353 4332 \family typewriter
4354 4333 'backup'
4355 4334 \family default
4356 4335 mode.
4357 4336 It saves your history up to that point and then continues logging.
4358 4337 \layout Standard
4359 4338
4360 4339
4361 4340 \family typewriter
4362 4341 %logstart
4363 4342 \family default
4364 4343 takes a second optional parameter: logging mode.
4365 4344 This can be one of (note that the modes are given unquoted):
4366 4345 \layout List
4367 4346 \labelwidthstring 00.00.0000
4368 4347
4369 4348
4370 4349 \family typewriter
4371 4350 over
4372 4351 \family default
4373 4352 : overwrite existing
4374 4353 \family typewriter
4375 4354 log_name
4376 4355 \family default
4377 4356 .
4378 4357 \layout List
4379 4358 \labelwidthstring 00.00.0000
4380 4359
4381 4360
4382 4361 \family typewriter
4383 4362 backup
4384 4363 \family default
4385 4364 : rename (if exists) to
4386 4365 \family typewriter
4387 4366 log_name~
4388 4367 \family default
4389 4368 and start
4390 4369 \family typewriter
4391 4370 log_name
4392 4371 \family default
4393 4372 .
4394 4373 \layout List
4395 4374 \labelwidthstring 00.00.0000
4396 4375
4397 4376
4398 4377 \family typewriter
4399 4378 append
4400 4379 \family default
4401 4380 : well, that says it.
4402 4381 \layout List
4403 4382 \labelwidthstring 00.00.0000
4404 4383
4405 4384
4406 4385 \family typewriter
4407 4386 rotate
4408 4387 \family default
4409 4388 : create rotating logs
4410 4389 \family typewriter
4411 4390 log_name
4412 4391 \family default
4413 4392 .
4414 4393 \family typewriter
4415 4394 1~
4416 4395 \family default
4417 4396 ,
4418 4397 \family typewriter
4419 4398 log_name.2~
4420 4399 \family default
4421 4400 , etc.
4422 4401 \layout Standard
4423 4402
4424 4403 The
4425 4404 \family typewriter
4426 4405 %logoff
4427 4406 \family default
4428 4407 and
4429 4408 \family typewriter
4430 4409 %logon
4431 4410 \family default
4432 4411 functions allow you to temporarily stop and resume logging to a file which
4433 4412 had previously been started with
4434 4413 \family typewriter
4435 4414 %logstart
4436 4415 \family default
4437 4416 .
4438 4417 They will fail (with an explanation) if you try to use them before logging
4439 4418 has been started.
4440 4419 \layout Subsection
4441 4420
4442 4421
4443 4422 \begin_inset LatexCommand \label{sub:System-shell-access}
4444 4423
4445 4424 \end_inset
4446 4425
4447 4426 System shell access
4448 4427 \layout Standard
4449 4428
4450 4429 Any input line beginning with a
4451 4430 \family typewriter
4452 4431 !
4453 4432 \family default
4454 4433 character is passed verbatim (minus the
4455 4434 \family typewriter
4456 4435 !
4457 4436 \family default
4458 4437 , of course) to the underlying operating system.
4459 4438 For example, typing
4460 4439 \family typewriter
4461 4440 !ls
4462 4441 \family default
4463 4442 will run
4464 4443 \family typewriter
4465 4444 'ls'
4466 4445 \family default
4467 4446 in the current directory.
4468 4447 \layout Subsubsection
4469 4448
4470 4449 Manual capture of command output
4471 4450 \layout Standard
4472 4451
4473 4452 If the input line begins with
4474 4453 \emph on
4475 4454 two
4476 4455 \emph default
4477 4456 exclamation marks,
4478 4457 \family typewriter
4479 4458 !!
4480 4459 \family default
4481 4460 , the command is executed but its output is captured and returned as a python
4482 4461 list, split on newlines.
4483 4462 Any output sent by the subprocess to standard error is printed separately,
4484 4463 so that the resulting list only captures standard output.
4485 4464 The
4486 4465 \family typewriter
4487 4466 !!
4488 4467 \family default
4489 4468 syntax is a shorthand for the
4490 4469 \family typewriter
4491 4470 %sx
4492 4471 \family default
4493 4472 magic command.
4494 4473 \layout Standard
4495 4474
4496 4475 Finally, the
4497 4476 \family typewriter
4498 4477 %sc
4499 4478 \family default
4500 4479 magic (short for `shell capture') is similar to
4501 4480 \family typewriter
4502 4481 %sx
4503 4482 \family default
4504 4483 , but allowing more fine-grained control of the capture details, and storing
4505 4484 the result directly into a named variable.
4506 4485 \layout Standard
4507 4486
4508 4487 See Sec.\SpecialChar ~
4509 4488
4510 4489 \begin_inset LatexCommand \ref{sec:magic}
4511 4490
4512 4491 \end_inset
4513 4492
4514 4493 for details on the magics
4515 4494 \family typewriter
4516 4495 %sc
4517 4496 \family default
4518 4497 and
4519 4498 \family typewriter
4520 4499 %sx
4521 4500 \family default
4522 4501 , or use IPython's own help (
4523 4502 \family typewriter
4524 4503 sc?
4525 4504 \family default
4526 4505 and
4527 4506 \family typewriter
4528 4507 sx?
4529 4508 \family default
4530 4509 ) for further details.
4531 4510 \layout Standard
4532 4511
4533 4512 IPython also allows you to expand the value of python variables when making
4534 4513 system calls.
4535 4514 Any python variable or expression which you prepend with
4536 4515 \family typewriter
4537 4516 $
4538 4517 \family default
4539 4518 will get expanded before the system call is made.
4540 4519
4541 4520 \layout Standard
4542 4521
4543 4522
4544 4523 \family typewriter
4545 4524 In [1]: pyvar='Hello world'
4546 4525 \newline
4547 4526 In [2]: !echo "A python variable: $pyvar"
4548 4527 \newline
4549 4528 A python variable: Hello world
4550 4529 \layout Standard
4551 4530
4552 4531 If you want the shell to actually see a literal
4553 4532 \family typewriter
4554 4533 $
4555 4534 \family default
4556 4535 , you need to type it twice:
4557 4536 \layout Standard
4558 4537
4559 4538
4560 4539 \family typewriter
4561 4540 In [3]: !echo "A system variable: $$HOME"
4562 4541 \newline
4563 4542 A system variable: /home/fperez
4564 4543 \layout Standard
4565 4544
4566 4545 You can pass arbitrary expressions, though you'll need to delimit them with
4567 4546
4568 4547 \family typewriter
4569 4548 {}
4570 4549 \family default
4571 4550 if there is ambiguity as to the extent of the expression:
4572 4551 \layout Standard
4573 4552
4574 4553
4575 4554 \family typewriter
4576 4555 In [5]: x=10
4577 4556 \newline
4578 4557 In [6]: y=20
4579 4558 \newline
4580 4559 In [13]: !echo $x+y
4581 4560 \newline
4582 4561 10+y
4583 4562 \newline
4584 4563 In [7]: !echo ${x+y}
4585 4564 \newline
4586 4565 30
4587 4566 \layout Standard
4588 4567
4589 4568 Even object attributes can be expanded:
4590 4569 \layout Standard
4591 4570
4592 4571
4593 4572 \family typewriter
4594 4573 In [12]: !echo $sys.argv
4595 4574 \newline
4596 4575 [/home/fperez/usr/bin/ipython]
4597 4576 \layout Subsection
4598 4577
4599 4578 System command aliases
4600 4579 \layout Standard
4601 4580
4602 4581 The
4603 4582 \family typewriter
4604 4583 %alias
4605 4584 \family default
4606 4585 magic function and the
4607 4586 \family typewriter
4608 4587 alias
4609 4588 \family default
4610 4589 option in the
4611 4590 \family typewriter
4612 4591 ipythonrc
4613 4592 \family default
4614 4593 configuration file allow you to define magic functions which are in fact
4615 4594 system shell commands.
4616 4595 These aliases can have parameters.
4617 4596
4618 4597 \layout Standard
4619 4598
4620 4599 '
4621 4600 \family typewriter
4622 4601 %alias alias_name cmd
4623 4602 \family default
4624 4603 ' defines '
4625 4604 \family typewriter
4626 4605 alias_name
4627 4606 \family default
4628 4607 ' as an alias for '
4629 4608 \family typewriter
4630 4609 cmd
4631 4610 \family default
4632 4611 '
4633 4612 \layout Standard
4634 4613
4635 4614 Then, typing '
4636 4615 \family typewriter
4637 4616 %alias_name params
4638 4617 \family default
4639 4618 ' will execute the system command '
4640 4619 \family typewriter
4641 4620 cmd params
4642 4621 \family default
4643 4622 ' (from your underlying operating system).
4644 4623
4645 4624 \layout Standard
4646 4625
4647 4626 You can also define aliases with parameters using
4648 4627 \family typewriter
4649 4628 %s
4650 4629 \family default
4651 4630 specifiers (one per parameter).
4652 4631 The following example defines the
4653 4632 \family typewriter
4654 4633 %parts
4655 4634 \family default
4656 4635 function as an alias to the command '
4657 4636 \family typewriter
4658 4637 echo first %s second %s
4659 4638 \family default
4660 4639 ' where each
4661 4640 \family typewriter
4662 4641 %s
4663 4642 \family default
4664 4643 will be replaced by a positional parameter to the call to
4665 4644 \family typewriter
4666 4645 %parts:
4667 4646 \layout Standard
4668 4647
4669 4648
4670 4649 \family typewriter
4671 4650 In [1]: alias parts echo first %s second %s
4672 4651 \newline
4673 4652 In [2]: %parts A B
4674 4653 \newline
4675 4654 first A second B
4676 4655 \newline
4677 4656 In [3]: %parts A
4678 4657 \newline
4679 4658 Incorrect number of arguments: 2 expected.
4680 4659
4681 4660 \newline
4682 4661 parts is an alias to: 'echo first %s second %s'
4683 4662 \layout Standard
4684 4663
4685 4664 If called with no parameters,
4686 4665 \family typewriter
4687 4666 %alias
4688 4667 \family default
4689 4668 prints the table of currently defined aliases.
4690 4669 \layout Standard
4691 4670
4692 4671 The
4693 4672 \family typewriter
4694 4673 %rehash/rehashx
4695 4674 \family default
4696 4675 magics allow you to load your entire
4697 4676 \family typewriter
4698 4677 $PATH
4699 4678 \family default
4700 4679 as ipython aliases.
4701 4680 See their respective docstrings (or sec.\SpecialChar ~
4702 4681
4703 4682 \begin_inset LatexCommand \ref{sec:magic}
4704 4683
4705 4684 \end_inset
4706 4685
4707 4686 for further details).
4708 4687 \layout Subsection
4709 4688
4710 4689
4711 4690 \begin_inset LatexCommand \label{sec:dreload}
4712 4691
4713 4692 \end_inset
4714 4693
4715 4694 Recursive reload
4716 4695 \layout Standard
4717 4696
4718 4697 The
4719 4698 \family typewriter
4720 4699 %dreload
4721 4700 \family default
4722 4701 command does a recursive reload of a module: changes made to the module
4723 4702 since you imported will actually be available without having to exit.
4724 4703 \layout Subsection
4725 4704
4726 4705 Verbose and colored exception traceback printouts
4727 4706 \layout Standard
4728 4707
4729 4708 IPython provides the option to see very detailed exception tracebacks, which
4730 4709 can be especially useful when debugging large programs.
4731 4710 You can run any Python file with the
4732 4711 \family typewriter
4733 4712 %run
4734 4713 \family default
4735 4714 function to benefit from these detailed tracebacks.
4736 4715 Furthermore, both normal and verbose tracebacks can be colored (if your
4737 4716 terminal supports it) which makes them much easier to parse visually.
4738 4717 \layout Standard
4739 4718
4740 4719 See the magic
4741 4720 \family typewriter
4742 4721 xmode
4743 4722 \family default
4744 4723 and
4745 4724 \family typewriter
4746 4725 colors
4747 4726 \family default
4748 4727 functions for details (just type
4749 4728 \family typewriter
4750 4729 %magic
4751 4730 \family default
4752 4731 ).
4753 4732 \layout Standard
4754 4733
4755 4734 These features are basically a terminal version of Ka-Ping Yee's
4756 4735 \family typewriter
4757 4736 cgitb
4758 4737 \family default
4759 4738 module, now part of the standard Python library.
4760 4739 \layout Subsection
4761 4740
4762 4741
4763 4742 \begin_inset LatexCommand \label{sec:cache_input}
4764 4743
4765 4744 \end_inset
4766 4745
4767 4746 Input caching system
4768 4747 \layout Standard
4769 4748
4770 4749 IPython offers numbered prompts (In/Out) with input and output caching.
4771 4750 All input is saved and can be retrieved as variables (besides the usual
4772 4751 arrow key recall).
4773 4752 \layout Standard
4774 4753
4775 4754 The following GLOBAL variables always exist (so don't overwrite them!):
4776 4755
4777 4756 \family typewriter
4778 4757 _i
4779 4758 \family default
4780 4759 : stores previous input.
4781 4760
4782 4761 \family typewriter
4783 4762 _ii
4784 4763 \family default
4785 4764 : next previous.
4786 4765
4787 4766 \family typewriter
4788 4767 _iii
4789 4768 \family default
4790 4769 : next-next previous.
4791 4770
4792 4771 \family typewriter
4793 4772 _ih
4794 4773 \family default
4795 4774 : a list of all input
4796 4775 \family typewriter
4797 4776 _ih[n]
4798 4777 \family default
4799 4778 is the input from line
4800 4779 \family typewriter
4801 4780 n
4802 4781 \family default
4803 4782 and this list is aliased to the global variable
4804 4783 \family typewriter
4805 4784 In
4806 4785 \family default
4807 4786 .
4808 4787 If you overwrite
4809 4788 \family typewriter
4810 4789 In
4811 4790 \family default
4812 4791 with a variable of your own, you can remake the assignment to the internal
4813 4792 list with a simple
4814 4793 \family typewriter
4815 4794 'In=_ih'
4816 4795 \family default
4817 4796 .
4818 4797 \layout Standard
4819 4798
4820 4799 Additionally, global variables named
4821 4800 \family typewriter
4822 4801 _i<n>
4823 4802 \family default
4824 4803 are dynamically created (
4825 4804 \family typewriter
4826 4805 <n>
4827 4806 \family default
4828 4807 being the prompt counter), such that
4829 4808 \newline
4830 4809
4831 4810 \family typewriter
4832 4811 _i<n> == _ih[<n>] == In[<n>].
4833 4812 \layout Standard
4834 4813
4835 4814 For example, what you typed at prompt 14 is available as
4836 4815 \family typewriter
4837 4816 _i14,
4838 4817 \family default
4839 4818
4840 4819 \family typewriter
4841 4820 _ih[14]
4842 4821 \family default
4843 4822 and
4844 4823 \family typewriter
4845 4824 In[14]
4846 4825 \family default
4847 4826 .
4848 4827 \layout Standard
4849 4828
4850 4829 This allows you to easily cut and paste multi line interactive prompts by
4851 4830 printing them out: they print like a clean string, without prompt characters.
4852 4831 You can also manipulate them like regular variables (they are strings),
4853 4832 modify or exec them (typing
4854 4833 \family typewriter
4855 4834 'exec _i9'
4856 4835 \family default
4857 4836 will re-execute the contents of input prompt 9, '
4858 4837 \family typewriter
4859 4838 exec In[9:14]+In[18]
4860 4839 \family default
4861 4840 ' will re-execute lines 9 through 13 and line 18).
4862 4841 \layout Standard
4863 4842
4864 4843 You can also re-execute multiple lines of input easily by using the magic
4865 4844
4866 4845 \family typewriter
4867 4846 %macro
4868 4847 \family default
4869 4848 function (which automates the process and allows re-execution without having
4870 4849 to type '
4871 4850 \family typewriter
4872 4851 exec
4873 4852 \family default
4874 4853 ' every time).
4875 4854 The macro system also allows you to re-execute previous lines which include
4876 4855 magic function calls (which require special processing).
4877 4856 Type
4878 4857 \family typewriter
4879 4858 %macro?
4880 4859 \family default
4881 4860 or see sec.
4882 4861
4883 4862 \begin_inset LatexCommand \ref{sec:magic}
4884 4863
4885 4864 \end_inset
4886 4865
4887 4866 for more details on the macro system.
4888 4867 \layout Standard
4889 4868
4890 4869 A history function
4891 4870 \family typewriter
4892 4871 %hist
4893 4872 \family default
4894 4873 allows you to see any part of your input history by printing a range of
4895 4874 the
4896 4875 \family typewriter
4897 4876 _i
4898 4877 \family default
4899 4878 variables.
4900 4879 \layout Subsection
4901 4880
4902 4881
4903 4882 \begin_inset LatexCommand \label{sec:cache_output}
4904 4883
4905 4884 \end_inset
4906 4885
4907 4886 Output caching system
4908 4887 \layout Standard
4909 4888
4910 4889 For output that is returned from actions, a system similar to the input
4911 4890 cache exists but using
4912 4891 \family typewriter
4913 4892 _
4914 4893 \family default
4915 4894 instead of
4916 4895 \family typewriter
4917 4896 _i
4918 4897 \family default
4919 4898 .
4920 4899 Only actions that produce a result (NOT assignments, for example) are cached.
4921 4900 If you are familiar with Mathematica, IPython's
4922 4901 \family typewriter
4923 4902 _
4924 4903 \family default
4925 4904 variables behave exactly like Mathematica's
4926 4905 \family typewriter
4927 4906 %
4928 4907 \family default
4929 4908 variables.
4930 4909 \layout Standard
4931 4910
4932 4911 The following GLOBAL variables always exist (so don't overwrite them!):
4933 4912
4934 4913 \layout List
4935 4914 \labelwidthstring 00.00.0000
4936 4915
4937 4916
4938 4917 \family typewriter
4939 4918 \series bold
4940 4919 _
4941 4920 \family default
4942 4921 \series default
4943 4922 (a
4944 4923 \emph on
4945 4924 single
4946 4925 \emph default
4947 4926 underscore) : stores previous output, like Python's default interpreter.
4948 4927 \layout List
4949 4928 \labelwidthstring 00.00.0000
4950 4929
4951 4930
4952 4931 \family typewriter
4953 4932 \series bold
4954 4933 __
4955 4934 \family default
4956 4935 \series default
4957 4936 (two underscores): next previous.
4958 4937 \layout List
4959 4938 \labelwidthstring 00.00.0000
4960 4939
4961 4940
4962 4941 \family typewriter
4963 4942 \series bold
4964 4943 ___
4965 4944 \family default
4966 4945 \series default
4967 4946 (three underscores): next-next previous.
4968 4947 \layout Standard
4969 4948
4970 4949 Additionally, global variables named
4971 4950 \family typewriter
4972 4951 _<n>
4973 4952 \family default
4974 4953 are dynamically created (
4975 4954 \family typewriter
4976 4955 <n>
4977 4956 \family default
4978 4957 being the prompt counter), such that the result of output
4979 4958 \family typewriter
4980 4959 <n>
4981 4960 \family default
4982 4961 is always available as
4983 4962 \family typewriter
4984 4963 _<n>
4985 4964 \family default
4986 4965 (don't use the angle brackets, just the number, e.g.
4987 4966
4988 4967 \family typewriter
4989 4968 _21
4990 4969 \family default
4991 4970 ).
4992 4971 \layout Standard
4993 4972
4994 4973 These global variables are all stored in a global dictionary (not a list,
4995 4974 since it only has entries for lines which returned a result) available
4996 4975 under the names
4997 4976 \family typewriter
4998 4977 _oh
4999 4978 \family default
5000 4979 and
5001 4980 \family typewriter
5002 4981 Out
5003 4982 \family default
5004 4983 (similar to
5005 4984 \family typewriter
5006 4985 _ih
5007 4986 \family default
5008 4987 and
5009 4988 \family typewriter
5010 4989 In
5011 4990 \family default
5012 4991 ).
5013 4992 So the output from line 12 can be obtained as
5014 4993 \family typewriter
5015 4994 _12
5016 4995 \family default
5017 4996 ,
5018 4997 \family typewriter
5019 4998 Out[12]
5020 4999 \family default
5021 5000 or
5022 5001 \family typewriter
5023 5002 _oh[12]
5024 5003 \family default
5025 5004 .
5026 5005 If you accidentally overwrite the
5027 5006 \family typewriter
5028 5007 Out
5029 5008 \family default
5030 5009 variable you can recover it by typing
5031 5010 \family typewriter
5032 5011 'Out=_oh
5033 5012 \family default
5034 5013 ' at the prompt.
5035 5014 \layout Standard
5036 5015
5037 5016 This system obviously can potentially put heavy memory demands on your system,
5038 5017 since it prevents Python's garbage collector from removing any previously
5039 5018 computed results.
5040 5019 You can control how many results are kept in memory with the option (at
5041 5020 the command line or in your
5042 5021 \family typewriter
5043 5022 ipythonrc
5044 5023 \family default
5045 5024 file)
5046 5025 \family typewriter
5047 5026 cache_size
5048 5027 \family default
5049 5028 .
5050 5029 If you set it to 0, the whole system is completely disabled and the prompts
5051 5030 revert to the classic
5052 5031 \family typewriter
5053 5032 '>>>'
5054 5033 \family default
5055 5034 of normal Python.
5056 5035 \layout Subsection
5057 5036
5058 5037 Directory history
5059 5038 \layout Standard
5060 5039
5061 5040 Your history of visited directories is kept in the global list
5062 5041 \family typewriter
5063 5042 _dh
5064 5043 \family default
5065 5044 , and the magic
5066 5045 \family typewriter
5067 5046 %cd
5068 5047 \family default
5069 5048 command can be used to go to any entry in that list.
5070 5049 The
5071 5050 \family typewriter
5072 5051 %dhist
5073 5052 \family default
5074 5053 command allows you to view this history.
5075 5054 \layout Subsection
5076 5055
5077 5056 Automatic parentheses and quotes
5078 5057 \layout Standard
5079 5058
5080 5059 These features were adapted from Nathan Gray's LazyPython.
5081 5060 They are meant to allow less typing for common situations.
5082 5061 \layout Subsubsection
5083 5062
5084 5063 Automatic parentheses
5085 5064 \layout Standard
5086 5065
5087 5066 Callable objects (i.e.
5088 5067 functions, methods, etc) can be invoked like this (notice the commas between
5089 5068 the arguments):
5090 5069 \layout Standard
5091 5070
5092 5071
5093 5072 \family typewriter
5094 5073 >>> callable_ob arg1, arg2, arg3
5095 5074 \layout Standard
5096 5075
5097 5076 and the input will be translated to this:
5098 5077 \layout Standard
5099 5078
5100 5079
5101 5080 \family typewriter
5102 5081 --> callable_ob(arg1, arg2, arg3)
5103 5082 \layout Standard
5104 5083
5105 5084 You can force automatic parentheses by using '/' as the first character
5106 5085 of a line.
5107 5086 For example:
5108 5087 \layout Standard
5109 5088
5110 5089
5111 5090 \family typewriter
5112 5091 >>> /globals # becomes 'globals()'
5113 5092 \layout Standard
5114 5093
5115 5094 Note that the '/' MUST be the first character on the line! This won't work:
5116 5095
5117 5096 \layout Standard
5118 5097
5119 5098
5120 5099 \family typewriter
5121 5100 >>> print /globals # syntax error
5122 5101 \layout Standard
5123 5102
5124 5103 In most cases the automatic algorithm should work, so you should rarely
5125 5104 need to explicitly invoke /.
5126 5105 One notable exception is if you are trying to call a function with a list
5127 5106 of tuples as arguments (the parenthesis will confuse IPython):
5128 5107 \layout Standard
5129 5108
5130 5109
5131 5110 \family typewriter
5132 5111 In [1]: zip (1,2,3),(4,5,6) # won't work
5133 5112 \layout Standard
5134 5113
5135 5114 but this will work:
5136 5115 \layout Standard
5137 5116
5138 5117
5139 5118 \family typewriter
5140 5119 In [2]: /zip (1,2,3),(4,5,6)
5141 5120 \newline
5142 5121 ------> zip ((1,2,3),(4,5,6))
5143 5122 \newline
5144 5123 Out[2]= [(1, 4), (2, 5), (3, 6)]
5145 5124 \layout Standard
5146 5125
5147 5126 IPython tells you that it has altered your command line by displaying the
5148 5127 new command line preceded by
5149 5128 \family typewriter
5150 5129 -->
5151 5130 \family default
5152 5131 .
5153 5132 e.g.:
5154 5133 \layout Standard
5155 5134
5156 5135
5157 5136 \family typewriter
5158 5137 In [18]: callable list
5159 5138 \newline
5160 5139 -------> callable (list)
5161 5140 \layout Subsubsection
5162 5141
5163 5142 Automatic quoting
5164 5143 \layout Standard
5165 5144
5166 5145 You can force automatic quoting of a function's arguments by using
5167 5146 \family typewriter
5168 5147 `,'
5169 5148 \family default
5170 5149 or
5171 5150 \family typewriter
5172 5151 `;'
5173 5152 \family default
5174 5153 as the first character of a line.
5175 5154 For example:
5176 5155 \layout Standard
5177 5156
5178 5157
5179 5158 \family typewriter
5180 5159 >>> ,my_function /home/me # becomes my_function("/home/me")
5181 5160 \layout Standard
5182 5161
5183 5162 If you use
5184 5163 \family typewriter
5185 5164 `;'
5186 5165 \family default
5187 5166 instead, the whole argument is quoted as a single string (while
5188 5167 \family typewriter
5189 5168 `,'
5190 5169 \family default
5191 5170 splits on whitespace):
5192 5171 \layout Standard
5193 5172
5194 5173
5195 5174 \family typewriter
5196 5175 >>> ,my_function a b c # becomes my_function("a","b","c")
5197 5176 \layout Standard
5198 5177
5199 5178
5200 5179 \family typewriter
5201 5180 >>> ;my_function a b c # becomes my_function("a b c")
5202 5181 \layout Standard
5203 5182
5204 5183 Note that the `
5205 5184 \family typewriter
5206 5185 ,
5207 5186 \family default
5208 5187 ' or `
5209 5188 \family typewriter
5210 5189 ;
5211 5190 \family default
5212 5191 ' MUST be the first character on the line! This won't work:
5213 5192 \layout Standard
5214 5193
5215 5194
5216 5195 \family typewriter
5217 5196 >>> x = ,my_function /home/me # syntax error
5218 5197 \layout Section
5219 5198
5220 5199
5221 5200 \begin_inset LatexCommand \label{sec:customization}
5222 5201
5223 5202 \end_inset
5224 5203
5225 5204 Customization
5226 5205 \layout Standard
5227 5206
5228 5207 As we've already mentioned, IPython reads a configuration file which can
5229 5208 be specified at the command line (
5230 5209 \family typewriter
5231 5210 -rcfile
5232 5211 \family default
5233 5212 ) or which by default is assumed to be called
5234 5213 \family typewriter
5235 5214 ipythonrc
5236 5215 \family default
5237 5216 .
5238 5217 Such a file is looked for in the current directory where IPython is started
5239 5218 and then in your
5240 5219 \family typewriter
5241 5220 IPYTHONDIR
5242 5221 \family default
5243 5222 , which allows you to have local configuration files for specific projects.
5244 5223 In this section we will call these types of configuration files simply
5245 5224 rcfiles (short for resource configuration file).
5246 5225 \layout Standard
5247 5226
5248 5227 The syntax of an rcfile is one of key-value pairs separated by whitespace,
5249 5228 one per line.
5250 5229 Lines beginning with a
5251 5230 \family typewriter
5252 5231 #
5253 5232 \family default
5254 5233 are ignored as comments, but comments can
5255 5234 \series bold
5256 5235 not
5257 5236 \series default
5258 5237 be put on lines with data (the parser is fairly primitive).
5259 5238 Note that these are not python files, and this is deliberate, because it
5260 5239 allows us to do some things which would be quite tricky to implement if
5261 5240 they were normal python files.
5262 5241 \layout Standard
5263 5242
5264 5243 First, an rcfile can contain permanent default values for almost all command
5265 5244 line options (except things like
5266 5245 \family typewriter
5267 5246 -help
5268 5247 \family default
5269 5248 or
5270 5249 \family typewriter
5271 5250 -Version
5272 5251 \family default
5273 5252 ).
5274 5253 Sec\SpecialChar ~
5275 5254
5276 5255 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5277 5256
5278 5257 \end_inset
5279 5258
5280 5259 contains a description of all command-line options.
5281 5260 However, values you explicitly specify at the command line override the
5282 5261 values defined in the rcfile.
5283 5262 \layout Standard
5284 5263
5285 5264 Besides command line option values, the rcfile can specify values for certain
5286 5265 extra special options which are not available at the command line.
5287 5266 These options are briefly described below.
5288 5267
5289 5268 \layout Standard
5290 5269
5291 5270 Each of these options may appear as many times as you need it in the file.
5292 5271 \layout List
5293 5272 \labelwidthstring 00.00.0000
5294 5273
5295 5274
5296 5275 \family typewriter
5297 5276 \series bold
5298 5277 include\SpecialChar ~
5299 5278 <file1>\SpecialChar ~
5300 5279 <file2>\SpecialChar ~
5301 5280 ...
5302 5281 \family default
5303 5282 \series default
5304 5283 : you can name
5305 5284 \emph on
5306 5285 other
5307 5286 \emph default
5308 5287 rcfiles you want to recursively load up to 15 levels (don't use the
5309 5288 \family typewriter
5310 5289 <>
5311 5290 \family default
5312 5291 brackets in your names!).
5313 5292 This feature allows you to define a 'base' rcfile with general options
5314 5293 and special-purpose files which can be loaded only when needed with particular
5315 5294 configuration options.
5316 5295 To make this more convenient, IPython accepts the
5317 5296 \family typewriter
5318 5297 -profile <name>
5319 5298 \family default
5320 5299 option (abbreviates to
5321 5300 \family typewriter
5322 5301 -p <name
5323 5302 \family default
5324 5303 >)
5325 5304 \family typewriter
5326 5305 which
5327 5306 \family default
5328 5307 tells it to look for an rcfile named
5329 5308 \family typewriter
5330 5309 ipythonrc-<name>
5331 5310 \family default
5332 5311 .
5333 5312
5334 5313 \layout List
5335 5314 \labelwidthstring 00.00.0000
5336 5315
5337 5316
5338 5317 \family typewriter
5339 5318 \series bold
5340 5319 import_mod\SpecialChar ~
5341 5320 <mod1>\SpecialChar ~
5342 5321 <mod2>\SpecialChar ~
5343 5322 ...
5344 5323 \family default
5345 5324 \series default
5346 5325 : import modules with '
5347 5326 \family typewriter
5348 5327 import
5349 5328 \family default
5350 5329
5351 5330 \family typewriter
5352 5331 <mod1>,<mod2>,...
5353 5332 \family default
5354 5333 '
5355 5334 \layout List
5356 5335 \labelwidthstring 00.00.0000
5357 5336
5358 5337
5359 5338 \family typewriter
5360 5339 \series bold
5361 5340 import_some\SpecialChar ~
5362 5341 <mod>\SpecialChar ~
5363 5342 <f1>\SpecialChar ~
5364 5343 <f2>\SpecialChar ~
5365 5344 ...
5366 5345 \family default
5367 5346 \series default
5368 5347 : import functions with '
5369 5348 \family typewriter
5370 5349 from <mod> import
5371 5350 \family default
5372 5351
5373 5352 \family typewriter
5374 5353 <f1>,<f2>,...
5375 5354 \family default
5376 5355 '
5377 5356 \layout List
5378 5357 \labelwidthstring 00.00.0000
5379 5358
5380 5359
5381 5360 \family typewriter
5382 5361 \series bold
5383 5362 import_all\SpecialChar ~
5384 5363 <mod1>\SpecialChar ~
5385 5364 <mod2>\SpecialChar ~
5386 5365 ...
5387 5366 \family default
5388 5367 \series default
5389 5368 : for each module listed import functions with '
5390 5369 \family typewriter
5391 5370 from <mod> import *
5392 5371 \family default
5393 5372 '
5394 5373 \layout List
5395 5374 \labelwidthstring 00.00.0000
5396 5375
5397 5376
5398 5377 \family typewriter
5399 5378 \series bold
5400 5379 execute\SpecialChar ~
5401 5380 <python\SpecialChar ~
5402 5381 code>
5403 5382 \family default
5404 5383 \series default
5405 5384 : give any single-line python code to be executed.
5406 5385 \layout List
5407 5386 \labelwidthstring 00.00.0000
5408 5387
5409 5388
5410 5389 \family typewriter
5411 5390 \series bold
5412 5391 execfile\SpecialChar ~
5413 5392 <filename>
5414 5393 \family default
5415 5394 \series default
5416 5395 : execute the python file given with an '
5417 5396 \family typewriter
5418 5397 execfile(filename)
5419 5398 \family default
5420 5399 ' command.
5421 5400 Username expansion is performed on the given names.
5422 5401 So if you need any amount of extra fancy customization that won't fit in
5423 5402 any of the above 'canned' options, you can just put it in a separate python
5424 5403 file and execute it.
5425 5404 \layout List
5426 5405 \labelwidthstring 00.00.0000
5427 5406
5428 5407
5429 5408 \family typewriter
5430 5409 \series bold
5431 5410 alias\SpecialChar ~
5432 5411 <alias_def>
5433 5412 \family default
5434 5413 \series default
5435 5414 : this is equivalent to calling '
5436 5415 \family typewriter
5437 5416 %alias\SpecialChar ~
5438 5417 <alias_def>
5439 5418 \family default
5440 5419 ' at the IPython command line.
5441 5420 This way, from within IPython you can do common system tasks without having
5442 5421 to exit it or use the
5443 5422 \family typewriter
5444 5423 !
5445 5424 \family default
5446 5425 escape.
5447 5426 IPython isn't meant to be a shell replacement, but it is often very useful
5448 5427 to be able to do things with files while testing code.
5449 5428 This gives you the flexibility to have within IPython any aliases you may
5450 5429 be used to under your normal system shell.
5451 5430 \layout Subsection
5452 5431
5453 5432
5454 5433 \begin_inset LatexCommand \label{sec:ipytonrc-sample}
5455 5434
5456 5435 \end_inset
5457 5436
5458 5437 Sample
5459 5438 \family typewriter
5460 5439 ipythonrc
5461 5440 \family default
5462 5441 file
5463 5442 \layout Standard
5464 5443
5465 5444 The default rcfile, called
5466 5445 \family typewriter
5467 5446 ipythonrc
5468 5447 \family default
5469 5448 and supplied in your
5470 5449 \family typewriter
5471 5450 IPYTHONDIR
5472 5451 \family default
5473 5452 directory contains lots of comments on all of these options.
5474 5453 We reproduce it here for reference:
5475 5454 \layout Standard
5476 5455
5477 5456
5478 5457 \begin_inset ERT
5479 5458 status Open
5480 5459
5481 5460 \layout Standard
5482 5461
5483 5462 \backslash
5484 5463 codelist{../IPython/UserConfig/ipythonrc}
5485 5464 \end_inset
5486 5465
5487 5466
5488 5467 \layout Subsection
5489 5468
5490 5469
5491 5470 \begin_inset LatexCommand \label{sec:prompts}
5492 5471
5493 5472 \end_inset
5494 5473
5495 5474 Fine-tuning your prompt
5496 5475 \layout Standard
5497 5476
5498 5477 IPython's prompts can be customized using a syntax similar to that of the
5499 5478
5500 5479 \family typewriter
5501 5480 bash
5502 5481 \family default
5503 5482 shell.
5504 5483 Many of
5505 5484 \family typewriter
5506 5485 bash
5507 5486 \family default
5508 5487 's escapes are supported, as well as a few additional ones.
5509 5488 We list them below:
5510 5489 \layout Description
5511 5490
5512 5491
5513 5492 \backslash
5514 5493 # the prompt/history count number
5515 5494 \layout Description
5516 5495
5517 5496
5518 5497 \backslash
5519 5498 D the prompt/history count, with the actual digits replaced by dots.
5520 5499 Used mainly in continuation prompts (prompt_in2)
5521 5500 \layout Description
5522 5501
5523 5502
5524 5503 \backslash
5525 5504 w the current working directory
5526 5505 \layout Description
5527 5506
5528 5507
5529 5508 \backslash
5530 5509 W the basename of current working directory
5531 5510 \layout Description
5532 5511
5533 5512
5534 5513 \backslash
5535 5514 X
5536 5515 \emph on
5537 5516 n
5538 5517 \emph default
5539 5518 where
5540 5519 \begin_inset Formula $n=0\ldots5.$
5541 5520 \end_inset
5542 5521
5543 5522 The current working directory, with
5544 5523 \family typewriter
5545 5524 $HOME
5546 5525 \family default
5547 5526 replaced by
5548 5527 \family typewriter
5549 5528 ~
5550 5529 \family default
5551 5530 , and filtered out to contain only
5552 5531 \begin_inset Formula $n$
5553 5532 \end_inset
5554 5533
5555 5534 path elements
5556 5535 \layout Description
5557 5536
5558 5537
5559 5538 \backslash
5560 5539 Y
5561 5540 \emph on
5562 5541 n
5563 5542 \emph default
5564 5543 Similar to
5565 5544 \backslash
5566 5545 X
5567 5546 \emph on
5568 5547 n
5569 5548 \emph default
5570 5549 , but with the
5571 5550 \begin_inset Formula $n+1$
5572 5551 \end_inset
5573 5552
5574 5553 element included if it is
5575 5554 \family typewriter
5576 5555 ~
5577 5556 \family default
5578 5557 (this is similar to the behavior of the %c
5579 5558 \emph on
5580 5559 n
5581 5560 \emph default
5582 5561 escapes in
5583 5562 \family typewriter
5584 5563 tcsh
5585 5564 \family default
5586 5565 )
5587 5566 \layout Description
5588 5567
5589 5568
5590 5569 \backslash
5591 5570 u the username of the current user
5592 5571 \layout Description
5593 5572
5594 5573
5595 5574 \backslash
5596 5575 $ if the effective UID is 0, a #, otherwise a $
5597 5576 \layout Description
5598 5577
5599 5578
5600 5579 \backslash
5601 5580 h the hostname up to the first `.'
5602 5581 \layout Description
5603 5582
5604 5583
5605 5584 \backslash
5606 5585 H the hostname
5607 5586 \layout Description
5608 5587
5609 5588
5610 5589 \backslash
5611 5590 n a newline
5612 5591 \layout Description
5613 5592
5614 5593
5615 5594 \backslash
5616 5595 r a carriage return
5617 5596 \layout Description
5618 5597
5619 5598
5620 5599 \backslash
5621 5600 v IPython version string
5622 5601 \layout Standard
5623 5602
5624 5603 In addition to these, ANSI color escapes can be insterted into the prompts,
5625 5604 as
5626 5605 \family typewriter
5627 5606
5628 5607 \backslash
5629 5608 C_
5630 5609 \emph on
5631 5610 ColorName
5632 5611 \family default
5633 5612 \emph default
5634 5613 .
5635 5614 The list of valid color names is: Black, Blue, Brown, Cyan, DarkGray, Green,
5636 5615 LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, NoColor,
5637 5616 Normal, Purple, Red, White, Yellow.
5638 5617 \layout Standard
5639 5618
5640 5619 Finally, IPython supports the evaluation of arbitrary expressions in your
5641 5620 prompt string.
5642 5621 The prompt strings are evaluated through the syntax of PEP 215, but basically
5643 5622 you can use
5644 5623 \family typewriter
5645 5624 $x.y
5646 5625 \family default
5647 5626 to expand the value of
5648 5627 \family typewriter
5649 5628 x.y
5650 5629 \family default
5651 5630 , and for more complicated expressions you can use braces:
5652 5631 \family typewriter
5653 5632 ${foo()+x}
5654 5633 \family default
5655 5634 will call function
5656 5635 \family typewriter
5657 5636 foo
5658 5637 \family default
5659 5638 and add to it the value of
5660 5639 \family typewriter
5661 5640 x
5662 5641 \family default
5663 5642 , before putting the result into your prompt.
5664 5643 For example, using
5665 5644 \newline
5666 5645
5667 5646 \family typewriter
5668 5647 prompt_in1 '${commands.getoutput("uptime")}
5669 5648 \backslash
5670 5649 nIn [
5671 5650 \backslash
5672 5651 #]: '
5673 5652 \newline
5674 5653
5675 5654 \family default
5676 5655 will print the result of the uptime command on each prompt (assuming the
5677 5656
5678 5657 \family typewriter
5679 5658 commands
5680 5659 \family default
5681 5660 module has been imported in your
5682 5661 \family typewriter
5683 5662 ipythonrc
5684 5663 \family default
5685 5664 file).
5686 5665 \layout Subsubsection
5687 5666
5688 5667 Prompt examples
5689 5668 \layout Standard
5690 5669
5691 5670 The following options in an ipythonrc file will give you IPython's default
5692 5671 prompts:
5693 5672 \layout Standard
5694 5673
5695 5674
5696 5675 \family typewriter
5697 5676 prompt_in1 'In [
5698 5677 \backslash
5699 5678 #]:'
5700 5679 \newline
5701 5680 prompt_in2 '\SpecialChar ~
5702 5681 \SpecialChar ~
5703 5682 \SpecialChar ~
5704 5683 .
5705 5684 \backslash
5706 5685 D.:'
5707 5686 \newline
5708 5687 prompt_out 'Out[
5709 5688 \backslash
5710 5689 #]:'
5711 5690 \layout Standard
5712 5691
5713 5692 which look like this:
5714 5693 \layout Standard
5715 5694
5716 5695
5717 5696 \family typewriter
5718 5697 In [1]: 1+2
5719 5698 \newline
5720 5699 Out[1]: 3
5721 5700 \layout Standard
5722 5701
5723 5702
5724 5703 \family typewriter
5725 5704 In [2]: for i in (1,2,3):
5726 5705 \newline
5727 5706
5728 5707 \begin_inset ERT
5729 5708 status Collapsed
5730 5709
5731 5710 \layout Standard
5732 5711
5733 5712 \backslash
5734 5713 hspace*{0mm}
5735 5714 \end_inset
5736 5715
5737 5716 \SpecialChar ~
5738 5717 \SpecialChar ~
5739 5718 \SpecialChar ~
5740 5719 ...: \SpecialChar ~
5741 5720 \SpecialChar ~
5742 5721 \SpecialChar ~
5743 5722 \SpecialChar ~
5744 5723 print i,
5745 5724 \newline
5746 5725
5747 5726 \begin_inset ERT
5748 5727 status Collapsed
5749 5728
5750 5729 \layout Standard
5751 5730
5752 5731 \backslash
5753 5732 hspace*{0mm}
5754 5733 \end_inset
5755 5734
5756 5735 \SpecialChar ~
5757 5736 \SpecialChar ~
5758 5737 \SpecialChar ~
5759 5738 ...:
5760 5739 \newline
5761 5740 1 2 3
5762 5741 \layout Standard
5763 5742
5764 5743 These will give you a very colorful prompt with path information:
5765 5744 \layout Standard
5766 5745
5767 5746
5768 5747 \family typewriter
5769 5748 #prompt_in1 '
5770 5749 \backslash
5771 5750 C_Red
5772 5751 \backslash
5773 5752 u
5774 5753 \backslash
5775 5754 C_Blue[
5776 5755 \backslash
5777 5756 C_Cyan
5778 5757 \backslash
5779 5758 Y1
5780 5759 \backslash
5781 5760 C_Blue]
5782 5761 \backslash
5783 5762 C_LightGreen
5784 5763 \backslash
5785 5764 #>'
5786 5765 \newline
5787 5766 prompt_in2 ' ..
5788 5767 \backslash
5789 5768 D>'
5790 5769 \newline
5791 5770 prompt_out '<
5792 5771 \backslash
5793 5772 #>'
5794 5773 \layout Standard
5795 5774
5796 5775 which look like this:
5797 5776 \layout Standard
5798 5777
5799 5778
5800 5779 \family typewriter
5801 5780 \color red
5802 5781 fperez
5803 5782 \color blue
5804 5783 [
5805 5784 \color cyan
5806 5785 ~/ipython
5807 5786 \color blue
5808 5787 ]
5809 5788 \color green
5810 5789 1>
5811 5790 \color default
5812 5791 1+2
5813 5792 \newline
5814 5793
5815 5794 \begin_inset ERT
5816 5795 status Collapsed
5817 5796
5818 5797 \layout Standard
5819 5798
5820 5799 \backslash
5821 5800 hspace*{0mm}
5822 5801 \end_inset
5823 5802
5824 5803 \SpecialChar ~
5825 5804 \SpecialChar ~
5826 5805 \SpecialChar ~
5827 5806 \SpecialChar ~
5828 5807 \SpecialChar ~
5829 5808 \SpecialChar ~
5830 5809 \SpecialChar ~
5831 5810 \SpecialChar ~
5832 5811 \SpecialChar ~
5833 5812 \SpecialChar ~
5834 5813 \SpecialChar ~
5835 5814 \SpecialChar ~
5836 5815 \SpecialChar ~
5837 5816 \SpecialChar ~
5838 5817 \SpecialChar ~
5839 5818 \SpecialChar ~
5840 5819
5841 5820 \color red
5842 5821 <1>
5843 5822 \color default
5844 5823 3
5845 5824 \newline
5846 5825
5847 5826 \color red
5848 5827 fperez
5849 5828 \color blue
5850 5829 [
5851 5830 \color cyan
5852 5831 ~/ipython
5853 5832 \color blue
5854 5833 ]
5855 5834 \color green
5856 5835 2>
5857 5836 \color default
5858 5837 for i in (1,2,3):
5859 5838 \newline
5860 5839
5861 5840 \begin_inset ERT
5862 5841 status Collapsed
5863 5842
5864 5843 \layout Standard
5865 5844
5866 5845 \backslash
5867 5846 hspace*{0mm}
5868 5847 \end_inset
5869 5848
5870 5849 \SpecialChar ~
5871 5850 \SpecialChar ~
5872 5851 \SpecialChar ~
5873 5852 \SpecialChar ~
5874 5853 \SpecialChar ~
5875 5854 \SpecialChar ~
5876 5855 \SpecialChar ~
5877 5856 \SpecialChar ~
5878 5857 \SpecialChar ~
5879 5858 \SpecialChar ~
5880 5859 \SpecialChar ~
5881 5860 \SpecialChar ~
5882 5861 \SpecialChar ~
5883 5862 \SpecialChar ~
5884 5863 \SpecialChar ~
5885 5864
5886 5865 \color green
5887 5866 ...>
5888 5867 \color default
5889 5868 \SpecialChar ~
5890 5869 \SpecialChar ~
5891 5870 \SpecialChar ~
5892 5871 \SpecialChar ~
5893 5872 print i,
5894 5873 \newline
5895 5874
5896 5875 \begin_inset ERT
5897 5876 status Collapsed
5898 5877
5899 5878 \layout Standard
5900 5879
5901 5880 \backslash
5902 5881 hspace*{0mm}
5903 5882 \end_inset
5904 5883
5905 5884 \SpecialChar ~
5906 5885 \SpecialChar ~
5907 5886 \SpecialChar ~
5908 5887 \SpecialChar ~
5909 5888 \SpecialChar ~
5910 5889 \SpecialChar ~
5911 5890 \SpecialChar ~
5912 5891 \SpecialChar ~
5913 5892 \SpecialChar ~
5914 5893 \SpecialChar ~
5915 5894 \SpecialChar ~
5916 5895 \SpecialChar ~
5917 5896 \SpecialChar ~
5918 5897 \SpecialChar ~
5919 5898 \SpecialChar ~
5920 5899
5921 5900 \color green
5922 5901 ...>
5923 5902 \color default
5924 5903
5925 5904 \newline
5926 5905 1 2 3
5927 5906 \layout Standard
5928 5907
5929 5908 The following shows the usage of dynamic expression evaluation:
5930 5909 \layout Subsection
5931 5910
5932 5911
5933 5912 \begin_inset LatexCommand \label{sec:profiles}
5934 5913
5935 5914 \end_inset
5936 5915
5937 5916 IPython profiles
5938 5917 \layout Standard
5939 5918
5940 5919 As we already mentioned, IPython supports the
5941 5920 \family typewriter
5942 5921 -profile
5943 5922 \family default
5944 5923 command-line option (see sec.
5945 5924
5946 5925 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5947 5926
5948 5927 \end_inset
5949 5928
5950 5929 ).
5951 5930 A profile is nothing more than a particular configuration file like your
5952 5931 basic
5953 5932 \family typewriter
5954 5933 ipythonrc
5955 5934 \family default
5956 5935 one, but with particular customizations for a specific purpose.
5957 5936 When you start IPython with '
5958 5937 \family typewriter
5959 5938 ipython -profile <name>
5960 5939 \family default
5961 5940 ', it assumes that in your
5962 5941 \family typewriter
5963 5942 IPYTHONDIR
5964 5943 \family default
5965 5944 there is a file called
5966 5945 \family typewriter
5967 5946 ipythonrc-<name>
5968 5947 \family default
5969 5948 , and loads it instead of the normal
5970 5949 \family typewriter
5971 5950 ipythonrc
5972 5951 \family default
5973 5952 .
5974 5953 \layout Standard
5975 5954
5976 5955 This system allows you to maintain multiple configurations which load modules,
5977 5956 set options, define functions, etc.
5978 5957 suitable for different tasks and activate them in a very simple manner.
5979 5958 In order to avoid having to repeat all of your basic options (common things
5980 5959 that don't change such as your color preferences, for example), any profile
5981 5960 can include another configuration file.
5982 5961 The most common way to use profiles is then to have each one include your
5983 5962 basic
5984 5963 \family typewriter
5985 5964 ipythonrc
5986 5965 \family default
5987 5966 file as a starting point, and then add further customizations.
5988 5967 \layout Standard
5989 5968
5990 5969 In sections
5991 5970 \begin_inset LatexCommand \ref{sec:syntax-extensions}
5992 5971
5993 5972 \end_inset
5994 5973
5995 5974 and
5996 5975 \begin_inset LatexCommand \ref{sec:Gnuplot}
5997 5976
5998 5977 \end_inset
5999 5978
6000 5979 we discuss some particular profiles which come as part of the standard
6001 5980 IPython distribution.
6002 5981 You may also look in your
6003 5982 \family typewriter
6004 5983 IPYTHONDIR
6005 5984 \family default
6006 5985 directory, any file whose name begins with
6007 5986 \family typewriter
6008 5987 ipythonrc-
6009 5988 \family default
6010 5989 is a profile.
6011 5990 You can use those as examples for further customizations to suit your own
6012 5991 needs.
6013 5992 \layout Section
6014 5993
6015 5994
6016 5995 \begin_inset OptArg
6017 5996 collapsed false
6018 5997
6019 5998 \layout Standard
6020 5999
6021 6000 IPython as default...
6022 6001 \end_inset
6023 6002
6024 6003 IPython as your default Python environment
6025 6004 \layout Standard
6026 6005
6027 6006 Python honors the environment variable
6028 6007 \family typewriter
6029 6008 PYTHONSTARTUP
6030 6009 \family default
6031 6010 and will execute at startup the file referenced by this variable.
6032 6011 If you put at the end of this file the following two lines of code:
6033 6012 \layout Standard
6034 6013
6035 6014
6036 6015 \family typewriter
6037 6016 import IPython
6038 6017 \newline
6039 6018 IPython.Shell.IPShell().mainloop(sys_exit=1)
6040 6019 \layout Standard
6041 6020
6042 6021 then IPython will be your working environment anytime you start Python.
6043 6022 The
6044 6023 \family typewriter
6045 6024 sys_exit=1
6046 6025 \family default
6047 6026 is needed to have IPython issue a call to
6048 6027 \family typewriter
6049 6028 sys.exit()
6050 6029 \family default
6051 6030 when it finishes, otherwise you'll be back at the normal Python '
6052 6031 \family typewriter
6053 6032 >>>
6054 6033 \family default
6055 6034 ' prompt
6056 6035 \begin_inset Foot
6057 6036 collapsed true
6058 6037
6059 6038 \layout Standard
6060 6039
6061 6040 Based on an idea by Holger Krekel.
6062 6041 \end_inset
6063 6042
6064 6043 .
6065 6044 \layout Standard
6066 6045
6067 6046 This is probably useful to developers who manage multiple Python versions
6068 6047 and don't want to have correspondingly multiple IPython versions.
6069 6048 Note that in this mode, there is no way to pass IPython any command-line
6070 6049 options, as those are trapped first by Python itself.
6071 6050 \layout Section
6072 6051
6073 6052
6074 6053 \begin_inset LatexCommand \label{sec:embed}
6075 6054
6076 6055 \end_inset
6077 6056
6078 6057 Embedding IPython
6079 6058 \layout Standard
6080 6059
6081 6060 It is possible to start an IPython instance
6082 6061 \emph on
6083 6062 inside
6084 6063 \emph default
6085 6064 your own Python programs.
6086 6065 This allows you to evaluate dynamically the state of your code, operate
6087 6066 with your variables, analyze them, etc.
6088 6067 Note however that any changes you make to values while in the shell do
6089 6068
6090 6069 \emph on
6091 6070 not
6092 6071 \emph default
6093 6072 propagate back to the running code, so it is safe to modify your values
6094 6073 because you won't break your code in bizarre ways by doing so.
6095 6074 \layout Standard
6096 6075
6097 6076 This feature allows you to easily have a fully functional python environment
6098 6077 for doing object introspection anywhere in your code with a simple function
6099 6078 call.
6100 6079 In some cases a simple print statement is enough, but if you need to do
6101 6080 more detailed analysis of a code fragment this feature can be very valuable.
6102 6081 \layout Standard
6103 6082
6104 6083 It can also be useful in scientific computing situations where it is common
6105 6084 to need to do some automatic, computationally intensive part and then stop
6106 6085 to look at data, plots, etc
6107 6086 \begin_inset Foot
6108 6087 collapsed true
6109 6088
6110 6089 \layout Standard
6111 6090
6112 6091 This functionality was inspired by IDL's combination of the
6113 6092 \family typewriter
6114 6093 stop
6115 6094 \family default
6116 6095 keyword and the
6117 6096 \family typewriter
6118 6097 .continue
6119 6098 \family default
6120 6099 executive command, which I have found very useful in the past, and by a
6121 6100 posting on comp.lang.python by cmkl <cmkleffner-AT-gmx.de> on Dec.
6122 6101 06/01 concerning similar uses of pyrepl.
6123 6102 \end_inset
6124 6103
6125 6104 .
6126 6105 Opening an IPython instance will give you full access to your data and
6127 6106 functions, and you can resume program execution once you are done with
6128 6107 the interactive part (perhaps to stop again later, as many times as needed).
6129 6108 \layout Standard
6130 6109
6131 6110 The following code snippet is the bare minimum you need to include in your
6132 6111 Python programs for this to work (detailed examples follow later):
6133 6112 \layout LyX-Code
6134 6113
6135 6114 from IPython.Shell import IPShellEmbed
6136 6115 \layout LyX-Code
6137 6116
6138 6117 ipshell = IPShellEmbed()
6139 6118 \layout LyX-Code
6140 6119
6141 6120 ipshell() # this call anywhere in your program will start IPython
6142 6121 \layout Standard
6143 6122
6144 6123 You can run embedded instances even in code which is itself being run at
6145 6124 the IPython interactive prompt with '
6146 6125 \family typewriter
6147 6126 %run\SpecialChar ~
6148 6127 <filename>
6149 6128 \family default
6150 6129 '.
6151 6130 Since it's easy to get lost as to where you are (in your top-level IPython
6152 6131 or in your embedded one), it's a good idea in such cases to set the in/out
6153 6132 prompts to something different for the embedded instances.
6154 6133 The code examples below illustrate this.
6155 6134 \layout Standard
6156 6135
6157 6136 You can also have multiple IPython instances in your program and open them
6158 6137 separately, for example with different options for data presentation.
6159 6138 If you close and open the same instance multiple times, its prompt counters
6160 6139 simply continue from each execution to the next.
6161 6140 \layout Standard
6162 6141
6163 6142 Please look at the docstrings in the
6164 6143 \family typewriter
6165 6144 Shell.py
6166 6145 \family default
6167 6146 module for more details on the use of this system.
6168 6147 \layout Standard
6169 6148
6170 6149 The following sample file illustrating how to use the embedding functionality
6171 6150 is provided in the examples directory as
6172 6151 \family typewriter
6173 6152 example-embed.py
6174 6153 \family default
6175 6154 .
6176 6155 It should be fairly self-explanatory:
6177 6156 \layout Standard
6178 6157
6179 6158
6180 6159 \begin_inset ERT
6181 6160 status Open
6182 6161
6183 6162 \layout Standard
6184 6163
6185 6164 \backslash
6186 6165 codelist{examples/example-embed.py}
6187 6166 \end_inset
6188 6167
6189 6168
6190 6169 \layout Standard
6191 6170
6192 6171 Once you understand how the system functions, you can use the following
6193 6172 code fragments in your programs which are ready for cut and paste:
6194 6173 \layout Standard
6195 6174
6196 6175
6197 6176 \begin_inset ERT
6198 6177 status Open
6199 6178
6200 6179 \layout Standard
6201 6180
6202 6181 \backslash
6203 6182 codelist{examples/example-embed-short.py}
6204 6183 \end_inset
6205 6184
6206 6185
6207 6186 \layout Section
6208 6187
6209 6188
6210 6189 \begin_inset LatexCommand \label{sec:using-pdb}
6211 6190
6212 6191 \end_inset
6213 6192
6214 6193 Using the Python debugger (
6215 6194 \family typewriter
6216 6195 pdb
6217 6196 \family default
6218 6197 )
6219 6198 \layout Subsection
6220 6199
6221 6200 Running entire programs via
6222 6201 \family typewriter
6223 6202 pdb
6224 6203 \layout Standard
6225 6204
6226 6205
6227 6206 \family typewriter
6228 6207 pdb
6229 6208 \family default
6230 6209 , the Python debugger, is a powerful interactive debugger which allows you
6231 6210 to step through code, set breakpoints, watch variables, etc.
6232 6211 IPython makes it very easy to start any script under the control of
6233 6212 \family typewriter
6234 6213 pdb
6235 6214 \family default
6236 6215 , regardless of whether you have wrapped it into a
6237 6216 \family typewriter
6238 6217 `main()'
6239 6218 \family default
6240 6219 function or not.
6241 6220 For this, simply type
6242 6221 \family typewriter
6243 6222 `%run -d myscript'
6244 6223 \family default
6245 6224 at an IPython prompt.
6246 6225 See the
6247 6226 \family typewriter
6248 6227 %run
6249 6228 \family default
6250 6229 command's documentation (via
6251 6230 \family typewriter
6252 6231 `%run?'
6253 6232 \family default
6254 6233 or in Sec.\SpecialChar ~
6255 6234
6256 6235 \begin_inset LatexCommand \ref{sec:magic}
6257 6236
6258 6237 \end_inset
6259 6238
6260 6239 ) for more details, including how to control where
6261 6240 \family typewriter
6262 6241 pdb
6263 6242 \family default
6264 6243 will stop execution first.
6265 6244 \layout Standard
6266 6245
6267 6246 For more information on the use of the
6268 6247 \family typewriter
6269 6248 pdb
6270 6249 \family default
6271 6250 debugger, read the included
6272 6251 \family typewriter
6273 6252 pdb.doc
6274 6253 \family default
6275 6254 file (part of the standard Python distribution).
6276 6255 On a stock Linux system it is located at
6277 6256 \family typewriter
6278 6257 /usr/lib/python2.3/pdb.doc
6279 6258 \family default
6280 6259 , but the easiest way to read it is by using the
6281 6260 \family typewriter
6282 6261 help()
6283 6262 \family default
6284 6263 function of the
6285 6264 \family typewriter
6286 6265 pdb
6287 6266 \family default
6288 6267 module as follows (in an IPython prompt):
6289 6268 \layout Standard
6290 6269
6291 6270
6292 6271 \family typewriter
6293 6272 In [1]: import pdb
6294 6273 \newline
6295 6274 In [2]: pdb.help()
6296 6275 \layout Standard
6297 6276
6298 6277 This will load the
6299 6278 \family typewriter
6300 6279 pdb.doc
6301 6280 \family default
6302 6281 document in a file viewer for you automatically.
6303 6282 \layout Subsection
6304 6283
6305 6284 Automatic invocation of
6306 6285 \family typewriter
6307 6286 pdb
6308 6287 \family default
6309 6288 on exceptions
6310 6289 \layout Standard
6311 6290
6312 6291 IPython, if started with the
6313 6292 \family typewriter
6314 6293 -pdb
6315 6294 \family default
6316 6295 option (or if the option is set in your rc file) can call the Python
6317 6296 \family typewriter
6318 6297 pdb
6319 6298 \family default
6320 6299 debugger every time your code triggers an uncaught exception
6321 6300 \begin_inset Foot
6322 6301 collapsed true
6323 6302
6324 6303 \layout Standard
6325 6304
6326 6305 Many thanks to Christopher Hart for the request which prompted adding this
6327 6306 feature to IPython.
6328 6307 \end_inset
6329 6308
6330 6309 .
6331 6310 This feature can also be toggled at any time with the
6332 6311 \family typewriter
6333 6312 %pdb
6334 6313 \family default
6335 6314 magic command.
6336 6315 This can be extremely useful in order to find the origin of subtle bugs,
6337 6316 because
6338 6317 \family typewriter
6339 6318 pdb
6340 6319 \family default
6341 6320 opens up at the point in your code which triggered the exception, and while
6342 6321 your program is at this point `dead', all the data is still available and
6343 6322 you can walk up and down the stack frame and understand the origin of the
6344 6323 problem.
6345 6324 \layout Standard
6346 6325
6347 6326 Furthermore, you can use these debugging facilities both with the embedded
6348 6327 IPython mode and without IPython at all.
6349 6328 For an embedded shell (see sec.
6350 6329
6351 6330 \begin_inset LatexCommand \ref{sec:embed}
6352 6331
6353 6332 \end_inset
6354 6333
6355 6334 ), simply call the constructor with
6356 6335 \family typewriter
6357 6336 `-pdb'
6358 6337 \family default
6359 6338 in the argument string and automatically
6360 6339 \family typewriter
6361 6340 pdb
6362 6341 \family default
6363 6342 will be called if an uncaught exception is triggered by your code.
6364 6343
6365 6344 \layout Standard
6366 6345
6367 6346 For stand-alone use of the feature in your programs which do not use IPython
6368 6347 at all, put the following lines toward the top of your `main' routine:
6369 6348 \layout Standard
6370 6349 \align left
6371 6350
6372 6351 \family typewriter
6373 6352 import sys,IPython.ultraTB
6374 6353 \newline
6375 6354 sys.excepthook = IPython.ultraTB.FormattedTB(mode=`Verbose', color_scheme=`Linux',
6376 6355 call_pdb=1)
6377 6356 \layout Standard
6378 6357
6379 6358 The
6380 6359 \family typewriter
6381 6360 mode
6382 6361 \family default
6383 6362 keyword can be either
6384 6363 \family typewriter
6385 6364 `Verbose'
6386 6365 \family default
6387 6366 or
6388 6367 \family typewriter
6389 6368 `Plain'
6390 6369 \family default
6391 6370 , giving either very detailed or normal tracebacks respectively.
6392 6371 The
6393 6372 \family typewriter
6394 6373 color_scheme
6395 6374 \family default
6396 6375 keyword can be one of
6397 6376 \family typewriter
6398 6377 `NoColor'
6399 6378 \family default
6400 6379 ,
6401 6380 \family typewriter
6402 6381 `Linux'
6403 6382 \family default
6404 6383 (default) or
6405 6384 \family typewriter
6406 6385 `LightBG'
6407 6386 \family default
6408 6387 .
6409 6388 These are the same options which can be set in IPython with
6410 6389 \family typewriter
6411 6390 -colors
6412 6391 \family default
6413 6392 and
6414 6393 \family typewriter
6415 6394 -xmode
6416 6395 \family default
6417 6396 .
6418 6397 \layout Standard
6419 6398
6420 6399 This will give any of your programs detailed, colored tracebacks with automatic
6421 6400 invocation of
6422 6401 \family typewriter
6423 6402 pdb
6424 6403 \family default
6425 6404 .
6426 6405 \layout Section
6427 6406
6428 6407
6429 6408 \begin_inset LatexCommand \label{sec:syntax-extensions}
6430 6409
6431 6410 \end_inset
6432 6411
6433 6412 Extensions for syntax processing
6434 6413 \layout Standard
6435 6414
6436 6415 This isn't for the faint of heart, because the potential for breaking things
6437 6416 is quite high.
6438 6417 But it can be a very powerful and useful feature.
6439 6418 In a nutshell, you can redefine the way IPython processes the user input
6440 6419 line to accept new, special extensions to the syntax without needing to
6441 6420 change any of IPython's own code.
6442 6421 \layout Standard
6443 6422
6444 6423 In the
6445 6424 \family typewriter
6446 6425 IPython/Extensions
6447 6426 \family default
6448 6427 directory you will find some examples supplied, which we will briefly describe
6449 6428 now.
6450 6429 These can be used `as is' (and both provide very useful functionality),
6451 6430 or you can use them as a starting point for writing your own extensions.
6452 6431 \layout Subsection
6453 6432
6454 6433 Pasting of code starting with
6455 6434 \family typewriter
6456 6435 `>>>
6457 6436 \family default
6458 6437 ' or
6459 6438 \family typewriter
6460 6439 `...
6461 6440
6462 6441 \family default
6463 6442 '
6464 6443 \layout Standard
6465 6444
6466 6445 In the python tutorial it is common to find code examples which have been
6467 6446 taken from real python sessions.
6468 6447 The problem with those is that all the lines begin with either
6469 6448 \family typewriter
6470 6449 `>>>
6471 6450 \family default
6472 6451 ' or
6473 6452 \family typewriter
6474 6453 `...
6475 6454
6476 6455 \family default
6477 6456 ', which makes it impossible to paste them all at once.
6478 6457 One must instead do a line by line manual copying, carefully removing the
6479 6458 leading extraneous characters.
6480 6459 \layout Standard
6481 6460
6482 6461 This extension identifies those starting characters and removes them from
6483 6462 the input automatically, so that one can paste multi-line examples directly
6484 6463 into IPython, saving a lot of time.
6485 6464 Please look at the file
6486 6465 \family typewriter
6487 6466 InterpreterPasteInput.py
6488 6467 \family default
6489 6468 in the
6490 6469 \family typewriter
6491 6470 IPython/Extensions
6492 6471 \family default
6493 6472 directory for details on how this is done.
6494 6473 \layout Standard
6495 6474
6496 6475 IPython comes with a special profile enabling this feature, called
6497 6476 \family typewriter
6498 6477 tutorial
6499 6478 \family default
6500 6479 \emph on
6501 6480 .
6502 6481
6503 6482 \emph default
6504 6483 Simply start IPython via
6505 6484 \family typewriter
6506 6485 `ipython\SpecialChar ~
6507 6486 -p\SpecialChar ~
6508 6487 tutorial'
6509 6488 \family default
6510 6489 and the feature will be available.
6511 6490 In a normal IPython session you can activate the feature by importing the
6512 6491 corresponding module with:
6513 6492 \newline
6514 6493
6515 6494 \family typewriter
6516 6495 In [1]: import IPython.Extensions.InterpreterPasteInput
6517 6496 \layout Standard
6518 6497
6519 6498 The following is a 'screenshot' of how things work when this extension is
6520 6499 on, copying an example from the standard tutorial:
6521 6500 \layout Standard
6522 6501
6523 6502
6524 6503 \family typewriter
6525 6504 IPython profile: tutorial
6526 6505 \newline
6527 6506 \SpecialChar ~
6528 6507
6529 6508 \newline
6530 6509 *** Pasting of code with ">>>" or "..." has been enabled.
6531 6510 \newline
6532 6511 \SpecialChar ~
6533 6512
6534 6513 \newline
6535 6514 In [1]: >>> def fib2(n): # return Fibonacci series up to n
6536 6515 \newline
6537 6516
6538 6517 \begin_inset ERT
6539 6518 status Collapsed
6540 6519
6541 6520 \layout Standard
6542 6521
6543 6522 \backslash
6544 6523 hspace*{0mm}
6545 6524 \end_inset
6546 6525
6547 6526 \SpecialChar ~
6548 6527 \SpecialChar ~
6549 6528 ...: ...\SpecialChar ~
6550 6529 \SpecialChar ~
6551 6530 \SpecialChar ~
6552 6531 \SpecialChar ~
6553 6532 """Return a list containing the Fibonacci series up to n."""
6554 6533 \newline
6555 6534
6556 6535 \begin_inset ERT
6557 6536 status Collapsed
6558 6537
6559 6538 \layout Standard
6560 6539
6561 6540 \backslash
6562 6541 hspace*{0mm}
6563 6542 \end_inset
6564 6543
6565 6544 \SpecialChar ~
6566 6545 \SpecialChar ~
6567 6546 ...: ...\SpecialChar ~
6568 6547 \SpecialChar ~
6569 6548 \SpecialChar ~
6570 6549 \SpecialChar ~
6571 6550 result = []
6572 6551 \newline
6573 6552
6574 6553 \begin_inset ERT
6575 6554 status Collapsed
6576 6555
6577 6556 \layout Standard
6578 6557
6579 6558 \backslash
6580 6559 hspace*{0mm}
6581 6560 \end_inset
6582 6561
6583 6562 \SpecialChar ~
6584 6563 \SpecialChar ~
6585 6564 ...: ...\SpecialChar ~
6586 6565 \SpecialChar ~
6587 6566 \SpecialChar ~
6588 6567 \SpecialChar ~
6589 6568 a, b = 0, 1
6590 6569 \newline
6591 6570
6592 6571 \begin_inset ERT
6593 6572 status Collapsed
6594 6573
6595 6574 \layout Standard
6596 6575
6597 6576 \backslash
6598 6577 hspace*{0mm}
6599 6578 \end_inset
6600 6579
6601 6580 \SpecialChar ~
6602 6581 \SpecialChar ~
6603 6582 ...: ...\SpecialChar ~
6604 6583 \SpecialChar ~
6605 6584 \SpecialChar ~
6606 6585 \SpecialChar ~
6607 6586 while b < n:
6608 6587 \newline
6609 6588
6610 6589 \begin_inset ERT
6611 6590 status Collapsed
6612 6591
6613 6592 \layout Standard
6614 6593
6615 6594 \backslash
6616 6595 hspace*{0mm}
6617 6596 \end_inset
6618 6597
6619 6598 \SpecialChar ~
6620 6599 \SpecialChar ~
6621 6600 ...: ...\SpecialChar ~
6622 6601 \SpecialChar ~
6623 6602 \SpecialChar ~
6624 6603 \SpecialChar ~
6625 6604 \SpecialChar ~
6626 6605 \SpecialChar ~
6627 6606 \SpecialChar ~
6628 6607 \SpecialChar ~
6629 6608 result.append(b)\SpecialChar ~
6630 6609 \SpecialChar ~
6631 6610 \SpecialChar ~
6632 6611 # see below
6633 6612 \newline
6634 6613
6635 6614 \begin_inset ERT
6636 6615 status Collapsed
6637 6616
6638 6617 \layout Standard
6639 6618
6640 6619 \backslash
6641 6620 hspace*{0mm}
6642 6621 \end_inset
6643 6622
6644 6623 \SpecialChar ~
6645 6624 \SpecialChar ~
6646 6625 ...: ...\SpecialChar ~
6647 6626 \SpecialChar ~
6648 6627 \SpecialChar ~
6649 6628 \SpecialChar ~
6650 6629 \SpecialChar ~
6651 6630 \SpecialChar ~
6652 6631 \SpecialChar ~
6653 6632 \SpecialChar ~
6654 6633 a, b = b, a+b
6655 6634 \newline
6656 6635
6657 6636 \begin_inset ERT
6658 6637 status Collapsed
6659 6638
6660 6639 \layout Standard
6661 6640
6662 6641 \backslash
6663 6642 hspace*{0mm}
6664 6643 \end_inset
6665 6644
6666 6645 \SpecialChar ~
6667 6646 \SpecialChar ~
6668 6647 ...: ...\SpecialChar ~
6669 6648 \SpecialChar ~
6670 6649 \SpecialChar ~
6671 6650 \SpecialChar ~
6672 6651 return result
6673 6652 \newline
6674 6653
6675 6654 \begin_inset ERT
6676 6655 status Collapsed
6677 6656
6678 6657 \layout Standard
6679 6658
6680 6659 \backslash
6681 6660 hspace*{0mm}
6682 6661 \end_inset
6683 6662
6684 6663 \SpecialChar ~
6685 6664 \SpecialChar ~
6686 6665 ...:
6687 6666 \newline
6688 6667 \SpecialChar ~
6689 6668
6690 6669 \newline
6691 6670 In [2]: fib2(10)
6692 6671 \newline
6693 6672 Out[2]: [1, 1, 2, 3, 5, 8]
6694 6673 \layout Standard
6695 6674
6696 6675 Note that as currently written, this extension does
6697 6676 \emph on
6698 6677 not
6699 6678 \emph default
6700 6679 recognize IPython's prompts for pasting.
6701 6680 Those are more complicated, since the user can change them very easily,
6702 6681 they involve numbers and can vary in length.
6703 6682 One could however extract all the relevant information from the IPython
6704 6683 instance and build an appropriate regular expression.
6705 6684 This is left as an exercise for the reader.
6706 6685 \layout Subsection
6707 6686
6708 6687 Input of physical quantities with units
6709 6688 \layout Standard
6710 6689
6711 6690 The module
6712 6691 \family typewriter
6713 6692 PhysicalQInput
6714 6693 \family default
6715 6694 allows a simplified form of input for physical quantities with units.
6716 6695 This file is meant to be used in conjunction with the
6717 6696 \family typewriter
6718 6697 PhysicalQInteractive
6719 6698 \family default
6720 6699 module (in the same directory) and
6721 6700 \family typewriter
6722 6701 Physics.PhysicalQuantities
6723 6702 \family default
6724 6703 from Konrad Hinsen's ScientificPython (
6725 6704 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/hinsen/scientific.html}
6726 6705
6727 6706 \end_inset
6728 6707
6729 6708 ).
6730 6709 \layout Standard
6731 6710
6732 6711 The
6733 6712 \family typewriter
6734 6713 Physics.PhysicalQuantities
6735 6714 \family default
6736 6715 module defines
6737 6716 \family typewriter
6738 6717 PhysicalQuantity
6739 6718 \family default
6740 6719 objects, but these must be declared as instances of a class.
6741 6720 For example, to define
6742 6721 \family typewriter
6743 6722 v
6744 6723 \family default
6745 6724 as a velocity of 3\SpecialChar ~
6746 6725 m/s, normally you would write:
6747 6726 \family typewriter
6748 6727
6749 6728 \newline
6750 6729 In [1]: v = PhysicalQuantity(3,'m/s')
6751 6730 \layout Standard
6752 6731
6753 6732 Using the
6754 6733 \family typewriter
6755 6734 PhysicalQ_Input
6756 6735 \family default
6757 6736 extension this can be input instead as:
6758 6737 \family typewriter
6759 6738
6760 6739 \newline
6761 6740 In [1]: v = 3 m/s
6762 6741 \family default
6763 6742
6764 6743 \newline
6765 6744 which is much more convenient for interactive use (even though it is blatantly
6766 6745 invalid Python syntax).
6767 6746 \layout Standard
6768 6747
6769 6748 The
6770 6749 \family typewriter
6771 6750 physics
6772 6751 \family default
6773 6752 profile supplied with IPython (enabled via
6774 6753 \family typewriter
6775 6754 'ipython -p physics'
6776 6755 \family default
6777 6756 ) uses these extensions, which you can also activate with:
6778 6757 \layout Standard
6779 6758
6780 6759
6781 6760 \family typewriter
6782 6761 from math import * # math MUST be imported BEFORE PhysicalQInteractive
6783 6762 \newline
6784 6763 from IPython.Extensions.PhysicalQInteractive import *
6785 6764 \newline
6786 6765 import IPython.Extensions.PhysicalQInput
6787 6766 \layout Section
6788 6767
6789 6768 IPython as a system shell
6790 6769 \layout Standard
6791 6770
6792 6771 IPython ships with a special profile called
6793 6772 \family typewriter
6794 6773 pysh
6795 6774 \family default
6796 6775 , which you can activate at the command line as
6797 6776 \family typewriter
6798 6777 `ipython -p pysh'
6799 6778 \family default
6800 6779 .
6801 6780 This loads
6802 6781 \family typewriter
6803 6782 InterpreterExec
6804 6783 \family default
6805 6784 , along with some additional facilities and a prompt customized for filesystem
6806 6785 navigation.
6807 6786 \layout Standard
6808 6787
6809 6788 Note that this does
6810 6789 \emph on
6811 6790 not
6812 6791 \emph default
6813 6792 make IPython a full-fledged system shell.
6814 6793 In particular, it has no job control, so if you type Ctrl-Z (under Unix),
6815 6794 you'll suspend pysh itself, not the process you just started.
6816 6795
6817 6796 \layout Standard
6818 6797
6819 6798 What the shell profile allows you to do is to use the convenient and powerful
6820 6799 syntax of Python to do quick scripting at the command line.
6821 6800 Below we describe some of its features.
6822 6801 \layout Subsection
6823 6802
6824 6803 Aliases
6825 6804 \layout Standard
6826 6805
6827 6806 All of your
6828 6807 \family typewriter
6829 6808 $PATH
6830 6809 \family default
6831 6810 has been loaded as IPython aliases, so you should be able to type any normal
6832 6811 system command and have it executed.
6833 6812 See
6834 6813 \family typewriter
6835 6814 %alias?
6836 6815 \family default
6837 6816 and
6838 6817 \family typewriter
6839 6818 %unalias?
6840 6819 \family default
6841 6820 for details on the alias facilities.
6842 6821 See also
6843 6822 \family typewriter
6844 6823 %rehash?
6845 6824 \family default
6846 6825 and
6847 6826 \family typewriter
6848 6827 %rehashx?
6849 6828 \family default
6850 6829 for details on the mechanism used to load
6851 6830 \family typewriter
6852 6831 $PATH
6853 6832 \family default
6854 6833 .
6855 6834 \layout Subsection
6856 6835
6857 6836 Special syntax
6858 6837 \layout Standard
6859 6838
6860 6839 Any lines which begin with
6861 6840 \family typewriter
6862 6841 `~'
6863 6842 \family default
6864 6843 ,
6865 6844 \family typewriter
6866 6845 `/'
6867 6846 \family default
6868 6847 and
6869 6848 \family typewriter
6870 6849 `.'
6871 6850 \family default
6872 6851 will be executed as shell commands instead of as Python code.
6873 6852 The special escapes below are also recognized.
6874 6853
6875 6854 \family typewriter
6876 6855 !cmd
6877 6856 \family default
6878 6857 is valid in single or multi-line input, all others are only valid in single-lin
6879 6858 e input:
6880 6859 \layout Description
6881 6860
6882 6861
6883 6862 \family typewriter
6884 6863 !cmd
6885 6864 \family default
6886 6865 pass `cmd' directly to the shell
6887 6866 \layout Description
6888 6867
6889 6868
6890 6869 \family typewriter
6891 6870 !!cmd
6892 6871 \family default
6893 6872 execute `cmd' and return output as a list (split on `
6894 6873 \backslash
6895 6874 n')
6896 6875 \layout Description
6897 6876
6898 6877
6899 6878 \family typewriter
6900 6879 $var=cmd
6901 6880 \family default
6902 6881 capture output of cmd into var, as a string
6903 6882 \layout Description
6904 6883
6905 6884
6906 6885 \family typewriter
6907 6886 $$var=cmd
6908 6887 \family default
6909 6888 capture output of cmd into var, as a list (split on `
6910 6889 \backslash
6911 6890 n')
6912 6891 \layout Standard
6913 6892
6914 6893 The
6915 6894 \family typewriter
6916 6895 $
6917 6896 \family default
6918 6897 /
6919 6898 \family typewriter
6920 6899 $$
6921 6900 \family default
6922 6901 syntaxes make Python variables from system output, which you can later
6923 6902 use for further scripting.
6924 6903 The converse is also possible: when executing an alias or calling to the
6925 6904 system via
6926 6905 \family typewriter
6927 6906 !
6928 6907 \family default
6929 6908 /
6930 6909 \family typewriter
6931 6910 !!
6932 6911 \family default
6933 6912 , you can expand any python variable or expression by prepending it with
6934 6913
6935 6914 \family typewriter
6936 6915 $
6937 6916 \family default
6938 6917 .
6939 6918 Full details of the allowed syntax can be found in Python's PEP 215.
6940 6919 \layout Standard
6941 6920
6942 6921 A few brief examples will illustrate these (note that the indentation below
6943 6922 may be incorrectly displayed):
6944 6923 \layout Standard
6945 6924
6946 6925
6947 6926 \family typewriter
6948 6927 fperez[~/test]|3> !ls *s.py
6949 6928 \newline
6950 6929 scopes.py strings.py
6951 6930 \layout Standard
6952 6931
6953 6932 ls is an internal alias, so there's no need to use
6954 6933 \family typewriter
6955 6934 !
6956 6935 \family default
6957 6936 :
6958 6937 \layout Standard
6959 6938
6960 6939
6961 6940 \family typewriter
6962 6941 fperez[~/test]|4> ls *s.py
6963 6942 \newline
6964 6943 scopes.py* strings.py
6965 6944 \layout Standard
6966 6945
6967 6946 !!ls will return the output into a Python variable:
6968 6947 \layout Standard
6969 6948
6970 6949
6971 6950 \family typewriter
6972 6951 fperez[~/test]|5> !!ls *s.py
6973 6952 \newline
6974 6953
6975 6954 \begin_inset ERT
6976 6955 status Collapsed
6977 6956
6978 6957 \layout Standard
6979 6958
6980 6959 \backslash
6981 6960 hspace*{0mm}
6982 6961 \end_inset
6983 6962
6984 6963 \SpecialChar ~
6985 6964 \SpecialChar ~
6986 6965 \SpecialChar ~
6987 6966 \SpecialChar ~
6988 6967 \SpecialChar ~
6989 6968 \SpecialChar ~
6990 6969 \SpecialChar ~
6991 6970 \SpecialChar ~
6992 6971 \SpecialChar ~
6993 6972 \SpecialChar ~
6994 6973 \SpecialChar ~
6995 6974 \SpecialChar ~
6996 6975 \SpecialChar ~
6997 6976 \SpecialChar ~
6998 6977 <5> ['scopes.py', 'strings.py']
6999 6978 \newline
7000 6979 fperez[~/test]|6> print _5
7001 6980 \newline
7002 6981 ['scopes.py', 'strings.py']
7003 6982 \layout Standard
7004 6983
7005 6984
7006 6985 \family typewriter
7007 6986 $
7008 6987 \family default
7009 6988 and
7010 6989 \family typewriter
7011 6990 $$
7012 6991 \family default
7013 6992 allow direct capture to named variables:
7014 6993 \layout Standard
7015 6994
7016 6995
7017 6996 \family typewriter
7018 6997 fperez[~/test]|7> $astr = ls *s.py
7019 6998 \newline
7020 6999 fperez[~/test]|8> astr
7021 7000 \newline
7022 7001
7023 7002 \begin_inset ERT
7024 7003 status Collapsed
7025 7004
7026 7005 \layout Standard
7027 7006
7028 7007 \backslash
7029 7008 hspace*{0mm}
7030 7009 \end_inset
7031 7010
7032 7011 \SpecialChar ~
7033 7012 \SpecialChar ~
7034 7013 \SpecialChar ~
7035 7014 \SpecialChar ~
7036 7015 \SpecialChar ~
7037 7016 \SpecialChar ~
7038 7017 \SpecialChar ~
7039 7018 \SpecialChar ~
7040 7019 \SpecialChar ~
7041 7020 \SpecialChar ~
7042 7021 \SpecialChar ~
7043 7022 \SpecialChar ~
7044 7023 \SpecialChar ~
7045 7024 \SpecialChar ~
7046 7025 <8> 'scopes.py
7047 7026 \backslash
7048 7027 nstrings.py'
7049 7028 \layout Standard
7050 7029
7051 7030
7052 7031 \family typewriter
7053 7032 fperez[~/test]|9> $$alist = ls *s.py
7054 7033 \newline
7055 7034 fperez[~/test]|10> alist
7056 7035 \newline
7057 7036
7058 7037 \begin_inset ERT
7059 7038 status Collapsed
7060 7039
7061 7040 \layout Standard
7062 7041
7063 7042 \backslash
7064 7043 hspace*{0mm}
7065 7044 \end_inset
7066 7045
7067 7046 \SpecialChar ~
7068 7047 \SpecialChar ~
7069 7048 \SpecialChar ~
7070 7049 \SpecialChar ~
7071 7050 \SpecialChar ~
7072 7051 \SpecialChar ~
7073 7052 \SpecialChar ~
7074 7053 \SpecialChar ~
7075 7054 \SpecialChar ~
7076 7055 \SpecialChar ~
7077 7056 \SpecialChar ~
7078 7057 \SpecialChar ~
7079 7058 \SpecialChar ~
7080 7059 \SpecialChar ~
7081 7060 <10> ['scopes.py', 'strings.py']
7082 7061 \layout Standard
7083 7062
7084 7063 alist is now a normal python list you can loop over.
7085 7064 Using
7086 7065 \family typewriter
7087 7066 $
7088 7067 \family default
7089 7068 will expand back the python values when alias calls are made:
7090 7069 \layout Standard
7091 7070
7092 7071
7093 7072 \family typewriter
7094 7073 fperez[~/test]|11> for f in alist:
7095 7074 \newline
7096 7075
7097 7076 \begin_inset ERT
7098 7077 status Collapsed
7099 7078
7100 7079 \layout Standard
7101 7080
7102 7081 \backslash
7103 7082 hspace*{0mm}
7104 7083 \end_inset
7105 7084
7106 7085 \SpecialChar ~
7107 7086 \SpecialChar ~
7108 7087 \SpecialChar ~
7109 7088 \SpecialChar ~
7110 7089 \SpecialChar ~
7111 7090 \SpecialChar ~
7112 7091 \SpecialChar ~
7113 7092 \SpecialChar ~
7114 7093 \SpecialChar ~
7115 7094 \SpecialChar ~
7116 7095 \SpecialChar ~
7117 7096 \SpecialChar ~
7118 7097 \SpecialChar ~
7119 7098 \SpecialChar ~
7120 7099 |..> \SpecialChar ~
7121 7100 \SpecialChar ~
7122 7101 \SpecialChar ~
7123 7102 \SpecialChar ~
7124 7103 print 'file',f,
7125 7104 \newline
7126 7105
7127 7106 \begin_inset ERT
7128 7107 status Collapsed
7129 7108
7130 7109 \layout Standard
7131 7110
7132 7111 \backslash
7133 7112 hspace*{0mm}
7134 7113 \end_inset
7135 7114
7136 7115 \SpecialChar ~
7137 7116 \SpecialChar ~
7138 7117 \SpecialChar ~
7139 7118 \SpecialChar ~
7140 7119 \SpecialChar ~
7141 7120 \SpecialChar ~
7142 7121 \SpecialChar ~
7143 7122 \SpecialChar ~
7144 7123 \SpecialChar ~
7145 7124 \SpecialChar ~
7146 7125 \SpecialChar ~
7147 7126 \SpecialChar ~
7148 7127 \SpecialChar ~
7149 7128 \SpecialChar ~
7150 7129 |..> \SpecialChar ~
7151 7130 \SpecialChar ~
7152 7131 \SpecialChar ~
7153 7132 \SpecialChar ~
7154 7133 wc -l $f
7155 7134 \newline
7156 7135
7157 7136 \begin_inset ERT
7158 7137 status Collapsed
7159 7138
7160 7139 \layout Standard
7161 7140
7162 7141 \backslash
7163 7142 hspace*{0mm}
7164 7143 \end_inset
7165 7144
7166 7145 \SpecialChar ~
7167 7146 \SpecialChar ~
7168 7147 \SpecialChar ~
7169 7148 \SpecialChar ~
7170 7149 \SpecialChar ~
7171 7150 \SpecialChar ~
7172 7151 \SpecialChar ~
7173 7152 \SpecialChar ~
7174 7153 \SpecialChar ~
7175 7154 \SpecialChar ~
7176 7155 \SpecialChar ~
7177 7156 \SpecialChar ~
7178 7157 \SpecialChar ~
7179 7158 \SpecialChar ~
7180 7159 |..>
7181 7160 \newline
7182 7161 file scopes.py 13 scopes.py
7183 7162 \newline
7184 7163 file strings.py 4 strings.py
7185 7164 \layout Standard
7186 7165
7187 7166 Note that you may need to protect your variables with braces if you want
7188 7167 to append strings to their names.
7189 7168 To copy all files in alist to
7190 7169 \family typewriter
7191 7170 .bak
7192 7171 \family default
7193 7172 extensions, you must use:
7194 7173 \layout Standard
7195 7174
7196 7175
7197 7176 \family typewriter
7198 7177 fperez[~/test]|12> for f in alist:
7199 7178 \newline
7200 7179
7201 7180 \begin_inset ERT
7202 7181 status Collapsed
7203 7182
7204 7183 \layout Standard
7205 7184
7206 7185 \backslash
7207 7186 hspace*{0mm}
7208 7187 \end_inset
7209 7188
7210 7189 \SpecialChar ~
7211 7190 \SpecialChar ~
7212 7191 \SpecialChar ~
7213 7192 \SpecialChar ~
7214 7193 \SpecialChar ~
7215 7194 \SpecialChar ~
7216 7195 \SpecialChar ~
7217 7196 \SpecialChar ~
7218 7197 \SpecialChar ~
7219 7198 \SpecialChar ~
7220 7199 \SpecialChar ~
7221 7200 \SpecialChar ~
7222 7201 \SpecialChar ~
7223 7202 \SpecialChar ~
7224 7203 |..> \SpecialChar ~
7225 7204 \SpecialChar ~
7226 7205 \SpecialChar ~
7227 7206 \SpecialChar ~
7228 7207 cp $f ${f}.bak
7229 7208 \layout Standard
7230 7209
7231 7210 If you try using
7232 7211 \family typewriter
7233 7212 $f.bak
7234 7213 \family default
7235 7214 , you'll get an AttributeError exception saying that your string object
7236 7215 doesn't have a
7237 7216 \family typewriter
7238 7217 .bak
7239 7218 \family default
7240 7219 attribute.
7241 7220 This is because the
7242 7221 \family typewriter
7243 7222 $
7244 7223 \family default
7245 7224 expansion mechanism allows you to expand full Python expressions:
7246 7225 \layout Standard
7247 7226
7248 7227
7249 7228 \family typewriter
7250 7229 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
7251 7230 \newline
7252 7231 sys.platform is: linux2
7253 7232 \layout Standard
7254 7233
7255 7234 IPython's input history handling is still active, which allows you to rerun
7256 7235 a single block of multi-line input by simply using exec:
7257 7236 \newline
7258 7237
7259 7238 \family typewriter
7260 7239 fperez[~/test]|14> $$alist = ls *.eps
7261 7240 \newline
7262 7241 fperez[~/test]|15> exec _i11
7263 7242 \newline
7264 7243 file image2.eps 921 image2.eps
7265 7244 \newline
7266 7245 file image.eps 921 image.eps
7267 7246 \layout Standard
7268 7247
7269 7248 While these are new special-case syntaxes, they are designed to allow very
7270 7249 efficient use of the shell with minimal typing.
7271 7250 At an interactive shell prompt, conciseness of expression wins over readability.
7272 7251 \layout Subsection
7273 7252
7274 7253 Useful functions and modules
7275 7254 \layout Standard
7276 7255
7277 7256 The os, sys and shutil modules from the Python standard library are automaticall
7278 7257 y loaded.
7279 7258 Some additional functions, useful for shell usage, are listed below.
7280 7259 You can request more help about them with `
7281 7260 \family typewriter
7282 7261 ?
7283 7262 \family default
7284 7263 '.
7285 7264 \layout Description
7286 7265
7287 7266
7288 7267 \family typewriter
7289 7268 shell
7290 7269 \family default
7291 7270 - execute a command in the underlying system shell
7292 7271 \layout Description
7293 7272
7294 7273
7295 7274 \family typewriter
7296 7275 system
7297 7276 \family default
7298 7277 - like
7299 7278 \family typewriter
7300 7279 shell()
7301 7280 \family default
7302 7281 , but return the exit status of the command
7303 7282 \layout Description
7304 7283
7305 7284
7306 7285 \family typewriter
7307 7286 sout
7308 7287 \family default
7309 7288 - capture the output of a command as a string
7310 7289 \layout Description
7311 7290
7312 7291
7313 7292 \family typewriter
7314 7293 lout
7315 7294 \family default
7316 7295 - capture the output of a command as a list (split on `
7317 7296 \backslash
7318 7297 n')
7319 7298 \layout Description
7320 7299
7321 7300
7322 7301 \family typewriter
7323 7302 getoutputerror
7324 7303 \family default
7325 7304 - capture (output,error) of a shell commandss
7326 7305 \layout Standard
7327 7306
7328 7307
7329 7308 \family typewriter
7330 7309 sout
7331 7310 \family default
7332 7311 /
7333 7312 \family typewriter
7334 7313 lout
7335 7314 \family default
7336 7315 are the functional equivalents of
7337 7316 \family typewriter
7338 7317 $
7339 7318 \family default
7340 7319 /
7341 7320 \family typewriter
7342 7321 $$
7343 7322 \family default
7344 7323 .
7345 7324 They are provided to allow you to capture system output in the middle of
7346 7325 true python code, function definitions, etc (where
7347 7326 \family typewriter
7348 7327 $
7349 7328 \family default
7350 7329 and
7351 7330 \family typewriter
7352 7331 $$
7353 7332 \family default
7354 7333 are invalid).
7355 7334 \layout Subsection
7356 7335
7357 7336 Directory management
7358 7337 \layout Standard
7359 7338
7360 7339 Since each command passed by pysh to the underlying system is executed in
7361 7340 a subshell which exits immediately, you can NOT use !cd to navigate the
7362 7341 filesystem.
7363 7342 \layout Standard
7364 7343
7365 7344 Pysh provides its own builtin
7366 7345 \family typewriter
7367 7346 `%cd
7368 7347 \family default
7369 7348 ' magic command to move in the filesystem (the
7370 7349 \family typewriter
7371 7350 %
7372 7351 \family default
7373 7352 is not required with automagic on).
7374 7353 It also maintains a list of visited directories (use
7375 7354 \family typewriter
7376 7355 %dhist
7377 7356 \family default
7378 7357 to see it) and allows direct switching to any of them.
7379 7358 Type
7380 7359 \family typewriter
7381 7360 `cd?
7382 7361 \family default
7383 7362 ' for more details.
7384 7363 \layout Standard
7385 7364
7386 7365
7387 7366 \family typewriter
7388 7367 %pushd
7389 7368 \family default
7390 7369 ,
7391 7370 \family typewriter
7392 7371 %popd
7393 7372 \family default
7394 7373 and
7395 7374 \family typewriter
7396 7375 %dirs
7397 7376 \family default
7398 7377 are provided for directory stack handling.
7399 7378 \layout Subsection
7400 7379
7401 7380 Prompt customization
7402 7381 \layout Standard
7403 7382
7404 7383 The supplied
7405 7384 \family typewriter
7406 7385 ipythonrc-pysh
7407 7386 \family default
7408 7387 profile comes with an example of a very colored and detailed prompt, mainly
7409 7388 to serve as an illustration.
7410 7389 The valid escape sequences, besides color names, are:
7411 7390 \layout Description
7412 7391
7413 7392
7414 7393 \backslash
7415 7394 # - Prompt number.
7416 7395 \layout Description
7417 7396
7418 7397
7419 7398 \backslash
7420 7399 D - Dots, as many as there are digits in
7421 7400 \backslash
7422 7401 # (so they align).
7423 7402 \layout Description
7424 7403
7425 7404
7426 7405 \backslash
7427 7406 w - Current working directory (cwd).
7428 7407 \layout Description
7429 7408
7430 7409
7431 7410 \backslash
7432 7411 W - Basename of current working directory.
7433 7412 \layout Description
7434 7413
7435 7414
7436 7415 \backslash
7437 7416 X
7438 7417 \emph on
7439 7418 N
7440 7419 \emph default
7441 7420 - Where
7442 7421 \emph on
7443 7422 N
7444 7423 \emph default
7445 7424 =0..5.
7446 7425 N terms of the cwd, with $HOME written as ~.
7447 7426 \layout Description
7448 7427
7449 7428
7450 7429 \backslash
7451 7430 Y
7452 7431 \emph on
7453 7432 N
7454 7433 \emph default
7455 7434 - Where
7456 7435 \emph on
7457 7436 N
7458 7437 \emph default
7459 7438 =0..5.
7460 7439 Like X
7461 7440 \emph on
7462 7441 N
7463 7442 \emph default
7464 7443 , but if ~ is term
7465 7444 \emph on
7466 7445 N
7467 7446 \emph default
7468 7447 +1 it's also shown.
7469 7448 \layout Description
7470 7449
7471 7450
7472 7451 \backslash
7473 7452 u - Username.
7474 7453 \layout Description
7475 7454
7476 7455
7477 7456 \backslash
7478 7457 H - Full hostname.
7479 7458 \layout Description
7480 7459
7481 7460
7482 7461 \backslash
7483 7462 h - Hostname up to first '.'
7484 7463 \layout Description
7485 7464
7486 7465
7487 7466 \backslash
7488 7467 $ - Root symbol ($ or #).
7489 7468
7490 7469 \layout Description
7491 7470
7492 7471
7493 7472 \backslash
7494 7473 t - Current time, in H:M:S format.
7495 7474 \layout Description
7496 7475
7497 7476
7498 7477 \backslash
7499 7478 v - IPython release version.
7500 7479
7501 7480 \layout Description
7502 7481
7503 7482
7504 7483 \backslash
7505 7484 n - Newline.
7506 7485
7507 7486 \layout Description
7508 7487
7509 7488
7510 7489 \backslash
7511 7490 r - Carriage return.
7512 7491
7513 7492 \layout Description
7514 7493
7515 7494
7516 7495 \backslash
7517 7496
7518 7497 \backslash
7519 7498 - An explicitly escaped '
7520 7499 \backslash
7521 7500 '.
7522 7501 \layout Standard
7523 7502
7524 7503 You can configure your prompt colors using any ANSI color escape.
7525 7504 Each color escape sets the color for any subsequent text, until another
7526 7505 escape comes in and changes things.
7527 7506 The valid color escapes are:
7528 7507 \layout Description
7529 7508
7530 7509
7531 7510 \backslash
7532 7511 C_Black
7533 7512 \layout Description
7534 7513
7535 7514
7536 7515 \backslash
7537 7516 C_Blue
7538 7517 \layout Description
7539 7518
7540 7519
7541 7520 \backslash
7542 7521 C_Brown
7543 7522 \layout Description
7544 7523
7545 7524
7546 7525 \backslash
7547 7526 C_Cyan
7548 7527 \layout Description
7549 7528
7550 7529
7551 7530 \backslash
7552 7531 C_DarkGray
7553 7532 \layout Description
7554 7533
7555 7534
7556 7535 \backslash
7557 7536 C_Green
7558 7537 \layout Description
7559 7538
7560 7539
7561 7540 \backslash
7562 7541 C_LightBlue
7563 7542 \layout Description
7564 7543
7565 7544
7566 7545 \backslash
7567 7546 C_LightCyan
7568 7547 \layout Description
7569 7548
7570 7549
7571 7550 \backslash
7572 7551 C_LightGray
7573 7552 \layout Description
7574 7553
7575 7554
7576 7555 \backslash
7577 7556 C_LightGreen
7578 7557 \layout Description
7579 7558
7580 7559
7581 7560 \backslash
7582 7561 C_LightPurple
7583 7562 \layout Description
7584 7563
7585 7564
7586 7565 \backslash
7587 7566 C_LightRed
7588 7567 \layout Description
7589 7568
7590 7569
7591 7570 \backslash
7592 7571 C_Purple
7593 7572 \layout Description
7594 7573
7595 7574
7596 7575 \backslash
7597 7576 C_Red
7598 7577 \layout Description
7599 7578
7600 7579
7601 7580 \backslash
7602 7581 C_White
7603 7582 \layout Description
7604 7583
7605 7584
7606 7585 \backslash
7607 7586 C_Yellow
7608 7587 \layout Description
7609 7588
7610 7589
7611 7590 \backslash
7612 7591 C_Normal Stop coloring, defaults to your terminal settings.
7613 7592 \layout Section
7614 7593
7615 7594
7616 7595 \begin_inset LatexCommand \label{sec:Threading-support}
7617 7596
7618 7597 \end_inset
7619 7598
7620 7599 Threading support
7621 7600 \layout Standard
7622 7601
7623 7602
7624 7603 \series bold
7625 7604 WARNING:
7626 7605 \series default
7627 7606 The threading support is still somewhat experimental, and it has only seen
7628 7607 reasonable testing under Linux.
7629 7608 Threaded code is particularly tricky to debug, and it tends to show extremely
7630 7609 platform-dependent behavior.
7631 7610 Since I only have access to Linux machines, I will have to rely on user's
7632 7611 experiences and assistance for this area of IPython to improve under other
7633 7612 platforms.
7634 7613 \layout Standard
7635 7614
7636 7615 IPython, via the
7637 7616 \family typewriter
7638 7617 -gthread
7639 7618 \family default
7640 7619 ,
7641 7620 \family typewriter
7642 7621 -qthread
7643 7622 \family default
7644 7623 and
7645 7624 \family typewriter
7646 7625 -wthread
7647 7626 \family default
7648 7627 options (described in Sec.\SpecialChar ~
7649 7628
7650 7629 \begin_inset LatexCommand \ref{sec:threading-opts}
7651 7630
7652 7631 \end_inset
7653 7632
7654 7633 ), can run in multithreaded mode to support pyGTK, Qt and WXPython applications
7655 7634 respectively.
7656 7635 These GUI toolkits need to control the python main loop of execution, so
7657 7636 under a normal Python interpreter, starting a pyGTK, Qt or WXPython application
7658 7637 will immediately freeze the shell.
7659 7638
7660 7639 \layout Standard
7661 7640
7662 7641 IPython, with one of these options (you can only use one at a time), separates
7663 7642 the graphical loop and IPython's code execution run into different threads.
7664 7643 This allows you to test interactively (with
7665 7644 \family typewriter
7666 7645 %run
7667 7646 \family default
7668 7647 , for example) your GUI code without blocking.
7669 7648 \layout Standard
7670 7649
7671 7650 A nice mini-tutorial on using IPython along with the Qt Designer application
7672 7651 is available at the SciPy wiki:
7673 7652 \begin_inset LatexCommand \htmlurl{http://www.scipy.org/wikis/topical_software/QtWithIPythonAndDesigner}
7674 7653
7675 7654 \end_inset
7676 7655
7677 7656 .
7678 7657 \layout Subsection
7679 7658
7680 7659 Tk issues
7681 7660 \layout Standard
7682 7661
7683 7662 As indicated in Sec.\SpecialChar ~
7684 7663
7685 7664 \begin_inset LatexCommand \ref{sec:threading-opts}
7686 7665
7687 7666 \end_inset
7688 7667
7689 7668 , a special
7690 7669 \family typewriter
7691 7670 -tk
7692 7671 \family default
7693 7672 option is provided to try and allow Tk graphical applications to coexist
7694 7673 interactively with WX, Qt or GTK ones.
7695 7674 Whether this works at all, however, is very platform and configuration
7696 7675 dependent.
7697 7676 Please experiment with simple test cases before committing to using this
7698 7677 combination of Tk and GTK/Qt/WX threading in a production environment.
7699 7678 \layout Subsection
7700 7679
7701 7680 Signals and Threads
7702 7681 \layout Standard
7703 7682
7704 7683 When any of the thread systems (GTK, Qt or WX) are active, either directly
7705 7684 or via
7706 7685 \family typewriter
7707 7686 -pylab
7708 7687 \family default
7709 7688 with a threaded backend, it is impossible to interrupt long-running Python
7710 7689 code via
7711 7690 \family typewriter
7712 7691 Ctrl-C
7713 7692 \family default
7714 7693 .
7715 7694 IPython can not pass the KeyboardInterrupt exception (or the underlying
7716 7695
7717 7696 \family typewriter
7718 7697 SIGINT
7719 7698 \family default
7720 7699 ) across threads, so any long-running process started from IPython will
7721 7700 run to completion, or will have to be killed via an external (OS-based)
7722 7701 mechanism.
7723 7702 \layout Standard
7724 7703
7725 7704 To the best of my knowledge, this limitation is imposed by the Python interprete
7726 7705 r itself, and it comes from the difficulty of writing portable signal/threaded
7727 7706 code.
7728 7707 If any user is an expert on this topic and can suggest a better solution,
7729 7708 I would love to hear about it.
7730 7709 In the IPython sources, look at the
7731 7710 \family typewriter
7732 7711 Shell.py
7733 7712 \family default
7734 7713 module, and in particular at the
7735 7714 \family typewriter
7736 7715 runcode()
7737 7716 \family default
7738 7717 method.
7739 7718
7740 7719 \layout Subsection
7741 7720
7742 7721 I/O pitfalls
7743 7722 \layout Standard
7744 7723
7745 7724 Be mindful that the Python interpreter switches between threads every
7746 7725 \begin_inset Formula $N$
7747 7726 \end_inset
7748 7727
7749 7728 bytecodes, where the default value as of Python\SpecialChar ~
7750 7729 2.3 is
7751 7730 \begin_inset Formula $N=100.$
7752 7731 \end_inset
7753 7732
7754 7733 This value can be read by using the
7755 7734 \family typewriter
7756 7735 sys.getcheckinterval()
7757 7736 \family default
7758 7737 function, and it can be reset via
7759 7738 \family typewriter
7760 7739 sys.setcheckinterval(
7761 7740 \emph on
7762 7741 N
7763 7742 \emph default
7764 7743 )
7765 7744 \family default
7766 7745 .
7767 7746 This switching of threads can cause subtly confusing effects if one of
7768 7747 your threads is doing file I/O.
7769 7748 In text mode, most systems only flush file buffers when they encounter
7770 7749 a
7771 7750 \family typewriter
7772 7751 `
7773 7752 \backslash
7774 7753 n'
7775 7754 \family default
7776 7755 .
7777 7756 An instruction as simple as
7778 7757 \family typewriter
7779 7758
7780 7759 \newline
7781 7760 \SpecialChar ~
7782 7761 \SpecialChar ~
7783 7762 print >> filehandle,
7784 7763 \begin_inset Quotes eld
7785 7764 \end_inset
7786 7765
7787 7766 hello world
7788 7767 \begin_inset Quotes erd
7789 7768 \end_inset
7790 7769
7791 7770
7792 7771 \family default
7793 7772
7794 7773 \newline
7795 7774 actually consists of several bytecodes, so it is possible that the newline
7796 7775 does not reach your file before the next thread switch.
7797 7776 Similarly, if you are writing to a file in binary mode, the file won't
7798 7777 be flushed until the buffer fills, and your other thread may see apparently
7799 7778 truncated files.
7800 7779
7801 7780 \layout Standard
7802 7781
7803 7782 For this reason, if you are using IPython's thread support and have (for
7804 7783 example) a GUI application which will read data generated by files written
7805 7784 to from the IPython thread, the safest approach is to open all of your
7806 7785 files in unbuffered mode (the third argument to the
7807 7786 \family typewriter
7808 7787 file/open
7809 7788 \family default
7810 7789 function is the buffering value):
7811 7790 \newline
7812 7791
7813 7792 \family typewriter
7814 7793 \SpecialChar ~
7815 7794 \SpecialChar ~
7816 7795 filehandle = open(filename,mode,0)
7817 7796 \layout Standard
7818 7797
7819 7798 This is obviously a brute force way of avoiding race conditions with the
7820 7799 file buffering.
7821 7800 If you want to do it cleanly, and you have a resource which is being shared
7822 7801 by the interactive IPython loop and your GUI thread, you should really
7823 7802 handle it with thread locking and syncrhonization properties.
7824 7803 The Python documentation discusses these.
7825 7804 \layout Section
7826 7805
7827 7806
7828 7807 \begin_inset LatexCommand \label{sec:interactive-demos}
7829 7808
7830 7809 \end_inset
7831 7810
7832 7811 Interactive demos with IPython
7833 7812 \layout Standard
7834 7813
7835 7814 IPython ships with a basic system for running scripts interactively in sections,
7836 7815 useful when presenting code to audiences.
7837 7816 A few tags embedded in comments (so that the script remains valid Python
7838 7817 code) divide a file into separate blocks, and the demo can be run one block
7839 7818 at a time, with IPython printing (with syntax highlighting) the block before
7840 7819 executing it, and returning to the interactive prompt after each block.
7841 7820 The interactive namespace is updated after each block is run with the contents
7842 7821 of the demo's namespace.
7843 7822 \layout Standard
7844 7823
7845 7824 This allows you to show a piece of code, run it and then execute interactively
7846 7825 commands based on the variables just created.
7847 7826 Once you want to continue, you simply execute the next block of the demo.
7848 7827 The following listing shows the markup necessary for dividing a script
7849 7828 into sections for execution as a demo.
7850 7829 \layout Standard
7851 7830
7852 7831
7853 7832 \begin_inset ERT
7854 7833 status Open
7855 7834
7856 7835 \layout Standard
7857 7836
7858 7837 \backslash
7859 7838 codelist{examples/example-demo.py}
7860 7839 \end_inset
7861 7840
7862 7841
7863 7842 \layout Standard
7864 7843
7865 7844 In order to run a file as a demo, you must first make a
7866 7845 \family typewriter
7867 7846 Demo
7868 7847 \family default
7869 7848 object out of it.
7870 7849 If the file is named
7871 7850 \family typewriter
7872 7851 myscript.py
7873 7852 \family default
7874 7853 , the following code will make a demo:
7875 7854 \layout LyX-Code
7876 7855
7877 7856 from IPython.demo import Demo
7878 7857 \layout LyX-Code
7879 7858
7880 7859 mydemo = Demo('myscript.py')
7881 7860 \layout Standard
7882 7861
7883 7862 This creates the
7884 7863 \family typewriter
7885 7864 mydemo
7886 7865 \family default
7887 7866 object, whose blocks you run one at a time by simply calling the object
7888 7867 with no arguments.
7889 7868 If you have autocall active in IPython (the default), all you need to do
7890 7869 is type
7891 7870 \layout LyX-Code
7892 7871
7893 7872 mydemo
7894 7873 \layout Standard
7895 7874
7896 7875 and IPython will call it, executing each block.
7897 7876 Demo objects can be restarted, you can move forward or back skipping blocks,
7898 7877 re-execute the last block, etc.
7899 7878 Simply use the Tab key on a demo object to see its methods, and call
7900 7879 \family typewriter
7901 7880 `?'
7902 7881 \family default
7903 7882 on them to see their docstrings for more usage details.
7904 7883 In addition, the
7905 7884 \family typewriter
7906 7885 demo
7907 7886 \family default
7908 7887 module itself contains a comprehensive docstring, which you can access
7909 7888 via
7910 7889 \layout LyX-Code
7911 7890
7912 7891 from IPython import demo
7913 7892 \layout LyX-Code
7914 7893
7915 7894 demo?
7916 7895 \layout Standard
7917 7896
7918 7897
7919 7898 \series bold
7920 7899 Limitations:
7921 7900 \series default
7922 7901 It is important to note that these demos are limited to fairly simple uses.
7923 7902 In particular, you can
7924 7903 \emph on
7925 7904 not
7926 7905 \emph default
7927 7906 put division marks in indented code (loops, if statements, function definitions
7928 7907 , etc.) Supporting something like this would basically require tracking the
7929 7908 internal execution state of the Python interpreter, so only top-level divisions
7930 7909 are allowed.
7931 7910 If you want to be able to open an IPython instance at an arbitrary point
7932 7911 in a program, you can use IPython's embedding facilities, described in
7933 7912 detail in Sec\SpecialChar \@.
7934 7913 \SpecialChar ~
7935 7914
7936 7915 \begin_inset LatexCommand \ref{sec:embed}
7937 7916
7938 7917 \end_inset
7939 7918
7940 7919 .
7941 7920 \layout Section
7942 7921
7943 7922
7944 7923 \begin_inset LatexCommand \label{sec:matplotlib-support}
7945 7924
7946 7925 \end_inset
7947 7926
7948 7927 Plotting with
7949 7928 \family typewriter
7950 7929 matplotlib
7951 7930 \family default
7952 7931
7953 7932 \layout Standard
7954 7933
7955 7934 The matplotlib library (
7956 7935 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
7957 7936
7958 7937 \end_inset
7959 7938
7960 7939 ) provides high quality 2D plotting for Python.
7961 7940 Matplotlib can produce plots on screen using a variety of GUI toolkits,
7962 7941 including Tk, GTK and WXPython.
7963 7942 It also provides a number of commands useful for scientific computing,
7964 7943 all with a syntax compatible with that of the popular Matlab program.
7965 7944 \layout Standard
7966 7945
7967 7946 IPython accepts the special option
7968 7947 \family typewriter
7969 7948 -pylab
7970 7949 \family default
7971 7950 (Sec.\SpecialChar ~
7972 7951
7973 7952 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
7974 7953
7975 7954 \end_inset
7976 7955
7977 7956 ).
7978 7957 This configures it to support matplotlib, honoring the settings in the
7979 7958
7980 7959 \family typewriter
7981 7960 .matplotlibrc
7982 7961 \family default
7983 7962 file.
7984 7963 IPython will detect the user's choice of matplotlib GUI backend, and automatica
7985 7964 lly select the proper threading model to prevent blocking.
7986 7965 It also sets matplotlib in interactive mode and modifies
7987 7966 \family typewriter
7988 7967 %run
7989 7968 \family default
7990 7969 slightly, so that any matplotlib-based script can be executed using
7991 7970 \family typewriter
7992 7971 %run
7993 7972 \family default
7994 7973 and the final
7995 7974 \family typewriter
7996 7975 show()
7997 7976 \family default
7998 7977 command does not block the interactive shell.
7999 7978 \layout Standard
8000 7979
8001 7980 The
8002 7981 \family typewriter
8003 7982 -pylab
8004 7983 \family default
8005 7984 option must be given first in order for IPython to configure its threading
8006 7985 mode.
8007 7986 However, you can still issue other options afterwards.
8008 7987 This allows you to have a matplotlib-based environment customized with
8009 7988 additional modules using the standard IPython profile mechanism (Sec.\SpecialChar ~
8010 7989
8011 7990 \begin_inset LatexCommand \ref{sec:profiles}
8012 7991
8013 7992 \end_inset
8014 7993
8015 7994 ): ``
8016 7995 \family typewriter
8017 7996 ipython -pylab -p myprofile
8018 7997 \family default
8019 7998 '' will load the profile defined in
8020 7999 \family typewriter
8021 8000 ipythonrc-myprofile
8022 8001 \family default
8023 8002 after configuring matplotlib.
8024 8003 \layout Section
8025 8004
8026 8005
8027 8006 \begin_inset LatexCommand \label{sec:Gnuplot}
8028 8007
8029 8008 \end_inset
8030 8009
8031 8010 Plotting with
8032 8011 \family typewriter
8033 8012 Gnuplot
8034 8013 \layout Standard
8035 8014
8036 8015 Through the magic extension system described in sec.
8037 8016
8038 8017 \begin_inset LatexCommand \ref{sec:magic}
8039 8018
8040 8019 \end_inset
8041 8020
8042 8021 , IPython incorporates a mechanism for conveniently interfacing with the
8043 8022 Gnuplot system (
8044 8023 \begin_inset LatexCommand \htmlurl{http://www.gnuplot.info}
8045 8024
8046 8025 \end_inset
8047 8026
8048 8027 ).
8049 8028 Gnuplot is a very complete 2D and 3D plotting package available for many
8050 8029 operating systems and commonly included in modern Linux distributions.
8051 8030
8052 8031 \layout Standard
8053 8032
8054 8033 Besides having Gnuplot installed, this functionality requires the
8055 8034 \family typewriter
8056 8035 Gnuplot.py
8057 8036 \family default
8058 8037 module for interfacing python with Gnuplot.
8059 8038 It can be downloaded from:
8060 8039 \begin_inset LatexCommand \htmlurl{http://gnuplot-py.sourceforge.net}
8061 8040
8062 8041 \end_inset
8063 8042
8064 8043 .
8065 8044 \layout Subsection
8066 8045
8067 8046 Proper Gnuplot configuration
8068 8047 \layout Standard
8069 8048
8070 8049 As of version 4.0, Gnuplot has excellent mouse and interactive keyboard support.
8071 8050 However, as of
8072 8051 \family typewriter
8073 8052 Gnuplot.py
8074 8053 \family default
8075 8054 version 1.7, a new option was added to communicate between Python and Gnuplot
8076 8055 via FIFOs (pipes).
8077 8056 This mechanism, while fast, also breaks the mouse system.
8078 8057 You must therefore set the variable
8079 8058 \family typewriter
8080 8059 prefer_fifo_data
8081 8060 \family default
8082 8061 to
8083 8062 \family typewriter
8084 8063 0
8085 8064 \family default
8086 8065 in file
8087 8066 \family typewriter
8088 8067 gp_unix.py
8089 8068 \family default
8090 8069 if you wish to keep the interactive mouse and keyboard features working
8091 8070 properly (
8092 8071 \family typewriter
8093 8072 prefer_inline_data
8094 8073 \family default
8095 8074 also must be
8096 8075 \family typewriter
8097 8076 0
8098 8077 \family default
8099 8078 , but this is the default so unless you've changed it manually you should
8100 8079 be fine).
8101 8080 \layout Standard
8102 8081
8103 8082 'Out of the box', Gnuplot is configured with a rather poor set of size,
8104 8083 color and linewidth choices which make the graphs fairly hard to read on
8105 8084 modern high-resolution displays (although they work fine on old 640x480
8106 8085 ones).
8107 8086 Below is a section of my
8108 8087 \family typewriter
8109 8088 .Xdefaults
8110 8089 \family default
8111 8090 file which I use for having a more convenient Gnuplot setup.
8112 8091 Remember to load it by running
8113 8092 \family typewriter
8114 8093 `xrdb .Xdefaults`
8115 8094 \family default
8116 8095 :
8117 8096 \layout Standard
8118 8097
8119 8098
8120 8099 \family typewriter
8121 8100 !******************************************************************
8122 8101 \newline
8123 8102 ! gnuplot options
8124 8103 \newline
8125 8104 ! modify this for a convenient window size
8126 8105 \newline
8127 8106 gnuplot*geometry: 780x580
8128 8107 \layout Standard
8129 8108
8130 8109
8131 8110 \family typewriter
8132 8111 ! on-screen font (not for PostScript)
8133 8112 \newline
8134 8113 gnuplot*font: -misc-fixed-bold-r-normal--15-120-100-100-c-90-iso8859-1
8135 8114 \layout Standard
8136 8115
8137 8116
8138 8117 \family typewriter
8139 8118 ! color options
8140 8119 \newline
8141 8120 gnuplot*background: black
8142 8121 \newline
8143 8122 gnuplot*textColor: white
8144 8123 \newline
8145 8124 gnuplot*borderColor: white
8146 8125 \newline
8147 8126 gnuplot*axisColor: white
8148 8127 \newline
8149 8128 gnuplot*line1Color: red
8150 8129 \newline
8151 8130 gnuplot*line2Color: green
8152 8131 \newline
8153 8132 gnuplot*line3Color: blue
8154 8133 \newline
8155 8134 gnuplot*line4Color: magenta
8156 8135 \newline
8157 8136 gnuplot*line5Color: cyan
8158 8137 \newline
8159 8138 gnuplot*line6Color: sienna
8160 8139 \newline
8161 8140 gnuplot*line7Color: orange
8162 8141 \newline
8163 8142 gnuplot*line8Color: coral
8164 8143 \layout Standard
8165 8144
8166 8145
8167 8146 \family typewriter
8168 8147 ! multiplicative factor for point styles
8169 8148 \newline
8170 8149 gnuplot*pointsize: 2
8171 8150 \layout Standard
8172 8151
8173 8152
8174 8153 \family typewriter
8175 8154 ! line width options (in pixels)
8176 8155 \newline
8177 8156 gnuplot*borderWidth: 2
8178 8157 \newline
8179 8158 gnuplot*axisWidth: 2
8180 8159 \newline
8181 8160 gnuplot*line1Width: 2
8182 8161 \newline
8183 8162 gnuplot*line2Width: 2
8184 8163 \newline
8185 8164 gnuplot*line3Width: 2
8186 8165 \newline
8187 8166 gnuplot*line4Width: 2
8188 8167 \newline
8189 8168 gnuplot*line5Width: 2
8190 8169 \newline
8191 8170 gnuplot*line6Width: 2
8192 8171 \newline
8193 8172 gnuplot*line7Width: 2
8194 8173 \newline
8195 8174 gnuplot*line8Width: 2
8196 8175 \layout Subsection
8197 8176
8198 8177 The
8199 8178 \family typewriter
8200 8179 IPython.GnuplotRuntime
8201 8180 \family default
8202 8181 module
8203 8182 \layout Standard
8204 8183
8205 8184 IPython includes a module called
8206 8185 \family typewriter
8207 8186 Gnuplot2.py
8208 8187 \family default
8209 8188 which extends and improves the default
8210 8189 \family typewriter
8211 8190 Gnuplot
8212 8191 \family default
8213 8192 .
8214 8193 \family typewriter
8215 8194 py
8216 8195 \family default
8217 8196 (which it still relies upon).
8218 8197 For example, the new
8219 8198 \family typewriter
8220 8199 plot
8221 8200 \family default
8222 8201 function adds several improvements to the original making it more convenient
8223 8202 for interactive use, and
8224 8203 \family typewriter
8225 8204 hardcopy
8226 8205 \family default
8227 8206 fixes a bug in the original which under some circumstances blocks the creation
8228 8207 of PostScript output.
8229 8208 \layout Standard
8230 8209
8231 8210 For scripting use,
8232 8211 \family typewriter
8233 8212 GnuplotRuntime.py
8234 8213 \family default
8235 8214 is provided, which wraps
8236 8215 \family typewriter
8237 8216 Gnuplot2.py
8238 8217 \family default
8239 8218 and creates a series of global aliases.
8240 8219 These make it easy to control Gnuplot plotting jobs through the Python
8241 8220 language.
8242 8221 \layout Standard
8243 8222
8244 8223 Below is some example code which illustrates how to configure Gnuplot inside
8245 8224 your own programs but have it available for further interactive use through
8246 8225 an embedded IPython instance.
8247 8226 Simply run this file at a system prompt.
8248 8227 This file is provided as
8249 8228 \family typewriter
8250 8229 example-gnuplot.py
8251 8230 \family default
8252 8231 in the examples directory:
8253 8232 \layout Standard
8254 8233
8255 8234
8256 8235 \begin_inset ERT
8257 8236 status Open
8258 8237
8259 8238 \layout Standard
8260 8239
8261 8240 \backslash
8262 8241 codelist{examples/example-gnuplot.py}
8263 8242 \end_inset
8264 8243
8265 8244
8266 8245 \layout Subsection
8267 8246
8268 8247 The
8269 8248 \family typewriter
8270 8249 numeric
8271 8250 \family default
8272 8251 profile: a scientific computing environment
8273 8252 \layout Standard
8274 8253
8275 8254 The
8276 8255 \family typewriter
8277 8256 numeric
8278 8257 \family default
8279 8258 IPython profile, which you can activate with
8280 8259 \family typewriter
8281 8260 `ipython -p numeric
8282 8261 \family default
8283 8262 ' will automatically load the IPython Gnuplot extensions (plus Numeric and
8284 8263 other useful things for numerical computing), contained in the
8285 8264 \family typewriter
8286 8265 IPython.GnuplotInteractive
8287 8266 \family default
8288 8267 module.
8289 8268 This will create the globals
8290 8269 \family typewriter
8291 8270 Gnuplot
8292 8271 \family default
8293 8272 (an alias to the improved Gnuplot2 module),
8294 8273 \family typewriter
8295 8274 gp
8296 8275 \family default
8297 8276 (a Gnuplot active instance), the new magic commands
8298 8277 \family typewriter
8299 8278 %gpc
8300 8279 \family default
8301 8280 and
8302 8281 \family typewriter
8303 8282 %gp_set_instance
8304 8283 \family default
8305 8284 and several other convenient globals.
8306 8285 Type
8307 8286 \family typewriter
8308 8287 gphelp()
8309 8288 \family default
8310 8289 for further details.
8311 8290 \layout Standard
8312 8291
8313 8292 This should turn IPython into a convenient environment for numerical computing,
8314 8293 with all the functions in the NumPy library and the Gnuplot facilities
8315 8294 for plotting.
8316 8295 Further improvements can be obtained by loading the SciPy libraries for
8317 8296 scientific computing, available at
8318 8297 \begin_inset LatexCommand \htmlurl{http://scipy.org}
8319 8298
8320 8299 \end_inset
8321 8300
8322 8301 .
8323 8302 \layout Standard
8324 8303
8325 8304 If you are in the middle of a working session with numerical objects and
8326 8305 need to plot them but you didn't start the
8327 8306 \family typewriter
8328 8307 numeric
8329 8308 \family default
8330 8309 profile, you can load these extensions at any time by typing
8331 8310 \newline
8332 8311
8333 8312 \family typewriter
8334 8313 from IPython.GnuplotInteractive import *
8335 8314 \newline
8336 8315
8337 8316 \family default
8338 8317 at the IPython prompt.
8339 8318 This will allow you to keep your objects intact and start using Gnuplot
8340 8319 to view them.
8341 8320 \layout Section
8342 8321
8343 8322 Reporting bugs
8344 8323 \layout Subsection*
8345 8324
8346 8325 Automatic crash reports
8347 8326 \layout Standard
8348 8327
8349 8328 Ideally, IPython itself shouldn't crash.
8350 8329 It will catch exceptions produced by you, but bugs in its internals will
8351 8330 still crash it.
8352 8331 \layout Standard
8353 8332
8354 8333 In such a situation, IPython will leave a file named
8355 8334 \family typewriter
8356 8335 IPython_crash_report.txt
8357 8336 \family default
8358 8337 in your IPYTHONDIR directory (that way if crashes happen several times
8359 8338 it won't litter many directories, the post-mortem file is always located
8360 8339 in the same place and new occurrences just overwrite the previous one).
8361 8340 If you can mail this file to the developers (see sec.
8362 8341
8363 8342 \begin_inset LatexCommand \ref{sec:credits}
8364 8343
8365 8344 \end_inset
8366 8345
8367 8346 for names and addresses), it will help us
8368 8347 \emph on
8369 8348 a lot
8370 8349 \emph default
8371 8350 in understanding the cause of the problem and fixing it sooner.
8372 8351 \layout Subsection*
8373 8352
8374 8353 The bug tracker
8375 8354 \layout Standard
8376 8355
8377 8356 IPython also has an online bug-tracker, located at
8378 8357 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython}
8379 8358
8380 8359 \end_inset
8381 8360
8382 8361 .
8383 8362 In addition to mailing the developers, it would be a good idea to file
8384 8363 a bug report here.
8385 8364 This will ensure that the issue is properly followed to conclusion.
8386 8365 \layout Standard
8387 8366
8388 8367 You can also use this bug tracker to file feature requests.
8389 8368 \layout Section
8390 8369
8391 8370 Brief history
8392 8371 \layout Subsection
8393 8372
8394 8373 Origins
8395 8374 \layout Standard
8396 8375
8397 8376 The current IPython system grew out of the following three projects:
8398 8377 \layout List
8399 8378 \labelwidthstring 00.00.0000
8400 8379
8401 8380 ipython by Fernando Pérez.
8402 8381 I was working on adding Mathematica-type prompts and a flexible configuration
8403 8382 system (something better than
8404 8383 \family typewriter
8405 8384 $PYTHONSTARTUP
8406 8385 \family default
8407 8386 ) to the standard Python interactive interpreter.
8408 8387 \layout List
8409 8388 \labelwidthstring 00.00.0000
8410 8389
8411 8390 IPP by Janko Hauser.
8412 8391 Very well organized, great usability.
8413 8392 Had an old help system.
8414 8393 IPP was used as the `container' code into which I added the functionality
8415 8394 from ipython and LazyPython.
8416 8395 \layout List
8417 8396 \labelwidthstring 00.00.0000
8418 8397
8419 8398 LazyPython by Nathan Gray.
8420 8399 Simple but
8421 8400 \emph on
8422 8401 very
8423 8402 \emph default
8424 8403 powerful.
8425 8404 The quick syntax (auto parens, auto quotes) and verbose/colored tracebacks
8426 8405 were all taken from here.
8427 8406 \layout Standard
8428 8407
8429 8408 When I found out (see sec.
8430 8409
8431 8410 \begin_inset LatexCommand \ref{figgins}
8432 8411
8433 8412 \end_inset
8434 8413
8435 8414 ) about IPP and LazyPython I tried to join all three into a unified system.
8436 8415 I thought this could provide a very nice working environment, both for
8437 8416 regular programming and scientific computing: shell-like features, IDL/Matlab
8438 8417 numerics, Mathematica-type prompt history and great object introspection
8439 8418 and help facilities.
8440 8419 I think it worked reasonably well, though it was a lot more work than I
8441 8420 had initially planned.
8442 8421 \layout Subsection
8443 8422
8444 8423 Current status
8445 8424 \layout Standard
8446 8425
8447 8426 The above listed features work, and quite well for the most part.
8448 8427 But until a major internal restructuring is done (see below), only bug
8449 8428 fixing will be done, no other features will be added (unless very minor
8450 8429 and well localized in the cleaner parts of the code).
8451 8430 \layout Standard
8452 8431
8453 8432 IPython consists of some 12000 lines of pure python code, of which roughly
8454 8433 50% are fairly clean.
8455 8434 The other 50% are fragile, messy code which needs a massive restructuring
8456 8435 before any further major work is done.
8457 8436 Even the messy code is fairly well documented though, and most of the problems
8458 8437 in the (non-existent) class design are well pointed to by a PyChecker run.
8459 8438 So the rewriting work isn't that bad, it will just be time-consuming.
8460 8439 \layout Subsection
8461 8440
8462 8441 Future
8463 8442 \layout Standard
8464 8443
8465 8444 See the separate
8466 8445 \family typewriter
8467 8446 new_design
8468 8447 \family default
8469 8448 document for details.
8470 8449 Ultimately, I would like to see IPython become part of the standard Python
8471 8450 distribution as a `big brother with batteries' to the standard Python interacti
8472 8451 ve interpreter.
8473 8452 But that will never happen with the current state of the code, so all contribut
8474 8453 ions are welcome.
8475 8454 \layout Section
8476 8455
8477 8456 License
8478 8457 \layout Standard
8479 8458
8480 8459 IPython is released under the terms of the BSD license, whose general form
8481 8460 can be found at:
8482 8461 \begin_inset LatexCommand \htmlurl{http://www.opensource.org/licenses/bsd-license.php}
8483 8462
8484 8463 \end_inset
8485 8464
8486 8465 .
8487 8466 The full text of the IPython license is reproduced below:
8488 8467 \layout Quote
8489 8468
8490 8469
8491 8470 \family typewriter
8492 8471 \size small
8493 8472 IPython is released under a BSD-type license.
8494 8473 \layout Quote
8495 8474
8496 8475
8497 8476 \family typewriter
8498 8477 \size small
8499 8478 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez <fperez@colorado.edu>.
8500 8479 \layout Quote
8501 8480
8502 8481
8503 8482 \family typewriter
8504 8483 \size small
8505 8484 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
8506 8485 \newline
8507 8486 Nathaniel Gray <n8gray@caltech.edu>.
8508 8487 \layout Quote
8509 8488
8510 8489
8511 8490 \family typewriter
8512 8491 \size small
8513 8492 All rights reserved.
8514 8493 \layout Quote
8515 8494
8516 8495
8517 8496 \family typewriter
8518 8497 \size small
8519 8498 Redistribution and use in source and binary forms, with or without modification,
8520 8499 are permitted provided that the following conditions are met:
8521 8500 \layout Quote
8522 8501
8523 8502
8524 8503 \family typewriter
8525 8504 \size small
8526 8505 a.
8527 8506 Redistributions of source code must retain the above copyright notice,
8528 8507 this list of conditions and the following disclaimer.
8529 8508 \layout Quote
8530 8509
8531 8510
8532 8511 \family typewriter
8533 8512 \size small
8534 8513 b.
8535 8514 Redistributions in binary form must reproduce the above copyright notice,
8536 8515 this list of conditions and the following disclaimer in the documentation
8537 8516 and/or other materials provided with the distribution.
8538 8517 \layout Quote
8539 8518
8540 8519
8541 8520 \family typewriter
8542 8521 \size small
8543 8522 c.
8544 8523 Neither the name of the copyright holders nor the names of any contributors
8545 8524 to this software may be used to endorse or promote products derived from
8546 8525 this software without specific prior written permission.
8547 8526 \layout Quote
8548 8527
8549 8528
8550 8529 \family typewriter
8551 8530 \size small
8552 8531 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8553 8532 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8554 8533 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8555 8534 PURPOSE ARE DISCLAIMED.
8556 8535 IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8557 8536 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
8558 8537 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8559 8538 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
8560 8539 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8561 8540 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8562 8541 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8563 8542
8564 8543 \layout Standard
8565 8544
8566 8545 Individual authors are the holders of the copyright for their code and are
8567 8546 listed in each file.
8568 8547 \layout Standard
8569 8548
8570 8549 Some files (
8571 8550 \family typewriter
8572 8551 DPyGetOpt.py
8573 8552 \family default
8574 8553 , for example) may be licensed under different conditions.
8575 8554 Ultimately each file indicates clearly the conditions under which its author/au
8576 8555 thors have decided to publish the code.
8577 8556 \layout Standard
8578 8557
8579 8558 Versions of IPython up to and including 0.6.3 were released under the GNU
8580 8559 Lesser General Public License (LGPL), available at
8581 8560 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/copyleft/lesser.html}
8582 8561
8583 8562 \end_inset
8584 8563
8585 8564 .
8586 8565 \layout Section
8587 8566
8588 8567
8589 8568 \begin_inset LatexCommand \label{sec:credits}
8590 8569
8591 8570 \end_inset
8592 8571
8593 8572 Credits
8594 8573 \layout Standard
8595 8574
8596 8575 IPython is mainly developed by Fernando Pérez
8597 8576 \family typewriter
8598 8577 <fperez@colorado.edu>
8599 8578 \family default
8600 8579 , but the project was born from mixing in Fernando's code with the IPP project
8601 8580 by Janko Hauser
8602 8581 \family typewriter
8603 8582 <jhauser-AT-zscout.de>
8604 8583 \family default
8605 8584 and LazyPython by Nathan Gray
8606 8585 \family typewriter
8607 8586 <n8gray-AT-caltech.edu>
8608 8587 \family default
8609 8588 .
8610 8589 For all IPython-related requests, please contact Fernando.
8611 8590
8612 8591 \layout Standard
8613 8592
8614 8593 As of late 2005, the following developers have joined the core team:
8615 8594 \layout List
8616 8595 \labelwidthstring 00.00.0000
8617 8596
8618 8597 Robert\SpecialChar ~
8619 8598 Kern
8620 8599 \family typewriter
8621 8600 <rkern-AT-enthought.com>
8622 8601 \family default
8623 8602 : co-mentored the 2005 Google Summer of Code project to develop python interacti
8624 8603 ve notebooks (XML documents) and graphical interface.
8625 8604 This project was awarded to the students Tzanko Matev
8626 8605 \family typewriter
8627 8606 <tsanko-AT-gmail.com>
8628 8607 \family default
8629 8608 and Toni Alatalo
8630 8609 \family typewriter
8631 8610 <antont-AT-an.org>
8632 8611 \layout List
8633 8612 \labelwidthstring 00.00.0000
8634 8613
8635 8614 Brian\SpecialChar ~
8636 8615 Granger
8637 8616 \family typewriter
8638 8617 <bgranger-AT-scu.edu>
8639 8618 \family default
8640 8619 : extending IPython to allow support for interactive parallel computing.
8641 8620 \layout Standard
8642 8621
8643 8622 User or development help should be requested via the IPython mailing lists:
8644 8623 \layout Description
8645 8624
8646 8625 User\SpecialChar ~
8647 8626 list:
8648 8627 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-user}
8649 8628
8650 8629 \end_inset
8651 8630
8652 8631
8653 8632 \layout Description
8654 8633
8655 8634 Developer's\SpecialChar ~
8656 8635 list:
8657 8636 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-dev}
8658 8637
8659 8638 \end_inset
8660 8639
8661 8640
8662 8641 \layout Standard
8663 8642
8664 8643 The IPython project is also very grateful to
8665 8644 \begin_inset Foot
8666 8645 collapsed true
8667 8646
8668 8647 \layout Standard
8669 8648
8670 8649 I've mangled email addresses to reduce spam, since the IPython manuals can
8671 8650 be accessed online.
8672 8651 \end_inset
8673 8652
8674 8653 :
8675 8654 \layout Standard
8676 8655
8677 8656 Bill Bumgarner
8678 8657 \family typewriter
8679 8658 <bbum-AT-friday.com>
8680 8659 \family default
8681 8660 : for providing the DPyGetOpt module which gives very powerful and convenient
8682 8661 handling of command-line options (light years ahead of what Python 2.1.1's
8683 8662 getopt module does).
8684 8663 \layout Standard
8685 8664
8686 8665 Ka-Ping Yee
8687 8666 \family typewriter
8688 8667 <ping-AT-lfw.org>
8689 8668 \family default
8690 8669 : for providing the Itpl module for convenient and powerful string interpolation
8691 8670 with a much nicer syntax than formatting through the '%' operator.
8692 8671 \layout Standard
8693 8672
8694 8673 Arnd Bäcker
8695 8674 \family typewriter
8696 8675 <baecker-AT-physik.tu-dresden.de>
8697 8676 \family default
8698 8677 : for his many very useful suggestions and comments, and lots of help with
8699 8678 testing and documentation checking.
8700 8679 Many of IPython's newer features are a result of discussions with him (bugs
8701 8680 are still my fault, not his).
8702 8681 \layout Standard
8703 8682
8704 8683 Obviously Guido van\SpecialChar ~
8705 8684 Rossum and the whole Python development team, that goes
8706 8685 without saying.
8707 8686 \layout Standard
8708 8687
8709 8688 IPython's website is generously hosted at
8710 8689 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
8711 8690
8712 8691 \end_inset
8713 8692
8714 8693 by Enthought (
8715 8694 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
8716 8695
8717 8696 \end_inset
8718 8697
8719 8698 ).
8720 8699 I am very grateful to them and all of the SciPy team for their contribution.
8721 8700 \layout Standard
8722 8701
8723 8702
8724 8703 \begin_inset LatexCommand \label{figgins}
8725 8704
8726 8705 \end_inset
8727 8706
8728 8707 Fernando would also like to thank Stephen Figgins
8729 8708 \family typewriter
8730 8709 <fig-AT-monitor.net>
8731 8710 \family default
8732 8711 , an O'Reilly Python editor.
8733 8712 His Oct/11/2001 article about IPP and LazyPython, was what got this project
8734 8713 started.
8735 8714 You can read it at:
8736 8715 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html}
8737 8716
8738 8717 \end_inset
8739 8718
8740 8719 .
8741 8720 \layout Standard
8742 8721
8743 8722 And last but not least, all the kind IPython users who have emailed new
8744 8723 code, bug reports, fixes, comments and ideas.
8745 8724 A brief list follows, please let me know if I have ommitted your name by
8746 8725 accident:
8747 8726 \layout List
8748 8727 \labelwidthstring 00.00.0000
8749 8728
8750 8729 Jack\SpecialChar ~
8751 8730 Moffit
8752 8731 \family typewriter
8753 8732 <jack-AT-xiph.org>
8754 8733 \family default
8755 8734 Bug fixes, including the infamous color problem.
8756 8735 This bug alone caused many lost hours and frustration, many thanks to him
8757 8736 for the fix.
8758 8737 I've always been a fan of Ogg & friends, now I have one more reason to
8759 8738 like these folks.
8760 8739 \newline
8761 8740 Jack is also contributing with Debian packaging and many other things.
8762 8741 \layout List
8763 8742 \labelwidthstring 00.00.0000
8764 8743
8765 8744 Alexander\SpecialChar ~
8766 8745 Schmolck
8767 8746 \family typewriter
8768 8747 <a.schmolck-AT-gmx.net>
8769 8748 \family default
8770 8749 Emacs work, bug reports, bug fixes, ideas, lots more.
8771 8750 The ipython.el mode for (X)Emacs is Alex's code, providing full support
8772 8751 for IPython under (X)Emacs.
8773 8752 \layout List
8774 8753 \labelwidthstring 00.00.0000
8775 8754
8776 8755 Andrea\SpecialChar ~
8777 8756 Riciputi
8778 8757 \family typewriter
8779 8758 <andrea.riciputi-AT-libero.it>
8780 8759 \family default
8781 8760 Mac OSX information, Fink package management.
8782 8761 \layout List
8783 8762 \labelwidthstring 00.00.0000
8784 8763
8785 8764 Gary\SpecialChar ~
8786 8765 Bishop
8787 8766 \family typewriter
8788 8767 <gb-AT-cs.unc.edu>
8789 8768 \family default
8790 8769 Bug reports, and patches to work around the exception handling idiosyncracies
8791 8770 of WxPython.
8792 8771 Readline and color support for Windows.
8793 8772 \layout List
8794 8773 \labelwidthstring 00.00.0000
8795 8774
8796 8775 Jeffrey\SpecialChar ~
8797 8776 Collins
8798 8777 \family typewriter
8799 8778 <Jeff.Collins-AT-vexcel.com>
8800 8779 \family default
8801 8780 Bug reports.
8802 8781 Much improved readline support, including fixes for Python 2.3.
8803 8782 \layout List
8804 8783 \labelwidthstring 00.00.0000
8805 8784
8806 8785 Dryice\SpecialChar ~
8807 8786 Liu
8808 8787 \family typewriter
8809 8788 <dryice-AT-liu.com.cn>
8810 8789 \family default
8811 8790 FreeBSD port.
8812 8791 \layout List
8813 8792 \labelwidthstring 00.00.0000
8814 8793
8815 8794 Mike\SpecialChar ~
8816 8795 Heeter
8817 8796 \family typewriter
8818 8797 <korora-AT-SDF.LONESTAR.ORG>
8819 8798 \layout List
8820 8799 \labelwidthstring 00.00.0000
8821 8800
8822 8801 Christopher\SpecialChar ~
8823 8802 Hart
8824 8803 \family typewriter
8825 8804 <hart-AT-caltech.edu>
8826 8805 \family default
8827 8806 PDB integration.
8828 8807 \layout List
8829 8808 \labelwidthstring 00.00.0000
8830 8809
8831 8810 Milan\SpecialChar ~
8832 8811 Zamazal
8833 8812 \family typewriter
8834 8813 <pdm-AT-zamazal.org>
8835 8814 \family default
8836 8815 Emacs info.
8837 8816 \layout List
8838 8817 \labelwidthstring 00.00.0000
8839 8818
8840 8819 Philip\SpecialChar ~
8841 8820 Hisley
8842 8821 \family typewriter
8843 8822 <compsys-AT-starpower.net>
8844 8823 \layout List
8845 8824 \labelwidthstring 00.00.0000
8846 8825
8847 8826 Holger\SpecialChar ~
8848 8827 Krekel
8849 8828 \family typewriter
8850 8829 <pyth-AT-devel.trillke.net>
8851 8830 \family default
8852 8831 Tab completion, lots more.
8853 8832 \layout List
8854 8833 \labelwidthstring 00.00.0000
8855 8834
8856 8835 Robin\SpecialChar ~
8857 8836 Siebler
8858 8837 \family typewriter
8859 8838 <robinsiebler-AT-starband.net>
8860 8839 \layout List
8861 8840 \labelwidthstring 00.00.0000
8862 8841
8863 8842 Ralf\SpecialChar ~
8864 8843 Ahlbrink
8865 8844 \family typewriter
8866 8845 <ralf_ahlbrink-AT-web.de>
8867 8846 \layout List
8868 8847 \labelwidthstring 00.00.0000
8869 8848
8870 8849 Thorsten\SpecialChar ~
8871 8850 Kampe
8872 8851 \family typewriter
8873 8852 <thorsten-AT-thorstenkampe.de>
8874 8853 \layout List
8875 8854 \labelwidthstring 00.00.0000
8876 8855
8877 8856 Fredrik\SpecialChar ~
8878 8857 Kant
8879 8858 \family typewriter
8880 8859 <fredrik.kant-AT-front.com>
8881 8860 \family default
8882 8861 Windows setup.
8883 8862 \layout List
8884 8863 \labelwidthstring 00.00.0000
8885 8864
8886 8865 Syver\SpecialChar ~
8887 8866 Enstad
8888 8867 \family typewriter
8889 8868 <syver-en-AT-online.no>
8890 8869 \family default
8891 8870 Windows setup.
8892 8871 \layout List
8893 8872 \labelwidthstring 00.00.0000
8894 8873
8895 8874 Richard
8896 8875 \family typewriter
8897 8876 <rxe-AT-renre-europe.com>
8898 8877 \family default
8899 8878 Global embedding.
8900 8879 \layout List
8901 8880 \labelwidthstring 00.00.0000
8902 8881
8903 8882 Hayden\SpecialChar ~
8904 8883 Callow
8905 8884 \family typewriter
8906 8885 <h.callow-AT-elec.canterbury.ac.nz>
8907 8886 \family default
8908 8887 Gnuplot.py 1.6 compatibility.
8909 8888 \layout List
8910 8889 \labelwidthstring 00.00.0000
8911 8890
8912 8891 Leonardo\SpecialChar ~
8913 8892 Santagada
8914 8893 \family typewriter
8915 8894 <retype-AT-terra.com.br>
8916 8895 \family default
8917 8896 Fixes for Windows installation.
8918 8897 \layout List
8919 8898 \labelwidthstring 00.00.0000
8920 8899
8921 8900 Christopher\SpecialChar ~
8922 8901 Armstrong
8923 8902 \family typewriter
8924 8903 <radix-AT-twistedmatrix.com>
8925 8904 \family default
8926 8905 Bugfixes.
8927 8906 \layout List
8928 8907 \labelwidthstring 00.00.0000
8929 8908
8930 8909 Francois\SpecialChar ~
8931 8910 Pinard
8932 8911 \family typewriter
8933 8912 <pinard-AT-iro.umontreal.ca>
8934 8913 \family default
8935 8914 Code and documentation fixes.
8936 8915 \layout List
8937 8916 \labelwidthstring 00.00.0000
8938 8917
8939 8918 Cory\SpecialChar ~
8940 8919 Dodt
8941 8920 \family typewriter
8942 8921 <cdodt-AT-fcoe.k12.ca.us>
8943 8922 \family default
8944 8923 Bug reports and Windows ideas.
8945 8924 Patches for Windows installer.
8946 8925 \layout List
8947 8926 \labelwidthstring 00.00.0000
8948 8927
8949 8928 Olivier\SpecialChar ~
8950 8929 Aubert
8951 8930 \family typewriter
8952 8931 <oaubert-AT-bat710.univ-lyon1.fr>
8953 8932 \family default
8954 8933 New magics.
8955 8934 \layout List
8956 8935 \labelwidthstring 00.00.0000
8957 8936
8958 8937 King\SpecialChar ~
8959 8938 C.\SpecialChar ~
8960 8939 Shu
8961 8940 \family typewriter
8962 8941 <kingshu-AT-myrealbox.com>
8963 8942 \family default
8964 8943 Autoindent patch.
8965 8944 \layout List
8966 8945 \labelwidthstring 00.00.0000
8967 8946
8968 8947 Chris\SpecialChar ~
8969 8948 Drexler
8970 8949 \family typewriter
8971 8950 <chris-AT-ac-drexler.de>
8972 8951 \family default
8973 8952 Readline packages for Win32/CygWin.
8974 8953 \layout List
8975 8954 \labelwidthstring 00.00.0000
8976 8955
8977 8956 Gustavo\SpecialChar ~
8978 8957 Córdova\SpecialChar ~
8979 8958 Avila
8980 8959 \family typewriter
8981 8960 <gcordova-AT-sismex.com>
8982 8961 \family default
8983 8962 EvalDict code for nice, lightweight string interpolation.
8984 8963 \layout List
8985 8964 \labelwidthstring 00.00.0000
8986 8965
8987 8966 Kasper\SpecialChar ~
8988 8967 Souren
8989 8968 \family typewriter
8990 8969 <Kasper.Souren-AT-ircam.fr>
8991 8970 \family default
8992 8971 Bug reports, ideas.
8993 8972 \layout List
8994 8973 \labelwidthstring 00.00.0000
8995 8974
8996 8975 Gever\SpecialChar ~
8997 8976 Tulley
8998 8977 \family typewriter
8999 8978 <gever-AT-helium.com>
9000 8979 \family default
9001 8980 Code contributions.
9002 8981 \layout List
9003 8982 \labelwidthstring 00.00.0000
9004 8983
9005 8984 Ralf\SpecialChar ~
9006 8985 Schmitt
9007 8986 \family typewriter
9008 8987 <ralf-AT-brainbot.com>
9009 8988 \family default
9010 8989 Bug reports & fixes.
9011 8990 \layout List
9012 8991 \labelwidthstring 00.00.0000
9013 8992
9014 8993 Oliver\SpecialChar ~
9015 8994 Sander
9016 8995 \family typewriter
9017 8996 <osander-AT-gmx.de>
9018 8997 \family default
9019 8998 Bug reports.
9020 8999 \layout List
9021 9000 \labelwidthstring 00.00.0000
9022 9001
9023 9002 Rod\SpecialChar ~
9024 9003 Holland
9025 9004 \family typewriter
9026 9005 <rhh-AT-structurelabs.com>
9027 9006 \family default
9028 9007 Bug reports and fixes to logging module.
9029 9008 \layout List
9030 9009 \labelwidthstring 00.00.0000
9031 9010
9032 9011 Daniel\SpecialChar ~
9033 9012 'Dang'\SpecialChar ~
9034 9013 Griffith
9035 9014 \family typewriter
9036 9015 <pythondev-dang-AT-lazytwinacres.net>
9037 9016 \family default
9038 9017 Fixes, enhancement suggestions for system shell use.
9039 9018 \layout List
9040 9019 \labelwidthstring 00.00.0000
9041 9020
9042 9021 Viktor\SpecialChar ~
9043 9022 Ransmayr
9044 9023 \family typewriter
9045 9024 <viktor.ransmayr-AT-t-online.de>
9046 9025 \family default
9047 9026 Tests and reports on Windows installation issues.
9048 9027 Contributed a true Windows binary installer.
9049 9028 \layout List
9050 9029 \labelwidthstring 00.00.0000
9051 9030
9052 9031 Mike\SpecialChar ~
9053 9032 Salib
9054 9033 \family typewriter
9055 9034 <msalib-AT-mit.edu>
9056 9035 \family default
9057 9036 Help fixing a subtle bug related to traceback printing.
9058 9037 \layout List
9059 9038 \labelwidthstring 00.00.0000
9060 9039
9061 9040 W.J.\SpecialChar ~
9062 9041 van\SpecialChar ~
9063 9042 der\SpecialChar ~
9064 9043 Laan
9065 9044 \family typewriter
9066 9045 <gnufnork-AT-hetdigitalegat.nl>
9067 9046 \family default
9068 9047 Bash-like prompt specials.
9069 9048 \layout List
9070 9049 \labelwidthstring 00.00.0000
9071 9050
9072 9051 Ville\SpecialChar ~
9073 9052 Vainio
9074 9053 \family typewriter
9075 9054 <vivainio-AT-kolumbus.fi>
9076 9055 \family default
9077 9056 Bugfixes and suggestions.
9078 9057 Excellent patches for many new features.
9079 9058 \layout List
9080 9059 \labelwidthstring 00.00.0000
9081 9060
9082 9061 Antoon\SpecialChar ~
9083 9062 Pardon
9084 9063 \family typewriter
9085 9064 <Antoon.Pardon-AT-rece.vub.ac.be>
9086 9065 \family default
9087 9066 Critical fix for the multithreaded IPython.
9088 9067 \layout List
9089 9068 \labelwidthstring 00.00.0000
9090 9069
9091 9070 John\SpecialChar ~
9092 9071 Hunter
9093 9072 \family typewriter
9094 9073 <jdhunter-AT-nitace.bsd.uchicago.edu>
9095 9074 \family default
9096 9075 Matplotlib author, helped with all the development of support for matplotlib
9097 9076 in IPyhton, including making necessary changes to matplotlib itself.
9098 9077 \layout List
9099 9078 \labelwidthstring 00.00.0000
9100 9079
9101 9080 Matthew\SpecialChar ~
9102 9081 Arnison
9103 9082 \family typewriter
9104 9083 <maffew-AT-cat.org.au>
9105 9084 \family default
9106 9085 Bug reports, `
9107 9086 \family typewriter
9108 9087 %run -d
9109 9088 \family default
9110 9089 ' idea.
9111 9090 \layout List
9112 9091 \labelwidthstring 00.00.0000
9113 9092
9114 9093 Prabhu\SpecialChar ~
9115 9094 Ramachandran
9116 9095 \family typewriter
9117 9096 <prabhu_r-AT-users.sourceforge.net>
9118 9097 \family default
9119 9098 Help with (X)Emacs support, threading patches, ideas...
9120 9099 \layout List
9121 9100 \labelwidthstring 00.00.0000
9122 9101
9123 9102 Norbert\SpecialChar ~
9124 9103 Tretkowski
9125 9104 \family typewriter
9126 9105 <tretkowski-AT-inittab.de>
9127 9106 \family default
9128 9107 help with Debian packaging and distribution.
9129 9108 \layout List
9130 9109 \labelwidthstring 00.00.0000
9131 9110
9132 9111 George\SpecialChar ~
9133 9112 Sakkis <
9134 9113 \family typewriter
9135 9114 gsakkis-AT-eden.rutgers.edu>
9136 9115 \family default
9137 9116 New matcher for tab-completing named arguments of user-defined functions.
9138 9117 \layout List
9139 9118 \labelwidthstring 00.00.0000
9140 9119
9141 9120 J�rgen\SpecialChar ~
9142 9121 Stenarson
9143 9122 \family typewriter
9144 9123 <jorgen.stenarson-AT-bostream.nu>
9145 9124 \family default
9146 9125 Wildcard support implementation for searching namespaces.
9147 9126 \layout List
9148 9127 \labelwidthstring 00.00.0000
9149 9128
9150 9129 Vivian\SpecialChar ~
9151 9130 De\SpecialChar ~
9152 9131 Smedt
9153 9132 \family typewriter
9154 9133 <vivian-AT-vdesmedt.com>
9155 9134 \family default
9156 9135 Debugger enhancements, so that when pdb is activated from within IPython,
9157 9136 coloring, tab completion and other features continue to work seamlessly.
9158 9137 \layout List
9159 9138 \labelwidthstring 00.00.0000
9160 9139
9161 Scott (email unknown) Support for automatic editor invocation on syntax
9162 errors (see
9140 Scott\SpecialChar ~
9141 Tsai
9142 \family typewriter
9143 <scottt958-AT-yahoo.com.tw>
9144 \family default
9145 Support for automatic editor invocation on syntax errors (see
9163 9146 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython/issue36}
9164 9147
9165 9148 \end_inset
9166 9149
9167 9150 ).
9168 9151 \the_end
General Comments 0
You need to be logged in to leave comments. Login now