##// END OF EJS Templates
Add Ville's patch for the new %store persistence magic.
fperez -
Show More
@@ -1,2594 +1,2669 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 966 2005-12-29 08:34:07Z fperez $"""
4 $Id: Magic.py 968 2005-12-29 17:15:38Z 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 import cPickle as pickle
33 34 from cStringIO import StringIO
34 35 from getopt import getopt
35 36 from pprint import pprint, pformat
36 37
37 38 # profile isn't bundled by default in Debian for license reasons
38 39 try:
39 40 import profile,pstats
40 41 except ImportError:
41 42 profile = pstats = None
42 43
43 44 # Homebrewed
44 45 from IPython import Debugger, OInspect, wildcard
45 46 from IPython.FakeModule import FakeModule
46 47 from IPython.Itpl import Itpl, itpl, printpl,itplns
47 48 from IPython.PyColorize import Parser
48 49 from IPython.Struct import Struct
49 50 from IPython.genutils import *
50 51
51 52 #***************************************************************************
52 53 # Utility functions
53 54 def on_off(tag):
54 55 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
55 56 return ['OFF','ON'][tag]
56 57
57 58
58 59 #****************************************************************************
59 60 # Utility classes
60 61 class Macro(list):
61 62 """Simple class to store the value of macros as strings.
62 63
63 64 This allows us to later exec them by checking when something is an
64 65 instance of this class."""
65 66
66 67 def __init__(self,data):
67 68 list.__init__(self,data)
68 69 self.value = ''.join(data)
69 70
70 71 #***************************************************************************
71 72 # Main class implementing Magic functionality
72 73 class Magic:
73 74 """Magic functions for InteractiveShell.
74 75
75 76 Shell functions which can be reached as %function_name. All magic
76 77 functions should accept a string, which they can parse for their own
77 78 needs. This can make some functions easier to type, eg `%cd ../`
78 79 vs. `%cd("../")`
79 80
80 81 ALL definitions MUST begin with the prefix magic_. The user won't need it
81 82 at the command line, but it is is needed in the definition. """
82 83
83 84 # class globals
84 85 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
85 86 'Automagic is ON, % prefix NOT needed for magic functions.']
86 87
87 88 #......................................................................
88 89 # some utility functions
89 90
90 91 def __init__(self,shell):
91 92
92 93 self.options_table = {}
93 94 if profile is None:
94 95 self.magic_prun = self.profile_missing_notice
95 96 self.shell = shell
96 97
97 98 def profile_missing_notice(self, *args, **kwargs):
98 99 error("""\
99 100 The profile module could not be found. If you are a Debian user,
100 101 it has been removed from the standard Debian package because of its non-free
101 102 license. To use profiling, please install"python2.3-profiler" from non-free.""")
102 103
103 104 def default_option(self,fn,optstr):
104 105 """Make an entry in the options_table for fn, with value optstr"""
105 106
106 107 if fn not in self.lsmagic():
107 108 error("%s is not a magic function" % fn)
108 109 self.options_table[fn] = optstr
109 110
110 111 def lsmagic(self):
111 112 """Return a list of currently available magic functions.
112 113
113 114 Gives a list of the bare names after mangling (['ls','cd', ...], not
114 115 ['magic_ls','magic_cd',...]"""
115 116
116 117 # FIXME. This needs a cleanup, in the way the magics list is built.
117 118
118 119 # magics in class definition
119 120 class_magic = lambda fn: fn.startswith('magic_') and \
120 121 callable(Magic.__dict__[fn])
121 122 # in instance namespace (run-time user additions)
122 123 inst_magic = lambda fn: fn.startswith('magic_') and \
123 124 callable(self.__dict__[fn])
124 125 # and bound magics by user (so they can access self):
125 126 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
126 127 callable(self.__class__.__dict__[fn])
127 128 magics = filter(class_magic,Magic.__dict__.keys()) + \
128 129 filter(inst_magic,self.__dict__.keys()) + \
129 130 filter(inst_bound_magic,self.__class__.__dict__.keys())
130 131 out = []
131 132 for fn in magics:
132 133 out.append(fn.replace('magic_','',1))
133 134 out.sort()
134 135 return out
135 136
136 137 def extract_input_slices(self,slices):
137 138 """Return as a string a set of input history slices.
138 139
139 140 The set of slices is given as a list of strings (like ['1','4:8','9'],
140 141 since this function is for use by magic functions which get their
141 142 arguments as strings."""
142 143
143 144 cmds = []
144 145 for chunk in slices:
145 146 if ':' in chunk:
146 147 ini,fin = map(int,chunk.split(':'))
147 148 else:
148 149 ini = int(chunk)
149 150 fin = ini+1
150 151 cmds.append(self.shell.input_hist[ini:fin])
151 152 return cmds
152 153
153 154 def _ofind(self,oname):
154 155 """Find an object in the available namespaces.
155 156
156 157 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
157 158
158 159 Has special code to detect magic functions.
159 160 """
160 161
161 162 oname = oname.strip()
162 163
163 164 # Namespaces to search in:
164 165 user_ns = self.shell.user_ns
165 166 internal_ns = self.shell.internal_ns
166 167 builtin_ns = __builtin__.__dict__
167 168 alias_ns = self.shell.alias_table
168 169
169 170 # Put them in a list. The order is important so that we find things in
170 171 # the same order that Python finds them.
171 172 namespaces = [ ('Interactive',user_ns),
172 173 ('IPython internal',internal_ns),
173 174 ('Python builtin',builtin_ns),
174 175 ('Alias',alias_ns),
175 176 ]
176 177
177 178 # initialize results to 'null'
178 179 found = 0; obj = None; ospace = None; ds = None;
179 180 ismagic = 0; isalias = 0
180 181
181 182 # Look for the given name by splitting it in parts. If the head is
182 183 # found, then we look for all the remaining parts as members, and only
183 184 # declare success if we can find them all.
184 185 oname_parts = oname.split('.')
185 186 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
186 187 for nsname,ns in namespaces:
187 188 try:
188 189 obj = ns[oname_head]
189 190 except KeyError:
190 191 continue
191 192 else:
192 193 for part in oname_rest:
193 194 try:
194 195 obj = getattr(obj,part)
195 196 except:
196 197 # Blanket except b/c some badly implemented objects
197 198 # allow __getattr__ to raise exceptions other than
198 199 # AttributeError, which then crashes IPython.
199 200 break
200 201 else:
201 202 # If we finish the for loop (no break), we got all members
202 203 found = 1
203 204 ospace = nsname
204 205 if ns == alias_ns:
205 206 isalias = 1
206 207 break # namespace loop
207 208
208 209 # Try to see if it's magic
209 210 if not found:
210 211 if oname.startswith(self.shell.ESC_MAGIC):
211 212 oname = oname[1:]
212 213 obj = getattr(self,'magic_'+oname,None)
213 214 if obj is not None:
214 215 found = 1
215 216 ospace = 'IPython internal'
216 217 ismagic = 1
217 218
218 219 # Last try: special-case some literals like '', [], {}, etc:
219 220 if not found and oname_head in ["''",'""','[]','{}','()']:
220 221 obj = eval(oname_head)
221 222 found = 1
222 223 ospace = 'Interactive'
223 224
224 225 return {'found':found, 'obj':obj, 'namespace':ospace,
225 226 'ismagic':ismagic, 'isalias':isalias}
226 227
227 228 def arg_err(self,func):
228 229 """Print docstring if incorrect arguments were passed"""
229 230 print 'Error in arguments:'
230 231 print OInspect.getdoc(func)
231 232
232 233
233 234 def format_latex(self,str):
234 235 """Format a string for latex inclusion."""
235 236
236 237 # Characters that need to be escaped for latex:
237 238 escape_re = re.compile(r'(%|_|\$)',re.MULTILINE)
238 239 # Magic command names as headers:
239 240 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
240 241 re.MULTILINE)
241 242 # Magic commands
242 243 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
243 244 re.MULTILINE)
244 245 # Paragraph continue
245 246 par_re = re.compile(r'\\$',re.MULTILINE)
246 247
247 248 str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str)
248 249 str = cmd_re.sub(r'\\texttt{\g<cmd>}',str)
249 250 str = par_re.sub(r'\\\\',str)
250 251 str = escape_re.sub(r'\\\1',str)
251 252 return str
252 253
253 254 def format_screen(self,str):
254 255 """Format a string for screen printing.
255 256
256 257 This removes some latex-type format codes."""
257 258 # Paragraph continue
258 259 par_re = re.compile(r'\\$',re.MULTILINE)
259 260 str = par_re.sub('',str)
260 261 return str
261 262
262 263 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
263 264 """Parse options passed to an argument string.
264 265
265 266 The interface is similar to that of getopt(), but it returns back a
266 267 Struct with the options as keys and the stripped argument string still
267 268 as a string.
268 269
269 270 arg_str is quoted as a true sys.argv vector by using shlex.split.
270 271 This allows us to easily expand variables, glob files, quote
271 272 arguments, etc.
272 273
273 274 Options:
274 275 -mode: default 'string'. If given as 'list', the argument string is
275 276 returned as a list (split on whitespace) instead of a string.
276 277
277 278 -list_all: put all option values in lists. Normally only options
278 279 appearing more than once are put in a list."""
279 280
280 281 # inject default options at the beginning of the input line
281 282 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
282 283 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
283 284
284 285 mode = kw.get('mode','string')
285 286 if mode not in ['string','list']:
286 287 raise ValueError,'incorrect mode given: %s' % mode
287 288 # Get options
288 289 list_all = kw.get('list_all',0)
289 290
290 291 # Check if we have more than one argument to warrant extra processing:
291 292 odict = {} # Dictionary with options
292 293 args = arg_str.split()
293 294 if len(args) >= 1:
294 295 # If the list of inputs only has 0 or 1 thing in it, there's no
295 296 # need to look for options
296 297 argv = shlex_split(arg_str)
297 298 # Do regular option processing
298 299 opts,args = getopt(argv,opt_str,*long_opts)
299 300 for o,a in opts:
300 301 if o.startswith('--'):
301 302 o = o[2:]
302 303 else:
303 304 o = o[1:]
304 305 try:
305 306 odict[o].append(a)
306 307 except AttributeError:
307 308 odict[o] = [odict[o],a]
308 309 except KeyError:
309 310 if list_all:
310 311 odict[o] = [a]
311 312 else:
312 313 odict[o] = a
313 314
314 315 # Prepare opts,args for return
315 316 opts = Struct(odict)
316 317 if mode == 'string':
317 318 args = ' '.join(args)
318 319
319 320 return opts,args
320 321
321 322 #......................................................................
322 323 # And now the actual magic functions
323 324
324 325 # Functions for IPython shell work (vars,funcs, config, etc)
325 326 def magic_lsmagic(self, parameter_s = ''):
326 327 """List currently available magic functions."""
327 328 mesc = self.shell.ESC_MAGIC
328 329 print 'Available magic functions:\n'+mesc+\
329 330 (' '+mesc).join(self.lsmagic())
330 331 print '\n' + Magic.auto_status[self.shell.rc.automagic]
331 332 return None
332 333
333 334 def magic_magic(self, parameter_s = ''):
334 335 """Print information about the magic function system."""
335 336
336 337 mode = ''
337 338 try:
338 339 if parameter_s.split()[0] == '-latex':
339 340 mode = 'latex'
340 341 except:
341 342 pass
342 343
343 344 magic_docs = []
344 345 for fname in self.lsmagic():
345 346 mname = 'magic_' + fname
346 347 for space in (Magic,self,self.__class__):
347 348 try:
348 349 fn = space.__dict__[mname]
349 350 except KeyError:
350 351 pass
351 352 else:
352 353 break
353 354 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
354 355 fname,fn.__doc__))
355 356 magic_docs = ''.join(magic_docs)
356 357
357 358 if mode == 'latex':
358 359 print self.format_latex(magic_docs)
359 360 return
360 361 else:
361 362 magic_docs = self.format_screen(magic_docs)
362 363
363 364 outmsg = """
364 365 IPython's 'magic' functions
365 366 ===========================
366 367
367 368 The magic function system provides a series of functions which allow you to
368 369 control the behavior of IPython itself, plus a lot of system-type
369 370 features. All these functions are prefixed with a % character, but parameters
370 371 are given without parentheses or quotes.
371 372
372 373 NOTE: If you have 'automagic' enabled (via the command line option or with the
373 374 %automagic function), you don't need to type in the % explicitly. By default,
374 375 IPython ships with automagic on, so you should only rarely need the % escape.
375 376
376 377 Example: typing '%cd mydir' (without the quotes) changes you working directory
377 378 to 'mydir', if it exists.
378 379
379 380 You can define your own magic functions to extend the system. See the supplied
380 381 ipythonrc and example-magic.py files for details (in your ipython
381 382 configuration directory, typically $HOME/.ipython/).
382 383
383 384 You can also define your own aliased names for magic functions. In your
384 385 ipythonrc file, placing a line like:
385 386
386 387 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
387 388
388 389 will define %pf as a new name for %profile.
389 390
390 391 You can also call magics in code using the ipmagic() function, which IPython
391 392 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
392 393
393 394 For a list of the available magic functions, use %lsmagic. For a description
394 395 of any of them, type %magic_name?, e.g. '%cd?'.
395 396
396 397 Currently the magic system has the following functions:\n"""
397 398
398 399 mesc = self.shell.ESC_MAGIC
399 400 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
400 401 "\n\n%s%s\n\n%s" % (outmsg,
401 402 magic_docs,mesc,mesc,
402 403 (' '+mesc).join(self.lsmagic()),
403 404 Magic.auto_status[self.shell.rc.automagic] ) )
404 405
405 406 page(outmsg,screen_lines=self.shell.rc.screen_length)
406 407
407 408 def magic_automagic(self, parameter_s = ''):
408 409 """Make magic functions callable without having to type the initial %.
409 410
410 411 Toggles on/off (when off, you must call it as %automagic, of
411 412 course). Note that magic functions have lowest priority, so if there's
412 413 a variable whose name collides with that of a magic fn, automagic
413 414 won't work for that function (you get the variable instead). However,
414 415 if you delete the variable (del var), the previously shadowed magic
415 416 function becomes visible to automagic again."""
416 417
417 418 rc = self.shell.rc
418 419 rc.automagic = not rc.automagic
419 420 print '\n' + Magic.auto_status[rc.automagic]
420 421
421 422 def magic_autocall(self, parameter_s = ''):
422 423 """Make functions callable without having to type parentheses.
423 424
424 425 This toggles the autocall command line option on and off."""
425 426
426 427 rc = self.shell.rc
427 428 rc.autocall = not rc.autocall
428 429 print "Automatic calling is:",['OFF','ON'][rc.autocall]
429 430
430 431 def magic_autoindent(self, parameter_s = ''):
431 432 """Toggle autoindent on/off (if available)."""
432 433
433 434 self.shell.set_autoindent()
434 435 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
435 436
436 437 def magic_system_verbose(self, parameter_s = ''):
437 438 """Toggle verbose printing of system calls on/off."""
438 439
439 440 self.shell.rc_set_toggle('system_verbose')
440 441 print "System verbose printing is:",\
441 442 ['OFF','ON'][self.shell.rc.system_verbose]
442 443
443 444 def magic_history(self, parameter_s = ''):
444 445 """Print input history (_i<n> variables), with most recent last.
445 446
446 447 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
447 448 %history [-n] n -> print at most n inputs\\
448 449 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
449 450
450 451 Each input's number <n> is shown, and is accessible as the
451 452 automatically generated variable _i<n>. Multi-line statements are
452 453 printed starting at a new line for easy copy/paste.
453 454
454 455 If option -n is used, input numbers are not printed. This is useful if
455 456 you want to get a printout of many lines which can be directly pasted
456 457 into a text editor.
457 458
458 459 This feature is only available if numbered prompts are in use."""
459 460
460 461 if not self.shell.outputcache.do_full_cache:
461 462 print 'This feature is only available if numbered prompts are in use.'
462 463 return
463 464 opts,args = self.parse_options(parameter_s,'n',mode='list')
464 465
465 466 default_length = 40
466 467 if len(args) == 0:
467 468 final = self.shell.outputcache.prompt_count
468 469 init = max(1,final-default_length)
469 470 elif len(args) == 1:
470 471 final = self.shell.outputcache.prompt_count
471 472 init = max(1,final-int(args[0]))
472 473 elif len(args) == 2:
473 474 init,final = map(int,args)
474 475 else:
475 476 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
476 477 print self.magic_hist.__doc__
477 478 return
478 479 width = len(str(final))
479 480 line_sep = ['','\n']
480 481 input_hist = self.shell.input_hist
481 482 print_nums = not opts.has_key('n')
482 483 for in_num in range(init,final):
483 484 inline = input_hist[in_num]
484 485 multiline = inline.count('\n') > 1
485 486 if print_nums:
486 487 print str(in_num).ljust(width)+':'+ line_sep[multiline],
487 488 if inline.startswith('#'+self.shell.ESC_MAGIC) or \
488 489 inline.startswith('#!'):
489 490 print inline[1:],
490 491 else:
491 492 print inline,
492 493
493 494 def magic_hist(self, parameter_s=''):
494 495 """Alternate name for %history."""
495 496 return self.magic_history(parameter_s)
496 497
497 498 def magic_p(self, parameter_s=''):
498 499 """Just a short alias for Python's 'print'."""
499 500 exec 'print ' + parameter_s in self.shell.user_ns
500 501
501 502 def magic_r(self, parameter_s=''):
502 503 """Repeat previous input.
503 504
504 505 If given an argument, repeats the previous command which starts with
505 506 the same string, otherwise it just repeats the previous input.
506 507
507 508 Shell escaped commands (with ! as first character) are not recognized
508 509 by this system, only pure python code and magic commands.
509 510 """
510 511
511 512 start = parameter_s.strip()
512 513 esc_magic = self.shell.ESC_MAGIC
513 514 # Identify magic commands even if automagic is on (which means
514 515 # the in-memory version is different from that typed by the user).
515 516 if self.shell.rc.automagic:
516 517 start_magic = esc_magic+start
517 518 else:
518 519 start_magic = start
519 520 # Look through the input history in reverse
520 521 for n in range(len(self.shell.input_hist)-2,0,-1):
521 522 input = self.shell.input_hist[n]
522 523 # skip plain 'r' lines so we don't recurse to infinity
523 524 if input != 'ipmagic("r")\n' and \
524 525 (input.startswith(start) or input.startswith(start_magic)):
525 526 #print 'match',`input` # dbg
526 527 print 'Executing:',input,
527 528 self.shell.runlines(input)
528 529 return
529 530 print 'No previous input matching `%s` found.' % start
530 531
531 532 def magic_page(self, parameter_s=''):
532 533 """Pretty print the object and display it through a pager.
533 534
534 535 If no parameter is given, use _ (last output)."""
535 536 # After a function contributed by Olivier Aubert, slightly modified.
536 537
537 538 oname = parameter_s and parameter_s or '_'
538 539 info = self._ofind(oname)
539 540 if info['found']:
540 541 page(pformat(info['obj']))
541 542 else:
542 543 print 'Object `%s` not found' % oname
543 544
544 545 def magic_profile(self, parameter_s=''):
545 546 """Print your currently active IPyhton profile."""
546 547 if self.shell.rc.profile:
547 548 printpl('Current IPython profile: $self.shell.rc.profile.')
548 549 else:
549 550 print 'No profile active.'
550 551
551 552 def _inspect(self,meth,oname,**kw):
552 553 """Generic interface to the inspector system.
553 554
554 555 This function is meant to be called by pdef, pdoc & friends."""
555 556
556 557 oname = oname.strip()
557 558 info = Struct(self._ofind(oname))
558 559 if info.found:
559 560 pmethod = getattr(self.shell.inspector,meth)
560 561 formatter = info.ismagic and self.format_screen or None
561 562 if meth == 'pdoc':
562 563 pmethod(info.obj,oname,formatter)
563 564 elif meth == 'pinfo':
564 565 pmethod(info.obj,oname,formatter,info,**kw)
565 566 else:
566 567 pmethod(info.obj,oname)
567 568 else:
568 569 print 'Object `%s` not found.' % oname
569 570 return 'not found' # so callers can take other action
570 571
571 572 def magic_pdef(self, parameter_s=''):
572 573 """Print the definition header for any callable object.
573 574
574 575 If the object is a class, print the constructor information."""
575 576 self._inspect('pdef',parameter_s)
576 577
577 578 def magic_pdoc(self, parameter_s=''):
578 579 """Print the docstring for an object.
579 580
580 581 If the given object is a class, it will print both the class and the
581 582 constructor docstrings."""
582 583 self._inspect('pdoc',parameter_s)
583 584
584 585 def magic_psource(self, parameter_s=''):
585 586 """Print (or run through pager) the source code for an object."""
586 587 self._inspect('psource',parameter_s)
587 588
588 589 def magic_pfile(self, parameter_s=''):
589 590 """Print (or run through pager) the file where an object is defined.
590 591
591 592 The file opens at the line where the object definition begins. IPython
592 593 will honor the environment variable PAGER if set, and otherwise will
593 594 do its best to print the file in a convenient form.
594 595
595 596 If the given argument is not an object currently defined, IPython will
596 597 try to interpret it as a filename (automatically adding a .py extension
597 598 if needed). You can thus use %pfile as a syntax highlighting code
598 599 viewer."""
599 600
600 601 # first interpret argument as an object name
601 602 out = self._inspect('pfile',parameter_s)
602 603 # if not, try the input as a filename
603 604 if out == 'not found':
604 605 try:
605 606 filename = get_py_filename(parameter_s)
606 607 except IOError,msg:
607 608 print msg
608 609 return
609 610 page(self.shell.inspector.format(file(filename).read()))
610 611
611 612 def magic_pinfo(self, parameter_s=''):
612 613 """Provide detailed information about an object.
613 614
614 615 '%pinfo object' is just a synonym for object? or ?object."""
615 616
616 617 #print 'pinfo par: <%s>' % parameter_s # dbg
617 618
618 619 # detail_level: 0 -> obj? , 1 -> obj??
619 620 detail_level = 0
620 621 # We need to detect if we got called as 'pinfo pinfo foo', which can
621 622 # happen if the user types 'pinfo foo?' at the cmd line.
622 623 pinfo,qmark1,oname,qmark2 = \
623 624 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
624 625 if pinfo or qmark1 or qmark2:
625 626 detail_level = 1
626 627 if "*" in oname:
627 628 self.magic_psearch(oname)
628 629 else:
629 630 self._inspect('pinfo',oname,detail_level=detail_level)
630 631
631 632 def magic_psearch(self, parameter_s=''):
632 633 """Search for object in namespaces by wildcard.
633 634
634 635 %psearch [options] PATTERN [OBJECT TYPE]
635 636
636 637 Note: ? can be used as a synonym for %psearch, at the beginning or at
637 638 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
638 639 rest of the command line must be unchanged (options come first), so
639 640 for example the following forms are equivalent
640 641
641 642 %psearch -i a* function
642 643 -i a* function?
643 644 ?-i a* function
644 645
645 646 Arguments:
646 647
647 648 PATTERN
648 649
649 650 where PATTERN is a string containing * as a wildcard similar to its
650 651 use in a shell. The pattern is matched in all namespaces on the
651 652 search path. By default objects starting with a single _ are not
652 653 matched, many IPython generated objects have a single
653 654 underscore. The default is case insensitive matching. Matching is
654 655 also done on the attributes of objects and not only on the objects
655 656 in a module.
656 657
657 658 [OBJECT TYPE]
658 659
659 660 Is the name of a python type from the types module. The name is
660 661 given in lowercase without the ending type, ex. StringType is
661 662 written string. By adding a type here only objects matching the
662 663 given type are matched. Using all here makes the pattern match all
663 664 types (this is the default).
664 665
665 666 Options:
666 667
667 668 -a: makes the pattern match even objects whose names start with a
668 669 single underscore. These names are normally ommitted from the
669 670 search.
670 671
671 672 -i/-c: make the pattern case insensitive/sensitive. If neither of
672 673 these options is given, the default is read from your ipythonrc
673 674 file. The option name which sets this value is
674 675 'wildcards_case_sensitive'. If this option is not specified in your
675 676 ipythonrc file, IPython's internal default is to do a case sensitive
676 677 search.
677 678
678 679 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
679 680 specifiy can be searched in any of the following namespaces:
680 681 'builtin', 'user', 'user_global','internal', 'alias', where
681 682 'builtin' and 'user' are the search defaults. Note that you should
682 683 not use quotes when specifying namespaces.
683 684
684 685 'Builtin' contains the python module builtin, 'user' contains all
685 686 user data, 'alias' only contain the shell aliases and no python
686 687 objects, 'internal' contains objects used by IPython. The
687 688 'user_global' namespace is only used by embedded IPython instances,
688 689 and it contains module-level globals. You can add namespaces to the
689 690 search with -s or exclude them with -e (these options can be given
690 691 more than once).
691 692
692 693 Examples:
693 694
694 695 %psearch a* -> objects beginning with an a
695 696 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
696 697 %psearch a* function -> all functions beginning with an a
697 698 %psearch re.e* -> objects beginning with an e in module re
698 699 %psearch r*.e* -> objects that start with e in modules starting in r
699 700 %psearch r*.* string -> all strings in modules beginning with r
700 701
701 702 Case sensitve search:
702 703
703 704 %psearch -c a* list all object beginning with lower case a
704 705
705 706 Show objects beginning with a single _:
706 707
707 708 %psearch -a _* list objects beginning with a single underscore"""
708 709
709 710 # default namespaces to be searched
710 711 def_search = ['user','builtin']
711 712
712 713 # Process options/args
713 714 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
714 715 opt = opts.get
715 716 shell = self.shell
716 717 psearch = shell.inspector.psearch
717 718
718 719 # select case options
719 720 if opts.has_key('i'):
720 721 ignore_case = True
721 722 elif opts.has_key('c'):
722 723 ignore_case = False
723 724 else:
724 725 ignore_case = not shell.rc.wildcards_case_sensitive
725 726
726 727 # Build list of namespaces to search from user options
727 728 def_search.extend(opt('s',[]))
728 729 ns_exclude = ns_exclude=opt('e',[])
729 730 ns_search = [nm for nm in def_search if nm not in ns_exclude]
730 731
731 732 # Call the actual search
732 733 try:
733 734 psearch(args,shell.ns_table,ns_search,
734 735 show_all=opt('a'),ignore_case=ignore_case)
735 736 except:
736 737 shell.showtraceback()
737 738
738 739 def magic_who_ls(self, parameter_s=''):
739 740 """Return a sorted list of all interactive variables.
740 741
741 742 If arguments are given, only variables of types matching these
742 743 arguments are returned."""
743 744
744 745 user_ns = self.shell.user_ns
745 746 out = []
746 747 typelist = parameter_s.split()
747 748 for i in self.shell.user_ns.keys():
748 749 if not (i.startswith('_') or i.startswith('_i')) \
749 750 and not (self.shell.internal_ns.has_key(i) or
750 751 self.shell.user_config_ns.has_key(i)):
751 752 if typelist:
752 753 if type(user_ns[i]).__name__ in typelist:
753 754 out.append(i)
754 755 else:
755 756 out.append(i)
756 757 out.sort()
757 758 return out
758 759
759 760 def magic_who(self, parameter_s=''):
760 761 """Print all interactive variables, with some minimal formatting.
761 762
762 763 If any arguments are given, only variables whose type matches one of
763 764 these are printed. For example:
764 765
765 766 %who function str
766 767
767 768 will only list functions and strings, excluding all other types of
768 769 variables. To find the proper type names, simply use type(var) at a
769 770 command line to see how python prints type names. For example:
770 771
771 772 In [1]: type('hello')\\
772 773 Out[1]: <type 'str'>
773 774
774 775 indicates that the type name for strings is 'str'.
775 776
776 777 %who always excludes executed names loaded through your configuration
777 778 file and things which are internal to IPython.
778 779
779 780 This is deliberate, as typically you may load many modules and the
780 781 purpose of %who is to show you only what you've manually defined."""
781 782
782 783 varlist = self.magic_who_ls(parameter_s)
783 784 if not varlist:
784 785 print 'Interactive namespace is empty.'
785 786 return
786 787
787 788 # if we have variables, move on...
788 789
789 790 # stupid flushing problem: when prompts have no separators, stdout is
790 791 # getting lost. I'm starting to think this is a python bug. I'm having
791 792 # to force a flush with a print because even a sys.stdout.flush
792 793 # doesn't seem to do anything!
793 794
794 795 count = 0
795 796 for i in varlist:
796 797 print i+'\t',
797 798 count += 1
798 799 if count > 8:
799 800 count = 0
800 801 print
801 802 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
802 803
803 804 print # well, this does force a flush at the expense of an extra \n
804 805
805 806 def magic_whos(self, parameter_s=''):
806 807 """Like %who, but gives some extra information about each variable.
807 808
808 809 The same type filtering of %who can be applied here.
809 810
810 811 For all variables, the type is printed. Additionally it prints:
811 812
812 813 - For {},[],(): their length.
813 814
814 815 - For Numeric arrays, a summary with shape, number of elements,
815 816 typecode and size in memory.
816 817
817 818 - Everything else: a string representation, snipping their middle if
818 819 too long."""
819 820
820 821 varnames = self.magic_who_ls(parameter_s)
821 822 if not varnames:
822 823 print 'Interactive namespace is empty.'
823 824 return
824 825
825 826 # if we have variables, move on...
826 827
827 828 # for these types, show len() instead of data:
828 829 seq_types = [types.DictType,types.ListType,types.TupleType]
829 830
830 831 # for Numeric arrays, display summary info
831 832 try:
832 833 import Numeric
833 834 except ImportError:
834 835 array_type = None
835 836 else:
836 837 array_type = Numeric.ArrayType.__name__
837 838
838 839 # Find all variable names and types so we can figure out column sizes
839 840 get_vars = lambda i: self.shell.user_ns[i]
840 841 type_name = lambda v: type(v).__name__
841 842 varlist = map(get_vars,varnames)
842 843 typelist = map(type_name,varlist)
843 844 # column labels and # of spaces as separator
844 845 varlabel = 'Variable'
845 846 typelabel = 'Type'
846 847 datalabel = 'Data/Info'
847 848 colsep = 3
848 849 # variable format strings
849 850 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
850 851 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
851 852 aformat = "%s: %s elems, type `%s`, %s bytes"
852 853 # find the size of the columns to format the output nicely
853 854 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
854 855 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
855 856 # table header
856 857 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
857 858 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
858 859 # and the table itself
859 860 kb = 1024
860 861 Mb = 1048576 # kb**2
861 862 for vname,var,vtype in zip(varnames,varlist,typelist):
862 863 print itpl(vformat),
863 864 if vtype in seq_types:
864 865 print len(var)
865 866 elif vtype==array_type:
866 867 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
867 868 vsize = Numeric.size(var)
868 869 vbytes = vsize*var.itemsize()
869 870 if vbytes < 100000:
870 871 print aformat % (vshape,vsize,var.typecode(),vbytes)
871 872 else:
872 873 print aformat % (vshape,vsize,var.typecode(),vbytes),
873 874 if vbytes < Mb:
874 875 print '(%s kb)' % (vbytes/kb,)
875 876 else:
876 877 print '(%s Mb)' % (vbytes/Mb,)
877 878 else:
878 879 vstr = str(var)
879 880 if len(vstr) < 50:
880 881 print vstr
881 882 else:
882 883 printpl(vfmt_short)
883 884
884 885 def magic_reset(self, parameter_s=''):
885 886 """Resets the namespace by removing all names defined by the user.
886 887
887 888 Input/Output history are left around in case you need them."""
888 889
889 890 ans = raw_input(
890 891 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
891 892 if not ans.lower() == 'y':
892 893 print 'Nothing done.'
893 894 return
894 895 user_ns = self.shell.user_ns
895 896 for i in self.magic_who_ls():
896 897 del(user_ns[i])
897 898
898 899 def magic_config(self,parameter_s=''):
899 900 """Show IPython's internal configuration."""
900 901
901 902 page('Current configuration structure:\n'+
902 903 pformat(self.shell.rc.dict()))
903 904
904 905 def magic_logstart(self,parameter_s=''):
905 906 """Start logging anywhere in a session.
906 907
907 908 %logstart [-o|-t] [log_name [log_mode]]
908 909
909 910 If no name is given, it defaults to a file named 'ipython_log.py' in your
910 911 current directory, in 'rotate' mode (see below).
911 912
912 913 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
913 914 history up to that point and then continues logging.
914 915
915 916 %logstart takes a second optional parameter: logging mode. This can be one
916 917 of (note that the modes are given unquoted):\\
917 918 append: well, that says it.\\
918 919 backup: rename (if exists) to name~ and start name.\\
919 920 global: single logfile in your home dir, appended to.\\
920 921 over : overwrite existing log.\\
921 922 rotate: create rotating logs name.1~, name.2~, etc.
922 923
923 924 Options:
924 925
925 926 -o: log also IPython's output. In this mode, all commands which
926 927 generate an Out[NN] prompt are recorded to the logfile, right after
927 928 their corresponding input line. The output lines are always
928 929 prepended with a #[Out]# marker, so that the log remains valid
929 930 Python code.
930 931
931 932 -t: put timestamps before each input line logged (these are put in
932 933 comments)."""
933 934
934 935 opts,par = self.parse_options(parameter_s,'ot')
935 936 log_output = 'o' in opts
936 937 timestamp = 't' in opts
937 938
938 939 rc = self.shell.rc
939 940 logger = self.shell.logger
940 941
941 942 # if no args are given, the defaults set in the logger constructor by
942 943 # ipytohn remain valid
943 944 if par:
944 945 try:
945 946 logfname,logmode = par.split()
946 947 except:
947 948 logfname = par
948 949 logmode = 'backup'
949 950 else:
950 951 logfname = logger.logfname
951 952 logmode = logger.logmode
952 953 # put logfname into rc struct as if it had been called on the command
953 954 # line, so it ends up saved in the log header Save it in case we need
954 955 # to restore it...
955 956 old_logfile = rc.opts.get('logfile','')
956 957 if logfname:
957 958 logfname = os.path.expanduser(logfname)
958 959 rc.opts.logfile = logfname
959 960 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
960 961 try:
961 962 started = logger.logstart(logfname,loghead,logmode,
962 963 log_output,timestamp)
963 964 except:
964 965 rc.opts.logfile = old_logfile
965 966 warn("Couldn't start log: %s" % sys.exc_info()[1])
966 967 else:
967 968 # log input history up to this point, optionally interleaving
968 969 # output if requested
969 970
970 971 if timestamp:
971 972 # disable timestamping for the previous history, since we've
972 973 # lost those already (no time machine here).
973 974 logger.timestamp = False
974 975 if log_output:
975 976 log_write = logger.log_write
976 977 input_hist = self.shell.input_hist
977 978 output_hist = self.shell.output_hist
978 979 for n in range(1,len(input_hist)-1):
979 980 log_write(input_hist[n].rstrip())
980 981 if n in output_hist:
981 982 log_write(repr(output_hist[n]),'output')
982 983 else:
983 984 logger.log_write(self.shell.input_hist[1:])
984 985 if timestamp:
985 986 # re-enable timestamping
986 987 logger.timestamp = True
987 988
988 989 print ('Activating auto-logging. '
989 990 'Current session state plus future input saved.')
990 991 logger.logstate()
991 992
992 993 def magic_logoff(self,parameter_s=''):
993 994 """Temporarily stop logging.
994 995
995 996 You must have previously started logging."""
996 997 self.shell.logger.switch_log(0)
997 998
998 999 def magic_logon(self,parameter_s=''):
999 1000 """Restart logging.
1000 1001
1001 1002 This function is for restarting logging which you've temporarily
1002 1003 stopped with %logoff. For starting logging for the first time, you
1003 1004 must use the %logstart function, which allows you to specify an
1004 1005 optional log filename."""
1005 1006
1006 1007 self.shell.logger.switch_log(1)
1007 1008
1008 1009 def magic_logstate(self,parameter_s=''):
1009 1010 """Print the status of the logging system."""
1010 1011
1011 1012 self.shell.logger.logstate()
1012 1013
1013 1014 def magic_pdb(self, parameter_s=''):
1014 1015 """Control the calling of the pdb interactive debugger.
1015 1016
1016 1017 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1017 1018 argument it works as a toggle.
1018 1019
1019 1020 When an exception is triggered, IPython can optionally call the
1020 1021 interactive pdb debugger after the traceback printout. %pdb toggles
1021 1022 this feature on and off."""
1022 1023
1023 1024 par = parameter_s.strip().lower()
1024 1025
1025 1026 if par:
1026 1027 try:
1027 1028 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1028 1029 except KeyError:
1029 1030 print ('Incorrect argument. Use on/1, off/0, '
1030 1031 'or nothing for a toggle.')
1031 1032 return
1032 1033 else:
1033 1034 # toggle
1034 1035 new_pdb = not self.shell.InteractiveTB.call_pdb
1035 1036
1036 1037 # set on the shell
1037 1038 self.shell.call_pdb = new_pdb
1038 1039 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1039 1040
1040 1041 def magic_prun(self, parameter_s ='',user_mode=1,
1041 1042 opts=None,arg_lst=None,prog_ns=None):
1042 1043
1043 1044 """Run a statement through the python code profiler.
1044 1045
1045 1046 Usage:\\
1046 1047 %prun [options] statement
1047 1048
1048 1049 The given statement (which doesn't require quote marks) is run via the
1049 1050 python profiler in a manner similar to the profile.run() function.
1050 1051 Namespaces are internally managed to work correctly; profile.run
1051 1052 cannot be used in IPython because it makes certain assumptions about
1052 1053 namespaces which do not hold under IPython.
1053 1054
1054 1055 Options:
1055 1056
1056 1057 -l <limit>: you can place restrictions on what or how much of the
1057 1058 profile gets printed. The limit value can be:
1058 1059
1059 1060 * A string: only information for function names containing this string
1060 1061 is printed.
1061 1062
1062 1063 * An integer: only these many lines are printed.
1063 1064
1064 1065 * A float (between 0 and 1): this fraction of the report is printed
1065 1066 (for example, use a limit of 0.4 to see the topmost 40% only).
1066 1067
1067 1068 You can combine several limits with repeated use of the option. For
1068 1069 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1069 1070 information about class constructors.
1070 1071
1071 1072 -r: return the pstats.Stats object generated by the profiling. This
1072 1073 object has all the information about the profile in it, and you can
1073 1074 later use it for further analysis or in other functions.
1074 1075
1075 1076 Since magic functions have a particular form of calling which prevents
1076 1077 you from writing something like:\\
1077 1078 In [1]: p = %prun -r print 4 # invalid!\\
1078 1079 you must instead use IPython's automatic variables to assign this:\\
1079 1080 In [1]: %prun -r print 4 \\
1080 1081 Out[1]: <pstats.Stats instance at 0x8222cec>\\
1081 1082 In [2]: stats = _
1082 1083
1083 1084 If you really need to assign this value via an explicit function call,
1084 1085 you can always tap directly into the true name of the magic function
1085 1086 by using the ipmagic function (which IPython automatically adds to the
1086 1087 builtins):\\
1087 1088 In [3]: stats = ipmagic('prun','-r print 4')
1088 1089
1089 1090 You can type ipmagic? for more details on ipmagic.
1090 1091
1091 1092 -s <key>: sort profile by given key. You can provide more than one key
1092 1093 by using the option several times: '-s key1 -s key2 -s key3...'. The
1093 1094 default sorting key is 'time'.
1094 1095
1095 1096 The following is copied verbatim from the profile documentation
1096 1097 referenced below:
1097 1098
1098 1099 When more than one key is provided, additional keys are used as
1099 1100 secondary criteria when the there is equality in all keys selected
1100 1101 before them.
1101 1102
1102 1103 Abbreviations can be used for any key names, as long as the
1103 1104 abbreviation is unambiguous. The following are the keys currently
1104 1105 defined:
1105 1106
1106 1107 Valid Arg Meaning\\
1107 1108 "calls" call count\\
1108 1109 "cumulative" cumulative time\\
1109 1110 "file" file name\\
1110 1111 "module" file name\\
1111 1112 "pcalls" primitive call count\\
1112 1113 "line" line number\\
1113 1114 "name" function name\\
1114 1115 "nfl" name/file/line\\
1115 1116 "stdname" standard name\\
1116 1117 "time" internal time
1117 1118
1118 1119 Note that all sorts on statistics are in descending order (placing
1119 1120 most time consuming items first), where as name, file, and line number
1120 1121 searches are in ascending order (i.e., alphabetical). The subtle
1121 1122 distinction between "nfl" and "stdname" is that the standard name is a
1122 1123 sort of the name as printed, which means that the embedded line
1123 1124 numbers get compared in an odd way. For example, lines 3, 20, and 40
1124 1125 would (if the file names were the same) appear in the string order
1125 1126 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1126 1127 line numbers. In fact, sort_stats("nfl") is the same as
1127 1128 sort_stats("name", "file", "line").
1128 1129
1129 1130 -T <filename>: save profile results as shown on screen to a text
1130 1131 file. The profile is still shown on screen.
1131 1132
1132 1133 -D <filename>: save (via dump_stats) profile statistics to given
1133 1134 filename. This data is in a format understod by the pstats module, and
1134 1135 is generated by a call to the dump_stats() method of profile
1135 1136 objects. The profile is still shown on screen.
1136 1137
1137 1138 If you want to run complete programs under the profiler's control, use
1138 1139 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1139 1140 contains profiler specific options as described here.
1140 1141
1141 1142 You can read the complete documentation for the profile module with:\\
1142 1143 In [1]: import profile; profile.help() """
1143 1144
1144 1145 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1145 1146 # protect user quote marks
1146 1147 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1147 1148
1148 1149 if user_mode: # regular user call
1149 1150 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1150 1151 list_all=1)
1151 1152 namespace = self.shell.user_ns
1152 1153 else: # called to run a program by %run -p
1153 1154 try:
1154 1155 filename = get_py_filename(arg_lst[0])
1155 1156 except IOError,msg:
1156 1157 error(msg)
1157 1158 return
1158 1159
1159 1160 arg_str = 'execfile(filename,prog_ns)'
1160 1161 namespace = locals()
1161 1162
1162 1163 opts.merge(opts_def)
1163 1164
1164 1165 prof = profile.Profile()
1165 1166 try:
1166 1167 prof = prof.runctx(arg_str,namespace,namespace)
1167 1168 sys_exit = ''
1168 1169 except SystemExit:
1169 1170 sys_exit = """*** SystemExit exception caught in code being profiled."""
1170 1171
1171 1172 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1172 1173
1173 1174 lims = opts.l
1174 1175 if lims:
1175 1176 lims = [] # rebuild lims with ints/floats/strings
1176 1177 for lim in opts.l:
1177 1178 try:
1178 1179 lims.append(int(lim))
1179 1180 except ValueError:
1180 1181 try:
1181 1182 lims.append(float(lim))
1182 1183 except ValueError:
1183 1184 lims.append(lim)
1184 1185
1185 1186 # trap output
1186 1187 sys_stdout = sys.stdout
1187 1188 stdout_trap = StringIO()
1188 1189 try:
1189 1190 sys.stdout = stdout_trap
1190 1191 stats.print_stats(*lims)
1191 1192 finally:
1192 1193 sys.stdout = sys_stdout
1193 1194 output = stdout_trap.getvalue()
1194 1195 output = output.rstrip()
1195 1196
1196 1197 page(output,screen_lines=self.shell.rc.screen_length)
1197 1198 print sys_exit,
1198 1199
1199 1200 dump_file = opts.D[0]
1200 1201 text_file = opts.T[0]
1201 1202 if dump_file:
1202 1203 prof.dump_stats(dump_file)
1203 1204 print '\n*** Profile stats marshalled to file',\
1204 1205 `dump_file`+'.',sys_exit
1205 1206 if text_file:
1206 1207 file(text_file,'w').write(output)
1207 1208 print '\n*** Profile printout saved to text file',\
1208 1209 `text_file`+'.',sys_exit
1209 1210
1210 1211 if opts.has_key('r'):
1211 1212 return stats
1212 1213 else:
1213 1214 return None
1214 1215
1215 1216 def magic_run(self, parameter_s ='',runner=None):
1216 1217 """Run the named file inside IPython as a program.
1217 1218
1218 1219 Usage:\\
1219 1220 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1220 1221
1221 1222 Parameters after the filename are passed as command-line arguments to
1222 1223 the program (put in sys.argv). Then, control returns to IPython's
1223 1224 prompt.
1224 1225
1225 1226 This is similar to running at a system prompt:\\
1226 1227 $ python file args\\
1227 1228 but with the advantage of giving you IPython's tracebacks, and of
1228 1229 loading all variables into your interactive namespace for further use
1229 1230 (unless -p is used, see below).
1230 1231
1231 1232 The file is executed in a namespace initially consisting only of
1232 1233 __name__=='__main__' and sys.argv constructed as indicated. It thus
1233 1234 sees its environment as if it were being run as a stand-alone
1234 1235 program. But after execution, the IPython interactive namespace gets
1235 1236 updated with all variables defined in the program (except for __name__
1236 1237 and sys.argv). This allows for very convenient loading of code for
1237 1238 interactive work, while giving each program a 'clean sheet' to run in.
1238 1239
1239 1240 Options:
1240 1241
1241 1242 -n: __name__ is NOT set to '__main__', but to the running file's name
1242 1243 without extension (as python does under import). This allows running
1243 1244 scripts and reloading the definitions in them without calling code
1244 1245 protected by an ' if __name__ == "__main__" ' clause.
1245 1246
1246 1247 -i: run the file in IPython's namespace instead of an empty one. This
1247 1248 is useful if you are experimenting with code written in a text editor
1248 1249 which depends on variables defined interactively.
1249 1250
1250 1251 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1251 1252 being run. This is particularly useful if IPython is being used to
1252 1253 run unittests, which always exit with a sys.exit() call. In such
1253 1254 cases you are interested in the output of the test results, not in
1254 1255 seeing a traceback of the unittest module.
1255 1256
1256 1257 -t: print timing information at the end of the run. IPython will give
1257 1258 you an estimated CPU time consumption for your script, which under
1258 1259 Unix uses the resource module to avoid the wraparound problems of
1259 1260 time.clock(). Under Unix, an estimate of time spent on system tasks
1260 1261 is also given (for Windows platforms this is reported as 0.0).
1261 1262
1262 1263 If -t is given, an additional -N<N> option can be given, where <N>
1263 1264 must be an integer indicating how many times you want the script to
1264 1265 run. The final timing report will include total and per run results.
1265 1266
1266 1267 For example (testing the script uniq_stable.py):
1267 1268
1268 1269 In [1]: run -t uniq_stable
1269 1270
1270 1271 IPython CPU timings (estimated):\\
1271 1272 User : 0.19597 s.\\
1272 1273 System: 0.0 s.\\
1273 1274
1274 1275 In [2]: run -t -N5 uniq_stable
1275 1276
1276 1277 IPython CPU timings (estimated):\\
1277 1278 Total runs performed: 5\\
1278 1279 Times : Total Per run\\
1279 1280 User : 0.910862 s, 0.1821724 s.\\
1280 1281 System: 0.0 s, 0.0 s.
1281 1282
1282 1283 -d: run your program under the control of pdb, the Python debugger.
1283 1284 This allows you to execute your program step by step, watch variables,
1284 1285 etc. Internally, what IPython does is similar to calling:
1285 1286
1286 1287 pdb.run('execfile("YOURFILENAME")')
1287 1288
1288 1289 with a breakpoint set on line 1 of your file. You can change the line
1289 1290 number for this automatic breakpoint to be <N> by using the -bN option
1290 1291 (where N must be an integer). For example:
1291 1292
1292 1293 %run -d -b40 myscript
1293 1294
1294 1295 will set the first breakpoint at line 40 in myscript.py. Note that
1295 1296 the first breakpoint must be set on a line which actually does
1296 1297 something (not a comment or docstring) for it to stop execution.
1297 1298
1298 1299 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1299 1300 first enter 'c' (without qoutes) to start execution up to the first
1300 1301 breakpoint.
1301 1302
1302 1303 Entering 'help' gives information about the use of the debugger. You
1303 1304 can easily see pdb's full documentation with "import pdb;pdb.help()"
1304 1305 at a prompt.
1305 1306
1306 1307 -p: run program under the control of the Python profiler module (which
1307 1308 prints a detailed report of execution times, function calls, etc).
1308 1309
1309 1310 You can pass other options after -p which affect the behavior of the
1310 1311 profiler itself. See the docs for %prun for details.
1311 1312
1312 1313 In this mode, the program's variables do NOT propagate back to the
1313 1314 IPython interactive namespace (because they remain in the namespace
1314 1315 where the profiler executes them).
1315 1316
1316 1317 Internally this triggers a call to %prun, see its documentation for
1317 1318 details on the options available specifically for profiling."""
1318 1319
1319 1320 # get arguments and set sys.argv for program to be run.
1320 1321 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1321 1322 mode='list',list_all=1)
1322 1323
1323 1324 try:
1324 1325 filename = get_py_filename(arg_lst[0])
1325 1326 except IndexError:
1326 1327 warn('you must provide at least a filename.')
1327 1328 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1328 1329 return
1329 1330 except IOError,msg:
1330 1331 error(msg)
1331 1332 return
1332 1333
1333 1334 # Control the response to exit() calls made by the script being run
1334 1335 exit_ignore = opts.has_key('e')
1335 1336
1336 1337 # Make sure that the running script gets a proper sys.argv as if it
1337 1338 # were run from a system shell.
1338 1339 save_argv = sys.argv # save it for later restoring
1339 1340 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1340 1341
1341 1342 if opts.has_key('i'):
1342 1343 prog_ns = self.shell.user_ns
1343 1344 __name__save = self.shell.user_ns['__name__']
1344 1345 prog_ns['__name__'] = '__main__'
1345 1346 else:
1346 1347 if opts.has_key('n'):
1347 1348 name = os.path.splitext(os.path.basename(filename))[0]
1348 1349 else:
1349 1350 name = '__main__'
1350 1351 prog_ns = {'__name__':name}
1351 1352
1352 1353 # pickle fix. See iplib for an explanation
1353 1354 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1354 1355
1355 1356 stats = None
1356 1357 try:
1357 1358 if opts.has_key('p'):
1358 1359 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1359 1360 else:
1360 1361 if opts.has_key('d'):
1361 1362 deb = Debugger.Pdb(self.shell.rc.colors)
1362 1363 # reset Breakpoint state, which is moronically kept
1363 1364 # in a class
1364 1365 bdb.Breakpoint.next = 1
1365 1366 bdb.Breakpoint.bplist = {}
1366 1367 bdb.Breakpoint.bpbynumber = [None]
1367 1368 # Set an initial breakpoint to stop execution
1368 1369 maxtries = 10
1369 1370 bp = int(opts.get('b',[1])[0])
1370 1371 checkline = deb.checkline(filename,bp)
1371 1372 if not checkline:
1372 1373 for bp in range(bp+1,bp+maxtries+1):
1373 1374 if deb.checkline(filename,bp):
1374 1375 break
1375 1376 else:
1376 1377 msg = ("\nI failed to find a valid line to set "
1377 1378 "a breakpoint\n"
1378 1379 "after trying up to line: %s.\n"
1379 1380 "Please set a valid breakpoint manually "
1380 1381 "with the -b option." % bp)
1381 1382 error(msg)
1382 1383 return
1383 1384 # if we find a good linenumber, set the breakpoint
1384 1385 deb.do_break('%s:%s' % (filename,bp))
1385 1386 # Start file run
1386 1387 print "NOTE: Enter 'c' at the",
1387 1388 print "ipdb> prompt to start your script."
1388 1389 try:
1389 1390 deb.run('execfile("%s")' % filename,prog_ns)
1390 1391 except:
1391 1392 etype, value, tb = sys.exc_info()
1392 1393 # Skip three frames in the traceback: the %run one,
1393 1394 # one inside bdb.py, and the command-line typed by the
1394 1395 # user (run by exec in pdb itself).
1395 1396 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1396 1397 else:
1397 1398 if runner is None:
1398 1399 runner = self.shell.safe_execfile
1399 1400 if opts.has_key('t'):
1400 1401 try:
1401 1402 nruns = int(opts['N'][0])
1402 1403 if nruns < 1:
1403 1404 error('Number of runs must be >=1')
1404 1405 return
1405 1406 except (KeyError):
1406 1407 nruns = 1
1407 1408 if nruns == 1:
1408 1409 t0 = clock2()
1409 1410 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1410 1411 t1 = clock2()
1411 1412 t_usr = t1[0]-t0[0]
1412 1413 t_sys = t1[1]-t1[1]
1413 1414 print "\nIPython CPU timings (estimated):"
1414 1415 print " User : %10s s." % t_usr
1415 1416 print " System: %10s s." % t_sys
1416 1417 else:
1417 1418 runs = range(nruns)
1418 1419 t0 = clock2()
1419 1420 for nr in runs:
1420 1421 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1421 1422 t1 = clock2()
1422 1423 t_usr = t1[0]-t0[0]
1423 1424 t_sys = t1[1]-t1[1]
1424 1425 print "\nIPython CPU timings (estimated):"
1425 1426 print "Total runs performed:",nruns
1426 1427 print " Times : %10s %10s" % ('Total','Per run')
1427 1428 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1428 1429 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1429 1430
1430 1431 else:
1431 1432 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1432 1433 if opts.has_key('i'):
1433 1434 self.shell.user_ns['__name__'] = __name__save
1434 1435 else:
1435 1436 # update IPython interactive namespace
1436 1437 del prog_ns['__name__']
1437 1438 self.shell.user_ns.update(prog_ns)
1438 1439 finally:
1439 1440 sys.argv = save_argv
1440 1441 return stats
1441 1442
1442 1443 def magic_runlog(self, parameter_s =''):
1443 1444 """Run files as logs.
1444 1445
1445 1446 Usage:\\
1446 1447 %runlog file1 file2 ...
1447 1448
1448 1449 Run the named files (treating them as log files) in sequence inside
1449 1450 the interpreter, and return to the prompt. This is much slower than
1450 1451 %run because each line is executed in a try/except block, but it
1451 1452 allows running files with syntax errors in them.
1452 1453
1453 1454 Normally IPython will guess when a file is one of its own logfiles, so
1454 1455 you can typically use %run even for logs. This shorthand allows you to
1455 1456 force any file to be treated as a log file."""
1456 1457
1457 1458 for f in parameter_s.split():
1458 1459 self.shell.safe_execfile(f,self.shell.user_ns,
1459 1460 self.shell.user_ns,islog=1)
1460 1461
1461 1462 def magic_time(self,parameter_s = ''):
1462 1463 """Time execution of a Python statement or expression.
1463 1464
1464 1465 The CPU and wall clock times are printed, and the value of the
1465 1466 expression (if any) is returned. Note that under Win32, system time
1466 1467 is always reported as 0, since it can not be measured.
1467 1468
1468 1469 This function provides very basic timing functionality. In Python
1469 1470 2.3, the timeit module offers more control and sophistication, but for
1470 1471 now IPython supports Python 2.2, so we can not rely on timeit being
1471 1472 present.
1472 1473
1473 1474 Some examples:
1474 1475
1475 1476 In [1]: time 2**128
1476 1477 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1477 1478 Wall time: 0.00
1478 1479 Out[1]: 340282366920938463463374607431768211456L
1479 1480
1480 1481 In [2]: n = 1000000
1481 1482
1482 1483 In [3]: time sum(range(n))
1483 1484 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1484 1485 Wall time: 1.37
1485 1486 Out[3]: 499999500000L
1486 1487
1487 1488 In [4]: time print 'hello world'
1488 1489 hello world
1489 1490 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1490 1491 Wall time: 0.00
1491 1492 """
1492 1493
1493 1494 # fail immediately if the given expression can't be compiled
1494 1495 try:
1495 1496 mode = 'eval'
1496 1497 code = compile(parameter_s,'<timed eval>',mode)
1497 1498 except SyntaxError:
1498 1499 mode = 'exec'
1499 1500 code = compile(parameter_s,'<timed exec>',mode)
1500 1501 # skew measurement as little as possible
1501 1502 glob = self.shell.user_ns
1502 1503 clk = clock2
1503 1504 wtime = time.time
1504 1505 # time execution
1505 1506 wall_st = wtime()
1506 1507 if mode=='eval':
1507 1508 st = clk()
1508 1509 out = eval(code,glob)
1509 1510 end = clk()
1510 1511 else:
1511 1512 st = clk()
1512 1513 exec code in glob
1513 1514 end = clk()
1514 1515 out = None
1515 1516 wall_end = wtime()
1516 1517 # Compute actual times and report
1517 1518 wall_time = wall_end-wall_st
1518 1519 cpu_user = end[0]-st[0]
1519 1520 cpu_sys = end[1]-st[1]
1520 1521 cpu_tot = cpu_user+cpu_sys
1521 1522 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1522 1523 (cpu_user,cpu_sys,cpu_tot)
1523 1524 print "Wall time: %.2f" % wall_time
1524 1525 return out
1525 1526
1526 1527 def magic_macro(self,parameter_s = ''):
1527 1528 """Define a set of input lines as a macro for future re-execution.
1528 1529
1529 1530 Usage:\\
1530 1531 %macro name n1:n2 n3:n4 ... n5 .. n6 ...
1531 1532
1532 1533 This will define a global variable called `name` which is a string
1533 1534 made of joining the slices and lines you specify (n1,n2,... numbers
1534 1535 above) from your input history into a single string. This variable
1535 1536 acts like an automatic function which re-executes those lines as if
1536 1537 you had typed them. You just type 'name' at the prompt and the code
1537 1538 executes.
1538 1539
1539 1540 Note that the slices use the standard Python slicing notation (5:8
1540 1541 means include lines numbered 5,6,7).
1541 1542
1542 1543 For example, if your history contains (%hist prints it):
1543 1544
1544 1545 44: x=1\\
1545 1546 45: y=3\\
1546 1547 46: z=x+y\\
1547 1548 47: print x\\
1548 1549 48: a=5\\
1549 1550 49: print 'x',x,'y',y\\
1550 1551
1551 1552 you can create a macro with lines 44 through 47 (included) and line 49
1552 1553 called my_macro with:
1553 1554
1554 1555 In [51]: %macro my_macro 44:48 49
1555 1556
1556 1557 Now, typing `my_macro` (without quotes) will re-execute all this code
1557 1558 in one pass.
1558 1559
1559 1560 You don't need to give the line-numbers in order, and any given line
1560 1561 number can appear multiple times. You can assemble macros with any
1561 1562 lines from your input history in any order.
1562 1563
1563 1564 The macro is a simple object which holds its value in an attribute,
1564 1565 but IPython's display system checks for macros and executes them as
1565 1566 code instead of printing them when you type their name.
1566 1567
1567 1568 You can view a macro's contents by explicitly printing it with:
1568 1569
1569 1570 'print macro_name'.
1570 1571
1571 1572 For one-off cases which DON'T contain magic function calls in them you
1572 1573 can obtain similar results by explicitly executing slices from your
1573 1574 input history with:
1574 1575
1575 1576 In [60]: exec In[44:48]+In[49]"""
1576 1577
1577 1578 args = parameter_s.split()
1578 1579 name,ranges = args[0], args[1:]
1579 1580 #print 'rng',ranges # dbg
1580 1581 lines = self.extract_input_slices(ranges)
1581 1582 macro = Macro(lines)
1582 1583 self.shell.user_ns.update({name:macro})
1583 1584 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1584 1585 print 'Macro contents:'
1585 1586 print macro
1586 1587
1587 1588 def magic_save(self,parameter_s = ''):
1588 1589 """Save a set of lines to a given filename.
1589 1590
1590 1591 Usage:\\
1591 1592 %save filename n1:n2 n3:n4 ... n5 .. n6 ...
1592 1593
1593 1594 This function uses the same syntax as %macro for line extraction, but
1594 1595 instead of creating a macro it saves the resulting string to the
1595 1596 filename you specify.
1596 1597
1597 1598 It adds a '.py' extension to the file if you don't do so yourself, and
1598 1599 it asks for confirmation before overwriting existing files."""
1599 1600
1600 1601 args = parameter_s.split()
1601 1602 fname,ranges = args[0], args[1:]
1602 1603 if not fname.endswith('.py'):
1603 1604 fname += '.py'
1604 1605 if os.path.isfile(fname):
1605 1606 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1606 1607 if ans.lower() not in ['y','yes']:
1607 1608 print 'Operation cancelled.'
1608 1609 return
1609 1610 cmds = ''.join(self.extract_input_slices(ranges))
1610 1611 f = file(fname,'w')
1611 1612 f.write(cmds)
1612 1613 f.close()
1613 1614 print 'The following commands were written to file `%s`:' % fname
1614 1615 print cmds
1615 1616
1616 1617 def magic_ed(self,parameter_s = ''):
1617 1618 """Alias to %edit."""
1618 1619 return self.magic_edit(parameter_s)
1619 1620
1620 1621 def magic_edit(self,parameter_s = '',last_call=['','']):
1621 1622 """Bring up an editor and execute the resulting code.
1622 1623
1623 1624 Usage:
1624 1625 %edit [options] [args]
1625 1626
1626 1627 %edit runs IPython's editor hook. The default version of this hook is
1627 1628 set to call the __IPYTHON__.rc.editor command. This is read from your
1628 1629 environment variable $EDITOR. If this isn't found, it will default to
1629 1630 vi under Linux/Unix and to notepad under Windows. See the end of this
1630 1631 docstring for how to change the editor hook.
1631 1632
1632 1633 You can also set the value of this editor via the command line option
1633 1634 '-editor' or in your ipythonrc file. This is useful if you wish to use
1634 1635 specifically for IPython an editor different from your typical default
1635 1636 (and for Windows users who typically don't set environment variables).
1636 1637
1637 1638 This command allows you to conveniently edit multi-line code right in
1638 1639 your IPython session.
1639 1640
1640 1641 If called without arguments, %edit opens up an empty editor with a
1641 1642 temporary file and will execute the contents of this file when you
1642 1643 close it (don't forget to save it!).
1643 1644
1644 1645 Options:
1645 1646
1646 1647 -p: this will call the editor with the same data as the previous time
1647 1648 it was used, regardless of how long ago (in your current session) it
1648 1649 was.
1649 1650
1650 1651 -x: do not execute the edited code immediately upon exit. This is
1651 1652 mainly useful if you are editing programs which need to be called with
1652 1653 command line arguments, which you can then do using %run.
1653 1654
1654 1655 Arguments:
1655 1656
1656 1657 If arguments are given, the following possibilites exist:
1657 1658
1658 1659 - The arguments are numbers or pairs of colon-separated numbers (like
1659 1660 1 4:8 9). These are interpreted as lines of previous input to be
1660 1661 loaded into the editor. The syntax is the same of the %macro command.
1661 1662
1662 1663 - If the argument doesn't start with a number, it is evaluated as a
1663 1664 variable and its contents loaded into the editor. You can thus edit
1664 1665 any string which contains python code (including the result of
1665 1666 previous edits).
1666 1667
1667 1668 - If the argument is the name of an object (other than a string),
1668 1669 IPython will try to locate the file where it was defined and open the
1669 1670 editor at the point where it is defined. You can use `%edit function`
1670 1671 to load an editor exactly at the point where 'function' is defined,
1671 1672 edit it and have the file be executed automatically.
1672 1673
1673 1674 Note: opening at an exact line is only supported under Unix, and some
1674 1675 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1675 1676 '+NUMBER' parameter necessary for this feature. Good editors like
1676 1677 (X)Emacs, vi, jed, pico and joe all do.
1677 1678
1678 1679 - If the argument is not found as a variable, IPython will look for a
1679 1680 file with that name (adding .py if necessary) and load it into the
1680 1681 editor. It will execute its contents with execfile() when you exit,
1681 1682 loading any code in the file into your interactive namespace.
1682 1683
1683 1684 After executing your code, %edit will return as output the code you
1684 1685 typed in the editor (except when it was an existing file). This way
1685 1686 you can reload the code in further invocations of %edit as a variable,
1686 1687 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1687 1688 the output.
1688 1689
1689 1690 Note that %edit is also available through the alias %ed.
1690 1691
1691 1692 This is an example of creating a simple function inside the editor and
1692 1693 then modifying it. First, start up the editor:
1693 1694
1694 1695 In [1]: ed\\
1695 1696 Editing... done. Executing edited code...\\
1696 1697 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1697 1698
1698 1699 We can then call the function foo():
1699 1700
1700 1701 In [2]: foo()\\
1701 1702 foo() was defined in an editing session
1702 1703
1703 1704 Now we edit foo. IPython automatically loads the editor with the
1704 1705 (temporary) file where foo() was previously defined:
1705 1706
1706 1707 In [3]: ed foo\\
1707 1708 Editing... done. Executing edited code...
1708 1709
1709 1710 And if we call foo() again we get the modified version:
1710 1711
1711 1712 In [4]: foo()\\
1712 1713 foo() has now been changed!
1713 1714
1714 1715 Here is an example of how to edit a code snippet successive
1715 1716 times. First we call the editor:
1716 1717
1717 1718 In [8]: ed\\
1718 1719 Editing... done. Executing edited code...\\
1719 1720 hello\\
1720 1721 Out[8]: "print 'hello'\\n"
1721 1722
1722 1723 Now we call it again with the previous output (stored in _):
1723 1724
1724 1725 In [9]: ed _\\
1725 1726 Editing... done. Executing edited code...\\
1726 1727 hello world\\
1727 1728 Out[9]: "print 'hello world'\\n"
1728 1729
1729 1730 Now we call it with the output #8 (stored in _8, also as Out[8]):
1730 1731
1731 1732 In [10]: ed _8\\
1732 1733 Editing... done. Executing edited code...\\
1733 1734 hello again\\
1734 1735 Out[10]: "print 'hello again'\\n"
1735 1736
1736 1737
1737 1738 Changing the default editor hook:
1738 1739
1739 1740 If you wish to write your own editor hook, you can put it in a
1740 1741 configuration file which you load at startup time. The default hook
1741 1742 is defined in the IPython.hooks module, and you can use that as a
1742 1743 starting example for further modifications. That file also has
1743 1744 general instructions on how to set a new hook for use once you've
1744 1745 defined it."""
1745 1746
1746 1747 # FIXME: This function has become a convoluted mess. It needs a
1747 1748 # ground-up rewrite with clean, simple logic.
1748 1749
1749 1750 def make_filename(arg):
1750 1751 "Make a filename from the given args"
1751 1752 try:
1752 1753 filename = get_py_filename(arg)
1753 1754 except IOError:
1754 1755 if args.endswith('.py'):
1755 1756 filename = arg
1756 1757 else:
1757 1758 filename = None
1758 1759 return filename
1759 1760
1760 1761 # custom exceptions
1761 1762 class DataIsObject(Exception): pass
1762 1763
1763 1764 opts,args = self.parse_options(parameter_s,'px')
1764 1765
1765 1766 # Default line number value
1766 1767 lineno = None
1767 1768 if opts.has_key('p'):
1768 1769 args = '_%s' % last_call[0]
1769 1770 if not self.shell.user_ns.has_key(args):
1770 1771 args = last_call[1]
1771 1772
1772 1773 # use last_call to remember the state of the previous call, but don't
1773 1774 # let it be clobbered by successive '-p' calls.
1774 1775 try:
1775 1776 last_call[0] = self.shell.outputcache.prompt_count
1776 1777 if not opts.has_key('p'):
1777 1778 last_call[1] = parameter_s
1778 1779 except:
1779 1780 pass
1780 1781
1781 1782 # by default this is done with temp files, except when the given
1782 1783 # arg is a filename
1783 1784 use_temp = 1
1784 1785
1785 1786 if re.match(r'\d',args):
1786 1787 # Mode where user specifies ranges of lines, like in %macro.
1787 1788 # This means that you can't edit files whose names begin with
1788 1789 # numbers this way. Tough.
1789 1790 ranges = args.split()
1790 1791 data = ''.join(self.extract_input_slices(ranges))
1791 1792 elif args.endswith('.py'):
1792 1793 filename = make_filename(args)
1793 1794 data = ''
1794 1795 use_temp = 0
1795 1796 elif args:
1796 1797 try:
1797 1798 # Load the parameter given as a variable. If not a string,
1798 1799 # process it as an object instead (below)
1799 1800
1800 1801 #print '*** args',args,'type',type(args) # dbg
1801 1802 data = eval(args,self.shell.user_ns)
1802 1803 if not type(data) in StringTypes:
1803 1804 raise DataIsObject
1804 1805 except (NameError,SyntaxError):
1805 1806 # given argument is not a variable, try as a filename
1806 1807 filename = make_filename(args)
1807 1808 if filename is None:
1808 1809 warn("Argument given (%s) can't be found as a variable "
1809 1810 "or as a filename." % args)
1810 1811 return
1811 1812 data = ''
1812 1813 use_temp = 0
1813 1814 except DataIsObject:
1814 1815 # For objects, try to edit the file where they are defined
1815 1816 try:
1816 1817 filename = inspect.getabsfile(data)
1817 1818 datafile = 1
1818 1819 except TypeError:
1819 1820 filename = make_filename(args)
1820 1821 datafile = 1
1821 1822 warn('Could not find file where `%s` is defined.\n'
1822 1823 'Opening a file named `%s`' % (args,filename))
1823 1824 # Now, make sure we can actually read the source (if it was in
1824 1825 # a temp file it's gone by now).
1825 1826 if datafile:
1826 1827 try:
1827 1828 lineno = inspect.getsourcelines(data)[1]
1828 1829 except IOError:
1829 1830 filename = make_filename(args)
1830 1831 if filename is None:
1831 1832 warn('The file `%s` where `%s` was defined cannot '
1832 1833 'be read.' % (filename,data))
1833 1834 return
1834 1835 use_temp = 0
1835 1836 else:
1836 1837 data = ''
1837 1838
1838 1839 if use_temp:
1839 1840 filename = tempfile.mktemp('.py')
1840 1841 self.shell.tempfiles.append(filename)
1841 1842
1842 1843 if data and use_temp:
1843 1844 tmp_file = open(filename,'w')
1844 1845 tmp_file.write(data)
1845 1846 tmp_file.close()
1846 1847
1847 1848 # do actual editing here
1848 1849 print 'Editing...',
1849 1850 sys.stdout.flush()
1850 1851 self.shell.hooks.editor(filename,lineno)
1851 1852 if opts.has_key('x'): # -x prevents actual execution
1852 1853 print
1853 1854 else:
1854 1855 print 'done. Executing edited code...'
1855 1856 try:
1856 1857 self.shell.safe_execfile(filename,self.shell.user_ns)
1857 1858 except IOError,msg:
1858 1859 if msg.filename == filename:
1859 1860 warn('File not found. Did you forget to save?')
1860 1861 return
1861 1862 else:
1862 1863 self.shell.showtraceback()
1863 1864 except:
1864 1865 self.shell.showtraceback()
1865 1866 if use_temp:
1866 1867 contents = open(filename).read()
1867 1868 return contents
1868 1869
1869 1870 def magic_xmode(self,parameter_s = ''):
1870 1871 """Switch modes for the exception handlers.
1871 1872
1872 1873 Valid modes: Plain, Context and Verbose.
1873 1874
1874 1875 If called without arguments, acts as a toggle."""
1875 1876
1876 1877 def xmode_switch_err(name):
1877 1878 warn('Error changing %s exception modes.\n%s' %
1878 1879 (name,sys.exc_info()[1]))
1879 1880
1880 1881 shell = self.shell
1881 1882 new_mode = parameter_s.strip().capitalize()
1882 1883 try:
1883 1884 shell.InteractiveTB.set_mode(mode=new_mode)
1884 1885 print 'Exception reporting mode:',shell.InteractiveTB.mode
1885 1886 except:
1886 1887 xmode_switch_err('user')
1887 1888
1888 1889 # threaded shells use a special handler in sys.excepthook
1889 1890 if shell.isthreaded:
1890 1891 try:
1891 1892 shell.sys_excepthook.set_mode(mode=new_mode)
1892 1893 except:
1893 1894 xmode_switch_err('threaded')
1894 1895
1895 1896 def magic_colors(self,parameter_s = ''):
1896 1897 """Switch color scheme for prompts, info system and exception handlers.
1897 1898
1898 1899 Currently implemented schemes: NoColor, Linux, LightBG.
1899 1900
1900 1901 Color scheme names are not case-sensitive."""
1901 1902
1902 1903 def color_switch_err(name):
1903 1904 warn('Error changing %s color schemes.\n%s' %
1904 1905 (name,sys.exc_info()[1]))
1905 1906
1906 1907
1907 1908 new_scheme = parameter_s.strip()
1908 1909 if not new_scheme:
1909 1910 print 'You must specify a color scheme.'
1910 1911 return
1911 1912 # Under Windows, check for Gary Bishop's readline, which is necessary
1912 1913 # for ANSI coloring
1913 1914 if os.name in ['nt','dos']:
1914 1915 try:
1915 1916 import readline
1916 1917 except ImportError:
1917 1918 has_readline = 0
1918 1919 else:
1919 1920 try:
1920 1921 readline.GetOutputFile()
1921 1922 except AttributeError:
1922 1923 has_readline = 0
1923 1924 else:
1924 1925 has_readline = 1
1925 1926 if not has_readline:
1926 1927 msg = """\
1927 1928 Proper color support under MS Windows requires Gary Bishop's readline library.
1928 1929 You can find it at:
1929 1930 http://sourceforge.net/projects/uncpythontools
1930 1931 Gary's readline needs the ctypes module, from:
1931 1932 http://starship.python.net/crew/theller/ctypes
1932 1933
1933 1934 Defaulting color scheme to 'NoColor'"""
1934 1935 new_scheme = 'NoColor'
1935 1936 warn(msg)
1936 1937 # local shortcut
1937 1938 shell = self.shell
1938 1939
1939 1940 # Set prompt colors
1940 1941 try:
1941 1942 shell.outputcache.set_colors(new_scheme)
1942 1943 except:
1943 1944 color_switch_err('prompt')
1944 1945 else:
1945 1946 shell.rc.colors = \
1946 1947 shell.outputcache.color_table.active_scheme_name
1947 1948 # Set exception colors
1948 1949 try:
1949 1950 shell.InteractiveTB.set_colors(scheme = new_scheme)
1950 1951 shell.SyntaxTB.set_colors(scheme = new_scheme)
1951 1952 except:
1952 1953 color_switch_err('exception')
1953 1954
1954 1955 # threaded shells use a verbose traceback in sys.excepthook
1955 1956 if shell.isthreaded:
1956 1957 try:
1957 1958 shell.sys_excepthook.set_colors(scheme=new_scheme)
1958 1959 except:
1959 1960 color_switch_err('system exception handler')
1960 1961
1961 1962 # Set info (for 'object?') colors
1962 1963 if shell.rc.color_info:
1963 1964 try:
1964 1965 shell.inspector.set_active_scheme(new_scheme)
1965 1966 except:
1966 1967 color_switch_err('object inspector')
1967 1968 else:
1968 1969 shell.inspector.set_active_scheme('NoColor')
1969 1970
1970 1971 def magic_color_info(self,parameter_s = ''):
1971 1972 """Toggle color_info.
1972 1973
1973 1974 The color_info configuration parameter controls whether colors are
1974 1975 used for displaying object details (by things like %psource, %pfile or
1975 1976 the '?' system). This function toggles this value with each call.
1976 1977
1977 1978 Note that unless you have a fairly recent pager (less works better
1978 1979 than more) in your system, using colored object information displays
1979 1980 will not work properly. Test it and see."""
1980 1981
1981 1982 self.shell.rc.color_info = 1 - self.shell.rc.color_info
1982 1983 self.magic_colors(self.shell.rc.colors)
1983 1984 print 'Object introspection functions have now coloring:',
1984 1985 print ['OFF','ON'][self.shell.rc.color_info]
1985 1986
1986 1987 def magic_Pprint(self, parameter_s=''):
1987 1988 """Toggle pretty printing on/off."""
1988 1989
1989 1990 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
1990 1991 print 'Pretty printing has been turned', \
1991 1992 ['OFF','ON'][self.shell.outputcache.Pprint]
1992 1993
1993 1994 def magic_exit(self, parameter_s=''):
1994 1995 """Exit IPython, confirming if configured to do so.
1995 1996
1996 1997 You can configure whether IPython asks for confirmation upon exit by
1997 1998 setting the confirm_exit flag in the ipythonrc file."""
1998 1999
1999 2000 self.shell.exit()
2000 2001
2001 2002 def magic_quit(self, parameter_s=''):
2002 2003 """Exit IPython, confirming if configured to do so (like %exit)"""
2003 2004
2004 2005 self.shell.exit()
2005 2006
2006 2007 def magic_Exit(self, parameter_s=''):
2007 2008 """Exit IPython without confirmation."""
2008 2009
2009 2010 self.shell.exit_now = True
2010 2011
2011 2012 def magic_Quit(self, parameter_s=''):
2012 2013 """Exit IPython without confirmation (like %Exit)."""
2013 2014
2014 2015 self.shell.exit_now = True
2015 2016
2016 2017 #......................................................................
2017 2018 # Functions to implement unix shell-type things
2018 2019
2019 2020 def magic_alias(self, parameter_s = ''):
2020 2021 """Define an alias for a system command.
2021 2022
2022 2023 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2023 2024
2024 2025 Then, typing 'alias_name params' will execute the system command 'cmd
2025 2026 params' (from your underlying operating system).
2026 2027
2027 2028 Aliases have lower precedence than magic functions and Python normal
2028 2029 variables, so if 'foo' is both a Python variable and an alias, the
2029 2030 alias can not be executed until 'del foo' removes the Python variable.
2030 2031
2031 2032 You can use the %l specifier in an alias definition to represent the
2032 2033 whole line when the alias is called. For example:
2033 2034
2034 2035 In [2]: alias all echo "Input in brackets: <%l>"\\
2035 2036 In [3]: all hello world\\
2036 2037 Input in brackets: <hello world>
2037 2038
2038 2039 You can also define aliases with parameters using %s specifiers (one
2039 2040 per parameter):
2040 2041
2041 2042 In [1]: alias parts echo first %s second %s\\
2042 2043 In [2]: %parts A B\\
2043 2044 first A second B\\
2044 2045 In [3]: %parts A\\
2045 2046 Incorrect number of arguments: 2 expected.\\
2046 2047 parts is an alias to: 'echo first %s second %s'
2047 2048
2048 2049 Note that %l and %s are mutually exclusive. You can only use one or
2049 2050 the other in your aliases.
2050 2051
2051 2052 Aliases expand Python variables just like system calls using ! or !!
2052 2053 do: all expressions prefixed with '$' get expanded. For details of
2053 2054 the semantic rules, see PEP-215:
2054 2055 http://www.python.org/peps/pep-0215.html. This is the library used by
2055 2056 IPython for variable expansion. If you want to access a true shell
2056 2057 variable, an extra $ is necessary to prevent its expansion by IPython:
2057 2058
2058 2059 In [6]: alias show echo\\
2059 2060 In [7]: PATH='A Python string'\\
2060 2061 In [8]: show $PATH\\
2061 2062 A Python string\\
2062 2063 In [9]: show $$PATH\\
2063 2064 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2064 2065
2065 2066 You can use the alias facility to acess all of $PATH. See the %rehash
2066 2067 and %rehashx functions, which automatically create aliases for the
2067 2068 contents of your $PATH.
2068 2069
2069 2070 If called with no parameters, %alias prints the current alias table."""
2070 2071
2071 2072 par = parameter_s.strip()
2072 2073 if not par:
2073 2074 if self.shell.rc.automagic:
2074 2075 prechar = ''
2075 2076 else:
2076 2077 prechar = self.shell.ESC_MAGIC
2077 2078 print 'Alias\t\tSystem Command\n'+'-'*30
2078 2079 atab = self.shell.alias_table
2079 2080 aliases = atab.keys()
2080 2081 aliases.sort()
2081 2082 for alias in aliases:
2082 2083 print prechar+alias+'\t\t'+atab[alias][1]
2083 2084 print '-'*30+'\nTotal number of aliases:',len(aliases)
2084 2085 return
2085 2086 try:
2086 2087 alias,cmd = par.split(None,1)
2087 2088 except:
2088 2089 print OInspect.getdoc(self.magic_alias)
2089 2090 else:
2090 2091 nargs = cmd.count('%s')
2091 2092 if nargs>0 and cmd.find('%l')>=0:
2092 2093 error('The %s and %l specifiers are mutually exclusive '
2093 2094 'in alias definitions.')
2094 2095 else: # all looks OK
2095 2096 self.shell.alias_table[alias] = (nargs,cmd)
2096 2097 self.shell.alias_table_validate(verbose=1)
2097 2098 # end magic_alias
2098 2099
2099 2100 def magic_unalias(self, parameter_s = ''):
2100 2101 """Remove an alias"""
2101 2102
2102 2103 aname = parameter_s.strip()
2103 2104 if aname in self.shell.alias_table:
2104 2105 del self.shell.alias_table[aname]
2105 2106
2106 2107 def magic_rehash(self, parameter_s = ''):
2107 2108 """Update the alias table with all entries in $PATH.
2108 2109
2109 2110 This version does no checks on execute permissions or whether the
2110 2111 contents of $PATH are truly files (instead of directories or something
2111 2112 else). For such a safer (but slower) version, use %rehashx."""
2112 2113
2113 2114 # This function (and rehashx) manipulate the alias_table directly
2114 2115 # rather than calling magic_alias, for speed reasons. A rehash on a
2115 2116 # typical Linux box involves several thousand entries, so efficiency
2116 2117 # here is a top concern.
2117 2118
2118 2119 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2119 2120 alias_table = self.shell.alias_table
2120 2121 for pdir in path:
2121 2122 for ff in os.listdir(pdir):
2122 2123 # each entry in the alias table must be (N,name), where
2123 2124 # N is the number of positional arguments of the alias.
2124 2125 alias_table[ff] = (0,ff)
2125 2126 # Make sure the alias table doesn't contain keywords or builtins
2126 2127 self.shell.alias_table_validate()
2127 2128 # Call again init_auto_alias() so we get 'rm -i' and other modified
2128 2129 # aliases since %rehash will probably clobber them
2129 2130 self.shell.init_auto_alias()
2130 2131
2131 2132 def magic_rehashx(self, parameter_s = ''):
2132 2133 """Update the alias table with all executable files in $PATH.
2133 2134
2134 2135 This version explicitly checks that every entry in $PATH is a file
2135 2136 with execute access (os.X_OK), so it is much slower than %rehash.
2136 2137
2137 2138 Under Windows, it checks executability as a match agains a
2138 2139 '|'-separated string of extensions, stored in the IPython config
2139 2140 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2140 2141
2141 2142 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2142 2143 alias_table = self.shell.alias_table
2143 2144
2144 2145 if os.name == 'posix':
2145 2146 isexec = lambda fname:os.path.isfile(fname) and \
2146 2147 os.access(fname,os.X_OK)
2147 2148 else:
2148 2149
2149 2150 try:
2150 2151 winext = os.environ['pathext'].replace(';','|').replace('.','')
2151 2152 except KeyError:
2152 2153 winext = 'exe|com|bat'
2153 2154
2154 2155 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2155 2156 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2156 2157 savedir = os.getcwd()
2157 2158 try:
2158 2159 # write the whole loop for posix/Windows so we don't have an if in
2159 2160 # the innermost part
2160 2161 if os.name == 'posix':
2161 2162 for pdir in path:
2162 2163 os.chdir(pdir)
2163 2164 for ff in os.listdir(pdir):
2164 2165 if isexec(ff):
2165 2166 # each entry in the alias table must be (N,name),
2166 2167 # where N is the number of positional arguments of the
2167 2168 # alias.
2168 2169 alias_table[ff] = (0,ff)
2169 2170 else:
2170 2171 for pdir in path:
2171 2172 os.chdir(pdir)
2172 2173 for ff in os.listdir(pdir):
2173 2174 if isexec(ff):
2174 2175 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2175 2176 # Make sure the alias table doesn't contain keywords or builtins
2176 2177 self.shell.alias_table_validate()
2177 2178 # Call again init_auto_alias() so we get 'rm -i' and other
2178 2179 # modified aliases since %rehashx will probably clobber them
2179 2180 self.shell.init_auto_alias()
2180 2181 finally:
2181 2182 os.chdir(savedir)
2182 2183
2183 2184 def magic_pwd(self, parameter_s = ''):
2184 2185 """Return the current working directory path."""
2185 2186 return os.getcwd()
2186 2187
2187 2188 def magic_cd(self, parameter_s=''):
2188 2189 """Change the current working directory.
2189 2190
2190 2191 This command automatically maintains an internal list of directories
2191 2192 you visit during your IPython session, in the variable _dh. The
2192 2193 command %dhist shows this history nicely formatted.
2193 2194
2194 2195 Usage:
2195 2196
2196 2197 cd 'dir': changes to directory 'dir'.
2197 2198
2198 2199 cd -: changes to the last visited directory.
2199 2200
2200 2201 cd -<n>: changes to the n-th directory in the directory history.
2201 2202
2202 2203 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2203 2204 (note: cd <bookmark_name> is enough if there is no
2204 2205 directory <bookmark_name>, but a bookmark with the name exists.)
2205 2206
2206 2207 Options:
2207 2208
2208 2209 -q: quiet. Do not print the working directory after the cd command is
2209 2210 executed. By default IPython's cd command does print this directory,
2210 2211 since the default prompts do not display path information.
2211 2212
2212 2213 Note that !cd doesn't work for this purpose because the shell where
2213 2214 !command runs is immediately discarded after executing 'command'."""
2214 2215
2215 2216 parameter_s = parameter_s.strip()
2216 2217 bkms = self.shell.persist.get("bookmarks",{})
2217 2218
2218 2219 numcd = re.match(r'(-)(\d+)$',parameter_s)
2219 2220 # jump in directory history by number
2220 2221 if numcd:
2221 2222 nn = int(numcd.group(2))
2222 2223 try:
2223 2224 ps = self.shell.user_ns['_dh'][nn]
2224 2225 except IndexError:
2225 2226 print 'The requested directory does not exist in history.'
2226 2227 return
2227 2228 else:
2228 2229 opts = {}
2229 2230 else:
2230 2231 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2231 2232 # jump to previous
2232 2233 if ps == '-':
2233 2234 try:
2234 2235 ps = self.shell.user_ns['_dh'][-2]
2235 2236 except IndexError:
2236 2237 print 'No previous directory to change to.'
2237 2238 return
2238 2239 # jump to bookmark
2239 2240 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2240 2241 if bkms.has_key(ps):
2241 2242 target = bkms[ps]
2242 2243 print '(bookmark:%s) -> %s' % (ps,target)
2243 2244 ps = target
2244 2245 else:
2245 2246 if bkms:
2246 2247 error("Bookmark '%s' not found. "
2247 2248 "Use '%bookmark -l' to see your bookmarks." % ps)
2248 2249 else:
2249 2250 print "Bookmarks not set - use %bookmark <bookmarkname>"
2250 2251 return
2251 2252
2252 2253 # at this point ps should point to the target dir
2253 2254 if ps:
2254 2255 try:
2255 2256 os.chdir(os.path.expanduser(ps))
2256 2257 except OSError:
2257 2258 print sys.exc_info()[1]
2258 2259 else:
2259 2260 self.shell.user_ns['_dh'].append(os.getcwd())
2260 2261 else:
2261 2262 os.chdir(self.shell.home_dir)
2262 2263 self.shell.user_ns['_dh'].append(os.getcwd())
2263 2264 if not 'q' in opts:
2264 2265 print self.shell.user_ns['_dh'][-1]
2265 2266
2266 2267 def magic_dhist(self, parameter_s=''):
2267 2268 """Print your history of visited directories.
2268 2269
2269 2270 %dhist -> print full history\\
2270 2271 %dhist n -> print last n entries only\\
2271 2272 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2272 2273
2273 2274 This history is automatically maintained by the %cd command, and
2274 2275 always available as the global list variable _dh. You can use %cd -<n>
2275 2276 to go to directory number <n>."""
2276 2277
2277 2278 dh = self.shell.user_ns['_dh']
2278 2279 if parameter_s:
2279 2280 try:
2280 2281 args = map(int,parameter_s.split())
2281 2282 except:
2282 2283 self.arg_err(Magic.magic_dhist)
2283 2284 return
2284 2285 if len(args) == 1:
2285 2286 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2286 2287 elif len(args) == 2:
2287 2288 ini,fin = args
2288 2289 else:
2289 2290 self.arg_err(Magic.magic_dhist)
2290 2291 return
2291 2292 else:
2292 2293 ini,fin = 0,len(dh)
2293 2294 nlprint(dh,
2294 2295 header = 'Directory history (kept in _dh)',
2295 2296 start=ini,stop=fin)
2296 2297
2297 2298 def magic_env(self, parameter_s=''):
2298 2299 """List environment variables."""
2299 2300
2300 2301 return os.environ.data
2301 2302
2302 2303 def magic_pushd(self, parameter_s=''):
2303 2304 """Place the current dir on stack and change directory.
2304 2305
2305 2306 Usage:\\
2306 2307 %pushd ['dirname']
2307 2308
2308 2309 %pushd with no arguments does a %pushd to your home directory.
2309 2310 """
2310 2311 if parameter_s == '': parameter_s = '~'
2311 2312 dir_s = self.shell.dir_stack
2312 2313 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2313 2314 os.path.expanduser(self.shell.dir_stack[0]):
2314 2315 try:
2315 2316 self.magic_cd(parameter_s)
2316 2317 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2317 2318 self.magic_dirs()
2318 2319 except:
2319 2320 print 'Invalid directory'
2320 2321 else:
2321 2322 print 'You are already there!'
2322 2323
2323 2324 def magic_popd(self, parameter_s=''):
2324 2325 """Change to directory popped off the top of the stack.
2325 2326 """
2326 2327 if len (self.shell.dir_stack) > 1:
2327 2328 self.shell.dir_stack.pop(0)
2328 2329 self.magic_cd(self.shell.dir_stack[0])
2329 2330 print self.shell.dir_stack[0]
2330 2331 else:
2331 2332 print "You can't remove the starting directory from the stack:",\
2332 2333 self.shell.dir_stack
2333 2334
2334 2335 def magic_dirs(self, parameter_s=''):
2335 2336 """Return the current directory stack."""
2336 2337
2337 2338 return self.shell.dir_stack[:]
2338 2339
2339 2340 def magic_sc(self, parameter_s=''):
2340 2341 """Shell capture - execute a shell command and capture its output.
2341 2342
2342 2343 %sc [options] varname=command
2343 2344
2344 2345 IPython will run the given command using commands.getoutput(), and
2345 2346 will then update the user's interactive namespace with a variable
2346 2347 called varname, containing the value of the call. Your command can
2347 2348 contain shell wildcards, pipes, etc.
2348 2349
2349 2350 The '=' sign in the syntax is mandatory, and the variable name you
2350 2351 supply must follow Python's standard conventions for valid names.
2351 2352
2352 2353 Options:
2353 2354
2354 2355 -l: list output. Split the output on newlines into a list before
2355 2356 assigning it to the given variable. By default the output is stored
2356 2357 as a single string.
2357 2358
2358 2359 -v: verbose. Print the contents of the variable.
2359 2360
2360 2361 In most cases you should not need to split as a list, because the
2361 2362 returned value is a special type of string which can automatically
2362 2363 provide its contents either as a list (split on newlines) or as a
2363 2364 space-separated string. These are convenient, respectively, either
2364 2365 for sequential processing or to be passed to a shell command.
2365 2366
2366 2367 For example:
2367 2368
2368 2369 # Capture into variable a
2369 2370 In [9]: sc a=ls *py
2370 2371
2371 2372 # a is a string with embedded newlines
2372 2373 In [10]: a
2373 2374 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2374 2375
2375 2376 # which can be seen as a list:
2376 2377 In [11]: a.l
2377 2378 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2378 2379
2379 2380 # or as a whitespace-separated string:
2380 2381 In [12]: a.s
2381 2382 Out[12]: 'setup.py win32_manual_post_install.py'
2382 2383
2383 2384 # a.s is useful to pass as a single command line:
2384 2385 In [13]: !wc -l $a.s
2385 2386 146 setup.py
2386 2387 130 win32_manual_post_install.py
2387 2388 276 total
2388 2389
2389 2390 # while the list form is useful to loop over:
2390 2391 In [14]: for f in a.l:
2391 2392 ....: !wc -l $f
2392 2393 ....:
2393 2394 146 setup.py
2394 2395 130 win32_manual_post_install.py
2395 2396
2396 2397 Similiarly, the lists returned by the -l option are also special, in
2397 2398 the sense that you can equally invoke the .s attribute on them to
2398 2399 automatically get a whitespace-separated string from their contents:
2399 2400
2400 2401 In [1]: sc -l b=ls *py
2401 2402
2402 2403 In [2]: b
2403 2404 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2404 2405
2405 2406 In [3]: b.s
2406 2407 Out[3]: 'setup.py win32_manual_post_install.py'
2407 2408
2408 2409 In summary, both the lists and strings used for ouptut capture have
2409 2410 the following special attributes:
2410 2411
2411 2412 .l (or .list) : value as list.
2412 2413 .n (or .nlstr): value as newline-separated string.
2413 2414 .s (or .spstr): value as space-separated string.
2414 2415 """
2415 2416
2416 2417 opts,args = self.parse_options(parameter_s,'lv')
2417 2418 # Try to get a variable name and command to run
2418 2419 try:
2419 2420 # the variable name must be obtained from the parse_options
2420 2421 # output, which uses shlex.split to strip options out.
2421 2422 var,_ = args.split('=',1)
2422 2423 var = var.strip()
2423 2424 # But the the command has to be extracted from the original input
2424 2425 # parameter_s, not on what parse_options returns, to avoid the
2425 2426 # quote stripping which shlex.split performs on it.
2426 2427 _,cmd = parameter_s.split('=',1)
2427 2428 except ValueError:
2428 2429 var,cmd = '',''
2429 2430 if not var:
2430 2431 error('you must specify a variable to assign the command to.')
2431 2432 return
2432 2433 # If all looks ok, proceed
2433 2434 out,err = self.shell.getoutputerror(cmd)
2434 2435 if err:
2435 2436 print >> Term.cerr,err
2436 2437 if opts.has_key('l'):
2437 2438 out = SList(out.split('\n'))
2438 2439 else:
2439 2440 out = LSString(out)
2440 2441 if opts.has_key('v'):
2441 2442 print '%s ==\n%s' % (var,pformat(out))
2442 2443 self.shell.user_ns.update({var:out})
2443 2444
2444 2445 def magic_sx(self, parameter_s=''):
2445 2446 """Shell execute - run a shell command and capture its output.
2446 2447
2447 2448 %sx command
2448 2449
2449 2450 IPython will run the given command using commands.getoutput(), and
2450 2451 return the result formatted as a list (split on '\\n'). Since the
2451 2452 output is _returned_, it will be stored in ipython's regular output
2452 2453 cache Out[N] and in the '_N' automatic variables.
2453 2454
2454 2455 Notes:
2455 2456
2456 2457 1) If an input line begins with '!!', then %sx is automatically
2457 2458 invoked. That is, while:
2458 2459 !ls
2459 2460 causes ipython to simply issue system('ls'), typing
2460 2461 !!ls
2461 2462 is a shorthand equivalent to:
2462 2463 %sx ls
2463 2464
2464 2465 2) %sx differs from %sc in that %sx automatically splits into a list,
2465 2466 like '%sc -l'. The reason for this is to make it as easy as possible
2466 2467 to process line-oriented shell output via further python commands.
2467 2468 %sc is meant to provide much finer control, but requires more
2468 2469 typing.
2469 2470
2470 2471 3) Just like %sc -l, this is a list with special attributes:
2471 2472
2472 2473 .l (or .list) : value as list.
2473 2474 .n (or .nlstr): value as newline-separated string.
2474 2475 .s (or .spstr): value as whitespace-separated string.
2475 2476
2476 2477 This is very useful when trying to use such lists as arguments to
2477 2478 system commands."""
2478 2479
2479 2480 if parameter_s:
2480 2481 out,err = self.shell.getoutputerror(parameter_s)
2481 2482 if err:
2482 2483 print >> Term.cerr,err
2483 2484 return SList(out.split('\n'))
2484 2485
2485 2486 def magic_bg(self, parameter_s=''):
2486 2487 """Run a job in the background, in a separate thread.
2487 2488
2488 2489 For example,
2489 2490
2490 2491 %bg myfunc(x,y,z=1)
2491 2492
2492 2493 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2493 2494 execution starts, a message will be printed indicating the job
2494 2495 number. If your job number is 5, you can use
2495 2496
2496 2497 myvar = jobs.result(5) or myvar = jobs[5].result
2497 2498
2498 2499 to assign this result to variable 'myvar'.
2499 2500
2500 2501 IPython has a job manager, accessible via the 'jobs' object. You can
2501 2502 type jobs? to get more information about it, and use jobs.<TAB> to see
2502 2503 its attributes. All attributes not starting with an underscore are
2503 2504 meant for public use.
2504 2505
2505 2506 In particular, look at the jobs.new() method, which is used to create
2506 2507 new jobs. This magic %bg function is just a convenience wrapper
2507 2508 around jobs.new(), for expression-based jobs. If you want to create a
2508 2509 new job with an explicit function object and arguments, you must call
2509 2510 jobs.new() directly.
2510 2511
2511 2512 The jobs.new docstring also describes in detail several important
2512 2513 caveats associated with a thread-based model for background job
2513 2514 execution. Type jobs.new? for details.
2514 2515
2515 2516 You can check the status of all jobs with jobs.status().
2516 2517
2517 2518 The jobs variable is set by IPython into the Python builtin namespace.
2518 2519 If you ever declare a variable named 'jobs', you will shadow this
2519 2520 name. You can either delete your global jobs variable to regain
2520 2521 access to the job manager, or make a new name and assign it manually
2521 2522 to the manager (stored in IPython's namespace). For example, to
2522 2523 assign the job manager to the Jobs name, use:
2523 2524
2524 2525 Jobs = __builtins__.jobs"""
2525 2526
2526 2527 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2527 2528
2529 def magic_store(self, parameter_s=''):
2530 """Lightweight persistence for ipython variables
2531
2532 Example:
2533
2534 ville@badger[~]|1> A = ['hello',10,'world']
2535 ville@badger[~]|2> %store A
2536 ville@badger[~]|3> Exit
2537
2538 (IPython session is closed and started again...)
2539
2540 ville@badger:~$ ipython -p pysh
2541 ville@badger[~]|1> print A
2542
2543 ['hello', 10, 'world']
2544
2545 Usage:
2546
2547 %store - Show list of all variables and their current values\\
2548 %store <var> - Store the *current* value of the variable to disk\\
2549 %store -d - Remove the variable and its value from storage\\
2550 %store -r - Remove all variables from storage
2551
2552 It should be noted that if you change the value of a variable, you
2553 need to %store it again if you want to persist the new value.
2554
2555 Note also that the variables will need to be pickleable; most basic
2556 python types can be safely %stored.
2557 """
2558
2559 opts,args = self.parse_options(parameter_s,'dr',mode='list')
2560 # delete
2561 if opts.has_key('d'):
2562 try:
2563 todel = args[0]
2564 except IndexError:
2565 error('You must provide the variable to forget')
2566 else:
2567 try:
2568 del self.shell.persist['S:' + todel]
2569 except:
2570 error("Can't delete variable '%s'" % todel)
2571 # reset
2572 elif opts.has_key('r'):
2573 for k in self.shell.persist.keys():
2574 if k.startswith('S:'):
2575 del self.shell.persist[k]
2576
2577 # run without arguments -> list variables & values
2578 elif not args:
2579 vars = [v[2:] for v in self.shell.persist.keys() if v.startswith('S:')]
2580 vars.sort()
2581 if vars:
2582 size = max(map(len,vars))
2583 else:
2584 size = 0
2585
2586 fmt = '%-'+str(size)+'s -> %s'
2587 print 'Stored variables and their in-memory values:'
2588 for var in vars:
2589 # print 30 first characters from every var
2590 print fmt % (var,repr(self.shell.user_ns.get(var, '<unavailable>'))[:50])
2591
2592 # default action - store the variable
2593 else:
2594 pickled = pickle.dumps(self.shell.user_ns[args[0] ])
2595 self.shell.persist[ 'S:' + args[0] ] = pickled
2596 print "Stored '%s' (%d bytes)" % (args[0], len(pickled))
2597
2598
2599
2600
2601
2602
2528 2603 def magic_bookmark(self, parameter_s=''):
2529 2604 """Manage IPython's bookmark system.
2530 2605
2531 2606 %bookmark <name> - set bookmark to current dir
2532 2607 %bookmark <name> <dir> - set bookmark to <dir>
2533 2608 %bookmark -l - list all bookmarks
2534 2609 %bookmark -d <name> - remove bookmark
2535 2610 %bookmark -r - remove all bookmarks
2536 2611
2537 2612 You can later on access a bookmarked folder with:
2538 2613 %cd -b <name>
2539 2614 or simply '%cd <name>' if there is no directory called <name> AND
2540 2615 there is such a bookmark defined.
2541 2616
2542 2617 Your bookmarks persist through IPython sessions, but they are
2543 2618 associated with each profile."""
2544 2619
2545 2620 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2546 2621 if len(args) > 2:
2547 2622 error('You can only give at most two arguments')
2548 2623 return
2549 2624
2550 2625 bkms = self.shell.persist.get('bookmarks',{})
2551 2626
2552 2627 if opts.has_key('d'):
2553 2628 try:
2554 2629 todel = args[0]
2555 2630 except IndexError:
2556 2631 error('You must provide a bookmark to delete')
2557 2632 else:
2558 2633 try:
2559 2634 del bkms[todel]
2560 2635 except:
2561 2636 error("Can't delete bookmark '%s'" % todel)
2562 2637 elif opts.has_key('r'):
2563 2638 bkms = {}
2564 2639 elif opts.has_key('l'):
2565 2640 bks = bkms.keys()
2566 2641 bks.sort()
2567 2642 if bks:
2568 2643 size = max(map(len,bks))
2569 2644 else:
2570 2645 size = 0
2571 2646 fmt = '%-'+str(size)+'s -> %s'
2572 2647 print 'Current bookmarks:'
2573 2648 for bk in bks:
2574 2649 print fmt % (bk,bkms[bk])
2575 2650 else:
2576 2651 if not args:
2577 2652 error("You must specify the bookmark name")
2578 2653 elif len(args)==1:
2579 2654 bkms[args[0]] = os.getcwd()
2580 2655 elif len(args)==2:
2581 2656 bkms[args[0]] = args[1]
2582 2657 self.shell.persist['bookmarks'] = bkms
2583 2658
2584 2659 def magic_pycat(self, parameter_s=''):
2585 2660 """Show a syntax-highlighted file through a pager.
2586 2661
2587 2662 This magic is similar to the cat utility, but it will assume the file
2588 2663 to be Python source and will show it with syntax highlighting. """
2589 2664
2590 2665 filename = get_py_filename(parameter_s)
2591 2666 page(self.shell.colorize(file_read(filename)),
2592 2667 screen_lines=self.shell.rc.screen_length)
2593 2668
2594 2669 # end Magic
@@ -1,2035 +1,2051 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 967 2005-12-29 09:02:13Z fperez $
9 $Id: iplib.py 968 2005-12-29 17:15:38Z 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
71 71 from IPython.Prompts import CachedOutput
72 72 from IPython.Struct import Struct
73 73 from IPython.background_jobs import BackgroundJobManager
74 74 from IPython.usage import cmd_line_usage,interactive_usage
75 75 from IPython.genutils import *
76 76
77 77 # store the builtin raw_input globally, and use this always, in case user code
78 78 # overwrites it (like wx.py.PyShell does)
79 79 raw_input_original = raw_input
80 80
81 81 #****************************************************************************
82 82 # Some utility function definitions
83 83
84 84 def softspace(file, newvalue):
85 85 """Copied from code.py, to remove the dependency"""
86 86 oldvalue = 0
87 87 try:
88 88 oldvalue = file.softspace
89 89 except AttributeError:
90 90 pass
91 91 try:
92 92 file.softspace = newvalue
93 93 except (AttributeError, TypeError):
94 94 # "attribute-less object" or "read-only attributes"
95 95 pass
96 96 return oldvalue
97 97
98 98 #****************************************************************************
99 99 # These special functions get installed in the builtin namespace, to provide
100 100 # programmatic (pure python) access to magics and aliases. This is important
101 101 # for logging, user scripting, and more.
102 102
103 103 def ipmagic(arg_s):
104 104 """Call a magic function by name.
105 105
106 106 Input: a string containing the name of the magic function to call and any
107 107 additional arguments to be passed to the magic.
108 108
109 109 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
110 110 prompt:
111 111
112 112 In[1]: %name -opt foo bar
113 113
114 114 To call a magic without arguments, simply use ipmagic('name').
115 115
116 116 This provides a proper Python function to call IPython's magics in any
117 117 valid Python code you can type at the interpreter, including loops and
118 118 compound statements. It is added by IPython to the Python builtin
119 119 namespace upon initialization."""
120 120
121 121 args = arg_s.split(' ',1)
122 122 magic_name = args[0]
123 123 if magic_name.startswith(__IPYTHON__.ESC_MAGIC):
124 124 magic_name = magic_name[1:]
125 125 try:
126 126 magic_args = args[1]
127 127 except IndexError:
128 128 magic_args = ''
129 129 fn = getattr(__IPYTHON__,'magic_'+magic_name,None)
130 130 if fn is None:
131 131 error("Magic function `%s` not found." % magic_name)
132 132 else:
133 133 magic_args = __IPYTHON__.var_expand(magic_args)
134 134 return fn(magic_args)
135 135
136 136 def ipalias(arg_s):
137 137 """Call an alias by name.
138 138
139 139 Input: a string containing the name of the alias to call and any
140 140 additional arguments to be passed to the magic.
141 141
142 142 ipalias('name -opt foo bar') is equivalent to typing at the ipython
143 143 prompt:
144 144
145 145 In[1]: name -opt foo bar
146 146
147 147 To call an alias without arguments, simply use ipalias('name').
148 148
149 149 This provides a proper Python function to call IPython's aliases in any
150 150 valid Python code you can type at the interpreter, including loops and
151 151 compound statements. It is added by IPython to the Python builtin
152 152 namespace upon initialization."""
153 153
154 154 args = arg_s.split(' ',1)
155 155 alias_name = args[0]
156 156 try:
157 157 alias_args = args[1]
158 158 except IndexError:
159 159 alias_args = ''
160 160 if alias_name in __IPYTHON__.alias_table:
161 161 __IPYTHON__.call_alias(alias_name,alias_args)
162 162 else:
163 163 error("Alias `%s` not found." % alias_name)
164 164
165 165 #****************************************************************************
166 166 # Local use exceptions
167 167 class SpaceInInput(exceptions.Exception): pass
168 168
169 169 #****************************************************************************
170 170 # Local use classes
171 171 class Bunch: pass
172 172
173 173 class InputList(list):
174 174 """Class to store user input.
175 175
176 176 It's basically a list, but slices return a string instead of a list, thus
177 177 allowing things like (assuming 'In' is an instance):
178 178
179 179 exec In[4:7]
180 180
181 181 or
182 182
183 183 exec In[5:9] + In[14] + In[21:25]"""
184 184
185 185 def __getslice__(self,i,j):
186 186 return ''.join(list.__getslice__(self,i,j))
187 187
188 188 class SyntaxTB(ultraTB.ListTB):
189 189 """Extension which holds some state: the last exception value"""
190 190
191 191 def __init__(self,color_scheme = 'NoColor'):
192 192 ultraTB.ListTB.__init__(self,color_scheme)
193 193 self.last_syntax_error = None
194 194
195 195 def __call__(self, etype, value, elist):
196 196 self.last_syntax_error = value
197 197 ultraTB.ListTB.__call__(self,etype,value,elist)
198 198
199 199 def clear_err_state(self):
200 200 """Return the current error state and clear it"""
201 201 e = self.last_syntax_error
202 202 self.last_syntax_error = None
203 203 return e
204 204
205 205 #****************************************************************************
206 206 # Main IPython class
207 207
208 208 # FIXME: the Magic class is a mixin for now, and will unfortunately remain so
209 209 # until a full rewrite is made. I've cleaned all cross-class uses of
210 210 # attributes and methods, but too much user code out there relies on the
211 211 # equlity %foo == __IP.magic_foo, so I can't actually remove the mixin usage.
212 212 #
213 213 # But at least now, all the pieces have been separated and we could, in
214 214 # principle, stop using the mixin. This will ease the transition to the
215 215 # chainsaw branch.
216 216
217 217 # For reference, the following is the list of 'self.foo' uses in the Magic
218 218 # class as of 2005-12-28. These are names we CAN'T use in the main ipython
219 219 # class, to prevent clashes.
220 220
221 221 # ['self.__class__', 'self.__dict__', 'self._inspect', 'self._ofind',
222 222 # 'self.arg_err', 'self.extract_input', 'self.format_', 'self.lsmagic',
223 223 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
224 224 # 'self.value']
225 225
226 226 class InteractiveShell(Magic):
227 227 """An enhanced console for Python."""
228 228
229 229 # class attribute to indicate whether the class supports threads or not.
230 230 # Subclasses with thread support should override this as needed.
231 231 isthreaded = False
232 232
233 233 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
234 234 user_ns = None,user_global_ns=None,banner2='',
235 235 custom_exceptions=((),None),embedded=False):
236 236
237 237 # some minimal strict typechecks. For some core data structures, I
238 238 # want actual basic python types, not just anything that looks like
239 239 # one. This is especially true for namespaces.
240 240 for ns in (user_ns,user_global_ns):
241 241 if ns is not None and type(ns) != types.DictType:
242 242 raise TypeError,'namespace must be a dictionary'
243 243
244 244 # Put a reference to self in builtins so that any form of embedded or
245 245 # imported code can test for being inside IPython.
246 246 __builtin__.__IPYTHON__ = self
247 247
248 248 # And load into builtins ipmagic/ipalias as well
249 249 __builtin__.ipmagic = ipmagic
250 250 __builtin__.ipalias = ipalias
251 251
252 252 # Add to __builtin__ other parts of IPython's public API
253 253 __builtin__.ip_set_hook = self.set_hook
254 254
255 255 # Keep in the builtins a flag for when IPython is active. We set it
256 256 # with setdefault so that multiple nested IPythons don't clobber one
257 257 # another. Each will increase its value by one upon being activated,
258 258 # which also gives us a way to determine the nesting level.
259 259 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
260 260
261 261 # Do the intuitively correct thing for quit/exit: we remove the
262 262 # builtins if they exist, and our own prefilter routine will handle
263 263 # these special cases
264 264 try:
265 265 del __builtin__.exit, __builtin__.quit
266 266 except AttributeError:
267 267 pass
268 268
269 269 # Store the actual shell's name
270 270 self.name = name
271 271
272 272 # We need to know whether the instance is meant for embedding, since
273 273 # global/local namespaces need to be handled differently in that case
274 274 self.embedded = embedded
275 275
276 276 # command compiler
277 277 self.compile = codeop.CommandCompiler()
278 278
279 279 # User input buffer
280 280 self.buffer = []
281 281
282 282 # Default name given in compilation of code
283 283 self.filename = '<ipython console>'
284 284
285 285 # Create the namespace where the user will operate. user_ns is
286 286 # normally the only one used, and it is passed to the exec calls as
287 287 # the locals argument. But we do carry a user_global_ns namespace
288 288 # given as the exec 'globals' argument, This is useful in embedding
289 289 # situations where the ipython shell opens in a context where the
290 290 # distinction between locals and globals is meaningful.
291 291
292 292 # FIXME. For some strange reason, __builtins__ is showing up at user
293 293 # level as a dict instead of a module. This is a manual fix, but I
294 294 # should really track down where the problem is coming from. Alex
295 295 # Schmolck reported this problem first.
296 296
297 297 # A useful post by Alex Martelli on this topic:
298 298 # Re: inconsistent value from __builtins__
299 299 # Von: Alex Martelli <aleaxit@yahoo.com>
300 300 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
301 301 # Gruppen: comp.lang.python
302 302
303 303 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
304 304 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
305 305 # > <type 'dict'>
306 306 # > >>> print type(__builtins__)
307 307 # > <type 'module'>
308 308 # > Is this difference in return value intentional?
309 309
310 310 # Well, it's documented that '__builtins__' can be either a dictionary
311 311 # or a module, and it's been that way for a long time. Whether it's
312 312 # intentional (or sensible), I don't know. In any case, the idea is
313 313 # that if you need to access the built-in namespace directly, you
314 314 # should start with "import __builtin__" (note, no 's') which will
315 315 # definitely give you a module. Yeah, it's somewhatΒ confusing:-(.
316 316
317 317 if user_ns is None:
318 318 # Set __name__ to __main__ to better match the behavior of the
319 319 # normal interpreter.
320 320 user_ns = {'__name__' :'__main__',
321 321 '__builtins__' : __builtin__,
322 322 }
323 323
324 324 if user_global_ns is None:
325 325 user_global_ns = {}
326 326
327 327 # Assign namespaces
328 328 # This is the namespace where all normal user variables live
329 329 self.user_ns = user_ns
330 330 # Embedded instances require a separate namespace for globals.
331 331 # Normally this one is unused by non-embedded instances.
332 332 self.user_global_ns = user_global_ns
333 333 # A namespace to keep track of internal data structures to prevent
334 334 # them from cluttering user-visible stuff. Will be updated later
335 335 self.internal_ns = {}
336 336
337 337 # Namespace of system aliases. Each entry in the alias
338 338 # table must be a 2-tuple of the form (N,name), where N is the number
339 339 # of positional arguments of the alias.
340 340 self.alias_table = {}
341 341
342 342 # A table holding all the namespaces IPython deals with, so that
343 343 # introspection facilities can search easily.
344 344 self.ns_table = {'user':user_ns,
345 345 'user_global':user_global_ns,
346 346 'alias':self.alias_table,
347 347 'internal':self.internal_ns,
348 348 'builtin':__builtin__.__dict__
349 349 }
350 350
351 351 # The user namespace MUST have a pointer to the shell itself.
352 352 self.user_ns[name] = self
353 353
354 354 # We need to insert into sys.modules something that looks like a
355 355 # module but which accesses the IPython namespace, for shelve and
356 356 # pickle to work interactively. Normally they rely on getting
357 357 # everything out of __main__, but for embedding purposes each IPython
358 358 # instance has its own private namespace, so we can't go shoving
359 359 # everything into __main__.
360 360
361 361 # note, however, that we should only do this for non-embedded
362 362 # ipythons, which really mimic the __main__.__dict__ with their own
363 363 # namespace. Embedded instances, on the other hand, should not do
364 364 # this because they need to manage the user local/global namespaces
365 365 # only, but they live within a 'normal' __main__ (meaning, they
366 366 # shouldn't overtake the execution environment of the script they're
367 367 # embedded in).
368 368
369 369 if not embedded:
370 370 try:
371 371 main_name = self.user_ns['__name__']
372 372 except KeyError:
373 373 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
374 374 else:
375 375 #print "pickle hack in place" # dbg
376 376 sys.modules[main_name] = FakeModule(self.user_ns)
377 377
378 378 # List of input with multi-line handling.
379 379 # Fill its zero entry, user counter starts at 1
380 380 self.input_hist = InputList(['\n'])
381 381
382 382 # list of visited directories
383 383 try:
384 384 self.dir_hist = [os.getcwd()]
385 385 except IOError, e:
386 386 self.dir_hist = []
387 387
388 388 # dict of output history
389 389 self.output_hist = {}
390 390
391 391 # dict of things NOT to alias (keywords, builtins and some magics)
392 392 no_alias = {}
393 393 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
394 394 for key in keyword.kwlist + no_alias_magics:
395 395 no_alias[key] = 1
396 396 no_alias.update(__builtin__.__dict__)
397 397 self.no_alias = no_alias
398 398
399 399 # make global variables for user access to these
400 400 self.user_ns['_ih'] = self.input_hist
401 401 self.user_ns['_oh'] = self.output_hist
402 402 self.user_ns['_dh'] = self.dir_hist
403 403
404 404 # user aliases to input and output histories
405 405 self.user_ns['In'] = self.input_hist
406 406 self.user_ns['Out'] = self.output_hist
407 407
408 408 # Object variable to store code object waiting execution. This is
409 409 # used mainly by the multithreaded shells, but it can come in handy in
410 410 # other situations. No need to use a Queue here, since it's a single
411 411 # item which gets cleared once run.
412 412 self.code_to_run = None
413 413
414 414 # Job manager (for jobs run as background threads)
415 415 self.jobs = BackgroundJobManager()
416 416 # Put the job manager into builtins so it's always there.
417 417 __builtin__.jobs = self.jobs
418 418
419 419 # escapes for automatic behavior on the command line
420 420 self.ESC_SHELL = '!'
421 421 self.ESC_HELP = '?'
422 422 self.ESC_MAGIC = '%'
423 423 self.ESC_QUOTE = ','
424 424 self.ESC_QUOTE2 = ';'
425 425 self.ESC_PAREN = '/'
426 426
427 427 # And their associated handlers
428 428 self.esc_handlers = {self.ESC_PAREN : self.handle_auto,
429 429 self.ESC_QUOTE : self.handle_auto,
430 430 self.ESC_QUOTE2 : self.handle_auto,
431 431 self.ESC_MAGIC : self.handle_magic,
432 432 self.ESC_HELP : self.handle_help,
433 433 self.ESC_SHELL : self.handle_shell_escape,
434 434 }
435 435
436 436 # class initializations
437 437 Magic.__init__(self,self)
438 438
439 439 # Python source parser/formatter for syntax highlighting
440 440 pyformat = PyColorize.Parser().format
441 441 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
442 442
443 443 # hooks holds pointers used for user-side customizations
444 444 self.hooks = Struct()
445 445
446 446 # Set all default hooks, defined in the IPython.hooks module.
447 447 hooks = IPython.hooks
448 448 for hook_name in hooks.__all__:
449 449 self.set_hook(hook_name,getattr(hooks,hook_name))
450 450
451 451 # Flag to mark unconditional exit
452 452 self.exit_now = False
453 453
454 454 self.usage_min = """\
455 455 An enhanced console for Python.
456 456 Some of its features are:
457 457 - Readline support if the readline library is present.
458 458 - Tab completion in the local namespace.
459 459 - Logging of input, see command-line options.
460 460 - System shell escape via ! , eg !ls.
461 461 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
462 462 - Keeps track of locally defined variables via %who, %whos.
463 463 - Show object information with a ? eg ?x or x? (use ?? for more info).
464 464 """
465 465 if usage: self.usage = usage
466 466 else: self.usage = self.usage_min
467 467
468 468 # Storage
469 469 self.rc = rc # This will hold all configuration information
470 470 self.inputcache = []
471 471 self._boundcache = []
472 472 self.pager = 'less'
473 473 # temporary files used for various purposes. Deleted at exit.
474 474 self.tempfiles = []
475 475
476 476 # Keep track of readline usage (later set by init_readline)
477 477 self.has_readline = False
478 478
479 479 # template for logfile headers. It gets resolved at runtime by the
480 480 # logstart method.
481 481 self.loghead_tpl = \
482 482 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
483 483 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
484 484 #log# opts = %s
485 485 #log# args = %s
486 486 #log# It is safe to make manual edits below here.
487 487 #log#-----------------------------------------------------------------------
488 488 """
489 489 # for pushd/popd management
490 490 try:
491 491 self.home_dir = get_home_dir()
492 492 except HomeDirError,msg:
493 493 fatal(msg)
494 494
495 495 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
496 496
497 497 # Functions to call the underlying shell.
498 498
499 499 # utility to expand user variables via Itpl
500 500 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
501 501 self.user_ns))
502 502 # The first is similar to os.system, but it doesn't return a value,
503 503 # and it allows interpolation of variables in the user's namespace.
504 504 self.system = lambda cmd: shell(self.var_expand(cmd),
505 505 header='IPython system call: ',
506 506 verbose=self.rc.system_verbose)
507 507 # These are for getoutput and getoutputerror:
508 508 self.getoutput = lambda cmd: \
509 509 getoutput(self.var_expand(cmd),
510 510 header='IPython system call: ',
511 511 verbose=self.rc.system_verbose)
512 512 self.getoutputerror = lambda cmd: \
513 513 getoutputerror(str(ItplNS(cmd.replace('#','\#'),
514 514 self.user_ns)),
515 515 header='IPython system call: ',
516 516 verbose=self.rc.system_verbose)
517 517
518 518 # RegExp for splitting line contents into pre-char//first
519 519 # word-method//rest. For clarity, each group in on one line.
520 520
521 521 # WARNING: update the regexp if the above escapes are changed, as they
522 522 # are hardwired in.
523 523
524 524 # Don't get carried away with trying to make the autocalling catch too
525 525 # much: it's better to be conservative rather than to trigger hidden
526 526 # evals() somewhere and end up causing side effects.
527 527
528 528 self.line_split = re.compile(r'^([\s*,;/])'
529 529 r'([\?\w\.]+\w*\s*)'
530 530 r'(\(?.*$)')
531 531
532 532 # Original re, keep around for a while in case changes break something
533 533 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
534 534 # r'(\s*[\?\w\.]+\w*\s*)'
535 535 # r'(\(?.*$)')
536 536
537 537 # RegExp to identify potential function names
538 538 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
539 539 # RegExp to exclude strings with this start from autocalling
540 540 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
541 541
542 542 # try to catch also methods for stuff in lists/tuples/dicts: off
543 543 # (experimental). For this to work, the line_split regexp would need
544 544 # to be modified so it wouldn't break things at '['. That line is
545 545 # nasty enough that I shouldn't change it until I can test it _well_.
546 546 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
547 547
548 548 # keep track of where we started running (mainly for crash post-mortem)
549 549 self.starting_dir = os.getcwd()
550 550
551 551 # Various switches which can be set
552 552 self.CACHELENGTH = 5000 # this is cheap, it's just text
553 553 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
554 554 self.banner2 = banner2
555 555
556 556 # TraceBack handlers:
557 557
558 558 # Syntax error handler.
559 559 self.SyntaxTB = SyntaxTB(color_scheme='NoColor')
560 560
561 561 # The interactive one is initialized with an offset, meaning we always
562 562 # want to remove the topmost item in the traceback, which is our own
563 563 # internal code. Valid modes: ['Plain','Context','Verbose']
564 564 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
565 565 color_scheme='NoColor',
566 566 tb_offset = 1)
567 567
568 568 # IPython itself shouldn't crash. This will produce a detailed
569 569 # post-mortem if it does. But we only install the crash handler for
570 570 # non-threaded shells, the threaded ones use a normal verbose reporter
571 571 # and lose the crash handler. This is because exceptions in the main
572 572 # thread (such as in GUI code) propagate directly to sys.excepthook,
573 573 # and there's no point in printing crash dumps for every user exception.
574 574 if self.isthreaded:
575 575 sys.excepthook = ultraTB.FormattedTB()
576 576 else:
577 577 from IPython import CrashHandler
578 578 sys.excepthook = CrashHandler.CrashHandler(self)
579 579
580 580 # The instance will store a pointer to this, so that runtime code
581 581 # (such as magics) can access it. This is because during the
582 582 # read-eval loop, it gets temporarily overwritten (to deal with GUI
583 583 # frameworks).
584 584 self.sys_excepthook = sys.excepthook
585 585
586 586 # and add any custom exception handlers the user may have specified
587 587 self.set_custom_exc(*custom_exceptions)
588 588
589 589 # Object inspector
590 590 self.inspector = OInspect.Inspector(OInspect.InspectColors,
591 591 PyColorize.ANSICodeColors,
592 592 'NoColor')
593 593 # indentation management
594 594 self.autoindent = False
595 595 self.indent_current_nsp = 0
596 596 self.indent_current = '' # actual indent string
597 597
598 598 # Make some aliases automatically
599 599 # Prepare list of shell aliases to auto-define
600 600 if os.name == 'posix':
601 601 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
602 602 'mv mv -i','rm rm -i','cp cp -i',
603 603 'cat cat','less less','clear clear',
604 604 # a better ls
605 605 'ls ls -F',
606 606 # long ls
607 607 'll ls -lF',
608 608 # color ls
609 609 'lc ls -F -o --color',
610 610 # ls normal files only
611 611 'lf ls -F -o --color %l | grep ^-',
612 612 # ls symbolic links
613 613 'lk ls -F -o --color %l | grep ^l',
614 614 # directories or links to directories,
615 615 'ldir ls -F -o --color %l | grep /$',
616 616 # things which are executable
617 617 'lx ls -F -o --color %l | grep ^-..x',
618 618 )
619 619 elif os.name in ['nt','dos']:
620 620 auto_alias = ('dir dir /on', 'ls dir /on',
621 621 'ddir dir /ad /on', 'ldir dir /ad /on',
622 622 'mkdir mkdir','rmdir rmdir','echo echo',
623 623 'ren ren','cls cls','copy copy')
624 624 else:
625 625 auto_alias = ()
626 626 self.auto_alias = map(lambda s:s.split(None,1),auto_alias)
627 627 # Call the actual (public) initializer
628 628 self.init_auto_alias()
629 629 # end __init__
630 630
631 631 def post_config_initialization(self):
632 632 """Post configuration init method
633 633
634 634 This is called after the configuration files have been processed to
635 635 'finalize' the initialization."""
636 636
637 637 rc = self.rc
638 638
639 639 # Load readline proper
640 640 if rc.readline:
641 641 self.init_readline()
642 642
643 643 # log system
644 644 self.logger = Logger(self,logfname='ipython_log.py',logmode='rotate')
645 645 # local shortcut, this is used a LOT
646 646 self.log = self.logger.log
647 647
648 648 # Initialize cache, set in/out prompts and printing system
649 649 self.outputcache = CachedOutput(self,
650 650 rc.cache_size,
651 651 rc.pprint,
652 652 input_sep = rc.separate_in,
653 653 output_sep = rc.separate_out,
654 654 output_sep2 = rc.separate_out2,
655 655 ps1 = rc.prompt_in1,
656 656 ps2 = rc.prompt_in2,
657 657 ps_out = rc.prompt_out,
658 658 pad_left = rc.prompts_pad_left)
659 659
660 660 # user may have over-ridden the default print hook:
661 661 try:
662 662 self.outputcache.__class__.display = self.hooks.display
663 663 except AttributeError:
664 664 pass
665 665
666 666 # I don't like assigning globally to sys, because it means when embedding
667 667 # instances, each embedded instance overrides the previous choice. But
668 668 # sys.displayhook seems to be called internally by exec, so I don't see a
669 669 # way around it.
670 670 sys.displayhook = self.outputcache
671 671
672 672 # Set user colors (don't do it in the constructor above so that it
673 673 # doesn't crash if colors option is invalid)
674 674 self.magic_colors(rc.colors)
675 675
676 676 # Set calling of pdb on exceptions
677 677 self.call_pdb = rc.pdb
678 678
679 679 # Load user aliases
680 680 for alias in rc.alias:
681 681 self.magic_alias(alias)
682 682
683 683 # dynamic data that survives through sessions
684 684 # XXX make the filename a config option?
685 685 persist_base = 'persist'
686 686 if rc.profile:
687 687 persist_base += '_%s' % rc.profile
688 688 self.persist_fname = os.path.join(rc.ipythondir,persist_base)
689 689
690 690 try:
691 691 self.persist = pickle.load(file(self.persist_fname))
692 692 except:
693 693 self.persist = {}
694
695
696 for (key, value) in [(k[2:],v) for (k,v) in self.persist.items() if k.startswith('S:')]:
697 try:
698 obj = pickle.loads(value)
699 except:
700
701 print "Unable to restore variable '%s', ignoring (use %%store -d to forget!)" % key
702 print "The error was:",sys.exc_info()[0]
703 continue
704
705
706 self.user_ns[key] = obj
707
708
709
694 710
695 711 def set_hook(self,name,hook):
696 712 """set_hook(name,hook) -> sets an internal IPython hook.
697 713
698 714 IPython exposes some of its internal API as user-modifiable hooks. By
699 715 resetting one of these hooks, you can modify IPython's behavior to
700 716 call at runtime your own routines."""
701 717
702 718 # At some point in the future, this should validate the hook before it
703 719 # accepts it. Probably at least check that the hook takes the number
704 720 # of args it's supposed to.
705 721 setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
706 722
707 723 def set_custom_exc(self,exc_tuple,handler):
708 724 """set_custom_exc(exc_tuple,handler)
709 725
710 726 Set a custom exception handler, which will be called if any of the
711 727 exceptions in exc_tuple occur in the mainloop (specifically, in the
712 728 runcode() method.
713 729
714 730 Inputs:
715 731
716 732 - exc_tuple: a *tuple* of valid exceptions to call the defined
717 733 handler for. It is very important that you use a tuple, and NOT A
718 734 LIST here, because of the way Python's except statement works. If
719 735 you only want to trap a single exception, use a singleton tuple:
720 736
721 737 exc_tuple == (MyCustomException,)
722 738
723 739 - handler: this must be defined as a function with the following
724 740 basic interface: def my_handler(self,etype,value,tb).
725 741
726 742 This will be made into an instance method (via new.instancemethod)
727 743 of IPython itself, and it will be called if any of the exceptions
728 744 listed in the exc_tuple are caught. If the handler is None, an
729 745 internal basic one is used, which just prints basic info.
730 746
731 747 WARNING: by putting in your own exception handler into IPython's main
732 748 execution loop, you run a very good chance of nasty crashes. This
733 749 facility should only be used if you really know what you are doing."""
734 750
735 751 assert type(exc_tuple)==type(()) , \
736 752 "The custom exceptions must be given AS A TUPLE."
737 753
738 754 def dummy_handler(self,etype,value,tb):
739 755 print '*** Simple custom exception handler ***'
740 756 print 'Exception type :',etype
741 757 print 'Exception value:',value
742 758 print 'Traceback :',tb
743 759 print 'Source code :','\n'.join(self.buffer)
744 760
745 761 if handler is None: handler = dummy_handler
746 762
747 763 self.CustomTB = new.instancemethod(handler,self,self.__class__)
748 764 self.custom_exceptions = exc_tuple
749 765
750 766 def set_custom_completer(self,completer,pos=0):
751 767 """set_custom_completer(completer,pos=0)
752 768
753 769 Adds a new custom completer function.
754 770
755 771 The position argument (defaults to 0) is the index in the completers
756 772 list where you want the completer to be inserted."""
757 773
758 774 newcomp = new.instancemethod(completer,self.Completer,
759 775 self.Completer.__class__)
760 776 self.Completer.matchers.insert(pos,newcomp)
761 777
762 778 def _get_call_pdb(self):
763 779 return self._call_pdb
764 780
765 781 def _set_call_pdb(self,val):
766 782
767 783 if val not in (0,1,False,True):
768 784 raise ValueError,'new call_pdb value must be boolean'
769 785
770 786 # store value in instance
771 787 self._call_pdb = val
772 788
773 789 # notify the actual exception handlers
774 790 self.InteractiveTB.call_pdb = val
775 791 if self.isthreaded:
776 792 try:
777 793 self.sys_excepthook.call_pdb = val
778 794 except:
779 795 warn('Failed to activate pdb for threaded exception handler')
780 796
781 797 call_pdb = property(_get_call_pdb,_set_call_pdb,None,
782 798 'Control auto-activation of pdb at exceptions')
783 799
784 800 def complete(self,text):
785 801 """Return a sorted list of all possible completions on text.
786 802
787 803 Inputs:
788 804
789 805 - text: a string of text to be completed on.
790 806
791 807 This is a wrapper around the completion mechanism, similar to what
792 808 readline does at the command line when the TAB key is hit. By
793 809 exposing it as a method, it can be used by other non-readline
794 810 environments (such as GUIs) for text completion.
795 811
796 812 Simple usage example:
797 813
798 814 In [1]: x = 'hello'
799 815
800 816 In [2]: __IP.complete('x.l')
801 817 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
802 818
803 819 complete = self.Completer.complete
804 820 state = 0
805 821 # use a dict so we get unique keys, since ipyhton's multiple
806 822 # completers can return duplicates.
807 823 comps = {}
808 824 while True:
809 825 newcomp = complete(text,state)
810 826 if newcomp is None:
811 827 break
812 828 comps[newcomp] = 1
813 829 state += 1
814 830 outcomps = comps.keys()
815 831 outcomps.sort()
816 832 return outcomps
817 833
818 834 def set_completer_frame(self, frame):
819 835 if frame:
820 836 self.Completer.namespace = frame.f_locals
821 837 self.Completer.global_namespace = frame.f_globals
822 838 else:
823 839 self.Completer.namespace = self.user_ns
824 840 self.Completer.global_namespace = self.user_global_ns
825 841
826 842 def init_auto_alias(self):
827 843 """Define some aliases automatically.
828 844
829 845 These are ALL parameter-less aliases"""
830 846 for alias,cmd in self.auto_alias:
831 847 self.alias_table[alias] = (0,cmd)
832 848
833 849 def alias_table_validate(self,verbose=0):
834 850 """Update information about the alias table.
835 851
836 852 In particular, make sure no Python keywords/builtins are in it."""
837 853
838 854 no_alias = self.no_alias
839 855 for k in self.alias_table.keys():
840 856 if k in no_alias:
841 857 del self.alias_table[k]
842 858 if verbose:
843 859 print ("Deleting alias <%s>, it's a Python "
844 860 "keyword or builtin." % k)
845 861
846 862 def set_autoindent(self,value=None):
847 863 """Set the autoindent flag, checking for readline support.
848 864
849 865 If called with no arguments, it acts as a toggle."""
850 866
851 867 if not self.has_readline:
852 868 if os.name == 'posix':
853 869 warn("The auto-indent feature requires the readline library")
854 870 self.autoindent = 0
855 871 return
856 872 if value is None:
857 873 self.autoindent = not self.autoindent
858 874 else:
859 875 self.autoindent = value
860 876
861 877 def rc_set_toggle(self,rc_field,value=None):
862 878 """Set or toggle a field in IPython's rc config. structure.
863 879
864 880 If called with no arguments, it acts as a toggle.
865 881
866 882 If called with a non-existent field, the resulting AttributeError
867 883 exception will propagate out."""
868 884
869 885 rc_val = getattr(self.rc,rc_field)
870 886 if value is None:
871 887 value = not rc_val
872 888 setattr(self.rc,rc_field,value)
873 889
874 890 def user_setup(self,ipythondir,rc_suffix,mode='install'):
875 891 """Install the user configuration directory.
876 892
877 893 Can be called when running for the first time or to upgrade the user's
878 894 .ipython/ directory with the mode parameter. Valid modes are 'install'
879 895 and 'upgrade'."""
880 896
881 897 def wait():
882 898 try:
883 899 raw_input("Please press <RETURN> to start IPython.")
884 900 except EOFError:
885 901 print >> Term.cout
886 902 print '*'*70
887 903
888 904 cwd = os.getcwd() # remember where we started
889 905 glb = glob.glob
890 906 print '*'*70
891 907 if mode == 'install':
892 908 print \
893 909 """Welcome to IPython. I will try to create a personal configuration directory
894 910 where you can customize many aspects of IPython's functionality in:\n"""
895 911 else:
896 912 print 'I am going to upgrade your configuration in:'
897 913
898 914 print ipythondir
899 915
900 916 rcdirend = os.path.join('IPython','UserConfig')
901 917 cfg = lambda d: os.path.join(d,rcdirend)
902 918 try:
903 919 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
904 920 except IOError:
905 921 warning = """
906 922 Installation error. IPython's directory was not found.
907 923
908 924 Check the following:
909 925
910 926 The ipython/IPython directory should be in a directory belonging to your
911 927 PYTHONPATH environment variable (that is, it should be in a directory
912 928 belonging to sys.path). You can copy it explicitly there or just link to it.
913 929
914 930 IPython will proceed with builtin defaults.
915 931 """
916 932 warn(warning)
917 933 wait()
918 934 return
919 935
920 936 if mode == 'install':
921 937 try:
922 938 shutil.copytree(rcdir,ipythondir)
923 939 os.chdir(ipythondir)
924 940 rc_files = glb("ipythonrc*")
925 941 for rc_file in rc_files:
926 942 os.rename(rc_file,rc_file+rc_suffix)
927 943 except:
928 944 warning = """
929 945
930 946 There was a problem with the installation:
931 947 %s
932 948 Try to correct it or contact the developers if you think it's a bug.
933 949 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
934 950 warn(warning)
935 951 wait()
936 952 return
937 953
938 954 elif mode == 'upgrade':
939 955 try:
940 956 os.chdir(ipythondir)
941 957 except:
942 958 print """
943 959 Can not upgrade: changing to directory %s failed. Details:
944 960 %s
945 961 """ % (ipythondir,sys.exc_info()[1])
946 962 wait()
947 963 return
948 964 else:
949 965 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
950 966 for new_full_path in sources:
951 967 new_filename = os.path.basename(new_full_path)
952 968 if new_filename.startswith('ipythonrc'):
953 969 new_filename = new_filename + rc_suffix
954 970 # The config directory should only contain files, skip any
955 971 # directories which may be there (like CVS)
956 972 if os.path.isdir(new_full_path):
957 973 continue
958 974 if os.path.exists(new_filename):
959 975 old_file = new_filename+'.old'
960 976 if os.path.exists(old_file):
961 977 os.remove(old_file)
962 978 os.rename(new_filename,old_file)
963 979 shutil.copy(new_full_path,new_filename)
964 980 else:
965 981 raise ValueError,'unrecognized mode for install:',`mode`
966 982
967 983 # Fix line-endings to those native to each platform in the config
968 984 # directory.
969 985 try:
970 986 os.chdir(ipythondir)
971 987 except:
972 988 print """
973 989 Problem: changing to directory %s failed.
974 990 Details:
975 991 %s
976 992
977 993 Some configuration files may have incorrect line endings. This should not
978 994 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
979 995 wait()
980 996 else:
981 997 for fname in glb('ipythonrc*'):
982 998 try:
983 999 native_line_ends(fname,backup=0)
984 1000 except IOError:
985 1001 pass
986 1002
987 1003 if mode == 'install':
988 1004 print """
989 1005 Successful installation!
990 1006
991 1007 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
992 1008 IPython manual (there are both HTML and PDF versions supplied with the
993 1009 distribution) to make sure that your system environment is properly configured
994 1010 to take advantage of IPython's features."""
995 1011 else:
996 1012 print """
997 1013 Successful upgrade!
998 1014
999 1015 All files in your directory:
1000 1016 %(ipythondir)s
1001 1017 which would have been overwritten by the upgrade were backed up with a .old
1002 1018 extension. If you had made particular customizations in those files you may
1003 1019 want to merge them back into the new files.""" % locals()
1004 1020 wait()
1005 1021 os.chdir(cwd)
1006 1022 # end user_setup()
1007 1023
1008 1024 def atexit_operations(self):
1009 1025 """This will be executed at the time of exit.
1010 1026
1011 1027 Saving of persistent data should be performed here. """
1012 1028
1013 1029 # input history
1014 1030 self.savehist()
1015 1031
1016 1032 # Cleanup all tempfiles left around
1017 1033 for tfile in self.tempfiles:
1018 1034 try:
1019 1035 os.unlink(tfile)
1020 1036 except OSError:
1021 1037 pass
1022 1038
1023 1039 # save the "persistent data" catch-all dictionary
1024 1040 try:
1025 1041 pickle.dump(self.persist, open(self.persist_fname,"w"))
1026 1042 except:
1027 1043 print "*** ERROR *** persistent data saving failed."
1028 1044
1029 1045 def savehist(self):
1030 1046 """Save input history to a file (via readline library)."""
1031 1047 try:
1032 1048 self.readline.write_history_file(self.histfile)
1033 1049 except:
1034 1050 print 'Unable to save IPython command history to file: ' + \
1035 1051 `self.histfile`
1036 1052
1037 1053 def pre_readline(self):
1038 1054 """readline hook to be used at the start of each line.
1039 1055
1040 1056 Currently it handles auto-indent only."""
1041 1057
1042 1058 self.readline.insert_text(self.indent_current)
1043 1059
1044 1060 def init_readline(self):
1045 1061 """Command history completion/saving/reloading."""
1046 1062 try:
1047 1063 import readline
1048 1064 except ImportError:
1049 1065 self.has_readline = 0
1050 1066 self.readline = None
1051 1067 # no point in bugging windows users with this every time:
1052 1068 if os.name == 'posix':
1053 1069 warn('Readline services not available on this platform.')
1054 1070 else:
1055 1071 import atexit
1056 1072 from IPython.completer import IPCompleter
1057 1073 self.Completer = IPCompleter(self,
1058 1074 self.user_ns,
1059 1075 self.user_global_ns,
1060 1076 self.rc.readline_omit__names,
1061 1077 self.alias_table)
1062 1078
1063 1079 # Platform-specific configuration
1064 1080 if os.name == 'nt':
1065 1081 self.readline_startup_hook = readline.set_pre_input_hook
1066 1082 else:
1067 1083 self.readline_startup_hook = readline.set_startup_hook
1068 1084
1069 1085 # Load user's initrc file (readline config)
1070 1086 inputrc_name = os.environ.get('INPUTRC')
1071 1087 if inputrc_name is None:
1072 1088 home_dir = get_home_dir()
1073 1089 if home_dir is not None:
1074 1090 inputrc_name = os.path.join(home_dir,'.inputrc')
1075 1091 if os.path.isfile(inputrc_name):
1076 1092 try:
1077 1093 readline.read_init_file(inputrc_name)
1078 1094 except:
1079 1095 warn('Problems reading readline initialization file <%s>'
1080 1096 % inputrc_name)
1081 1097
1082 1098 self.has_readline = 1
1083 1099 self.readline = readline
1084 1100 # save this in sys so embedded copies can restore it properly
1085 1101 sys.ipcompleter = self.Completer.complete
1086 1102 readline.set_completer(self.Completer.complete)
1087 1103
1088 1104 # Configure readline according to user's prefs
1089 1105 for rlcommand in self.rc.readline_parse_and_bind:
1090 1106 readline.parse_and_bind(rlcommand)
1091 1107
1092 1108 # remove some chars from the delimiters list
1093 1109 delims = readline.get_completer_delims()
1094 1110 delims = delims.translate(string._idmap,
1095 1111 self.rc.readline_remove_delims)
1096 1112 readline.set_completer_delims(delims)
1097 1113 # otherwise we end up with a monster history after a while:
1098 1114 readline.set_history_length(1000)
1099 1115 try:
1100 1116 #print '*** Reading readline history' # dbg
1101 1117 readline.read_history_file(self.histfile)
1102 1118 except IOError:
1103 1119 pass # It doesn't exist yet.
1104 1120
1105 1121 atexit.register(self.atexit_operations)
1106 1122 del atexit
1107 1123
1108 1124 # Configure auto-indent for all platforms
1109 1125 self.set_autoindent(self.rc.autoindent)
1110 1126
1111 1127 def _should_recompile(self,e):
1112 1128 """Utility routine for edit_syntax_error"""
1113 1129
1114 1130 if e.filename in ('<ipython console>','<input>','<string>',
1115 1131 '<console>'):
1116 1132 return False
1117 1133 try:
1118 1134 if not ask_yes_no('Return to editor to correct syntax error? '
1119 1135 '[Y/n] ','y'):
1120 1136 return False
1121 1137 except EOFError:
1122 1138 return False
1123 1139 self.hooks.fix_error_editor(e.filename,e.lineno,e.offset,e.msg)
1124 1140 return True
1125 1141
1126 1142 def edit_syntax_error(self):
1127 1143 """The bottom half of the syntax error handler called in the main loop.
1128 1144
1129 1145 Loop until syntax error is fixed or user cancels.
1130 1146 """
1131 1147
1132 1148 while self.SyntaxTB.last_syntax_error:
1133 1149 # copy and clear last_syntax_error
1134 1150 err = self.SyntaxTB.clear_err_state()
1135 1151 if not self._should_recompile(err):
1136 1152 return
1137 1153 try:
1138 1154 # may set last_syntax_error again if a SyntaxError is raised
1139 1155 self.safe_execfile(err.filename,self.shell.user_ns)
1140 1156 except:
1141 1157 self.showtraceback()
1142 1158 else:
1143 1159 f = file(err.filename)
1144 1160 try:
1145 1161 sys.displayhook(f.read())
1146 1162 finally:
1147 1163 f.close()
1148 1164
1149 1165 def showsyntaxerror(self, filename=None):
1150 1166 """Display the syntax error that just occurred.
1151 1167
1152 1168 This doesn't display a stack trace because there isn't one.
1153 1169
1154 1170 If a filename is given, it is stuffed in the exception instead
1155 1171 of what was there before (because Python's parser always uses
1156 1172 "<string>" when reading from a string).
1157 1173 """
1158 1174 type, value, sys.last_traceback = sys.exc_info()
1159 1175 sys.last_type = type
1160 1176 sys.last_value = value
1161 1177 if filename and type is SyntaxError:
1162 1178 # Work hard to stuff the correct filename in the exception
1163 1179 try:
1164 1180 msg, (dummy_filename, lineno, offset, line) = value
1165 1181 except:
1166 1182 # Not the format we expect; leave it alone
1167 1183 pass
1168 1184 else:
1169 1185 # Stuff in the right filename
1170 1186 try:
1171 1187 # Assume SyntaxError is a class exception
1172 1188 value = SyntaxError(msg, (filename, lineno, offset, line))
1173 1189 except:
1174 1190 # If that failed, assume SyntaxError is a string
1175 1191 value = msg, (filename, lineno, offset, line)
1176 1192 self.SyntaxTB(type,value,[])
1177 1193
1178 1194 def debugger(self):
1179 1195 """Call the pdb debugger."""
1180 1196
1181 1197 if not self.rc.pdb:
1182 1198 return
1183 1199 pdb.pm()
1184 1200
1185 1201 def showtraceback(self,exc_tuple = None,filename=None):
1186 1202 """Display the exception that just occurred."""
1187 1203
1188 1204 # Though this won't be called by syntax errors in the input line,
1189 1205 # there may be SyntaxError cases whith imported code.
1190 1206 if exc_tuple is None:
1191 1207 type, value, tb = sys.exc_info()
1192 1208 else:
1193 1209 type, value, tb = exc_tuple
1194 1210 if type is SyntaxError:
1195 1211 self.showsyntaxerror(filename)
1196 1212 else:
1197 1213 sys.last_type = type
1198 1214 sys.last_value = value
1199 1215 sys.last_traceback = tb
1200 1216 self.InteractiveTB()
1201 1217 if self.InteractiveTB.call_pdb and self.has_readline:
1202 1218 # pdb mucks up readline, fix it back
1203 1219 self.readline.set_completer(self.Completer.complete)
1204 1220
1205 1221 def update_cache(self, line):
1206 1222 """puts line into cache"""
1207 1223 self.inputcache.insert(0, line) # This copies the cache every time ... :-(
1208 1224 if len(self.inputcache) >= self.CACHELENGTH:
1209 1225 self.inputcache.pop() # This doesn't :-)
1210 1226
1211 1227 def mainloop(self,banner=None):
1212 1228 """Creates the local namespace and starts the mainloop.
1213 1229
1214 1230 If an optional banner argument is given, it will override the
1215 1231 internally created default banner."""
1216 1232
1217 1233 if self.rc.c: # Emulate Python's -c option
1218 1234 self.exec_init_cmd()
1219 1235 if banner is None:
1220 1236 if self.rc.banner:
1221 1237 banner = self.BANNER+self.banner2
1222 1238 else:
1223 1239 banner = ''
1224 1240 self.interact(banner)
1225 1241
1226 1242 def exec_init_cmd(self):
1227 1243 """Execute a command given at the command line.
1228 1244
1229 1245 This emulates Python's -c option."""
1230 1246
1231 1247 sys.argv = ['-c']
1232 1248 self.push(self.rc.c)
1233 1249
1234 1250 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1235 1251 """Embeds IPython into a running python program.
1236 1252
1237 1253 Input:
1238 1254
1239 1255 - header: An optional header message can be specified.
1240 1256
1241 1257 - local_ns, global_ns: working namespaces. If given as None, the
1242 1258 IPython-initialized one is updated with __main__.__dict__, so that
1243 1259 program variables become visible but user-specific configuration
1244 1260 remains possible.
1245 1261
1246 1262 - stack_depth: specifies how many levels in the stack to go to
1247 1263 looking for namespaces (when local_ns and global_ns are None). This
1248 1264 allows an intermediate caller to make sure that this function gets
1249 1265 the namespace from the intended level in the stack. By default (0)
1250 1266 it will get its locals and globals from the immediate caller.
1251 1267
1252 1268 Warning: it's possible to use this in a program which is being run by
1253 1269 IPython itself (via %run), but some funny things will happen (a few
1254 1270 globals get overwritten). In the future this will be cleaned up, as
1255 1271 there is no fundamental reason why it can't work perfectly."""
1256 1272
1257 1273 # Get locals and globals from caller
1258 1274 if local_ns is None or global_ns is None:
1259 1275 call_frame = sys._getframe(stack_depth).f_back
1260 1276
1261 1277 if local_ns is None:
1262 1278 local_ns = call_frame.f_locals
1263 1279 if global_ns is None:
1264 1280 global_ns = call_frame.f_globals
1265 1281
1266 1282 # Update namespaces and fire up interpreter
1267 1283 self.user_ns = local_ns
1268 1284 self.user_global_ns = global_ns
1269 1285
1270 1286 # Patch for global embedding to make sure that things don't overwrite
1271 1287 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1272 1288 # FIXME. Test this a bit more carefully (the if.. is new)
1273 1289 if local_ns is None and global_ns is None:
1274 1290 self.user_global_ns.update(__main__.__dict__)
1275 1291
1276 1292 # make sure the tab-completer has the correct frame information, so it
1277 1293 # actually completes using the frame's locals/globals
1278 1294 self.set_completer_frame(call_frame)
1279 1295
1280 1296 self.interact(header)
1281 1297
1282 1298 def interact(self, banner=None):
1283 1299 """Closely emulate the interactive Python console.
1284 1300
1285 1301 The optional banner argument specify the banner to print
1286 1302 before the first interaction; by default it prints a banner
1287 1303 similar to the one printed by the real Python interpreter,
1288 1304 followed by the current class name in parentheses (so as not
1289 1305 to confuse this with the real interpreter -- since it's so
1290 1306 close!).
1291 1307
1292 1308 """
1293 1309 cprt = 'Type "copyright", "credits" or "license" for more information.'
1294 1310 if banner is None:
1295 1311 self.write("Python %s on %s\n%s\n(%s)\n" %
1296 1312 (sys.version, sys.platform, cprt,
1297 1313 self.__class__.__name__))
1298 1314 else:
1299 1315 self.write(banner)
1300 1316
1301 1317 more = 0
1302 1318
1303 1319 # Mark activity in the builtins
1304 1320 __builtin__.__dict__['__IPYTHON__active'] += 1
1305 1321
1306 1322 # compiled regexps for autoindent management
1307 1323 ini_spaces_re = re.compile(r'^(\s+)')
1308 1324 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
1309 1325
1310 1326 # exit_now is set by a call to %Exit or %Quit
1311 1327 while not self.exit_now:
1312 1328 try:
1313 1329 if more:
1314 1330 prompt = self.outputcache.prompt2
1315 1331 if self.autoindent:
1316 1332 self.readline_startup_hook(self.pre_readline)
1317 1333 else:
1318 1334 prompt = self.outputcache.prompt1
1319 1335 try:
1320 1336 line = self.raw_input(prompt,more)
1321 1337 if self.autoindent:
1322 1338 self.readline_startup_hook(None)
1323 1339 except EOFError:
1324 1340 if self.autoindent:
1325 1341 self.readline_startup_hook(None)
1326 1342 self.write("\n")
1327 1343 self.exit()
1328 1344 else:
1329 1345 more = self.push(line)
1330 1346 # Auto-indent management
1331 1347 if self.autoindent:
1332 1348 if line:
1333 1349 ini_spaces = ini_spaces_re.match(line)
1334 1350 if ini_spaces:
1335 1351 nspaces = ini_spaces.end()
1336 1352 else:
1337 1353 nspaces = 0
1338 1354 self.indent_current_nsp = nspaces
1339 1355
1340 1356 if line[-1] == ':':
1341 1357 self.indent_current_nsp += 4
1342 1358 elif dedent_re.match(line):
1343 1359 self.indent_current_nsp -= 4
1344 1360 else:
1345 1361 self.indent_current_nsp = 0
1346 1362
1347 1363 # indent_current is the actual string to be inserted
1348 1364 # by the readline hooks for indentation
1349 1365 self.indent_current = ' '* self.indent_current_nsp
1350 1366
1351 1367 if (self.SyntaxTB.last_syntax_error and
1352 1368 self.rc.autoedit_syntax):
1353 1369 self.edit_syntax_error()
1354 1370
1355 1371 except KeyboardInterrupt:
1356 1372 self.write("\nKeyboardInterrupt\n")
1357 1373 self.resetbuffer()
1358 1374 more = 0
1359 1375 # keep cache in sync with the prompt counter:
1360 1376 self.outputcache.prompt_count -= 1
1361 1377
1362 1378 if self.autoindent:
1363 1379 self.indent_current_nsp = 0
1364 1380 self.indent_current = ' '* self.indent_current_nsp
1365 1381
1366 1382 except bdb.BdbQuit:
1367 1383 warn("The Python debugger has exited with a BdbQuit exception.\n"
1368 1384 "Because of how pdb handles the stack, it is impossible\n"
1369 1385 "for IPython to properly format this particular exception.\n"
1370 1386 "IPython will resume normal operation.")
1371 1387
1372 1388 # We are off again...
1373 1389 __builtin__.__dict__['__IPYTHON__active'] -= 1
1374 1390
1375 1391 def excepthook(self, type, value, tb):
1376 1392 """One more defense for GUI apps that call sys.excepthook.
1377 1393
1378 1394 GUI frameworks like wxPython trap exceptions and call
1379 1395 sys.excepthook themselves. I guess this is a feature that
1380 1396 enables them to keep running after exceptions that would
1381 1397 otherwise kill their mainloop. This is a bother for IPython
1382 1398 which excepts to catch all of the program exceptions with a try:
1383 1399 except: statement.
1384 1400
1385 1401 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1386 1402 any app directly invokes sys.excepthook, it will look to the user like
1387 1403 IPython crashed. In order to work around this, we can disable the
1388 1404 CrashHandler and replace it with this excepthook instead, which prints a
1389 1405 regular traceback using our InteractiveTB. In this fashion, apps which
1390 1406 call sys.excepthook will generate a regular-looking exception from
1391 1407 IPython, and the CrashHandler will only be triggered by real IPython
1392 1408 crashes.
1393 1409
1394 1410 This hook should be used sparingly, only in places which are not likely
1395 1411 to be true IPython errors.
1396 1412 """
1397 1413
1398 1414 self.InteractiveTB(type, value, tb, tb_offset=0)
1399 1415 if self.InteractiveTB.call_pdb and self.has_readline:
1400 1416 self.readline.set_completer(self.Completer.complete)
1401 1417
1402 1418 def call_alias(self,alias,rest=''):
1403 1419 """Call an alias given its name and the rest of the line.
1404 1420
1405 1421 This function MUST be given a proper alias, because it doesn't make
1406 1422 any checks when looking up into the alias table. The caller is
1407 1423 responsible for invoking it only with a valid alias."""
1408 1424
1409 1425 #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg
1410 1426 nargs,cmd = self.alias_table[alias]
1411 1427 # Expand the %l special to be the user's input line
1412 1428 if cmd.find('%l') >= 0:
1413 1429 cmd = cmd.replace('%l',rest)
1414 1430 rest = ''
1415 1431 if nargs==0:
1416 1432 # Simple, argument-less aliases
1417 1433 cmd = '%s %s' % (cmd,rest)
1418 1434 else:
1419 1435 # Handle aliases with positional arguments
1420 1436 args = rest.split(None,nargs)
1421 1437 if len(args)< nargs:
1422 1438 error('Alias <%s> requires %s arguments, %s given.' %
1423 1439 (alias,nargs,len(args)))
1424 1440 return
1425 1441 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1426 1442 # Now call the macro, evaluating in the user's namespace
1427 1443 try:
1428 1444 self.system(cmd)
1429 1445 except:
1430 1446 self.showtraceback()
1431 1447
1432 1448 def runlines(self,lines):
1433 1449 """Run a string of one or more lines of source.
1434 1450
1435 1451 This method is capable of running a string containing multiple source
1436 1452 lines, as if they had been entered at the IPython prompt. Since it
1437 1453 exposes IPython's processing machinery, the given strings can contain
1438 1454 magic calls (%magic), special shell access (!cmd), etc."""
1439 1455
1440 1456 # We must start with a clean buffer, in case this is run from an
1441 1457 # interactive IPython session (via a magic, for example).
1442 1458 self.resetbuffer()
1443 1459 lines = lines.split('\n')
1444 1460 more = 0
1445 1461 for line in lines:
1446 1462 # skip blank lines so we don't mess up the prompt counter, but do
1447 1463 # NOT skip even a blank line if we are in a code block (more is
1448 1464 # true)
1449 1465 if line or more:
1450 1466 more = self.push((self.prefilter(line,more)))
1451 1467 # IPython's runsource returns None if there was an error
1452 1468 # compiling the code. This allows us to stop processing right
1453 1469 # away, so the user gets the error message at the right place.
1454 1470 if more is None:
1455 1471 break
1456 1472 # final newline in case the input didn't have it, so that the code
1457 1473 # actually does get executed
1458 1474 if more:
1459 1475 self.push('\n')
1460 1476
1461 1477 def runsource(self, source, filename='<input>', symbol='single'):
1462 1478 """Compile and run some source in the interpreter.
1463 1479
1464 1480 Arguments are as for compile_command().
1465 1481
1466 1482 One several things can happen:
1467 1483
1468 1484 1) The input is incorrect; compile_command() raised an
1469 1485 exception (SyntaxError or OverflowError). A syntax traceback
1470 1486 will be printed by calling the showsyntaxerror() method.
1471 1487
1472 1488 2) The input is incomplete, and more input is required;
1473 1489 compile_command() returned None. Nothing happens.
1474 1490
1475 1491 3) The input is complete; compile_command() returned a code
1476 1492 object. The code is executed by calling self.runcode() (which
1477 1493 also handles run-time exceptions, except for SystemExit).
1478 1494
1479 1495 The return value is:
1480 1496
1481 1497 - True in case 2
1482 1498
1483 1499 - False in the other cases, unless an exception is raised, where
1484 1500 None is returned instead. This can be used by external callers to
1485 1501 know whether to continue feeding input or not.
1486 1502
1487 1503 The return value can be used to decide whether to use sys.ps1 or
1488 1504 sys.ps2 to prompt the next line."""
1489 1505
1490 1506 try:
1491 1507 code = self.compile(source,filename,symbol)
1492 1508 except (OverflowError, SyntaxError, ValueError):
1493 1509 # Case 1
1494 1510 self.showsyntaxerror(filename)
1495 1511 return None
1496 1512
1497 1513 if code is None:
1498 1514 # Case 2
1499 1515 return True
1500 1516
1501 1517 # Case 3
1502 1518 # We store the code object so that threaded shells and
1503 1519 # custom exception handlers can access all this info if needed.
1504 1520 # The source corresponding to this can be obtained from the
1505 1521 # buffer attribute as '\n'.join(self.buffer).
1506 1522 self.code_to_run = code
1507 1523 # now actually execute the code object
1508 1524 if self.runcode(code) == 0:
1509 1525 return False
1510 1526 else:
1511 1527 return None
1512 1528
1513 1529 def runcode(self,code_obj):
1514 1530 """Execute a code object.
1515 1531
1516 1532 When an exception occurs, self.showtraceback() is called to display a
1517 1533 traceback.
1518 1534
1519 1535 Return value: a flag indicating whether the code to be run completed
1520 1536 successfully:
1521 1537
1522 1538 - 0: successful execution.
1523 1539 - 1: an error occurred.
1524 1540 """
1525 1541
1526 1542 # Set our own excepthook in case the user code tries to call it
1527 1543 # directly, so that the IPython crash handler doesn't get triggered
1528 1544 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1529 1545
1530 1546 # we save the original sys.excepthook in the instance, in case config
1531 1547 # code (such as magics) needs access to it.
1532 1548 self.sys_excepthook = old_excepthook
1533 1549 outflag = 1 # happens in more places, so it's easier as default
1534 1550 try:
1535 1551 try:
1536 1552 # Embedded instances require separate global/local namespaces
1537 1553 # so they can see both the surrounding (local) namespace and
1538 1554 # the module-level globals when called inside another function.
1539 1555 if self.embedded:
1540 1556 exec code_obj in self.user_global_ns, self.user_ns
1541 1557 # Normal (non-embedded) instances should only have a single
1542 1558 # namespace for user code execution, otherwise functions won't
1543 1559 # see interactive top-level globals.
1544 1560 else:
1545 1561 exec code_obj in self.user_ns
1546 1562 finally:
1547 1563 # Reset our crash handler in place
1548 1564 sys.excepthook = old_excepthook
1549 1565 except SystemExit:
1550 1566 self.resetbuffer()
1551 1567 self.showtraceback()
1552 1568 warn("Type exit or quit to exit IPython "
1553 1569 "(%Exit or %Quit do so unconditionally).",level=1)
1554 1570 except self.custom_exceptions:
1555 1571 etype,value,tb = sys.exc_info()
1556 1572 self.CustomTB(etype,value,tb)
1557 1573 except:
1558 1574 self.showtraceback()
1559 1575 else:
1560 1576 outflag = 0
1561 1577 if softspace(sys.stdout, 0):
1562 1578 print
1563 1579 # Flush out code object which has been run (and source)
1564 1580 self.code_to_run = None
1565 1581 return outflag
1566 1582
1567 1583 def push(self, line):
1568 1584 """Push a line to the interpreter.
1569 1585
1570 1586 The line should not have a trailing newline; it may have
1571 1587 internal newlines. The line is appended to a buffer and the
1572 1588 interpreter's runsource() method is called with the
1573 1589 concatenated contents of the buffer as source. If this
1574 1590 indicates that the command was executed or invalid, the buffer
1575 1591 is reset; otherwise, the command is incomplete, and the buffer
1576 1592 is left as it was after the line was appended. The return
1577 1593 value is 1 if more input is required, 0 if the line was dealt
1578 1594 with in some way (this is the same as runsource()).
1579 1595
1580 1596 """
1581 1597 self.buffer.append(line)
1582 1598 more = self.runsource('\n'.join(self.buffer), self.filename)
1583 1599 if not more:
1584 1600 self.resetbuffer()
1585 1601 return more
1586 1602
1587 1603 def resetbuffer(self):
1588 1604 """Reset the input buffer."""
1589 1605 self.buffer[:] = []
1590 1606
1591 1607 def raw_input(self,prompt='',continue_prompt=False):
1592 1608 """Write a prompt and read a line.
1593 1609
1594 1610 The returned line does not include the trailing newline.
1595 1611 When the user enters the EOF key sequence, EOFError is raised.
1596 1612
1597 1613 Optional inputs:
1598 1614
1599 1615 - prompt(''): a string to be printed to prompt the user.
1600 1616
1601 1617 - continue_prompt(False): whether this line is the first one or a
1602 1618 continuation in a sequence of inputs.
1603 1619 """
1604 1620
1605 1621 line = raw_input_original(prompt)
1606 1622 # Try to be reasonably smart about not re-indenting pasted input more
1607 1623 # than necessary. We do this by trimming out the auto-indent initial
1608 1624 # spaces, if the user's actual input started itself with whitespace.
1609 1625 if self.autoindent:
1610 1626 line2 = line[self.indent_current_nsp:]
1611 1627 if line2[0:1] in (' ','\t'):
1612 1628 line = line2
1613 1629 return self.prefilter(line,continue_prompt)
1614 1630
1615 1631 def split_user_input(self,line):
1616 1632 """Split user input into pre-char, function part and rest."""
1617 1633
1618 1634 lsplit = self.line_split.match(line)
1619 1635 if lsplit is None: # no regexp match returns None
1620 1636 try:
1621 1637 iFun,theRest = line.split(None,1)
1622 1638 except ValueError:
1623 1639 iFun,theRest = line,''
1624 1640 pre = re.match('^(\s*)(.*)',line).groups()[0]
1625 1641 else:
1626 1642 pre,iFun,theRest = lsplit.groups()
1627 1643
1628 1644 #print 'line:<%s>' % line # dbg
1629 1645 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
1630 1646 return pre,iFun.strip(),theRest
1631 1647
1632 1648 def _prefilter(self, line, continue_prompt):
1633 1649 """Calls different preprocessors, depending on the form of line."""
1634 1650
1635 1651 # All handlers *must* return a value, even if it's blank ('').
1636 1652
1637 1653 # Lines are NOT logged here. Handlers should process the line as
1638 1654 # needed, update the cache AND log it (so that the input cache array
1639 1655 # stays synced).
1640 1656
1641 1657 # This function is _very_ delicate, and since it's also the one which
1642 1658 # determines IPython's response to user input, it must be as efficient
1643 1659 # as possible. For this reason it has _many_ returns in it, trying
1644 1660 # always to exit as quickly as it can figure out what it needs to do.
1645 1661
1646 1662 # This function is the main responsible for maintaining IPython's
1647 1663 # behavior respectful of Python's semantics. So be _very_ careful if
1648 1664 # making changes to anything here.
1649 1665
1650 1666 #.....................................................................
1651 1667 # Code begins
1652 1668
1653 1669 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
1654 1670
1655 1671 # save the line away in case we crash, so the post-mortem handler can
1656 1672 # record it
1657 1673 self._last_input_line = line
1658 1674
1659 1675 #print '***line: <%s>' % line # dbg
1660 1676
1661 1677 # the input history needs to track even empty lines
1662 1678 if not line.strip():
1663 1679 if not continue_prompt:
1664 1680 self.outputcache.prompt_count -= 1
1665 1681 return self.handle_normal(line,continue_prompt)
1666 1682 #return self.handle_normal('',continue_prompt)
1667 1683
1668 1684 # print '***cont',continue_prompt # dbg
1669 1685 # special handlers are only allowed for single line statements
1670 1686 if continue_prompt and not self.rc.multi_line_specials:
1671 1687 return self.handle_normal(line,continue_prompt)
1672 1688
1673 1689 # For the rest, we need the structure of the input
1674 1690 pre,iFun,theRest = self.split_user_input(line)
1675 1691 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1676 1692
1677 1693 # First check for explicit escapes in the last/first character
1678 1694 handler = None
1679 1695 if line[-1] == self.ESC_HELP:
1680 1696 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
1681 1697 if handler is None:
1682 1698 # look at the first character of iFun, NOT of line, so we skip
1683 1699 # leading whitespace in multiline input
1684 1700 handler = self.esc_handlers.get(iFun[0:1])
1685 1701 if handler is not None:
1686 1702 return handler(line,continue_prompt,pre,iFun,theRest)
1687 1703 # Emacs ipython-mode tags certain input lines
1688 1704 if line.endswith('# PYTHON-MODE'):
1689 1705 return self.handle_emacs(line,continue_prompt)
1690 1706
1691 1707 # Next, check if we can automatically execute this thing
1692 1708
1693 1709 # Allow ! in multi-line statements if multi_line_specials is on:
1694 1710 if continue_prompt and self.rc.multi_line_specials and \
1695 1711 iFun.startswith(self.ESC_SHELL):
1696 1712 return self.handle_shell_escape(line,continue_prompt,
1697 1713 pre=pre,iFun=iFun,
1698 1714 theRest=theRest)
1699 1715
1700 1716 # Let's try to find if the input line is a magic fn
1701 1717 oinfo = None
1702 1718 if hasattr(self,'magic_'+iFun):
1703 1719 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1704 1720 if oinfo['ismagic']:
1705 1721 # Be careful not to call magics when a variable assignment is
1706 1722 # being made (ls='hi', for example)
1707 1723 if self.rc.automagic and \
1708 1724 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
1709 1725 (self.rc.multi_line_specials or not continue_prompt):
1710 1726 return self.handle_magic(line,continue_prompt,
1711 1727 pre,iFun,theRest)
1712 1728 else:
1713 1729 return self.handle_normal(line,continue_prompt)
1714 1730
1715 1731 # If the rest of the line begins with an (in)equality, assginment or
1716 1732 # function call, we should not call _ofind but simply execute it.
1717 1733 # This avoids spurious geattr() accesses on objects upon assignment.
1718 1734 #
1719 1735 # It also allows users to assign to either alias or magic names true
1720 1736 # python variables (the magic/alias systems always take second seat to
1721 1737 # true python code).
1722 1738 if theRest and theRest[0] in '!=()':
1723 1739 return self.handle_normal(line,continue_prompt)
1724 1740
1725 1741 if oinfo is None:
1726 1742 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1727 1743
1728 1744 if not oinfo['found']:
1729 1745 return self.handle_normal(line,continue_prompt)
1730 1746 else:
1731 1747 #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg
1732 1748 if oinfo['isalias']:
1733 1749 return self.handle_alias(line,continue_prompt,
1734 1750 pre,iFun,theRest)
1735 1751
1736 1752 if self.rc.autocall and \
1737 1753 not self.re_exclude_auto.match(theRest) and \
1738 1754 self.re_fun_name.match(iFun) and \
1739 1755 callable(oinfo['obj']) :
1740 1756 #print 'going auto' # dbg
1741 1757 return self.handle_auto(line,continue_prompt,pre,iFun,theRest)
1742 1758 else:
1743 1759 #print 'was callable?', callable(oinfo['obj']) # dbg
1744 1760 return self.handle_normal(line,continue_prompt)
1745 1761
1746 1762 # If we get here, we have a normal Python line. Log and return.
1747 1763 return self.handle_normal(line,continue_prompt)
1748 1764
1749 1765 def _prefilter_dumb(self, line, continue_prompt):
1750 1766 """simple prefilter function, for debugging"""
1751 1767 return self.handle_normal(line,continue_prompt)
1752 1768
1753 1769 # Set the default prefilter() function (this can be user-overridden)
1754 1770 prefilter = _prefilter
1755 1771
1756 1772 def handle_normal(self,line,continue_prompt=None,
1757 1773 pre=None,iFun=None,theRest=None):
1758 1774 """Handle normal input lines. Use as a template for handlers."""
1759 1775
1760 1776 # With autoindent on, we need some way to exit the input loop, and I
1761 1777 # don't want to force the user to have to backspace all the way to
1762 1778 # clear the line. The rule will be in this case, that either two
1763 1779 # lines of pure whitespace in a row, or a line of pure whitespace but
1764 1780 # of a size different to the indent level, will exit the input loop.
1765 1781 if (continue_prompt and self.autoindent and isspace(line) and
1766 1782 (line != self.indent_current or isspace(self.buffer[-1]))):
1767 1783 line = ''
1768 1784
1769 1785 self.log(line,continue_prompt)
1770 1786 self.update_cache(line)
1771 1787 return line
1772 1788
1773 1789 def handle_alias(self,line,continue_prompt=None,
1774 1790 pre=None,iFun=None,theRest=None):
1775 1791 """Handle alias input lines. """
1776 1792
1777 1793 theRest = esc_quotes(theRest)
1778 1794 # log the ipalias form, which doesn't depend on the instance name
1779 1795 line_log = 'ipalias("%s %s")' % (iFun,theRest)
1780 1796 self.log(line_log,continue_prompt)
1781 1797 self.update_cache(line_log)
1782 1798 # this is what actually gets executed
1783 1799 return "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1784 1800
1785 1801 def handle_shell_escape(self, line, continue_prompt=None,
1786 1802 pre=None,iFun=None,theRest=None):
1787 1803 """Execute the line in a shell, empty return value"""
1788 1804
1789 1805 #print 'line in :', `line` # dbg
1790 1806 # Example of a special handler. Others follow a similar pattern.
1791 1807 if continue_prompt: # multi-line statements
1792 1808 if iFun.startswith('!!'):
1793 1809 print 'SyntaxError: !! is not allowed in multiline statements'
1794 1810 return pre
1795 1811 else:
1796 1812 cmd = ("%s %s" % (iFun[1:],theRest)) #.replace('"','\\"')
1797 1813 #line_out = '%s%s.system("%s")' % (pre,self.name,cmd)
1798 1814 line_out = '%s%s.system(r"""%s"""[:-1])' % (pre,self.name,cmd + "_")
1799 1815 #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')'
1800 1816 else: # single-line input
1801 1817 if line.startswith('!!'):
1802 1818 # rewrite iFun/theRest to properly hold the call to %sx and
1803 1819 # the actual command to be executed, so handle_magic can work
1804 1820 # correctly
1805 1821 theRest = '%s %s' % (iFun[2:],theRest)
1806 1822 iFun = 'sx'
1807 1823 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]),
1808 1824 continue_prompt,pre,iFun,theRest)
1809 1825 else:
1810 1826 #cmd = esc_quotes(line[1:])
1811 1827 cmd=line[1:]
1812 1828 #line_out = '%s.system("%s")' % (self.name,cmd)
1813 1829 line_out = '%s.system(r"""%s"""[:-1])' % (self.name,cmd +"_")
1814 1830 #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')'
1815 1831 # update cache/log and return
1816 1832 self.log(line_out,continue_prompt)
1817 1833 self.update_cache(line_out) # readline cache gets normal line
1818 1834 #print 'line out r:', `line_out` # dbg
1819 1835 #print 'line out s:', line_out # dbg
1820 1836 return line_out
1821 1837
1822 1838 def handle_magic(self, line, continue_prompt=None,
1823 1839 pre=None,iFun=None,theRest=None):
1824 1840 """Execute magic functions.
1825 1841
1826 1842 Also log them with a prepended # so the log is clean Python."""
1827 1843
1828 1844 cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest)))
1829 1845 self.log(cmd,continue_prompt)
1830 1846 self.update_cache(line)
1831 1847 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
1832 1848 return cmd
1833 1849
1834 1850 def handle_auto(self, line, continue_prompt=None,
1835 1851 pre=None,iFun=None,theRest=None):
1836 1852 """Hande lines which can be auto-executed, quoting if requested."""
1837 1853
1838 1854 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1839 1855
1840 1856 # This should only be active for single-line input!
1841 1857 if continue_prompt:
1842 1858 return line
1843 1859
1844 1860 if pre == self.ESC_QUOTE:
1845 1861 # Auto-quote splitting on whitespace
1846 1862 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
1847 1863 elif pre == self.ESC_QUOTE2:
1848 1864 # Auto-quote whole string
1849 1865 newcmd = '%s("%s")' % (iFun,theRest)
1850 1866 else:
1851 1867 # Auto-paren
1852 1868 if theRest[0:1] in ('=','['):
1853 1869 # Don't autocall in these cases. They can be either
1854 1870 # rebindings of an existing callable's name, or item access
1855 1871 # for an object which is BOTH callable and implements
1856 1872 # __getitem__.
1857 1873 return '%s %s' % (iFun,theRest)
1858 1874 if theRest.endswith(';'):
1859 1875 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
1860 1876 else:
1861 1877 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1862 1878
1863 1879 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
1864 1880 # log what is now valid Python, not the actual user input (without the
1865 1881 # final newline)
1866 1882 self.log(newcmd,continue_prompt)
1867 1883 return newcmd
1868 1884
1869 1885 def handle_help(self, line, continue_prompt=None,
1870 1886 pre=None,iFun=None,theRest=None):
1871 1887 """Try to get some help for the object.
1872 1888
1873 1889 obj? or ?obj -> basic information.
1874 1890 obj?? or ??obj -> more details.
1875 1891 """
1876 1892
1877 1893 # We need to make sure that we don't process lines which would be
1878 1894 # otherwise valid python, such as "x=1 # what?"
1879 1895 try:
1880 1896 codeop.compile_command(line)
1881 1897 except SyntaxError:
1882 1898 # We should only handle as help stuff which is NOT valid syntax
1883 1899 if line[0]==self.ESC_HELP:
1884 1900 line = line[1:]
1885 1901 elif line[-1]==self.ESC_HELP:
1886 1902 line = line[:-1]
1887 1903 self.log('#?'+line)
1888 1904 self.update_cache(line)
1889 1905 if line:
1890 1906 self.magic_pinfo(line)
1891 1907 else:
1892 1908 page(self.usage,screen_lines=self.rc.screen_length)
1893 1909 return '' # Empty string is needed here!
1894 1910 except:
1895 1911 # Pass any other exceptions through to the normal handler
1896 1912 return self.handle_normal(line,continue_prompt)
1897 1913 else:
1898 1914 # If the code compiles ok, we should handle it normally
1899 1915 return self.handle_normal(line,continue_prompt)
1900 1916
1901 1917 def handle_emacs(self,line,continue_prompt=None,
1902 1918 pre=None,iFun=None,theRest=None):
1903 1919 """Handle input lines marked by python-mode."""
1904 1920
1905 1921 # Currently, nothing is done. Later more functionality can be added
1906 1922 # here if needed.
1907 1923
1908 1924 # The input cache shouldn't be updated
1909 1925
1910 1926 return line
1911 1927
1912 1928 def write(self,data):
1913 1929 """Write a string to the default output"""
1914 1930 Term.cout.write(data)
1915 1931
1916 1932 def write_err(self,data):
1917 1933 """Write a string to the default error output"""
1918 1934 Term.cerr.write(data)
1919 1935
1920 1936 def exit(self):
1921 1937 """Handle interactive exit.
1922 1938
1923 1939 This method sets the exit_now attribute."""
1924 1940
1925 1941 if self.rc.confirm_exit:
1926 1942 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
1927 1943 self.exit_now = True
1928 1944 else:
1929 1945 self.exit_now = True
1930 1946 return self.exit_now
1931 1947
1932 1948 def safe_execfile(self,fname,*where,**kw):
1933 1949 fname = os.path.expanduser(fname)
1934 1950
1935 1951 # find things also in current directory
1936 1952 dname = os.path.dirname(fname)
1937 1953 if not sys.path.count(dname):
1938 1954 sys.path.append(dname)
1939 1955
1940 1956 try:
1941 1957 xfile = open(fname)
1942 1958 except:
1943 1959 print >> Term.cerr, \
1944 1960 'Could not open file <%s> for safe execution.' % fname
1945 1961 return None
1946 1962
1947 1963 kw.setdefault('islog',0)
1948 1964 kw.setdefault('quiet',1)
1949 1965 kw.setdefault('exit_ignore',0)
1950 1966 first = xfile.readline()
1951 1967 loghead = str(self.loghead_tpl).split('\n',1)[0].strip()
1952 1968 xfile.close()
1953 1969 # line by line execution
1954 1970 if first.startswith(loghead) or kw['islog']:
1955 1971 print 'Loading log file <%s> one line at a time...' % fname
1956 1972 if kw['quiet']:
1957 1973 stdout_save = sys.stdout
1958 1974 sys.stdout = StringIO.StringIO()
1959 1975 try:
1960 1976 globs,locs = where[0:2]
1961 1977 except:
1962 1978 try:
1963 1979 globs = locs = where[0]
1964 1980 except:
1965 1981 globs = locs = globals()
1966 1982 badblocks = []
1967 1983
1968 1984 # we also need to identify indented blocks of code when replaying
1969 1985 # logs and put them together before passing them to an exec
1970 1986 # statement. This takes a bit of regexp and look-ahead work in the
1971 1987 # file. It's easiest if we swallow the whole thing in memory
1972 1988 # first, and manually walk through the lines list moving the
1973 1989 # counter ourselves.
1974 1990 indent_re = re.compile('\s+\S')
1975 1991 xfile = open(fname)
1976 1992 filelines = xfile.readlines()
1977 1993 xfile.close()
1978 1994 nlines = len(filelines)
1979 1995 lnum = 0
1980 1996 while lnum < nlines:
1981 1997 line = filelines[lnum]
1982 1998 lnum += 1
1983 1999 # don't re-insert logger status info into cache
1984 2000 if line.startswith('#log#'):
1985 2001 continue
1986 2002 elif line.startswith('#!'):
1987 2003 self.update_cache(line[1:])
1988 2004 else:
1989 2005 # build a block of code (maybe a single line) for execution
1990 2006 block = line
1991 2007 try:
1992 2008 next = filelines[lnum] # lnum has already incremented
1993 2009 except:
1994 2010 next = None
1995 2011 while next and indent_re.match(next):
1996 2012 block += next
1997 2013 lnum += 1
1998 2014 try:
1999 2015 next = filelines[lnum]
2000 2016 except:
2001 2017 next = None
2002 2018 # now execute the block of one or more lines
2003 2019 try:
2004 2020 exec block in globs,locs
2005 2021 self.update_cache(block.rstrip())
2006 2022 except SystemExit:
2007 2023 pass
2008 2024 except:
2009 2025 badblocks.append(block.rstrip())
2010 2026 if kw['quiet']: # restore stdout
2011 2027 sys.stdout.close()
2012 2028 sys.stdout = stdout_save
2013 2029 print 'Finished replaying log file <%s>' % fname
2014 2030 if badblocks:
2015 2031 print >> sys.stderr, ('\nThe following lines/blocks in file '
2016 2032 '<%s> reported errors:' % fname)
2017 2033
2018 2034 for badline in badblocks:
2019 2035 print >> sys.stderr, badline
2020 2036 else: # regular file execution
2021 2037 try:
2022 2038 execfile(fname,*where)
2023 2039 except SyntaxError:
2024 2040 etype,evalue = sys.exc_info()[:2]
2025 2041 self.SyntaxTB(etype,evalue,[])
2026 2042 warn('Failure executing file: <%s>' % fname)
2027 2043 except SystemExit,status:
2028 2044 if not kw['exit_ignore']:
2029 2045 self.InteractiveTB()
2030 2046 warn('Failure executing file: <%s>' % fname)
2031 2047 except:
2032 2048 self.InteractiveTB()
2033 2049 warn('Failure executing file: <%s>' % fname)
2034 2050
2035 2051 #************************* end of file <iplib.py> *****************************
@@ -1,4627 +1,4631 b''
1 1 2005-12-29 Fernando Perez <Fernando.Perez@colorado.edu>
2 2
3 3 * IPython/Magic.py (Macro): simplified Macro class to just
4 4 subclass list. We've had only 2.2 compatibility for a very long
5 5 time, yet I was still avoiding subclassing the builtin types. No
6 6 more (I'm also starting to use properties, though I won't shift to
7 7 2.3-specific features quite yet).
8 (magic_store): added Ville's patch for lightweight variable
9 persistence, after a request on the user list by Matt Wilkie
10 <maphew at gmail.com>. The new %store magic's docstring has full
11 details.
8 12
9 13 * IPython/iplib.py (InteractiveShell.post_config_initialization):
10 14 changed the default logfile name from 'ipython.log' to
11 15 'ipython_log.py'. These logs are real python files, and now that
12 16 we have much better multiline support, people are more likely to
13 17 want to use them as such. Might as well name them correctly.
14 18
15 19 * IPython/Magic.py: substantial cleanup. While we can't stop
16 20 using magics as mixins, due to the existing customizations 'out
17 21 there' which rely on the mixin naming conventions, at least I
18 22 cleaned out all cross-class name usage. So once we are OK with
19 23 breaking compatibility, the two systems can be separated.
20 24
21 25 * IPython/Logger.py: major cleanup. This one is NOT a mixin
22 26 anymore, and the class is a fair bit less hideous as well. New
23 27 features were also introduced: timestamping of input, and logging
24 28 of output results. These are user-visible with the -t and -o
25 29 options to %logstart. Closes
26 30 http://www.scipy.net/roundup/ipython/issue11 and a request by
27 31 William Stein (SAGE developer - http://modular.ucsd.edu/sage).
28 32
29 33 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
30 34
31 35 * IPython/iplib.py (handle_shell_escape): add Ville's patch to
32 36 better hadnle backslashes in paths. See the thread 'More Windows
33 37 questions part 2 - \/ characters revisited' on the iypthon user
34 38 list:
35 39 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
36 40
37 41 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
38 42
39 43 (InteractiveShell.__init__): change threaded shells to not use the
40 44 ipython crash handler. This was causing more problems than not,
41 45 as exceptions in the main thread (GUI code, typically) would
42 46 always show up as a 'crash', when they really weren't.
43 47
44 48 The colors and exception mode commands (%colors/%xmode) have been
45 49 synchronized to also take this into account, so users can get
46 50 verbose exceptions for their threaded code as well. I also added
47 51 support for activating pdb inside this exception handler as well,
48 52 so now GUI authors can use IPython's enhanced pdb at runtime.
49 53
50 54 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
51 55 true by default, and add it to the shipped ipythonrc file. Since
52 56 this asks the user before proceeding, I think it's OK to make it
53 57 true by default.
54 58
55 59 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
56 60 of the previous special-casing of input in the eval loop. I think
57 61 this is cleaner, as they really are commands and shouldn't have
58 62 a special role in the middle of the core code.
59 63
60 64 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
61 65
62 66 * IPython/iplib.py (edit_syntax_error): added support for
63 67 automatically reopening the editor if the file had a syntax error
64 68 in it. Thanks to scottt who provided the patch at:
65 69 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
66 70 version committed).
67 71
68 72 * IPython/iplib.py (handle_normal): add suport for multi-line
69 73 input with emtpy lines. This fixes
70 74 http://www.scipy.net/roundup/ipython/issue43 and a similar
71 75 discussion on the user list.
72 76
73 77 WARNING: a behavior change is necessarily introduced to support
74 78 blank lines: now a single blank line with whitespace does NOT
75 79 break the input loop, which means that when autoindent is on, by
76 80 default hitting return on the next (indented) line does NOT exit.
77 81
78 82 Instead, to exit a multiline input you can either have:
79 83
80 84 - TWO whitespace lines (just hit return again), or
81 85 - a single whitespace line of a different length than provided
82 86 by the autoindent (add or remove a space).
83 87
84 88 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
85 89 module to better organize all readline-related functionality.
86 90 I've deleted FlexCompleter and put all completion clases here.
87 91
88 92 * IPython/iplib.py (raw_input): improve indentation management.
89 93 It is now possible to paste indented code with autoindent on, and
90 94 the code is interpreted correctly (though it still looks bad on
91 95 screen, due to the line-oriented nature of ipython).
92 96 (MagicCompleter.complete): change behavior so that a TAB key on an
93 97 otherwise empty line actually inserts a tab, instead of completing
94 98 on the entire global namespace. This makes it easier to use the
95 99 TAB key for indentation. After a request by Hans Meine
96 100 <hans_meine-AT-gmx.net>
97 101 (_prefilter): add support so that typing plain 'exit' or 'quit'
98 102 does a sensible thing. Originally I tried to deviate as little as
99 103 possible from the default python behavior, but even that one may
100 104 change in this direction (thread on python-dev to that effect).
101 105 Regardless, ipython should do the right thing even if CPython's
102 106 '>>>' prompt doesn't.
103 107 (InteractiveShell): removed subclassing code.InteractiveConsole
104 108 class. By now we'd overridden just about all of its methods: I've
105 109 copied the remaining two over, and now ipython is a standalone
106 110 class. This will provide a clearer picture for the chainsaw
107 111 branch refactoring.
108 112
109 113 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
110 114
111 115 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
112 116 failures for objects which break when dir() is called on them.
113 117
114 118 * IPython/FlexCompleter.py (Completer.__init__): Added support for
115 119 distinct local and global namespaces in the completer API. This
116 120 change allows us top properly handle completion with distinct
117 121 scopes, including in embedded instances (this had never really
118 122 worked correctly).
119 123
120 124 Note: this introduces a change in the constructor for
121 125 MagicCompleter, as a new global_namespace parameter is now the
122 126 second argument (the others were bumped one position).
123 127
124 128 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
125 129
126 130 * IPython/iplib.py (embed_mainloop): fix tab-completion in
127 131 embedded instances (which can be done now thanks to Vivian's
128 132 frame-handling fixes for pdb).
129 133 (InteractiveShell.__init__): Fix namespace handling problem in
130 134 embedded instances. We were overwriting __main__ unconditionally,
131 135 and this should only be done for 'full' (non-embedded) IPython;
132 136 embedded instances must respect the caller's __main__. Thanks to
133 137 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
134 138
135 139 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
136 140
137 141 * setup.py: added download_url to setup(). This registers the
138 142 download address at PyPI, which is not only useful to humans
139 143 browsing the site, but is also picked up by setuptools (the Eggs
140 144 machinery). Thanks to Ville and R. Kern for the info/discussion
141 145 on this.
142 146
143 147 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
144 148
145 149 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
146 150 This brings a lot of nice functionality to the pdb mode, which now
147 151 has tab-completion, syntax highlighting, and better stack handling
148 152 than before. Many thanks to Vivian De Smedt
149 153 <vivian-AT-vdesmedt.com> for the original patches.
150 154
151 155 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
152 156
153 157 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
154 158 sequence to consistently accept the banner argument. The
155 159 inconsistency was tripping SAGE, thanks to Gary Zablackis
156 160 <gzabl-AT-yahoo.com> for the report.
157 161
158 162 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
159 163
160 164 * IPython/iplib.py (InteractiveShell.post_config_initialization):
161 165 Fix bug where a naked 'alias' call in the ipythonrc file would
162 166 cause a crash. Bug reported by Jorgen Stenarson.
163 167
164 168 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
165 169
166 170 * IPython/ipmaker.py (make_IPython): cleanups which should improve
167 171 startup time.
168 172
169 173 * IPython/iplib.py (runcode): my globals 'fix' for embedded
170 174 instances had introduced a bug with globals in normal code. Now
171 175 it's working in all cases.
172 176
173 177 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
174 178 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
175 179 has been introduced to set the default case sensitivity of the
176 180 searches. Users can still select either mode at runtime on a
177 181 per-search basis.
178 182
179 183 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
180 184
181 185 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
182 186 attributes in wildcard searches for subclasses. Modified version
183 187 of a patch by Jorgen.
184 188
185 189 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
186 190
187 191 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
188 192 embedded instances. I added a user_global_ns attribute to the
189 193 InteractiveShell class to handle this.
190 194
191 195 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
192 196
193 197 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
194 198 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
195 199 (reported under win32, but may happen also in other platforms).
196 200 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
197 201
198 202 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
199 203
200 204 * IPython/Magic.py (magic_psearch): new support for wildcard
201 205 patterns. Now, typing ?a*b will list all names which begin with a
202 206 and end in b, for example. The %psearch magic has full
203 207 docstrings. Many thanks to JΓΆrgen Stenarson
204 208 <jorgen.stenarson-AT-bostream.nu>, author of the patches
205 209 implementing this functionality.
206 210
207 211 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
208 212
209 213 * Manual: fixed long-standing annoyance of double-dashes (as in
210 214 --prefix=~, for example) being stripped in the HTML version. This
211 215 is a latex2html bug, but a workaround was provided. Many thanks
212 216 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
213 217 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
214 218 rolling. This seemingly small issue had tripped a number of users
215 219 when first installing, so I'm glad to see it gone.
216 220
217 221 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
218 222
219 223 * IPython/Extensions/numeric_formats.py: fix missing import,
220 224 reported by Stephen Walton.
221 225
222 226 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
223 227
224 228 * IPython/demo.py: finish demo module, fully documented now.
225 229
226 230 * IPython/genutils.py (file_read): simple little utility to read a
227 231 file and ensure it's closed afterwards.
228 232
229 233 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
230 234
231 235 * IPython/demo.py (Demo.__init__): added support for individually
232 236 tagging blocks for automatic execution.
233 237
234 238 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
235 239 syntax-highlighted python sources, requested by John.
236 240
237 241 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
238 242
239 243 * IPython/demo.py (Demo.again): fix bug where again() blocks after
240 244 finishing.
241 245
242 246 * IPython/genutils.py (shlex_split): moved from Magic to here,
243 247 where all 2.2 compatibility stuff lives. I needed it for demo.py.
244 248
245 249 * IPython/demo.py (Demo.__init__): added support for silent
246 250 blocks, improved marks as regexps, docstrings written.
247 251 (Demo.__init__): better docstring, added support for sys.argv.
248 252
249 253 * IPython/genutils.py (marquee): little utility used by the demo
250 254 code, handy in general.
251 255
252 256 * IPython/demo.py (Demo.__init__): new class for interactive
253 257 demos. Not documented yet, I just wrote it in a hurry for
254 258 scipy'05. Will docstring later.
255 259
256 260 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
257 261
258 262 * IPython/Shell.py (sigint_handler): Drastic simplification which
259 263 also seems to make Ctrl-C work correctly across threads! This is
260 264 so simple, that I can't beleive I'd missed it before. Needs more
261 265 testing, though.
262 266 (KBINT): Never mind, revert changes. I'm sure I'd tried something
263 267 like this before...
264 268
265 269 * IPython/genutils.py (get_home_dir): add protection against
266 270 non-dirs in win32 registry.
267 271
268 272 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
269 273 bug where dict was mutated while iterating (pysh crash).
270 274
271 275 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
272 276
273 277 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
274 278 spurious newlines added by this routine. After a report by
275 279 F. Mantegazza.
276 280
277 281 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
278 282
279 283 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
280 284 calls. These were a leftover from the GTK 1.x days, and can cause
281 285 problems in certain cases (after a report by John Hunter).
282 286
283 287 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
284 288 os.getcwd() fails at init time. Thanks to patch from David Remahl
285 289 <chmod007-AT-mac.com>.
286 290 (InteractiveShell.__init__): prevent certain special magics from
287 291 being shadowed by aliases. Closes
288 292 http://www.scipy.net/roundup/ipython/issue41.
289 293
290 294 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
291 295
292 296 * IPython/iplib.py (InteractiveShell.complete): Added new
293 297 top-level completion method to expose the completion mechanism
294 298 beyond readline-based environments.
295 299
296 300 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
297 301
298 302 * tools/ipsvnc (svnversion): fix svnversion capture.
299 303
300 304 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
301 305 attribute to self, which was missing. Before, it was set by a
302 306 routine which in certain cases wasn't being called, so the
303 307 instance could end up missing the attribute. This caused a crash.
304 308 Closes http://www.scipy.net/roundup/ipython/issue40.
305 309
306 310 2005-08-16 Fernando Perez <fperez@colorado.edu>
307 311
308 312 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
309 313 contains non-string attribute. Closes
310 314 http://www.scipy.net/roundup/ipython/issue38.
311 315
312 316 2005-08-14 Fernando Perez <fperez@colorado.edu>
313 317
314 318 * tools/ipsvnc: Minor improvements, to add changeset info.
315 319
316 320 2005-08-12 Fernando Perez <fperez@colorado.edu>
317 321
318 322 * IPython/iplib.py (runsource): remove self.code_to_run_src
319 323 attribute. I realized this is nothing more than
320 324 '\n'.join(self.buffer), and having the same data in two different
321 325 places is just asking for synchronization bugs. This may impact
322 326 people who have custom exception handlers, so I need to warn
323 327 ipython-dev about it (F. Mantegazza may use them).
324 328
325 329 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
326 330
327 331 * IPython/genutils.py: fix 2.2 compatibility (generators)
328 332
329 333 2005-07-18 Fernando Perez <fperez@colorado.edu>
330 334
331 335 * IPython/genutils.py (get_home_dir): fix to help users with
332 336 invalid $HOME under win32.
333 337
334 338 2005-07-17 Fernando Perez <fperez@colorado.edu>
335 339
336 340 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
337 341 some old hacks and clean up a bit other routines; code should be
338 342 simpler and a bit faster.
339 343
340 344 * IPython/iplib.py (interact): removed some last-resort attempts
341 345 to survive broken stdout/stderr. That code was only making it
342 346 harder to abstract out the i/o (necessary for gui integration),
343 347 and the crashes it could prevent were extremely rare in practice
344 348 (besides being fully user-induced in a pretty violent manner).
345 349
346 350 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
347 351 Nothing major yet, but the code is simpler to read; this should
348 352 make it easier to do more serious modifications in the future.
349 353
350 354 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
351 355 which broke in .15 (thanks to a report by Ville).
352 356
353 357 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
354 358 be quite correct, I know next to nothing about unicode). This
355 359 will allow unicode strings to be used in prompts, amongst other
356 360 cases. It also will prevent ipython from crashing when unicode
357 361 shows up unexpectedly in many places. If ascii encoding fails, we
358 362 assume utf_8. Currently the encoding is not a user-visible
359 363 setting, though it could be made so if there is demand for it.
360 364
361 365 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
362 366
363 367 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
364 368
365 369 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
366 370
367 371 * IPython/genutils.py: Add 2.2 compatibility here, so all other
368 372 code can work transparently for 2.2/2.3.
369 373
370 374 2005-07-16 Fernando Perez <fperez@colorado.edu>
371 375
372 376 * IPython/ultraTB.py (ExceptionColors): Make a global variable
373 377 out of the color scheme table used for coloring exception
374 378 tracebacks. This allows user code to add new schemes at runtime.
375 379 This is a minimally modified version of the patch at
376 380 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
377 381 for the contribution.
378 382
379 383 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
380 384 slightly modified version of the patch in
381 385 http://www.scipy.net/roundup/ipython/issue34, which also allows me
382 386 to remove the previous try/except solution (which was costlier).
383 387 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
384 388
385 389 2005-06-08 Fernando Perez <fperez@colorado.edu>
386 390
387 391 * IPython/iplib.py (write/write_err): Add methods to abstract all
388 392 I/O a bit more.
389 393
390 394 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
391 395 warning, reported by Aric Hagberg, fix by JD Hunter.
392 396
393 397 2005-06-02 *** Released version 0.6.15
394 398
395 399 2005-06-01 Fernando Perez <fperez@colorado.edu>
396 400
397 401 * IPython/iplib.py (MagicCompleter.file_matches): Fix
398 402 tab-completion of filenames within open-quoted strings. Note that
399 403 this requires that in ~/.ipython/ipythonrc, users change the
400 404 readline delimiters configuration to read:
401 405
402 406 readline_remove_delims -/~
403 407
404 408
405 409 2005-05-31 *** Released version 0.6.14
406 410
407 411 2005-05-29 Fernando Perez <fperez@colorado.edu>
408 412
409 413 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
410 414 with files not on the filesystem. Reported by Eliyahu Sandler
411 415 <eli@gondolin.net>
412 416
413 417 2005-05-22 Fernando Perez <fperez@colorado.edu>
414 418
415 419 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
416 420 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
417 421
418 422 2005-05-19 Fernando Perez <fperez@colorado.edu>
419 423
420 424 * IPython/iplib.py (safe_execfile): close a file which could be
421 425 left open (causing problems in win32, which locks open files).
422 426 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
423 427
424 428 2005-05-18 Fernando Perez <fperez@colorado.edu>
425 429
426 430 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
427 431 keyword arguments correctly to safe_execfile().
428 432
429 433 2005-05-13 Fernando Perez <fperez@colorado.edu>
430 434
431 435 * ipython.1: Added info about Qt to manpage, and threads warning
432 436 to usage page (invoked with --help).
433 437
434 438 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
435 439 new matcher (it goes at the end of the priority list) to do
436 440 tab-completion on named function arguments. Submitted by George
437 441 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
438 442 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
439 443 for more details.
440 444
441 445 * IPython/Magic.py (magic_run): Added new -e flag to ignore
442 446 SystemExit exceptions in the script being run. Thanks to a report
443 447 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
444 448 producing very annoying behavior when running unit tests.
445 449
446 450 2005-05-12 Fernando Perez <fperez@colorado.edu>
447 451
448 452 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
449 453 which I'd broken (again) due to a changed regexp. In the process,
450 454 added ';' as an escape to auto-quote the whole line without
451 455 splitting its arguments. Thanks to a report by Jerry McRae
452 456 <qrs0xyc02-AT-sneakemail.com>.
453 457
454 458 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
455 459 possible crashes caused by a TokenError. Reported by Ed Schofield
456 460 <schofield-AT-ftw.at>.
457 461
458 462 2005-05-06 Fernando Perez <fperez@colorado.edu>
459 463
460 464 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
461 465
462 466 2005-04-29 Fernando Perez <fperez@colorado.edu>
463 467
464 468 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
465 469 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
466 470 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
467 471 which provides support for Qt interactive usage (similar to the
468 472 existing one for WX and GTK). This had been often requested.
469 473
470 474 2005-04-14 *** Released version 0.6.13
471 475
472 476 2005-04-08 Fernando Perez <fperez@colorado.edu>
473 477
474 478 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
475 479 from _ofind, which gets called on almost every input line. Now,
476 480 we only try to get docstrings if they are actually going to be
477 481 used (the overhead of fetching unnecessary docstrings can be
478 482 noticeable for certain objects, such as Pyro proxies).
479 483
480 484 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
481 485 for completers. For some reason I had been passing them the state
482 486 variable, which completers never actually need, and was in
483 487 conflict with the rlcompleter API. Custom completers ONLY need to
484 488 take the text parameter.
485 489
486 490 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
487 491 work correctly in pysh. I've also moved all the logic which used
488 492 to be in pysh.py here, which will prevent problems with future
489 493 upgrades. However, this time I must warn users to update their
490 494 pysh profile to include the line
491 495
492 496 import_all IPython.Extensions.InterpreterExec
493 497
494 498 because otherwise things won't work for them. They MUST also
495 499 delete pysh.py and the line
496 500
497 501 execfile pysh.py
498 502
499 503 from their ipythonrc-pysh.
500 504
501 505 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
502 506 robust in the face of objects whose dir() returns non-strings
503 507 (which it shouldn't, but some broken libs like ITK do). Thanks to
504 508 a patch by John Hunter (implemented differently, though). Also
505 509 minor improvements by using .extend instead of + on lists.
506 510
507 511 * pysh.py:
508 512
509 513 2005-04-06 Fernando Perez <fperez@colorado.edu>
510 514
511 515 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
512 516 by default, so that all users benefit from it. Those who don't
513 517 want it can still turn it off.
514 518
515 519 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
516 520 config file, I'd forgotten about this, so users were getting it
517 521 off by default.
518 522
519 523 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
520 524 consistency. Now magics can be called in multiline statements,
521 525 and python variables can be expanded in magic calls via $var.
522 526 This makes the magic system behave just like aliases or !system
523 527 calls.
524 528
525 529 2005-03-28 Fernando Perez <fperez@colorado.edu>
526 530
527 531 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
528 532 expensive string additions for building command. Add support for
529 533 trailing ';' when autocall is used.
530 534
531 535 2005-03-26 Fernando Perez <fperez@colorado.edu>
532 536
533 537 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
534 538 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
535 539 ipython.el robust against prompts with any number of spaces
536 540 (including 0) after the ':' character.
537 541
538 542 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
539 543 continuation prompt, which misled users to think the line was
540 544 already indented. Closes debian Bug#300847, reported to me by
541 545 Norbert Tretkowski <tretkowski-AT-inittab.de>.
542 546
543 547 2005-03-23 Fernando Perez <fperez@colorado.edu>
544 548
545 549 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
546 550 properly aligned if they have embedded newlines.
547 551
548 552 * IPython/iplib.py (runlines): Add a public method to expose
549 553 IPython's code execution machinery, so that users can run strings
550 554 as if they had been typed at the prompt interactively.
551 555 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
552 556 methods which can call the system shell, but with python variable
553 557 expansion. The three such methods are: __IPYTHON__.system,
554 558 .getoutput and .getoutputerror. These need to be documented in a
555 559 'public API' section (to be written) of the manual.
556 560
557 561 2005-03-20 Fernando Perez <fperez@colorado.edu>
558 562
559 563 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
560 564 for custom exception handling. This is quite powerful, and it
561 565 allows for user-installable exception handlers which can trap
562 566 custom exceptions at runtime and treat them separately from
563 567 IPython's default mechanisms. At the request of FrΓ©dΓ©ric
564 568 Mantegazza <mantegazza-AT-ill.fr>.
565 569 (InteractiveShell.set_custom_completer): public API function to
566 570 add new completers at runtime.
567 571
568 572 2005-03-19 Fernando Perez <fperez@colorado.edu>
569 573
570 574 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
571 575 allow objects which provide their docstrings via non-standard
572 576 mechanisms (like Pyro proxies) to still be inspected by ipython's
573 577 ? system.
574 578
575 579 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
576 580 automatic capture system. I tried quite hard to make it work
577 581 reliably, and simply failed. I tried many combinations with the
578 582 subprocess module, but eventually nothing worked in all needed
579 583 cases (not blocking stdin for the child, duplicating stdout
580 584 without blocking, etc). The new %sc/%sx still do capture to these
581 585 magical list/string objects which make shell use much more
582 586 conveninent, so not all is lost.
583 587
584 588 XXX - FIX MANUAL for the change above!
585 589
586 590 (runsource): I copied code.py's runsource() into ipython to modify
587 591 it a bit. Now the code object and source to be executed are
588 592 stored in ipython. This makes this info accessible to third-party
589 593 tools, like custom exception handlers. After a request by FrΓ©dΓ©ric
590 594 Mantegazza <mantegazza-AT-ill.fr>.
591 595
592 596 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
593 597 history-search via readline (like C-p/C-n). I'd wanted this for a
594 598 long time, but only recently found out how to do it. For users
595 599 who already have their ipythonrc files made and want this, just
596 600 add:
597 601
598 602 readline_parse_and_bind "\e[A": history-search-backward
599 603 readline_parse_and_bind "\e[B": history-search-forward
600 604
601 605 2005-03-18 Fernando Perez <fperez@colorado.edu>
602 606
603 607 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
604 608 LSString and SList classes which allow transparent conversions
605 609 between list mode and whitespace-separated string.
606 610 (magic_r): Fix recursion problem in %r.
607 611
608 612 * IPython/genutils.py (LSString): New class to be used for
609 613 automatic storage of the results of all alias/system calls in _o
610 614 and _e (stdout/err). These provide a .l/.list attribute which
611 615 does automatic splitting on newlines. This means that for most
612 616 uses, you'll never need to do capturing of output with %sc/%sx
613 617 anymore, since ipython keeps this always done for you. Note that
614 618 only the LAST results are stored, the _o/e variables are
615 619 overwritten on each call. If you need to save their contents
616 620 further, simply bind them to any other name.
617 621
618 622 2005-03-17 Fernando Perez <fperez@colorado.edu>
619 623
620 624 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
621 625 prompt namespace handling.
622 626
623 627 2005-03-16 Fernando Perez <fperez@colorado.edu>
624 628
625 629 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
626 630 classic prompts to be '>>> ' (final space was missing, and it
627 631 trips the emacs python mode).
628 632 (BasePrompt.__str__): Added safe support for dynamic prompt
629 633 strings. Now you can set your prompt string to be '$x', and the
630 634 value of x will be printed from your interactive namespace. The
631 635 interpolation syntax includes the full Itpl support, so
632 636 ${foo()+x+bar()} is a valid prompt string now, and the function
633 637 calls will be made at runtime.
634 638
635 639 2005-03-15 Fernando Perez <fperez@colorado.edu>
636 640
637 641 * IPython/Magic.py (magic_history): renamed %hist to %history, to
638 642 avoid name clashes in pylab. %hist still works, it just forwards
639 643 the call to %history.
640 644
641 645 2005-03-02 *** Released version 0.6.12
642 646
643 647 2005-03-02 Fernando Perez <fperez@colorado.edu>
644 648
645 649 * IPython/iplib.py (handle_magic): log magic calls properly as
646 650 ipmagic() function calls.
647 651
648 652 * IPython/Magic.py (magic_time): Improved %time to support
649 653 statements and provide wall-clock as well as CPU time.
650 654
651 655 2005-02-27 Fernando Perez <fperez@colorado.edu>
652 656
653 657 * IPython/hooks.py: New hooks module, to expose user-modifiable
654 658 IPython functionality in a clean manner. For now only the editor
655 659 hook is actually written, and other thigns which I intend to turn
656 660 into proper hooks aren't yet there. The display and prefilter
657 661 stuff, for example, should be hooks. But at least now the
658 662 framework is in place, and the rest can be moved here with more
659 663 time later. IPython had had a .hooks variable for a long time for
660 664 this purpose, but I'd never actually used it for anything.
661 665
662 666 2005-02-26 Fernando Perez <fperez@colorado.edu>
663 667
664 668 * IPython/ipmaker.py (make_IPython): make the default ipython
665 669 directory be called _ipython under win32, to follow more the
666 670 naming peculiarities of that platform (where buggy software like
667 671 Visual Sourcesafe breaks with .named directories). Reported by
668 672 Ville Vainio.
669 673
670 674 2005-02-23 Fernando Perez <fperez@colorado.edu>
671 675
672 676 * IPython/iplib.py (InteractiveShell.__init__): removed a few
673 677 auto_aliases for win32 which were causing problems. Users can
674 678 define the ones they personally like.
675 679
676 680 2005-02-21 Fernando Perez <fperez@colorado.edu>
677 681
678 682 * IPython/Magic.py (magic_time): new magic to time execution of
679 683 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
680 684
681 685 2005-02-19 Fernando Perez <fperez@colorado.edu>
682 686
683 687 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
684 688 into keys (for prompts, for example).
685 689
686 690 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
687 691 prompts in case users want them. This introduces a small behavior
688 692 change: ipython does not automatically add a space to all prompts
689 693 anymore. To get the old prompts with a space, users should add it
690 694 manually to their ipythonrc file, so for example prompt_in1 should
691 695 now read 'In [\#]: ' instead of 'In [\#]:'.
692 696 (BasePrompt.__init__): New option prompts_pad_left (only in rc
693 697 file) to control left-padding of secondary prompts.
694 698
695 699 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
696 700 the profiler can't be imported. Fix for Debian, which removed
697 701 profile.py because of License issues. I applied a slightly
698 702 modified version of the original Debian patch at
699 703 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
700 704
701 705 2005-02-17 Fernando Perez <fperez@colorado.edu>
702 706
703 707 * IPython/genutils.py (native_line_ends): Fix bug which would
704 708 cause improper line-ends under win32 b/c I was not opening files
705 709 in binary mode. Bug report and fix thanks to Ville.
706 710
707 711 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
708 712 trying to catch spurious foo[1] autocalls. My fix actually broke
709 713 ',/' autoquote/call with explicit escape (bad regexp).
710 714
711 715 2005-02-15 *** Released version 0.6.11
712 716
713 717 2005-02-14 Fernando Perez <fperez@colorado.edu>
714 718
715 719 * IPython/background_jobs.py: New background job management
716 720 subsystem. This is implemented via a new set of classes, and
717 721 IPython now provides a builtin 'jobs' object for background job
718 722 execution. A convenience %bg magic serves as a lightweight
719 723 frontend for starting the more common type of calls. This was
720 724 inspired by discussions with B. Granger and the BackgroundCommand
721 725 class described in the book Python Scripting for Computational
722 726 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
723 727 (although ultimately no code from this text was used, as IPython's
724 728 system is a separate implementation).
725 729
726 730 * IPython/iplib.py (MagicCompleter.python_matches): add new option
727 731 to control the completion of single/double underscore names
728 732 separately. As documented in the example ipytonrc file, the
729 733 readline_omit__names variable can now be set to 2, to omit even
730 734 single underscore names. Thanks to a patch by Brian Wong
731 735 <BrianWong-AT-AirgoNetworks.Com>.
732 736 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
733 737 be autocalled as foo([1]) if foo were callable. A problem for
734 738 things which are both callable and implement __getitem__.
735 739 (init_readline): Fix autoindentation for win32. Thanks to a patch
736 740 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
737 741
738 742 2005-02-12 Fernando Perez <fperez@colorado.edu>
739 743
740 744 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
741 745 which I had written long ago to sort out user error messages which
742 746 may occur during startup. This seemed like a good idea initially,
743 747 but it has proven a disaster in retrospect. I don't want to
744 748 change much code for now, so my fix is to set the internal 'debug'
745 749 flag to true everywhere, whose only job was precisely to control
746 750 this subsystem. This closes issue 28 (as well as avoiding all
747 751 sorts of strange hangups which occur from time to time).
748 752
749 753 2005-02-07 Fernando Perez <fperez@colorado.edu>
750 754
751 755 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
752 756 previous call produced a syntax error.
753 757
754 758 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
755 759 classes without constructor.
756 760
757 761 2005-02-06 Fernando Perez <fperez@colorado.edu>
758 762
759 763 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
760 764 completions with the results of each matcher, so we return results
761 765 to the user from all namespaces. This breaks with ipython
762 766 tradition, but I think it's a nicer behavior. Now you get all
763 767 possible completions listed, from all possible namespaces (python,
764 768 filesystem, magics...) After a request by John Hunter
765 769 <jdhunter-AT-nitace.bsd.uchicago.edu>.
766 770
767 771 2005-02-05 Fernando Perez <fperez@colorado.edu>
768 772
769 773 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
770 774 the call had quote characters in it (the quotes were stripped).
771 775
772 776 2005-01-31 Fernando Perez <fperez@colorado.edu>
773 777
774 778 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
775 779 Itpl.itpl() to make the code more robust against psyco
776 780 optimizations.
777 781
778 782 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
779 783 of causing an exception. Quicker, cleaner.
780 784
781 785 2005-01-28 Fernando Perez <fperez@colorado.edu>
782 786
783 787 * scripts/ipython_win_post_install.py (install): hardcode
784 788 sys.prefix+'python.exe' as the executable path. It turns out that
785 789 during the post-installation run, sys.executable resolves to the
786 790 name of the binary installer! I should report this as a distutils
787 791 bug, I think. I updated the .10 release with this tiny fix, to
788 792 avoid annoying the lists further.
789 793
790 794 2005-01-27 *** Released version 0.6.10
791 795
792 796 2005-01-27 Fernando Perez <fperez@colorado.edu>
793 797
794 798 * IPython/numutils.py (norm): Added 'inf' as optional name for
795 799 L-infinity norm, included references to mathworld.com for vector
796 800 norm definitions.
797 801 (amin/amax): added amin/amax for array min/max. Similar to what
798 802 pylab ships with after the recent reorganization of names.
799 803 (spike/spike_odd): removed deprecated spike/spike_odd functions.
800 804
801 805 * ipython.el: committed Alex's recent fixes and improvements.
802 806 Tested with python-mode from CVS, and it looks excellent. Since
803 807 python-mode hasn't released anything in a while, I'm temporarily
804 808 putting a copy of today's CVS (v 4.70) of python-mode in:
805 809 http://ipython.scipy.org/tmp/python-mode.el
806 810
807 811 * scripts/ipython_win_post_install.py (install): Win32 fix to use
808 812 sys.executable for the executable name, instead of assuming it's
809 813 called 'python.exe' (the post-installer would have produced broken
810 814 setups on systems with a differently named python binary).
811 815
812 816 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
813 817 references to os.linesep, to make the code more
814 818 platform-independent. This is also part of the win32 coloring
815 819 fixes.
816 820
817 821 * IPython/genutils.py (page_dumb): Remove attempts to chop long
818 822 lines, which actually cause coloring bugs because the length of
819 823 the line is very difficult to correctly compute with embedded
820 824 escapes. This was the source of all the coloring problems under
821 825 Win32. I think that _finally_, Win32 users have a properly
822 826 working ipython in all respects. This would never have happened
823 827 if not for Gary Bishop and Viktor Ransmayr's great help and work.
824 828
825 829 2005-01-26 *** Released version 0.6.9
826 830
827 831 2005-01-25 Fernando Perez <fperez@colorado.edu>
828 832
829 833 * setup.py: finally, we have a true Windows installer, thanks to
830 834 the excellent work of Viktor Ransmayr
831 835 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
832 836 Windows users. The setup routine is quite a bit cleaner thanks to
833 837 this, and the post-install script uses the proper functions to
834 838 allow a clean de-installation using the standard Windows Control
835 839 Panel.
836 840
837 841 * IPython/genutils.py (get_home_dir): changed to use the $HOME
838 842 environment variable under all OSes (including win32) if
839 843 available. This will give consistency to win32 users who have set
840 844 this variable for any reason. If os.environ['HOME'] fails, the
841 845 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
842 846
843 847 2005-01-24 Fernando Perez <fperez@colorado.edu>
844 848
845 849 * IPython/numutils.py (empty_like): add empty_like(), similar to
846 850 zeros_like() but taking advantage of the new empty() Numeric routine.
847 851
848 852 2005-01-23 *** Released version 0.6.8
849 853
850 854 2005-01-22 Fernando Perez <fperez@colorado.edu>
851 855
852 856 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
853 857 automatic show() calls. After discussing things with JDH, it
854 858 turns out there are too many corner cases where this can go wrong.
855 859 It's best not to try to be 'too smart', and simply have ipython
856 860 reproduce as much as possible the default behavior of a normal
857 861 python shell.
858 862
859 863 * IPython/iplib.py (InteractiveShell.__init__): Modified the
860 864 line-splitting regexp and _prefilter() to avoid calling getattr()
861 865 on assignments. This closes
862 866 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
863 867 readline uses getattr(), so a simple <TAB> keypress is still
864 868 enough to trigger getattr() calls on an object.
865 869
866 870 2005-01-21 Fernando Perez <fperez@colorado.edu>
867 871
868 872 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
869 873 docstring under pylab so it doesn't mask the original.
870 874
871 875 2005-01-21 *** Released version 0.6.7
872 876
873 877 2005-01-21 Fernando Perez <fperez@colorado.edu>
874 878
875 879 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
876 880 signal handling for win32 users in multithreaded mode.
877 881
878 882 2005-01-17 Fernando Perez <fperez@colorado.edu>
879 883
880 884 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
881 885 instances with no __init__. After a crash report by Norbert Nemec
882 886 <Norbert-AT-nemec-online.de>.
883 887
884 888 2005-01-14 Fernando Perez <fperez@colorado.edu>
885 889
886 890 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
887 891 names for verbose exceptions, when multiple dotted names and the
888 892 'parent' object were present on the same line.
889 893
890 894 2005-01-11 Fernando Perez <fperez@colorado.edu>
891 895
892 896 * IPython/genutils.py (flag_calls): new utility to trap and flag
893 897 calls in functions. I need it to clean up matplotlib support.
894 898 Also removed some deprecated code in genutils.
895 899
896 900 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
897 901 that matplotlib scripts called with %run, which don't call show()
898 902 themselves, still have their plotting windows open.
899 903
900 904 2005-01-05 Fernando Perez <fperez@colorado.edu>
901 905
902 906 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
903 907 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
904 908
905 909 2004-12-19 Fernando Perez <fperez@colorado.edu>
906 910
907 911 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
908 912 parent_runcode, which was an eyesore. The same result can be
909 913 obtained with Python's regular superclass mechanisms.
910 914
911 915 2004-12-17 Fernando Perez <fperez@colorado.edu>
912 916
913 917 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
914 918 reported by Prabhu.
915 919 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
916 920 sys.stderr) instead of explicitly calling sys.stderr. This helps
917 921 maintain our I/O abstractions clean, for future GUI embeddings.
918 922
919 923 * IPython/genutils.py (info): added new utility for sys.stderr
920 924 unified info message handling (thin wrapper around warn()).
921 925
922 926 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
923 927 composite (dotted) names on verbose exceptions.
924 928 (VerboseTB.nullrepr): harden against another kind of errors which
925 929 Python's inspect module can trigger, and which were crashing
926 930 IPython. Thanks to a report by Marco Lombardi
927 931 <mlombard-AT-ma010192.hq.eso.org>.
928 932
929 933 2004-12-13 *** Released version 0.6.6
930 934
931 935 2004-12-12 Fernando Perez <fperez@colorado.edu>
932 936
933 937 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
934 938 generated by pygtk upon initialization if it was built without
935 939 threads (for matplotlib users). After a crash reported by
936 940 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
937 941
938 942 * IPython/ipmaker.py (make_IPython): fix small bug in the
939 943 import_some parameter for multiple imports.
940 944
941 945 * IPython/iplib.py (ipmagic): simplified the interface of
942 946 ipmagic() to take a single string argument, just as it would be
943 947 typed at the IPython cmd line.
944 948 (ipalias): Added new ipalias() with an interface identical to
945 949 ipmagic(). This completes exposing a pure python interface to the
946 950 alias and magic system, which can be used in loops or more complex
947 951 code where IPython's automatic line mangling is not active.
948 952
949 953 * IPython/genutils.py (timing): changed interface of timing to
950 954 simply run code once, which is the most common case. timings()
951 955 remains unchanged, for the cases where you want multiple runs.
952 956
953 957 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
954 958 bug where Python2.2 crashes with exec'ing code which does not end
955 959 in a single newline. Python 2.3 is OK, so I hadn't noticed this
956 960 before.
957 961
958 962 2004-12-10 Fernando Perez <fperez@colorado.edu>
959 963
960 964 * IPython/Magic.py (Magic.magic_prun): changed name of option from
961 965 -t to -T, to accomodate the new -t flag in %run (the %run and
962 966 %prun options are kind of intermixed, and it's not easy to change
963 967 this with the limitations of python's getopt).
964 968
965 969 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
966 970 the execution of scripts. It's not as fine-tuned as timeit.py,
967 971 but it works from inside ipython (and under 2.2, which lacks
968 972 timeit.py). Optionally a number of runs > 1 can be given for
969 973 timing very short-running code.
970 974
971 975 * IPython/genutils.py (uniq_stable): new routine which returns a
972 976 list of unique elements in any iterable, but in stable order of
973 977 appearance. I needed this for the ultraTB fixes, and it's a handy
974 978 utility.
975 979
976 980 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
977 981 dotted names in Verbose exceptions. This had been broken since
978 982 the very start, now x.y will properly be printed in a Verbose
979 983 traceback, instead of x being shown and y appearing always as an
980 984 'undefined global'. Getting this to work was a bit tricky,
981 985 because by default python tokenizers are stateless. Saved by
982 986 python's ability to easily add a bit of state to an arbitrary
983 987 function (without needing to build a full-blown callable object).
984 988
985 989 Also big cleanup of this code, which had horrendous runtime
986 990 lookups of zillions of attributes for colorization. Moved all
987 991 this code into a few templates, which make it cleaner and quicker.
988 992
989 993 Printout quality was also improved for Verbose exceptions: one
990 994 variable per line, and memory addresses are printed (this can be
991 995 quite handy in nasty debugging situations, which is what Verbose
992 996 is for).
993 997
994 998 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
995 999 the command line as scripts to be loaded by embedded instances.
996 1000 Doing so has the potential for an infinite recursion if there are
997 1001 exceptions thrown in the process. This fixes a strange crash
998 1002 reported by Philippe MULLER <muller-AT-irit.fr>.
999 1003
1000 1004 2004-12-09 Fernando Perez <fperez@colorado.edu>
1001 1005
1002 1006 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
1003 1007 to reflect new names in matplotlib, which now expose the
1004 1008 matlab-compatible interface via a pylab module instead of the
1005 1009 'matlab' name. The new code is backwards compatible, so users of
1006 1010 all matplotlib versions are OK. Patch by J. Hunter.
1007 1011
1008 1012 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
1009 1013 of __init__ docstrings for instances (class docstrings are already
1010 1014 automatically printed). Instances with customized docstrings
1011 1015 (indep. of the class) are also recognized and all 3 separate
1012 1016 docstrings are printed (instance, class, constructor). After some
1013 1017 comments/suggestions by J. Hunter.
1014 1018
1015 1019 2004-12-05 Fernando Perez <fperez@colorado.edu>
1016 1020
1017 1021 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
1018 1022 warnings when tab-completion fails and triggers an exception.
1019 1023
1020 1024 2004-12-03 Fernando Perez <fperez@colorado.edu>
1021 1025
1022 1026 * IPython/Magic.py (magic_prun): Fix bug where an exception would
1023 1027 be triggered when using 'run -p'. An incorrect option flag was
1024 1028 being set ('d' instead of 'D').
1025 1029 (manpage): fix missing escaped \- sign.
1026 1030
1027 1031 2004-11-30 *** Released version 0.6.5
1028 1032
1029 1033 2004-11-30 Fernando Perez <fperez@colorado.edu>
1030 1034
1031 1035 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
1032 1036 setting with -d option.
1033 1037
1034 1038 * setup.py (docfiles): Fix problem where the doc glob I was using
1035 1039 was COMPLETELY BROKEN. It was giving the right files by pure
1036 1040 accident, but failed once I tried to include ipython.el. Note:
1037 1041 glob() does NOT allow you to do exclusion on multiple endings!
1038 1042
1039 1043 2004-11-29 Fernando Perez <fperez@colorado.edu>
1040 1044
1041 1045 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
1042 1046 the manpage as the source. Better formatting & consistency.
1043 1047
1044 1048 * IPython/Magic.py (magic_run): Added new -d option, to run
1045 1049 scripts under the control of the python pdb debugger. Note that
1046 1050 this required changing the %prun option -d to -D, to avoid a clash
1047 1051 (since %run must pass options to %prun, and getopt is too dumb to
1048 1052 handle options with string values with embedded spaces). Thanks
1049 1053 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
1050 1054 (magic_who_ls): added type matching to %who and %whos, so that one
1051 1055 can filter their output to only include variables of certain
1052 1056 types. Another suggestion by Matthew.
1053 1057 (magic_whos): Added memory summaries in kb and Mb for arrays.
1054 1058 (magic_who): Improve formatting (break lines every 9 vars).
1055 1059
1056 1060 2004-11-28 Fernando Perez <fperez@colorado.edu>
1057 1061
1058 1062 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
1059 1063 cache when empty lines were present.
1060 1064
1061 1065 2004-11-24 Fernando Perez <fperez@colorado.edu>
1062 1066
1063 1067 * IPython/usage.py (__doc__): document the re-activated threading
1064 1068 options for WX and GTK.
1065 1069
1066 1070 2004-11-23 Fernando Perez <fperez@colorado.edu>
1067 1071
1068 1072 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
1069 1073 the -wthread and -gthread options, along with a new -tk one to try
1070 1074 and coordinate Tk threading with wx/gtk. The tk support is very
1071 1075 platform dependent, since it seems to require Tcl and Tk to be
1072 1076 built with threads (Fedora1/2 appears NOT to have it, but in
1073 1077 Prabhu's Debian boxes it works OK). But even with some Tk
1074 1078 limitations, this is a great improvement.
1075 1079
1076 1080 * IPython/Prompts.py (prompt_specials_color): Added \t for time
1077 1081 info in user prompts. Patch by Prabhu.
1078 1082
1079 1083 2004-11-18 Fernando Perez <fperez@colorado.edu>
1080 1084
1081 1085 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
1082 1086 EOFErrors and bail, to avoid infinite loops if a non-terminating
1083 1087 file is fed into ipython. Patch submitted in issue 19 by user,
1084 1088 many thanks.
1085 1089
1086 1090 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
1087 1091 autoquote/parens in continuation prompts, which can cause lots of
1088 1092 problems. Closes roundup issue 20.
1089 1093
1090 1094 2004-11-17 Fernando Perez <fperez@colorado.edu>
1091 1095
1092 1096 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
1093 1097 reported as debian bug #280505. I'm not sure my local changelog
1094 1098 entry has the proper debian format (Jack?).
1095 1099
1096 1100 2004-11-08 *** Released version 0.6.4
1097 1101
1098 1102 2004-11-08 Fernando Perez <fperez@colorado.edu>
1099 1103
1100 1104 * IPython/iplib.py (init_readline): Fix exit message for Windows
1101 1105 when readline is active. Thanks to a report by Eric Jones
1102 1106 <eric-AT-enthought.com>.
1103 1107
1104 1108 2004-11-07 Fernando Perez <fperez@colorado.edu>
1105 1109
1106 1110 * IPython/genutils.py (page): Add a trap for OSError exceptions,
1107 1111 sometimes seen by win2k/cygwin users.
1108 1112
1109 1113 2004-11-06 Fernando Perez <fperez@colorado.edu>
1110 1114
1111 1115 * IPython/iplib.py (interact): Change the handling of %Exit from
1112 1116 trying to propagate a SystemExit to an internal ipython flag.
1113 1117 This is less elegant than using Python's exception mechanism, but
1114 1118 I can't get that to work reliably with threads, so under -pylab
1115 1119 %Exit was hanging IPython. Cross-thread exception handling is
1116 1120 really a bitch. Thaks to a bug report by Stephen Walton
1117 1121 <stephen.walton-AT-csun.edu>.
1118 1122
1119 1123 2004-11-04 Fernando Perez <fperez@colorado.edu>
1120 1124
1121 1125 * IPython/iplib.py (raw_input_original): store a pointer to the
1122 1126 true raw_input to harden against code which can modify it
1123 1127 (wx.py.PyShell does this and would otherwise crash ipython).
1124 1128 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
1125 1129
1126 1130 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
1127 1131 Ctrl-C problem, which does not mess up the input line.
1128 1132
1129 1133 2004-11-03 Fernando Perez <fperez@colorado.edu>
1130 1134
1131 1135 * IPython/Release.py: Changed licensing to BSD, in all files.
1132 1136 (name): lowercase name for tarball/RPM release.
1133 1137
1134 1138 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
1135 1139 use throughout ipython.
1136 1140
1137 1141 * IPython/Magic.py (Magic._ofind): Switch to using the new
1138 1142 OInspect.getdoc() function.
1139 1143
1140 1144 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
1141 1145 of the line currently being canceled via Ctrl-C. It's extremely
1142 1146 ugly, but I don't know how to do it better (the problem is one of
1143 1147 handling cross-thread exceptions).
1144 1148
1145 1149 2004-10-28 Fernando Perez <fperez@colorado.edu>
1146 1150
1147 1151 * IPython/Shell.py (signal_handler): add signal handlers to trap
1148 1152 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
1149 1153 report by Francesc Alted.
1150 1154
1151 1155 2004-10-21 Fernando Perez <fperez@colorado.edu>
1152 1156
1153 1157 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
1154 1158 to % for pysh syntax extensions.
1155 1159
1156 1160 2004-10-09 Fernando Perez <fperez@colorado.edu>
1157 1161
1158 1162 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
1159 1163 arrays to print a more useful summary, without calling str(arr).
1160 1164 This avoids the problem of extremely lengthy computations which
1161 1165 occur if arr is large, and appear to the user as a system lockup
1162 1166 with 100% cpu activity. After a suggestion by Kristian Sandberg
1163 1167 <Kristian.Sandberg@colorado.edu>.
1164 1168 (Magic.__init__): fix bug in global magic escapes not being
1165 1169 correctly set.
1166 1170
1167 1171 2004-10-08 Fernando Perez <fperez@colorado.edu>
1168 1172
1169 1173 * IPython/Magic.py (__license__): change to absolute imports of
1170 1174 ipython's own internal packages, to start adapting to the absolute
1171 1175 import requirement of PEP-328.
1172 1176
1173 1177 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
1174 1178 files, and standardize author/license marks through the Release
1175 1179 module instead of having per/file stuff (except for files with
1176 1180 particular licenses, like the MIT/PSF-licensed codes).
1177 1181
1178 1182 * IPython/Debugger.py: remove dead code for python 2.1
1179 1183
1180 1184 2004-10-04 Fernando Perez <fperez@colorado.edu>
1181 1185
1182 1186 * IPython/iplib.py (ipmagic): New function for accessing magics
1183 1187 via a normal python function call.
1184 1188
1185 1189 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
1186 1190 from '@' to '%', to accomodate the new @decorator syntax of python
1187 1191 2.4.
1188 1192
1189 1193 2004-09-29 Fernando Perez <fperez@colorado.edu>
1190 1194
1191 1195 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
1192 1196 matplotlib.use to prevent running scripts which try to switch
1193 1197 interactive backends from within ipython. This will just crash
1194 1198 the python interpreter, so we can't allow it (but a detailed error
1195 1199 is given to the user).
1196 1200
1197 1201 2004-09-28 Fernando Perez <fperez@colorado.edu>
1198 1202
1199 1203 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
1200 1204 matplotlib-related fixes so that using @run with non-matplotlib
1201 1205 scripts doesn't pop up spurious plot windows. This requires
1202 1206 matplotlib >= 0.63, where I had to make some changes as well.
1203 1207
1204 1208 * IPython/ipmaker.py (make_IPython): update version requirement to
1205 1209 python 2.2.
1206 1210
1207 1211 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
1208 1212 banner arg for embedded customization.
1209 1213
1210 1214 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
1211 1215 explicit uses of __IP as the IPython's instance name. Now things
1212 1216 are properly handled via the shell.name value. The actual code
1213 1217 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
1214 1218 is much better than before. I'll clean things completely when the
1215 1219 magic stuff gets a real overhaul.
1216 1220
1217 1221 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
1218 1222 minor changes to debian dir.
1219 1223
1220 1224 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
1221 1225 pointer to the shell itself in the interactive namespace even when
1222 1226 a user-supplied dict is provided. This is needed for embedding
1223 1227 purposes (found by tests with Michel Sanner).
1224 1228
1225 1229 2004-09-27 Fernando Perez <fperez@colorado.edu>
1226 1230
1227 1231 * IPython/UserConfig/ipythonrc: remove []{} from
1228 1232 readline_remove_delims, so that things like [modname.<TAB> do
1229 1233 proper completion. This disables [].TAB, but that's a less common
1230 1234 case than module names in list comprehensions, for example.
1231 1235 Thanks to a report by Andrea Riciputi.
1232 1236
1233 1237 2004-09-09 Fernando Perez <fperez@colorado.edu>
1234 1238
1235 1239 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1236 1240 blocking problems in win32 and osx. Fix by John.
1237 1241
1238 1242 2004-09-08 Fernando Perez <fperez@colorado.edu>
1239 1243
1240 1244 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1241 1245 for Win32 and OSX. Fix by John Hunter.
1242 1246
1243 1247 2004-08-30 *** Released version 0.6.3
1244 1248
1245 1249 2004-08-30 Fernando Perez <fperez@colorado.edu>
1246 1250
1247 1251 * setup.py (isfile): Add manpages to list of dependent files to be
1248 1252 updated.
1249 1253
1250 1254 2004-08-27 Fernando Perez <fperez@colorado.edu>
1251 1255
1252 1256 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1253 1257 for now. They don't really work with standalone WX/GTK code
1254 1258 (though matplotlib IS working fine with both of those backends).
1255 1259 This will neeed much more testing. I disabled most things with
1256 1260 comments, so turning it back on later should be pretty easy.
1257 1261
1258 1262 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1259 1263 autocalling of expressions like r'foo', by modifying the line
1260 1264 split regexp. Closes
1261 1265 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1262 1266 Riley <ipythonbugs-AT-sabi.net>.
1263 1267 (InteractiveShell.mainloop): honor --nobanner with banner
1264 1268 extensions.
1265 1269
1266 1270 * IPython/Shell.py: Significant refactoring of all classes, so
1267 1271 that we can really support ALL matplotlib backends and threading
1268 1272 models (John spotted a bug with Tk which required this). Now we
1269 1273 should support single-threaded, WX-threads and GTK-threads, both
1270 1274 for generic code and for matplotlib.
1271 1275
1272 1276 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1273 1277 -pylab, to simplify things for users. Will also remove the pylab
1274 1278 profile, since now all of matplotlib configuration is directly
1275 1279 handled here. This also reduces startup time.
1276 1280
1277 1281 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1278 1282 shell wasn't being correctly called. Also in IPShellWX.
1279 1283
1280 1284 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1281 1285 fine-tune banner.
1282 1286
1283 1287 * IPython/numutils.py (spike): Deprecate these spike functions,
1284 1288 delete (long deprecated) gnuplot_exec handler.
1285 1289
1286 1290 2004-08-26 Fernando Perez <fperez@colorado.edu>
1287 1291
1288 1292 * ipython.1: Update for threading options, plus some others which
1289 1293 were missing.
1290 1294
1291 1295 * IPython/ipmaker.py (__call__): Added -wthread option for
1292 1296 wxpython thread handling. Make sure threading options are only
1293 1297 valid at the command line.
1294 1298
1295 1299 * scripts/ipython: moved shell selection into a factory function
1296 1300 in Shell.py, to keep the starter script to a minimum.
1297 1301
1298 1302 2004-08-25 Fernando Perez <fperez@colorado.edu>
1299 1303
1300 1304 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1301 1305 John. Along with some recent changes he made to matplotlib, the
1302 1306 next versions of both systems should work very well together.
1303 1307
1304 1308 2004-08-24 Fernando Perez <fperez@colorado.edu>
1305 1309
1306 1310 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1307 1311 tried to switch the profiling to using hotshot, but I'm getting
1308 1312 strange errors from prof.runctx() there. I may be misreading the
1309 1313 docs, but it looks weird. For now the profiling code will
1310 1314 continue to use the standard profiler.
1311 1315
1312 1316 2004-08-23 Fernando Perez <fperez@colorado.edu>
1313 1317
1314 1318 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1315 1319 threaded shell, by John Hunter. It's not quite ready yet, but
1316 1320 close.
1317 1321
1318 1322 2004-08-22 Fernando Perez <fperez@colorado.edu>
1319 1323
1320 1324 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1321 1325 in Magic and ultraTB.
1322 1326
1323 1327 * ipython.1: document threading options in manpage.
1324 1328
1325 1329 * scripts/ipython: Changed name of -thread option to -gthread,
1326 1330 since this is GTK specific. I want to leave the door open for a
1327 1331 -wthread option for WX, which will most likely be necessary. This
1328 1332 change affects usage and ipmaker as well.
1329 1333
1330 1334 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1331 1335 handle the matplotlib shell issues. Code by John Hunter
1332 1336 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1333 1337 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1334 1338 broken (and disabled for end users) for now, but it puts the
1335 1339 infrastructure in place.
1336 1340
1337 1341 2004-08-21 Fernando Perez <fperez@colorado.edu>
1338 1342
1339 1343 * ipythonrc-pylab: Add matplotlib support.
1340 1344
1341 1345 * matplotlib_config.py: new files for matplotlib support, part of
1342 1346 the pylab profile.
1343 1347
1344 1348 * IPython/usage.py (__doc__): documented the threading options.
1345 1349
1346 1350 2004-08-20 Fernando Perez <fperez@colorado.edu>
1347 1351
1348 1352 * ipython: Modified the main calling routine to handle the -thread
1349 1353 and -mpthread options. This needs to be done as a top-level hack,
1350 1354 because it determines which class to instantiate for IPython
1351 1355 itself.
1352 1356
1353 1357 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1354 1358 classes to support multithreaded GTK operation without blocking,
1355 1359 and matplotlib with all backends. This is a lot of still very
1356 1360 experimental code, and threads are tricky. So it may still have a
1357 1361 few rough edges... This code owes a lot to
1358 1362 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1359 1363 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1360 1364 to John Hunter for all the matplotlib work.
1361 1365
1362 1366 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1363 1367 options for gtk thread and matplotlib support.
1364 1368
1365 1369 2004-08-16 Fernando Perez <fperez@colorado.edu>
1366 1370
1367 1371 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1368 1372 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1369 1373 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1370 1374
1371 1375 2004-08-11 Fernando Perez <fperez@colorado.edu>
1372 1376
1373 1377 * setup.py (isfile): Fix build so documentation gets updated for
1374 1378 rpms (it was only done for .tgz builds).
1375 1379
1376 1380 2004-08-10 Fernando Perez <fperez@colorado.edu>
1377 1381
1378 1382 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1379 1383
1380 1384 * iplib.py : Silence syntax error exceptions in tab-completion.
1381 1385
1382 1386 2004-08-05 Fernando Perez <fperez@colorado.edu>
1383 1387
1384 1388 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1385 1389 'color off' mark for continuation prompts. This was causing long
1386 1390 continuation lines to mis-wrap.
1387 1391
1388 1392 2004-08-01 Fernando Perez <fperez@colorado.edu>
1389 1393
1390 1394 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1391 1395 for building ipython to be a parameter. All this is necessary
1392 1396 right now to have a multithreaded version, but this insane
1393 1397 non-design will be cleaned up soon. For now, it's a hack that
1394 1398 works.
1395 1399
1396 1400 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1397 1401 args in various places. No bugs so far, but it's a dangerous
1398 1402 practice.
1399 1403
1400 1404 2004-07-31 Fernando Perez <fperez@colorado.edu>
1401 1405
1402 1406 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1403 1407 fix completion of files with dots in their names under most
1404 1408 profiles (pysh was OK because the completion order is different).
1405 1409
1406 1410 2004-07-27 Fernando Perez <fperez@colorado.edu>
1407 1411
1408 1412 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1409 1413 keywords manually, b/c the one in keyword.py was removed in python
1410 1414 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1411 1415 This is NOT a bug under python 2.3 and earlier.
1412 1416
1413 1417 2004-07-26 Fernando Perez <fperez@colorado.edu>
1414 1418
1415 1419 * IPython/ultraTB.py (VerboseTB.text): Add another
1416 1420 linecache.checkcache() call to try to prevent inspect.py from
1417 1421 crashing under python 2.3. I think this fixes
1418 1422 http://www.scipy.net/roundup/ipython/issue17.
1419 1423
1420 1424 2004-07-26 *** Released version 0.6.2
1421 1425
1422 1426 2004-07-26 Fernando Perez <fperez@colorado.edu>
1423 1427
1424 1428 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1425 1429 fail for any number.
1426 1430 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1427 1431 empty bookmarks.
1428 1432
1429 1433 2004-07-26 *** Released version 0.6.1
1430 1434
1431 1435 2004-07-26 Fernando Perez <fperez@colorado.edu>
1432 1436
1433 1437 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1434 1438
1435 1439 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1436 1440 escaping '()[]{}' in filenames.
1437 1441
1438 1442 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1439 1443 Python 2.2 users who lack a proper shlex.split.
1440 1444
1441 1445 2004-07-19 Fernando Perez <fperez@colorado.edu>
1442 1446
1443 1447 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1444 1448 for reading readline's init file. I follow the normal chain:
1445 1449 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1446 1450 report by Mike Heeter. This closes
1447 1451 http://www.scipy.net/roundup/ipython/issue16.
1448 1452
1449 1453 2004-07-18 Fernando Perez <fperez@colorado.edu>
1450 1454
1451 1455 * IPython/iplib.py (__init__): Add better handling of '\' under
1452 1456 Win32 for filenames. After a patch by Ville.
1453 1457
1454 1458 2004-07-17 Fernando Perez <fperez@colorado.edu>
1455 1459
1456 1460 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1457 1461 autocalling would be triggered for 'foo is bar' if foo is
1458 1462 callable. I also cleaned up the autocall detection code to use a
1459 1463 regexp, which is faster. Bug reported by Alexander Schmolck.
1460 1464
1461 1465 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1462 1466 '?' in them would confuse the help system. Reported by Alex
1463 1467 Schmolck.
1464 1468
1465 1469 2004-07-16 Fernando Perez <fperez@colorado.edu>
1466 1470
1467 1471 * IPython/GnuplotInteractive.py (__all__): added plot2.
1468 1472
1469 1473 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1470 1474 plotting dictionaries, lists or tuples of 1d arrays.
1471 1475
1472 1476 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1473 1477 optimizations.
1474 1478
1475 1479 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1476 1480 the information which was there from Janko's original IPP code:
1477 1481
1478 1482 03.05.99 20:53 porto.ifm.uni-kiel.de
1479 1483 --Started changelog.
1480 1484 --make clear do what it say it does
1481 1485 --added pretty output of lines from inputcache
1482 1486 --Made Logger a mixin class, simplifies handling of switches
1483 1487 --Added own completer class. .string<TAB> expands to last history
1484 1488 line which starts with string. The new expansion is also present
1485 1489 with Ctrl-r from the readline library. But this shows, who this
1486 1490 can be done for other cases.
1487 1491 --Added convention that all shell functions should accept a
1488 1492 parameter_string This opens the door for different behaviour for
1489 1493 each function. @cd is a good example of this.
1490 1494
1491 1495 04.05.99 12:12 porto.ifm.uni-kiel.de
1492 1496 --added logfile rotation
1493 1497 --added new mainloop method which freezes first the namespace
1494 1498
1495 1499 07.05.99 21:24 porto.ifm.uni-kiel.de
1496 1500 --added the docreader classes. Now there is a help system.
1497 1501 -This is only a first try. Currently it's not easy to put new
1498 1502 stuff in the indices. But this is the way to go. Info would be
1499 1503 better, but HTML is every where and not everybody has an info
1500 1504 system installed and it's not so easy to change html-docs to info.
1501 1505 --added global logfile option
1502 1506 --there is now a hook for object inspection method pinfo needs to
1503 1507 be provided for this. Can be reached by two '??'.
1504 1508
1505 1509 08.05.99 20:51 porto.ifm.uni-kiel.de
1506 1510 --added a README
1507 1511 --bug in rc file. Something has changed so functions in the rc
1508 1512 file need to reference the shell and not self. Not clear if it's a
1509 1513 bug or feature.
1510 1514 --changed rc file for new behavior
1511 1515
1512 1516 2004-07-15 Fernando Perez <fperez@colorado.edu>
1513 1517
1514 1518 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1515 1519 cache was falling out of sync in bizarre manners when multi-line
1516 1520 input was present. Minor optimizations and cleanup.
1517 1521
1518 1522 (Logger): Remove old Changelog info for cleanup. This is the
1519 1523 information which was there from Janko's original code:
1520 1524
1521 1525 Changes to Logger: - made the default log filename a parameter
1522 1526
1523 1527 - put a check for lines beginning with !@? in log(). Needed
1524 1528 (even if the handlers properly log their lines) for mid-session
1525 1529 logging activation to work properly. Without this, lines logged
1526 1530 in mid session, which get read from the cache, would end up
1527 1531 'bare' (with !@? in the open) in the log. Now they are caught
1528 1532 and prepended with a #.
1529 1533
1530 1534 * IPython/iplib.py (InteractiveShell.init_readline): added check
1531 1535 in case MagicCompleter fails to be defined, so we don't crash.
1532 1536
1533 1537 2004-07-13 Fernando Perez <fperez@colorado.edu>
1534 1538
1535 1539 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1536 1540 of EPS if the requested filename ends in '.eps'.
1537 1541
1538 1542 2004-07-04 Fernando Perez <fperez@colorado.edu>
1539 1543
1540 1544 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1541 1545 escaping of quotes when calling the shell.
1542 1546
1543 1547 2004-07-02 Fernando Perez <fperez@colorado.edu>
1544 1548
1545 1549 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1546 1550 gettext not working because we were clobbering '_'. Fixes
1547 1551 http://www.scipy.net/roundup/ipython/issue6.
1548 1552
1549 1553 2004-07-01 Fernando Perez <fperez@colorado.edu>
1550 1554
1551 1555 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1552 1556 into @cd. Patch by Ville.
1553 1557
1554 1558 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1555 1559 new function to store things after ipmaker runs. Patch by Ville.
1556 1560 Eventually this will go away once ipmaker is removed and the class
1557 1561 gets cleaned up, but for now it's ok. Key functionality here is
1558 1562 the addition of the persistent storage mechanism, a dict for
1559 1563 keeping data across sessions (for now just bookmarks, but more can
1560 1564 be implemented later).
1561 1565
1562 1566 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1563 1567 persistent across sections. Patch by Ville, I modified it
1564 1568 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1565 1569 added a '-l' option to list all bookmarks.
1566 1570
1567 1571 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1568 1572 center for cleanup. Registered with atexit.register(). I moved
1569 1573 here the old exit_cleanup(). After a patch by Ville.
1570 1574
1571 1575 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1572 1576 characters in the hacked shlex_split for python 2.2.
1573 1577
1574 1578 * IPython/iplib.py (file_matches): more fixes to filenames with
1575 1579 whitespace in them. It's not perfect, but limitations in python's
1576 1580 readline make it impossible to go further.
1577 1581
1578 1582 2004-06-29 Fernando Perez <fperez@colorado.edu>
1579 1583
1580 1584 * IPython/iplib.py (file_matches): escape whitespace correctly in
1581 1585 filename completions. Bug reported by Ville.
1582 1586
1583 1587 2004-06-28 Fernando Perez <fperez@colorado.edu>
1584 1588
1585 1589 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1586 1590 the history file will be called 'history-PROFNAME' (or just
1587 1591 'history' if no profile is loaded). I was getting annoyed at
1588 1592 getting my Numerical work history clobbered by pysh sessions.
1589 1593
1590 1594 * IPython/iplib.py (InteractiveShell.__init__): Internal
1591 1595 getoutputerror() function so that we can honor the system_verbose
1592 1596 flag for _all_ system calls. I also added escaping of #
1593 1597 characters here to avoid confusing Itpl.
1594 1598
1595 1599 * IPython/Magic.py (shlex_split): removed call to shell in
1596 1600 parse_options and replaced it with shlex.split(). The annoying
1597 1601 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1598 1602 to backport it from 2.3, with several frail hacks (the shlex
1599 1603 module is rather limited in 2.2). Thanks to a suggestion by Ville
1600 1604 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1601 1605 problem.
1602 1606
1603 1607 (Magic.magic_system_verbose): new toggle to print the actual
1604 1608 system calls made by ipython. Mainly for debugging purposes.
1605 1609
1606 1610 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1607 1611 doesn't support persistence. Reported (and fix suggested) by
1608 1612 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1609 1613
1610 1614 2004-06-26 Fernando Perez <fperez@colorado.edu>
1611 1615
1612 1616 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1613 1617 continue prompts.
1614 1618
1615 1619 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1616 1620 function (basically a big docstring) and a few more things here to
1617 1621 speedup startup. pysh.py is now very lightweight. We want because
1618 1622 it gets execfile'd, while InterpreterExec gets imported, so
1619 1623 byte-compilation saves time.
1620 1624
1621 1625 2004-06-25 Fernando Perez <fperez@colorado.edu>
1622 1626
1623 1627 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1624 1628 -NUM', which was recently broken.
1625 1629
1626 1630 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1627 1631 in multi-line input (but not !!, which doesn't make sense there).
1628 1632
1629 1633 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1630 1634 It's just too useful, and people can turn it off in the less
1631 1635 common cases where it's a problem.
1632 1636
1633 1637 2004-06-24 Fernando Perez <fperez@colorado.edu>
1634 1638
1635 1639 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1636 1640 special syntaxes (like alias calling) is now allied in multi-line
1637 1641 input. This is still _very_ experimental, but it's necessary for
1638 1642 efficient shell usage combining python looping syntax with system
1639 1643 calls. For now it's restricted to aliases, I don't think it
1640 1644 really even makes sense to have this for magics.
1641 1645
1642 1646 2004-06-23 Fernando Perez <fperez@colorado.edu>
1643 1647
1644 1648 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1645 1649 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1646 1650
1647 1651 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1648 1652 extensions under Windows (after code sent by Gary Bishop). The
1649 1653 extensions considered 'executable' are stored in IPython's rc
1650 1654 structure as win_exec_ext.
1651 1655
1652 1656 * IPython/genutils.py (shell): new function, like system() but
1653 1657 without return value. Very useful for interactive shell work.
1654 1658
1655 1659 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1656 1660 delete aliases.
1657 1661
1658 1662 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1659 1663 sure that the alias table doesn't contain python keywords.
1660 1664
1661 1665 2004-06-21 Fernando Perez <fperez@colorado.edu>
1662 1666
1663 1667 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1664 1668 non-existent items are found in $PATH. Reported by Thorsten.
1665 1669
1666 1670 2004-06-20 Fernando Perez <fperez@colorado.edu>
1667 1671
1668 1672 * IPython/iplib.py (complete): modified the completer so that the
1669 1673 order of priorities can be easily changed at runtime.
1670 1674
1671 1675 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1672 1676 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1673 1677
1674 1678 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1675 1679 expand Python variables prepended with $ in all system calls. The
1676 1680 same was done to InteractiveShell.handle_shell_escape. Now all
1677 1681 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1678 1682 expansion of python variables and expressions according to the
1679 1683 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1680 1684
1681 1685 Though PEP-215 has been rejected, a similar (but simpler) one
1682 1686 seems like it will go into Python 2.4, PEP-292 -
1683 1687 http://www.python.org/peps/pep-0292.html.
1684 1688
1685 1689 I'll keep the full syntax of PEP-215, since IPython has since the
1686 1690 start used Ka-Ping Yee's reference implementation discussed there
1687 1691 (Itpl), and I actually like the powerful semantics it offers.
1688 1692
1689 1693 In order to access normal shell variables, the $ has to be escaped
1690 1694 via an extra $. For example:
1691 1695
1692 1696 In [7]: PATH='a python variable'
1693 1697
1694 1698 In [8]: !echo $PATH
1695 1699 a python variable
1696 1700
1697 1701 In [9]: !echo $$PATH
1698 1702 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1699 1703
1700 1704 (Magic.parse_options): escape $ so the shell doesn't evaluate
1701 1705 things prematurely.
1702 1706
1703 1707 * IPython/iplib.py (InteractiveShell.call_alias): added the
1704 1708 ability for aliases to expand python variables via $.
1705 1709
1706 1710 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1707 1711 system, now there's a @rehash/@rehashx pair of magics. These work
1708 1712 like the csh rehash command, and can be invoked at any time. They
1709 1713 build a table of aliases to everything in the user's $PATH
1710 1714 (@rehash uses everything, @rehashx is slower but only adds
1711 1715 executable files). With this, the pysh.py-based shell profile can
1712 1716 now simply call rehash upon startup, and full access to all
1713 1717 programs in the user's path is obtained.
1714 1718
1715 1719 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1716 1720 functionality is now fully in place. I removed the old dynamic
1717 1721 code generation based approach, in favor of a much lighter one
1718 1722 based on a simple dict. The advantage is that this allows me to
1719 1723 now have thousands of aliases with negligible cost (unthinkable
1720 1724 with the old system).
1721 1725
1722 1726 2004-06-19 Fernando Perez <fperez@colorado.edu>
1723 1727
1724 1728 * IPython/iplib.py (__init__): extended MagicCompleter class to
1725 1729 also complete (last in priority) on user aliases.
1726 1730
1727 1731 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1728 1732 call to eval.
1729 1733 (ItplNS.__init__): Added a new class which functions like Itpl,
1730 1734 but allows configuring the namespace for the evaluation to occur
1731 1735 in.
1732 1736
1733 1737 2004-06-18 Fernando Perez <fperez@colorado.edu>
1734 1738
1735 1739 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1736 1740 better message when 'exit' or 'quit' are typed (a common newbie
1737 1741 confusion).
1738 1742
1739 1743 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1740 1744 check for Windows users.
1741 1745
1742 1746 * IPython/iplib.py (InteractiveShell.user_setup): removed
1743 1747 disabling of colors for Windows. I'll test at runtime and issue a
1744 1748 warning if Gary's readline isn't found, as to nudge users to
1745 1749 download it.
1746 1750
1747 1751 2004-06-16 Fernando Perez <fperez@colorado.edu>
1748 1752
1749 1753 * IPython/genutils.py (Stream.__init__): changed to print errors
1750 1754 to sys.stderr. I had a circular dependency here. Now it's
1751 1755 possible to run ipython as IDLE's shell (consider this pre-alpha,
1752 1756 since true stdout things end up in the starting terminal instead
1753 1757 of IDLE's out).
1754 1758
1755 1759 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1756 1760 users who haven't # updated their prompt_in2 definitions. Remove
1757 1761 eventually.
1758 1762 (multiple_replace): added credit to original ASPN recipe.
1759 1763
1760 1764 2004-06-15 Fernando Perez <fperez@colorado.edu>
1761 1765
1762 1766 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1763 1767 list of auto-defined aliases.
1764 1768
1765 1769 2004-06-13 Fernando Perez <fperez@colorado.edu>
1766 1770
1767 1771 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1768 1772 install was really requested (so setup.py can be used for other
1769 1773 things under Windows).
1770 1774
1771 1775 2004-06-10 Fernando Perez <fperez@colorado.edu>
1772 1776
1773 1777 * IPython/Logger.py (Logger.create_log): Manually remove any old
1774 1778 backup, since os.remove may fail under Windows. Fixes bug
1775 1779 reported by Thorsten.
1776 1780
1777 1781 2004-06-09 Fernando Perez <fperez@colorado.edu>
1778 1782
1779 1783 * examples/example-embed.py: fixed all references to %n (replaced
1780 1784 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1781 1785 for all examples and the manual as well.
1782 1786
1783 1787 2004-06-08 Fernando Perez <fperez@colorado.edu>
1784 1788
1785 1789 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1786 1790 alignment and color management. All 3 prompt subsystems now
1787 1791 inherit from BasePrompt.
1788 1792
1789 1793 * tools/release: updates for windows installer build and tag rpms
1790 1794 with python version (since paths are fixed).
1791 1795
1792 1796 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1793 1797 which will become eventually obsolete. Also fixed the default
1794 1798 prompt_in2 to use \D, so at least new users start with the correct
1795 1799 defaults.
1796 1800 WARNING: Users with existing ipythonrc files will need to apply
1797 1801 this fix manually!
1798 1802
1799 1803 * setup.py: make windows installer (.exe). This is finally the
1800 1804 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1801 1805 which I hadn't included because it required Python 2.3 (or recent
1802 1806 distutils).
1803 1807
1804 1808 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1805 1809 usage of new '\D' escape.
1806 1810
1807 1811 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1808 1812 lacks os.getuid())
1809 1813 (CachedOutput.set_colors): Added the ability to turn coloring
1810 1814 on/off with @colors even for manually defined prompt colors. It
1811 1815 uses a nasty global, but it works safely and via the generic color
1812 1816 handling mechanism.
1813 1817 (Prompt2.__init__): Introduced new escape '\D' for continuation
1814 1818 prompts. It represents the counter ('\#') as dots.
1815 1819 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1816 1820 need to update their ipythonrc files and replace '%n' with '\D' in
1817 1821 their prompt_in2 settings everywhere. Sorry, but there's
1818 1822 otherwise no clean way to get all prompts to properly align. The
1819 1823 ipythonrc shipped with IPython has been updated.
1820 1824
1821 1825 2004-06-07 Fernando Perez <fperez@colorado.edu>
1822 1826
1823 1827 * setup.py (isfile): Pass local_icons option to latex2html, so the
1824 1828 resulting HTML file is self-contained. Thanks to
1825 1829 dryice-AT-liu.com.cn for the tip.
1826 1830
1827 1831 * pysh.py: I created a new profile 'shell', which implements a
1828 1832 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1829 1833 system shell, nor will it become one anytime soon. It's mainly
1830 1834 meant to illustrate the use of the new flexible bash-like prompts.
1831 1835 I guess it could be used by hardy souls for true shell management,
1832 1836 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1833 1837 profile. This uses the InterpreterExec extension provided by
1834 1838 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1835 1839
1836 1840 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1837 1841 auto-align itself with the length of the previous input prompt
1838 1842 (taking into account the invisible color escapes).
1839 1843 (CachedOutput.__init__): Large restructuring of this class. Now
1840 1844 all three prompts (primary1, primary2, output) are proper objects,
1841 1845 managed by the 'parent' CachedOutput class. The code is still a
1842 1846 bit hackish (all prompts share state via a pointer to the cache),
1843 1847 but it's overall far cleaner than before.
1844 1848
1845 1849 * IPython/genutils.py (getoutputerror): modified to add verbose,
1846 1850 debug and header options. This makes the interface of all getout*
1847 1851 functions uniform.
1848 1852 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1849 1853
1850 1854 * IPython/Magic.py (Magic.default_option): added a function to
1851 1855 allow registering default options for any magic command. This
1852 1856 makes it easy to have profiles which customize the magics globally
1853 1857 for a certain use. The values set through this function are
1854 1858 picked up by the parse_options() method, which all magics should
1855 1859 use to parse their options.
1856 1860
1857 1861 * IPython/genutils.py (warn): modified the warnings framework to
1858 1862 use the Term I/O class. I'm trying to slowly unify all of
1859 1863 IPython's I/O operations to pass through Term.
1860 1864
1861 1865 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1862 1866 the secondary prompt to correctly match the length of the primary
1863 1867 one for any prompt. Now multi-line code will properly line up
1864 1868 even for path dependent prompts, such as the new ones available
1865 1869 via the prompt_specials.
1866 1870
1867 1871 2004-06-06 Fernando Perez <fperez@colorado.edu>
1868 1872
1869 1873 * IPython/Prompts.py (prompt_specials): Added the ability to have
1870 1874 bash-like special sequences in the prompts, which get
1871 1875 automatically expanded. Things like hostname, current working
1872 1876 directory and username are implemented already, but it's easy to
1873 1877 add more in the future. Thanks to a patch by W.J. van der Laan
1874 1878 <gnufnork-AT-hetdigitalegat.nl>
1875 1879 (prompt_specials): Added color support for prompt strings, so
1876 1880 users can define arbitrary color setups for their prompts.
1877 1881
1878 1882 2004-06-05 Fernando Perez <fperez@colorado.edu>
1879 1883
1880 1884 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1881 1885 code to load Gary Bishop's readline and configure it
1882 1886 automatically. Thanks to Gary for help on this.
1883 1887
1884 1888 2004-06-01 Fernando Perez <fperez@colorado.edu>
1885 1889
1886 1890 * IPython/Logger.py (Logger.create_log): fix bug for logging
1887 1891 with no filename (previous fix was incomplete).
1888 1892
1889 1893 2004-05-25 Fernando Perez <fperez@colorado.edu>
1890 1894
1891 1895 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1892 1896 parens would get passed to the shell.
1893 1897
1894 1898 2004-05-20 Fernando Perez <fperez@colorado.edu>
1895 1899
1896 1900 * IPython/Magic.py (Magic.magic_prun): changed default profile
1897 1901 sort order to 'time' (the more common profiling need).
1898 1902
1899 1903 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1900 1904 so that source code shown is guaranteed in sync with the file on
1901 1905 disk (also changed in psource). Similar fix to the one for
1902 1906 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
1903 1907 <yann.ledu-AT-noos.fr>.
1904 1908
1905 1909 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
1906 1910 with a single option would not be correctly parsed. Closes
1907 1911 http://www.scipy.net/roundup/ipython/issue14. This bug had been
1908 1912 introduced in 0.6.0 (on 2004-05-06).
1909 1913
1910 1914 2004-05-13 *** Released version 0.6.0
1911 1915
1912 1916 2004-05-13 Fernando Perez <fperez@colorado.edu>
1913 1917
1914 1918 * debian/: Added debian/ directory to CVS, so that debian support
1915 1919 is publicly accessible. The debian package is maintained by Jack
1916 1920 Moffit <jack-AT-xiph.org>.
1917 1921
1918 1922 * Documentation: included the notes about an ipython-based system
1919 1923 shell (the hypothetical 'pysh') into the new_design.pdf document,
1920 1924 so that these ideas get distributed to users along with the
1921 1925 official documentation.
1922 1926
1923 1927 2004-05-10 Fernando Perez <fperez@colorado.edu>
1924 1928
1925 1929 * IPython/Logger.py (Logger.create_log): fix recently introduced
1926 1930 bug (misindented line) where logstart would fail when not given an
1927 1931 explicit filename.
1928 1932
1929 1933 2004-05-09 Fernando Perez <fperez@colorado.edu>
1930 1934
1931 1935 * IPython/Magic.py (Magic.parse_options): skip system call when
1932 1936 there are no options to look for. Faster, cleaner for the common
1933 1937 case.
1934 1938
1935 1939 * Documentation: many updates to the manual: describing Windows
1936 1940 support better, Gnuplot updates, credits, misc small stuff. Also
1937 1941 updated the new_design doc a bit.
1938 1942
1939 1943 2004-05-06 *** Released version 0.6.0.rc1
1940 1944
1941 1945 2004-05-06 Fernando Perez <fperez@colorado.edu>
1942 1946
1943 1947 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
1944 1948 operations to use the vastly more efficient list/''.join() method.
1945 1949 (FormattedTB.text): Fix
1946 1950 http://www.scipy.net/roundup/ipython/issue12 - exception source
1947 1951 extract not updated after reload. Thanks to Mike Salib
1948 1952 <msalib-AT-mit.edu> for pinning the source of the problem.
1949 1953 Fortunately, the solution works inside ipython and doesn't require
1950 1954 any changes to python proper.
1951 1955
1952 1956 * IPython/Magic.py (Magic.parse_options): Improved to process the
1953 1957 argument list as a true shell would (by actually using the
1954 1958 underlying system shell). This way, all @magics automatically get
1955 1959 shell expansion for variables. Thanks to a comment by Alex
1956 1960 Schmolck.
1957 1961
1958 1962 2004-04-04 Fernando Perez <fperez@colorado.edu>
1959 1963
1960 1964 * IPython/iplib.py (InteractiveShell.interact): Added a special
1961 1965 trap for a debugger quit exception, which is basically impossible
1962 1966 to handle by normal mechanisms, given what pdb does to the stack.
1963 1967 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
1964 1968
1965 1969 2004-04-03 Fernando Perez <fperez@colorado.edu>
1966 1970
1967 1971 * IPython/genutils.py (Term): Standardized the names of the Term
1968 1972 class streams to cin/cout/cerr, following C++ naming conventions
1969 1973 (I can't use in/out/err because 'in' is not a valid attribute
1970 1974 name).
1971 1975
1972 1976 * IPython/iplib.py (InteractiveShell.interact): don't increment
1973 1977 the prompt if there's no user input. By Daniel 'Dang' Griffith
1974 1978 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
1975 1979 Francois Pinard.
1976 1980
1977 1981 2004-04-02 Fernando Perez <fperez@colorado.edu>
1978 1982
1979 1983 * IPython/genutils.py (Stream.__init__): Modified to survive at
1980 1984 least importing in contexts where stdin/out/err aren't true file
1981 1985 objects, such as PyCrust (they lack fileno() and mode). However,
1982 1986 the recovery facilities which rely on these things existing will
1983 1987 not work.
1984 1988
1985 1989 2004-04-01 Fernando Perez <fperez@colorado.edu>
1986 1990
1987 1991 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
1988 1992 use the new getoutputerror() function, so it properly
1989 1993 distinguishes stdout/err.
1990 1994
1991 1995 * IPython/genutils.py (getoutputerror): added a function to
1992 1996 capture separately the standard output and error of a command.
1993 1997 After a comment from dang on the mailing lists. This code is
1994 1998 basically a modified version of commands.getstatusoutput(), from
1995 1999 the standard library.
1996 2000
1997 2001 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
1998 2002 '!!' as a special syntax (shorthand) to access @sx.
1999 2003
2000 2004 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
2001 2005 command and return its output as a list split on '\n'.
2002 2006
2003 2007 2004-03-31 Fernando Perez <fperez@colorado.edu>
2004 2008
2005 2009 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
2006 2010 method to dictionaries used as FakeModule instances if they lack
2007 2011 it. At least pydoc in python2.3 breaks for runtime-defined
2008 2012 functions without this hack. At some point I need to _really_
2009 2013 understand what FakeModule is doing, because it's a gross hack.
2010 2014 But it solves Arnd's problem for now...
2011 2015
2012 2016 2004-02-27 Fernando Perez <fperez@colorado.edu>
2013 2017
2014 2018 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
2015 2019 mode would behave erratically. Also increased the number of
2016 2020 possible logs in rotate mod to 999. Thanks to Rod Holland
2017 2021 <rhh@StructureLABS.com> for the report and fixes.
2018 2022
2019 2023 2004-02-26 Fernando Perez <fperez@colorado.edu>
2020 2024
2021 2025 * IPython/genutils.py (page): Check that the curses module really
2022 2026 has the initscr attribute before trying to use it. For some
2023 2027 reason, the Solaris curses module is missing this. I think this
2024 2028 should be considered a Solaris python bug, but I'm not sure.
2025 2029
2026 2030 2004-01-17 Fernando Perez <fperez@colorado.edu>
2027 2031
2028 2032 * IPython/genutils.py (Stream.__init__): Changes to try to make
2029 2033 ipython robust against stdin/out/err being closed by the user.
2030 2034 This is 'user error' (and blocks a normal python session, at least
2031 2035 the stdout case). However, Ipython should be able to survive such
2032 2036 instances of abuse as gracefully as possible. To simplify the
2033 2037 coding and maintain compatibility with Gary Bishop's Term
2034 2038 contributions, I've made use of classmethods for this. I think
2035 2039 this introduces a dependency on python 2.2.
2036 2040
2037 2041 2004-01-13 Fernando Perez <fperez@colorado.edu>
2038 2042
2039 2043 * IPython/numutils.py (exp_safe): simplified the code a bit and
2040 2044 removed the need for importing the kinds module altogether.
2041 2045
2042 2046 2004-01-06 Fernando Perez <fperez@colorado.edu>
2043 2047
2044 2048 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
2045 2049 a magic function instead, after some community feedback. No
2046 2050 special syntax will exist for it, but its name is deliberately
2047 2051 very short.
2048 2052
2049 2053 2003-12-20 Fernando Perez <fperez@colorado.edu>
2050 2054
2051 2055 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
2052 2056 new functionality, to automagically assign the result of a shell
2053 2057 command to a variable. I'll solicit some community feedback on
2054 2058 this before making it permanent.
2055 2059
2056 2060 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
2057 2061 requested about callables for which inspect couldn't obtain a
2058 2062 proper argspec. Thanks to a crash report sent by Etienne
2059 2063 Posthumus <etienne-AT-apple01.cs.vu.nl>.
2060 2064
2061 2065 2003-12-09 Fernando Perez <fperez@colorado.edu>
2062 2066
2063 2067 * IPython/genutils.py (page): patch for the pager to work across
2064 2068 various versions of Windows. By Gary Bishop.
2065 2069
2066 2070 2003-12-04 Fernando Perez <fperez@colorado.edu>
2067 2071
2068 2072 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
2069 2073 Gnuplot.py version 1.7, whose internal names changed quite a bit.
2070 2074 While I tested this and it looks ok, there may still be corner
2071 2075 cases I've missed.
2072 2076
2073 2077 2003-12-01 Fernando Perez <fperez@colorado.edu>
2074 2078
2075 2079 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
2076 2080 where a line like 'p,q=1,2' would fail because the automagic
2077 2081 system would be triggered for @p.
2078 2082
2079 2083 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
2080 2084 cleanups, code unmodified.
2081 2085
2082 2086 * IPython/genutils.py (Term): added a class for IPython to handle
2083 2087 output. In most cases it will just be a proxy for stdout/err, but
2084 2088 having this allows modifications to be made for some platforms,
2085 2089 such as handling color escapes under Windows. All of this code
2086 2090 was contributed by Gary Bishop, with minor modifications by me.
2087 2091 The actual changes affect many files.
2088 2092
2089 2093 2003-11-30 Fernando Perez <fperez@colorado.edu>
2090 2094
2091 2095 * IPython/iplib.py (file_matches): new completion code, courtesy
2092 2096 of Jeff Collins. This enables filename completion again under
2093 2097 python 2.3, which disabled it at the C level.
2094 2098
2095 2099 2003-11-11 Fernando Perez <fperez@colorado.edu>
2096 2100
2097 2101 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
2098 2102 for Numeric.array(map(...)), but often convenient.
2099 2103
2100 2104 2003-11-05 Fernando Perez <fperez@colorado.edu>
2101 2105
2102 2106 * IPython/numutils.py (frange): Changed a call from int() to
2103 2107 int(round()) to prevent a problem reported with arange() in the
2104 2108 numpy list.
2105 2109
2106 2110 2003-10-06 Fernando Perez <fperez@colorado.edu>
2107 2111
2108 2112 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
2109 2113 prevent crashes if sys lacks an argv attribute (it happens with
2110 2114 embedded interpreters which build a bare-bones sys module).
2111 2115 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
2112 2116
2113 2117 2003-09-24 Fernando Perez <fperez@colorado.edu>
2114 2118
2115 2119 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
2116 2120 to protect against poorly written user objects where __getattr__
2117 2121 raises exceptions other than AttributeError. Thanks to a bug
2118 2122 report by Oliver Sander <osander-AT-gmx.de>.
2119 2123
2120 2124 * IPython/FakeModule.py (FakeModule.__repr__): this method was
2121 2125 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
2122 2126
2123 2127 2003-09-09 Fernando Perez <fperez@colorado.edu>
2124 2128
2125 2129 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
2126 2130 unpacking a list whith a callable as first element would
2127 2131 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
2128 2132 Collins.
2129 2133
2130 2134 2003-08-25 *** Released version 0.5.0
2131 2135
2132 2136 2003-08-22 Fernando Perez <fperez@colorado.edu>
2133 2137
2134 2138 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
2135 2139 improperly defined user exceptions. Thanks to feedback from Mark
2136 2140 Russell <mrussell-AT-verio.net>.
2137 2141
2138 2142 2003-08-20 Fernando Perez <fperez@colorado.edu>
2139 2143
2140 2144 * IPython/OInspect.py (Inspector.pinfo): changed String Form
2141 2145 printing so that it would print multi-line string forms starting
2142 2146 with a new line. This way the formatting is better respected for
2143 2147 objects which work hard to make nice string forms.
2144 2148
2145 2149 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
2146 2150 autocall would overtake data access for objects with both
2147 2151 __getitem__ and __call__.
2148 2152
2149 2153 2003-08-19 *** Released version 0.5.0-rc1
2150 2154
2151 2155 2003-08-19 Fernando Perez <fperez@colorado.edu>
2152 2156
2153 2157 * IPython/deep_reload.py (load_tail): single tiny change here
2154 2158 seems to fix the long-standing bug of dreload() failing to work
2155 2159 for dotted names. But this module is pretty tricky, so I may have
2156 2160 missed some subtlety. Needs more testing!.
2157 2161
2158 2162 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
2159 2163 exceptions which have badly implemented __str__ methods.
2160 2164 (VerboseTB.text): harden against inspect.getinnerframes crashing,
2161 2165 which I've been getting reports about from Python 2.3 users. I
2162 2166 wish I had a simple test case to reproduce the problem, so I could
2163 2167 either write a cleaner workaround or file a bug report if
2164 2168 necessary.
2165 2169
2166 2170 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
2167 2171 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
2168 2172 a bug report by Tjabo Kloppenburg.
2169 2173
2170 2174 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
2171 2175 crashes. Wrapped the pdb call in a blanket try/except, since pdb
2172 2176 seems rather unstable. Thanks to a bug report by Tjabo
2173 2177 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
2174 2178
2175 2179 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
2176 2180 this out soon because of the critical fixes in the inner loop for
2177 2181 generators.
2178 2182
2179 2183 * IPython/Magic.py (Magic.getargspec): removed. This (and
2180 2184 _get_def) have been obsoleted by OInspect for a long time, I
2181 2185 hadn't noticed that they were dead code.
2182 2186 (Magic._ofind): restored _ofind functionality for a few literals
2183 2187 (those in ["''",'""','[]','{}','()']). But it won't work anymore
2184 2188 for things like "hello".capitalize?, since that would require a
2185 2189 potentially dangerous eval() again.
2186 2190
2187 2191 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
2188 2192 logic a bit more to clean up the escapes handling and minimize the
2189 2193 use of _ofind to only necessary cases. The interactive 'feel' of
2190 2194 IPython should have improved quite a bit with the changes in
2191 2195 _prefilter and _ofind (besides being far safer than before).
2192 2196
2193 2197 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
2194 2198 obscure, never reported). Edit would fail to find the object to
2195 2199 edit under some circumstances.
2196 2200 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
2197 2201 which were causing double-calling of generators. Those eval calls
2198 2202 were _very_ dangerous, since code with side effects could be
2199 2203 triggered. As they say, 'eval is evil'... These were the
2200 2204 nastiest evals in IPython. Besides, _ofind is now far simpler,
2201 2205 and it should also be quite a bit faster. Its use of inspect is
2202 2206 also safer, so perhaps some of the inspect-related crashes I've
2203 2207 seen lately with Python 2.3 might be taken care of. That will
2204 2208 need more testing.
2205 2209
2206 2210 2003-08-17 Fernando Perez <fperez@colorado.edu>
2207 2211
2208 2212 * IPython/iplib.py (InteractiveShell._prefilter): significant
2209 2213 simplifications to the logic for handling user escapes. Faster
2210 2214 and simpler code.
2211 2215
2212 2216 2003-08-14 Fernando Perez <fperez@colorado.edu>
2213 2217
2214 2218 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
2215 2219 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
2216 2220 but it should be quite a bit faster. And the recursive version
2217 2221 generated O(log N) intermediate storage for all rank>1 arrays,
2218 2222 even if they were contiguous.
2219 2223 (l1norm): Added this function.
2220 2224 (norm): Added this function for arbitrary norms (including
2221 2225 l-infinity). l1 and l2 are still special cases for convenience
2222 2226 and speed.
2223 2227
2224 2228 2003-08-03 Fernando Perez <fperez@colorado.edu>
2225 2229
2226 2230 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
2227 2231 exceptions, which now raise PendingDeprecationWarnings in Python
2228 2232 2.3. There were some in Magic and some in Gnuplot2.
2229 2233
2230 2234 2003-06-30 Fernando Perez <fperez@colorado.edu>
2231 2235
2232 2236 * IPython/genutils.py (page): modified to call curses only for
2233 2237 terminals where TERM=='xterm'. After problems under many other
2234 2238 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2235 2239
2236 2240 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2237 2241 would be triggered when readline was absent. This was just an old
2238 2242 debugging statement I'd forgotten to take out.
2239 2243
2240 2244 2003-06-20 Fernando Perez <fperez@colorado.edu>
2241 2245
2242 2246 * IPython/genutils.py (clock): modified to return only user time
2243 2247 (not counting system time), after a discussion on scipy. While
2244 2248 system time may be a useful quantity occasionally, it may much
2245 2249 more easily be skewed by occasional swapping or other similar
2246 2250 activity.
2247 2251
2248 2252 2003-06-05 Fernando Perez <fperez@colorado.edu>
2249 2253
2250 2254 * IPython/numutils.py (identity): new function, for building
2251 2255 arbitrary rank Kronecker deltas (mostly backwards compatible with
2252 2256 Numeric.identity)
2253 2257
2254 2258 2003-06-03 Fernando Perez <fperez@colorado.edu>
2255 2259
2256 2260 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2257 2261 arguments passed to magics with spaces, to allow trailing '\' to
2258 2262 work normally (mainly for Windows users).
2259 2263
2260 2264 2003-05-29 Fernando Perez <fperez@colorado.edu>
2261 2265
2262 2266 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2263 2267 instead of pydoc.help. This fixes a bizarre behavior where
2264 2268 printing '%s' % locals() would trigger the help system. Now
2265 2269 ipython behaves like normal python does.
2266 2270
2267 2271 Note that if one does 'from pydoc import help', the bizarre
2268 2272 behavior returns, but this will also happen in normal python, so
2269 2273 it's not an ipython bug anymore (it has to do with how pydoc.help
2270 2274 is implemented).
2271 2275
2272 2276 2003-05-22 Fernando Perez <fperez@colorado.edu>
2273 2277
2274 2278 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2275 2279 return [] instead of None when nothing matches, also match to end
2276 2280 of line. Patch by Gary Bishop.
2277 2281
2278 2282 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2279 2283 protection as before, for files passed on the command line. This
2280 2284 prevents the CrashHandler from kicking in if user files call into
2281 2285 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2282 2286 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2283 2287
2284 2288 2003-05-20 *** Released version 0.4.0
2285 2289
2286 2290 2003-05-20 Fernando Perez <fperez@colorado.edu>
2287 2291
2288 2292 * setup.py: added support for manpages. It's a bit hackish b/c of
2289 2293 a bug in the way the bdist_rpm distutils target handles gzipped
2290 2294 manpages, but it works. After a patch by Jack.
2291 2295
2292 2296 2003-05-19 Fernando Perez <fperez@colorado.edu>
2293 2297
2294 2298 * IPython/numutils.py: added a mockup of the kinds module, since
2295 2299 it was recently removed from Numeric. This way, numutils will
2296 2300 work for all users even if they are missing kinds.
2297 2301
2298 2302 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2299 2303 failure, which can occur with SWIG-wrapped extensions. After a
2300 2304 crash report from Prabhu.
2301 2305
2302 2306 2003-05-16 Fernando Perez <fperez@colorado.edu>
2303 2307
2304 2308 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2305 2309 protect ipython from user code which may call directly
2306 2310 sys.excepthook (this looks like an ipython crash to the user, even
2307 2311 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2308 2312 This is especially important to help users of WxWindows, but may
2309 2313 also be useful in other cases.
2310 2314
2311 2315 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2312 2316 an optional tb_offset to be specified, and to preserve exception
2313 2317 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2314 2318
2315 2319 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2316 2320
2317 2321 2003-05-15 Fernando Perez <fperez@colorado.edu>
2318 2322
2319 2323 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2320 2324 installing for a new user under Windows.
2321 2325
2322 2326 2003-05-12 Fernando Perez <fperez@colorado.edu>
2323 2327
2324 2328 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2325 2329 handler for Emacs comint-based lines. Currently it doesn't do
2326 2330 much (but importantly, it doesn't update the history cache). In
2327 2331 the future it may be expanded if Alex needs more functionality
2328 2332 there.
2329 2333
2330 2334 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2331 2335 info to crash reports.
2332 2336
2333 2337 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2334 2338 just like Python's -c. Also fixed crash with invalid -color
2335 2339 option value at startup. Thanks to Will French
2336 2340 <wfrench-AT-bestweb.net> for the bug report.
2337 2341
2338 2342 2003-05-09 Fernando Perez <fperez@colorado.edu>
2339 2343
2340 2344 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2341 2345 to EvalDict (it's a mapping, after all) and simplified its code
2342 2346 quite a bit, after a nice discussion on c.l.py where Gustavo
2343 2347 CΓ³rdova <gcordova-AT-sismex.com> suggested the new version.
2344 2348
2345 2349 2003-04-30 Fernando Perez <fperez@colorado.edu>
2346 2350
2347 2351 * IPython/genutils.py (timings_out): modified it to reduce its
2348 2352 overhead in the common reps==1 case.
2349 2353
2350 2354 2003-04-29 Fernando Perez <fperez@colorado.edu>
2351 2355
2352 2356 * IPython/genutils.py (timings_out): Modified to use the resource
2353 2357 module, which avoids the wraparound problems of time.clock().
2354 2358
2355 2359 2003-04-17 *** Released version 0.2.15pre4
2356 2360
2357 2361 2003-04-17 Fernando Perez <fperez@colorado.edu>
2358 2362
2359 2363 * setup.py (scriptfiles): Split windows-specific stuff over to a
2360 2364 separate file, in an attempt to have a Windows GUI installer.
2361 2365 That didn't work, but part of the groundwork is done.
2362 2366
2363 2367 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2364 2368 indent/unindent with 4 spaces. Particularly useful in combination
2365 2369 with the new auto-indent option.
2366 2370
2367 2371 2003-04-16 Fernando Perez <fperez@colorado.edu>
2368 2372
2369 2373 * IPython/Magic.py: various replacements of self.rc for
2370 2374 self.shell.rc. A lot more remains to be done to fully disentangle
2371 2375 this class from the main Shell class.
2372 2376
2373 2377 * IPython/GnuplotRuntime.py: added checks for mouse support so
2374 2378 that we don't try to enable it if the current gnuplot doesn't
2375 2379 really support it. Also added checks so that we don't try to
2376 2380 enable persist under Windows (where Gnuplot doesn't recognize the
2377 2381 option).
2378 2382
2379 2383 * IPython/iplib.py (InteractiveShell.interact): Added optional
2380 2384 auto-indenting code, after a patch by King C. Shu
2381 2385 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2382 2386 get along well with pasting indented code. If I ever figure out
2383 2387 how to make that part go well, it will become on by default.
2384 2388
2385 2389 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2386 2390 crash ipython if there was an unmatched '%' in the user's prompt
2387 2391 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2388 2392
2389 2393 * IPython/iplib.py (InteractiveShell.interact): removed the
2390 2394 ability to ask the user whether he wants to crash or not at the
2391 2395 'last line' exception handler. Calling functions at that point
2392 2396 changes the stack, and the error reports would have incorrect
2393 2397 tracebacks.
2394 2398
2395 2399 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2396 2400 pass through a peger a pretty-printed form of any object. After a
2397 2401 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2398 2402
2399 2403 2003-04-14 Fernando Perez <fperez@colorado.edu>
2400 2404
2401 2405 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2402 2406 all files in ~ would be modified at first install (instead of
2403 2407 ~/.ipython). This could be potentially disastrous, as the
2404 2408 modification (make line-endings native) could damage binary files.
2405 2409
2406 2410 2003-04-10 Fernando Perez <fperez@colorado.edu>
2407 2411
2408 2412 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2409 2413 handle only lines which are invalid python. This now means that
2410 2414 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2411 2415 for the bug report.
2412 2416
2413 2417 2003-04-01 Fernando Perez <fperez@colorado.edu>
2414 2418
2415 2419 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2416 2420 where failing to set sys.last_traceback would crash pdb.pm().
2417 2421 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2418 2422 report.
2419 2423
2420 2424 2003-03-25 Fernando Perez <fperez@colorado.edu>
2421 2425
2422 2426 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2423 2427 before printing it (it had a lot of spurious blank lines at the
2424 2428 end).
2425 2429
2426 2430 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2427 2431 output would be sent 21 times! Obviously people don't use this
2428 2432 too often, or I would have heard about it.
2429 2433
2430 2434 2003-03-24 Fernando Perez <fperez@colorado.edu>
2431 2435
2432 2436 * setup.py (scriptfiles): renamed the data_files parameter from
2433 2437 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2434 2438 for the patch.
2435 2439
2436 2440 2003-03-20 Fernando Perez <fperez@colorado.edu>
2437 2441
2438 2442 * IPython/genutils.py (error): added error() and fatal()
2439 2443 functions.
2440 2444
2441 2445 2003-03-18 *** Released version 0.2.15pre3
2442 2446
2443 2447 2003-03-18 Fernando Perez <fperez@colorado.edu>
2444 2448
2445 2449 * setupext/install_data_ext.py
2446 2450 (install_data_ext.initialize_options): Class contributed by Jack
2447 2451 Moffit for fixing the old distutils hack. He is sending this to
2448 2452 the distutils folks so in the future we may not need it as a
2449 2453 private fix.
2450 2454
2451 2455 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2452 2456 changes for Debian packaging. See his patch for full details.
2453 2457 The old distutils hack of making the ipythonrc* files carry a
2454 2458 bogus .py extension is gone, at last. Examples were moved to a
2455 2459 separate subdir under doc/, and the separate executable scripts
2456 2460 now live in their own directory. Overall a great cleanup. The
2457 2461 manual was updated to use the new files, and setup.py has been
2458 2462 fixed for this setup.
2459 2463
2460 2464 * IPython/PyColorize.py (Parser.usage): made non-executable and
2461 2465 created a pycolor wrapper around it to be included as a script.
2462 2466
2463 2467 2003-03-12 *** Released version 0.2.15pre2
2464 2468
2465 2469 2003-03-12 Fernando Perez <fperez@colorado.edu>
2466 2470
2467 2471 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2468 2472 long-standing problem with garbage characters in some terminals.
2469 2473 The issue was really that the \001 and \002 escapes must _only_ be
2470 2474 passed to input prompts (which call readline), but _never_ to
2471 2475 normal text to be printed on screen. I changed ColorANSI to have
2472 2476 two classes: TermColors and InputTermColors, each with the
2473 2477 appropriate escapes for input prompts or normal text. The code in
2474 2478 Prompts.py got slightly more complicated, but this very old and
2475 2479 annoying bug is finally fixed.
2476 2480
2477 2481 All the credit for nailing down the real origin of this problem
2478 2482 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2479 2483 *Many* thanks to him for spending quite a bit of effort on this.
2480 2484
2481 2485 2003-03-05 *** Released version 0.2.15pre1
2482 2486
2483 2487 2003-03-03 Fernando Perez <fperez@colorado.edu>
2484 2488
2485 2489 * IPython/FakeModule.py: Moved the former _FakeModule to a
2486 2490 separate file, because it's also needed by Magic (to fix a similar
2487 2491 pickle-related issue in @run).
2488 2492
2489 2493 2003-03-02 Fernando Perez <fperez@colorado.edu>
2490 2494
2491 2495 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2492 2496 the autocall option at runtime.
2493 2497 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2494 2498 across Magic.py to start separating Magic from InteractiveShell.
2495 2499 (Magic._ofind): Fixed to return proper namespace for dotted
2496 2500 names. Before, a dotted name would always return 'not currently
2497 2501 defined', because it would find the 'parent'. s.x would be found,
2498 2502 but since 'x' isn't defined by itself, it would get confused.
2499 2503 (Magic.magic_run): Fixed pickling problems reported by Ralf
2500 2504 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2501 2505 that I'd used when Mike Heeter reported similar issues at the
2502 2506 top-level, but now for @run. It boils down to injecting the
2503 2507 namespace where code is being executed with something that looks
2504 2508 enough like a module to fool pickle.dump(). Since a pickle stores
2505 2509 a named reference to the importing module, we need this for
2506 2510 pickles to save something sensible.
2507 2511
2508 2512 * IPython/ipmaker.py (make_IPython): added an autocall option.
2509 2513
2510 2514 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2511 2515 the auto-eval code. Now autocalling is an option, and the code is
2512 2516 also vastly safer. There is no more eval() involved at all.
2513 2517
2514 2518 2003-03-01 Fernando Perez <fperez@colorado.edu>
2515 2519
2516 2520 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2517 2521 dict with named keys instead of a tuple.
2518 2522
2519 2523 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2520 2524
2521 2525 * setup.py (make_shortcut): Fixed message about directories
2522 2526 created during Windows installation (the directories were ok, just
2523 2527 the printed message was misleading). Thanks to Chris Liechti
2524 2528 <cliechti-AT-gmx.net> for the heads up.
2525 2529
2526 2530 2003-02-21 Fernando Perez <fperez@colorado.edu>
2527 2531
2528 2532 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2529 2533 of ValueError exception when checking for auto-execution. This
2530 2534 one is raised by things like Numeric arrays arr.flat when the
2531 2535 array is non-contiguous.
2532 2536
2533 2537 2003-01-31 Fernando Perez <fperez@colorado.edu>
2534 2538
2535 2539 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2536 2540 not return any value at all (even though the command would get
2537 2541 executed).
2538 2542 (xsys): Flush stdout right after printing the command to ensure
2539 2543 proper ordering of commands and command output in the total
2540 2544 output.
2541 2545 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2542 2546 system/getoutput as defaults. The old ones are kept for
2543 2547 compatibility reasons, so no code which uses this library needs
2544 2548 changing.
2545 2549
2546 2550 2003-01-27 *** Released version 0.2.14
2547 2551
2548 2552 2003-01-25 Fernando Perez <fperez@colorado.edu>
2549 2553
2550 2554 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2551 2555 functions defined in previous edit sessions could not be re-edited
2552 2556 (because the temp files were immediately removed). Now temp files
2553 2557 are removed only at IPython's exit.
2554 2558 (Magic.magic_run): Improved @run to perform shell-like expansions
2555 2559 on its arguments (~users and $VARS). With this, @run becomes more
2556 2560 like a normal command-line.
2557 2561
2558 2562 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2559 2563 bugs related to embedding and cleaned up that code. A fairly
2560 2564 important one was the impossibility to access the global namespace
2561 2565 through the embedded IPython (only local variables were visible).
2562 2566
2563 2567 2003-01-14 Fernando Perez <fperez@colorado.edu>
2564 2568
2565 2569 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2566 2570 auto-calling to be a bit more conservative. Now it doesn't get
2567 2571 triggered if any of '!=()<>' are in the rest of the input line, to
2568 2572 allow comparing callables. Thanks to Alex for the heads up.
2569 2573
2570 2574 2003-01-07 Fernando Perez <fperez@colorado.edu>
2571 2575
2572 2576 * IPython/genutils.py (page): fixed estimation of the number of
2573 2577 lines in a string to be paged to simply count newlines. This
2574 2578 prevents over-guessing due to embedded escape sequences. A better
2575 2579 long-term solution would involve stripping out the control chars
2576 2580 for the count, but it's potentially so expensive I just don't
2577 2581 think it's worth doing.
2578 2582
2579 2583 2002-12-19 *** Released version 0.2.14pre50
2580 2584
2581 2585 2002-12-19 Fernando Perez <fperez@colorado.edu>
2582 2586
2583 2587 * tools/release (version): Changed release scripts to inform
2584 2588 Andrea and build a NEWS file with a list of recent changes.
2585 2589
2586 2590 * IPython/ColorANSI.py (__all__): changed terminal detection
2587 2591 code. Seems to work better for xterms without breaking
2588 2592 konsole. Will need more testing to determine if WinXP and Mac OSX
2589 2593 also work ok.
2590 2594
2591 2595 2002-12-18 *** Released version 0.2.14pre49
2592 2596
2593 2597 2002-12-18 Fernando Perez <fperez@colorado.edu>
2594 2598
2595 2599 * Docs: added new info about Mac OSX, from Andrea.
2596 2600
2597 2601 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2598 2602 allow direct plotting of python strings whose format is the same
2599 2603 of gnuplot data files.
2600 2604
2601 2605 2002-12-16 Fernando Perez <fperez@colorado.edu>
2602 2606
2603 2607 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2604 2608 value of exit question to be acknowledged.
2605 2609
2606 2610 2002-12-03 Fernando Perez <fperez@colorado.edu>
2607 2611
2608 2612 * IPython/ipmaker.py: removed generators, which had been added
2609 2613 by mistake in an earlier debugging run. This was causing trouble
2610 2614 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2611 2615 for pointing this out.
2612 2616
2613 2617 2002-11-17 Fernando Perez <fperez@colorado.edu>
2614 2618
2615 2619 * Manual: updated the Gnuplot section.
2616 2620
2617 2621 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2618 2622 a much better split of what goes in Runtime and what goes in
2619 2623 Interactive.
2620 2624
2621 2625 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2622 2626 being imported from iplib.
2623 2627
2624 2628 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2625 2629 for command-passing. Now the global Gnuplot instance is called
2626 2630 'gp' instead of 'g', which was really a far too fragile and
2627 2631 common name.
2628 2632
2629 2633 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2630 2634 bounding boxes generated by Gnuplot for square plots.
2631 2635
2632 2636 * IPython/genutils.py (popkey): new function added. I should
2633 2637 suggest this on c.l.py as a dict method, it seems useful.
2634 2638
2635 2639 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2636 2640 to transparently handle PostScript generation. MUCH better than
2637 2641 the previous plot_eps/replot_eps (which I removed now). The code
2638 2642 is also fairly clean and well documented now (including
2639 2643 docstrings).
2640 2644
2641 2645 2002-11-13 Fernando Perez <fperez@colorado.edu>
2642 2646
2643 2647 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2644 2648 (inconsistent with options).
2645 2649
2646 2650 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2647 2651 manually disabled, I don't know why. Fixed it.
2648 2652 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2649 2653 eps output.
2650 2654
2651 2655 2002-11-12 Fernando Perez <fperez@colorado.edu>
2652 2656
2653 2657 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2654 2658 don't propagate up to caller. Fixes crash reported by François
2655 2659 Pinard.
2656 2660
2657 2661 2002-11-09 Fernando Perez <fperez@colorado.edu>
2658 2662
2659 2663 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2660 2664 history file for new users.
2661 2665 (make_IPython): fixed bug where initial install would leave the
2662 2666 user running in the .ipython dir.
2663 2667 (make_IPython): fixed bug where config dir .ipython would be
2664 2668 created regardless of the given -ipythondir option. Thanks to Cory
2665 2669 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2666 2670
2667 2671 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2668 2672 type confirmations. Will need to use it in all of IPython's code
2669 2673 consistently.
2670 2674
2671 2675 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2672 2676 context to print 31 lines instead of the default 5. This will make
2673 2677 the crash reports extremely detailed in case the problem is in
2674 2678 libraries I don't have access to.
2675 2679
2676 2680 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2677 2681 line of defense' code to still crash, but giving users fair
2678 2682 warning. I don't want internal errors to go unreported: if there's
2679 2683 an internal problem, IPython should crash and generate a full
2680 2684 report.
2681 2685
2682 2686 2002-11-08 Fernando Perez <fperez@colorado.edu>
2683 2687
2684 2688 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2685 2689 otherwise uncaught exceptions which can appear if people set
2686 2690 sys.stdout to something badly broken. Thanks to a crash report
2687 2691 from henni-AT-mail.brainbot.com.
2688 2692
2689 2693 2002-11-04 Fernando Perez <fperez@colorado.edu>
2690 2694
2691 2695 * IPython/iplib.py (InteractiveShell.interact): added
2692 2696 __IPYTHON__active to the builtins. It's a flag which goes on when
2693 2697 the interaction starts and goes off again when it stops. This
2694 2698 allows embedding code to detect being inside IPython. Before this
2695 2699 was done via __IPYTHON__, but that only shows that an IPython
2696 2700 instance has been created.
2697 2701
2698 2702 * IPython/Magic.py (Magic.magic_env): I realized that in a
2699 2703 UserDict, instance.data holds the data as a normal dict. So I
2700 2704 modified @env to return os.environ.data instead of rebuilding a
2701 2705 dict by hand.
2702 2706
2703 2707 2002-11-02 Fernando Perez <fperez@colorado.edu>
2704 2708
2705 2709 * IPython/genutils.py (warn): changed so that level 1 prints no
2706 2710 header. Level 2 is now the default (with 'WARNING' header, as
2707 2711 before). I think I tracked all places where changes were needed in
2708 2712 IPython, but outside code using the old level numbering may have
2709 2713 broken.
2710 2714
2711 2715 * IPython/iplib.py (InteractiveShell.runcode): added this to
2712 2716 handle the tracebacks in SystemExit traps correctly. The previous
2713 2717 code (through interact) was printing more of the stack than
2714 2718 necessary, showing IPython internal code to the user.
2715 2719
2716 2720 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2717 2721 default. Now that the default at the confirmation prompt is yes,
2718 2722 it's not so intrusive. François' argument that ipython sessions
2719 2723 tend to be complex enough not to lose them from an accidental C-d,
2720 2724 is a valid one.
2721 2725
2722 2726 * IPython/iplib.py (InteractiveShell.interact): added a
2723 2727 showtraceback() call to the SystemExit trap, and modified the exit
2724 2728 confirmation to have yes as the default.
2725 2729
2726 2730 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2727 2731 this file. It's been gone from the code for a long time, this was
2728 2732 simply leftover junk.
2729 2733
2730 2734 2002-11-01 Fernando Perez <fperez@colorado.edu>
2731 2735
2732 2736 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2733 2737 added. If set, IPython now traps EOF and asks for
2734 2738 confirmation. After a request by François Pinard.
2735 2739
2736 2740 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2737 2741 of @abort, and with a new (better) mechanism for handling the
2738 2742 exceptions.
2739 2743
2740 2744 2002-10-27 Fernando Perez <fperez@colorado.edu>
2741 2745
2742 2746 * IPython/usage.py (__doc__): updated the --help information and
2743 2747 the ipythonrc file to indicate that -log generates
2744 2748 ./ipython.log. Also fixed the corresponding info in @logstart.
2745 2749 This and several other fixes in the manuals thanks to reports by
2746 2750 François Pinard <pinard-AT-iro.umontreal.ca>.
2747 2751
2748 2752 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2749 2753 refer to @logstart (instead of @log, which doesn't exist).
2750 2754
2751 2755 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2752 2756 AttributeError crash. Thanks to Christopher Armstrong
2753 2757 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2754 2758 introduced recently (in 0.2.14pre37) with the fix to the eval
2755 2759 problem mentioned below.
2756 2760
2757 2761 2002-10-17 Fernando Perez <fperez@colorado.edu>
2758 2762
2759 2763 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2760 2764 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2761 2765
2762 2766 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2763 2767 this function to fix a problem reported by Alex Schmolck. He saw
2764 2768 it with list comprehensions and generators, which were getting
2765 2769 called twice. The real problem was an 'eval' call in testing for
2766 2770 automagic which was evaluating the input line silently.
2767 2771
2768 2772 This is a potentially very nasty bug, if the input has side
2769 2773 effects which must not be repeated. The code is much cleaner now,
2770 2774 without any blanket 'except' left and with a regexp test for
2771 2775 actual function names.
2772 2776
2773 2777 But an eval remains, which I'm not fully comfortable with. I just
2774 2778 don't know how to find out if an expression could be a callable in
2775 2779 the user's namespace without doing an eval on the string. However
2776 2780 that string is now much more strictly checked so that no code
2777 2781 slips by, so the eval should only happen for things that can
2778 2782 really be only function/method names.
2779 2783
2780 2784 2002-10-15 Fernando Perez <fperez@colorado.edu>
2781 2785
2782 2786 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2783 2787 OSX information to main manual, removed README_Mac_OSX file from
2784 2788 distribution. Also updated credits for recent additions.
2785 2789
2786 2790 2002-10-10 Fernando Perez <fperez@colorado.edu>
2787 2791
2788 2792 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2789 2793 terminal-related issues. Many thanks to Andrea Riciputi
2790 2794 <andrea.riciputi-AT-libero.it> for writing it.
2791 2795
2792 2796 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2793 2797 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2794 2798
2795 2799 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2796 2800 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2797 2801 <syver-en-AT-online.no> who both submitted patches for this problem.
2798 2802
2799 2803 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2800 2804 global embedding to make sure that things don't overwrite user
2801 2805 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2802 2806
2803 2807 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2804 2808 compatibility. Thanks to Hayden Callow
2805 2809 <h.callow-AT-elec.canterbury.ac.nz>
2806 2810
2807 2811 2002-10-04 Fernando Perez <fperez@colorado.edu>
2808 2812
2809 2813 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2810 2814 Gnuplot.File objects.
2811 2815
2812 2816 2002-07-23 Fernando Perez <fperez@colorado.edu>
2813 2817
2814 2818 * IPython/genutils.py (timing): Added timings() and timing() for
2815 2819 quick access to the most commonly needed data, the execution
2816 2820 times. Old timing() renamed to timings_out().
2817 2821
2818 2822 2002-07-18 Fernando Perez <fperez@colorado.edu>
2819 2823
2820 2824 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2821 2825 bug with nested instances disrupting the parent's tab completion.
2822 2826
2823 2827 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2824 2828 all_completions code to begin the emacs integration.
2825 2829
2826 2830 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2827 2831 argument to allow titling individual arrays when plotting.
2828 2832
2829 2833 2002-07-15 Fernando Perez <fperez@colorado.edu>
2830 2834
2831 2835 * setup.py (make_shortcut): changed to retrieve the value of
2832 2836 'Program Files' directory from the registry (this value changes in
2833 2837 non-english versions of Windows). Thanks to Thomas Fanslau
2834 2838 <tfanslau-AT-gmx.de> for the report.
2835 2839
2836 2840 2002-07-10 Fernando Perez <fperez@colorado.edu>
2837 2841
2838 2842 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2839 2843 a bug in pdb, which crashes if a line with only whitespace is
2840 2844 entered. Bug report submitted to sourceforge.
2841 2845
2842 2846 2002-07-09 Fernando Perez <fperez@colorado.edu>
2843 2847
2844 2848 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2845 2849 reporting exceptions (it's a bug in inspect.py, I just set a
2846 2850 workaround).
2847 2851
2848 2852 2002-07-08 Fernando Perez <fperez@colorado.edu>
2849 2853
2850 2854 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2851 2855 __IPYTHON__ in __builtins__ to show up in user_ns.
2852 2856
2853 2857 2002-07-03 Fernando Perez <fperez@colorado.edu>
2854 2858
2855 2859 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2856 2860 name from @gp_set_instance to @gp_set_default.
2857 2861
2858 2862 * IPython/ipmaker.py (make_IPython): default editor value set to
2859 2863 '0' (a string), to match the rc file. Otherwise will crash when
2860 2864 .strip() is called on it.
2861 2865
2862 2866
2863 2867 2002-06-28 Fernando Perez <fperez@colorado.edu>
2864 2868
2865 2869 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2866 2870 of files in current directory when a file is executed via
2867 2871 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2868 2872
2869 2873 * setup.py (manfiles): fix for rpm builds, submitted by RA
2870 2874 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2871 2875
2872 2876 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2873 2877 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2874 2878 string!). A. Schmolck caught this one.
2875 2879
2876 2880 2002-06-27 Fernando Perez <fperez@colorado.edu>
2877 2881
2878 2882 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2879 2883 defined files at the cmd line. __name__ wasn't being set to
2880 2884 __main__.
2881 2885
2882 2886 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2883 2887 regular lists and tuples besides Numeric arrays.
2884 2888
2885 2889 * IPython/Prompts.py (CachedOutput.__call__): Added output
2886 2890 supression for input ending with ';'. Similar to Mathematica and
2887 2891 Matlab. The _* vars and Out[] list are still updated, just like
2888 2892 Mathematica behaves.
2889 2893
2890 2894 2002-06-25 Fernando Perez <fperez@colorado.edu>
2891 2895
2892 2896 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2893 2897 .ini extensions for profiels under Windows.
2894 2898
2895 2899 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2896 2900 string form. Fix contributed by Alexander Schmolck
2897 2901 <a.schmolck-AT-gmx.net>
2898 2902
2899 2903 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2900 2904 pre-configured Gnuplot instance.
2901 2905
2902 2906 2002-06-21 Fernando Perez <fperez@colorado.edu>
2903 2907
2904 2908 * IPython/numutils.py (exp_safe): new function, works around the
2905 2909 underflow problems in Numeric.
2906 2910 (log2): New fn. Safe log in base 2: returns exact integer answer
2907 2911 for exact integer powers of 2.
2908 2912
2909 2913 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
2910 2914 properly.
2911 2915
2912 2916 2002-06-20 Fernando Perez <fperez@colorado.edu>
2913 2917
2914 2918 * IPython/genutils.py (timing): new function like
2915 2919 Mathematica's. Similar to time_test, but returns more info.
2916 2920
2917 2921 2002-06-18 Fernando Perez <fperez@colorado.edu>
2918 2922
2919 2923 * IPython/Magic.py (Magic.magic_save): modified @save and @r
2920 2924 according to Mike Heeter's suggestions.
2921 2925
2922 2926 2002-06-16 Fernando Perez <fperez@colorado.edu>
2923 2927
2924 2928 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
2925 2929 system. GnuplotMagic is gone as a user-directory option. New files
2926 2930 make it easier to use all the gnuplot stuff both from external
2927 2931 programs as well as from IPython. Had to rewrite part of
2928 2932 hardcopy() b/c of a strange bug: often the ps files simply don't
2929 2933 get created, and require a repeat of the command (often several
2930 2934 times).
2931 2935
2932 2936 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
2933 2937 resolve output channel at call time, so that if sys.stderr has
2934 2938 been redirected by user this gets honored.
2935 2939
2936 2940 2002-06-13 Fernando Perez <fperez@colorado.edu>
2937 2941
2938 2942 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
2939 2943 IPShell. Kept a copy with the old names to avoid breaking people's
2940 2944 embedded code.
2941 2945
2942 2946 * IPython/ipython: simplified it to the bare minimum after
2943 2947 Holger's suggestions. Added info about how to use it in
2944 2948 PYTHONSTARTUP.
2945 2949
2946 2950 * IPython/Shell.py (IPythonShell): changed the options passing
2947 2951 from a string with funky %s replacements to a straight list. Maybe
2948 2952 a bit more typing, but it follows sys.argv conventions, so there's
2949 2953 less special-casing to remember.
2950 2954
2951 2955 2002-06-12 Fernando Perez <fperez@colorado.edu>
2952 2956
2953 2957 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
2954 2958 command. Thanks to a suggestion by Mike Heeter.
2955 2959 (Magic.magic_pfile): added behavior to look at filenames if given
2956 2960 arg is not a defined object.
2957 2961 (Magic.magic_save): New @save function to save code snippets. Also
2958 2962 a Mike Heeter idea.
2959 2963
2960 2964 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
2961 2965 plot() and replot(). Much more convenient now, especially for
2962 2966 interactive use.
2963 2967
2964 2968 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
2965 2969 filenames.
2966 2970
2967 2971 2002-06-02 Fernando Perez <fperez@colorado.edu>
2968 2972
2969 2973 * IPython/Struct.py (Struct.__init__): modified to admit
2970 2974 initialization via another struct.
2971 2975
2972 2976 * IPython/genutils.py (SystemExec.__init__): New stateful
2973 2977 interface to xsys and bq. Useful for writing system scripts.
2974 2978
2975 2979 2002-05-30 Fernando Perez <fperez@colorado.edu>
2976 2980
2977 2981 * MANIFEST.in: Changed docfile selection to exclude all the lyx
2978 2982 documents. This will make the user download smaller (it's getting
2979 2983 too big).
2980 2984
2981 2985 2002-05-29 Fernando Perez <fperez@colorado.edu>
2982 2986
2983 2987 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
2984 2988 fix problems with shelve and pickle. Seems to work, but I don't
2985 2989 know if corner cases break it. Thanks to Mike Heeter
2986 2990 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
2987 2991
2988 2992 2002-05-24 Fernando Perez <fperez@colorado.edu>
2989 2993
2990 2994 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
2991 2995 macros having broken.
2992 2996
2993 2997 2002-05-21 Fernando Perez <fperez@colorado.edu>
2994 2998
2995 2999 * IPython/Magic.py (Magic.magic_logstart): fixed recently
2996 3000 introduced logging bug: all history before logging started was
2997 3001 being written one character per line! This came from the redesign
2998 3002 of the input history as a special list which slices to strings,
2999 3003 not to lists.
3000 3004
3001 3005 2002-05-20 Fernando Perez <fperez@colorado.edu>
3002 3006
3003 3007 * IPython/Prompts.py (CachedOutput.__init__): made the color table
3004 3008 be an attribute of all classes in this module. The design of these
3005 3009 classes needs some serious overhauling.
3006 3010
3007 3011 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
3008 3012 which was ignoring '_' in option names.
3009 3013
3010 3014 * IPython/ultraTB.py (FormattedTB.__init__): Changed
3011 3015 'Verbose_novars' to 'Context' and made it the new default. It's a
3012 3016 bit more readable and also safer than verbose.
3013 3017
3014 3018 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
3015 3019 triple-quoted strings.
3016 3020
3017 3021 * IPython/OInspect.py (__all__): new module exposing the object
3018 3022 introspection facilities. Now the corresponding magics are dummy
3019 3023 wrappers around this. Having this module will make it much easier
3020 3024 to put these functions into our modified pdb.
3021 3025 This new object inspector system uses the new colorizing module,
3022 3026 so source code and other things are nicely syntax highlighted.
3023 3027
3024 3028 2002-05-18 Fernando Perez <fperez@colorado.edu>
3025 3029
3026 3030 * IPython/ColorANSI.py: Split the coloring tools into a separate
3027 3031 module so I can use them in other code easier (they were part of
3028 3032 ultraTB).
3029 3033
3030 3034 2002-05-17 Fernando Perez <fperez@colorado.edu>
3031 3035
3032 3036 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3033 3037 fixed it to set the global 'g' also to the called instance, as
3034 3038 long as 'g' was still a gnuplot instance (so it doesn't overwrite
3035 3039 user's 'g' variables).
3036 3040
3037 3041 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
3038 3042 global variables (aliases to _ih,_oh) so that users which expect
3039 3043 In[5] or Out[7] to work aren't unpleasantly surprised.
3040 3044 (InputList.__getslice__): new class to allow executing slices of
3041 3045 input history directly. Very simple class, complements the use of
3042 3046 macros.
3043 3047
3044 3048 2002-05-16 Fernando Perez <fperez@colorado.edu>
3045 3049
3046 3050 * setup.py (docdirbase): make doc directory be just doc/IPython
3047 3051 without version numbers, it will reduce clutter for users.
3048 3052
3049 3053 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
3050 3054 execfile call to prevent possible memory leak. See for details:
3051 3055 http://mail.python.org/pipermail/python-list/2002-February/088476.html
3052 3056
3053 3057 2002-05-15 Fernando Perez <fperez@colorado.edu>
3054 3058
3055 3059 * IPython/Magic.py (Magic.magic_psource): made the object
3056 3060 introspection names be more standard: pdoc, pdef, pfile and
3057 3061 psource. They all print/page their output, and it makes
3058 3062 remembering them easier. Kept old names for compatibility as
3059 3063 aliases.
3060 3064
3061 3065 2002-05-14 Fernando Perez <fperez@colorado.edu>
3062 3066
3063 3067 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
3064 3068 what the mouse problem was. The trick is to use gnuplot with temp
3065 3069 files and NOT with pipes (for data communication), because having
3066 3070 both pipes and the mouse on is bad news.
3067 3071
3068 3072 2002-05-13 Fernando Perez <fperez@colorado.edu>
3069 3073
3070 3074 * IPython/Magic.py (Magic._ofind): fixed namespace order search
3071 3075 bug. Information would be reported about builtins even when
3072 3076 user-defined functions overrode them.
3073 3077
3074 3078 2002-05-11 Fernando Perez <fperez@colorado.edu>
3075 3079
3076 3080 * IPython/__init__.py (__all__): removed FlexCompleter from
3077 3081 __all__ so that things don't fail in platforms without readline.
3078 3082
3079 3083 2002-05-10 Fernando Perez <fperez@colorado.edu>
3080 3084
3081 3085 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
3082 3086 it requires Numeric, effectively making Numeric a dependency for
3083 3087 IPython.
3084 3088
3085 3089 * Released 0.2.13
3086 3090
3087 3091 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
3088 3092 profiler interface. Now all the major options from the profiler
3089 3093 module are directly supported in IPython, both for single
3090 3094 expressions (@prun) and for full programs (@run -p).
3091 3095
3092 3096 2002-05-09 Fernando Perez <fperez@colorado.edu>
3093 3097
3094 3098 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
3095 3099 magic properly formatted for screen.
3096 3100
3097 3101 * setup.py (make_shortcut): Changed things to put pdf version in
3098 3102 doc/ instead of doc/manual (had to change lyxport a bit).
3099 3103
3100 3104 * IPython/Magic.py (Profile.string_stats): made profile runs go
3101 3105 through pager (they are long and a pager allows searching, saving,
3102 3106 etc.)
3103 3107
3104 3108 2002-05-08 Fernando Perez <fperez@colorado.edu>
3105 3109
3106 3110 * Released 0.2.12
3107 3111
3108 3112 2002-05-06 Fernando Perez <fperez@colorado.edu>
3109 3113
3110 3114 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
3111 3115 introduced); 'hist n1 n2' was broken.
3112 3116 (Magic.magic_pdb): added optional on/off arguments to @pdb
3113 3117 (Magic.magic_run): added option -i to @run, which executes code in
3114 3118 the IPython namespace instead of a clean one. Also added @irun as
3115 3119 an alias to @run -i.
3116 3120
3117 3121 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3118 3122 fixed (it didn't really do anything, the namespaces were wrong).
3119 3123
3120 3124 * IPython/Debugger.py (__init__): Added workaround for python 2.1
3121 3125
3122 3126 * IPython/__init__.py (__all__): Fixed package namespace, now
3123 3127 'import IPython' does give access to IPython.<all> as
3124 3128 expected. Also renamed __release__ to Release.
3125 3129
3126 3130 * IPython/Debugger.py (__license__): created new Pdb class which
3127 3131 functions like a drop-in for the normal pdb.Pdb but does NOT
3128 3132 import readline by default. This way it doesn't muck up IPython's
3129 3133 readline handling, and now tab-completion finally works in the
3130 3134 debugger -- sort of. It completes things globally visible, but the
3131 3135 completer doesn't track the stack as pdb walks it. That's a bit
3132 3136 tricky, and I'll have to implement it later.
3133 3137
3134 3138 2002-05-05 Fernando Perez <fperez@colorado.edu>
3135 3139
3136 3140 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
3137 3141 magic docstrings when printed via ? (explicit \'s were being
3138 3142 printed).
3139 3143
3140 3144 * IPython/ipmaker.py (make_IPython): fixed namespace
3141 3145 identification bug. Now variables loaded via logs or command-line
3142 3146 files are recognized in the interactive namespace by @who.
3143 3147
3144 3148 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
3145 3149 log replay system stemming from the string form of Structs.
3146 3150
3147 3151 * IPython/Magic.py (Macro.__init__): improved macros to properly
3148 3152 handle magic commands in them.
3149 3153 (Magic.magic_logstart): usernames are now expanded so 'logstart
3150 3154 ~/mylog' now works.
3151 3155
3152 3156 * IPython/iplib.py (complete): fixed bug where paths starting with
3153 3157 '/' would be completed as magic names.
3154 3158
3155 3159 2002-05-04 Fernando Perez <fperez@colorado.edu>
3156 3160
3157 3161 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
3158 3162 allow running full programs under the profiler's control.
3159 3163
3160 3164 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
3161 3165 mode to report exceptions verbosely but without formatting
3162 3166 variables. This addresses the issue of ipython 'freezing' (it's
3163 3167 not frozen, but caught in an expensive formatting loop) when huge
3164 3168 variables are in the context of an exception.
3165 3169 (VerboseTB.text): Added '--->' markers at line where exception was
3166 3170 triggered. Much clearer to read, especially in NoColor modes.
3167 3171
3168 3172 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
3169 3173 implemented in reverse when changing to the new parse_options().
3170 3174
3171 3175 2002-05-03 Fernando Perez <fperez@colorado.edu>
3172 3176
3173 3177 * IPython/Magic.py (Magic.parse_options): new function so that
3174 3178 magics can parse options easier.
3175 3179 (Magic.magic_prun): new function similar to profile.run(),
3176 3180 suggested by Chris Hart.
3177 3181 (Magic.magic_cd): fixed behavior so that it only changes if
3178 3182 directory actually is in history.
3179 3183
3180 3184 * IPython/usage.py (__doc__): added information about potential
3181 3185 slowness of Verbose exception mode when there are huge data
3182 3186 structures to be formatted (thanks to Archie Paulson).
3183 3187
3184 3188 * IPython/ipmaker.py (make_IPython): Changed default logging
3185 3189 (when simply called with -log) to use curr_dir/ipython.log in
3186 3190 rotate mode. Fixed crash which was occuring with -log before
3187 3191 (thanks to Jim Boyle).
3188 3192
3189 3193 2002-05-01 Fernando Perez <fperez@colorado.edu>
3190 3194
3191 3195 * Released 0.2.11 for these fixes (mainly the ultraTB one which
3192 3196 was nasty -- though somewhat of a corner case).
3193 3197
3194 3198 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
3195 3199 text (was a bug).
3196 3200
3197 3201 2002-04-30 Fernando Perez <fperez@colorado.edu>
3198 3202
3199 3203 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
3200 3204 a print after ^D or ^C from the user so that the In[] prompt
3201 3205 doesn't over-run the gnuplot one.
3202 3206
3203 3207 2002-04-29 Fernando Perez <fperez@colorado.edu>
3204 3208
3205 3209 * Released 0.2.10
3206 3210
3207 3211 * IPython/__release__.py (version): get date dynamically.
3208 3212
3209 3213 * Misc. documentation updates thanks to Arnd's comments. Also ran
3210 3214 a full spellcheck on the manual (hadn't been done in a while).
3211 3215
3212 3216 2002-04-27 Fernando Perez <fperez@colorado.edu>
3213 3217
3214 3218 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
3215 3219 starting a log in mid-session would reset the input history list.
3216 3220
3217 3221 2002-04-26 Fernando Perez <fperez@colorado.edu>
3218 3222
3219 3223 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
3220 3224 all files were being included in an update. Now anything in
3221 3225 UserConfig that matches [A-Za-z]*.py will go (this excludes
3222 3226 __init__.py)
3223 3227
3224 3228 2002-04-25 Fernando Perez <fperez@colorado.edu>
3225 3229
3226 3230 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
3227 3231 to __builtins__ so that any form of embedded or imported code can
3228 3232 test for being inside IPython.
3229 3233
3230 3234 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3231 3235 changed to GnuplotMagic because it's now an importable module,
3232 3236 this makes the name follow that of the standard Gnuplot module.
3233 3237 GnuplotMagic can now be loaded at any time in mid-session.
3234 3238
3235 3239 2002-04-24 Fernando Perez <fperez@colorado.edu>
3236 3240
3237 3241 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3238 3242 the globals (IPython has its own namespace) and the
3239 3243 PhysicalQuantity stuff is much better anyway.
3240 3244
3241 3245 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3242 3246 embedding example to standard user directory for
3243 3247 distribution. Also put it in the manual.
3244 3248
3245 3249 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3246 3250 instance as first argument (so it doesn't rely on some obscure
3247 3251 hidden global).
3248 3252
3249 3253 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3250 3254 delimiters. While it prevents ().TAB from working, it allows
3251 3255 completions in open (... expressions. This is by far a more common
3252 3256 case.
3253 3257
3254 3258 2002-04-23 Fernando Perez <fperez@colorado.edu>
3255 3259
3256 3260 * IPython/Extensions/InterpreterPasteInput.py: new
3257 3261 syntax-processing module for pasting lines with >>> or ... at the
3258 3262 start.
3259 3263
3260 3264 * IPython/Extensions/PhysicalQ_Interactive.py
3261 3265 (PhysicalQuantityInteractive.__int__): fixed to work with either
3262 3266 Numeric or math.
3263 3267
3264 3268 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3265 3269 provided profiles. Now we have:
3266 3270 -math -> math module as * and cmath with its own namespace.
3267 3271 -numeric -> Numeric as *, plus gnuplot & grace
3268 3272 -physics -> same as before
3269 3273
3270 3274 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3271 3275 user-defined magics wouldn't be found by @magic if they were
3272 3276 defined as class methods. Also cleaned up the namespace search
3273 3277 logic and the string building (to use %s instead of many repeated
3274 3278 string adds).
3275 3279
3276 3280 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3277 3281 of user-defined magics to operate with class methods (cleaner, in
3278 3282 line with the gnuplot code).
3279 3283
3280 3284 2002-04-22 Fernando Perez <fperez@colorado.edu>
3281 3285
3282 3286 * setup.py: updated dependency list so that manual is updated when
3283 3287 all included files change.
3284 3288
3285 3289 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3286 3290 the delimiter removal option (the fix is ugly right now).
3287 3291
3288 3292 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3289 3293 all of the math profile (quicker loading, no conflict between
3290 3294 g-9.8 and g-gnuplot).
3291 3295
3292 3296 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3293 3297 name of post-mortem files to IPython_crash_report.txt.
3294 3298
3295 3299 * Cleanup/update of the docs. Added all the new readline info and
3296 3300 formatted all lists as 'real lists'.
3297 3301
3298 3302 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3299 3303 tab-completion options, since the full readline parse_and_bind is
3300 3304 now accessible.
3301 3305
3302 3306 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3303 3307 handling of readline options. Now users can specify any string to
3304 3308 be passed to parse_and_bind(), as well as the delimiters to be
3305 3309 removed.
3306 3310 (InteractiveShell.__init__): Added __name__ to the global
3307 3311 namespace so that things like Itpl which rely on its existence
3308 3312 don't crash.
3309 3313 (InteractiveShell._prefilter): Defined the default with a _ so
3310 3314 that prefilter() is easier to override, while the default one
3311 3315 remains available.
3312 3316
3313 3317 2002-04-18 Fernando Perez <fperez@colorado.edu>
3314 3318
3315 3319 * Added information about pdb in the docs.
3316 3320
3317 3321 2002-04-17 Fernando Perez <fperez@colorado.edu>
3318 3322
3319 3323 * IPython/ipmaker.py (make_IPython): added rc_override option to
3320 3324 allow passing config options at creation time which may override
3321 3325 anything set in the config files or command line. This is
3322 3326 particularly useful for configuring embedded instances.
3323 3327
3324 3328 2002-04-15 Fernando Perez <fperez@colorado.edu>
3325 3329
3326 3330 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3327 3331 crash embedded instances because of the input cache falling out of
3328 3332 sync with the output counter.
3329 3333
3330 3334 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3331 3335 mode which calls pdb after an uncaught exception in IPython itself.
3332 3336
3333 3337 2002-04-14 Fernando Perez <fperez@colorado.edu>
3334 3338
3335 3339 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3336 3340 readline, fix it back after each call.
3337 3341
3338 3342 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3339 3343 method to force all access via __call__(), which guarantees that
3340 3344 traceback references are properly deleted.
3341 3345
3342 3346 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3343 3347 improve printing when pprint is in use.
3344 3348
3345 3349 2002-04-13 Fernando Perez <fperez@colorado.edu>
3346 3350
3347 3351 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3348 3352 exceptions aren't caught anymore. If the user triggers one, he
3349 3353 should know why he's doing it and it should go all the way up,
3350 3354 just like any other exception. So now @abort will fully kill the
3351 3355 embedded interpreter and the embedding code (unless that happens
3352 3356 to catch SystemExit).
3353 3357
3354 3358 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3355 3359 and a debugger() method to invoke the interactive pdb debugger
3356 3360 after printing exception information. Also added the corresponding
3357 3361 -pdb option and @pdb magic to control this feature, and updated
3358 3362 the docs. After a suggestion from Christopher Hart
3359 3363 (hart-AT-caltech.edu).
3360 3364
3361 3365 2002-04-12 Fernando Perez <fperez@colorado.edu>
3362 3366
3363 3367 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3364 3368 the exception handlers defined by the user (not the CrashHandler)
3365 3369 so that user exceptions don't trigger an ipython bug report.
3366 3370
3367 3371 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3368 3372 configurable (it should have always been so).
3369 3373
3370 3374 2002-03-26 Fernando Perez <fperez@colorado.edu>
3371 3375
3372 3376 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3373 3377 and there to fix embedding namespace issues. This should all be
3374 3378 done in a more elegant way.
3375 3379
3376 3380 2002-03-25 Fernando Perez <fperez@colorado.edu>
3377 3381
3378 3382 * IPython/genutils.py (get_home_dir): Try to make it work under
3379 3383 win9x also.
3380 3384
3381 3385 2002-03-20 Fernando Perez <fperez@colorado.edu>
3382 3386
3383 3387 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3384 3388 sys.displayhook untouched upon __init__.
3385 3389
3386 3390 2002-03-19 Fernando Perez <fperez@colorado.edu>
3387 3391
3388 3392 * Released 0.2.9 (for embedding bug, basically).
3389 3393
3390 3394 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3391 3395 exceptions so that enclosing shell's state can be restored.
3392 3396
3393 3397 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3394 3398 naming conventions in the .ipython/ dir.
3395 3399
3396 3400 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3397 3401 from delimiters list so filenames with - in them get expanded.
3398 3402
3399 3403 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3400 3404 sys.displayhook not being properly restored after an embedded call.
3401 3405
3402 3406 2002-03-18 Fernando Perez <fperez@colorado.edu>
3403 3407
3404 3408 * Released 0.2.8
3405 3409
3406 3410 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3407 3411 some files weren't being included in a -upgrade.
3408 3412 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3409 3413 on' so that the first tab completes.
3410 3414 (InteractiveShell.handle_magic): fixed bug with spaces around
3411 3415 quotes breaking many magic commands.
3412 3416
3413 3417 * setup.py: added note about ignoring the syntax error messages at
3414 3418 installation.
3415 3419
3416 3420 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3417 3421 streamlining the gnuplot interface, now there's only one magic @gp.
3418 3422
3419 3423 2002-03-17 Fernando Perez <fperez@colorado.edu>
3420 3424
3421 3425 * IPython/UserConfig/magic_gnuplot.py: new name for the
3422 3426 example-magic_pm.py file. Much enhanced system, now with a shell
3423 3427 for communicating directly with gnuplot, one command at a time.
3424 3428
3425 3429 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3426 3430 setting __name__=='__main__'.
3427 3431
3428 3432 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3429 3433 mini-shell for accessing gnuplot from inside ipython. Should
3430 3434 extend it later for grace access too. Inspired by Arnd's
3431 3435 suggestion.
3432 3436
3433 3437 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3434 3438 calling magic functions with () in their arguments. Thanks to Arnd
3435 3439 Baecker for pointing this to me.
3436 3440
3437 3441 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3438 3442 infinitely for integer or complex arrays (only worked with floats).
3439 3443
3440 3444 2002-03-16 Fernando Perez <fperez@colorado.edu>
3441 3445
3442 3446 * setup.py: Merged setup and setup_windows into a single script
3443 3447 which properly handles things for windows users.
3444 3448
3445 3449 2002-03-15 Fernando Perez <fperez@colorado.edu>
3446 3450
3447 3451 * Big change to the manual: now the magics are all automatically
3448 3452 documented. This information is generated from their docstrings
3449 3453 and put in a latex file included by the manual lyx file. This way
3450 3454 we get always up to date information for the magics. The manual
3451 3455 now also has proper version information, also auto-synced.
3452 3456
3453 3457 For this to work, an undocumented --magic_docstrings option was added.
3454 3458
3455 3459 2002-03-13 Fernando Perez <fperez@colorado.edu>
3456 3460
3457 3461 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3458 3462 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3459 3463
3460 3464 2002-03-12 Fernando Perez <fperez@colorado.edu>
3461 3465
3462 3466 * IPython/ultraTB.py (TermColors): changed color escapes again to
3463 3467 fix the (old, reintroduced) line-wrapping bug. Basically, if
3464 3468 \001..\002 aren't given in the color escapes, lines get wrapped
3465 3469 weirdly. But giving those screws up old xterms and emacs terms. So
3466 3470 I added some logic for emacs terms to be ok, but I can't identify old
3467 3471 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3468 3472
3469 3473 2002-03-10 Fernando Perez <fperez@colorado.edu>
3470 3474
3471 3475 * IPython/usage.py (__doc__): Various documentation cleanups and
3472 3476 updates, both in usage docstrings and in the manual.
3473 3477
3474 3478 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3475 3479 handling of caching. Set minimum acceptabe value for having a
3476 3480 cache at 20 values.
3477 3481
3478 3482 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3479 3483 install_first_time function to a method, renamed it and added an
3480 3484 'upgrade' mode. Now people can update their config directory with
3481 3485 a simple command line switch (-upgrade, also new).
3482 3486
3483 3487 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3484 3488 @file (convenient for automagic users under Python >= 2.2).
3485 3489 Removed @files (it seemed more like a plural than an abbrev. of
3486 3490 'file show').
3487 3491
3488 3492 * IPython/iplib.py (install_first_time): Fixed crash if there were
3489 3493 backup files ('~') in .ipython/ install directory.
3490 3494
3491 3495 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3492 3496 system. Things look fine, but these changes are fairly
3493 3497 intrusive. Test them for a few days.
3494 3498
3495 3499 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3496 3500 the prompts system. Now all in/out prompt strings are user
3497 3501 controllable. This is particularly useful for embedding, as one
3498 3502 can tag embedded instances with particular prompts.
3499 3503
3500 3504 Also removed global use of sys.ps1/2, which now allows nested
3501 3505 embeddings without any problems. Added command-line options for
3502 3506 the prompt strings.
3503 3507
3504 3508 2002-03-08 Fernando Perez <fperez@colorado.edu>
3505 3509
3506 3510 * IPython/UserConfig/example-embed-short.py (ipshell): added
3507 3511 example file with the bare minimum code for embedding.
3508 3512
3509 3513 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3510 3514 functionality for the embeddable shell to be activated/deactivated
3511 3515 either globally or at each call.
3512 3516
3513 3517 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3514 3518 rewriting the prompt with '--->' for auto-inputs with proper
3515 3519 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3516 3520 this is handled by the prompts class itself, as it should.
3517 3521
3518 3522 2002-03-05 Fernando Perez <fperez@colorado.edu>
3519 3523
3520 3524 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3521 3525 @logstart to avoid name clashes with the math log function.
3522 3526
3523 3527 * Big updates to X/Emacs section of the manual.
3524 3528
3525 3529 * Removed ipython_emacs. Milan explained to me how to pass
3526 3530 arguments to ipython through Emacs. Some day I'm going to end up
3527 3531 learning some lisp...
3528 3532
3529 3533 2002-03-04 Fernando Perez <fperez@colorado.edu>
3530 3534
3531 3535 * IPython/ipython_emacs: Created script to be used as the
3532 3536 py-python-command Emacs variable so we can pass IPython
3533 3537 parameters. I can't figure out how to tell Emacs directly to pass
3534 3538 parameters to IPython, so a dummy shell script will do it.
3535 3539
3536 3540 Other enhancements made for things to work better under Emacs'
3537 3541 various types of terminals. Many thanks to Milan Zamazal
3538 3542 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3539 3543
3540 3544 2002-03-01 Fernando Perez <fperez@colorado.edu>
3541 3545
3542 3546 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3543 3547 that loading of readline is now optional. This gives better
3544 3548 control to emacs users.
3545 3549
3546 3550 * IPython/ultraTB.py (__date__): Modified color escape sequences
3547 3551 and now things work fine under xterm and in Emacs' term buffers
3548 3552 (though not shell ones). Well, in emacs you get colors, but all
3549 3553 seem to be 'light' colors (no difference between dark and light
3550 3554 ones). But the garbage chars are gone, and also in xterms. It
3551 3555 seems that now I'm using 'cleaner' ansi sequences.
3552 3556
3553 3557 2002-02-21 Fernando Perez <fperez@colorado.edu>
3554 3558
3555 3559 * Released 0.2.7 (mainly to publish the scoping fix).
3556 3560
3557 3561 * IPython/Logger.py (Logger.logstate): added. A corresponding
3558 3562 @logstate magic was created.
3559 3563
3560 3564 * IPython/Magic.py: fixed nested scoping problem under Python
3561 3565 2.1.x (automagic wasn't working).
3562 3566
3563 3567 2002-02-20 Fernando Perez <fperez@colorado.edu>
3564 3568
3565 3569 * Released 0.2.6.
3566 3570
3567 3571 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3568 3572 option so that logs can come out without any headers at all.
3569 3573
3570 3574 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3571 3575 SciPy.
3572 3576
3573 3577 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3574 3578 that embedded IPython calls don't require vars() to be explicitly
3575 3579 passed. Now they are extracted from the caller's frame (code
3576 3580 snatched from Eric Jones' weave). Added better documentation to
3577 3581 the section on embedding and the example file.
3578 3582
3579 3583 * IPython/genutils.py (page): Changed so that under emacs, it just
3580 3584 prints the string. You can then page up and down in the emacs
3581 3585 buffer itself. This is how the builtin help() works.
3582 3586
3583 3587 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3584 3588 macro scoping: macros need to be executed in the user's namespace
3585 3589 to work as if they had been typed by the user.
3586 3590
3587 3591 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3588 3592 execute automatically (no need to type 'exec...'). They then
3589 3593 behave like 'true macros'. The printing system was also modified
3590 3594 for this to work.
3591 3595
3592 3596 2002-02-19 Fernando Perez <fperez@colorado.edu>
3593 3597
3594 3598 * IPython/genutils.py (page_file): new function for paging files
3595 3599 in an OS-independent way. Also necessary for file viewing to work
3596 3600 well inside Emacs buffers.
3597 3601 (page): Added checks for being in an emacs buffer.
3598 3602 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3599 3603 same bug in iplib.
3600 3604
3601 3605 2002-02-18 Fernando Perez <fperez@colorado.edu>
3602 3606
3603 3607 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3604 3608 of readline so that IPython can work inside an Emacs buffer.
3605 3609
3606 3610 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3607 3611 method signatures (they weren't really bugs, but it looks cleaner
3608 3612 and keeps PyChecker happy).
3609 3613
3610 3614 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3611 3615 for implementing various user-defined hooks. Currently only
3612 3616 display is done.
3613 3617
3614 3618 * IPython/Prompts.py (CachedOutput._display): changed display
3615 3619 functions so that they can be dynamically changed by users easily.
3616 3620
3617 3621 * IPython/Extensions/numeric_formats.py (num_display): added an
3618 3622 extension for printing NumPy arrays in flexible manners. It
3619 3623 doesn't do anything yet, but all the structure is in
3620 3624 place. Ultimately the plan is to implement output format control
3621 3625 like in Octave.
3622 3626
3623 3627 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3624 3628 methods are found at run-time by all the automatic machinery.
3625 3629
3626 3630 2002-02-17 Fernando Perez <fperez@colorado.edu>
3627 3631
3628 3632 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3629 3633 whole file a little.
3630 3634
3631 3635 * ToDo: closed this document. Now there's a new_design.lyx
3632 3636 document for all new ideas. Added making a pdf of it for the
3633 3637 end-user distro.
3634 3638
3635 3639 * IPython/Logger.py (Logger.switch_log): Created this to replace
3636 3640 logon() and logoff(). It also fixes a nasty crash reported by
3637 3641 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3638 3642
3639 3643 * IPython/iplib.py (complete): got auto-completion to work with
3640 3644 automagic (I had wanted this for a long time).
3641 3645
3642 3646 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3643 3647 to @file, since file() is now a builtin and clashes with automagic
3644 3648 for @file.
3645 3649
3646 3650 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3647 3651 of this was previously in iplib, which had grown to more than 2000
3648 3652 lines, way too long. No new functionality, but it makes managing
3649 3653 the code a bit easier.
3650 3654
3651 3655 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3652 3656 information to crash reports.
3653 3657
3654 3658 2002-02-12 Fernando Perez <fperez@colorado.edu>
3655 3659
3656 3660 * Released 0.2.5.
3657 3661
3658 3662 2002-02-11 Fernando Perez <fperez@colorado.edu>
3659 3663
3660 3664 * Wrote a relatively complete Windows installer. It puts
3661 3665 everything in place, creates Start Menu entries and fixes the
3662 3666 color issues. Nothing fancy, but it works.
3663 3667
3664 3668 2002-02-10 Fernando Perez <fperez@colorado.edu>
3665 3669
3666 3670 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3667 3671 os.path.expanduser() call so that we can type @run ~/myfile.py and
3668 3672 have thigs work as expected.
3669 3673
3670 3674 * IPython/genutils.py (page): fixed exception handling so things
3671 3675 work both in Unix and Windows correctly. Quitting a pager triggers
3672 3676 an IOError/broken pipe in Unix, and in windows not finding a pager
3673 3677 is also an IOError, so I had to actually look at the return value
3674 3678 of the exception, not just the exception itself. Should be ok now.
3675 3679
3676 3680 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3677 3681 modified to allow case-insensitive color scheme changes.
3678 3682
3679 3683 2002-02-09 Fernando Perez <fperez@colorado.edu>
3680 3684
3681 3685 * IPython/genutils.py (native_line_ends): new function to leave
3682 3686 user config files with os-native line-endings.
3683 3687
3684 3688 * README and manual updates.
3685 3689
3686 3690 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3687 3691 instead of StringType to catch Unicode strings.
3688 3692
3689 3693 * IPython/genutils.py (filefind): fixed bug for paths with
3690 3694 embedded spaces (very common in Windows).
3691 3695
3692 3696 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3693 3697 files under Windows, so that they get automatically associated
3694 3698 with a text editor. Windows makes it a pain to handle
3695 3699 extension-less files.
3696 3700
3697 3701 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3698 3702 warning about readline only occur for Posix. In Windows there's no
3699 3703 way to get readline, so why bother with the warning.
3700 3704
3701 3705 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3702 3706 for __str__ instead of dir(self), since dir() changed in 2.2.
3703 3707
3704 3708 * Ported to Windows! Tested on XP, I suspect it should work fine
3705 3709 on NT/2000, but I don't think it will work on 98 et al. That
3706 3710 series of Windows is such a piece of junk anyway that I won't try
3707 3711 porting it there. The XP port was straightforward, showed a few
3708 3712 bugs here and there (fixed all), in particular some string
3709 3713 handling stuff which required considering Unicode strings (which
3710 3714 Windows uses). This is good, but hasn't been too tested :) No
3711 3715 fancy installer yet, I'll put a note in the manual so people at
3712 3716 least make manually a shortcut.
3713 3717
3714 3718 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3715 3719 into a single one, "colors". This now controls both prompt and
3716 3720 exception color schemes, and can be changed both at startup
3717 3721 (either via command-line switches or via ipythonrc files) and at
3718 3722 runtime, with @colors.
3719 3723 (Magic.magic_run): renamed @prun to @run and removed the old
3720 3724 @run. The two were too similar to warrant keeping both.
3721 3725
3722 3726 2002-02-03 Fernando Perez <fperez@colorado.edu>
3723 3727
3724 3728 * IPython/iplib.py (install_first_time): Added comment on how to
3725 3729 configure the color options for first-time users. Put a <return>
3726 3730 request at the end so that small-terminal users get a chance to
3727 3731 read the startup info.
3728 3732
3729 3733 2002-01-23 Fernando Perez <fperez@colorado.edu>
3730 3734
3731 3735 * IPython/iplib.py (CachedOutput.update): Changed output memory
3732 3736 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3733 3737 input history we still use _i. Did this b/c these variable are
3734 3738 very commonly used in interactive work, so the less we need to
3735 3739 type the better off we are.
3736 3740 (Magic.magic_prun): updated @prun to better handle the namespaces
3737 3741 the file will run in, including a fix for __name__ not being set
3738 3742 before.
3739 3743
3740 3744 2002-01-20 Fernando Perez <fperez@colorado.edu>
3741 3745
3742 3746 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3743 3747 extra garbage for Python 2.2. Need to look more carefully into
3744 3748 this later.
3745 3749
3746 3750 2002-01-19 Fernando Perez <fperez@colorado.edu>
3747 3751
3748 3752 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3749 3753 display SyntaxError exceptions properly formatted when they occur
3750 3754 (they can be triggered by imported code).
3751 3755
3752 3756 2002-01-18 Fernando Perez <fperez@colorado.edu>
3753 3757
3754 3758 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3755 3759 SyntaxError exceptions are reported nicely formatted, instead of
3756 3760 spitting out only offset information as before.
3757 3761 (Magic.magic_prun): Added the @prun function for executing
3758 3762 programs with command line args inside IPython.
3759 3763
3760 3764 2002-01-16 Fernando Perez <fperez@colorado.edu>
3761 3765
3762 3766 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3763 3767 to *not* include the last item given in a range. This brings their
3764 3768 behavior in line with Python's slicing:
3765 3769 a[n1:n2] -> a[n1]...a[n2-1]
3766 3770 It may be a bit less convenient, but I prefer to stick to Python's
3767 3771 conventions *everywhere*, so users never have to wonder.
3768 3772 (Magic.magic_macro): Added @macro function to ease the creation of
3769 3773 macros.
3770 3774
3771 3775 2002-01-05 Fernando Perez <fperez@colorado.edu>
3772 3776
3773 3777 * Released 0.2.4.
3774 3778
3775 3779 * IPython/iplib.py (Magic.magic_pdef):
3776 3780 (InteractiveShell.safe_execfile): report magic lines and error
3777 3781 lines without line numbers so one can easily copy/paste them for
3778 3782 re-execution.
3779 3783
3780 3784 * Updated manual with recent changes.
3781 3785
3782 3786 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3783 3787 docstring printing when class? is called. Very handy for knowing
3784 3788 how to create class instances (as long as __init__ is well
3785 3789 documented, of course :)
3786 3790 (Magic.magic_doc): print both class and constructor docstrings.
3787 3791 (Magic.magic_pdef): give constructor info if passed a class and
3788 3792 __call__ info for callable object instances.
3789 3793
3790 3794 2002-01-04 Fernando Perez <fperez@colorado.edu>
3791 3795
3792 3796 * Made deep_reload() off by default. It doesn't always work
3793 3797 exactly as intended, so it's probably safer to have it off. It's
3794 3798 still available as dreload() anyway, so nothing is lost.
3795 3799
3796 3800 2002-01-02 Fernando Perez <fperez@colorado.edu>
3797 3801
3798 3802 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3799 3803 so I wanted an updated release).
3800 3804
3801 3805 2001-12-27 Fernando Perez <fperez@colorado.edu>
3802 3806
3803 3807 * IPython/iplib.py (InteractiveShell.interact): Added the original
3804 3808 code from 'code.py' for this module in order to change the
3805 3809 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3806 3810 the history cache would break when the user hit Ctrl-C, and
3807 3811 interact() offers no way to add any hooks to it.
3808 3812
3809 3813 2001-12-23 Fernando Perez <fperez@colorado.edu>
3810 3814
3811 3815 * setup.py: added check for 'MANIFEST' before trying to remove
3812 3816 it. Thanks to Sean Reifschneider.
3813 3817
3814 3818 2001-12-22 Fernando Perez <fperez@colorado.edu>
3815 3819
3816 3820 * Released 0.2.2.
3817 3821
3818 3822 * Finished (reasonably) writing the manual. Later will add the
3819 3823 python-standard navigation stylesheets, but for the time being
3820 3824 it's fairly complete. Distribution will include html and pdf
3821 3825 versions.
3822 3826
3823 3827 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3824 3828 (MayaVi author).
3825 3829
3826 3830 2001-12-21 Fernando Perez <fperez@colorado.edu>
3827 3831
3828 3832 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3829 3833 good public release, I think (with the manual and the distutils
3830 3834 installer). The manual can use some work, but that can go
3831 3835 slowly. Otherwise I think it's quite nice for end users. Next
3832 3836 summer, rewrite the guts of it...
3833 3837
3834 3838 * Changed format of ipythonrc files to use whitespace as the
3835 3839 separator instead of an explicit '='. Cleaner.
3836 3840
3837 3841 2001-12-20 Fernando Perez <fperez@colorado.edu>
3838 3842
3839 3843 * Started a manual in LyX. For now it's just a quick merge of the
3840 3844 various internal docstrings and READMEs. Later it may grow into a
3841 3845 nice, full-blown manual.
3842 3846
3843 3847 * Set up a distutils based installer. Installation should now be
3844 3848 trivially simple for end-users.
3845 3849
3846 3850 2001-12-11 Fernando Perez <fperez@colorado.edu>
3847 3851
3848 3852 * Released 0.2.0. First public release, announced it at
3849 3853 comp.lang.python. From now on, just bugfixes...
3850 3854
3851 3855 * Went through all the files, set copyright/license notices and
3852 3856 cleaned up things. Ready for release.
3853 3857
3854 3858 2001-12-10 Fernando Perez <fperez@colorado.edu>
3855 3859
3856 3860 * Changed the first-time installer not to use tarfiles. It's more
3857 3861 robust now and less unix-dependent. Also makes it easier for
3858 3862 people to later upgrade versions.
3859 3863
3860 3864 * Changed @exit to @abort to reflect the fact that it's pretty
3861 3865 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3862 3866 becomes significant only when IPyhton is embedded: in that case,
3863 3867 C-D closes IPython only, but @abort kills the enclosing program
3864 3868 too (unless it had called IPython inside a try catching
3865 3869 SystemExit).
3866 3870
3867 3871 * Created Shell module which exposes the actuall IPython Shell
3868 3872 classes, currently the normal and the embeddable one. This at
3869 3873 least offers a stable interface we won't need to change when
3870 3874 (later) the internals are rewritten. That rewrite will be confined
3871 3875 to iplib and ipmaker, but the Shell interface should remain as is.
3872 3876
3873 3877 * Added embed module which offers an embeddable IPShell object,
3874 3878 useful to fire up IPython *inside* a running program. Great for
3875 3879 debugging or dynamical data analysis.
3876 3880
3877 3881 2001-12-08 Fernando Perez <fperez@colorado.edu>
3878 3882
3879 3883 * Fixed small bug preventing seeing info from methods of defined
3880 3884 objects (incorrect namespace in _ofind()).
3881 3885
3882 3886 * Documentation cleanup. Moved the main usage docstrings to a
3883 3887 separate file, usage.py (cleaner to maintain, and hopefully in the
3884 3888 future some perlpod-like way of producing interactive, man and
3885 3889 html docs out of it will be found).
3886 3890
3887 3891 * Added @profile to see your profile at any time.
3888 3892
3889 3893 * Added @p as an alias for 'print'. It's especially convenient if
3890 3894 using automagic ('p x' prints x).
3891 3895
3892 3896 * Small cleanups and fixes after a pychecker run.
3893 3897
3894 3898 * Changed the @cd command to handle @cd - and @cd -<n> for
3895 3899 visiting any directory in _dh.
3896 3900
3897 3901 * Introduced _dh, a history of visited directories. @dhist prints
3898 3902 it out with numbers.
3899 3903
3900 3904 2001-12-07 Fernando Perez <fperez@colorado.edu>
3901 3905
3902 3906 * Released 0.1.22
3903 3907
3904 3908 * Made initialization a bit more robust against invalid color
3905 3909 options in user input (exit, not traceback-crash).
3906 3910
3907 3911 * Changed the bug crash reporter to write the report only in the
3908 3912 user's .ipython directory. That way IPython won't litter people's
3909 3913 hard disks with crash files all over the place. Also print on
3910 3914 screen the necessary mail command.
3911 3915
3912 3916 * With the new ultraTB, implemented LightBG color scheme for light
3913 3917 background terminals. A lot of people like white backgrounds, so I
3914 3918 guess we should at least give them something readable.
3915 3919
3916 3920 2001-12-06 Fernando Perez <fperez@colorado.edu>
3917 3921
3918 3922 * Modified the structure of ultraTB. Now there's a proper class
3919 3923 for tables of color schemes which allow adding schemes easily and
3920 3924 switching the active scheme without creating a new instance every
3921 3925 time (which was ridiculous). The syntax for creating new schemes
3922 3926 is also cleaner. I think ultraTB is finally done, with a clean
3923 3927 class structure. Names are also much cleaner (now there's proper
3924 3928 color tables, no need for every variable to also have 'color' in
3925 3929 its name).
3926 3930
3927 3931 * Broke down genutils into separate files. Now genutils only
3928 3932 contains utility functions, and classes have been moved to their
3929 3933 own files (they had enough independent functionality to warrant
3930 3934 it): ConfigLoader, OutputTrap, Struct.
3931 3935
3932 3936 2001-12-05 Fernando Perez <fperez@colorado.edu>
3933 3937
3934 3938 * IPython turns 21! Released version 0.1.21, as a candidate for
3935 3939 public consumption. If all goes well, release in a few days.
3936 3940
3937 3941 * Fixed path bug (files in Extensions/ directory wouldn't be found
3938 3942 unless IPython/ was explicitly in sys.path).
3939 3943
3940 3944 * Extended the FlexCompleter class as MagicCompleter to allow
3941 3945 completion of @-starting lines.
3942 3946
3943 3947 * Created __release__.py file as a central repository for release
3944 3948 info that other files can read from.
3945 3949
3946 3950 * Fixed small bug in logging: when logging was turned on in
3947 3951 mid-session, old lines with special meanings (!@?) were being
3948 3952 logged without the prepended comment, which is necessary since
3949 3953 they are not truly valid python syntax. This should make session
3950 3954 restores produce less errors.
3951 3955
3952 3956 * The namespace cleanup forced me to make a FlexCompleter class
3953 3957 which is nothing but a ripoff of rlcompleter, but with selectable
3954 3958 namespace (rlcompleter only works in __main__.__dict__). I'll try
3955 3959 to submit a note to the authors to see if this change can be
3956 3960 incorporated in future rlcompleter releases (Dec.6: done)
3957 3961
3958 3962 * More fixes to namespace handling. It was a mess! Now all
3959 3963 explicit references to __main__.__dict__ are gone (except when
3960 3964 really needed) and everything is handled through the namespace
3961 3965 dicts in the IPython instance. We seem to be getting somewhere
3962 3966 with this, finally...
3963 3967
3964 3968 * Small documentation updates.
3965 3969
3966 3970 * Created the Extensions directory under IPython (with an
3967 3971 __init__.py). Put the PhysicalQ stuff there. This directory should
3968 3972 be used for all special-purpose extensions.
3969 3973
3970 3974 * File renaming:
3971 3975 ipythonlib --> ipmaker
3972 3976 ipplib --> iplib
3973 3977 This makes a bit more sense in terms of what these files actually do.
3974 3978
3975 3979 * Moved all the classes and functions in ipythonlib to ipplib, so
3976 3980 now ipythonlib only has make_IPython(). This will ease up its
3977 3981 splitting in smaller functional chunks later.
3978 3982
3979 3983 * Cleaned up (done, I think) output of @whos. Better column
3980 3984 formatting, and now shows str(var) for as much as it can, which is
3981 3985 typically what one gets with a 'print var'.
3982 3986
3983 3987 2001-12-04 Fernando Perez <fperez@colorado.edu>
3984 3988
3985 3989 * Fixed namespace problems. Now builtin/IPyhton/user names get
3986 3990 properly reported in their namespace. Internal namespace handling
3987 3991 is finally getting decent (not perfect yet, but much better than
3988 3992 the ad-hoc mess we had).
3989 3993
3990 3994 * Removed -exit option. If people just want to run a python
3991 3995 script, that's what the normal interpreter is for. Less
3992 3996 unnecessary options, less chances for bugs.
3993 3997
3994 3998 * Added a crash handler which generates a complete post-mortem if
3995 3999 IPython crashes. This will help a lot in tracking bugs down the
3996 4000 road.
3997 4001
3998 4002 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
3999 4003 which were boud to functions being reassigned would bypass the
4000 4004 logger, breaking the sync of _il with the prompt counter. This
4001 4005 would then crash IPython later when a new line was logged.
4002 4006
4003 4007 2001-12-02 Fernando Perez <fperez@colorado.edu>
4004 4008
4005 4009 * Made IPython a package. This means people don't have to clutter
4006 4010 their sys.path with yet another directory. Changed the INSTALL
4007 4011 file accordingly.
4008 4012
4009 4013 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
4010 4014 sorts its output (so @who shows it sorted) and @whos formats the
4011 4015 table according to the width of the first column. Nicer, easier to
4012 4016 read. Todo: write a generic table_format() which takes a list of
4013 4017 lists and prints it nicely formatted, with optional row/column
4014 4018 separators and proper padding and justification.
4015 4019
4016 4020 * Released 0.1.20
4017 4021
4018 4022 * Fixed bug in @log which would reverse the inputcache list (a
4019 4023 copy operation was missing).
4020 4024
4021 4025 * Code cleanup. @config was changed to use page(). Better, since
4022 4026 its output is always quite long.
4023 4027
4024 4028 * Itpl is back as a dependency. I was having too many problems
4025 4029 getting the parametric aliases to work reliably, and it's just
4026 4030 easier to code weird string operations with it than playing %()s
4027 4031 games. It's only ~6k, so I don't think it's too big a deal.
4028 4032
4029 4033 * Found (and fixed) a very nasty bug with history. !lines weren't
4030 4034 getting cached, and the out of sync caches would crash
4031 4035 IPython. Fixed it by reorganizing the prefilter/handlers/logger
4032 4036 division of labor a bit better. Bug fixed, cleaner structure.
4033 4037
4034 4038 2001-12-01 Fernando Perez <fperez@colorado.edu>
4035 4039
4036 4040 * Released 0.1.19
4037 4041
4038 4042 * Added option -n to @hist to prevent line number printing. Much
4039 4043 easier to copy/paste code this way.
4040 4044
4041 4045 * Created global _il to hold the input list. Allows easy
4042 4046 re-execution of blocks of code by slicing it (inspired by Janko's
4043 4047 comment on 'macros').
4044 4048
4045 4049 * Small fixes and doc updates.
4046 4050
4047 4051 * Rewrote @history function (was @h). Renamed it to @hist, @h is
4048 4052 much too fragile with automagic. Handles properly multi-line
4049 4053 statements and takes parameters.
4050 4054
4051 4055 2001-11-30 Fernando Perez <fperez@colorado.edu>
4052 4056
4053 4057 * Version 0.1.18 released.
4054 4058
4055 4059 * Fixed nasty namespace bug in initial module imports.
4056 4060
4057 4061 * Added copyright/license notes to all code files (except
4058 4062 DPyGetOpt). For the time being, LGPL. That could change.
4059 4063
4060 4064 * Rewrote a much nicer README, updated INSTALL, cleaned up
4061 4065 ipythonrc-* samples.
4062 4066
4063 4067 * Overall code/documentation cleanup. Basically ready for
4064 4068 release. Only remaining thing: licence decision (LGPL?).
4065 4069
4066 4070 * Converted load_config to a class, ConfigLoader. Now recursion
4067 4071 control is better organized. Doesn't include the same file twice.
4068 4072
4069 4073 2001-11-29 Fernando Perez <fperez@colorado.edu>
4070 4074
4071 4075 * Got input history working. Changed output history variables from
4072 4076 _p to _o so that _i is for input and _o for output. Just cleaner
4073 4077 convention.
4074 4078
4075 4079 * Implemented parametric aliases. This pretty much allows the
4076 4080 alias system to offer full-blown shell convenience, I think.
4077 4081
4078 4082 * Version 0.1.17 released, 0.1.18 opened.
4079 4083
4080 4084 * dot_ipython/ipythonrc (alias): added documentation.
4081 4085 (xcolor): Fixed small bug (xcolors -> xcolor)
4082 4086
4083 4087 * Changed the alias system. Now alias is a magic command to define
4084 4088 aliases just like the shell. Rationale: the builtin magics should
4085 4089 be there for things deeply connected to IPython's
4086 4090 architecture. And this is a much lighter system for what I think
4087 4091 is the really important feature: allowing users to define quickly
4088 4092 magics that will do shell things for them, so they can customize
4089 4093 IPython easily to match their work habits. If someone is really
4090 4094 desperate to have another name for a builtin alias, they can
4091 4095 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
4092 4096 works.
4093 4097
4094 4098 2001-11-28 Fernando Perez <fperez@colorado.edu>
4095 4099
4096 4100 * Changed @file so that it opens the source file at the proper
4097 4101 line. Since it uses less, if your EDITOR environment is
4098 4102 configured, typing v will immediately open your editor of choice
4099 4103 right at the line where the object is defined. Not as quick as
4100 4104 having a direct @edit command, but for all intents and purposes it
4101 4105 works. And I don't have to worry about writing @edit to deal with
4102 4106 all the editors, less does that.
4103 4107
4104 4108 * Version 0.1.16 released, 0.1.17 opened.
4105 4109
4106 4110 * Fixed some nasty bugs in the page/page_dumb combo that could
4107 4111 crash IPython.
4108 4112
4109 4113 2001-11-27 Fernando Perez <fperez@colorado.edu>
4110 4114
4111 4115 * Version 0.1.15 released, 0.1.16 opened.
4112 4116
4113 4117 * Finally got ? and ?? to work for undefined things: now it's
4114 4118 possible to type {}.get? and get information about the get method
4115 4119 of dicts, or os.path? even if only os is defined (so technically
4116 4120 os.path isn't). Works at any level. For example, after import os,
4117 4121 os?, os.path?, os.path.abspath? all work. This is great, took some
4118 4122 work in _ofind.
4119 4123
4120 4124 * Fixed more bugs with logging. The sanest way to do it was to add
4121 4125 to @log a 'mode' parameter. Killed two in one shot (this mode
4122 4126 option was a request of Janko's). I think it's finally clean
4123 4127 (famous last words).
4124 4128
4125 4129 * Added a page_dumb() pager which does a decent job of paging on
4126 4130 screen, if better things (like less) aren't available. One less
4127 4131 unix dependency (someday maybe somebody will port this to
4128 4132 windows).
4129 4133
4130 4134 * Fixed problem in magic_log: would lock of logging out if log
4131 4135 creation failed (because it would still think it had succeeded).
4132 4136
4133 4137 * Improved the page() function using curses to auto-detect screen
4134 4138 size. Now it can make a much better decision on whether to print
4135 4139 or page a string. Option screen_length was modified: a value 0
4136 4140 means auto-detect, and that's the default now.
4137 4141
4138 4142 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
4139 4143 go out. I'll test it for a few days, then talk to Janko about
4140 4144 licences and announce it.
4141 4145
4142 4146 * Fixed the length of the auto-generated ---> prompt which appears
4143 4147 for auto-parens and auto-quotes. Getting this right isn't trivial,
4144 4148 with all the color escapes, different prompt types and optional
4145 4149 separators. But it seems to be working in all the combinations.
4146 4150
4147 4151 2001-11-26 Fernando Perez <fperez@colorado.edu>
4148 4152
4149 4153 * Wrote a regexp filter to get option types from the option names
4150 4154 string. This eliminates the need to manually keep two duplicate
4151 4155 lists.
4152 4156
4153 4157 * Removed the unneeded check_option_names. Now options are handled
4154 4158 in a much saner manner and it's easy to visually check that things
4155 4159 are ok.
4156 4160
4157 4161 * Updated version numbers on all files I modified to carry a
4158 4162 notice so Janko and Nathan have clear version markers.
4159 4163
4160 4164 * Updated docstring for ultraTB with my changes. I should send
4161 4165 this to Nathan.
4162 4166
4163 4167 * Lots of small fixes. Ran everything through pychecker again.
4164 4168
4165 4169 * Made loading of deep_reload an cmd line option. If it's not too
4166 4170 kosher, now people can just disable it. With -nodeep_reload it's
4167 4171 still available as dreload(), it just won't overwrite reload().
4168 4172
4169 4173 * Moved many options to the no| form (-opt and -noopt
4170 4174 accepted). Cleaner.
4171 4175
4172 4176 * Changed magic_log so that if called with no parameters, it uses
4173 4177 'rotate' mode. That way auto-generated logs aren't automatically
4174 4178 over-written. For normal logs, now a backup is made if it exists
4175 4179 (only 1 level of backups). A new 'backup' mode was added to the
4176 4180 Logger class to support this. This was a request by Janko.
4177 4181
4178 4182 * Added @logoff/@logon to stop/restart an active log.
4179 4183
4180 4184 * Fixed a lot of bugs in log saving/replay. It was pretty
4181 4185 broken. Now special lines (!@,/) appear properly in the command
4182 4186 history after a log replay.
4183 4187
4184 4188 * Tried and failed to implement full session saving via pickle. My
4185 4189 idea was to pickle __main__.__dict__, but modules can't be
4186 4190 pickled. This would be a better alternative to replaying logs, but
4187 4191 seems quite tricky to get to work. Changed -session to be called
4188 4192 -logplay, which more accurately reflects what it does. And if we
4189 4193 ever get real session saving working, -session is now available.
4190 4194
4191 4195 * Implemented color schemes for prompts also. As for tracebacks,
4192 4196 currently only NoColor and Linux are supported. But now the
4193 4197 infrastructure is in place, based on a generic ColorScheme
4194 4198 class. So writing and activating new schemes both for the prompts
4195 4199 and the tracebacks should be straightforward.
4196 4200
4197 4201 * Version 0.1.13 released, 0.1.14 opened.
4198 4202
4199 4203 * Changed handling of options for output cache. Now counter is
4200 4204 hardwired starting at 1 and one specifies the maximum number of
4201 4205 entries *in the outcache* (not the max prompt counter). This is
4202 4206 much better, since many statements won't increase the cache
4203 4207 count. It also eliminated some confusing options, now there's only
4204 4208 one: cache_size.
4205 4209
4206 4210 * Added 'alias' magic function and magic_alias option in the
4207 4211 ipythonrc file. Now the user can easily define whatever names he
4208 4212 wants for the magic functions without having to play weird
4209 4213 namespace games. This gives IPython a real shell-like feel.
4210 4214
4211 4215 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
4212 4216 @ or not).
4213 4217
4214 4218 This was one of the last remaining 'visible' bugs (that I know
4215 4219 of). I think if I can clean up the session loading so it works
4216 4220 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
4217 4221 about licensing).
4218 4222
4219 4223 2001-11-25 Fernando Perez <fperez@colorado.edu>
4220 4224
4221 4225 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
4222 4226 there's a cleaner distinction between what ? and ?? show.
4223 4227
4224 4228 * Added screen_length option. Now the user can define his own
4225 4229 screen size for page() operations.
4226 4230
4227 4231 * Implemented magic shell-like functions with automatic code
4228 4232 generation. Now adding another function is just a matter of adding
4229 4233 an entry to a dict, and the function is dynamically generated at
4230 4234 run-time. Python has some really cool features!
4231 4235
4232 4236 * Renamed many options to cleanup conventions a little. Now all
4233 4237 are lowercase, and only underscores where needed. Also in the code
4234 4238 option name tables are clearer.
4235 4239
4236 4240 * Changed prompts a little. Now input is 'In [n]:' instead of
4237 4241 'In[n]:='. This allows it the numbers to be aligned with the
4238 4242 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4239 4243 Python (it was a Mathematica thing). The '...' continuation prompt
4240 4244 was also changed a little to align better.
4241 4245
4242 4246 * Fixed bug when flushing output cache. Not all _p<n> variables
4243 4247 exist, so their deletion needs to be wrapped in a try:
4244 4248
4245 4249 * Figured out how to properly use inspect.formatargspec() (it
4246 4250 requires the args preceded by *). So I removed all the code from
4247 4251 _get_pdef in Magic, which was just replicating that.
4248 4252
4249 4253 * Added test to prefilter to allow redefining magic function names
4250 4254 as variables. This is ok, since the @ form is always available,
4251 4255 but whe should allow the user to define a variable called 'ls' if
4252 4256 he needs it.
4253 4257
4254 4258 * Moved the ToDo information from README into a separate ToDo.
4255 4259
4256 4260 * General code cleanup and small bugfixes. I think it's close to a
4257 4261 state where it can be released, obviously with a big 'beta'
4258 4262 warning on it.
4259 4263
4260 4264 * Got the magic function split to work. Now all magics are defined
4261 4265 in a separate class. It just organizes things a bit, and now
4262 4266 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4263 4267 was too long).
4264 4268
4265 4269 * Changed @clear to @reset to avoid potential confusions with
4266 4270 the shell command clear. Also renamed @cl to @clear, which does
4267 4271 exactly what people expect it to from their shell experience.
4268 4272
4269 4273 Added a check to the @reset command (since it's so
4270 4274 destructive, it's probably a good idea to ask for confirmation).
4271 4275 But now reset only works for full namespace resetting. Since the
4272 4276 del keyword is already there for deleting a few specific
4273 4277 variables, I don't see the point of having a redundant magic
4274 4278 function for the same task.
4275 4279
4276 4280 2001-11-24 Fernando Perez <fperez@colorado.edu>
4277 4281
4278 4282 * Updated the builtin docs (esp. the ? ones).
4279 4283
4280 4284 * Ran all the code through pychecker. Not terribly impressed with
4281 4285 it: lots of spurious warnings and didn't really find anything of
4282 4286 substance (just a few modules being imported and not used).
4283 4287
4284 4288 * Implemented the new ultraTB functionality into IPython. New
4285 4289 option: xcolors. This chooses color scheme. xmode now only selects
4286 4290 between Plain and Verbose. Better orthogonality.
4287 4291
4288 4292 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4289 4293 mode and color scheme for the exception handlers. Now it's
4290 4294 possible to have the verbose traceback with no coloring.
4291 4295
4292 4296 2001-11-23 Fernando Perez <fperez@colorado.edu>
4293 4297
4294 4298 * Version 0.1.12 released, 0.1.13 opened.
4295 4299
4296 4300 * Removed option to set auto-quote and auto-paren escapes by
4297 4301 user. The chances of breaking valid syntax are just too high. If
4298 4302 someone *really* wants, they can always dig into the code.
4299 4303
4300 4304 * Made prompt separators configurable.
4301 4305
4302 4306 2001-11-22 Fernando Perez <fperez@colorado.edu>
4303 4307
4304 4308 * Small bugfixes in many places.
4305 4309
4306 4310 * Removed the MyCompleter class from ipplib. It seemed redundant
4307 4311 with the C-p,C-n history search functionality. Less code to
4308 4312 maintain.
4309 4313
4310 4314 * Moved all the original ipython.py code into ipythonlib.py. Right
4311 4315 now it's just one big dump into a function called make_IPython, so
4312 4316 no real modularity has been gained. But at least it makes the
4313 4317 wrapper script tiny, and since ipythonlib is a module, it gets
4314 4318 compiled and startup is much faster.
4315 4319
4316 4320 This is a reasobably 'deep' change, so we should test it for a
4317 4321 while without messing too much more with the code.
4318 4322
4319 4323 2001-11-21 Fernando Perez <fperez@colorado.edu>
4320 4324
4321 4325 * Version 0.1.11 released, 0.1.12 opened for further work.
4322 4326
4323 4327 * Removed dependency on Itpl. It was only needed in one place. It
4324 4328 would be nice if this became part of python, though. It makes life
4325 4329 *a lot* easier in some cases.
4326 4330
4327 4331 * Simplified the prefilter code a bit. Now all handlers are
4328 4332 expected to explicitly return a value (at least a blank string).
4329 4333
4330 4334 * Heavy edits in ipplib. Removed the help system altogether. Now
4331 4335 obj?/?? is used for inspecting objects, a magic @doc prints
4332 4336 docstrings, and full-blown Python help is accessed via the 'help'
4333 4337 keyword. This cleans up a lot of code (less to maintain) and does
4334 4338 the job. Since 'help' is now a standard Python component, might as
4335 4339 well use it and remove duplicate functionality.
4336 4340
4337 4341 Also removed the option to use ipplib as a standalone program. By
4338 4342 now it's too dependent on other parts of IPython to function alone.
4339 4343
4340 4344 * Fixed bug in genutils.pager. It would crash if the pager was
4341 4345 exited immediately after opening (broken pipe).
4342 4346
4343 4347 * Trimmed down the VerboseTB reporting a little. The header is
4344 4348 much shorter now and the repeated exception arguments at the end
4345 4349 have been removed. For interactive use the old header seemed a bit
4346 4350 excessive.
4347 4351
4348 4352 * Fixed small bug in output of @whos for variables with multi-word
4349 4353 types (only first word was displayed).
4350 4354
4351 4355 2001-11-17 Fernando Perez <fperez@colorado.edu>
4352 4356
4353 4357 * Version 0.1.10 released, 0.1.11 opened for further work.
4354 4358
4355 4359 * Modified dirs and friends. dirs now *returns* the stack (not
4356 4360 prints), so one can manipulate it as a variable. Convenient to
4357 4361 travel along many directories.
4358 4362
4359 4363 * Fixed bug in magic_pdef: would only work with functions with
4360 4364 arguments with default values.
4361 4365
4362 4366 2001-11-14 Fernando Perez <fperez@colorado.edu>
4363 4367
4364 4368 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4365 4369 example with IPython. Various other minor fixes and cleanups.
4366 4370
4367 4371 * Version 0.1.9 released, 0.1.10 opened for further work.
4368 4372
4369 4373 * Added sys.path to the list of directories searched in the
4370 4374 execfile= option. It used to be the current directory and the
4371 4375 user's IPYTHONDIR only.
4372 4376
4373 4377 2001-11-13 Fernando Perez <fperez@colorado.edu>
4374 4378
4375 4379 * Reinstated the raw_input/prefilter separation that Janko had
4376 4380 initially. This gives a more convenient setup for extending the
4377 4381 pre-processor from the outside: raw_input always gets a string,
4378 4382 and prefilter has to process it. We can then redefine prefilter
4379 4383 from the outside and implement extensions for special
4380 4384 purposes.
4381 4385
4382 4386 Today I got one for inputting PhysicalQuantity objects
4383 4387 (from Scientific) without needing any function calls at
4384 4388 all. Extremely convenient, and it's all done as a user-level
4385 4389 extension (no IPython code was touched). Now instead of:
4386 4390 a = PhysicalQuantity(4.2,'m/s**2')
4387 4391 one can simply say
4388 4392 a = 4.2 m/s**2
4389 4393 or even
4390 4394 a = 4.2 m/s^2
4391 4395
4392 4396 I use this, but it's also a proof of concept: IPython really is
4393 4397 fully user-extensible, even at the level of the parsing of the
4394 4398 command line. It's not trivial, but it's perfectly doable.
4395 4399
4396 4400 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4397 4401 the problem of modules being loaded in the inverse order in which
4398 4402 they were defined in
4399 4403
4400 4404 * Version 0.1.8 released, 0.1.9 opened for further work.
4401 4405
4402 4406 * Added magics pdef, source and file. They respectively show the
4403 4407 definition line ('prototype' in C), source code and full python
4404 4408 file for any callable object. The object inspector oinfo uses
4405 4409 these to show the same information.
4406 4410
4407 4411 * Version 0.1.7 released, 0.1.8 opened for further work.
4408 4412
4409 4413 * Separated all the magic functions into a class called Magic. The
4410 4414 InteractiveShell class was becoming too big for Xemacs to handle
4411 4415 (de-indenting a line would lock it up for 10 seconds while it
4412 4416 backtracked on the whole class!)
4413 4417
4414 4418 FIXME: didn't work. It can be done, but right now namespaces are
4415 4419 all messed up. Do it later (reverted it for now, so at least
4416 4420 everything works as before).
4417 4421
4418 4422 * Got the object introspection system (magic_oinfo) working! I
4419 4423 think this is pretty much ready for release to Janko, so he can
4420 4424 test it for a while and then announce it. Pretty much 100% of what
4421 4425 I wanted for the 'phase 1' release is ready. Happy, tired.
4422 4426
4423 4427 2001-11-12 Fernando Perez <fperez@colorado.edu>
4424 4428
4425 4429 * Version 0.1.6 released, 0.1.7 opened for further work.
4426 4430
4427 4431 * Fixed bug in printing: it used to test for truth before
4428 4432 printing, so 0 wouldn't print. Now checks for None.
4429 4433
4430 4434 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4431 4435 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4432 4436 reaches by hand into the outputcache. Think of a better way to do
4433 4437 this later.
4434 4438
4435 4439 * Various small fixes thanks to Nathan's comments.
4436 4440
4437 4441 * Changed magic_pprint to magic_Pprint. This way it doesn't
4438 4442 collide with pprint() and the name is consistent with the command
4439 4443 line option.
4440 4444
4441 4445 * Changed prompt counter behavior to be fully like
4442 4446 Mathematica's. That is, even input that doesn't return a result
4443 4447 raises the prompt counter. The old behavior was kind of confusing
4444 4448 (getting the same prompt number several times if the operation
4445 4449 didn't return a result).
4446 4450
4447 4451 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4448 4452
4449 4453 * Fixed -Classic mode (wasn't working anymore).
4450 4454
4451 4455 * Added colored prompts using Nathan's new code. Colors are
4452 4456 currently hardwired, they can be user-configurable. For
4453 4457 developers, they can be chosen in file ipythonlib.py, at the
4454 4458 beginning of the CachedOutput class def.
4455 4459
4456 4460 2001-11-11 Fernando Perez <fperez@colorado.edu>
4457 4461
4458 4462 * Version 0.1.5 released, 0.1.6 opened for further work.
4459 4463
4460 4464 * Changed magic_env to *return* the environment as a dict (not to
4461 4465 print it). This way it prints, but it can also be processed.
4462 4466
4463 4467 * Added Verbose exception reporting to interactive
4464 4468 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4465 4469 traceback. Had to make some changes to the ultraTB file. This is
4466 4470 probably the last 'big' thing in my mental todo list. This ties
4467 4471 in with the next entry:
4468 4472
4469 4473 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4470 4474 has to specify is Plain, Color or Verbose for all exception
4471 4475 handling.
4472 4476
4473 4477 * Removed ShellServices option. All this can really be done via
4474 4478 the magic system. It's easier to extend, cleaner and has automatic
4475 4479 namespace protection and documentation.
4476 4480
4477 4481 2001-11-09 Fernando Perez <fperez@colorado.edu>
4478 4482
4479 4483 * Fixed bug in output cache flushing (missing parameter to
4480 4484 __init__). Other small bugs fixed (found using pychecker).
4481 4485
4482 4486 * Version 0.1.4 opened for bugfixing.
4483 4487
4484 4488 2001-11-07 Fernando Perez <fperez@colorado.edu>
4485 4489
4486 4490 * Version 0.1.3 released, mainly because of the raw_input bug.
4487 4491
4488 4492 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4489 4493 and when testing for whether things were callable, a call could
4490 4494 actually be made to certain functions. They would get called again
4491 4495 once 'really' executed, with a resulting double call. A disaster
4492 4496 in many cases (list.reverse() would never work!).
4493 4497
4494 4498 * Removed prefilter() function, moved its code to raw_input (which
4495 4499 after all was just a near-empty caller for prefilter). This saves
4496 4500 a function call on every prompt, and simplifies the class a tiny bit.
4497 4501
4498 4502 * Fix _ip to __ip name in magic example file.
4499 4503
4500 4504 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4501 4505 work with non-gnu versions of tar.
4502 4506
4503 4507 2001-11-06 Fernando Perez <fperez@colorado.edu>
4504 4508
4505 4509 * Version 0.1.2. Just to keep track of the recent changes.
4506 4510
4507 4511 * Fixed nasty bug in output prompt routine. It used to check 'if
4508 4512 arg != None...'. Problem is, this fails if arg implements a
4509 4513 special comparison (__cmp__) which disallows comparing to
4510 4514 None. Found it when trying to use the PhysicalQuantity module from
4511 4515 ScientificPython.
4512 4516
4513 4517 2001-11-05 Fernando Perez <fperez@colorado.edu>
4514 4518
4515 4519 * Also added dirs. Now the pushd/popd/dirs family functions
4516 4520 basically like the shell, with the added convenience of going home
4517 4521 when called with no args.
4518 4522
4519 4523 * pushd/popd slightly modified to mimic shell behavior more
4520 4524 closely.
4521 4525
4522 4526 * Added env,pushd,popd from ShellServices as magic functions. I
4523 4527 think the cleanest will be to port all desired functions from
4524 4528 ShellServices as magics and remove ShellServices altogether. This
4525 4529 will provide a single, clean way of adding functionality
4526 4530 (shell-type or otherwise) to IP.
4527 4531
4528 4532 2001-11-04 Fernando Perez <fperez@colorado.edu>
4529 4533
4530 4534 * Added .ipython/ directory to sys.path. This way users can keep
4531 4535 customizations there and access them via import.
4532 4536
4533 4537 2001-11-03 Fernando Perez <fperez@colorado.edu>
4534 4538
4535 4539 * Opened version 0.1.1 for new changes.
4536 4540
4537 4541 * Changed version number to 0.1.0: first 'public' release, sent to
4538 4542 Nathan and Janko.
4539 4543
4540 4544 * Lots of small fixes and tweaks.
4541 4545
4542 4546 * Minor changes to whos format. Now strings are shown, snipped if
4543 4547 too long.
4544 4548
4545 4549 * Changed ShellServices to work on __main__ so they show up in @who
4546 4550
4547 4551 * Help also works with ? at the end of a line:
4548 4552 ?sin and sin?
4549 4553 both produce the same effect. This is nice, as often I use the
4550 4554 tab-complete to find the name of a method, but I used to then have
4551 4555 to go to the beginning of the line to put a ? if I wanted more
4552 4556 info. Now I can just add the ? and hit return. Convenient.
4553 4557
4554 4558 2001-11-02 Fernando Perez <fperez@colorado.edu>
4555 4559
4556 4560 * Python version check (>=2.1) added.
4557 4561
4558 4562 * Added LazyPython documentation. At this point the docs are quite
4559 4563 a mess. A cleanup is in order.
4560 4564
4561 4565 * Auto-installer created. For some bizarre reason, the zipfiles
4562 4566 module isn't working on my system. So I made a tar version
4563 4567 (hopefully the command line options in various systems won't kill
4564 4568 me).
4565 4569
4566 4570 * Fixes to Struct in genutils. Now all dictionary-like methods are
4567 4571 protected (reasonably).
4568 4572
4569 4573 * Added pager function to genutils and changed ? to print usage
4570 4574 note through it (it was too long).
4571 4575
4572 4576 * Added the LazyPython functionality. Works great! I changed the
4573 4577 auto-quote escape to ';', it's on home row and next to '. But
4574 4578 both auto-quote and auto-paren (still /) escapes are command-line
4575 4579 parameters.
4576 4580
4577 4581
4578 4582 2001-11-01 Fernando Perez <fperez@colorado.edu>
4579 4583
4580 4584 * Version changed to 0.0.7. Fairly large change: configuration now
4581 4585 is all stored in a directory, by default .ipython. There, all
4582 4586 config files have normal looking names (not .names)
4583 4587
4584 4588 * Version 0.0.6 Released first to Lucas and Archie as a test
4585 4589 run. Since it's the first 'semi-public' release, change version to
4586 4590 > 0.0.6 for any changes now.
4587 4591
4588 4592 * Stuff I had put in the ipplib.py changelog:
4589 4593
4590 4594 Changes to InteractiveShell:
4591 4595
4592 4596 - Made the usage message a parameter.
4593 4597
4594 4598 - Require the name of the shell variable to be given. It's a bit
4595 4599 of a hack, but allows the name 'shell' not to be hardwire in the
4596 4600 magic (@) handler, which is problematic b/c it requires
4597 4601 polluting the global namespace with 'shell'. This in turn is
4598 4602 fragile: if a user redefines a variable called shell, things
4599 4603 break.
4600 4604
4601 4605 - magic @: all functions available through @ need to be defined
4602 4606 as magic_<name>, even though they can be called simply as
4603 4607 @<name>. This allows the special command @magic to gather
4604 4608 information automatically about all existing magic functions,
4605 4609 even if they are run-time user extensions, by parsing the shell
4606 4610 instance __dict__ looking for special magic_ names.
4607 4611
4608 4612 - mainloop: added *two* local namespace parameters. This allows
4609 4613 the class to differentiate between parameters which were there
4610 4614 before and after command line initialization was processed. This
4611 4615 way, later @who can show things loaded at startup by the
4612 4616 user. This trick was necessary to make session saving/reloading
4613 4617 really work: ideally after saving/exiting/reloading a session,
4614 4618 *everythin* should look the same, including the output of @who. I
4615 4619 was only able to make this work with this double namespace
4616 4620 trick.
4617 4621
4618 4622 - added a header to the logfile which allows (almost) full
4619 4623 session restoring.
4620 4624
4621 4625 - prepend lines beginning with @ or !, with a and log
4622 4626 them. Why? !lines: may be useful to know what you did @lines:
4623 4627 they may affect session state. So when restoring a session, at
4624 4628 least inform the user of their presence. I couldn't quite get
4625 4629 them to properly re-execute, but at least the user is warned.
4626 4630
4627 4631 * Started ChangeLog.
General Comments 0
You need to be logged in to leave comments. Login now