##// END OF EJS Templates
Fixes to input splitting to reduce the occurrences of spurious attribute...
fperez -
Show More
@@ -1,3084 +1,3085 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 2104 2007-02-20 10:25:51Z fperez $"""
4 $Id: Magic.py 2122 2007-03-01 02:27:11Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
8 8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 9 #
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #*****************************************************************************
13 13
14 14 #****************************************************************************
15 15 # Modules and globals
16 16
17 17 from IPython import Release
18 18 __author__ = '%s <%s>\n%s <%s>' % \
19 19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
20 20 __license__ = Release.license
21 21
22 22 # Python standard modules
23 23 import __builtin__
24 24 import bdb
25 25 import inspect
26 26 import os
27 27 import pdb
28 28 import pydoc
29 29 import sys
30 30 import re
31 31 import tempfile
32 32 import time
33 33 import cPickle as pickle
34 34 import textwrap
35 35 from cStringIO import StringIO
36 36 from getopt import getopt,GetoptError
37 37 from pprint import pprint, pformat
38 38
39 39 # cProfile was added in Python2.5
40 40 try:
41 41 import cProfile as profile
42 42 import pstats
43 43 except ImportError:
44 44 # profile isn't bundled by default in Debian for license reasons
45 45 try:
46 46 import profile,pstats
47 47 except ImportError:
48 48 profile = pstats = None
49 49
50 50 # Homebrewed
51 51 import IPython
52 52 from IPython import Debugger, OInspect, wildcard
53 53 from IPython.FakeModule import FakeModule
54 54 from IPython.Itpl import Itpl, itpl, printpl,itplns
55 55 from IPython.PyColorize import Parser
56 56 from IPython.ipstruct import Struct
57 57 from IPython.macro import Macro
58 58 from IPython.genutils import *
59 59 from IPython import platutils
60 60
61 61 #***************************************************************************
62 62 # Utility functions
63 63 def on_off(tag):
64 64 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
65 65 return ['OFF','ON'][tag]
66 66
67 67 class Bunch: pass
68 68
69 69 #***************************************************************************
70 70 # Main class implementing Magic functionality
71 71 class Magic:
72 72 """Magic functions for InteractiveShell.
73 73
74 74 Shell functions which can be reached as %function_name. All magic
75 75 functions should accept a string, which they can parse for their own
76 76 needs. This can make some functions easier to type, eg `%cd ../`
77 77 vs. `%cd("../")`
78 78
79 79 ALL definitions MUST begin with the prefix magic_. The user won't need it
80 80 at the command line, but it is is needed in the definition. """
81 81
82 82 # class globals
83 83 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
84 84 'Automagic is ON, % prefix NOT needed for magic functions.']
85 85
86 86 #......................................................................
87 87 # some utility functions
88 88
89 89 def __init__(self,shell):
90 90
91 91 self.options_table = {}
92 92 if profile is None:
93 93 self.magic_prun = self.profile_missing_notice
94 94 self.shell = shell
95 95
96 96 # namespace for holding state we may need
97 97 self._magic_state = Bunch()
98 98
99 99 def profile_missing_notice(self, *args, **kwargs):
100 100 error("""\
101 101 The profile module could not be found. If you are a Debian user,
102 102 it has been removed from the standard Debian package because of its non-free
103 103 license. To use profiling, please install"python2.3-profiler" from non-free.""")
104 104
105 105 def default_option(self,fn,optstr):
106 106 """Make an entry in the options_table for fn, with value optstr"""
107 107
108 108 if fn not in self.lsmagic():
109 109 error("%s is not a magic function" % fn)
110 110 self.options_table[fn] = optstr
111 111
112 112 def lsmagic(self):
113 113 """Return a list of currently available magic functions.
114 114
115 115 Gives a list of the bare names after mangling (['ls','cd', ...], not
116 116 ['magic_ls','magic_cd',...]"""
117 117
118 118 # FIXME. This needs a cleanup, in the way the magics list is built.
119 119
120 120 # magics in class definition
121 121 class_magic = lambda fn: fn.startswith('magic_') and \
122 122 callable(Magic.__dict__[fn])
123 123 # in instance namespace (run-time user additions)
124 124 inst_magic = lambda fn: fn.startswith('magic_') and \
125 125 callable(self.__dict__[fn])
126 126 # and bound magics by user (so they can access self):
127 127 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
128 128 callable(self.__class__.__dict__[fn])
129 129 magics = filter(class_magic,Magic.__dict__.keys()) + \
130 130 filter(inst_magic,self.__dict__.keys()) + \
131 131 filter(inst_bound_magic,self.__class__.__dict__.keys())
132 132 out = []
133 133 for fn in magics:
134 134 out.append(fn.replace('magic_','',1))
135 135 out.sort()
136 136 return out
137 137
138 138 def extract_input_slices(self,slices,raw=False):
139 139 """Return as a string a set of input history slices.
140 140
141 141 Inputs:
142 142
143 143 - slices: the set of slices is given as a list of strings (like
144 144 ['1','4:8','9'], since this function is for use by magic functions
145 145 which get their arguments as strings.
146 146
147 147 Optional inputs:
148 148
149 149 - raw(False): by default, the processed input is used. If this is
150 150 true, the raw input history is used instead.
151 151
152 152 Note that slices can be called with two notations:
153 153
154 154 N:M -> standard python form, means including items N...(M-1).
155 155
156 156 N-M -> include items N..M (closed endpoint)."""
157 157
158 158 if raw:
159 159 hist = self.shell.input_hist_raw
160 160 else:
161 161 hist = self.shell.input_hist
162 162
163 163 cmds = []
164 164 for chunk in slices:
165 165 if ':' in chunk:
166 166 ini,fin = map(int,chunk.split(':'))
167 167 elif '-' in chunk:
168 168 ini,fin = map(int,chunk.split('-'))
169 169 fin += 1
170 170 else:
171 171 ini = int(chunk)
172 172 fin = ini+1
173 173 cmds.append(hist[ini:fin])
174 174 return cmds
175 175
176 176 def _ofind(self, oname, namespaces=None):
177 177 """Find an object in the available namespaces.
178 178
179 179 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
180 180
181 181 Has special code to detect magic functions.
182 182 """
183 183
184 184 oname = oname.strip()
185 185
186 186 alias_ns = None
187 187 if namespaces is None:
188 188 # Namespaces to search in:
189 189 # Put them in a list. The order is important so that we
190 190 # find things in the same order that Python finds them.
191 191 namespaces = [ ('Interactive', self.shell.user_ns),
192 192 ('IPython internal', self.shell.internal_ns),
193 193 ('Python builtin', __builtin__.__dict__),
194 194 ('Alias', self.shell.alias_table),
195 195 ]
196 196 alias_ns = self.shell.alias_table
197 197
198 198 # initialize results to 'null'
199 199 found = 0; obj = None; ospace = None; ds = None;
200 200 ismagic = 0; isalias = 0; parent = None
201 201
202 202 # Look for the given name by splitting it in parts. If the head is
203 203 # found, then we look for all the remaining parts as members, and only
204 204 # declare success if we can find them all.
205 205 oname_parts = oname.split('.')
206 206 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
207 207 for nsname,ns in namespaces:
208 208 try:
209 209 obj = ns[oname_head]
210 210 except KeyError:
211 211 continue
212 212 else:
213 #print 'oname_rest:', oname_rest # dbg
213 214 for part in oname_rest:
214 215 try:
215 216 parent = obj
216 217 obj = getattr(obj,part)
217 218 except:
218 219 # Blanket except b/c some badly implemented objects
219 220 # allow __getattr__ to raise exceptions other than
220 221 # AttributeError, which then crashes IPython.
221 222 break
222 223 else:
223 224 # If we finish the for loop (no break), we got all members
224 225 found = 1
225 226 ospace = nsname
226 227 if ns == alias_ns:
227 228 isalias = 1
228 229 break # namespace loop
229 230
230 231 # Try to see if it's magic
231 232 if not found:
232 233 if oname.startswith(self.shell.ESC_MAGIC):
233 234 oname = oname[1:]
234 235 obj = getattr(self,'magic_'+oname,None)
235 236 if obj is not None:
236 237 found = 1
237 238 ospace = 'IPython internal'
238 239 ismagic = 1
239 240
240 241 # Last try: special-case some literals like '', [], {}, etc:
241 242 if not found and oname_head in ["''",'""','[]','{}','()']:
242 243 obj = eval(oname_head)
243 244 found = 1
244 245 ospace = 'Interactive'
245 246
246 247 return {'found':found, 'obj':obj, 'namespace':ospace,
247 248 'ismagic':ismagic, 'isalias':isalias, 'parent':parent}
248 249
249 250 def arg_err(self,func):
250 251 """Print docstring if incorrect arguments were passed"""
251 252 print 'Error in arguments:'
252 253 print OInspect.getdoc(func)
253 254
254 255 def format_latex(self,strng):
255 256 """Format a string for latex inclusion."""
256 257
257 258 # Characters that need to be escaped for latex:
258 259 escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE)
259 260 # Magic command names as headers:
260 261 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
261 262 re.MULTILINE)
262 263 # Magic commands
263 264 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
264 265 re.MULTILINE)
265 266 # Paragraph continue
266 267 par_re = re.compile(r'\\$',re.MULTILINE)
267 268
268 269 # The "\n" symbol
269 270 newline_re = re.compile(r'\\n')
270 271
271 272 # Now build the string for output:
272 273 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
273 274 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
274 275 strng)
275 276 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
276 277 strng = par_re.sub(r'\\\\',strng)
277 278 strng = escape_re.sub(r'\\\1',strng)
278 279 strng = newline_re.sub(r'\\textbackslash{}n',strng)
279 280 return strng
280 281
281 282 def format_screen(self,strng):
282 283 """Format a string for screen printing.
283 284
284 285 This removes some latex-type format codes."""
285 286 # Paragraph continue
286 287 par_re = re.compile(r'\\$',re.MULTILINE)
287 288 strng = par_re.sub('',strng)
288 289 return strng
289 290
290 291 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
291 292 """Parse options passed to an argument string.
292 293
293 294 The interface is similar to that of getopt(), but it returns back a
294 295 Struct with the options as keys and the stripped argument string still
295 296 as a string.
296 297
297 298 arg_str is quoted as a true sys.argv vector by using shlex.split.
298 299 This allows us to easily expand variables, glob files, quote
299 300 arguments, etc.
300 301
301 302 Options:
302 303 -mode: default 'string'. If given as 'list', the argument string is
303 304 returned as a list (split on whitespace) instead of a string.
304 305
305 306 -list_all: put all option values in lists. Normally only options
306 307 appearing more than once are put in a list.
307 308
308 309 -posix (True): whether to split the input line in POSIX mode or not,
309 310 as per the conventions outlined in the shlex module from the
310 311 standard library."""
311 312
312 313 # inject default options at the beginning of the input line
313 314 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
314 315 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
315 316
316 317 mode = kw.get('mode','string')
317 318 if mode not in ['string','list']:
318 319 raise ValueError,'incorrect mode given: %s' % mode
319 320 # Get options
320 321 list_all = kw.get('list_all',0)
321 322 posix = kw.get('posix',True)
322 323
323 324 # Check if we have more than one argument to warrant extra processing:
324 325 odict = {} # Dictionary with options
325 326 args = arg_str.split()
326 327 if len(args) >= 1:
327 328 # If the list of inputs only has 0 or 1 thing in it, there's no
328 329 # need to look for options
329 330 argv = arg_split(arg_str,posix)
330 331 # Do regular option processing
331 332 try:
332 333 opts,args = getopt(argv,opt_str,*long_opts)
333 334 except GetoptError,e:
334 335 raise GetoptError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
335 336 " ".join(long_opts)))
336 337 for o,a in opts:
337 338 if o.startswith('--'):
338 339 o = o[2:]
339 340 else:
340 341 o = o[1:]
341 342 try:
342 343 odict[o].append(a)
343 344 except AttributeError:
344 345 odict[o] = [odict[o],a]
345 346 except KeyError:
346 347 if list_all:
347 348 odict[o] = [a]
348 349 else:
349 350 odict[o] = a
350 351
351 352 # Prepare opts,args for return
352 353 opts = Struct(odict)
353 354 if mode == 'string':
354 355 args = ' '.join(args)
355 356
356 357 return opts,args
357 358
358 359 #......................................................................
359 360 # And now the actual magic functions
360 361
361 362 # Functions for IPython shell work (vars,funcs, config, etc)
362 363 def magic_lsmagic(self, parameter_s = ''):
363 364 """List currently available magic functions."""
364 365 mesc = self.shell.ESC_MAGIC
365 366 print 'Available magic functions:\n'+mesc+\
366 367 (' '+mesc).join(self.lsmagic())
367 368 print '\n' + Magic.auto_status[self.shell.rc.automagic]
368 369 return None
369 370
370 371 def magic_magic(self, parameter_s = ''):
371 372 """Print information about the magic function system."""
372 373
373 374 mode = ''
374 375 try:
375 376 if parameter_s.split()[0] == '-latex':
376 377 mode = 'latex'
377 378 if parameter_s.split()[0] == '-brief':
378 379 mode = 'brief'
379 380 except:
380 381 pass
381 382
382 383 magic_docs = []
383 384 for fname in self.lsmagic():
384 385 mname = 'magic_' + fname
385 386 for space in (Magic,self,self.__class__):
386 387 try:
387 388 fn = space.__dict__[mname]
388 389 except KeyError:
389 390 pass
390 391 else:
391 392 break
392 393 if mode == 'brief':
393 394 # only first line
394 395 fndoc = fn.__doc__.split('\n',1)[0]
395 396 else:
396 397 fndoc = fn.__doc__
397 398
398 399 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
399 400 fname,fndoc))
400 401 magic_docs = ''.join(magic_docs)
401 402
402 403 if mode == 'latex':
403 404 print self.format_latex(magic_docs)
404 405 return
405 406 else:
406 407 magic_docs = self.format_screen(magic_docs)
407 408 if mode == 'brief':
408 409 return magic_docs
409 410
410 411 outmsg = """
411 412 IPython's 'magic' functions
412 413 ===========================
413 414
414 415 The magic function system provides a series of functions which allow you to
415 416 control the behavior of IPython itself, plus a lot of system-type
416 417 features. All these functions are prefixed with a % character, but parameters
417 418 are given without parentheses or quotes.
418 419
419 420 NOTE: If you have 'automagic' enabled (via the command line option or with the
420 421 %automagic function), you don't need to type in the % explicitly. By default,
421 422 IPython ships with automagic on, so you should only rarely need the % escape.
422 423
423 424 Example: typing '%cd mydir' (without the quotes) changes you working directory
424 425 to 'mydir', if it exists.
425 426
426 427 You can define your own magic functions to extend the system. See the supplied
427 428 ipythonrc and example-magic.py files for details (in your ipython
428 429 configuration directory, typically $HOME/.ipython/).
429 430
430 431 You can also define your own aliased names for magic functions. In your
431 432 ipythonrc file, placing a line like:
432 433
433 434 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
434 435
435 436 will define %pf as a new name for %profile.
436 437
437 438 You can also call magics in code using the ipmagic() function, which IPython
438 439 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
439 440
440 441 For a list of the available magic functions, use %lsmagic. For a description
441 442 of any of them, type %magic_name?, e.g. '%cd?'.
442 443
443 444 Currently the magic system has the following functions:\n"""
444 445
445 446 mesc = self.shell.ESC_MAGIC
446 447 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
447 448 "\n\n%s%s\n\n%s" % (outmsg,
448 449 magic_docs,mesc,mesc,
449 450 (' '+mesc).join(self.lsmagic()),
450 451 Magic.auto_status[self.shell.rc.automagic] ) )
451 452
452 453 page(outmsg,screen_lines=self.shell.rc.screen_length)
453 454
454 455 def magic_automagic(self, parameter_s = ''):
455 456 """Make magic functions callable without having to type the initial %.
456 457
457 458 Without argumentsl toggles on/off (when off, you must call it as
458 459 %automagic, of course). With arguments it sets the value, and you can
459 460 use any of (case insensitive):
460 461
461 462 - on,1,True: to activate
462 463
463 464 - off,0,False: to deactivate.
464 465
465 466 Note that magic functions have lowest priority, so if there's a
466 467 variable whose name collides with that of a magic fn, automagic won't
467 468 work for that function (you get the variable instead). However, if you
468 469 delete the variable (del var), the previously shadowed magic function
469 470 becomes visible to automagic again."""
470 471
471 472 rc = self.shell.rc
472 473 arg = parameter_s.lower()
473 474 if parameter_s in ('on','1','true'):
474 475 rc.automagic = True
475 476 elif parameter_s in ('off','0','false'):
476 477 rc.automagic = False
477 478 else:
478 479 rc.automagic = not rc.automagic
479 480 print '\n' + Magic.auto_status[rc.automagic]
480 481
481 482 def magic_autocall(self, parameter_s = ''):
482 483 """Make functions callable without having to type parentheses.
483 484
484 485 Usage:
485 486
486 487 %autocall [mode]
487 488
488 489 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
489 490 value is toggled on and off (remembering the previous state)."""
490 491
491 492 rc = self.shell.rc
492 493
493 494 if parameter_s:
494 495 arg = int(parameter_s)
495 496 else:
496 497 arg = 'toggle'
497 498
498 499 if not arg in (0,1,2,'toggle'):
499 500 error('Valid modes: (0->Off, 1->Smart, 2->Full')
500 501 return
501 502
502 503 if arg in (0,1,2):
503 504 rc.autocall = arg
504 505 else: # toggle
505 506 if rc.autocall:
506 507 self._magic_state.autocall_save = rc.autocall
507 508 rc.autocall = 0
508 509 else:
509 510 try:
510 511 rc.autocall = self._magic_state.autocall_save
511 512 except AttributeError:
512 513 rc.autocall = self._magic_state.autocall_save = 1
513 514
514 515 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
515 516
516 517 def magic_autoindent(self, parameter_s = ''):
517 518 """Toggle autoindent on/off (if available)."""
518 519
519 520 self.shell.set_autoindent()
520 521 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
521 522
522 523 def magic_system_verbose(self, parameter_s = ''):
523 524 """Set verbose printing of system calls.
524 525
525 526 If called without an argument, act as a toggle"""
526 527
527 528 if parameter_s:
528 529 val = bool(eval(parameter_s))
529 530 else:
530 531 val = None
531 532
532 533 self.shell.rc_set_toggle('system_verbose',val)
533 534 print "System verbose printing is:",\
534 535 ['OFF','ON'][self.shell.rc.system_verbose]
535 536
536 537 def magic_history(self, parameter_s = ''):
537 538 """Print input history (_i<n> variables), with most recent last.
538 539
539 540 %history -> print at most 40 inputs (some may be multi-line)\\
540 541 %history n -> print at most n inputs\\
541 542 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
542 543
543 544 Each input's number <n> is shown, and is accessible as the
544 545 automatically generated variable _i<n>. Multi-line statements are
545 546 printed starting at a new line for easy copy/paste.
546 547
547 548
548 549 Options:
549 550
550 551 -n: do NOT print line numbers. This is useful if you want to get a
551 552 printout of many lines which can be directly pasted into a text
552 553 editor.
553 554
554 555 This feature is only available if numbered prompts are in use.
555 556
556 557 -r: print the 'raw' history. IPython filters your input and
557 558 converts it all into valid Python source before executing it (things
558 559 like magics or aliases are turned into function calls, for
559 560 example). With this option, you'll see the unfiltered history
560 561 instead of the filtered version: '%cd /' will be seen as '%cd /'
561 562 instead of '_ip.magic("%cd /")'.
562 563 """
563 564
564 565 shell = self.shell
565 566 if not shell.outputcache.do_full_cache:
566 567 print 'This feature is only available if numbered prompts are in use.'
567 568 return
568 569 opts,args = self.parse_options(parameter_s,'nr',mode='list')
569 570
570 571 if opts.has_key('r'):
571 572 input_hist = shell.input_hist_raw
572 573 else:
573 574 input_hist = shell.input_hist
574 575
575 576 default_length = 40
576 577 if len(args) == 0:
577 578 final = len(input_hist)
578 579 init = max(1,final-default_length)
579 580 elif len(args) == 1:
580 581 final = len(input_hist)
581 582 init = max(1,final-int(args[0]))
582 583 elif len(args) == 2:
583 584 init,final = map(int,args)
584 585 else:
585 586 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
586 587 print self.magic_hist.__doc__
587 588 return
588 589 width = len(str(final))
589 590 line_sep = ['','\n']
590 591 print_nums = not opts.has_key('n')
591 592 for in_num in range(init,final):
592 593 inline = input_hist[in_num]
593 594 multiline = int(inline.count('\n') > 1)
594 595 if print_nums:
595 596 print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
596 597 print inline,
597 598
598 599 def magic_hist(self, parameter_s=''):
599 600 """Alternate name for %history."""
600 601 return self.magic_history(parameter_s)
601 602
602 603 def magic_p(self, parameter_s=''):
603 604 """Just a short alias for Python's 'print'."""
604 605 exec 'print ' + parameter_s in self.shell.user_ns
605 606
606 607 def magic_r(self, parameter_s=''):
607 608 """Repeat previous input.
608 609
609 610 If given an argument, repeats the previous command which starts with
610 611 the same string, otherwise it just repeats the previous input.
611 612
612 613 Shell escaped commands (with ! as first character) are not recognized
613 614 by this system, only pure python code and magic commands.
614 615 """
615 616
616 617 start = parameter_s.strip()
617 618 esc_magic = self.shell.ESC_MAGIC
618 619 # Identify magic commands even if automagic is on (which means
619 620 # the in-memory version is different from that typed by the user).
620 621 if self.shell.rc.automagic:
621 622 start_magic = esc_magic+start
622 623 else:
623 624 start_magic = start
624 625 # Look through the input history in reverse
625 626 for n in range(len(self.shell.input_hist)-2,0,-1):
626 627 input = self.shell.input_hist[n]
627 628 # skip plain 'r' lines so we don't recurse to infinity
628 629 if input != '_ip.magic("r")\n' and \
629 630 (input.startswith(start) or input.startswith(start_magic)):
630 631 #print 'match',`input` # dbg
631 632 print 'Executing:',input,
632 633 self.shell.runlines(input)
633 634 return
634 635 print 'No previous input matching `%s` found.' % start
635 636
636 637 def magic_page(self, parameter_s=''):
637 638 """Pretty print the object and display it through a pager.
638 639
639 640 %page [options] OBJECT
640 641
641 642 If no object is given, use _ (last output).
642 643
643 644 Options:
644 645
645 646 -r: page str(object), don't pretty-print it."""
646 647
647 648 # After a function contributed by Olivier Aubert, slightly modified.
648 649
649 650 # Process options/args
650 651 opts,args = self.parse_options(parameter_s,'r')
651 652 raw = 'r' in opts
652 653
653 654 oname = args and args or '_'
654 655 info = self._ofind(oname)
655 656 if info['found']:
656 657 txt = (raw and str or pformat)( info['obj'] )
657 658 page(txt)
658 659 else:
659 660 print 'Object `%s` not found' % oname
660 661
661 662 def magic_profile(self, parameter_s=''):
662 663 """Print your currently active IPyhton profile."""
663 664 if self.shell.rc.profile:
664 665 printpl('Current IPython profile: $self.shell.rc.profile.')
665 666 else:
666 667 print 'No profile active.'
667 668
668 669 def _inspect(self,meth,oname,namespaces=None,**kw):
669 670 """Generic interface to the inspector system.
670 671
671 672 This function is meant to be called by pdef, pdoc & friends."""
672 673
673 674 oname = oname.strip()
674 675 info = Struct(self._ofind(oname, namespaces))
675 676
676 677 if info.found:
677 678 # Get the docstring of the class property if it exists.
678 679 path = oname.split('.')
679 680 root = '.'.join(path[:-1])
680 681 if info.parent is not None:
681 682 try:
682 683 target = getattr(info.parent, '__class__')
683 684 # The object belongs to a class instance.
684 685 try:
685 686 target = getattr(target, path[-1])
686 687 # The class defines the object.
687 688 if isinstance(target, property):
688 689 oname = root + '.__class__.' + path[-1]
689 690 info = Struct(self._ofind(oname))
690 691 except AttributeError: pass
691 692 except AttributeError: pass
692 693
693 694 pmethod = getattr(self.shell.inspector,meth)
694 695 formatter = info.ismagic and self.format_screen or None
695 696 if meth == 'pdoc':
696 697 pmethod(info.obj,oname,formatter)
697 698 elif meth == 'pinfo':
698 699 pmethod(info.obj,oname,formatter,info,**kw)
699 700 else:
700 701 pmethod(info.obj,oname)
701 702 else:
702 703 print 'Object `%s` not found.' % oname
703 704 return 'not found' # so callers can take other action
704 705
705 706 def magic_pdef(self, parameter_s='', namespaces=None):
706 707 """Print the definition header for any callable object.
707 708
708 709 If the object is a class, print the constructor information."""
709 710 self._inspect('pdef',parameter_s, namespaces)
710 711
711 712 def magic_pdoc(self, parameter_s='', namespaces=None):
712 713 """Print the docstring for an object.
713 714
714 715 If the given object is a class, it will print both the class and the
715 716 constructor docstrings."""
716 717 self._inspect('pdoc',parameter_s, namespaces)
717 718
718 719 def magic_psource(self, parameter_s='', namespaces=None):
719 720 """Print (or run through pager) the source code for an object."""
720 721 self._inspect('psource',parameter_s, namespaces)
721 722
722 723 def magic_pfile(self, parameter_s=''):
723 724 """Print (or run through pager) the file where an object is defined.
724 725
725 726 The file opens at the line where the object definition begins. IPython
726 727 will honor the environment variable PAGER if set, and otherwise will
727 728 do its best to print the file in a convenient form.
728 729
729 730 If the given argument is not an object currently defined, IPython will
730 731 try to interpret it as a filename (automatically adding a .py extension
731 732 if needed). You can thus use %pfile as a syntax highlighting code
732 733 viewer."""
733 734
734 735 # first interpret argument as an object name
735 736 out = self._inspect('pfile',parameter_s)
736 737 # if not, try the input as a filename
737 738 if out == 'not found':
738 739 try:
739 740 filename = get_py_filename(parameter_s)
740 741 except IOError,msg:
741 742 print msg
742 743 return
743 744 page(self.shell.inspector.format(file(filename).read()))
744 745
745 746 def magic_pinfo(self, parameter_s='', namespaces=None):
746 747 """Provide detailed information about an object.
747 748
748 749 '%pinfo object' is just a synonym for object? or ?object."""
749 750
750 751 #print 'pinfo par: <%s>' % parameter_s # dbg
751 752
752 753 # detail_level: 0 -> obj? , 1 -> obj??
753 754 detail_level = 0
754 755 # We need to detect if we got called as 'pinfo pinfo foo', which can
755 756 # happen if the user types 'pinfo foo?' at the cmd line.
756 757 pinfo,qmark1,oname,qmark2 = \
757 758 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
758 759 if pinfo or qmark1 or qmark2:
759 760 detail_level = 1
760 761 if "*" in oname:
761 762 self.magic_psearch(oname)
762 763 else:
763 764 self._inspect('pinfo', oname, detail_level=detail_level,
764 765 namespaces=namespaces)
765 766
766 767 def magic_psearch(self, parameter_s=''):
767 768 """Search for object in namespaces by wildcard.
768 769
769 770 %psearch [options] PATTERN [OBJECT TYPE]
770 771
771 772 Note: ? can be used as a synonym for %psearch, at the beginning or at
772 773 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
773 774 rest of the command line must be unchanged (options come first), so
774 775 for example the following forms are equivalent
775 776
776 777 %psearch -i a* function
777 778 -i a* function?
778 779 ?-i a* function
779 780
780 781 Arguments:
781 782
782 783 PATTERN
783 784
784 785 where PATTERN is a string containing * as a wildcard similar to its
785 786 use in a shell. The pattern is matched in all namespaces on the
786 787 search path. By default objects starting with a single _ are not
787 788 matched, many IPython generated objects have a single
788 789 underscore. The default is case insensitive matching. Matching is
789 790 also done on the attributes of objects and not only on the objects
790 791 in a module.
791 792
792 793 [OBJECT TYPE]
793 794
794 795 Is the name of a python type from the types module. The name is
795 796 given in lowercase without the ending type, ex. StringType is
796 797 written string. By adding a type here only objects matching the
797 798 given type are matched. Using all here makes the pattern match all
798 799 types (this is the default).
799 800
800 801 Options:
801 802
802 803 -a: makes the pattern match even objects whose names start with a
803 804 single underscore. These names are normally ommitted from the
804 805 search.
805 806
806 807 -i/-c: make the pattern case insensitive/sensitive. If neither of
807 808 these options is given, the default is read from your ipythonrc
808 809 file. The option name which sets this value is
809 810 'wildcards_case_sensitive'. If this option is not specified in your
810 811 ipythonrc file, IPython's internal default is to do a case sensitive
811 812 search.
812 813
813 814 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
814 815 specifiy can be searched in any of the following namespaces:
815 816 'builtin', 'user', 'user_global','internal', 'alias', where
816 817 'builtin' and 'user' are the search defaults. Note that you should
817 818 not use quotes when specifying namespaces.
818 819
819 820 'Builtin' contains the python module builtin, 'user' contains all
820 821 user data, 'alias' only contain the shell aliases and no python
821 822 objects, 'internal' contains objects used by IPython. The
822 823 'user_global' namespace is only used by embedded IPython instances,
823 824 and it contains module-level globals. You can add namespaces to the
824 825 search with -s or exclude them with -e (these options can be given
825 826 more than once).
826 827
827 828 Examples:
828 829
829 830 %psearch a* -> objects beginning with an a
830 831 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
831 832 %psearch a* function -> all functions beginning with an a
832 833 %psearch re.e* -> objects beginning with an e in module re
833 834 %psearch r*.e* -> objects that start with e in modules starting in r
834 835 %psearch r*.* string -> all strings in modules beginning with r
835 836
836 837 Case sensitve search:
837 838
838 839 %psearch -c a* list all object beginning with lower case a
839 840
840 841 Show objects beginning with a single _:
841 842
842 843 %psearch -a _* list objects beginning with a single underscore"""
843 844
844 845 # default namespaces to be searched
845 846 def_search = ['user','builtin']
846 847
847 848 # Process options/args
848 849 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
849 850 opt = opts.get
850 851 shell = self.shell
851 852 psearch = shell.inspector.psearch
852 853
853 854 # select case options
854 855 if opts.has_key('i'):
855 856 ignore_case = True
856 857 elif opts.has_key('c'):
857 858 ignore_case = False
858 859 else:
859 860 ignore_case = not shell.rc.wildcards_case_sensitive
860 861
861 862 # Build list of namespaces to search from user options
862 863 def_search.extend(opt('s',[]))
863 864 ns_exclude = ns_exclude=opt('e',[])
864 865 ns_search = [nm for nm in def_search if nm not in ns_exclude]
865 866
866 867 # Call the actual search
867 868 try:
868 869 psearch(args,shell.ns_table,ns_search,
869 870 show_all=opt('a'),ignore_case=ignore_case)
870 871 except:
871 872 shell.showtraceback()
872 873
873 874 def magic_who_ls(self, parameter_s=''):
874 875 """Return a sorted list of all interactive variables.
875 876
876 877 If arguments are given, only variables of types matching these
877 878 arguments are returned."""
878 879
879 880 user_ns = self.shell.user_ns
880 881 internal_ns = self.shell.internal_ns
881 882 user_config_ns = self.shell.user_config_ns
882 883 out = []
883 884 typelist = parameter_s.split()
884 885
885 886 for i in user_ns:
886 887 if not (i.startswith('_') or i.startswith('_i')) \
887 888 and not (i in internal_ns or i in user_config_ns):
888 889 if typelist:
889 890 if type(user_ns[i]).__name__ in typelist:
890 891 out.append(i)
891 892 else:
892 893 out.append(i)
893 894 out.sort()
894 895 return out
895 896
896 897 def magic_who(self, parameter_s=''):
897 898 """Print all interactive variables, with some minimal formatting.
898 899
899 900 If any arguments are given, only variables whose type matches one of
900 901 these are printed. For example:
901 902
902 903 %who function str
903 904
904 905 will only list functions and strings, excluding all other types of
905 906 variables. To find the proper type names, simply use type(var) at a
906 907 command line to see how python prints type names. For example:
907 908
908 909 In [1]: type('hello')\\
909 910 Out[1]: <type 'str'>
910 911
911 912 indicates that the type name for strings is 'str'.
912 913
913 914 %who always excludes executed names loaded through your configuration
914 915 file and things which are internal to IPython.
915 916
916 917 This is deliberate, as typically you may load many modules and the
917 918 purpose of %who is to show you only what you've manually defined."""
918 919
919 920 varlist = self.magic_who_ls(parameter_s)
920 921 if not varlist:
921 922 print 'Interactive namespace is empty.'
922 923 return
923 924
924 925 # if we have variables, move on...
925 926
926 927 # stupid flushing problem: when prompts have no separators, stdout is
927 928 # getting lost. I'm starting to think this is a python bug. I'm having
928 929 # to force a flush with a print because even a sys.stdout.flush
929 930 # doesn't seem to do anything!
930 931
931 932 count = 0
932 933 for i in varlist:
933 934 print i+'\t',
934 935 count += 1
935 936 if count > 8:
936 937 count = 0
937 938 print
938 939 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
939 940
940 941 print # well, this does force a flush at the expense of an extra \n
941 942
942 943 def magic_whos(self, parameter_s=''):
943 944 """Like %who, but gives some extra information about each variable.
944 945
945 946 The same type filtering of %who can be applied here.
946 947
947 948 For all variables, the type is printed. Additionally it prints:
948 949
949 950 - For {},[],(): their length.
950 951
951 952 - For Numeric arrays, a summary with shape, number of elements,
952 953 typecode and size in memory.
953 954
954 955 - Everything else: a string representation, snipping their middle if
955 956 too long."""
956 957
957 958 varnames = self.magic_who_ls(parameter_s)
958 959 if not varnames:
959 960 print 'Interactive namespace is empty.'
960 961 return
961 962
962 963 # if we have variables, move on...
963 964
964 965 # for these types, show len() instead of data:
965 966 seq_types = [types.DictType,types.ListType,types.TupleType]
966 967
967 968 # for Numeric arrays, display summary info
968 969 try:
969 970 import Numeric
970 971 except ImportError:
971 972 array_type = None
972 973 else:
973 974 array_type = Numeric.ArrayType.__name__
974 975
975 976 # Find all variable names and types so we can figure out column sizes
976 977
977 978 def get_vars(i):
978 979 return self.shell.user_ns[i]
979 980
980 981 # some types are well known and can be shorter
981 982 abbrevs = {'IPython.macro.Macro' : 'Macro'}
982 983 def type_name(v):
983 984 tn = type(v).__name__
984 985 return abbrevs.get(tn,tn)
985 986
986 987 varlist = map(get_vars,varnames)
987 988
988 989 typelist = []
989 990 for vv in varlist:
990 991 tt = type_name(vv)
991 992
992 993 if tt=='instance':
993 994 typelist.append( abbrevs.get(str(vv.__class__),str(vv.__class__)))
994 995 else:
995 996 typelist.append(tt)
996 997
997 998 # column labels and # of spaces as separator
998 999 varlabel = 'Variable'
999 1000 typelabel = 'Type'
1000 1001 datalabel = 'Data/Info'
1001 1002 colsep = 3
1002 1003 # variable format strings
1003 1004 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
1004 1005 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
1005 1006 aformat = "%s: %s elems, type `%s`, %s bytes"
1006 1007 # find the size of the columns to format the output nicely
1007 1008 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
1008 1009 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
1009 1010 # table header
1010 1011 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
1011 1012 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
1012 1013 # and the table itself
1013 1014 kb = 1024
1014 1015 Mb = 1048576 # kb**2
1015 1016 for vname,var,vtype in zip(varnames,varlist,typelist):
1016 1017 print itpl(vformat),
1017 1018 if vtype in seq_types:
1018 1019 print len(var)
1019 1020 elif vtype==array_type:
1020 1021 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
1021 1022 vsize = Numeric.size(var)
1022 1023 vbytes = vsize*var.itemsize()
1023 1024 if vbytes < 100000:
1024 1025 print aformat % (vshape,vsize,var.typecode(),vbytes)
1025 1026 else:
1026 1027 print aformat % (vshape,vsize,var.typecode(),vbytes),
1027 1028 if vbytes < Mb:
1028 1029 print '(%s kb)' % (vbytes/kb,)
1029 1030 else:
1030 1031 print '(%s Mb)' % (vbytes/Mb,)
1031 1032 else:
1032 1033 vstr = str(var).replace('\n','\\n')
1033 1034 if len(vstr) < 50:
1034 1035 print vstr
1035 1036 else:
1036 1037 printpl(vfmt_short)
1037 1038
1038 1039 def magic_reset(self, parameter_s=''):
1039 1040 """Resets the namespace by removing all names defined by the user.
1040 1041
1041 1042 Input/Output history are left around in case you need them."""
1042 1043
1043 1044 ans = self.shell.ask_yes_no(
1044 1045 "Once deleted, variables cannot be recovered. Proceed (y/[n])? ")
1045 1046 if not ans:
1046 1047 print 'Nothing done.'
1047 1048 return
1048 1049 user_ns = self.shell.user_ns
1049 1050 for i in self.magic_who_ls():
1050 1051 del(user_ns[i])
1051 1052
1052 1053 def magic_logstart(self,parameter_s=''):
1053 1054 """Start logging anywhere in a session.
1054 1055
1055 1056 %logstart [-o|-r|-t] [log_name [log_mode]]
1056 1057
1057 1058 If no name is given, it defaults to a file named 'ipython_log.py' in your
1058 1059 current directory, in 'rotate' mode (see below).
1059 1060
1060 1061 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
1061 1062 history up to that point and then continues logging.
1062 1063
1063 1064 %logstart takes a second optional parameter: logging mode. This can be one
1064 1065 of (note that the modes are given unquoted):\\
1065 1066 append: well, that says it.\\
1066 1067 backup: rename (if exists) to name~ and start name.\\
1067 1068 global: single logfile in your home dir, appended to.\\
1068 1069 over : overwrite existing log.\\
1069 1070 rotate: create rotating logs name.1~, name.2~, etc.
1070 1071
1071 1072 Options:
1072 1073
1073 1074 -o: log also IPython's output. In this mode, all commands which
1074 1075 generate an Out[NN] prompt are recorded to the logfile, right after
1075 1076 their corresponding input line. The output lines are always
1076 1077 prepended with a '#[Out]# ' marker, so that the log remains valid
1077 1078 Python code.
1078 1079
1079 1080 Since this marker is always the same, filtering only the output from
1080 1081 a log is very easy, using for example a simple awk call:
1081 1082
1082 1083 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
1083 1084
1084 1085 -r: log 'raw' input. Normally, IPython's logs contain the processed
1085 1086 input, so that user lines are logged in their final form, converted
1086 1087 into valid Python. For example, %Exit is logged as
1087 1088 '_ip.magic("Exit"). If the -r flag is given, all input is logged
1088 1089 exactly as typed, with no transformations applied.
1089 1090
1090 1091 -t: put timestamps before each input line logged (these are put in
1091 1092 comments)."""
1092 1093
1093 1094 opts,par = self.parse_options(parameter_s,'ort')
1094 1095 log_output = 'o' in opts
1095 1096 log_raw_input = 'r' in opts
1096 1097 timestamp = 't' in opts
1097 1098
1098 1099 rc = self.shell.rc
1099 1100 logger = self.shell.logger
1100 1101
1101 1102 # if no args are given, the defaults set in the logger constructor by
1102 1103 # ipytohn remain valid
1103 1104 if par:
1104 1105 try:
1105 1106 logfname,logmode = par.split()
1106 1107 except:
1107 1108 logfname = par
1108 1109 logmode = 'backup'
1109 1110 else:
1110 1111 logfname = logger.logfname
1111 1112 logmode = logger.logmode
1112 1113 # put logfname into rc struct as if it had been called on the command
1113 1114 # line, so it ends up saved in the log header Save it in case we need
1114 1115 # to restore it...
1115 1116 old_logfile = rc.opts.get('logfile','')
1116 1117 if logfname:
1117 1118 logfname = os.path.expanduser(logfname)
1118 1119 rc.opts.logfile = logfname
1119 1120 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
1120 1121 try:
1121 1122 started = logger.logstart(logfname,loghead,logmode,
1122 1123 log_output,timestamp,log_raw_input)
1123 1124 except:
1124 1125 rc.opts.logfile = old_logfile
1125 1126 warn("Couldn't start log: %s" % sys.exc_info()[1])
1126 1127 else:
1127 1128 # log input history up to this point, optionally interleaving
1128 1129 # output if requested
1129 1130
1130 1131 if timestamp:
1131 1132 # disable timestamping for the previous history, since we've
1132 1133 # lost those already (no time machine here).
1133 1134 logger.timestamp = False
1134 1135
1135 1136 if log_raw_input:
1136 1137 input_hist = self.shell.input_hist_raw
1137 1138 else:
1138 1139 input_hist = self.shell.input_hist
1139 1140
1140 1141 if log_output:
1141 1142 log_write = logger.log_write
1142 1143 output_hist = self.shell.output_hist
1143 1144 for n in range(1,len(input_hist)-1):
1144 1145 log_write(input_hist[n].rstrip())
1145 1146 if n in output_hist:
1146 1147 log_write(repr(output_hist[n]),'output')
1147 1148 else:
1148 1149 logger.log_write(input_hist[1:])
1149 1150 if timestamp:
1150 1151 # re-enable timestamping
1151 1152 logger.timestamp = True
1152 1153
1153 1154 print ('Activating auto-logging. '
1154 1155 'Current session state plus future input saved.')
1155 1156 logger.logstate()
1156 1157
1157 1158 def magic_logoff(self,parameter_s=''):
1158 1159 """Temporarily stop logging.
1159 1160
1160 1161 You must have previously started logging."""
1161 1162 self.shell.logger.switch_log(0)
1162 1163
1163 1164 def magic_logon(self,parameter_s=''):
1164 1165 """Restart logging.
1165 1166
1166 1167 This function is for restarting logging which you've temporarily
1167 1168 stopped with %logoff. For starting logging for the first time, you
1168 1169 must use the %logstart function, which allows you to specify an
1169 1170 optional log filename."""
1170 1171
1171 1172 self.shell.logger.switch_log(1)
1172 1173
1173 1174 def magic_logstate(self,parameter_s=''):
1174 1175 """Print the status of the logging system."""
1175 1176
1176 1177 self.shell.logger.logstate()
1177 1178
1178 1179 def magic_pdb(self, parameter_s=''):
1179 1180 """Control the automatic calling of the pdb interactive debugger.
1180 1181
1181 1182 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1182 1183 argument it works as a toggle.
1183 1184
1184 1185 When an exception is triggered, IPython can optionally call the
1185 1186 interactive pdb debugger after the traceback printout. %pdb toggles
1186 1187 this feature on and off.
1187 1188
1188 1189 The initial state of this feature is set in your ipythonrc
1189 1190 configuration file (the variable is called 'pdb').
1190 1191
1191 1192 If you want to just activate the debugger AFTER an exception has fired,
1192 1193 without having to type '%pdb on' and rerunning your code, you can use
1193 1194 the %debug magic."""
1194 1195
1195 1196 par = parameter_s.strip().lower()
1196 1197
1197 1198 if par:
1198 1199 try:
1199 1200 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1200 1201 except KeyError:
1201 1202 print ('Incorrect argument. Use on/1, off/0, '
1202 1203 'or nothing for a toggle.')
1203 1204 return
1204 1205 else:
1205 1206 # toggle
1206 1207 new_pdb = not self.shell.call_pdb
1207 1208
1208 1209 # set on the shell
1209 1210 self.shell.call_pdb = new_pdb
1210 1211 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1211 1212
1212 1213 def magic_debug(self, parameter_s=''):
1213 1214 """Activate the interactive debugger in post-mortem mode.
1214 1215
1215 1216 If an exception has just occurred, this lets you inspect its stack
1216 1217 frames interactively. Note that this will always work only on the last
1217 1218 traceback that occurred, so you must call this quickly after an
1218 1219 exception that you wish to inspect has fired, because if another one
1219 1220 occurs, it clobbers the previous one.
1220 1221
1221 1222 If you want IPython to automatically do this on every exception, see
1222 1223 the %pdb magic for more details.
1223 1224 """
1224 1225
1225 1226 self.shell.debugger(force=True)
1226 1227
1227 1228 def magic_prun(self, parameter_s ='',user_mode=1,
1228 1229 opts=None,arg_lst=None,prog_ns=None):
1229 1230
1230 1231 """Run a statement through the python code profiler.
1231 1232
1232 1233 Usage:\\
1233 1234 %prun [options] statement
1234 1235
1235 1236 The given statement (which doesn't require quote marks) is run via the
1236 1237 python profiler in a manner similar to the profile.run() function.
1237 1238 Namespaces are internally managed to work correctly; profile.run
1238 1239 cannot be used in IPython because it makes certain assumptions about
1239 1240 namespaces which do not hold under IPython.
1240 1241
1241 1242 Options:
1242 1243
1243 1244 -l <limit>: you can place restrictions on what or how much of the
1244 1245 profile gets printed. The limit value can be:
1245 1246
1246 1247 * A string: only information for function names containing this string
1247 1248 is printed.
1248 1249
1249 1250 * An integer: only these many lines are printed.
1250 1251
1251 1252 * A float (between 0 and 1): this fraction of the report is printed
1252 1253 (for example, use a limit of 0.4 to see the topmost 40% only).
1253 1254
1254 1255 You can combine several limits with repeated use of the option. For
1255 1256 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1256 1257 information about class constructors.
1257 1258
1258 1259 -r: return the pstats.Stats object generated by the profiling. This
1259 1260 object has all the information about the profile in it, and you can
1260 1261 later use it for further analysis or in other functions.
1261 1262
1262 1263 -s <key>: sort profile by given key. You can provide more than one key
1263 1264 by using the option several times: '-s key1 -s key2 -s key3...'. The
1264 1265 default sorting key is 'time'.
1265 1266
1266 1267 The following is copied verbatim from the profile documentation
1267 1268 referenced below:
1268 1269
1269 1270 When more than one key is provided, additional keys are used as
1270 1271 secondary criteria when the there is equality in all keys selected
1271 1272 before them.
1272 1273
1273 1274 Abbreviations can be used for any key names, as long as the
1274 1275 abbreviation is unambiguous. The following are the keys currently
1275 1276 defined:
1276 1277
1277 1278 Valid Arg Meaning\\
1278 1279 "calls" call count\\
1279 1280 "cumulative" cumulative time\\
1280 1281 "file" file name\\
1281 1282 "module" file name\\
1282 1283 "pcalls" primitive call count\\
1283 1284 "line" line number\\
1284 1285 "name" function name\\
1285 1286 "nfl" name/file/line\\
1286 1287 "stdname" standard name\\
1287 1288 "time" internal time
1288 1289
1289 1290 Note that all sorts on statistics are in descending order (placing
1290 1291 most time consuming items first), where as name, file, and line number
1291 1292 searches are in ascending order (i.e., alphabetical). The subtle
1292 1293 distinction between "nfl" and "stdname" is that the standard name is a
1293 1294 sort of the name as printed, which means that the embedded line
1294 1295 numbers get compared in an odd way. For example, lines 3, 20, and 40
1295 1296 would (if the file names were the same) appear in the string order
1296 1297 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1297 1298 line numbers. In fact, sort_stats("nfl") is the same as
1298 1299 sort_stats("name", "file", "line").
1299 1300
1300 1301 -T <filename>: save profile results as shown on screen to a text
1301 1302 file. The profile is still shown on screen.
1302 1303
1303 1304 -D <filename>: save (via dump_stats) profile statistics to given
1304 1305 filename. This data is in a format understod by the pstats module, and
1305 1306 is generated by a call to the dump_stats() method of profile
1306 1307 objects. The profile is still shown on screen.
1307 1308
1308 1309 If you want to run complete programs under the profiler's control, use
1309 1310 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1310 1311 contains profiler specific options as described here.
1311 1312
1312 1313 You can read the complete documentation for the profile module with:\\
1313 1314 In [1]: import profile; profile.help() """
1314 1315
1315 1316 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1316 1317 # protect user quote marks
1317 1318 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1318 1319
1319 1320 if user_mode: # regular user call
1320 1321 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1321 1322 list_all=1)
1322 1323 namespace = self.shell.user_ns
1323 1324 else: # called to run a program by %run -p
1324 1325 try:
1325 1326 filename = get_py_filename(arg_lst[0])
1326 1327 except IOError,msg:
1327 1328 error(msg)
1328 1329 return
1329 1330
1330 1331 arg_str = 'execfile(filename,prog_ns)'
1331 1332 namespace = locals()
1332 1333
1333 1334 opts.merge(opts_def)
1334 1335
1335 1336 prof = profile.Profile()
1336 1337 try:
1337 1338 prof = prof.runctx(arg_str,namespace,namespace)
1338 1339 sys_exit = ''
1339 1340 except SystemExit:
1340 1341 sys_exit = """*** SystemExit exception caught in code being profiled."""
1341 1342
1342 1343 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1343 1344
1344 1345 lims = opts.l
1345 1346 if lims:
1346 1347 lims = [] # rebuild lims with ints/floats/strings
1347 1348 for lim in opts.l:
1348 1349 try:
1349 1350 lims.append(int(lim))
1350 1351 except ValueError:
1351 1352 try:
1352 1353 lims.append(float(lim))
1353 1354 except ValueError:
1354 1355 lims.append(lim)
1355 1356
1356 1357 # trap output
1357 1358 sys_stdout = sys.stdout
1358 1359 stdout_trap = StringIO()
1359 1360 try:
1360 1361 sys.stdout = stdout_trap
1361 1362 stats.print_stats(*lims)
1362 1363 finally:
1363 1364 sys.stdout = sys_stdout
1364 1365 output = stdout_trap.getvalue()
1365 1366 output = output.rstrip()
1366 1367
1367 1368 page(output,screen_lines=self.shell.rc.screen_length)
1368 1369 print sys_exit,
1369 1370
1370 1371 dump_file = opts.D[0]
1371 1372 text_file = opts.T[0]
1372 1373 if dump_file:
1373 1374 prof.dump_stats(dump_file)
1374 1375 print '\n*** Profile stats marshalled to file',\
1375 1376 `dump_file`+'.',sys_exit
1376 1377 if text_file:
1377 1378 file(text_file,'w').write(output)
1378 1379 print '\n*** Profile printout saved to text file',\
1379 1380 `text_file`+'.',sys_exit
1380 1381
1381 1382 if opts.has_key('r'):
1382 1383 return stats
1383 1384 else:
1384 1385 return None
1385 1386
1386 1387 def magic_run(self, parameter_s ='',runner=None):
1387 1388 """Run the named file inside IPython as a program.
1388 1389
1389 1390 Usage:\\
1390 1391 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1391 1392
1392 1393 Parameters after the filename are passed as command-line arguments to
1393 1394 the program (put in sys.argv). Then, control returns to IPython's
1394 1395 prompt.
1395 1396
1396 1397 This is similar to running at a system prompt:\\
1397 1398 $ python file args\\
1398 1399 but with the advantage of giving you IPython's tracebacks, and of
1399 1400 loading all variables into your interactive namespace for further use
1400 1401 (unless -p is used, see below).
1401 1402
1402 1403 The file is executed in a namespace initially consisting only of
1403 1404 __name__=='__main__' and sys.argv constructed as indicated. It thus
1404 1405 sees its environment as if it were being run as a stand-alone
1405 1406 program. But after execution, the IPython interactive namespace gets
1406 1407 updated with all variables defined in the program (except for __name__
1407 1408 and sys.argv). This allows for very convenient loading of code for
1408 1409 interactive work, while giving each program a 'clean sheet' to run in.
1409 1410
1410 1411 Options:
1411 1412
1412 1413 -n: __name__ is NOT set to '__main__', but to the running file's name
1413 1414 without extension (as python does under import). This allows running
1414 1415 scripts and reloading the definitions in them without calling code
1415 1416 protected by an ' if __name__ == "__main__" ' clause.
1416 1417
1417 1418 -i: run the file in IPython's namespace instead of an empty one. This
1418 1419 is useful if you are experimenting with code written in a text editor
1419 1420 which depends on variables defined interactively.
1420 1421
1421 1422 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1422 1423 being run. This is particularly useful if IPython is being used to
1423 1424 run unittests, which always exit with a sys.exit() call. In such
1424 1425 cases you are interested in the output of the test results, not in
1425 1426 seeing a traceback of the unittest module.
1426 1427
1427 1428 -t: print timing information at the end of the run. IPython will give
1428 1429 you an estimated CPU time consumption for your script, which under
1429 1430 Unix uses the resource module to avoid the wraparound problems of
1430 1431 time.clock(). Under Unix, an estimate of time spent on system tasks
1431 1432 is also given (for Windows platforms this is reported as 0.0).
1432 1433
1433 1434 If -t is given, an additional -N<N> option can be given, where <N>
1434 1435 must be an integer indicating how many times you want the script to
1435 1436 run. The final timing report will include total and per run results.
1436 1437
1437 1438 For example (testing the script uniq_stable.py):
1438 1439
1439 1440 In [1]: run -t uniq_stable
1440 1441
1441 1442 IPython CPU timings (estimated):\\
1442 1443 User : 0.19597 s.\\
1443 1444 System: 0.0 s.\\
1444 1445
1445 1446 In [2]: run -t -N5 uniq_stable
1446 1447
1447 1448 IPython CPU timings (estimated):\\
1448 1449 Total runs performed: 5\\
1449 1450 Times : Total Per run\\
1450 1451 User : 0.910862 s, 0.1821724 s.\\
1451 1452 System: 0.0 s, 0.0 s.
1452 1453
1453 1454 -d: run your program under the control of pdb, the Python debugger.
1454 1455 This allows you to execute your program step by step, watch variables,
1455 1456 etc. Internally, what IPython does is similar to calling:
1456 1457
1457 1458 pdb.run('execfile("YOURFILENAME")')
1458 1459
1459 1460 with a breakpoint set on line 1 of your file. You can change the line
1460 1461 number for this automatic breakpoint to be <N> by using the -bN option
1461 1462 (where N must be an integer). For example:
1462 1463
1463 1464 %run -d -b40 myscript
1464 1465
1465 1466 will set the first breakpoint at line 40 in myscript.py. Note that
1466 1467 the first breakpoint must be set on a line which actually does
1467 1468 something (not a comment or docstring) for it to stop execution.
1468 1469
1469 1470 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1470 1471 first enter 'c' (without qoutes) to start execution up to the first
1471 1472 breakpoint.
1472 1473
1473 1474 Entering 'help' gives information about the use of the debugger. You
1474 1475 can easily see pdb's full documentation with "import pdb;pdb.help()"
1475 1476 at a prompt.
1476 1477
1477 1478 -p: run program under the control of the Python profiler module (which
1478 1479 prints a detailed report of execution times, function calls, etc).
1479 1480
1480 1481 You can pass other options after -p which affect the behavior of the
1481 1482 profiler itself. See the docs for %prun for details.
1482 1483
1483 1484 In this mode, the program's variables do NOT propagate back to the
1484 1485 IPython interactive namespace (because they remain in the namespace
1485 1486 where the profiler executes them).
1486 1487
1487 1488 Internally this triggers a call to %prun, see its documentation for
1488 1489 details on the options available specifically for profiling.
1489 1490
1490 1491 There is one special usage for which the text above doesn't apply:
1491 1492 if the filename ends with .ipy, the file is run as ipython script,
1492 1493 just as if the commands were written on IPython prompt.
1493 1494 """
1494 1495
1495 1496 # get arguments and set sys.argv for program to be run.
1496 1497 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1497 1498 mode='list',list_all=1)
1498 1499
1499 1500 try:
1500 1501 filename = get_py_filename(arg_lst[0])
1501 1502 except IndexError:
1502 1503 warn('you must provide at least a filename.')
1503 1504 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1504 1505 return
1505 1506 except IOError,msg:
1506 1507 error(msg)
1507 1508 return
1508 1509
1509 1510 if filename.lower().endswith('.ipy'):
1510 1511 self.api.runlines(open(filename).read())
1511 1512 return
1512 1513
1513 1514 # Control the response to exit() calls made by the script being run
1514 1515 exit_ignore = opts.has_key('e')
1515 1516
1516 1517 # Make sure that the running script gets a proper sys.argv as if it
1517 1518 # were run from a system shell.
1518 1519 save_argv = sys.argv # save it for later restoring
1519 1520 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1520 1521
1521 1522 if opts.has_key('i'):
1522 1523 prog_ns = self.shell.user_ns
1523 1524 __name__save = self.shell.user_ns['__name__']
1524 1525 prog_ns['__name__'] = '__main__'
1525 1526 else:
1526 1527 if opts.has_key('n'):
1527 1528 name = os.path.splitext(os.path.basename(filename))[0]
1528 1529 else:
1529 1530 name = '__main__'
1530 1531 prog_ns = {'__name__':name}
1531 1532
1532 1533 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1533 1534 # set the __file__ global in the script's namespace
1534 1535 prog_ns['__file__'] = filename
1535 1536
1536 1537 # pickle fix. See iplib for an explanation. But we need to make sure
1537 1538 # that, if we overwrite __main__, we replace it at the end
1538 1539 if prog_ns['__name__'] == '__main__':
1539 1540 restore_main = sys.modules['__main__']
1540 1541 else:
1541 1542 restore_main = False
1542 1543
1543 1544 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1544 1545
1545 1546 stats = None
1546 1547 try:
1547 1548 if self.shell.has_readline:
1548 1549 self.shell.savehist()
1549 1550
1550 1551 if opts.has_key('p'):
1551 1552 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1552 1553 else:
1553 1554 if opts.has_key('d'):
1554 1555 deb = Debugger.Pdb(self.shell.rc.colors)
1555 1556 # reset Breakpoint state, which is moronically kept
1556 1557 # in a class
1557 1558 bdb.Breakpoint.next = 1
1558 1559 bdb.Breakpoint.bplist = {}
1559 1560 bdb.Breakpoint.bpbynumber = [None]
1560 1561 # Set an initial breakpoint to stop execution
1561 1562 maxtries = 10
1562 1563 bp = int(opts.get('b',[1])[0])
1563 1564 checkline = deb.checkline(filename,bp)
1564 1565 if not checkline:
1565 1566 for bp in range(bp+1,bp+maxtries+1):
1566 1567 if deb.checkline(filename,bp):
1567 1568 break
1568 1569 else:
1569 1570 msg = ("\nI failed to find a valid line to set "
1570 1571 "a breakpoint\n"
1571 1572 "after trying up to line: %s.\n"
1572 1573 "Please set a valid breakpoint manually "
1573 1574 "with the -b option." % bp)
1574 1575 error(msg)
1575 1576 return
1576 1577 # if we find a good linenumber, set the breakpoint
1577 1578 deb.do_break('%s:%s' % (filename,bp))
1578 1579 # Start file run
1579 1580 print "NOTE: Enter 'c' at the",
1580 1581 print "%s prompt to start your script." % deb.prompt
1581 1582 try:
1582 1583 deb.run('execfile("%s")' % filename,prog_ns)
1583 1584
1584 1585 except:
1585 1586 etype, value, tb = sys.exc_info()
1586 1587 # Skip three frames in the traceback: the %run one,
1587 1588 # one inside bdb.py, and the command-line typed by the
1588 1589 # user (run by exec in pdb itself).
1589 1590 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1590 1591 else:
1591 1592 if runner is None:
1592 1593 runner = self.shell.safe_execfile
1593 1594 if opts.has_key('t'):
1594 1595 try:
1595 1596 nruns = int(opts['N'][0])
1596 1597 if nruns < 1:
1597 1598 error('Number of runs must be >=1')
1598 1599 return
1599 1600 except (KeyError):
1600 1601 nruns = 1
1601 1602 if nruns == 1:
1602 1603 t0 = clock2()
1603 1604 runner(filename,prog_ns,prog_ns,
1604 1605 exit_ignore=exit_ignore)
1605 1606 t1 = clock2()
1606 1607 t_usr = t1[0]-t0[0]
1607 1608 t_sys = t1[1]-t1[1]
1608 1609 print "\nIPython CPU timings (estimated):"
1609 1610 print " User : %10s s." % t_usr
1610 1611 print " System: %10s s." % t_sys
1611 1612 else:
1612 1613 runs = range(nruns)
1613 1614 t0 = clock2()
1614 1615 for nr in runs:
1615 1616 runner(filename,prog_ns,prog_ns,
1616 1617 exit_ignore=exit_ignore)
1617 1618 t1 = clock2()
1618 1619 t_usr = t1[0]-t0[0]
1619 1620 t_sys = t1[1]-t1[1]
1620 1621 print "\nIPython CPU timings (estimated):"
1621 1622 print "Total runs performed:",nruns
1622 1623 print " Times : %10s %10s" % ('Total','Per run')
1623 1624 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1624 1625 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1625 1626
1626 1627 else:
1627 1628 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1628 1629 if opts.has_key('i'):
1629 1630 self.shell.user_ns['__name__'] = __name__save
1630 1631 else:
1631 1632 # update IPython interactive namespace
1632 1633 del prog_ns['__name__']
1633 1634 self.shell.user_ns.update(prog_ns)
1634 1635 finally:
1635 1636 sys.argv = save_argv
1636 1637 if restore_main:
1637 1638 sys.modules['__main__'] = restore_main
1638 1639 if self.shell.has_readline:
1639 1640 self.shell.readline.read_history_file(self.shell.histfile)
1640 1641
1641 1642 return stats
1642 1643
1643 1644 def magic_runlog(self, parameter_s =''):
1644 1645 """Run files as logs.
1645 1646
1646 1647 Usage:\\
1647 1648 %runlog file1 file2 ...
1648 1649
1649 1650 Run the named files (treating them as log files) in sequence inside
1650 1651 the interpreter, and return to the prompt. This is much slower than
1651 1652 %run because each line is executed in a try/except block, but it
1652 1653 allows running files with syntax errors in them.
1653 1654
1654 1655 Normally IPython will guess when a file is one of its own logfiles, so
1655 1656 you can typically use %run even for logs. This shorthand allows you to
1656 1657 force any file to be treated as a log file."""
1657 1658
1658 1659 for f in parameter_s.split():
1659 1660 self.shell.safe_execfile(f,self.shell.user_ns,
1660 1661 self.shell.user_ns,islog=1)
1661 1662
1662 1663 def magic_timeit(self, parameter_s =''):
1663 1664 """Time execution of a Python statement or expression
1664 1665
1665 1666 Usage:\\
1666 1667 %timeit [-n<N> -r<R> [-t|-c]] statement
1667 1668
1668 1669 Time execution of a Python statement or expression using the timeit
1669 1670 module.
1670 1671
1671 1672 Options:
1672 1673 -n<N>: execute the given statement <N> times in a loop. If this value
1673 1674 is not given, a fitting value is chosen.
1674 1675
1675 1676 -r<R>: repeat the loop iteration <R> times and take the best result.
1676 1677 Default: 3
1677 1678
1678 1679 -t: use time.time to measure the time, which is the default on Unix.
1679 1680 This function measures wall time.
1680 1681
1681 1682 -c: use time.clock to measure the time, which is the default on
1682 1683 Windows and measures wall time. On Unix, resource.getrusage is used
1683 1684 instead and returns the CPU user time.
1684 1685
1685 1686 -p<P>: use a precision of <P> digits to display the timing result.
1686 1687 Default: 3
1687 1688
1688 1689
1689 1690 Examples:\\
1690 1691 In [1]: %timeit pass
1691 1692 10000000 loops, best of 3: 53.3 ns per loop
1692 1693
1693 1694 In [2]: u = None
1694 1695
1695 1696 In [3]: %timeit u is None
1696 1697 10000000 loops, best of 3: 184 ns per loop
1697 1698
1698 1699 In [4]: %timeit -r 4 u == None
1699 1700 1000000 loops, best of 4: 242 ns per loop
1700 1701
1701 1702 In [5]: import time
1702 1703
1703 1704 In [6]: %timeit -n1 time.sleep(2)
1704 1705 1 loops, best of 3: 2 s per loop
1705 1706
1706 1707
1707 1708 The times reported by %timeit will be slightly higher than those
1708 1709 reported by the timeit.py script when variables are accessed. This is
1709 1710 due to the fact that %timeit executes the statement in the namespace
1710 1711 of the shell, compared with timeit.py, which uses a single setup
1711 1712 statement to import function or create variables. Generally, the bias
1712 1713 does not matter as long as results from timeit.py are not mixed with
1713 1714 those from %timeit."""
1714 1715
1715 1716 import timeit
1716 1717 import math
1717 1718
1718 1719 units = ["s", "ms", "\xc2\xb5s", "ns"]
1719 1720 scaling = [1, 1e3, 1e6, 1e9]
1720 1721
1721 1722 opts, stmt = self.parse_options(parameter_s,'n:r:tcp:',
1722 1723 posix=False)
1723 1724 if stmt == "":
1724 1725 return
1725 1726 timefunc = timeit.default_timer
1726 1727 number = int(getattr(opts, "n", 0))
1727 1728 repeat = int(getattr(opts, "r", timeit.default_repeat))
1728 1729 precision = int(getattr(opts, "p", 3))
1729 1730 if hasattr(opts, "t"):
1730 1731 timefunc = time.time
1731 1732 if hasattr(opts, "c"):
1732 1733 timefunc = clock
1733 1734
1734 1735 timer = timeit.Timer(timer=timefunc)
1735 1736 # this code has tight coupling to the inner workings of timeit.Timer,
1736 1737 # but is there a better way to achieve that the code stmt has access
1737 1738 # to the shell namespace?
1738 1739
1739 1740 src = timeit.template % {'stmt': timeit.reindent(stmt, 8),
1740 1741 'setup': "pass"}
1741 1742 code = compile(src, "<magic-timeit>", "exec")
1742 1743 ns = {}
1743 1744 exec code in self.shell.user_ns, ns
1744 1745 timer.inner = ns["inner"]
1745 1746
1746 1747 if number == 0:
1747 1748 # determine number so that 0.2 <= total time < 2.0
1748 1749 number = 1
1749 1750 for i in range(1, 10):
1750 1751 number *= 10
1751 1752 if timer.timeit(number) >= 0.2:
1752 1753 break
1753 1754
1754 1755 best = min(timer.repeat(repeat, number)) / number
1755 1756
1756 1757 if best > 0.0:
1757 1758 order = min(-int(math.floor(math.log10(best)) // 3), 3)
1758 1759 else:
1759 1760 order = 3
1760 1761 print "%d loops, best of %d: %.*g %s per loop" % (number, repeat,
1761 1762 precision,
1762 1763 best * scaling[order],
1763 1764 units[order])
1764 1765
1765 1766 def magic_time(self,parameter_s = ''):
1766 1767 """Time execution of a Python statement or expression.
1767 1768
1768 1769 The CPU and wall clock times are printed, and the value of the
1769 1770 expression (if any) is returned. Note that under Win32, system time
1770 1771 is always reported as 0, since it can not be measured.
1771 1772
1772 1773 This function provides very basic timing functionality. In Python
1773 1774 2.3, the timeit module offers more control and sophistication, so this
1774 1775 could be rewritten to use it (patches welcome).
1775 1776
1776 1777 Some examples:
1777 1778
1778 1779 In [1]: time 2**128
1779 1780 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1780 1781 Wall time: 0.00
1781 1782 Out[1]: 340282366920938463463374607431768211456L
1782 1783
1783 1784 In [2]: n = 1000000
1784 1785
1785 1786 In [3]: time sum(range(n))
1786 1787 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1787 1788 Wall time: 1.37
1788 1789 Out[3]: 499999500000L
1789 1790
1790 1791 In [4]: time print 'hello world'
1791 1792 hello world
1792 1793 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1793 1794 Wall time: 0.00
1794 1795 """
1795 1796
1796 1797 # fail immediately if the given expression can't be compiled
1797 1798 try:
1798 1799 mode = 'eval'
1799 1800 code = compile(parameter_s,'<timed eval>',mode)
1800 1801 except SyntaxError:
1801 1802 mode = 'exec'
1802 1803 code = compile(parameter_s,'<timed exec>',mode)
1803 1804 # skew measurement as little as possible
1804 1805 glob = self.shell.user_ns
1805 1806 clk = clock2
1806 1807 wtime = time.time
1807 1808 # time execution
1808 1809 wall_st = wtime()
1809 1810 if mode=='eval':
1810 1811 st = clk()
1811 1812 out = eval(code,glob)
1812 1813 end = clk()
1813 1814 else:
1814 1815 st = clk()
1815 1816 exec code in glob
1816 1817 end = clk()
1817 1818 out = None
1818 1819 wall_end = wtime()
1819 1820 # Compute actual times and report
1820 1821 wall_time = wall_end-wall_st
1821 1822 cpu_user = end[0]-st[0]
1822 1823 cpu_sys = end[1]-st[1]
1823 1824 cpu_tot = cpu_user+cpu_sys
1824 1825 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1825 1826 (cpu_user,cpu_sys,cpu_tot)
1826 1827 print "Wall time: %.2f" % wall_time
1827 1828 return out
1828 1829
1829 1830 def magic_macro(self,parameter_s = ''):
1830 1831 """Define a set of input lines as a macro for future re-execution.
1831 1832
1832 1833 Usage:\\
1833 1834 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
1834 1835
1835 1836 Options:
1836 1837
1837 1838 -r: use 'raw' input. By default, the 'processed' history is used,
1838 1839 so that magics are loaded in their transformed version to valid
1839 1840 Python. If this option is given, the raw input as typed as the
1840 1841 command line is used instead.
1841 1842
1842 1843 This will define a global variable called `name` which is a string
1843 1844 made of joining the slices and lines you specify (n1,n2,... numbers
1844 1845 above) from your input history into a single string. This variable
1845 1846 acts like an automatic function which re-executes those lines as if
1846 1847 you had typed them. You just type 'name' at the prompt and the code
1847 1848 executes.
1848 1849
1849 1850 The notation for indicating number ranges is: n1-n2 means 'use line
1850 1851 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1851 1852 using the lines numbered 5,6 and 7.
1852 1853
1853 1854 Note: as a 'hidden' feature, you can also use traditional python slice
1854 1855 notation, where N:M means numbers N through M-1.
1855 1856
1856 1857 For example, if your history contains (%hist prints it):
1857 1858
1858 1859 44: x=1\\
1859 1860 45: y=3\\
1860 1861 46: z=x+y\\
1861 1862 47: print x\\
1862 1863 48: a=5\\
1863 1864 49: print 'x',x,'y',y\\
1864 1865
1865 1866 you can create a macro with lines 44 through 47 (included) and line 49
1866 1867 called my_macro with:
1867 1868
1868 1869 In [51]: %macro my_macro 44-47 49
1869 1870
1870 1871 Now, typing `my_macro` (without quotes) will re-execute all this code
1871 1872 in one pass.
1872 1873
1873 1874 You don't need to give the line-numbers in order, and any given line
1874 1875 number can appear multiple times. You can assemble macros with any
1875 1876 lines from your input history in any order.
1876 1877
1877 1878 The macro is a simple object which holds its value in an attribute,
1878 1879 but IPython's display system checks for macros and executes them as
1879 1880 code instead of printing them when you type their name.
1880 1881
1881 1882 You can view a macro's contents by explicitly printing it with:
1882 1883
1883 1884 'print macro_name'.
1884 1885
1885 1886 For one-off cases which DON'T contain magic function calls in them you
1886 1887 can obtain similar results by explicitly executing slices from your
1887 1888 input history with:
1888 1889
1889 1890 In [60]: exec In[44:48]+In[49]"""
1890 1891
1891 1892 opts,args = self.parse_options(parameter_s,'r',mode='list')
1892 1893 name,ranges = args[0], args[1:]
1893 1894 #print 'rng',ranges # dbg
1894 1895 lines = self.extract_input_slices(ranges,opts.has_key('r'))
1895 1896 macro = Macro(lines)
1896 1897 self.shell.user_ns.update({name:macro})
1897 1898 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1898 1899 print 'Macro contents:'
1899 1900 print macro,
1900 1901
1901 1902 def magic_save(self,parameter_s = ''):
1902 1903 """Save a set of lines to a given filename.
1903 1904
1904 1905 Usage:\\
1905 1906 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
1906 1907
1907 1908 Options:
1908 1909
1909 1910 -r: use 'raw' input. By default, the 'processed' history is used,
1910 1911 so that magics are loaded in their transformed version to valid
1911 1912 Python. If this option is given, the raw input as typed as the
1912 1913 command line is used instead.
1913 1914
1914 1915 This function uses the same syntax as %macro for line extraction, but
1915 1916 instead of creating a macro it saves the resulting string to the
1916 1917 filename you specify.
1917 1918
1918 1919 It adds a '.py' extension to the file if you don't do so yourself, and
1919 1920 it asks for confirmation before overwriting existing files."""
1920 1921
1921 1922 opts,args = self.parse_options(parameter_s,'r',mode='list')
1922 1923 fname,ranges = args[0], args[1:]
1923 1924 if not fname.endswith('.py'):
1924 1925 fname += '.py'
1925 1926 if os.path.isfile(fname):
1926 1927 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1927 1928 if ans.lower() not in ['y','yes']:
1928 1929 print 'Operation cancelled.'
1929 1930 return
1930 1931 cmds = ''.join(self.extract_input_slices(ranges,opts.has_key('r')))
1931 1932 f = file(fname,'w')
1932 1933 f.write(cmds)
1933 1934 f.close()
1934 1935 print 'The following commands were written to file `%s`:' % fname
1935 1936 print cmds
1936 1937
1937 1938 def _edit_macro(self,mname,macro):
1938 1939 """open an editor with the macro data in a file"""
1939 1940 filename = self.shell.mktempfile(macro.value)
1940 1941 self.shell.hooks.editor(filename)
1941 1942
1942 1943 # and make a new macro object, to replace the old one
1943 1944 mfile = open(filename)
1944 1945 mvalue = mfile.read()
1945 1946 mfile.close()
1946 1947 self.shell.user_ns[mname] = Macro(mvalue)
1947 1948
1948 1949 def magic_ed(self,parameter_s=''):
1949 1950 """Alias to %edit."""
1950 1951 return self.magic_edit(parameter_s)
1951 1952
1952 1953 def magic_edit(self,parameter_s='',last_call=['','']):
1953 1954 """Bring up an editor and execute the resulting code.
1954 1955
1955 1956 Usage:
1956 1957 %edit [options] [args]
1957 1958
1958 1959 %edit runs IPython's editor hook. The default version of this hook is
1959 1960 set to call the __IPYTHON__.rc.editor command. This is read from your
1960 1961 environment variable $EDITOR. If this isn't found, it will default to
1961 1962 vi under Linux/Unix and to notepad under Windows. See the end of this
1962 1963 docstring for how to change the editor hook.
1963 1964
1964 1965 You can also set the value of this editor via the command line option
1965 1966 '-editor' or in your ipythonrc file. This is useful if you wish to use
1966 1967 specifically for IPython an editor different from your typical default
1967 1968 (and for Windows users who typically don't set environment variables).
1968 1969
1969 1970 This command allows you to conveniently edit multi-line code right in
1970 1971 your IPython session.
1971 1972
1972 1973 If called without arguments, %edit opens up an empty editor with a
1973 1974 temporary file and will execute the contents of this file when you
1974 1975 close it (don't forget to save it!).
1975 1976
1976 1977
1977 1978 Options:
1978 1979
1979 1980 -n <number>: open the editor at a specified line number. By default,
1980 1981 the IPython editor hook uses the unix syntax 'editor +N filename', but
1981 1982 you can configure this by providing your own modified hook if your
1982 1983 favorite editor supports line-number specifications with a different
1983 1984 syntax.
1984 1985
1985 1986 -p: this will call the editor with the same data as the previous time
1986 1987 it was used, regardless of how long ago (in your current session) it
1987 1988 was.
1988 1989
1989 1990 -r: use 'raw' input. This option only applies to input taken from the
1990 1991 user's history. By default, the 'processed' history is used, so that
1991 1992 magics are loaded in their transformed version to valid Python. If
1992 1993 this option is given, the raw input as typed as the command line is
1993 1994 used instead. When you exit the editor, it will be executed by
1994 1995 IPython's own processor.
1995 1996
1996 1997 -x: do not execute the edited code immediately upon exit. This is
1997 1998 mainly useful if you are editing programs which need to be called with
1998 1999 command line arguments, which you can then do using %run.
1999 2000
2000 2001
2001 2002 Arguments:
2002 2003
2003 2004 If arguments are given, the following possibilites exist:
2004 2005
2005 2006 - The arguments are numbers or pairs of colon-separated numbers (like
2006 2007 1 4:8 9). These are interpreted as lines of previous input to be
2007 2008 loaded into the editor. The syntax is the same of the %macro command.
2008 2009
2009 2010 - If the argument doesn't start with a number, it is evaluated as a
2010 2011 variable and its contents loaded into the editor. You can thus edit
2011 2012 any string which contains python code (including the result of
2012 2013 previous edits).
2013 2014
2014 2015 - If the argument is the name of an object (other than a string),
2015 2016 IPython will try to locate the file where it was defined and open the
2016 2017 editor at the point where it is defined. You can use `%edit function`
2017 2018 to load an editor exactly at the point where 'function' is defined,
2018 2019 edit it and have the file be executed automatically.
2019 2020
2020 2021 If the object is a macro (see %macro for details), this opens up your
2021 2022 specified editor with a temporary file containing the macro's data.
2022 2023 Upon exit, the macro is reloaded with the contents of the file.
2023 2024
2024 2025 Note: opening at an exact line is only supported under Unix, and some
2025 2026 editors (like kedit and gedit up to Gnome 2.8) do not understand the
2026 2027 '+NUMBER' parameter necessary for this feature. Good editors like
2027 2028 (X)Emacs, vi, jed, pico and joe all do.
2028 2029
2029 2030 - If the argument is not found as a variable, IPython will look for a
2030 2031 file with that name (adding .py if necessary) and load it into the
2031 2032 editor. It will execute its contents with execfile() when you exit,
2032 2033 loading any code in the file into your interactive namespace.
2033 2034
2034 2035 After executing your code, %edit will return as output the code you
2035 2036 typed in the editor (except when it was an existing file). This way
2036 2037 you can reload the code in further invocations of %edit as a variable,
2037 2038 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
2038 2039 the output.
2039 2040
2040 2041 Note that %edit is also available through the alias %ed.
2041 2042
2042 2043 This is an example of creating a simple function inside the editor and
2043 2044 then modifying it. First, start up the editor:
2044 2045
2045 2046 In [1]: ed\\
2046 2047 Editing... done. Executing edited code...\\
2047 2048 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
2048 2049
2049 2050 We can then call the function foo():
2050 2051
2051 2052 In [2]: foo()\\
2052 2053 foo() was defined in an editing session
2053 2054
2054 2055 Now we edit foo. IPython automatically loads the editor with the
2055 2056 (temporary) file where foo() was previously defined:
2056 2057
2057 2058 In [3]: ed foo\\
2058 2059 Editing... done. Executing edited code...
2059 2060
2060 2061 And if we call foo() again we get the modified version:
2061 2062
2062 2063 In [4]: foo()\\
2063 2064 foo() has now been changed!
2064 2065
2065 2066 Here is an example of how to edit a code snippet successive
2066 2067 times. First we call the editor:
2067 2068
2068 2069 In [8]: ed\\
2069 2070 Editing... done. Executing edited code...\\
2070 2071 hello\\
2071 2072 Out[8]: "print 'hello'\\n"
2072 2073
2073 2074 Now we call it again with the previous output (stored in _):
2074 2075
2075 2076 In [9]: ed _\\
2076 2077 Editing... done. Executing edited code...\\
2077 2078 hello world\\
2078 2079 Out[9]: "print 'hello world'\\n"
2079 2080
2080 2081 Now we call it with the output #8 (stored in _8, also as Out[8]):
2081 2082
2082 2083 In [10]: ed _8\\
2083 2084 Editing... done. Executing edited code...\\
2084 2085 hello again\\
2085 2086 Out[10]: "print 'hello again'\\n"
2086 2087
2087 2088
2088 2089 Changing the default editor hook:
2089 2090
2090 2091 If you wish to write your own editor hook, you can put it in a
2091 2092 configuration file which you load at startup time. The default hook
2092 2093 is defined in the IPython.hooks module, and you can use that as a
2093 2094 starting example for further modifications. That file also has
2094 2095 general instructions on how to set a new hook for use once you've
2095 2096 defined it."""
2096 2097
2097 2098 # FIXME: This function has become a convoluted mess. It needs a
2098 2099 # ground-up rewrite with clean, simple logic.
2099 2100
2100 2101 def make_filename(arg):
2101 2102 "Make a filename from the given args"
2102 2103 try:
2103 2104 filename = get_py_filename(arg)
2104 2105 except IOError:
2105 2106 if args.endswith('.py'):
2106 2107 filename = arg
2107 2108 else:
2108 2109 filename = None
2109 2110 return filename
2110 2111
2111 2112 # custom exceptions
2112 2113 class DataIsObject(Exception): pass
2113 2114
2114 2115 opts,args = self.parse_options(parameter_s,'prxn:')
2115 2116 # Set a few locals from the options for convenience:
2116 2117 opts_p = opts.has_key('p')
2117 2118 opts_r = opts.has_key('r')
2118 2119
2119 2120 # Default line number value
2120 2121 lineno = opts.get('n',None)
2121 2122
2122 2123 if opts_p:
2123 2124 args = '_%s' % last_call[0]
2124 2125 if not self.shell.user_ns.has_key(args):
2125 2126 args = last_call[1]
2126 2127
2127 2128 # use last_call to remember the state of the previous call, but don't
2128 2129 # let it be clobbered by successive '-p' calls.
2129 2130 try:
2130 2131 last_call[0] = self.shell.outputcache.prompt_count
2131 2132 if not opts_p:
2132 2133 last_call[1] = parameter_s
2133 2134 except:
2134 2135 pass
2135 2136
2136 2137 # by default this is done with temp files, except when the given
2137 2138 # arg is a filename
2138 2139 use_temp = 1
2139 2140
2140 2141 if re.match(r'\d',args):
2141 2142 # Mode where user specifies ranges of lines, like in %macro.
2142 2143 # This means that you can't edit files whose names begin with
2143 2144 # numbers this way. Tough.
2144 2145 ranges = args.split()
2145 2146 data = ''.join(self.extract_input_slices(ranges,opts_r))
2146 2147 elif args.endswith('.py'):
2147 2148 filename = make_filename(args)
2148 2149 data = ''
2149 2150 use_temp = 0
2150 2151 elif args:
2151 2152 try:
2152 2153 # Load the parameter given as a variable. If not a string,
2153 2154 # process it as an object instead (below)
2154 2155
2155 2156 #print '*** args',args,'type',type(args) # dbg
2156 2157 data = eval(args,self.shell.user_ns)
2157 2158 if not type(data) in StringTypes:
2158 2159 raise DataIsObject
2159 2160
2160 2161 except (NameError,SyntaxError):
2161 2162 # given argument is not a variable, try as a filename
2162 2163 filename = make_filename(args)
2163 2164 if filename is None:
2164 2165 warn("Argument given (%s) can't be found as a variable "
2165 2166 "or as a filename." % args)
2166 2167 return
2167 2168
2168 2169 data = ''
2169 2170 use_temp = 0
2170 2171 except DataIsObject:
2171 2172
2172 2173 # macros have a special edit function
2173 2174 if isinstance(data,Macro):
2174 2175 self._edit_macro(args,data)
2175 2176 return
2176 2177
2177 2178 # For objects, try to edit the file where they are defined
2178 2179 try:
2179 2180 filename = inspect.getabsfile(data)
2180 2181 datafile = 1
2181 2182 except TypeError:
2182 2183 filename = make_filename(args)
2183 2184 datafile = 1
2184 2185 warn('Could not find file where `%s` is defined.\n'
2185 2186 'Opening a file named `%s`' % (args,filename))
2186 2187 # Now, make sure we can actually read the source (if it was in
2187 2188 # a temp file it's gone by now).
2188 2189 if datafile:
2189 2190 try:
2190 2191 if lineno is None:
2191 2192 lineno = inspect.getsourcelines(data)[1]
2192 2193 except IOError:
2193 2194 filename = make_filename(args)
2194 2195 if filename is None:
2195 2196 warn('The file `%s` where `%s` was defined cannot '
2196 2197 'be read.' % (filename,data))
2197 2198 return
2198 2199 use_temp = 0
2199 2200 else:
2200 2201 data = ''
2201 2202
2202 2203 if use_temp:
2203 2204 filename = self.shell.mktempfile(data)
2204 2205 print 'IPython will make a temporary file named:',filename
2205 2206
2206 2207 # do actual editing here
2207 2208 print 'Editing...',
2208 2209 sys.stdout.flush()
2209 2210 self.shell.hooks.editor(filename,lineno)
2210 2211 if opts.has_key('x'): # -x prevents actual execution
2211 2212 print
2212 2213 else:
2213 2214 print 'done. Executing edited code...'
2214 2215 if opts_r:
2215 2216 self.shell.runlines(file_read(filename))
2216 2217 else:
2217 2218 self.shell.safe_execfile(filename,self.shell.user_ns)
2218 2219 if use_temp:
2219 2220 try:
2220 2221 return open(filename).read()
2221 2222 except IOError,msg:
2222 2223 if msg.filename == filename:
2223 2224 warn('File not found. Did you forget to save?')
2224 2225 return
2225 2226 else:
2226 2227 self.shell.showtraceback()
2227 2228
2228 2229 def magic_xmode(self,parameter_s = ''):
2229 2230 """Switch modes for the exception handlers.
2230 2231
2231 2232 Valid modes: Plain, Context and Verbose.
2232 2233
2233 2234 If called without arguments, acts as a toggle."""
2234 2235
2235 2236 def xmode_switch_err(name):
2236 2237 warn('Error changing %s exception modes.\n%s' %
2237 2238 (name,sys.exc_info()[1]))
2238 2239
2239 2240 shell = self.shell
2240 2241 new_mode = parameter_s.strip().capitalize()
2241 2242 try:
2242 2243 shell.InteractiveTB.set_mode(mode=new_mode)
2243 2244 print 'Exception reporting mode:',shell.InteractiveTB.mode
2244 2245 except:
2245 2246 xmode_switch_err('user')
2246 2247
2247 2248 # threaded shells use a special handler in sys.excepthook
2248 2249 if shell.isthreaded:
2249 2250 try:
2250 2251 shell.sys_excepthook.set_mode(mode=new_mode)
2251 2252 except:
2252 2253 xmode_switch_err('threaded')
2253 2254
2254 2255 def magic_colors(self,parameter_s = ''):
2255 2256 """Switch color scheme for prompts, info system and exception handlers.
2256 2257
2257 2258 Currently implemented schemes: NoColor, Linux, LightBG.
2258 2259
2259 2260 Color scheme names are not case-sensitive."""
2260 2261
2261 2262 def color_switch_err(name):
2262 2263 warn('Error changing %s color schemes.\n%s' %
2263 2264 (name,sys.exc_info()[1]))
2264 2265
2265 2266
2266 2267 new_scheme = parameter_s.strip()
2267 2268 if not new_scheme:
2268 2269 print 'You must specify a color scheme.'
2269 2270 return
2270 2271 import IPython.rlineimpl as readline
2271 2272 if not readline.have_readline:
2272 2273 msg = """\
2273 2274 Proper color support under MS Windows requires the pyreadline library.
2274 2275 You can find it at:
2275 2276 http://ipython.scipy.org/moin/PyReadline/Intro
2276 2277 Gary's readline needs the ctypes module, from:
2277 2278 http://starship.python.net/crew/theller/ctypes
2278 2279 (Note that ctypes is already part of Python versions 2.5 and newer).
2279 2280
2280 2281 Defaulting color scheme to 'NoColor'"""
2281 2282 new_scheme = 'NoColor'
2282 2283 warn(msg)
2283 2284 # local shortcut
2284 2285 shell = self.shell
2285 2286
2286 2287 # Set prompt colors
2287 2288 try:
2288 2289 shell.outputcache.set_colors(new_scheme)
2289 2290 except:
2290 2291 color_switch_err('prompt')
2291 2292 else:
2292 2293 shell.rc.colors = \
2293 2294 shell.outputcache.color_table.active_scheme_name
2294 2295 # Set exception colors
2295 2296 try:
2296 2297 shell.InteractiveTB.set_colors(scheme = new_scheme)
2297 2298 shell.SyntaxTB.set_colors(scheme = new_scheme)
2298 2299 except:
2299 2300 color_switch_err('exception')
2300 2301
2301 2302 # threaded shells use a verbose traceback in sys.excepthook
2302 2303 if shell.isthreaded:
2303 2304 try:
2304 2305 shell.sys_excepthook.set_colors(scheme=new_scheme)
2305 2306 except:
2306 2307 color_switch_err('system exception handler')
2307 2308
2308 2309 # Set info (for 'object?') colors
2309 2310 if shell.rc.color_info:
2310 2311 try:
2311 2312 shell.inspector.set_active_scheme(new_scheme)
2312 2313 except:
2313 2314 color_switch_err('object inspector')
2314 2315 else:
2315 2316 shell.inspector.set_active_scheme('NoColor')
2316 2317
2317 2318 def magic_color_info(self,parameter_s = ''):
2318 2319 """Toggle color_info.
2319 2320
2320 2321 The color_info configuration parameter controls whether colors are
2321 2322 used for displaying object details (by things like %psource, %pfile or
2322 2323 the '?' system). This function toggles this value with each call.
2323 2324
2324 2325 Note that unless you have a fairly recent pager (less works better
2325 2326 than more) in your system, using colored object information displays
2326 2327 will not work properly. Test it and see."""
2327 2328
2328 2329 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2329 2330 self.magic_colors(self.shell.rc.colors)
2330 2331 print 'Object introspection functions have now coloring:',
2331 2332 print ['OFF','ON'][self.shell.rc.color_info]
2332 2333
2333 2334 def magic_Pprint(self, parameter_s=''):
2334 2335 """Toggle pretty printing on/off."""
2335 2336
2336 2337 self.shell.rc.pprint = 1 - self.shell.rc.pprint
2337 2338 print 'Pretty printing has been turned', \
2338 2339 ['OFF','ON'][self.shell.rc.pprint]
2339 2340
2340 2341 def magic_exit(self, parameter_s=''):
2341 2342 """Exit IPython, confirming if configured to do so.
2342 2343
2343 2344 You can configure whether IPython asks for confirmation upon exit by
2344 2345 setting the confirm_exit flag in the ipythonrc file."""
2345 2346
2346 2347 self.shell.exit()
2347 2348
2348 2349 def magic_quit(self, parameter_s=''):
2349 2350 """Exit IPython, confirming if configured to do so (like %exit)"""
2350 2351
2351 2352 self.shell.exit()
2352 2353
2353 2354 def magic_Exit(self, parameter_s=''):
2354 2355 """Exit IPython without confirmation."""
2355 2356
2356 2357 self.shell.exit_now = True
2357 2358
2358 2359 def magic_Quit(self, parameter_s=''):
2359 2360 """Exit IPython without confirmation (like %Exit)."""
2360 2361
2361 2362 self.shell.exit_now = True
2362 2363
2363 2364 #......................................................................
2364 2365 # Functions to implement unix shell-type things
2365 2366
2366 2367 def magic_alias(self, parameter_s = ''):
2367 2368 """Define an alias for a system command.
2368 2369
2369 2370 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2370 2371
2371 2372 Then, typing 'alias_name params' will execute the system command 'cmd
2372 2373 params' (from your underlying operating system).
2373 2374
2374 2375 Aliases have lower precedence than magic functions and Python normal
2375 2376 variables, so if 'foo' is both a Python variable and an alias, the
2376 2377 alias can not be executed until 'del foo' removes the Python variable.
2377 2378
2378 2379 You can use the %l specifier in an alias definition to represent the
2379 2380 whole line when the alias is called. For example:
2380 2381
2381 2382 In [2]: alias all echo "Input in brackets: <%l>"\\
2382 2383 In [3]: all hello world\\
2383 2384 Input in brackets: <hello world>
2384 2385
2385 2386 You can also define aliases with parameters using %s specifiers (one
2386 2387 per parameter):
2387 2388
2388 2389 In [1]: alias parts echo first %s second %s\\
2389 2390 In [2]: %parts A B\\
2390 2391 first A second B\\
2391 2392 In [3]: %parts A\\
2392 2393 Incorrect number of arguments: 2 expected.\\
2393 2394 parts is an alias to: 'echo first %s second %s'
2394 2395
2395 2396 Note that %l and %s are mutually exclusive. You can only use one or
2396 2397 the other in your aliases.
2397 2398
2398 2399 Aliases expand Python variables just like system calls using ! or !!
2399 2400 do: all expressions prefixed with '$' get expanded. For details of
2400 2401 the semantic rules, see PEP-215:
2401 2402 http://www.python.org/peps/pep-0215.html. This is the library used by
2402 2403 IPython for variable expansion. If you want to access a true shell
2403 2404 variable, an extra $ is necessary to prevent its expansion by IPython:
2404 2405
2405 2406 In [6]: alias show echo\\
2406 2407 In [7]: PATH='A Python string'\\
2407 2408 In [8]: show $PATH\\
2408 2409 A Python string\\
2409 2410 In [9]: show $$PATH\\
2410 2411 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2411 2412
2412 2413 You can use the alias facility to acess all of $PATH. See the %rehash
2413 2414 and %rehashx functions, which automatically create aliases for the
2414 2415 contents of your $PATH.
2415 2416
2416 2417 If called with no parameters, %alias prints the current alias table."""
2417 2418
2418 2419 par = parameter_s.strip()
2419 2420 if not par:
2420 2421 stored = self.db.get('stored_aliases', {} )
2421 2422 atab = self.shell.alias_table
2422 2423 aliases = atab.keys()
2423 2424 aliases.sort()
2424 2425 res = []
2425 2426 showlast = []
2426 2427 for alias in aliases:
2427 2428 tgt = atab[alias][1]
2428 2429 # 'interesting' aliases
2429 2430 if (alias in stored or
2430 2431 alias != os.path.splitext(tgt)[0] or
2431 2432 ' ' in tgt):
2432 2433 showlast.append((alias, tgt))
2433 2434 else:
2434 2435 res.append((alias, tgt ))
2435 2436
2436 2437 # show most interesting aliases last
2437 2438 res.extend(showlast)
2438 2439 print "Total number of aliases:",len(aliases)
2439 2440 return res
2440 2441 try:
2441 2442 alias,cmd = par.split(None,1)
2442 2443 except:
2443 2444 print OInspect.getdoc(self.magic_alias)
2444 2445 else:
2445 2446 nargs = cmd.count('%s')
2446 2447 if nargs>0 and cmd.find('%l')>=0:
2447 2448 error('The %s and %l specifiers are mutually exclusive '
2448 2449 'in alias definitions.')
2449 2450 else: # all looks OK
2450 2451 self.shell.alias_table[alias] = (nargs,cmd)
2451 2452 self.shell.alias_table_validate(verbose=0)
2452 2453 # end magic_alias
2453 2454
2454 2455 def magic_unalias(self, parameter_s = ''):
2455 2456 """Remove an alias"""
2456 2457
2457 2458 aname = parameter_s.strip()
2458 2459 if aname in self.shell.alias_table:
2459 2460 del self.shell.alias_table[aname]
2460 2461 stored = self.db.get('stored_aliases', {} )
2461 2462 if aname in stored:
2462 2463 print "Removing %stored alias",aname
2463 2464 del stored[aname]
2464 2465 self.db['stored_aliases'] = stored
2465 2466
2466 2467 def magic_rehash(self, parameter_s = ''):
2467 2468 """Update the alias table with all entries in $PATH.
2468 2469
2469 2470 This version does no checks on execute permissions or whether the
2470 2471 contents of $PATH are truly files (instead of directories or something
2471 2472 else). For such a safer (but slower) version, use %rehashx."""
2472 2473
2473 2474 # This function (and rehashx) manipulate the alias_table directly
2474 2475 # rather than calling magic_alias, for speed reasons. A rehash on a
2475 2476 # typical Linux box involves several thousand entries, so efficiency
2476 2477 # here is a top concern.
2477 2478
2478 2479 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2479 2480 alias_table = self.shell.alias_table
2480 2481 for pdir in path:
2481 2482 for ff in os.listdir(pdir):
2482 2483 # each entry in the alias table must be (N,name), where
2483 2484 # N is the number of positional arguments of the alias.
2484 2485 alias_table[ff] = (0,ff)
2485 2486 # Make sure the alias table doesn't contain keywords or builtins
2486 2487 self.shell.alias_table_validate()
2487 2488 # Call again init_auto_alias() so we get 'rm -i' and other modified
2488 2489 # aliases since %rehash will probably clobber them
2489 2490 self.shell.init_auto_alias()
2490 2491
2491 2492 def magic_rehashx(self, parameter_s = ''):
2492 2493 """Update the alias table with all executable files in $PATH.
2493 2494
2494 2495 This version explicitly checks that every entry in $PATH is a file
2495 2496 with execute access (os.X_OK), so it is much slower than %rehash.
2496 2497
2497 2498 Under Windows, it checks executability as a match agains a
2498 2499 '|'-separated string of extensions, stored in the IPython config
2499 2500 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2500 2501
2501 2502 path = [os.path.abspath(os.path.expanduser(p)) for p in
2502 2503 os.environ['PATH'].split(os.pathsep)]
2503 2504 path = filter(os.path.isdir,path)
2504 2505
2505 2506 alias_table = self.shell.alias_table
2506 2507 syscmdlist = []
2507 2508 if os.name == 'posix':
2508 2509 isexec = lambda fname:os.path.isfile(fname) and \
2509 2510 os.access(fname,os.X_OK)
2510 2511 else:
2511 2512
2512 2513 try:
2513 2514 winext = os.environ['pathext'].replace(';','|').replace('.','')
2514 2515 except KeyError:
2515 2516 winext = 'exe|com|bat|py'
2516 2517 if 'py' not in winext:
2517 2518 winext += '|py'
2518 2519 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2519 2520 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2520 2521 savedir = os.getcwd()
2521 2522 try:
2522 2523 # write the whole loop for posix/Windows so we don't have an if in
2523 2524 # the innermost part
2524 2525 if os.name == 'posix':
2525 2526 for pdir in path:
2526 2527 os.chdir(pdir)
2527 2528 for ff in os.listdir(pdir):
2528 2529 if isexec(ff) and ff not in self.shell.no_alias:
2529 2530 # each entry in the alias table must be (N,name),
2530 2531 # where N is the number of positional arguments of the
2531 2532 # alias.
2532 2533 alias_table[ff] = (0,ff)
2533 2534 syscmdlist.append(ff)
2534 2535 else:
2535 2536 for pdir in path:
2536 2537 os.chdir(pdir)
2537 2538 for ff in os.listdir(pdir):
2538 2539 base, ext = os.path.splitext(ff)
2539 2540 if isexec(ff) and base not in self.shell.no_alias:
2540 2541 if ext.lower() == '.exe':
2541 2542 ff = base
2542 2543 alias_table[base] = (0,ff)
2543 2544 syscmdlist.append(ff)
2544 2545 # Make sure the alias table doesn't contain keywords or builtins
2545 2546 self.shell.alias_table_validate()
2546 2547 # Call again init_auto_alias() so we get 'rm -i' and other
2547 2548 # modified aliases since %rehashx will probably clobber them
2548 2549 self.shell.init_auto_alias()
2549 2550 db = self.getapi().db
2550 2551 db['syscmdlist'] = syscmdlist
2551 2552 finally:
2552 2553 os.chdir(savedir)
2553 2554
2554 2555 def magic_pwd(self, parameter_s = ''):
2555 2556 """Return the current working directory path."""
2556 2557 return os.getcwd()
2557 2558
2558 2559 def magic_cd(self, parameter_s=''):
2559 2560 """Change the current working directory.
2560 2561
2561 2562 This command automatically maintains an internal list of directories
2562 2563 you visit during your IPython session, in the variable _dh. The
2563 2564 command %dhist shows this history nicely formatted. You can also
2564 2565 do 'cd -<tab>' to see directory history conveniently.
2565 2566
2566 2567 Usage:
2567 2568
2568 2569 cd 'dir': changes to directory 'dir'.
2569 2570
2570 2571 cd -: changes to the last visited directory.
2571 2572
2572 2573 cd -<n>: changes to the n-th directory in the directory history.
2573 2574
2574 2575 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2575 2576 (note: cd <bookmark_name> is enough if there is no
2576 2577 directory <bookmark_name>, but a bookmark with the name exists.)
2577 2578 'cd -b <tab>' allows you to tab-complete bookmark names.
2578 2579
2579 2580 Options:
2580 2581
2581 2582 -q: quiet. Do not print the working directory after the cd command is
2582 2583 executed. By default IPython's cd command does print this directory,
2583 2584 since the default prompts do not display path information.
2584 2585
2585 2586 Note that !cd doesn't work for this purpose because the shell where
2586 2587 !command runs is immediately discarded after executing 'command'."""
2587 2588
2588 2589 parameter_s = parameter_s.strip()
2589 2590 #bkms = self.shell.persist.get("bookmarks",{})
2590 2591
2591 2592 numcd = re.match(r'(-)(\d+)$',parameter_s)
2592 2593 # jump in directory history by number
2593 2594 if numcd:
2594 2595 nn = int(numcd.group(2))
2595 2596 try:
2596 2597 ps = self.shell.user_ns['_dh'][nn]
2597 2598 except IndexError:
2598 2599 print 'The requested directory does not exist in history.'
2599 2600 return
2600 2601 else:
2601 2602 opts = {}
2602 2603 else:
2603 2604 #turn all non-space-escaping backslashes to slashes,
2604 2605 # for c:\windows\directory\names\
2605 2606 parameter_s = re.sub(r'\\(?! )','/', parameter_s)
2606 2607 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2607 2608 # jump to previous
2608 2609 if ps == '-':
2609 2610 try:
2610 2611 ps = self.shell.user_ns['_dh'][-2]
2611 2612 except IndexError:
2612 2613 print 'No previous directory to change to.'
2613 2614 return
2614 2615 # jump to bookmark if needed
2615 2616 else:
2616 2617 if not os.path.isdir(ps) or opts.has_key('b'):
2617 2618 bkms = self.db.get('bookmarks', {})
2618 2619
2619 2620 if bkms.has_key(ps):
2620 2621 target = bkms[ps]
2621 2622 print '(bookmark:%s) -> %s' % (ps,target)
2622 2623 ps = target
2623 2624 else:
2624 2625 if opts.has_key('b'):
2625 2626 error("Bookmark '%s' not found. "
2626 2627 "Use '%%bookmark -l' to see your bookmarks." % ps)
2627 2628 return
2628 2629
2629 2630 # at this point ps should point to the target dir
2630 2631 if ps:
2631 2632 try:
2632 2633 os.chdir(os.path.expanduser(ps))
2633 2634 if self.shell.rc.term_title:
2634 2635 #print 'set term title:',self.shell.rc.term_title # dbg
2635 2636 ttitle = ("IPy:" + (
2636 2637 os.getcwd() == '/' and '/' or \
2637 2638 os.path.basename(os.getcwd())))
2638 2639 platutils.set_term_title(ttitle)
2639 2640 except OSError:
2640 2641 print sys.exc_info()[1]
2641 2642 else:
2642 2643 self.shell.user_ns['_dh'].append(os.getcwd())
2643 2644 else:
2644 2645 os.chdir(self.shell.home_dir)
2645 2646 if self.shell.rc.term_title:
2646 2647 platutils.set_term_title("IPy:~")
2647 2648 self.shell.user_ns['_dh'].append(os.getcwd())
2648 2649 if not 'q' in opts:
2649 2650 print self.shell.user_ns['_dh'][-1]
2650 2651
2651 2652 def magic_dhist(self, parameter_s=''):
2652 2653 """Print your history of visited directories.
2653 2654
2654 2655 %dhist -> print full history\\
2655 2656 %dhist n -> print last n entries only\\
2656 2657 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2657 2658
2658 2659 This history is automatically maintained by the %cd command, and
2659 2660 always available as the global list variable _dh. You can use %cd -<n>
2660 2661 to go to directory number <n>."""
2661 2662
2662 2663 dh = self.shell.user_ns['_dh']
2663 2664 if parameter_s:
2664 2665 try:
2665 2666 args = map(int,parameter_s.split())
2666 2667 except:
2667 2668 self.arg_err(Magic.magic_dhist)
2668 2669 return
2669 2670 if len(args) == 1:
2670 2671 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2671 2672 elif len(args) == 2:
2672 2673 ini,fin = args
2673 2674 else:
2674 2675 self.arg_err(Magic.magic_dhist)
2675 2676 return
2676 2677 else:
2677 2678 ini,fin = 0,len(dh)
2678 2679 nlprint(dh,
2679 2680 header = 'Directory history (kept in _dh)',
2680 2681 start=ini,stop=fin)
2681 2682
2682 2683 def magic_env(self, parameter_s=''):
2683 2684 """List environment variables."""
2684 2685
2685 2686 return os.environ.data
2686 2687
2687 2688 def magic_pushd(self, parameter_s=''):
2688 2689 """Place the current dir on stack and change directory.
2689 2690
2690 2691 Usage:\\
2691 2692 %pushd ['dirname']
2692 2693
2693 2694 %pushd with no arguments does a %pushd to your home directory.
2694 2695 """
2695 2696 if parameter_s == '': parameter_s = '~'
2696 2697 dir_s = self.shell.dir_stack
2697 2698 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2698 2699 os.path.expanduser(self.shell.dir_stack[0]):
2699 2700 try:
2700 2701 self.magic_cd(parameter_s)
2701 2702 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2702 2703 self.magic_dirs()
2703 2704 except:
2704 2705 print 'Invalid directory'
2705 2706 else:
2706 2707 print 'You are already there!'
2707 2708
2708 2709 def magic_popd(self, parameter_s=''):
2709 2710 """Change to directory popped off the top of the stack.
2710 2711 """
2711 2712 if len (self.shell.dir_stack) > 1:
2712 2713 self.shell.dir_stack.pop(0)
2713 2714 self.magic_cd(self.shell.dir_stack[0])
2714 2715 print self.shell.dir_stack[0]
2715 2716 else:
2716 2717 print "You can't remove the starting directory from the stack:",\
2717 2718 self.shell.dir_stack
2718 2719
2719 2720 def magic_dirs(self, parameter_s=''):
2720 2721 """Return the current directory stack."""
2721 2722
2722 2723 return self.shell.dir_stack[:]
2723 2724
2724 2725 def magic_sc(self, parameter_s=''):
2725 2726 """Shell capture - execute a shell command and capture its output.
2726 2727
2727 2728 DEPRECATED. Suboptimal, retained for backwards compatibility.
2728 2729
2729 2730 You should use the form 'var = !command' instead. Example:
2730 2731
2731 2732 "%sc -l myfiles = ls ~" should now be written as
2732 2733
2733 2734 "myfiles = !ls ~"
2734 2735
2735 2736 myfiles.s, myfiles.l and myfiles.n still apply as documented
2736 2737 below.
2737 2738
2738 2739 --
2739 2740 %sc [options] varname=command
2740 2741
2741 2742 IPython will run the given command using commands.getoutput(), and
2742 2743 will then update the user's interactive namespace with a variable
2743 2744 called varname, containing the value of the call. Your command can
2744 2745 contain shell wildcards, pipes, etc.
2745 2746
2746 2747 The '=' sign in the syntax is mandatory, and the variable name you
2747 2748 supply must follow Python's standard conventions for valid names.
2748 2749
2749 2750 (A special format without variable name exists for internal use)
2750 2751
2751 2752 Options:
2752 2753
2753 2754 -l: list output. Split the output on newlines into a list before
2754 2755 assigning it to the given variable. By default the output is stored
2755 2756 as a single string.
2756 2757
2757 2758 -v: verbose. Print the contents of the variable.
2758 2759
2759 2760 In most cases you should not need to split as a list, because the
2760 2761 returned value is a special type of string which can automatically
2761 2762 provide its contents either as a list (split on newlines) or as a
2762 2763 space-separated string. These are convenient, respectively, either
2763 2764 for sequential processing or to be passed to a shell command.
2764 2765
2765 2766 For example:
2766 2767
2767 2768 # Capture into variable a
2768 2769 In [9]: sc a=ls *py
2769 2770
2770 2771 # a is a string with embedded newlines
2771 2772 In [10]: a
2772 2773 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2773 2774
2774 2775 # which can be seen as a list:
2775 2776 In [11]: a.l
2776 2777 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2777 2778
2778 2779 # or as a whitespace-separated string:
2779 2780 In [12]: a.s
2780 2781 Out[12]: 'setup.py win32_manual_post_install.py'
2781 2782
2782 2783 # a.s is useful to pass as a single command line:
2783 2784 In [13]: !wc -l $a.s
2784 2785 146 setup.py
2785 2786 130 win32_manual_post_install.py
2786 2787 276 total
2787 2788
2788 2789 # while the list form is useful to loop over:
2789 2790 In [14]: for f in a.l:
2790 2791 ....: !wc -l $f
2791 2792 ....:
2792 2793 146 setup.py
2793 2794 130 win32_manual_post_install.py
2794 2795
2795 2796 Similiarly, the lists returned by the -l option are also special, in
2796 2797 the sense that you can equally invoke the .s attribute on them to
2797 2798 automatically get a whitespace-separated string from their contents:
2798 2799
2799 2800 In [1]: sc -l b=ls *py
2800 2801
2801 2802 In [2]: b
2802 2803 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2803 2804
2804 2805 In [3]: b.s
2805 2806 Out[3]: 'setup.py win32_manual_post_install.py'
2806 2807
2807 2808 In summary, both the lists and strings used for ouptut capture have
2808 2809 the following special attributes:
2809 2810
2810 2811 .l (or .list) : value as list.
2811 2812 .n (or .nlstr): value as newline-separated string.
2812 2813 .s (or .spstr): value as space-separated string.
2813 2814 """
2814 2815
2815 2816 opts,args = self.parse_options(parameter_s,'lv')
2816 2817 # Try to get a variable name and command to run
2817 2818 try:
2818 2819 # the variable name must be obtained from the parse_options
2819 2820 # output, which uses shlex.split to strip options out.
2820 2821 var,_ = args.split('=',1)
2821 2822 var = var.strip()
2822 2823 # But the the command has to be extracted from the original input
2823 2824 # parameter_s, not on what parse_options returns, to avoid the
2824 2825 # quote stripping which shlex.split performs on it.
2825 2826 _,cmd = parameter_s.split('=',1)
2826 2827 except ValueError:
2827 2828 var,cmd = '',''
2828 2829 # If all looks ok, proceed
2829 2830 out,err = self.shell.getoutputerror(cmd)
2830 2831 if err:
2831 2832 print >> Term.cerr,err
2832 2833 if opts.has_key('l'):
2833 2834 out = SList(out.split('\n'))
2834 2835 else:
2835 2836 out = LSString(out)
2836 2837 if opts.has_key('v'):
2837 2838 print '%s ==\n%s' % (var,pformat(out))
2838 2839 if var:
2839 2840 self.shell.user_ns.update({var:out})
2840 2841 else:
2841 2842 return out
2842 2843
2843 2844 def magic_sx(self, parameter_s=''):
2844 2845 """Shell execute - run a shell command and capture its output.
2845 2846
2846 2847 %sx command
2847 2848
2848 2849 IPython will run the given command using commands.getoutput(), and
2849 2850 return the result formatted as a list (split on '\\n'). Since the
2850 2851 output is _returned_, it will be stored in ipython's regular output
2851 2852 cache Out[N] and in the '_N' automatic variables.
2852 2853
2853 2854 Notes:
2854 2855
2855 2856 1) If an input line begins with '!!', then %sx is automatically
2856 2857 invoked. That is, while:
2857 2858 !ls
2858 2859 causes ipython to simply issue system('ls'), typing
2859 2860 !!ls
2860 2861 is a shorthand equivalent to:
2861 2862 %sx ls
2862 2863
2863 2864 2) %sx differs from %sc in that %sx automatically splits into a list,
2864 2865 like '%sc -l'. The reason for this is to make it as easy as possible
2865 2866 to process line-oriented shell output via further python commands.
2866 2867 %sc is meant to provide much finer control, but requires more
2867 2868 typing.
2868 2869
2869 2870 3) Just like %sc -l, this is a list with special attributes:
2870 2871
2871 2872 .l (or .list) : value as list.
2872 2873 .n (or .nlstr): value as newline-separated string.
2873 2874 .s (or .spstr): value as whitespace-separated string.
2874 2875
2875 2876 This is very useful when trying to use such lists as arguments to
2876 2877 system commands."""
2877 2878
2878 2879 if parameter_s:
2879 2880 out,err = self.shell.getoutputerror(parameter_s)
2880 2881 if err:
2881 2882 print >> Term.cerr,err
2882 2883 return SList(out.split('\n'))
2883 2884
2884 2885 def magic_bg(self, parameter_s=''):
2885 2886 """Run a job in the background, in a separate thread.
2886 2887
2887 2888 For example,
2888 2889
2889 2890 %bg myfunc(x,y,z=1)
2890 2891
2891 2892 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2892 2893 execution starts, a message will be printed indicating the job
2893 2894 number. If your job number is 5, you can use
2894 2895
2895 2896 myvar = jobs.result(5) or myvar = jobs[5].result
2896 2897
2897 2898 to assign this result to variable 'myvar'.
2898 2899
2899 2900 IPython has a job manager, accessible via the 'jobs' object. You can
2900 2901 type jobs? to get more information about it, and use jobs.<TAB> to see
2901 2902 its attributes. All attributes not starting with an underscore are
2902 2903 meant for public use.
2903 2904
2904 2905 In particular, look at the jobs.new() method, which is used to create
2905 2906 new jobs. This magic %bg function is just a convenience wrapper
2906 2907 around jobs.new(), for expression-based jobs. If you want to create a
2907 2908 new job with an explicit function object and arguments, you must call
2908 2909 jobs.new() directly.
2909 2910
2910 2911 The jobs.new docstring also describes in detail several important
2911 2912 caveats associated with a thread-based model for background job
2912 2913 execution. Type jobs.new? for details.
2913 2914
2914 2915 You can check the status of all jobs with jobs.status().
2915 2916
2916 2917 The jobs variable is set by IPython into the Python builtin namespace.
2917 2918 If you ever declare a variable named 'jobs', you will shadow this
2918 2919 name. You can either delete your global jobs variable to regain
2919 2920 access to the job manager, or make a new name and assign it manually
2920 2921 to the manager (stored in IPython's namespace). For example, to
2921 2922 assign the job manager to the Jobs name, use:
2922 2923
2923 2924 Jobs = __builtins__.jobs"""
2924 2925
2925 2926 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2926 2927
2927 2928
2928 2929 def magic_bookmark(self, parameter_s=''):
2929 2930 """Manage IPython's bookmark system.
2930 2931
2931 2932 %bookmark <name> - set bookmark to current dir
2932 2933 %bookmark <name> <dir> - set bookmark to <dir>
2933 2934 %bookmark -l - list all bookmarks
2934 2935 %bookmark -d <name> - remove bookmark
2935 2936 %bookmark -r - remove all bookmarks
2936 2937
2937 2938 You can later on access a bookmarked folder with:
2938 2939 %cd -b <name>
2939 2940 or simply '%cd <name>' if there is no directory called <name> AND
2940 2941 there is such a bookmark defined.
2941 2942
2942 2943 Your bookmarks persist through IPython sessions, but they are
2943 2944 associated with each profile."""
2944 2945
2945 2946 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2946 2947 if len(args) > 2:
2947 2948 error('You can only give at most two arguments')
2948 2949 return
2949 2950
2950 2951 bkms = self.db.get('bookmarks',{})
2951 2952
2952 2953 if opts.has_key('d'):
2953 2954 try:
2954 2955 todel = args[0]
2955 2956 except IndexError:
2956 2957 error('You must provide a bookmark to delete')
2957 2958 else:
2958 2959 try:
2959 2960 del bkms[todel]
2960 2961 except:
2961 2962 error("Can't delete bookmark '%s'" % todel)
2962 2963 elif opts.has_key('r'):
2963 2964 bkms = {}
2964 2965 elif opts.has_key('l'):
2965 2966 bks = bkms.keys()
2966 2967 bks.sort()
2967 2968 if bks:
2968 2969 size = max(map(len,bks))
2969 2970 else:
2970 2971 size = 0
2971 2972 fmt = '%-'+str(size)+'s -> %s'
2972 2973 print 'Current bookmarks:'
2973 2974 for bk in bks:
2974 2975 print fmt % (bk,bkms[bk])
2975 2976 else:
2976 2977 if not args:
2977 2978 error("You must specify the bookmark name")
2978 2979 elif len(args)==1:
2979 2980 bkms[args[0]] = os.getcwd()
2980 2981 elif len(args)==2:
2981 2982 bkms[args[0]] = args[1]
2982 2983 self.db['bookmarks'] = bkms
2983 2984
2984 2985 def magic_pycat(self, parameter_s=''):
2985 2986 """Show a syntax-highlighted file through a pager.
2986 2987
2987 2988 This magic is similar to the cat utility, but it will assume the file
2988 2989 to be Python source and will show it with syntax highlighting. """
2989 2990
2990 2991 try:
2991 2992 filename = get_py_filename(parameter_s)
2992 2993 cont = file_read(filename)
2993 2994 except IOError:
2994 2995 try:
2995 2996 cont = eval(parameter_s,self.user_ns)
2996 2997 except NameError:
2997 2998 cont = None
2998 2999 if cont is None:
2999 3000 print "Error: no such file or variable"
3000 3001 return
3001 3002
3002 3003 page(self.shell.pycolorize(cont),
3003 3004 screen_lines=self.shell.rc.screen_length)
3004 3005
3005 3006 def magic_cpaste(self, parameter_s=''):
3006 3007 """Allows you to paste & execute a pre-formatted code block from clipboard
3007 3008
3008 3009 You must terminate the block with '--' (two minus-signs) alone on the
3009 3010 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
3010 3011 is the new sentinel for this operation)
3011 3012
3012 3013 The block is dedented prior to execution to enable execution of
3013 3014 method definitions. '>' characters at the beginning of a line is
3014 3015 ignored, to allow pasting directly from e-mails. The executed block
3015 3016 is also assigned to variable named 'pasted_block' for later editing
3016 3017 with '%edit pasted_block'.
3017 3018
3018 3019 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
3019 3020 This assigns the pasted block to variable 'foo' as string, without
3020 3021 dedenting or executing it.
3021 3022
3022 3023 Do not be alarmed by garbled output on Windows (it's a readline bug).
3023 3024 Just press enter and type -- (and press enter again) and the block
3024 3025 will be what was just pasted.
3025 3026
3026 3027 IPython statements (magics, shell escapes) are not supported (yet).
3027 3028 """
3028 3029 opts,args = self.parse_options(parameter_s,'s:',mode='string')
3029 3030 par = args.strip()
3030 3031 sentinel = opts.get('s','--')
3031 3032
3032 3033 from IPython import iplib
3033 3034 lines = []
3034 3035 print "Pasting code; enter '%s' alone on the line to stop." % sentinel
3035 3036 while 1:
3036 3037 l = iplib.raw_input_original(':')
3037 3038 if l ==sentinel:
3038 3039 break
3039 3040 lines.append(l.lstrip('>'))
3040 3041 block = "\n".join(lines) + '\n'
3041 3042 #print "block:\n",block
3042 3043 if not par:
3043 3044 b = textwrap.dedent(block)
3044 3045 exec b in self.user_ns
3045 3046 self.user_ns['pasted_block'] = b
3046 3047 else:
3047 3048 self.user_ns[par] = block
3048 3049 print "Block assigned to '%s'" % par
3049 3050
3050 3051 def magic_quickref(self,arg):
3051 3052 """ Show a quick reference sheet """
3052 3053 import IPython.usage
3053 3054 qr = IPython.usage.quick_reference + self.magic_magic('-brief')
3054 3055
3055 3056 page(qr)
3056 3057
3057 3058 def magic_upgrade(self,arg):
3058 3059 """ Upgrade your IPython installation
3059 3060
3060 3061 This will copy the config files that don't yet exist in your
3061 3062 ipython dir from the system config dir. Use this after upgrading
3062 3063 IPython if you don't wish to delete your .ipython dir.
3063 3064
3064 3065 Call with -nolegacy to get rid of ipythonrc* files (recommended for
3065 3066 new users)
3066 3067
3067 3068 """
3068 3069 ip = self.getapi()
3069 3070 ipinstallation = path(IPython.__file__).dirname()
3070 3071 upgrade_script = '%s "%s"' % (sys.executable,ipinstallation / 'upgrade_dir.py')
3071 3072 src_config = ipinstallation / 'UserConfig'
3072 3073 userdir = path(ip.options.ipythondir)
3073 3074 cmd = '%s "%s" "%s"' % (upgrade_script, src_config, userdir)
3074 3075 print ">",cmd
3075 3076 shell(cmd)
3076 3077 if arg == '-nolegacy':
3077 3078 legacy = userdir.files('ipythonrc*')
3078 3079 print "Nuking legacy files:",legacy
3079 3080
3080 3081 [p.remove() for p in legacy]
3081 3082 suffix = (sys.platform == 'win32' and '.ini' or '')
3082 3083 (userdir / ('ipythonrc' + suffix)).write_text('# Empty, see ipy_user_conf.py\n')
3083 3084
3084 3085 # end Magic
@@ -1,2542 +1,2548 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 IPython -- An enhanced Interactive Python
4 4
5 5 Requires Python 2.3 or newer.
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 2014 2007-01-05 10:36:58Z fperez $
9 $Id: iplib.py 2122 2007-03-01 02:27:11Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
13 13 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
14 14 # Copyright (C) 2001-2006 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 IPython import Release
32 32 __author__ = '%s <%s>\n%s <%s>' % \
33 33 ( Release.authors['Janko'] + Release.authors['Fernando'] )
34 34 __license__ = Release.license
35 35 __version__ = Release.version
36 36
37 37 # Python standard modules
38 38 import __main__
39 39 import __builtin__
40 40 import StringIO
41 41 import bdb
42 42 import cPickle as pickle
43 43 import codeop
44 44 import exceptions
45 45 import glob
46 46 import inspect
47 47 import keyword
48 48 import new
49 49 import os
50 50 import pydoc
51 51 import re
52 52 import shutil
53 53 import string
54 54 import sys
55 55 import tempfile
56 56 import traceback
57 57 import types
58 58 import pickleshare
59 59 from sets import Set
60 60 from pprint import pprint, pformat
61 61
62 62 # IPython's own modules
63 63 import IPython
64 64 from IPython import OInspect,PyColorize,ultraTB
65 65 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
66 66 from IPython.FakeModule import FakeModule
67 67 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
68 68 from IPython.Logger import Logger
69 69 from IPython.Magic import Magic
70 70 from IPython.Prompts import CachedOutput
71 71 from IPython.ipstruct import Struct
72 72 from IPython.background_jobs import BackgroundJobManager
73 73 from IPython.usage import cmd_line_usage,interactive_usage
74 74 from IPython.genutils import *
75 75 from IPython.strdispatch import StrDispatch
76 76 import IPython.ipapi
77 77
78 78 # Globals
79 79
80 80 # store the builtin raw_input globally, and use this always, in case user code
81 81 # overwrites it (like wx.py.PyShell does)
82 82 raw_input_original = raw_input
83 83
84 84 # compiled regexps for autoindent management
85 85 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
86 86
87 87
88 88 #****************************************************************************
89 89 # Some utility function definitions
90 90
91 91 ini_spaces_re = re.compile(r'^(\s+)')
92 92
93 93 def num_ini_spaces(strng):
94 94 """Return the number of initial spaces in a string"""
95 95
96 96 ini_spaces = ini_spaces_re.match(strng)
97 97 if ini_spaces:
98 98 return ini_spaces.end()
99 99 else:
100 100 return 0
101 101
102 102 def softspace(file, newvalue):
103 103 """Copied from code.py, to remove the dependency"""
104 104
105 105 oldvalue = 0
106 106 try:
107 107 oldvalue = file.softspace
108 108 except AttributeError:
109 109 pass
110 110 try:
111 111 file.softspace = newvalue
112 112 except (AttributeError, TypeError):
113 113 # "attribute-less object" or "read-only attributes"
114 114 pass
115 115 return oldvalue
116 116
117 117
118 118 #****************************************************************************
119 119 # Local use exceptions
120 120 class SpaceInInput(exceptions.Exception): pass
121 121
122 122
123 123 #****************************************************************************
124 124 # Local use classes
125 125 class Bunch: pass
126 126
127 127 class Undefined: pass
128 128
129 129 class Quitter(object):
130 130 """Simple class to handle exit, similar to Python 2.5's.
131 131
132 132 It handles exiting in an ipython-safe manner, which the one in Python 2.5
133 133 doesn't do (obviously, since it doesn't know about ipython)."""
134 134
135 135 def __init__(self,shell,name):
136 136 self.shell = shell
137 137 self.name = name
138 138
139 139 def __repr__(self):
140 140 return 'Type %s() to exit.' % self.name
141 141 __str__ = __repr__
142 142
143 143 def __call__(self):
144 144 self.shell.exit()
145 145
146 146 class InputList(list):
147 147 """Class to store user input.
148 148
149 149 It's basically a list, but slices return a string instead of a list, thus
150 150 allowing things like (assuming 'In' is an instance):
151 151
152 152 exec In[4:7]
153 153
154 154 or
155 155
156 156 exec In[5:9] + In[14] + In[21:25]"""
157 157
158 158 def __getslice__(self,i,j):
159 159 return ''.join(list.__getslice__(self,i,j))
160 160
161 161 class SyntaxTB(ultraTB.ListTB):
162 162 """Extension which holds some state: the last exception value"""
163 163
164 164 def __init__(self,color_scheme = 'NoColor'):
165 165 ultraTB.ListTB.__init__(self,color_scheme)
166 166 self.last_syntax_error = None
167 167
168 168 def __call__(self, etype, value, elist):
169 169 self.last_syntax_error = value
170 170 ultraTB.ListTB.__call__(self,etype,value,elist)
171 171
172 172 def clear_err_state(self):
173 173 """Return the current error state and clear it"""
174 174 e = self.last_syntax_error
175 175 self.last_syntax_error = None
176 176 return e
177 177
178 178 #****************************************************************************
179 179 # Main IPython class
180 180
181 181 # FIXME: the Magic class is a mixin for now, and will unfortunately remain so
182 182 # until a full rewrite is made. I've cleaned all cross-class uses of
183 183 # attributes and methods, but too much user code out there relies on the
184 184 # equlity %foo == __IP.magic_foo, so I can't actually remove the mixin usage.
185 185 #
186 186 # But at least now, all the pieces have been separated and we could, in
187 187 # principle, stop using the mixin. This will ease the transition to the
188 188 # chainsaw branch.
189 189
190 190 # For reference, the following is the list of 'self.foo' uses in the Magic
191 191 # class as of 2005-12-28. These are names we CAN'T use in the main ipython
192 192 # class, to prevent clashes.
193 193
194 194 # ['self.__class__', 'self.__dict__', 'self._inspect', 'self._ofind',
195 195 # 'self.arg_err', 'self.extract_input', 'self.format_', 'self.lsmagic',
196 196 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
197 197 # 'self.value']
198 198
199 199 class InteractiveShell(object,Magic):
200 200 """An enhanced console for Python."""
201 201
202 202 # class attribute to indicate whether the class supports threads or not.
203 203 # Subclasses with thread support should override this as needed.
204 204 isthreaded = False
205 205
206 206 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
207 207 user_ns = None,user_global_ns=None,banner2='',
208 208 custom_exceptions=((),None),embedded=False):
209 209
210 210 # log system
211 211 self.logger = Logger(self,logfname='ipython_log.py',logmode='rotate')
212 212
213 213 # some minimal strict typechecks. For some core data structures, I
214 214 # want actual basic python types, not just anything that looks like
215 215 # one. This is especially true for namespaces.
216 216 for ns in (user_ns,user_global_ns):
217 217 if ns is not None and type(ns) != types.DictType:
218 218 raise TypeError,'namespace must be a dictionary'
219 219
220 220 # Job manager (for jobs run as background threads)
221 221 self.jobs = BackgroundJobManager()
222 222
223 223 # Store the actual shell's name
224 224 self.name = name
225 225
226 226 # We need to know whether the instance is meant for embedding, since
227 227 # global/local namespaces need to be handled differently in that case
228 228 self.embedded = embedded
229 229
230 230 # command compiler
231 231 self.compile = codeop.CommandCompiler()
232 232
233 233 # User input buffer
234 234 self.buffer = []
235 235
236 236 # Default name given in compilation of code
237 237 self.filename = '<ipython console>'
238 238
239 239 # Install our own quitter instead of the builtins. For python2.3-2.4,
240 240 # this brings in behavior like 2.5, and for 2.5 it's identical.
241 241 __builtin__.exit = Quitter(self,'exit')
242 242 __builtin__.quit = Quitter(self,'quit')
243 243
244 244 # Make an empty namespace, which extension writers can rely on both
245 245 # existing and NEVER being used by ipython itself. This gives them a
246 246 # convenient location for storing additional information and state
247 247 # their extensions may require, without fear of collisions with other
248 248 # ipython names that may develop later.
249 249 self.meta = Struct()
250 250
251 251 # Create the namespace where the user will operate. user_ns is
252 252 # normally the only one used, and it is passed to the exec calls as
253 253 # the locals argument. But we do carry a user_global_ns namespace
254 254 # given as the exec 'globals' argument, This is useful in embedding
255 255 # situations where the ipython shell opens in a context where the
256 256 # distinction between locals and globals is meaningful.
257 257
258 258 # FIXME. For some strange reason, __builtins__ is showing up at user
259 259 # level as a dict instead of a module. This is a manual fix, but I
260 260 # should really track down where the problem is coming from. Alex
261 261 # Schmolck reported this problem first.
262 262
263 263 # A useful post by Alex Martelli on this topic:
264 264 # Re: inconsistent value from __builtins__
265 265 # Von: Alex Martelli <aleaxit@yahoo.com>
266 266 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
267 267 # Gruppen: comp.lang.python
268 268
269 269 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
270 270 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
271 271 # > <type 'dict'>
272 272 # > >>> print type(__builtins__)
273 273 # > <type 'module'>
274 274 # > Is this difference in return value intentional?
275 275
276 276 # Well, it's documented that '__builtins__' can be either a dictionary
277 277 # or a module, and it's been that way for a long time. Whether it's
278 278 # intentional (or sensible), I don't know. In any case, the idea is
279 279 # that if you need to access the built-in namespace directly, you
280 280 # should start with "import __builtin__" (note, no 's') which will
281 281 # definitely give you a module. Yeah, it's somewhat confusing:-(.
282 282
283 283 # These routines return properly built dicts as needed by the rest of
284 284 # the code, and can also be used by extension writers to generate
285 285 # properly initialized namespaces.
286 286 user_ns = IPython.ipapi.make_user_ns(user_ns)
287 287 user_global_ns = IPython.ipapi.make_user_global_ns(user_global_ns)
288 288
289 289 # Assign namespaces
290 290 # This is the namespace where all normal user variables live
291 291 self.user_ns = user_ns
292 292 # Embedded instances require a separate namespace for globals.
293 293 # Normally this one is unused by non-embedded instances.
294 294 self.user_global_ns = user_global_ns
295 295 # A namespace to keep track of internal data structures to prevent
296 296 # them from cluttering user-visible stuff. Will be updated later
297 297 self.internal_ns = {}
298 298
299 299 # Namespace of system aliases. Each entry in the alias
300 300 # table must be a 2-tuple of the form (N,name), where N is the number
301 301 # of positional arguments of the alias.
302 302 self.alias_table = {}
303 303
304 304 # A table holding all the namespaces IPython deals with, so that
305 305 # introspection facilities can search easily.
306 306 self.ns_table = {'user':user_ns,
307 307 'user_global':user_global_ns,
308 308 'alias':self.alias_table,
309 309 'internal':self.internal_ns,
310 310 'builtin':__builtin__.__dict__
311 311 }
312 312
313 313 # The user namespace MUST have a pointer to the shell itself.
314 314 self.user_ns[name] = self
315 315
316 316 # We need to insert into sys.modules something that looks like a
317 317 # module but which accesses the IPython namespace, for shelve and
318 318 # pickle to work interactively. Normally they rely on getting
319 319 # everything out of __main__, but for embedding purposes each IPython
320 320 # instance has its own private namespace, so we can't go shoving
321 321 # everything into __main__.
322 322
323 323 # note, however, that we should only do this for non-embedded
324 324 # ipythons, which really mimic the __main__.__dict__ with their own
325 325 # namespace. Embedded instances, on the other hand, should not do
326 326 # this because they need to manage the user local/global namespaces
327 327 # only, but they live within a 'normal' __main__ (meaning, they
328 328 # shouldn't overtake the execution environment of the script they're
329 329 # embedded in).
330 330
331 331 if not embedded:
332 332 try:
333 333 main_name = self.user_ns['__name__']
334 334 except KeyError:
335 335 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
336 336 else:
337 337 #print "pickle hack in place" # dbg
338 338 #print 'main_name:',main_name # dbg
339 339 sys.modules[main_name] = FakeModule(self.user_ns)
340 340
341 341 # List of input with multi-line handling.
342 342 # Fill its zero entry, user counter starts at 1
343 343 self.input_hist = InputList(['\n'])
344 344 # This one will hold the 'raw' input history, without any
345 345 # pre-processing. This will allow users to retrieve the input just as
346 346 # it was exactly typed in by the user, with %hist -r.
347 347 self.input_hist_raw = InputList(['\n'])
348 348
349 349 # list of visited directories
350 350 try:
351 351 self.dir_hist = [os.getcwd()]
352 352 except IOError, e:
353 353 self.dir_hist = []
354 354
355 355 # dict of output history
356 356 self.output_hist = {}
357 357
358 358 # dict of things NOT to alias (keywords, builtins and some magics)
359 359 no_alias = {}
360 360 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
361 361 for key in keyword.kwlist + no_alias_magics:
362 362 no_alias[key] = 1
363 363 no_alias.update(__builtin__.__dict__)
364 364 self.no_alias = no_alias
365 365
366 366 # make global variables for user access to these
367 367 self.user_ns['_ih'] = self.input_hist
368 368 self.user_ns['_oh'] = self.output_hist
369 369 self.user_ns['_dh'] = self.dir_hist
370 370
371 371 # user aliases to input and output histories
372 372 self.user_ns['In'] = self.input_hist
373 373 self.user_ns['Out'] = self.output_hist
374 374
375 375 # Object variable to store code object waiting execution. This is
376 376 # used mainly by the multithreaded shells, but it can come in handy in
377 377 # other situations. No need to use a Queue here, since it's a single
378 378 # item which gets cleared once run.
379 379 self.code_to_run = None
380 380
381 381 # escapes for automatic behavior on the command line
382 382 self.ESC_SHELL = '!'
383 383 self.ESC_HELP = '?'
384 384 self.ESC_MAGIC = '%'
385 385 self.ESC_QUOTE = ','
386 386 self.ESC_QUOTE2 = ';'
387 387 self.ESC_PAREN = '/'
388 388
389 389 # And their associated handlers
390 390 self.esc_handlers = {self.ESC_PAREN : self.handle_auto,
391 391 self.ESC_QUOTE : self.handle_auto,
392 392 self.ESC_QUOTE2 : self.handle_auto,
393 393 self.ESC_MAGIC : self.handle_magic,
394 394 self.ESC_HELP : self.handle_help,
395 395 self.ESC_SHELL : self.handle_shell_escape,
396 396 }
397 397
398 398 # class initializations
399 399 Magic.__init__(self,self)
400 400
401 401 # Python source parser/formatter for syntax highlighting
402 402 pyformat = PyColorize.Parser().format
403 403 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
404 404
405 405 # hooks holds pointers used for user-side customizations
406 406 self.hooks = Struct()
407 407
408 408 self.strdispatchers = {}
409 409
410 410 # Set all default hooks, defined in the IPython.hooks module.
411 411 hooks = IPython.hooks
412 412 for hook_name in hooks.__all__:
413 413 # default hooks have priority 100, i.e. low; user hooks should have 0-100 priority
414 414 self.set_hook(hook_name,getattr(hooks,hook_name), 100)
415 415 #print "bound hook",hook_name
416 416
417 417 # Flag to mark unconditional exit
418 418 self.exit_now = False
419 419
420 420 self.usage_min = """\
421 421 An enhanced console for Python.
422 422 Some of its features are:
423 423 - Readline support if the readline library is present.
424 424 - Tab completion in the local namespace.
425 425 - Logging of input, see command-line options.
426 426 - System shell escape via ! , eg !ls.
427 427 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
428 428 - Keeps track of locally defined variables via %who, %whos.
429 429 - Show object information with a ? eg ?x or x? (use ?? for more info).
430 430 """
431 431 if usage: self.usage = usage
432 432 else: self.usage = self.usage_min
433 433
434 434 # Storage
435 435 self.rc = rc # This will hold all configuration information
436 436 self.pager = 'less'
437 437 # temporary files used for various purposes. Deleted at exit.
438 438 self.tempfiles = []
439 439
440 440 # Keep track of readline usage (later set by init_readline)
441 441 self.has_readline = False
442 442
443 443 # template for logfile headers. It gets resolved at runtime by the
444 444 # logstart method.
445 445 self.loghead_tpl = \
446 446 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
447 447 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
448 448 #log# opts = %s
449 449 #log# args = %s
450 450 #log# It is safe to make manual edits below here.
451 451 #log#-----------------------------------------------------------------------
452 452 """
453 453 # for pushd/popd management
454 454 try:
455 455 self.home_dir = get_home_dir()
456 456 except HomeDirError,msg:
457 457 fatal(msg)
458 458
459 459 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
460 460
461 461 # Functions to call the underlying shell.
462 462
463 463 # The first is similar to os.system, but it doesn't return a value,
464 464 # and it allows interpolation of variables in the user's namespace.
465 465 self.system = lambda cmd: \
466 466 shell(self.var_expand(cmd,depth=2),
467 467 header=self.rc.system_header,
468 468 verbose=self.rc.system_verbose)
469 469
470 470 # These are for getoutput and getoutputerror:
471 471 self.getoutput = lambda cmd: \
472 472 getoutput(self.var_expand(cmd,depth=2),
473 473 header=self.rc.system_header,
474 474 verbose=self.rc.system_verbose)
475 475
476 476 self.getoutputerror = lambda cmd: \
477 477 getoutputerror(self.var_expand(cmd,depth=2),
478 478 header=self.rc.system_header,
479 479 verbose=self.rc.system_verbose)
480 480
481 481 # RegExp for splitting line contents into pre-char//first
482 482 # word-method//rest. For clarity, each group in on one line.
483 483
484 484 # WARNING: update the regexp if the above escapes are changed, as they
485 485 # are hardwired in.
486 486
487 487 # Don't get carried away with trying to make the autocalling catch too
488 488 # much: it's better to be conservative rather than to trigger hidden
489 489 # evals() somewhere and end up causing side effects.
490 490
491 491 self.line_split = re.compile(r'^([\s*,;/])'
492 492 r'([\?\w\.]+\w*\s*)'
493 493 r'(\(?.*$)')
494 494
495 # A simpler regexp used as a fallback if the above doesn't work. This
496 # one is more conservative in how it partitions the input. This code
497 # can probably be cleaned up to do everything with just one regexp, but
498 # I'm afraid of breaking something; do it once the unit tests are in
499 # place.
500 self.line_split_fallback = re.compile(r'^(\s*)'
501 r'([\w\.]*)'
502 r'(.*)')
503
495 504 # Original re, keep around for a while in case changes break something
496 505 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
497 506 # r'(\s*[\?\w\.]+\w*\s*)'
498 507 # r'(\(?.*$)')
499 508
500 509 # RegExp to identify potential function names
501 510 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
502 511
503 512 # RegExp to exclude strings with this start from autocalling. In
504 513 # particular, all binary operators should be excluded, so that if foo
505 514 # is callable, foo OP bar doesn't become foo(OP bar), which is
506 515 # invalid. The characters '!=()' don't need to be checked for, as the
507 516 # _prefilter routine explicitely does so, to catch direct calls and
508 517 # rebindings of existing names.
509 518
510 519 # Warning: the '-' HAS TO BE AT THE END of the first group, otherwise
511 520 # it affects the rest of the group in square brackets.
512 521 self.re_exclude_auto = re.compile(r'^[<>,&^\|\*/\+-]'
513 522 '|^is |^not |^in |^and |^or ')
514 523
515 524 # try to catch also methods for stuff in lists/tuples/dicts: off
516 525 # (experimental). For this to work, the line_split regexp would need
517 526 # to be modified so it wouldn't break things at '['. That line is
518 527 # nasty enough that I shouldn't change it until I can test it _well_.
519 528 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
520 529
521 530 # keep track of where we started running (mainly for crash post-mortem)
522 531 self.starting_dir = os.getcwd()
523 532
524 533 # Various switches which can be set
525 534 self.CACHELENGTH = 5000 # this is cheap, it's just text
526 535 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
527 536 self.banner2 = banner2
528 537
529 538 # TraceBack handlers:
530 539
531 540 # Syntax error handler.
532 541 self.SyntaxTB = SyntaxTB(color_scheme='NoColor')
533 542
534 543 # The interactive one is initialized with an offset, meaning we always
535 544 # want to remove the topmost item in the traceback, which is our own
536 545 # internal code. Valid modes: ['Plain','Context','Verbose']
537 546 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
538 547 color_scheme='NoColor',
539 548 tb_offset = 1)
540 549
541 550 # IPython itself shouldn't crash. This will produce a detailed
542 551 # post-mortem if it does. But we only install the crash handler for
543 552 # non-threaded shells, the threaded ones use a normal verbose reporter
544 553 # and lose the crash handler. This is because exceptions in the main
545 554 # thread (such as in GUI code) propagate directly to sys.excepthook,
546 555 # and there's no point in printing crash dumps for every user exception.
547 556 if self.isthreaded:
548 557 ipCrashHandler = ultraTB.FormattedTB()
549 558 else:
550 559 from IPython import CrashHandler
551 560 ipCrashHandler = CrashHandler.IPythonCrashHandler(self)
552 561 self.set_crash_handler(ipCrashHandler)
553 562
554 563 # and add any custom exception handlers the user may have specified
555 564 self.set_custom_exc(*custom_exceptions)
556 565
557 566 # indentation management
558 567 self.autoindent = False
559 568 self.indent_current_nsp = 0
560 569
561 570 # Make some aliases automatically
562 571 # Prepare list of shell aliases to auto-define
563 572 if os.name == 'posix':
564 573 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
565 574 'mv mv -i','rm rm -i','cp cp -i',
566 575 'cat cat','less less','clear clear',
567 576 # a better ls
568 577 'ls ls -F',
569 578 # long ls
570 579 'll ls -lF')
571 580 # Extra ls aliases with color, which need special treatment on BSD
572 581 # variants
573 582 ls_extra = ( # color ls
574 583 'lc ls -F -o --color',
575 584 # ls normal files only
576 585 'lf ls -F -o --color %l | grep ^-',
577 586 # ls symbolic links
578 587 'lk ls -F -o --color %l | grep ^l',
579 588 # directories or links to directories,
580 589 'ldir ls -F -o --color %l | grep /$',
581 590 # things which are executable
582 591 'lx ls -F -o --color %l | grep ^-..x',
583 592 )
584 593 # The BSDs don't ship GNU ls, so they don't understand the
585 594 # --color switch out of the box
586 595 if 'bsd' in sys.platform:
587 596 ls_extra = ( # ls normal files only
588 597 'lf ls -lF | grep ^-',
589 598 # ls symbolic links
590 599 'lk ls -lF | grep ^l',
591 600 # directories or links to directories,
592 601 'ldir ls -lF | grep /$',
593 602 # things which are executable
594 603 'lx ls -lF | grep ^-..x',
595 604 )
596 605 auto_alias = auto_alias + ls_extra
597 606 elif os.name in ['nt','dos']:
598 607 auto_alias = ('dir dir /on', 'ls dir /on',
599 608 'ddir dir /ad /on', 'ldir dir /ad /on',
600 609 'mkdir mkdir','rmdir rmdir','echo echo',
601 610 'ren ren','cls cls','copy copy')
602 611 else:
603 612 auto_alias = ()
604 613 self.auto_alias = [s.split(None,1) for s in auto_alias]
605 614 # Call the actual (public) initializer
606 615 self.init_auto_alias()
607 616
608 617 # Produce a public API instance
609 618 self.api = IPython.ipapi.IPApi(self)
610 619
611 620 # track which builtins we add, so we can clean up later
612 621 self.builtins_added = {}
613 622 # This method will add the necessary builtins for operation, but
614 623 # tracking what it did via the builtins_added dict.
615 624 self.add_builtins()
616 625
617 626 # end __init__
618 627
619 628 def var_expand(self,cmd,depth=0):
620 629 """Expand python variables in a string.
621 630
622 631 The depth argument indicates how many frames above the caller should
623 632 be walked to look for the local namespace where to expand variables.
624 633
625 634 The global namespace for expansion is always the user's interactive
626 635 namespace.
627 636 """
628 637
629 638 return str(ItplNS(cmd.replace('#','\#'),
630 639 self.user_ns, # globals
631 640 # Skip our own frame in searching for locals:
632 641 sys._getframe(depth+1).f_locals # locals
633 642 ))
634 643
635 644 def pre_config_initialization(self):
636 645 """Pre-configuration init method
637 646
638 647 This is called before the configuration files are processed to
639 648 prepare the services the config files might need.
640 649
641 650 self.rc already has reasonable default values at this point.
642 651 """
643 652 rc = self.rc
644 653
645 654 self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db")
646 655
647 656 def post_config_initialization(self):
648 657 """Post configuration init method
649 658
650 659 This is called after the configuration files have been processed to
651 660 'finalize' the initialization."""
652 661
653 662 rc = self.rc
654 663
655 664 # Object inspector
656 665 self.inspector = OInspect.Inspector(OInspect.InspectColors,
657 666 PyColorize.ANSICodeColors,
658 667 'NoColor',
659 668 rc.object_info_string_level)
660 669
661 670 # Load readline proper
662 671 if rc.readline:
663 672 self.init_readline()
664 673
665 674 # local shortcut, this is used a LOT
666 675 self.log = self.logger.log
667 676
668 677 # Initialize cache, set in/out prompts and printing system
669 678 self.outputcache = CachedOutput(self,
670 679 rc.cache_size,
671 680 rc.pprint,
672 681 input_sep = rc.separate_in,
673 682 output_sep = rc.separate_out,
674 683 output_sep2 = rc.separate_out2,
675 684 ps1 = rc.prompt_in1,
676 685 ps2 = rc.prompt_in2,
677 686 ps_out = rc.prompt_out,
678 687 pad_left = rc.prompts_pad_left)
679 688
680 689 # user may have over-ridden the default print hook:
681 690 try:
682 691 self.outputcache.__class__.display = self.hooks.display
683 692 except AttributeError:
684 693 pass
685 694
686 695 # I don't like assigning globally to sys, because it means when
687 696 # embedding instances, each embedded instance overrides the previous
688 697 # choice. But sys.displayhook seems to be called internally by exec,
689 698 # so I don't see a way around it. We first save the original and then
690 699 # overwrite it.
691 700 self.sys_displayhook = sys.displayhook
692 701 sys.displayhook = self.outputcache
693 702
694 703 # Set user colors (don't do it in the constructor above so that it
695 704 # doesn't crash if colors option is invalid)
696 705 self.magic_colors(rc.colors)
697 706
698 707 # Set calling of pdb on exceptions
699 708 self.call_pdb = rc.pdb
700 709
701 710 # Load user aliases
702 711 for alias in rc.alias:
703 712 self.magic_alias(alias)
704 713 self.hooks.late_startup_hook()
705 714
706 715 batchrun = False
707 716 for batchfile in [path(arg) for arg in self.rc.args
708 717 if arg.lower().endswith('.ipy')]:
709 718 if not batchfile.isfile():
710 719 print "No such batch file:", batchfile
711 720 continue
712 721 self.api.runlines(batchfile.text())
713 722 batchrun = True
714 723 if batchrun:
715 724 self.exit_now = True
716 725
717 726 def add_builtins(self):
718 727 """Store ipython references into the builtin namespace.
719 728
720 729 Some parts of ipython operate via builtins injected here, which hold a
721 730 reference to IPython itself."""
722 731
723 732 # TODO: deprecate all except _ip; 'jobs' should be installed
724 733 # by an extension and the rest are under _ip, ipalias is redundant
725 734 builtins_new = dict(__IPYTHON__ = self,
726 735 ip_set_hook = self.set_hook,
727 736 jobs = self.jobs,
728 737 ipmagic = wrap_deprecated(self.ipmagic,'_ip.magic()'),
729 738 ipalias = wrap_deprecated(self.ipalias),
730 739 ipsystem = wrap_deprecated(self.ipsystem,'_ip.system()'),
731 740 _ip = self.api
732 741 )
733 742 for biname,bival in builtins_new.items():
734 743 try:
735 744 # store the orignal value so we can restore it
736 745 self.builtins_added[biname] = __builtin__.__dict__[biname]
737 746 except KeyError:
738 747 # or mark that it wasn't defined, and we'll just delete it at
739 748 # cleanup
740 749 self.builtins_added[biname] = Undefined
741 750 __builtin__.__dict__[biname] = bival
742 751
743 752 # Keep in the builtins a flag for when IPython is active. We set it
744 753 # with setdefault so that multiple nested IPythons don't clobber one
745 754 # another. Each will increase its value by one upon being activated,
746 755 # which also gives us a way to determine the nesting level.
747 756 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
748 757
749 758 def clean_builtins(self):
750 759 """Remove any builtins which might have been added by add_builtins, or
751 760 restore overwritten ones to their previous values."""
752 761 for biname,bival in self.builtins_added.items():
753 762 if bival is Undefined:
754 763 del __builtin__.__dict__[biname]
755 764 else:
756 765 __builtin__.__dict__[biname] = bival
757 766 self.builtins_added.clear()
758 767
759 768 def set_hook(self,name,hook, priority = 50, str_key = None, re_key = None):
760 769 """set_hook(name,hook) -> sets an internal IPython hook.
761 770
762 771 IPython exposes some of its internal API as user-modifiable hooks. By
763 772 adding your function to one of these hooks, you can modify IPython's
764 773 behavior to call at runtime your own routines."""
765 774
766 775 # At some point in the future, this should validate the hook before it
767 776 # accepts it. Probably at least check that the hook takes the number
768 777 # of args it's supposed to.
769 778
770 779 f = new.instancemethod(hook,self,self.__class__)
771 780
772 781 # check if the hook is for strdispatcher first
773 782 if str_key is not None:
774 783 sdp = self.strdispatchers.get(name, StrDispatch())
775 784 sdp.add_s(str_key, f, priority )
776 785 self.strdispatchers[name] = sdp
777 786 return
778 787 if re_key is not None:
779 788 sdp = self.strdispatchers.get(name, StrDispatch())
780 789 sdp.add_re(re.compile(re_key), f, priority )
781 790 self.strdispatchers[name] = sdp
782 791 return
783 792
784 793 dp = getattr(self.hooks, name, None)
785 794 if name not in IPython.hooks.__all__:
786 795 print "Warning! Hook '%s' is not one of %s" % (name, IPython.hooks.__all__ )
787 796 if not dp:
788 797 dp = IPython.hooks.CommandChainDispatcher()
789 798
790 799 try:
791 800 dp.add(f,priority)
792 801 except AttributeError:
793 802 # it was not commandchain, plain old func - replace
794 803 dp = f
795 804
796 805 setattr(self.hooks,name, dp)
797 806
798 807
799 808 #setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
800 809
801 810 def set_crash_handler(self,crashHandler):
802 811 """Set the IPython crash handler.
803 812
804 813 This must be a callable with a signature suitable for use as
805 814 sys.excepthook."""
806 815
807 816 # Install the given crash handler as the Python exception hook
808 817 sys.excepthook = crashHandler
809 818
810 819 # The instance will store a pointer to this, so that runtime code
811 820 # (such as magics) can access it. This is because during the
812 821 # read-eval loop, it gets temporarily overwritten (to deal with GUI
813 822 # frameworks).
814 823 self.sys_excepthook = sys.excepthook
815 824
816 825
817 826 def set_custom_exc(self,exc_tuple,handler):
818 827 """set_custom_exc(exc_tuple,handler)
819 828
820 829 Set a custom exception handler, which will be called if any of the
821 830 exceptions in exc_tuple occur in the mainloop (specifically, in the
822 831 runcode() method.
823 832
824 833 Inputs:
825 834
826 835 - exc_tuple: a *tuple* of valid exceptions to call the defined
827 836 handler for. It is very important that you use a tuple, and NOT A
828 837 LIST here, because of the way Python's except statement works. If
829 838 you only want to trap a single exception, use a singleton tuple:
830 839
831 840 exc_tuple == (MyCustomException,)
832 841
833 842 - handler: this must be defined as a function with the following
834 843 basic interface: def my_handler(self,etype,value,tb).
835 844
836 845 This will be made into an instance method (via new.instancemethod)
837 846 of IPython itself, and it will be called if any of the exceptions
838 847 listed in the exc_tuple are caught. If the handler is None, an
839 848 internal basic one is used, which just prints basic info.
840 849
841 850 WARNING: by putting in your own exception handler into IPython's main
842 851 execution loop, you run a very good chance of nasty crashes. This
843 852 facility should only be used if you really know what you are doing."""
844 853
845 854 assert type(exc_tuple)==type(()) , \
846 855 "The custom exceptions must be given AS A TUPLE."
847 856
848 857 def dummy_handler(self,etype,value,tb):
849 858 print '*** Simple custom exception handler ***'
850 859 print 'Exception type :',etype
851 860 print 'Exception value:',value
852 861 print 'Traceback :',tb
853 862 print 'Source code :','\n'.join(self.buffer)
854 863
855 864 if handler is None: handler = dummy_handler
856 865
857 866 self.CustomTB = new.instancemethod(handler,self,self.__class__)
858 867 self.custom_exceptions = exc_tuple
859 868
860 869 def set_custom_completer(self,completer,pos=0):
861 870 """set_custom_completer(completer,pos=0)
862 871
863 872 Adds a new custom completer function.
864 873
865 874 The position argument (defaults to 0) is the index in the completers
866 875 list where you want the completer to be inserted."""
867 876
868 877 newcomp = new.instancemethod(completer,self.Completer,
869 878 self.Completer.__class__)
870 879 self.Completer.matchers.insert(pos,newcomp)
871 880
872 881 def _get_call_pdb(self):
873 882 return self._call_pdb
874 883
875 884 def _set_call_pdb(self,val):
876 885
877 886 if val not in (0,1,False,True):
878 887 raise ValueError,'new call_pdb value must be boolean'
879 888
880 889 # store value in instance
881 890 self._call_pdb = val
882 891
883 892 # notify the actual exception handlers
884 893 self.InteractiveTB.call_pdb = val
885 894 if self.isthreaded:
886 895 try:
887 896 self.sys_excepthook.call_pdb = val
888 897 except:
889 898 warn('Failed to activate pdb for threaded exception handler')
890 899
891 900 call_pdb = property(_get_call_pdb,_set_call_pdb,None,
892 901 'Control auto-activation of pdb at exceptions')
893 902
894 903
895 904 # These special functions get installed in the builtin namespace, to
896 905 # provide programmatic (pure python) access to magics, aliases and system
897 906 # calls. This is important for logging, user scripting, and more.
898 907
899 908 # We are basically exposing, via normal python functions, the three
900 909 # mechanisms in which ipython offers special call modes (magics for
901 910 # internal control, aliases for direct system access via pre-selected
902 911 # names, and !cmd for calling arbitrary system commands).
903 912
904 913 def ipmagic(self,arg_s):
905 914 """Call a magic function by name.
906 915
907 916 Input: a string containing the name of the magic function to call and any
908 917 additional arguments to be passed to the magic.
909 918
910 919 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
911 920 prompt:
912 921
913 922 In[1]: %name -opt foo bar
914 923
915 924 To call a magic without arguments, simply use ipmagic('name').
916 925
917 926 This provides a proper Python function to call IPython's magics in any
918 927 valid Python code you can type at the interpreter, including loops and
919 928 compound statements. It is added by IPython to the Python builtin
920 929 namespace upon initialization."""
921 930
922 931 args = arg_s.split(' ',1)
923 932 magic_name = args[0]
924 933 magic_name = magic_name.lstrip(self.ESC_MAGIC)
925 934
926 935 try:
927 936 magic_args = args[1]
928 937 except IndexError:
929 938 magic_args = ''
930 939 fn = getattr(self,'magic_'+magic_name,None)
931 940 if fn is None:
932 941 error("Magic function `%s` not found." % magic_name)
933 942 else:
934 943 magic_args = self.var_expand(magic_args,1)
935 944 return fn(magic_args)
936 945
937 946 def ipalias(self,arg_s):
938 947 """Call an alias by name.
939 948
940 949 Input: a string containing the name of the alias to call and any
941 950 additional arguments to be passed to the magic.
942 951
943 952 ipalias('name -opt foo bar') is equivalent to typing at the ipython
944 953 prompt:
945 954
946 955 In[1]: name -opt foo bar
947 956
948 957 To call an alias without arguments, simply use ipalias('name').
949 958
950 959 This provides a proper Python function to call IPython's aliases in any
951 960 valid Python code you can type at the interpreter, including loops and
952 961 compound statements. It is added by IPython to the Python builtin
953 962 namespace upon initialization."""
954 963
955 964 args = arg_s.split(' ',1)
956 965 alias_name = args[0]
957 966 try:
958 967 alias_args = args[1]
959 968 except IndexError:
960 969 alias_args = ''
961 970 if alias_name in self.alias_table:
962 971 self.call_alias(alias_name,alias_args)
963 972 else:
964 973 error("Alias `%s` not found." % alias_name)
965 974
966 975 def ipsystem(self,arg_s):
967 976 """Make a system call, using IPython."""
968 977
969 978 self.system(arg_s)
970 979
971 980 def complete(self,text):
972 981 """Return a sorted list of all possible completions on text.
973 982
974 983 Inputs:
975 984
976 985 - text: a string of text to be completed on.
977 986
978 987 This is a wrapper around the completion mechanism, similar to what
979 988 readline does at the command line when the TAB key is hit. By
980 989 exposing it as a method, it can be used by other non-readline
981 990 environments (such as GUIs) for text completion.
982 991
983 992 Simple usage example:
984 993
985 994 In [1]: x = 'hello'
986 995
987 996 In [2]: __IP.complete('x.l')
988 997 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
989 998
990 999 complete = self.Completer.complete
991 1000 state = 0
992 1001 # use a dict so we get unique keys, since ipyhton's multiple
993 1002 # completers can return duplicates.
994 1003 comps = {}
995 1004 while True:
996 1005 newcomp = complete(text,state)
997 1006 if newcomp is None:
998 1007 break
999 1008 comps[newcomp] = 1
1000 1009 state += 1
1001 1010 outcomps = comps.keys()
1002 1011 outcomps.sort()
1003 1012 return outcomps
1004 1013
1005 1014 def set_completer_frame(self, frame=None):
1006 1015 if frame:
1007 1016 self.Completer.namespace = frame.f_locals
1008 1017 self.Completer.global_namespace = frame.f_globals
1009 1018 else:
1010 1019 self.Completer.namespace = self.user_ns
1011 1020 self.Completer.global_namespace = self.user_global_ns
1012 1021
1013 1022 def init_auto_alias(self):
1014 1023 """Define some aliases automatically.
1015 1024
1016 1025 These are ALL parameter-less aliases"""
1017 1026
1018 1027 for alias,cmd in self.auto_alias:
1019 1028 self.alias_table[alias] = (0,cmd)
1020 1029
1021 1030 def alias_table_validate(self,verbose=0):
1022 1031 """Update information about the alias table.
1023 1032
1024 1033 In particular, make sure no Python keywords/builtins are in it."""
1025 1034
1026 1035 no_alias = self.no_alias
1027 1036 for k in self.alias_table.keys():
1028 1037 if k in no_alias:
1029 1038 del self.alias_table[k]
1030 1039 if verbose:
1031 1040 print ("Deleting alias <%s>, it's a Python "
1032 1041 "keyword or builtin." % k)
1033 1042
1034 1043 def set_autoindent(self,value=None):
1035 1044 """Set the autoindent flag, checking for readline support.
1036 1045
1037 1046 If called with no arguments, it acts as a toggle."""
1038 1047
1039 1048 if not self.has_readline:
1040 1049 if os.name == 'posix':
1041 1050 warn("The auto-indent feature requires the readline library")
1042 1051 self.autoindent = 0
1043 1052 return
1044 1053 if value is None:
1045 1054 self.autoindent = not self.autoindent
1046 1055 else:
1047 1056 self.autoindent = value
1048 1057
1049 1058 def rc_set_toggle(self,rc_field,value=None):
1050 1059 """Set or toggle a field in IPython's rc config. structure.
1051 1060
1052 1061 If called with no arguments, it acts as a toggle.
1053 1062
1054 1063 If called with a non-existent field, the resulting AttributeError
1055 1064 exception will propagate out."""
1056 1065
1057 1066 rc_val = getattr(self.rc,rc_field)
1058 1067 if value is None:
1059 1068 value = not rc_val
1060 1069 setattr(self.rc,rc_field,value)
1061 1070
1062 1071 def user_setup(self,ipythondir,rc_suffix,mode='install'):
1063 1072 """Install the user configuration directory.
1064 1073
1065 1074 Can be called when running for the first time or to upgrade the user's
1066 1075 .ipython/ directory with the mode parameter. Valid modes are 'install'
1067 1076 and 'upgrade'."""
1068 1077
1069 1078 def wait():
1070 1079 try:
1071 1080 raw_input("Please press <RETURN> to start IPython.")
1072 1081 except EOFError:
1073 1082 print >> Term.cout
1074 1083 print '*'*70
1075 1084
1076 1085 cwd = os.getcwd() # remember where we started
1077 1086 glb = glob.glob
1078 1087 print '*'*70
1079 1088 if mode == 'install':
1080 1089 print \
1081 1090 """Welcome to IPython. I will try to create a personal configuration directory
1082 1091 where you can customize many aspects of IPython's functionality in:\n"""
1083 1092 else:
1084 1093 print 'I am going to upgrade your configuration in:'
1085 1094
1086 1095 print ipythondir
1087 1096
1088 1097 rcdirend = os.path.join('IPython','UserConfig')
1089 1098 cfg = lambda d: os.path.join(d,rcdirend)
1090 1099 try:
1091 1100 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
1092 1101 except IOError:
1093 1102 warning = """
1094 1103 Installation error. IPython's directory was not found.
1095 1104
1096 1105 Check the following:
1097 1106
1098 1107 The ipython/IPython directory should be in a directory belonging to your
1099 1108 PYTHONPATH environment variable (that is, it should be in a directory
1100 1109 belonging to sys.path). You can copy it explicitly there or just link to it.
1101 1110
1102 1111 IPython will proceed with builtin defaults.
1103 1112 """
1104 1113 warn(warning)
1105 1114 wait()
1106 1115 return
1107 1116
1108 1117 if mode == 'install':
1109 1118 try:
1110 1119 shutil.copytree(rcdir,ipythondir)
1111 1120 os.chdir(ipythondir)
1112 1121 rc_files = glb("ipythonrc*")
1113 1122 for rc_file in rc_files:
1114 1123 os.rename(rc_file,rc_file+rc_suffix)
1115 1124 except:
1116 1125 warning = """
1117 1126
1118 1127 There was a problem with the installation:
1119 1128 %s
1120 1129 Try to correct it or contact the developers if you think it's a bug.
1121 1130 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
1122 1131 warn(warning)
1123 1132 wait()
1124 1133 return
1125 1134
1126 1135 elif mode == 'upgrade':
1127 1136 try:
1128 1137 os.chdir(ipythondir)
1129 1138 except:
1130 1139 print """
1131 1140 Can not upgrade: changing to directory %s failed. Details:
1132 1141 %s
1133 1142 """ % (ipythondir,sys.exc_info()[1])
1134 1143 wait()
1135 1144 return
1136 1145 else:
1137 1146 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
1138 1147 for new_full_path in sources:
1139 1148 new_filename = os.path.basename(new_full_path)
1140 1149 if new_filename.startswith('ipythonrc'):
1141 1150 new_filename = new_filename + rc_suffix
1142 1151 # The config directory should only contain files, skip any
1143 1152 # directories which may be there (like CVS)
1144 1153 if os.path.isdir(new_full_path):
1145 1154 continue
1146 1155 if os.path.exists(new_filename):
1147 1156 old_file = new_filename+'.old'
1148 1157 if os.path.exists(old_file):
1149 1158 os.remove(old_file)
1150 1159 os.rename(new_filename,old_file)
1151 1160 shutil.copy(new_full_path,new_filename)
1152 1161 else:
1153 1162 raise ValueError,'unrecognized mode for install:',`mode`
1154 1163
1155 1164 # Fix line-endings to those native to each platform in the config
1156 1165 # directory.
1157 1166 try:
1158 1167 os.chdir(ipythondir)
1159 1168 except:
1160 1169 print """
1161 1170 Problem: changing to directory %s failed.
1162 1171 Details:
1163 1172 %s
1164 1173
1165 1174 Some configuration files may have incorrect line endings. This should not
1166 1175 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
1167 1176 wait()
1168 1177 else:
1169 1178 for fname in glb('ipythonrc*'):
1170 1179 try:
1171 1180 native_line_ends(fname,backup=0)
1172 1181 except IOError:
1173 1182 pass
1174 1183
1175 1184 if mode == 'install':
1176 1185 print """
1177 1186 Successful installation!
1178 1187
1179 1188 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
1180 1189 IPython manual (there are both HTML and PDF versions supplied with the
1181 1190 distribution) to make sure that your system environment is properly configured
1182 1191 to take advantage of IPython's features.
1183 1192
1184 1193 Important note: the configuration system has changed! The old system is
1185 1194 still in place, but its setting may be partly overridden by the settings in
1186 1195 "~/.ipython/ipy_user_conf.py" config file. Please take a look at the file
1187 1196 if some of the new settings bother you.
1188 1197
1189 1198 """
1190 1199 else:
1191 1200 print """
1192 1201 Successful upgrade!
1193 1202
1194 1203 All files in your directory:
1195 1204 %(ipythondir)s
1196 1205 which would have been overwritten by the upgrade were backed up with a .old
1197 1206 extension. If you had made particular customizations in those files you may
1198 1207 want to merge them back into the new files.""" % locals()
1199 1208 wait()
1200 1209 os.chdir(cwd)
1201 1210 # end user_setup()
1202 1211
1203 1212 def atexit_operations(self):
1204 1213 """This will be executed at the time of exit.
1205 1214
1206 1215 Saving of persistent data should be performed here. """
1207 1216
1208 1217 #print '*** IPython exit cleanup ***' # dbg
1209 1218 # input history
1210 1219 self.savehist()
1211 1220
1212 1221 # Cleanup all tempfiles left around
1213 1222 for tfile in self.tempfiles:
1214 1223 try:
1215 1224 os.unlink(tfile)
1216 1225 except OSError:
1217 1226 pass
1218 1227
1219 1228 # save the "persistent data" catch-all dictionary
1220 1229 self.hooks.shutdown_hook()
1221 1230
1222 1231 def savehist(self):
1223 1232 """Save input history to a file (via readline library)."""
1224 1233 try:
1225 1234 self.readline.write_history_file(self.histfile)
1226 1235 except:
1227 1236 print 'Unable to save IPython command history to file: ' + \
1228 1237 `self.histfile`
1229 1238
1230 1239 def history_saving_wrapper(self, func):
1231 1240 """ Wrap func for readline history saving
1232 1241
1233 1242 Convert func into callable that saves & restores
1234 1243 history around the call """
1235 1244
1236 1245 if not self.has_readline:
1237 1246 return func
1238 1247
1239 1248 def wrapper():
1240 1249 self.savehist()
1241 1250 try:
1242 1251 func()
1243 1252 finally:
1244 1253 readline.read_history_file(self.histfile)
1245 1254 return wrapper
1246 1255
1247 1256
1248 1257 def pre_readline(self):
1249 1258 """readline hook to be used at the start of each line.
1250 1259
1251 1260 Currently it handles auto-indent only."""
1252 1261
1253 1262 #debugx('self.indent_current_nsp','pre_readline:')
1254 1263 self.readline.insert_text(self.indent_current_str())
1255 1264
1256 1265 def init_readline(self):
1257 1266 """Command history completion/saving/reloading."""
1258 1267
1259 1268 import IPython.rlineimpl as readline
1260 1269 if not readline.have_readline:
1261 1270 self.has_readline = 0
1262 1271 self.readline = None
1263 1272 # no point in bugging windows users with this every time:
1264 1273 warn('Readline services not available on this platform.')
1265 1274 else:
1266 1275 sys.modules['readline'] = readline
1267 1276 import atexit
1268 1277 from IPython.completer import IPCompleter
1269 1278 self.Completer = IPCompleter(self,
1270 1279 self.user_ns,
1271 1280 self.user_global_ns,
1272 1281 self.rc.readline_omit__names,
1273 1282 self.alias_table)
1274 1283 sdisp = self.strdispatchers.get('complete_command', StrDispatch())
1275 1284 self.strdispatchers['complete_command'] = sdisp
1276 1285 self.Completer.custom_completers = sdisp
1277 1286 # Platform-specific configuration
1278 1287 if os.name == 'nt':
1279 1288 self.readline_startup_hook = readline.set_pre_input_hook
1280 1289 else:
1281 1290 self.readline_startup_hook = readline.set_startup_hook
1282 1291
1283 1292 # Load user's initrc file (readline config)
1284 1293 inputrc_name = os.environ.get('INPUTRC')
1285 1294 if inputrc_name is None:
1286 1295 home_dir = get_home_dir()
1287 1296 if home_dir is not None:
1288 1297 inputrc_name = os.path.join(home_dir,'.inputrc')
1289 1298 if os.path.isfile(inputrc_name):
1290 1299 try:
1291 1300 readline.read_init_file(inputrc_name)
1292 1301 except:
1293 1302 warn('Problems reading readline initialization file <%s>'
1294 1303 % inputrc_name)
1295 1304
1296 1305 self.has_readline = 1
1297 1306 self.readline = readline
1298 1307 # save this in sys so embedded copies can restore it properly
1299 1308 sys.ipcompleter = self.Completer.complete
1300 1309 readline.set_completer(self.Completer.complete)
1301 1310
1302 1311 # Configure readline according to user's prefs
1303 1312 for rlcommand in self.rc.readline_parse_and_bind:
1304 1313 readline.parse_and_bind(rlcommand)
1305 1314
1306 1315 # remove some chars from the delimiters list
1307 1316 delims = readline.get_completer_delims()
1308 1317 delims = delims.translate(string._idmap,
1309 1318 self.rc.readline_remove_delims)
1310 1319 readline.set_completer_delims(delims)
1311 1320 # otherwise we end up with a monster history after a while:
1312 1321 readline.set_history_length(1000)
1313 1322 try:
1314 1323 #print '*** Reading readline history' # dbg
1315 1324 readline.read_history_file(self.histfile)
1316 1325 except IOError:
1317 1326 pass # It doesn't exist yet.
1318 1327
1319 1328 atexit.register(self.atexit_operations)
1320 1329 del atexit
1321 1330
1322 1331 # Configure auto-indent for all platforms
1323 1332 self.set_autoindent(self.rc.autoindent)
1324 1333
1325 1334 def ask_yes_no(self,prompt,default=True):
1326 1335 if self.rc.quiet:
1327 1336 return True
1328 1337 return ask_yes_no(prompt,default)
1329 1338
1330 1339 def _should_recompile(self,e):
1331 1340 """Utility routine for edit_syntax_error"""
1332 1341
1333 1342 if e.filename in ('<ipython console>','<input>','<string>',
1334 1343 '<console>','<BackgroundJob compilation>',
1335 1344 None):
1336 1345
1337 1346 return False
1338 1347 try:
1339 1348 if (self.rc.autoedit_syntax and
1340 1349 not self.ask_yes_no('Return to editor to correct syntax error? '
1341 1350 '[Y/n] ','y')):
1342 1351 return False
1343 1352 except EOFError:
1344 1353 return False
1345 1354
1346 1355 def int0(x):
1347 1356 try:
1348 1357 return int(x)
1349 1358 except TypeError:
1350 1359 return 0
1351 1360 # always pass integer line and offset values to editor hook
1352 1361 self.hooks.fix_error_editor(e.filename,
1353 1362 int0(e.lineno),int0(e.offset),e.msg)
1354 1363 return True
1355 1364
1356 1365 def edit_syntax_error(self):
1357 1366 """The bottom half of the syntax error handler called in the main loop.
1358 1367
1359 1368 Loop until syntax error is fixed or user cancels.
1360 1369 """
1361 1370
1362 1371 while self.SyntaxTB.last_syntax_error:
1363 1372 # copy and clear last_syntax_error
1364 1373 err = self.SyntaxTB.clear_err_state()
1365 1374 if not self._should_recompile(err):
1366 1375 return
1367 1376 try:
1368 1377 # may set last_syntax_error again if a SyntaxError is raised
1369 1378 self.safe_execfile(err.filename,self.user_ns)
1370 1379 except:
1371 1380 self.showtraceback()
1372 1381 else:
1373 1382 try:
1374 1383 f = file(err.filename)
1375 1384 try:
1376 1385 sys.displayhook(f.read())
1377 1386 finally:
1378 1387 f.close()
1379 1388 except:
1380 1389 self.showtraceback()
1381 1390
1382 1391 def showsyntaxerror(self, filename=None):
1383 1392 """Display the syntax error that just occurred.
1384 1393
1385 1394 This doesn't display a stack trace because there isn't one.
1386 1395
1387 1396 If a filename is given, it is stuffed in the exception instead
1388 1397 of what was there before (because Python's parser always uses
1389 1398 "<string>" when reading from a string).
1390 1399 """
1391 1400 etype, value, last_traceback = sys.exc_info()
1392 1401
1393 1402 # See note about these variables in showtraceback() below
1394 1403 sys.last_type = etype
1395 1404 sys.last_value = value
1396 1405 sys.last_traceback = last_traceback
1397 1406
1398 1407 if filename and etype is SyntaxError:
1399 1408 # Work hard to stuff the correct filename in the exception
1400 1409 try:
1401 1410 msg, (dummy_filename, lineno, offset, line) = value
1402 1411 except:
1403 1412 # Not the format we expect; leave it alone
1404 1413 pass
1405 1414 else:
1406 1415 # Stuff in the right filename
1407 1416 try:
1408 1417 # Assume SyntaxError is a class exception
1409 1418 value = SyntaxError(msg, (filename, lineno, offset, line))
1410 1419 except:
1411 1420 # If that failed, assume SyntaxError is a string
1412 1421 value = msg, (filename, lineno, offset, line)
1413 1422 self.SyntaxTB(etype,value,[])
1414 1423
1415 1424 def debugger(self,force=False):
1416 1425 """Call the pydb/pdb debugger.
1417 1426
1418 1427 Keywords:
1419 1428
1420 1429 - force(False): by default, this routine checks the instance call_pdb
1421 1430 flag and does not actually invoke the debugger if the flag is false.
1422 1431 The 'force' option forces the debugger to activate even if the flag
1423 1432 is false.
1424 1433 """
1425 1434
1426 1435 if not (force or self.call_pdb):
1427 1436 return
1428 1437
1429 1438 if not hasattr(sys,'last_traceback'):
1430 1439 error('No traceback has been produced, nothing to debug.')
1431 1440 return
1432 1441
1433 1442 have_pydb = False
1434 1443 # use pydb if available
1435 1444 try:
1436 1445 from pydb import pm
1437 1446 have_pydb = True
1438 1447 except ImportError:
1439 1448 pass
1440 1449 if not have_pydb:
1441 1450 # fallback to our internal debugger
1442 1451 pm = lambda : self.InteractiveTB.debugger(force=True)
1443 1452 self.history_saving_wrapper(pm)()
1444 1453
1445 1454 def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None):
1446 1455 """Display the exception that just occurred.
1447 1456
1448 1457 If nothing is known about the exception, this is the method which
1449 1458 should be used throughout the code for presenting user tracebacks,
1450 1459 rather than directly invoking the InteractiveTB object.
1451 1460
1452 1461 A specific showsyntaxerror() also exists, but this method can take
1453 1462 care of calling it if needed, so unless you are explicitly catching a
1454 1463 SyntaxError exception, don't try to analyze the stack manually and
1455 1464 simply call this method."""
1456 1465
1457 1466 # Though this won't be called by syntax errors in the input line,
1458 1467 # there may be SyntaxError cases whith imported code.
1459 1468 if exc_tuple is None:
1460 1469 etype, value, tb = sys.exc_info()
1461 1470 else:
1462 1471 etype, value, tb = exc_tuple
1463 1472
1464 1473 if etype is SyntaxError:
1465 1474 self.showsyntaxerror(filename)
1466 1475 else:
1467 1476 # WARNING: these variables are somewhat deprecated and not
1468 1477 # necessarily safe to use in a threaded environment, but tools
1469 1478 # like pdb depend on their existence, so let's set them. If we
1470 1479 # find problems in the field, we'll need to revisit their use.
1471 1480 sys.last_type = etype
1472 1481 sys.last_value = value
1473 1482 sys.last_traceback = tb
1474 1483
1475 1484 if etype in self.custom_exceptions:
1476 1485 self.CustomTB(etype,value,tb)
1477 1486 else:
1478 1487 self.InteractiveTB(etype,value,tb,tb_offset=tb_offset)
1479 1488 if self.InteractiveTB.call_pdb and self.has_readline:
1480 1489 # pdb mucks up readline, fix it back
1481 1490 self.readline.set_completer(self.Completer.complete)
1482 1491
1483 1492 def mainloop(self,banner=None):
1484 1493 """Creates the local namespace and starts the mainloop.
1485 1494
1486 1495 If an optional banner argument is given, it will override the
1487 1496 internally created default banner."""
1488 1497
1489 1498 if self.rc.c: # Emulate Python's -c option
1490 1499 self.exec_init_cmd()
1491 1500 if banner is None:
1492 1501 if not self.rc.banner:
1493 1502 banner = ''
1494 1503 # banner is string? Use it directly!
1495 1504 elif isinstance(self.rc.banner,basestring):
1496 1505 banner = self.rc.banner
1497 1506 else:
1498 1507 banner = self.BANNER+self.banner2
1499 1508
1500 1509 self.interact(banner)
1501 1510
1502 1511 def exec_init_cmd(self):
1503 1512 """Execute a command given at the command line.
1504 1513
1505 1514 This emulates Python's -c option."""
1506 1515
1507 1516 #sys.argv = ['-c']
1508 1517 self.push(self.rc.c)
1509 1518
1510 1519 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1511 1520 """Embeds IPython into a running python program.
1512 1521
1513 1522 Input:
1514 1523
1515 1524 - header: An optional header message can be specified.
1516 1525
1517 1526 - local_ns, global_ns: working namespaces. If given as None, the
1518 1527 IPython-initialized one is updated with __main__.__dict__, so that
1519 1528 program variables become visible but user-specific configuration
1520 1529 remains possible.
1521 1530
1522 1531 - stack_depth: specifies how many levels in the stack to go to
1523 1532 looking for namespaces (when local_ns and global_ns are None). This
1524 1533 allows an intermediate caller to make sure that this function gets
1525 1534 the namespace from the intended level in the stack. By default (0)
1526 1535 it will get its locals and globals from the immediate caller.
1527 1536
1528 1537 Warning: it's possible to use this in a program which is being run by
1529 1538 IPython itself (via %run), but some funny things will happen (a few
1530 1539 globals get overwritten). In the future this will be cleaned up, as
1531 1540 there is no fundamental reason why it can't work perfectly."""
1532 1541
1533 1542 # Get locals and globals from caller
1534 1543 if local_ns is None or global_ns is None:
1535 1544 call_frame = sys._getframe(stack_depth).f_back
1536 1545
1537 1546 if local_ns is None:
1538 1547 local_ns = call_frame.f_locals
1539 1548 if global_ns is None:
1540 1549 global_ns = call_frame.f_globals
1541 1550
1542 1551 # Update namespaces and fire up interpreter
1543 1552
1544 1553 # The global one is easy, we can just throw it in
1545 1554 self.user_global_ns = global_ns
1546 1555
1547 1556 # but the user/local one is tricky: ipython needs it to store internal
1548 1557 # data, but we also need the locals. We'll copy locals in the user
1549 1558 # one, but will track what got copied so we can delete them at exit.
1550 1559 # This is so that a later embedded call doesn't see locals from a
1551 1560 # previous call (which most likely existed in a separate scope).
1552 1561 local_varnames = local_ns.keys()
1553 1562 self.user_ns.update(local_ns)
1554 1563
1555 1564 # Patch for global embedding to make sure that things don't overwrite
1556 1565 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1557 1566 # FIXME. Test this a bit more carefully (the if.. is new)
1558 1567 if local_ns is None and global_ns is None:
1559 1568 self.user_global_ns.update(__main__.__dict__)
1560 1569
1561 1570 # make sure the tab-completer has the correct frame information, so it
1562 1571 # actually completes using the frame's locals/globals
1563 1572 self.set_completer_frame()
1564 1573
1565 1574 # before activating the interactive mode, we need to make sure that
1566 1575 # all names in the builtin namespace needed by ipython point to
1567 1576 # ourselves, and not to other instances.
1568 1577 self.add_builtins()
1569 1578
1570 1579 self.interact(header)
1571 1580
1572 1581 # now, purge out the user namespace from anything we might have added
1573 1582 # from the caller's local namespace
1574 1583 delvar = self.user_ns.pop
1575 1584 for var in local_varnames:
1576 1585 delvar(var,None)
1577 1586 # and clean builtins we may have overridden
1578 1587 self.clean_builtins()
1579 1588
1580 1589 def interact(self, banner=None):
1581 1590 """Closely emulate the interactive Python console.
1582 1591
1583 1592 The optional banner argument specify the banner to print
1584 1593 before the first interaction; by default it prints a banner
1585 1594 similar to the one printed by the real Python interpreter,
1586 1595 followed by the current class name in parentheses (so as not
1587 1596 to confuse this with the real interpreter -- since it's so
1588 1597 close!).
1589 1598
1590 1599 """
1591 1600
1592 1601 if self.exit_now:
1593 1602 # batch run -> do not interact
1594 1603 return
1595 1604 cprt = 'Type "copyright", "credits" or "license" for more information.'
1596 1605 if banner is None:
1597 1606 self.write("Python %s on %s\n%s\n(%s)\n" %
1598 1607 (sys.version, sys.platform, cprt,
1599 1608 self.__class__.__name__))
1600 1609 else:
1601 1610 self.write(banner)
1602 1611
1603 1612 more = 0
1604 1613
1605 1614 # Mark activity in the builtins
1606 1615 __builtin__.__dict__['__IPYTHON__active'] += 1
1607 1616
1608 1617 # exit_now is set by a call to %Exit or %Quit
1609 1618 while not self.exit_now:
1610 1619 if more:
1611 1620 prompt = self.hooks.generate_prompt(True)
1612 1621 if self.autoindent:
1613 1622 self.readline_startup_hook(self.pre_readline)
1614 1623 else:
1615 1624 prompt = self.hooks.generate_prompt(False)
1616 1625 try:
1617 1626 line = self.raw_input(prompt,more)
1618 1627 if self.exit_now:
1619 1628 # quick exit on sys.std[in|out] close
1620 1629 break
1621 1630 if self.autoindent:
1622 1631 self.readline_startup_hook(None)
1623 1632 except KeyboardInterrupt:
1624 1633 self.write('\nKeyboardInterrupt\n')
1625 1634 self.resetbuffer()
1626 1635 # keep cache in sync with the prompt counter:
1627 1636 self.outputcache.prompt_count -= 1
1628 1637
1629 1638 if self.autoindent:
1630 1639 self.indent_current_nsp = 0
1631 1640 more = 0
1632 1641 except EOFError:
1633 1642 if self.autoindent:
1634 1643 self.readline_startup_hook(None)
1635 1644 self.write('\n')
1636 1645 self.exit()
1637 1646 except bdb.BdbQuit:
1638 1647 warn('The Python debugger has exited with a BdbQuit exception.\n'
1639 1648 'Because of how pdb handles the stack, it is impossible\n'
1640 1649 'for IPython to properly format this particular exception.\n'
1641 1650 'IPython will resume normal operation.')
1642 1651 except:
1643 1652 # exceptions here are VERY RARE, but they can be triggered
1644 1653 # asynchronously by signal handlers, for example.
1645 1654 self.showtraceback()
1646 1655 else:
1647 1656 more = self.push(line)
1648 1657 if (self.SyntaxTB.last_syntax_error and
1649 1658 self.rc.autoedit_syntax):
1650 1659 self.edit_syntax_error()
1651 1660
1652 1661 # We are off again...
1653 1662 __builtin__.__dict__['__IPYTHON__active'] -= 1
1654 1663
1655 1664 def excepthook(self, etype, value, tb):
1656 1665 """One more defense for GUI apps that call sys.excepthook.
1657 1666
1658 1667 GUI frameworks like wxPython trap exceptions and call
1659 1668 sys.excepthook themselves. I guess this is a feature that
1660 1669 enables them to keep running after exceptions that would
1661 1670 otherwise kill their mainloop. This is a bother for IPython
1662 1671 which excepts to catch all of the program exceptions with a try:
1663 1672 except: statement.
1664 1673
1665 1674 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1666 1675 any app directly invokes sys.excepthook, it will look to the user like
1667 1676 IPython crashed. In order to work around this, we can disable the
1668 1677 CrashHandler and replace it with this excepthook instead, which prints a
1669 1678 regular traceback using our InteractiveTB. In this fashion, apps which
1670 1679 call sys.excepthook will generate a regular-looking exception from
1671 1680 IPython, and the CrashHandler will only be triggered by real IPython
1672 1681 crashes.
1673 1682
1674 1683 This hook should be used sparingly, only in places which are not likely
1675 1684 to be true IPython errors.
1676 1685 """
1677 1686 self.showtraceback((etype,value,tb),tb_offset=0)
1678 1687
1679 1688 def expand_aliases(self,fn,rest):
1680 1689 """ Expand multiple levels of aliases:
1681 1690
1682 1691 if:
1683 1692
1684 1693 alias foo bar /tmp
1685 1694 alias baz foo
1686 1695
1687 1696 then:
1688 1697
1689 1698 baz huhhahhei -> bar /tmp huhhahhei
1690 1699
1691 1700 """
1692 1701 line = fn + " " + rest
1693 1702
1694 1703 done = Set()
1695 1704 while 1:
1696 1705 pre,fn,rest = self.split_user_input(line)
1697 1706 if fn in self.alias_table:
1698 1707 if fn in done:
1699 1708 warn("Cyclic alias definition, repeated '%s'" % fn)
1700 1709 return ""
1701 1710 done.add(fn)
1702 1711
1703 1712 l2 = self.transform_alias(fn,rest)
1704 1713 # dir -> dir
1705 1714 # print "alias",line, "->",l2 #dbg
1706 1715 if l2 == line:
1707 1716 break
1708 1717 # ls -> ls -F should not recurse forever
1709 1718 if l2.split(None,1)[0] == line.split(None,1)[0]:
1710 1719 line = l2
1711 1720 break
1712 1721
1713 1722 line=l2
1714 1723
1715 1724
1716 1725 # print "al expand to",line #dbg
1717 1726 else:
1718 1727 break
1719 1728
1720 1729 return line
1721 1730
1722 1731 def transform_alias(self, alias,rest=''):
1723 1732 """ Transform alias to system command string.
1724 1733 """
1725 1734 nargs,cmd = self.alias_table[alias]
1726 1735 if ' ' in cmd and os.path.isfile(cmd):
1727 1736 cmd = '"%s"' % cmd
1728 1737
1729 1738 # Expand the %l special to be the user's input line
1730 1739 if cmd.find('%l') >= 0:
1731 1740 cmd = cmd.replace('%l',rest)
1732 1741 rest = ''
1733 1742 if nargs==0:
1734 1743 # Simple, argument-less aliases
1735 1744 cmd = '%s %s' % (cmd,rest)
1736 1745 else:
1737 1746 # Handle aliases with positional arguments
1738 1747 args = rest.split(None,nargs)
1739 1748 if len(args)< nargs:
1740 1749 error('Alias <%s> requires %s arguments, %s given.' %
1741 1750 (alias,nargs,len(args)))
1742 1751 return None
1743 1752 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1744 1753 # Now call the macro, evaluating in the user's namespace
1745 1754 #print 'new command: <%r>' % cmd # dbg
1746 1755 return cmd
1747 1756
1748 1757 def call_alias(self,alias,rest=''):
1749 1758 """Call an alias given its name and the rest of the line.
1750 1759
1751 1760 This is only used to provide backwards compatibility for users of
1752 1761 ipalias(), use of which is not recommended for anymore."""
1753 1762
1754 1763 # Now call the macro, evaluating in the user's namespace
1755 1764 cmd = self.transform_alias(alias, rest)
1756 1765 try:
1757 1766 self.system(cmd)
1758 1767 except:
1759 1768 self.showtraceback()
1760 1769
1761 1770 def indent_current_str(self):
1762 1771 """return the current level of indentation as a string"""
1763 1772 return self.indent_current_nsp * ' '
1764 1773
1765 1774 def autoindent_update(self,line):
1766 1775 """Keep track of the indent level."""
1767 1776
1768 1777 #debugx('line')
1769 1778 #debugx('self.indent_current_nsp')
1770 1779 if self.autoindent:
1771 1780 if line:
1772 1781 inisp = num_ini_spaces(line)
1773 1782 if inisp < self.indent_current_nsp:
1774 1783 self.indent_current_nsp = inisp
1775 1784
1776 1785 if line[-1] == ':':
1777 1786 self.indent_current_nsp += 4
1778 1787 elif dedent_re.match(line):
1779 1788 self.indent_current_nsp -= 4
1780 1789 else:
1781 1790 self.indent_current_nsp = 0
1782 1791
1783 1792 def runlines(self,lines):
1784 1793 """Run a string of one or more lines of source.
1785 1794
1786 1795 This method is capable of running a string containing multiple source
1787 1796 lines, as if they had been entered at the IPython prompt. Since it
1788 1797 exposes IPython's processing machinery, the given strings can contain
1789 1798 magic calls (%magic), special shell access (!cmd), etc."""
1790 1799
1791 1800 # We must start with a clean buffer, in case this is run from an
1792 1801 # interactive IPython session (via a magic, for example).
1793 1802 self.resetbuffer()
1794 1803 lines = lines.split('\n')
1795 1804 more = 0
1796 1805 for line in lines:
1797 1806 # skip blank lines so we don't mess up the prompt counter, but do
1798 1807 # NOT skip even a blank line if we are in a code block (more is
1799 1808 # true)
1800 1809 if line or more:
1801 1810 more = self.push(self.prefilter(line,more))
1802 1811 # IPython's runsource returns None if there was an error
1803 1812 # compiling the code. This allows us to stop processing right
1804 1813 # away, so the user gets the error message at the right place.
1805 1814 if more is None:
1806 1815 break
1807 1816 # final newline in case the input didn't have it, so that the code
1808 1817 # actually does get executed
1809 1818 if more:
1810 1819 self.push('\n')
1811 1820
1812 1821 def runsource(self, source, filename='<input>', symbol='single'):
1813 1822 """Compile and run some source in the interpreter.
1814 1823
1815 1824 Arguments are as for compile_command().
1816 1825
1817 1826 One several things can happen:
1818 1827
1819 1828 1) The input is incorrect; compile_command() raised an
1820 1829 exception (SyntaxError or OverflowError). A syntax traceback
1821 1830 will be printed by calling the showsyntaxerror() method.
1822 1831
1823 1832 2) The input is incomplete, and more input is required;
1824 1833 compile_command() returned None. Nothing happens.
1825 1834
1826 1835 3) The input is complete; compile_command() returned a code
1827 1836 object. The code is executed by calling self.runcode() (which
1828 1837 also handles run-time exceptions, except for SystemExit).
1829 1838
1830 1839 The return value is:
1831 1840
1832 1841 - True in case 2
1833 1842
1834 1843 - False in the other cases, unless an exception is raised, where
1835 1844 None is returned instead. This can be used by external callers to
1836 1845 know whether to continue feeding input or not.
1837 1846
1838 1847 The return value can be used to decide whether to use sys.ps1 or
1839 1848 sys.ps2 to prompt the next line."""
1840 1849
1841 1850 # if the source code has leading blanks, add 'if 1:\n' to it
1842 1851 # this allows execution of indented pasted code. It is tempting
1843 1852 # to add '\n' at the end of source to run commands like ' a=1'
1844 1853 # directly, but this fails for more complicated scenarios
1845 1854 if source[:1] in [' ', '\t']:
1846 1855 source = 'if 1:\n%s' % source
1847 1856
1848 1857 try:
1849 1858 code = self.compile(source,filename,symbol)
1850 1859 except (OverflowError, SyntaxError, ValueError):
1851 1860 # Case 1
1852 1861 self.showsyntaxerror(filename)
1853 1862 return None
1854 1863
1855 1864 if code is None:
1856 1865 # Case 2
1857 1866 return True
1858 1867
1859 1868 # Case 3
1860 1869 # We store the code object so that threaded shells and
1861 1870 # custom exception handlers can access all this info if needed.
1862 1871 # The source corresponding to this can be obtained from the
1863 1872 # buffer attribute as '\n'.join(self.buffer).
1864 1873 self.code_to_run = code
1865 1874 # now actually execute the code object
1866 1875 if self.runcode(code) == 0:
1867 1876 return False
1868 1877 else:
1869 1878 return None
1870 1879
1871 1880 def runcode(self,code_obj):
1872 1881 """Execute a code object.
1873 1882
1874 1883 When an exception occurs, self.showtraceback() is called to display a
1875 1884 traceback.
1876 1885
1877 1886 Return value: a flag indicating whether the code to be run completed
1878 1887 successfully:
1879 1888
1880 1889 - 0: successful execution.
1881 1890 - 1: an error occurred.
1882 1891 """
1883 1892
1884 1893 # Set our own excepthook in case the user code tries to call it
1885 1894 # directly, so that the IPython crash handler doesn't get triggered
1886 1895 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1887 1896
1888 1897 # we save the original sys.excepthook in the instance, in case config
1889 1898 # code (such as magics) needs access to it.
1890 1899 self.sys_excepthook = old_excepthook
1891 1900 outflag = 1 # happens in more places, so it's easier as default
1892 1901 try:
1893 1902 try:
1894 1903 # Embedded instances require separate global/local namespaces
1895 1904 # so they can see both the surrounding (local) namespace and
1896 1905 # the module-level globals when called inside another function.
1897 1906 if self.embedded:
1898 1907 exec code_obj in self.user_global_ns, self.user_ns
1899 1908 # Normal (non-embedded) instances should only have a single
1900 1909 # namespace for user code execution, otherwise functions won't
1901 1910 # see interactive top-level globals.
1902 1911 else:
1903 1912 exec code_obj in self.user_ns
1904 1913 finally:
1905 1914 # Reset our crash handler in place
1906 1915 sys.excepthook = old_excepthook
1907 1916 except SystemExit:
1908 1917 self.resetbuffer()
1909 1918 self.showtraceback()
1910 1919 warn("Type %exit or %quit to exit IPython "
1911 1920 "(%Exit or %Quit do so unconditionally).",level=1)
1912 1921 except self.custom_exceptions:
1913 1922 etype,value,tb = sys.exc_info()
1914 1923 self.CustomTB(etype,value,tb)
1915 1924 except:
1916 1925 self.showtraceback()
1917 1926 else:
1918 1927 outflag = 0
1919 1928 if softspace(sys.stdout, 0):
1920 1929 print
1921 1930 # Flush out code object which has been run (and source)
1922 1931 self.code_to_run = None
1923 1932 return outflag
1924 1933
1925 1934 def push(self, line):
1926 1935 """Push a line to the interpreter.
1927 1936
1928 1937 The line should not have a trailing newline; it may have
1929 1938 internal newlines. The line is appended to a buffer and the
1930 1939 interpreter's runsource() method is called with the
1931 1940 concatenated contents of the buffer as source. If this
1932 1941 indicates that the command was executed or invalid, the buffer
1933 1942 is reset; otherwise, the command is incomplete, and the buffer
1934 1943 is left as it was after the line was appended. The return
1935 1944 value is 1 if more input is required, 0 if the line was dealt
1936 1945 with in some way (this is the same as runsource()).
1937 1946 """
1938 1947
1939 1948 # autoindent management should be done here, and not in the
1940 1949 # interactive loop, since that one is only seen by keyboard input. We
1941 1950 # need this done correctly even for code run via runlines (which uses
1942 1951 # push).
1943 1952
1944 1953 #print 'push line: <%s>' % line # dbg
1945 1954 for subline in line.splitlines():
1946 1955 self.autoindent_update(subline)
1947 1956 self.buffer.append(line)
1948 1957 more = self.runsource('\n'.join(self.buffer), self.filename)
1949 1958 if not more:
1950 1959 self.resetbuffer()
1951 1960 return more
1952 1961
1953 1962 def resetbuffer(self):
1954 1963 """Reset the input buffer."""
1955 1964 self.buffer[:] = []
1956 1965
1957 1966 def raw_input(self,prompt='',continue_prompt=False):
1958 1967 """Write a prompt and read a line.
1959 1968
1960 1969 The returned line does not include the trailing newline.
1961 1970 When the user enters the EOF key sequence, EOFError is raised.
1962 1971
1963 1972 Optional inputs:
1964 1973
1965 1974 - prompt(''): a string to be printed to prompt the user.
1966 1975
1967 1976 - continue_prompt(False): whether this line is the first one or a
1968 1977 continuation in a sequence of inputs.
1969 1978 """
1970 1979
1971 1980 try:
1972 1981 line = raw_input_original(prompt)
1973 1982 except ValueError:
1974 1983 warn("\n********\nYou or a %run:ed script called sys.stdin.close() or sys.stdout.close()!\nExiting IPython!")
1975 1984 self.exit_now = True
1976 1985 return ""
1977 1986
1978 1987
1979 1988 # Try to be reasonably smart about not re-indenting pasted input more
1980 1989 # than necessary. We do this by trimming out the auto-indent initial
1981 1990 # spaces, if the user's actual input started itself with whitespace.
1982 1991 #debugx('self.buffer[-1]')
1983 1992
1984 1993 if self.autoindent:
1985 1994 if num_ini_spaces(line) > self.indent_current_nsp:
1986 1995 line = line[self.indent_current_nsp:]
1987 1996 self.indent_current_nsp = 0
1988 1997
1989 1998 # store the unfiltered input before the user has any chance to modify
1990 1999 # it.
1991 2000 if line.strip():
1992 2001 if continue_prompt:
1993 2002 self.input_hist_raw[-1] += '%s\n' % line
1994 2003 if self.has_readline: # and some config option is set?
1995 2004 try:
1996 2005 histlen = self.readline.get_current_history_length()
1997 2006 newhist = self.input_hist_raw[-1].rstrip()
1998 2007 self.readline.remove_history_item(histlen-1)
1999 2008 self.readline.replace_history_item(histlen-2,newhist)
2000 2009 except AttributeError:
2001 2010 pass # re{move,place}_history_item are new in 2.4.
2002 2011 else:
2003 2012 self.input_hist_raw.append('%s\n' % line)
2004 2013
2005 2014 try:
2006 2015 lineout = self.prefilter(line,continue_prompt)
2007 2016 except:
2008 2017 # blanket except, in case a user-defined prefilter crashes, so it
2009 2018 # can't take all of ipython with it.
2010 2019 self.showtraceback()
2011 2020 return ''
2012 2021 else:
2013 2022 return lineout
2014 2023
2015 2024 def split_user_input(self,line):
2016 2025 """Split user input into pre-char, function part and rest."""
2017 2026
2018 2027 lsplit = self.line_split.match(line)
2019 2028 if lsplit is None: # no regexp match returns None
2020 try:
2021 iFun,theRest = line.split(None,1)
2022 except ValueError:
2023 iFun,theRest = line,''
2024 pre = re.match('^(\s*)(.*)',line).groups()[0]
2025 else:
2026 pre,iFun,theRest = lsplit.groups()
2029 lsplit = self.line_split_fallback.match(line)
2027 2030
2031 #pre,iFun,theRest = lsplit.groups() # dbg
2028 2032 #print 'line:<%s>' % line # dbg
2029 2033 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
2030 return pre,iFun.strip(),theRest
2034 #return pre,iFun.strip(),theRest # dbg
2035
2036 return lsplit.groups()
2031 2037
2032 2038 def _prefilter(self, line, continue_prompt):
2033 2039 """Calls different preprocessors, depending on the form of line."""
2034 2040
2035 2041 # All handlers *must* return a value, even if it's blank ('').
2036 2042
2037 2043 # Lines are NOT logged here. Handlers should process the line as
2038 2044 # needed, update the cache AND log it (so that the input cache array
2039 2045 # stays synced).
2040 2046
2041 2047 # This function is _very_ delicate, and since it's also the one which
2042 2048 # determines IPython's response to user input, it must be as efficient
2043 2049 # as possible. For this reason it has _many_ returns in it, trying
2044 2050 # always to exit as quickly as it can figure out what it needs to do.
2045 2051
2046 2052 # This function is the main responsible for maintaining IPython's
2047 2053 # behavior respectful of Python's semantics. So be _very_ careful if
2048 2054 # making changes to anything here.
2049 2055
2050 2056 #.....................................................................
2051 2057 # Code begins
2052 2058
2053 2059 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
2054 2060
2055 2061 # save the line away in case we crash, so the post-mortem handler can
2056 2062 # record it
2057 2063 self._last_input_line = line
2058 2064
2059 2065 #print '***line: <%s>' % line # dbg
2060 2066
2061 2067 # the input history needs to track even empty lines
2062 2068 stripped = line.strip()
2063 2069
2064 2070 if not stripped:
2065 2071 if not continue_prompt:
2066 2072 self.outputcache.prompt_count -= 1
2067 2073 return self.handle_normal(line,continue_prompt)
2068 2074 #return self.handle_normal('',continue_prompt)
2069 2075
2070 2076 # print '***cont',continue_prompt # dbg
2071 2077 # special handlers are only allowed for single line statements
2072 2078 if continue_prompt and not self.rc.multi_line_specials:
2073 2079 return self.handle_normal(line,continue_prompt)
2074 2080
2075 2081
2076 2082 # For the rest, we need the structure of the input
2077 2083 pre,iFun,theRest = self.split_user_input(line)
2078 2084
2079 2085 # See whether any pre-existing handler can take care of it
2080 2086
2081 2087 rewritten = self.hooks.input_prefilter(stripped)
2082 2088 if rewritten != stripped: # ok, some prefilter did something
2083 2089 rewritten = pre + rewritten # add indentation
2084 2090 return self.handle_normal(rewritten)
2085 2091
2086 2092 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
2087 2093
2088 2094 # First check for explicit escapes in the last/first character
2089 2095 handler = None
2090 2096 if line[-1] == self.ESC_HELP:
2091 2097 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
2092 2098 if handler is None:
2093 2099 # look at the first character of iFun, NOT of line, so we skip
2094 2100 # leading whitespace in multiline input
2095 2101 handler = self.esc_handlers.get(iFun[0:1])
2096 2102 if handler is not None:
2097 2103 return handler(line,continue_prompt,pre,iFun,theRest)
2098 2104 # Emacs ipython-mode tags certain input lines
2099 2105 if line.endswith('# PYTHON-MODE'):
2100 2106 return self.handle_emacs(line,continue_prompt)
2101 2107
2102 2108 # Next, check if we can automatically execute this thing
2103 2109
2104 2110 # Allow ! in multi-line statements if multi_line_specials is on:
2105 2111 if continue_prompt and self.rc.multi_line_specials and \
2106 2112 iFun.startswith(self.ESC_SHELL):
2107 2113 return self.handle_shell_escape(line,continue_prompt,
2108 2114 pre=pre,iFun=iFun,
2109 2115 theRest=theRest)
2110 2116
2111 2117 # Let's try to find if the input line is a magic fn
2112 2118 oinfo = None
2113 2119 if hasattr(self,'magic_'+iFun):
2114 2120 # WARNING: _ofind uses getattr(), so it can consume generators and
2115 2121 # cause other side effects.
2116 2122 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
2117 2123 if oinfo['ismagic']:
2118 2124 # Be careful not to call magics when a variable assignment is
2119 2125 # being made (ls='hi', for example)
2120 2126 if self.rc.automagic and \
2121 2127 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
2122 2128 (self.rc.multi_line_specials or not continue_prompt):
2123 2129 return self.handle_magic(line,continue_prompt,
2124 2130 pre,iFun,theRest)
2125 2131 else:
2126 2132 return self.handle_normal(line,continue_prompt)
2127 2133
2128 2134 # If the rest of the line begins with an (in)equality, assginment or
2129 2135 # function call, we should not call _ofind but simply execute it.
2130 2136 # This avoids spurious geattr() accesses on objects upon assignment.
2131 2137 #
2132 2138 # It also allows users to assign to either alias or magic names true
2133 2139 # python variables (the magic/alias systems always take second seat to
2134 2140 # true python code).
2135 2141 if theRest and theRest[0] in '!=()':
2136 2142 return self.handle_normal(line,continue_prompt)
2137 2143
2138 2144 if oinfo is None:
2139 2145 # let's try to ensure that _oinfo is ONLY called when autocall is
2140 2146 # on. Since it has inevitable potential side effects, at least
2141 2147 # having autocall off should be a guarantee to the user that no
2142 2148 # weird things will happen.
2143 2149
2144 2150 if self.rc.autocall:
2145 2151 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
2146 2152 else:
2147 2153 # in this case, all that's left is either an alias or
2148 2154 # processing the line normally.
2149 2155 if iFun in self.alias_table:
2150 2156 # if autocall is off, by not running _ofind we won't know
2151 2157 # whether the given name may also exist in one of the
2152 2158 # user's namespace. At this point, it's best to do a
2153 2159 # quick check just to be sure that we don't let aliases
2154 2160 # shadow variables.
2155 2161 head = iFun.split('.',1)[0]
2156 2162 if head in self.user_ns or head in self.internal_ns \
2157 2163 or head in __builtin__.__dict__:
2158 2164 return self.handle_normal(line,continue_prompt)
2159 2165 else:
2160 2166 return self.handle_alias(line,continue_prompt,
2161 2167 pre,iFun,theRest)
2162 2168
2163 2169 else:
2164 2170 return self.handle_normal(line,continue_prompt)
2165 2171
2166 2172 if not oinfo['found']:
2167 2173 return self.handle_normal(line,continue_prompt)
2168 2174 else:
2169 2175 #print 'pre<%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
2170 2176 if oinfo['isalias']:
2171 2177 return self.handle_alias(line,continue_prompt,
2172 2178 pre,iFun,theRest)
2173 2179
2174 2180 if (self.rc.autocall
2175 2181 and
2176 2182 (
2177 2183 #only consider exclusion re if not "," or ";" autoquoting
2178 2184 (pre == self.ESC_QUOTE or pre == self.ESC_QUOTE2
2179 2185 or pre == self.ESC_PAREN) or
2180 2186 (not self.re_exclude_auto.match(theRest)))
2181 2187 and
2182 2188 self.re_fun_name.match(iFun) and
2183 2189 callable(oinfo['obj'])) :
2184 2190 #print 'going auto' # dbg
2185 2191 return self.handle_auto(line,continue_prompt,
2186 2192 pre,iFun,theRest,oinfo['obj'])
2187 2193 else:
2188 2194 #print 'was callable?', callable(oinfo['obj']) # dbg
2189 2195 return self.handle_normal(line,continue_prompt)
2190 2196
2191 2197 # If we get here, we have a normal Python line. Log and return.
2192 2198 return self.handle_normal(line,continue_prompt)
2193 2199
2194 2200 def _prefilter_dumb(self, line, continue_prompt):
2195 2201 """simple prefilter function, for debugging"""
2196 2202 return self.handle_normal(line,continue_prompt)
2197 2203
2198 2204
2199 2205 def multiline_prefilter(self, line, continue_prompt):
2200 2206 """ Run _prefilter for each line of input
2201 2207
2202 2208 Covers cases where there are multiple lines in the user entry,
2203 2209 which is the case when the user goes back to a multiline history
2204 2210 entry and presses enter.
2205 2211
2206 2212 """
2207 2213 out = []
2208 2214 for l in line.rstrip('\n').split('\n'):
2209 2215 out.append(self._prefilter(l, continue_prompt))
2210 2216 return '\n'.join(out)
2211 2217
2212 2218 # Set the default prefilter() function (this can be user-overridden)
2213 2219 prefilter = multiline_prefilter
2214 2220
2215 2221 def handle_normal(self,line,continue_prompt=None,
2216 2222 pre=None,iFun=None,theRest=None):
2217 2223 """Handle normal input lines. Use as a template for handlers."""
2218 2224
2219 2225 # With autoindent on, we need some way to exit the input loop, and I
2220 2226 # don't want to force the user to have to backspace all the way to
2221 2227 # clear the line. The rule will be in this case, that either two
2222 2228 # lines of pure whitespace in a row, or a line of pure whitespace but
2223 2229 # of a size different to the indent level, will exit the input loop.
2224 2230
2225 2231 if (continue_prompt and self.autoindent and line.isspace() and
2226 2232 (0 < abs(len(line) - self.indent_current_nsp) <= 2 or
2227 2233 (self.buffer[-1]).isspace() )):
2228 2234 line = ''
2229 2235
2230 2236 self.log(line,line,continue_prompt)
2231 2237 return line
2232 2238
2233 2239 def handle_alias(self,line,continue_prompt=None,
2234 2240 pre=None,iFun=None,theRest=None):
2235 2241 """Handle alias input lines. """
2236 2242
2237 2243 # pre is needed, because it carries the leading whitespace. Otherwise
2238 2244 # aliases won't work in indented sections.
2239 2245 transformed = self.expand_aliases(iFun, theRest)
2240 2246 line_out = '%s_ip.system(%s)' % (pre, make_quoted_expr( transformed ))
2241 2247 self.log(line,line_out,continue_prompt)
2242 2248 #print 'line out:',line_out # dbg
2243 2249 return line_out
2244 2250
2245 2251 def handle_shell_escape(self, line, continue_prompt=None,
2246 2252 pre=None,iFun=None,theRest=None):
2247 2253 """Execute the line in a shell, empty return value"""
2248 2254
2249 2255 #print 'line in :', `line` # dbg
2250 2256 # Example of a special handler. Others follow a similar pattern.
2251 2257 if line.lstrip().startswith('!!'):
2252 2258 # rewrite iFun/theRest to properly hold the call to %sx and
2253 2259 # the actual command to be executed, so handle_magic can work
2254 2260 # correctly
2255 2261 theRest = '%s %s' % (iFun[2:],theRest)
2256 2262 iFun = 'sx'
2257 2263 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,
2258 2264 line.lstrip()[2:]),
2259 2265 continue_prompt,pre,iFun,theRest)
2260 2266 else:
2261 2267 cmd=line.lstrip().lstrip('!')
2262 2268 line_out = '%s_ip.system(%s)' % (pre,make_quoted_expr(cmd))
2263 2269 # update cache/log and return
2264 2270 self.log(line,line_out,continue_prompt)
2265 2271 return line_out
2266 2272
2267 2273 def handle_magic(self, line, continue_prompt=None,
2268 2274 pre=None,iFun=None,theRest=None):
2269 2275 """Execute magic functions."""
2270 2276
2271 2277
2272 2278 cmd = '%s_ip.magic(%s)' % (pre,make_quoted_expr(iFun + " " + theRest))
2273 2279 self.log(line,cmd,continue_prompt)
2274 2280 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
2275 2281 return cmd
2276 2282
2277 2283 def handle_auto(self, line, continue_prompt=None,
2278 2284 pre=None,iFun=None,theRest=None,obj=None):
2279 2285 """Hande lines which can be auto-executed, quoting if requested."""
2280 2286
2281 2287 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
2282 2288
2283 2289 # This should only be active for single-line input!
2284 2290 if continue_prompt:
2285 2291 self.log(line,line,continue_prompt)
2286 2292 return line
2287 2293
2288 2294 auto_rewrite = True
2289 2295
2290 2296 if pre == self.ESC_QUOTE:
2291 2297 # Auto-quote splitting on whitespace
2292 2298 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
2293 2299 elif pre == self.ESC_QUOTE2:
2294 2300 # Auto-quote whole string
2295 2301 newcmd = '%s("%s")' % (iFun,theRest)
2296 2302 elif pre == self.ESC_PAREN:
2297 2303 newcmd = '%s(%s)' % (iFun,",".join(theRest.split()))
2298 2304 else:
2299 2305 # Auto-paren.
2300 2306 # We only apply it to argument-less calls if the autocall
2301 2307 # parameter is set to 2. We only need to check that autocall is <
2302 2308 # 2, since this function isn't called unless it's at least 1.
2303 2309 if not theRest and (self.rc.autocall < 2):
2304 2310 newcmd = '%s %s' % (iFun,theRest)
2305 2311 auto_rewrite = False
2306 2312 else:
2307 2313 if theRest.startswith('['):
2308 2314 if hasattr(obj,'__getitem__'):
2309 2315 # Don't autocall in this case: item access for an object
2310 2316 # which is BOTH callable and implements __getitem__.
2311 2317 newcmd = '%s %s' % (iFun,theRest)
2312 2318 auto_rewrite = False
2313 2319 else:
2314 2320 # if the object doesn't support [] access, go ahead and
2315 2321 # autocall
2316 2322 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
2317 2323 elif theRest.endswith(';'):
2318 2324 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
2319 2325 else:
2320 2326 newcmd = '%s(%s)' % (iFun.rstrip(), theRest)
2321 2327
2322 2328 if auto_rewrite:
2323 2329 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
2324 2330 # log what is now valid Python, not the actual user input (without the
2325 2331 # final newline)
2326 2332 self.log(line,newcmd,continue_prompt)
2327 2333 return newcmd
2328 2334
2329 2335 def handle_help(self, line, continue_prompt=None,
2330 2336 pre=None,iFun=None,theRest=None):
2331 2337 """Try to get some help for the object.
2332 2338
2333 2339 obj? or ?obj -> basic information.
2334 2340 obj?? or ??obj -> more details.
2335 2341 """
2336 2342
2337 2343 # We need to make sure that we don't process lines which would be
2338 2344 # otherwise valid python, such as "x=1 # what?"
2339 2345 try:
2340 2346 codeop.compile_command(line)
2341 2347 except SyntaxError:
2342 2348 # We should only handle as help stuff which is NOT valid syntax
2343 2349 if line[0]==self.ESC_HELP:
2344 2350 line = line[1:]
2345 2351 elif line[-1]==self.ESC_HELP:
2346 2352 line = line[:-1]
2347 2353 self.log(line,'#?'+line,continue_prompt)
2348 2354 if line:
2349 2355 self.magic_pinfo(line)
2350 2356 else:
2351 2357 page(self.usage,screen_lines=self.rc.screen_length)
2352 2358 return '' # Empty string is needed here!
2353 2359 except:
2354 2360 # Pass any other exceptions through to the normal handler
2355 2361 return self.handle_normal(line,continue_prompt)
2356 2362 else:
2357 2363 # If the code compiles ok, we should handle it normally
2358 2364 return self.handle_normal(line,continue_prompt)
2359 2365
2360 2366 def getapi(self):
2361 2367 """ Get an IPApi object for this shell instance
2362 2368
2363 2369 Getting an IPApi object is always preferable to accessing the shell
2364 2370 directly, but this holds true especially for extensions.
2365 2371
2366 2372 It should always be possible to implement an extension with IPApi
2367 2373 alone. If not, contact maintainer to request an addition.
2368 2374
2369 2375 """
2370 2376 return self.api
2371 2377
2372 2378 def handle_emacs(self,line,continue_prompt=None,
2373 2379 pre=None,iFun=None,theRest=None):
2374 2380 """Handle input lines marked by python-mode."""
2375 2381
2376 2382 # Currently, nothing is done. Later more functionality can be added
2377 2383 # here if needed.
2378 2384
2379 2385 # The input cache shouldn't be updated
2380 2386
2381 2387 return line
2382 2388
2383 2389 def mktempfile(self,data=None):
2384 2390 """Make a new tempfile and return its filename.
2385 2391
2386 2392 This makes a call to tempfile.mktemp, but it registers the created
2387 2393 filename internally so ipython cleans it up at exit time.
2388 2394
2389 2395 Optional inputs:
2390 2396
2391 2397 - data(None): if data is given, it gets written out to the temp file
2392 2398 immediately, and the file is closed again."""
2393 2399
2394 2400 filename = tempfile.mktemp('.py','ipython_edit_')
2395 2401 self.tempfiles.append(filename)
2396 2402
2397 2403 if data:
2398 2404 tmp_file = open(filename,'w')
2399 2405 tmp_file.write(data)
2400 2406 tmp_file.close()
2401 2407 return filename
2402 2408
2403 2409 def write(self,data):
2404 2410 """Write a string to the default output"""
2405 2411 Term.cout.write(data)
2406 2412
2407 2413 def write_err(self,data):
2408 2414 """Write a string to the default error output"""
2409 2415 Term.cerr.write(data)
2410 2416
2411 2417 def exit(self):
2412 2418 """Handle interactive exit.
2413 2419
2414 2420 This method sets the exit_now attribute."""
2415 2421
2416 2422 if self.rc.confirm_exit:
2417 2423 if self.ask_yes_no('Do you really want to exit ([y]/n)?','y'):
2418 2424 self.exit_now = True
2419 2425 else:
2420 2426 self.exit_now = True
2421 2427
2422 2428 def safe_execfile(self,fname,*where,**kw):
2423 2429 """A safe version of the builtin execfile().
2424 2430
2425 2431 This version will never throw an exception, and knows how to handle
2426 2432 ipython logs as well."""
2427 2433
2428 2434 def syspath_cleanup():
2429 2435 """Internal cleanup routine for sys.path."""
2430 2436 if add_dname:
2431 2437 try:
2432 2438 sys.path.remove(dname)
2433 2439 except ValueError:
2434 2440 # For some reason the user has already removed it, ignore.
2435 2441 pass
2436 2442
2437 2443 fname = os.path.expanduser(fname)
2438 2444
2439 2445 # Find things also in current directory. This is needed to mimic the
2440 2446 # behavior of running a script from the system command line, where
2441 2447 # Python inserts the script's directory into sys.path
2442 2448 dname = os.path.dirname(os.path.abspath(fname))
2443 2449 add_dname = False
2444 2450 if dname not in sys.path:
2445 2451 sys.path.insert(0,dname)
2446 2452 add_dname = True
2447 2453
2448 2454 try:
2449 2455 xfile = open(fname)
2450 2456 except:
2451 2457 print >> Term.cerr, \
2452 2458 'Could not open file <%s> for safe execution.' % fname
2453 2459 syspath_cleanup()
2454 2460 return None
2455 2461
2456 2462 kw.setdefault('islog',0)
2457 2463 kw.setdefault('quiet',1)
2458 2464 kw.setdefault('exit_ignore',0)
2459 2465 first = xfile.readline()
2460 2466 loghead = str(self.loghead_tpl).split('\n',1)[0].strip()
2461 2467 xfile.close()
2462 2468 # line by line execution
2463 2469 if first.startswith(loghead) or kw['islog']:
2464 2470 print 'Loading log file <%s> one line at a time...' % fname
2465 2471 if kw['quiet']:
2466 2472 stdout_save = sys.stdout
2467 2473 sys.stdout = StringIO.StringIO()
2468 2474 try:
2469 2475 globs,locs = where[0:2]
2470 2476 except:
2471 2477 try:
2472 2478 globs = locs = where[0]
2473 2479 except:
2474 2480 globs = locs = globals()
2475 2481 badblocks = []
2476 2482
2477 2483 # we also need to identify indented blocks of code when replaying
2478 2484 # logs and put them together before passing them to an exec
2479 2485 # statement. This takes a bit of regexp and look-ahead work in the
2480 2486 # file. It's easiest if we swallow the whole thing in memory
2481 2487 # first, and manually walk through the lines list moving the
2482 2488 # counter ourselves.
2483 2489 indent_re = re.compile('\s+\S')
2484 2490 xfile = open(fname)
2485 2491 filelines = xfile.readlines()
2486 2492 xfile.close()
2487 2493 nlines = len(filelines)
2488 2494 lnum = 0
2489 2495 while lnum < nlines:
2490 2496 line = filelines[lnum]
2491 2497 lnum += 1
2492 2498 # don't re-insert logger status info into cache
2493 2499 if line.startswith('#log#'):
2494 2500 continue
2495 2501 else:
2496 2502 # build a block of code (maybe a single line) for execution
2497 2503 block = line
2498 2504 try:
2499 2505 next = filelines[lnum] # lnum has already incremented
2500 2506 except:
2501 2507 next = None
2502 2508 while next and indent_re.match(next):
2503 2509 block += next
2504 2510 lnum += 1
2505 2511 try:
2506 2512 next = filelines[lnum]
2507 2513 except:
2508 2514 next = None
2509 2515 # now execute the block of one or more lines
2510 2516 try:
2511 2517 exec block in globs,locs
2512 2518 except SystemExit:
2513 2519 pass
2514 2520 except:
2515 2521 badblocks.append(block.rstrip())
2516 2522 if kw['quiet']: # restore stdout
2517 2523 sys.stdout.close()
2518 2524 sys.stdout = stdout_save
2519 2525 print 'Finished replaying log file <%s>' % fname
2520 2526 if badblocks:
2521 2527 print >> sys.stderr, ('\nThe following lines/blocks in file '
2522 2528 '<%s> reported errors:' % fname)
2523 2529
2524 2530 for badline in badblocks:
2525 2531 print >> sys.stderr, badline
2526 2532 else: # regular file execution
2527 2533 try:
2528 2534 execfile(fname,*where)
2529 2535 except SyntaxError:
2530 2536 self.showsyntaxerror()
2531 2537 warn('Failure executing file: <%s>' % fname)
2532 2538 except SystemExit,status:
2533 2539 if not kw['exit_ignore']:
2534 2540 self.showtraceback()
2535 2541 warn('Failure executing file: <%s>' % fname)
2536 2542 except:
2537 2543 self.showtraceback()
2538 2544 warn('Failure executing file: <%s>' % fname)
2539 2545
2540 2546 syspath_cleanup()
2541 2547
2542 2548 #************************* end of file <iplib.py> *****************************
@@ -1,6251 +1,6257 b''
1 2007-02-28 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/iplib.py (split_user_input): fix input splitting so we
4 don't attempt attribute accesses on things that can't possibly be
5 valid Python attributes. After a bug report by Alex Schmolck.
6
1 7 2007-02-27 Fernando Perez <Fernando.Perez@colorado.edu>
2 8
3 9 * IPython/Shell.py (IPShellGTK.mainloop): update threads calls to
4 10 avoid a DeprecationWarning from GTK.
5 11
6 12 2007-02-22 Fernando Perez <Fernando.Perez@colorado.edu>
7 13
8 14 * IPython/genutils.py (clock): I modified clock() to return total
9 15 time, user+system. This is a more commonly needed metric. I also
10 16 introduced the new clocku/clocks to get only user/system time if
11 17 one wants those instead.
12 18
13 19 ***WARNING: API CHANGE*** clock() used to return only user time,
14 20 so if you want exactly the same results as before, use clocku
15 21 instead.
16 22
17 23 2007-02-22 Ville Vainio <vivainio@gmail.com>
18 24
19 25 * IPython/Extensions/ipy_p4.py: Extension for improved
20 26 p4 (perforce version control system) experience.
21 27 Adds %p4 magic with p4 command completion and
22 28 automatic -G argument (marshall output as python dict)
23 29
24 30 2007-02-19 Fernando Perez <Fernando.Perez@colorado.edu>
25 31
26 32 * IPython/demo.py (Demo.re_stop): make dashes optional in demo
27 33 stop marks.
28 34 (ClearingMixin): a simple mixin to easily make a Demo class clear
29 35 the screen in between blocks and have empty marquees. The
30 36 ClearDemo and ClearIPDemo classes that use it are included.
31 37
32 38 2007-02-18 Fernando Perez <Fernando.Perez@colorado.edu>
33 39
34 40 * IPython/irunner.py (pexpect_monkeypatch): patch pexpect to
35 41 protect against exceptions at Python shutdown time. Patch
36 42 sumbmitted to upstream.
37 43
38 44 2007-02-14 Walter Doerwald <walter@livinglogic.de>
39 45
40 46 * IPython/Extensions/ibrowse.py: If entering the first object level
41 47 (i.e. the object for which the browser has been started) fails,
42 48 now the error is raised directly (aborting the browser) instead of
43 49 running into an empty levels list later.
44 50
45 51 2007-02-03 Walter Doerwald <walter@livinglogic.de>
46 52
47 53 * IPython/Extensions/ipipe.py: Add an xrepr implementation
48 54 for the noitem object.
49 55
50 56 2007-01-31 Fernando Perez <Fernando.Perez@colorado.edu>
51 57
52 58 * IPython/completer.py (Completer.attr_matches): Fix small
53 59 tab-completion bug with Enthought Traits objects with units.
54 60 Thanks to a bug report by Tom Denniston
55 61 <tom.denniston-AT-alum.dartmouth.org>.
56 62
57 63 2007-01-27 Fernando Perez <Fernando.Perez@colorado.edu>
58 64
59 65 * IPython/Extensions/ipy_stock_completers.py (runlistpy): fix a
60 66 bug where only .ipy or .py would be completed. Once the first
61 67 argument to %run has been given, all completions are valid because
62 68 they are the arguments to the script, which may well be non-python
63 69 filenames.
64 70
65 71 * IPython/irunner.py (InteractiveRunner.run_source): major updates
66 72 to irunner to allow it to correctly support real doctesting of
67 73 out-of-process ipython code.
68 74
69 75 * IPython/Magic.py (magic_cd): Make the setting of the terminal
70 76 title an option (-noterm_title) because it completely breaks
71 77 doctesting.
72 78
73 79 * IPython/demo.py: fix IPythonDemo class that was not actually working.
74 80
75 81 2007-01-24 Fernando Perez <Fernando.Perez@colorado.edu>
76 82
77 83 * IPython/irunner.py (main): fix small bug where extensions were
78 84 not being correctly recognized.
79 85
80 86 2007-01-23 Walter Doerwald <walter@livinglogic.de>
81 87
82 88 * IPython/Extensions/ipipe.py (xiter): Make sure that iterating
83 89 a string containing a single line yields the string itself as the
84 90 only item.
85 91
86 92 * IPython/Extensions/ibrowse.py (ibrowse): Avoid entering an
87 93 object if it's the same as the one on the last level (This avoids
88 94 infinite recursion for one line strings).
89 95
90 96 2007-01-17 Fernando Perez <Fernando.Perez@colorado.edu>
91 97
92 98 * IPython/ultraTB.py (AutoFormattedTB.__call__): properly flush
93 99 all output streams before printing tracebacks. This ensures that
94 100 user output doesn't end up interleaved with traceback output.
95 101
96 102 2007-01-10 Ville Vainio <vivainio@gmail.com>
97 103
98 104 * Extensions/envpersist.py: Turbocharged %env that remembers
99 105 env vars across sessions; e.g. "%env PATH+=;/opt/scripts" or
100 106 "%env VISUAL=jed".
101 107
102 108 2007-01-05 Fernando Perez <Fernando.Perez@colorado.edu>
103 109
104 110 * IPython/iplib.py (showtraceback): ensure that we correctly call
105 111 custom handlers in all cases (some with pdb were slipping through,
106 112 but I'm not exactly sure why).
107 113
108 114 * IPython/Debugger.py (Tracer.__init__): added new class to
109 115 support set_trace-like usage of IPython's enhanced debugger.
110 116
111 117 2006-12-24 Ville Vainio <vivainio@gmail.com>
112 118
113 119 * ipmaker.py: more informative message when ipy_user_conf
114 120 import fails (suggest running %upgrade).
115 121
116 122 * tools/run_ipy_in_profiler.py: Utility to see where
117 123 the time during IPython startup is spent.
118 124
119 125 2006-12-20 Ville Vainio <vivainio@gmail.com>
120 126
121 127 * 0.7.3 is out - merge all from 0.7.3 branch to trunk
122 128
123 129 * ipapi.py: Add new ipapi method, expand_alias.
124 130
125 131 * Release.py: Bump up version to 0.7.4.svn
126 132
127 133 2006-12-17 Ville Vainio <vivainio@gmail.com>
128 134
129 135 * Extensions/jobctrl.py: Fixed &cmd arg arg...
130 136 to work properly on posix too
131 137
132 138 * Release.py: Update revnum (version is still just 0.7.3).
133 139
134 140 2006-12-15 Ville Vainio <vivainio@gmail.com>
135 141
136 142 * scripts/ipython_win_post_install: create ipython.py in
137 143 prefix + "/scripts".
138 144
139 145 * Release.py: Update version to 0.7.3.
140 146
141 147 2006-12-14 Ville Vainio <vivainio@gmail.com>
142 148
143 149 * scripts/ipython_win_post_install: Overwrite old shortcuts
144 150 if they already exist
145 151
146 152 * Release.py: release 0.7.3rc2
147 153
148 154 2006-12-13 Ville Vainio <vivainio@gmail.com>
149 155
150 156 * Branch and update Release.py for 0.7.3rc1
151 157
152 158 2006-12-13 Fernando Perez <Fernando.Perez@colorado.edu>
153 159
154 160 * IPython/Shell.py (IPShellWX): update for current WX naming
155 161 conventions, to avoid a deprecation warning with current WX
156 162 versions. Thanks to a report by Danny Shevitz.
157 163
158 164 2006-12-12 Ville Vainio <vivainio@gmail.com>
159 165
160 166 * ipmaker.py: apply david cournapeau's patch to make
161 167 import_some work properly even when ipythonrc does
162 168 import_some on empty list (it was an old bug!).
163 169
164 170 * UserConfig/ipy_user_conf.py, UserConfig/ipythonrc:
165 171 Add deprecation note to ipythonrc and a url to wiki
166 172 in ipy_user_conf.py
167 173
168 174
169 175 * Magic.py (%run): %run myscript.ipy now runs myscript.ipy
170 176 as if it was typed on IPython command prompt, i.e.
171 177 as IPython script.
172 178
173 179 * example-magic.py, magic_grepl.py: remove outdated examples
174 180
175 181 2006-12-11 Fernando Perez <Fernando.Perez@colorado.edu>
176 182
177 183 * IPython/iplib.py (debugger): prevent a nasty traceback if %debug
178 184 is called before any exception has occurred.
179 185
180 186 2006-12-08 Ville Vainio <vivainio@gmail.com>
181 187
182 188 * Extensions/ipy_stock_completers.py: fix cd completer
183 189 to translate /'s to \'s again.
184 190
185 191 * completer.py: prevent traceback on file completions w/
186 192 backslash.
187 193
188 194 * Release.py: Update release number to 0.7.3b3 for release
189 195
190 196 2006-12-07 Ville Vainio <vivainio@gmail.com>
191 197
192 198 * Extensions/ipy_signals.py: Ignore ctrl+C in IPython process
193 199 while executing external code. Provides more shell-like behaviour
194 200 and overall better response to ctrl + C / ctrl + break.
195 201
196 202 * tools/make_tarball.py: new script to create tarball straight from svn
197 203 (setup.py sdist doesn't work on win32).
198 204
199 205 * Extensions/ipy_stock_completers.py: fix cd completer to give up
200 206 on dirnames with spaces and use the default completer instead.
201 207
202 208 * Revision.py: Change version to 0.7.3b2 for release.
203 209
204 210 2006-12-05 Ville Vainio <vivainio@gmail.com>
205 211
206 212 * Magic.py, iplib.py, completer.py: Apply R. Bernstein's
207 213 pydb patch 4 (rm debug printing, py 2.5 checking)
208 214
209 215 2006-11-30 Walter Doerwald <walter@livinglogic.de>
210 216 * IPython/Extensions/ibrowse.py: Add two new commands to ibrowse:
211 217 "refresh" (mapped to "r") refreshes the screen by restarting the iterator.
212 218 "refreshfind" (mapped to "R") does the same but tries to go back to the same
213 219 object the cursor was on before the refresh. The command "markrange" is
214 220 mapped to "%" now.
215 221 * IPython/Extensions/ibrowse.py: Make igrpentry and ipwdentry comparable.
216 222
217 223 2006-11-29 Fernando Perez <Fernando.Perez@colorado.edu>
218 224
219 225 * IPython/Magic.py (magic_debug): new %debug magic to activate the
220 226 interactive debugger on the last traceback, without having to call
221 227 %pdb and rerun your code. Made minor changes in various modules,
222 228 should automatically recognize pydb if available.
223 229
224 230 2006-11-28 Ville Vainio <vivainio@gmail.com>
225 231
226 232 * completer.py: If the text start with !, show file completions
227 233 properly. This helps when trying to complete command name
228 234 for shell escapes.
229 235
230 236 2006-11-27 Ville Vainio <vivainio@gmail.com>
231 237
232 238 * ipy_stock_completers.py: bzr completer submitted by Stefan van
233 239 der Walt. Clean up svn and hg completers by using a common
234 240 vcs_completer.
235 241
236 242 2006-11-26 Ville Vainio <vivainio@gmail.com>
237 243
238 244 * Remove ipconfig and %config; you should use _ip.options structure
239 245 directly instead!
240 246
241 247 * genutils.py: add wrap_deprecated function for deprecating callables
242 248
243 249 * iplib.py: deprecate ipmagic, ipsystem, ipalias. Use _ip.magic and
244 250 _ip.system instead. ipalias is redundant.
245 251
246 252 * Magic.py: %rehashdir no longer aliases 'cmdname' to 'cmdname.exe' on
247 253 win32, but just 'cmdname'. Other extensions (non-'exe') are still made
248 254 explicit.
249 255
250 256 * ipy_stock_completers.py: 'hg' (mercurial VCS) now has a custom
251 257 completer. Try it by entering 'hg ' and pressing tab.
252 258
253 259 * macro.py: Give Macro a useful __repr__ method
254 260
255 261 * Magic.py: %whos abbreviates the typename of Macro for brevity.
256 262
257 263 2006-11-24 Walter Doerwald <walter@livinglogic.de>
258 264 * IPython/Extensions/astyle.py: Do a relative import of ipipe, so that
259 265 we don't get a duplicate ipipe module, where registration of the xrepr
260 266 implementation for Text is useless.
261 267
262 268 * IPython/Extensions/ipipe.py: Fix __xrepr__() implementation for ils.
263 269
264 270 * IPython/Extensions/ibrowse.py: Fix keymapping for the enter command.
265 271
266 272 2006-11-24 Ville Vainio <vivainio@gmail.com>
267 273
268 274 * Magic.py, manual_base.lyx: Kirill Smelkov patch:
269 275 try to use "cProfile" instead of the slower pure python
270 276 "profile"
271 277
272 278 2006-11-23 Ville Vainio <vivainio@gmail.com>
273 279
274 280 * manual_base.lyx: Kirill Smelkov patch: Fix wrong
275 281 Qt+IPython+Designer link in documentation.
276 282
277 283 * Extensions/ipy_pydb.py: R. Bernstein's patch for passing
278 284 correct Pdb object to %pydb.
279 285
280 286
281 287 2006-11-22 Walter Doerwald <walter@livinglogic.de>
282 288 * IPython/Extensions/astyle.py: Text needs it's own implemenation of the
283 289 generic xrepr(), otherwise the list implementation would kick in.
284 290
285 291 2006-11-21 Ville Vainio <vivainio@gmail.com>
286 292
287 293 * upgrade_dir.py: Now actually overwrites a nonmodified user file
288 294 with one from UserConfig.
289 295
290 296 * ipy_profile_sh.py: Add dummy "depth" to var_expand lambda,
291 297 it was missing which broke the sh profile.
292 298
293 299 * completer.py: file completer now uses explicit '/' instead
294 300 of os.path.join, expansion of 'foo' was broken on win32
295 301 if there was one directory with name 'foobar'.
296 302
297 303 * A bunch of patches from Kirill Smelkov:
298 304
299 305 * [patch 9/9] doc: point bug-tracker URL to IPythons trac-tickets.
300 306
301 307 * [patch 7/9] Implement %page -r (page in raw mode) -
302 308
303 309 * [patch 5/9] ScientificPython webpage has moved
304 310
305 311 * [patch 4/9] The manual mentions %ds, should be %dhist
306 312
307 313 * [patch 3/9] Kill old bits from %prun doc.
308 314
309 315 * [patch 1/9] Fix typos here and there.
310 316
311 317 2006-11-08 Ville Vainio <vivainio@gmail.com>
312 318
313 319 * completer.py (attr_matches): catch all exceptions raised
314 320 by eval of expr with dots.
315 321
316 322 2006-11-07 Fernando Perez <Fernando.Perez@colorado.edu>
317 323
318 324 * IPython/iplib.py (runsource): Prepend an 'if 1:' to the user
319 325 input if it starts with whitespace. This allows you to paste
320 326 indented input from any editor without manually having to type in
321 327 the 'if 1:', which is convenient when working interactively.
322 328 Slightly modifed version of a patch by Bo Peng
323 329 <bpeng-AT-rice.edu>.
324 330
325 331 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu>
326 332
327 333 * IPython/irunner.py (main): modified irunner so it automatically
328 334 recognizes the right runner to use based on the extension (.py for
329 335 python, .ipy for ipython and .sage for sage).
330 336
331 337 * IPython/iplib.py (InteractiveShell.ipconfig): new builtin, also
332 338 visible in ipapi as ip.config(), to programatically control the
333 339 internal rc object. There's an accompanying %config magic for
334 340 interactive use, which has been enhanced to match the
335 341 funtionality in ipconfig.
336 342
337 343 * IPython/Magic.py (magic_system_verbose): Change %system_verbose
338 344 so it's not just a toggle, it now takes an argument. Add support
339 345 for a customizable header when making system calls, as the new
340 346 system_header variable in the ipythonrc file.
341 347
342 348 2006-11-03 Walter Doerwald <walter@livinglogic.de>
343 349
344 350 * IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now
345 351 generic functions (using Philip J. Eby's simplegeneric package).
346 352 This makes it possible to customize the display of third-party classes
347 353 without having to monkeypatch them. xiter() no longer supports a mode
348 354 argument and the XMode class has been removed. The same functionality can
349 355 be implemented via IterAttributeDescriptor and IterMethodDescriptor.
350 356 One consequence of the switch to generic functions is that xrepr() and
351 357 xattrs() implementation must define the default value for the mode
352 358 argument themselves and xattrs() implementations must return real
353 359 descriptors.
354 360
355 361 * IPython/external: This new subpackage will contain all third-party
356 362 packages that are bundled with IPython. (The first one is simplegeneric).
357 363
358 364 * IPython/Extensions/ipipe.py (ifile/ils): Readd output of the parent
359 365 directory which as been dropped in r1703.
360 366
361 367 * IPython/Extensions/ipipe.py (iless): Fixed.
362 368
363 369 * IPython/Extensions/ibrowse: Fixed sorting under Python 2.3.
364 370
365 371 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu>
366 372
367 373 * IPython/iplib.py (InteractiveShell.var_expand): fix stack
368 374 handling in variable expansion so that shells and magics recognize
369 375 function local scopes correctly. Bug reported by Brian.
370 376
371 377 * scripts/ipython: remove the very first entry in sys.path which
372 378 Python auto-inserts for scripts, so that sys.path under IPython is
373 379 as similar as possible to that under plain Python.
374 380
375 381 * IPython/completer.py (IPCompleter.file_matches): Fix
376 382 tab-completion so that quotes are not closed unless the completion
377 383 is unambiguous. After a request by Stefan. Minor cleanups in
378 384 ipy_stock_completers.
379 385
380 386 2006-11-02 Ville Vainio <vivainio@gmail.com>
381 387
382 388 * ipy_stock_completers.py: Add %run and %cd completers.
383 389
384 390 * completer.py: Try running custom completer for both
385 391 "foo" and "%foo" if the command is just "foo". Ignore case
386 392 when filtering possible completions.
387 393
388 394 * UserConfig/ipy_user_conf.py: install stock completers as default
389 395
390 396 * iplib.py (history_saving_wrapper), debugger(), ipy_pydb.py:
391 397 simplified readline history save / restore through a wrapper
392 398 function
393 399
394 400
395 401 2006-10-31 Ville Vainio <vivainio@gmail.com>
396 402
397 403 * strdispatch.py, completer.py, ipy_stock_completers.py:
398 404 Allow str_key ("command") in completer hooks. Implement
399 405 trivial completer for 'import' (stdlib modules only). Rename
400 406 ipy_linux_package_managers.py to ipy_stock_completers.py.
401 407 SVN completer.
402 408
403 409 * Extensions/ledit.py: %magic line editor for easily and
404 410 incrementally manipulating lists of strings. The magic command
405 411 name is %led.
406 412
407 413 2006-10-30 Ville Vainio <vivainio@gmail.com>
408 414
409 415 * Debugger.py, iplib.py (debugger()): Add last set of Rocky
410 416 Bernsteins's patches for pydb integration.
411 417 http://bashdb.sourceforge.net/pydb/
412 418
413 419 * strdispatch.py, iplib.py, completer.py, IPython/__init__.py,
414 420 Extensions/ipy_linux_package_managers.py, hooks.py: Implement
415 421 custom completer hook to allow the users to implement their own
416 422 completers. See ipy_linux_package_managers.py for example. The
417 423 hook name is 'complete_command'.
418 424
419 425 2006-10-28 Fernando Perez <Fernando.Perez@colorado.edu>
420 426
421 427 * IPython/UserConfig/ipythonrc-scipy: minor cleanups to remove old
422 428 Numeric leftovers.
423 429
424 430 * ipython.el (py-execute-region): apply Stefan's patch to fix
425 431 garbled results if the python shell hasn't been previously started.
426 432
427 433 * IPython/genutils.py (arg_split): moved to genutils, since it's a
428 434 pretty generic function and useful for other things.
429 435
430 436 * IPython/OInspect.py (getsource): Add customizable source
431 437 extractor. After a request/patch form W. Stein (SAGE).
432 438
433 439 * IPython/irunner.py (InteractiveRunner.run_source): reset tty
434 440 window size to a more reasonable value from what pexpect does,
435 441 since their choice causes wrapping bugs with long input lines.
436 442
437 443 2006-10-28 Ville Vainio <vivainio@gmail.com>
438 444
439 445 * Magic.py (%run): Save and restore the readline history from
440 446 file around %run commands to prevent side effects from
441 447 %runned programs that might use readline (e.g. pydb).
442 448
443 449 * extensions/ipy_pydb.py: Adds %pydb magic when imported, for
444 450 invoking the pydb enhanced debugger.
445 451
446 452 2006-10-23 Walter Doerwald <walter@livinglogic.de>
447 453
448 454 * IPython/Extensions/ipipe.py (ifile): Remove all methods that
449 455 call the base class method and propagate the return value to
450 456 ifile. This is now done by path itself.
451 457
452 458 2006-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
453 459
454 460 * IPython/ipapi.py (IPApi.__init__): Added new entry to public
455 461 api: set_crash_handler(), to expose the ability to change the
456 462 internal crash handler.
457 463
458 464 * IPython/CrashHandler.py (CrashHandler.__init__): abstract out
459 465 the various parameters of the crash handler so that apps using
460 466 IPython as their engine can customize crash handling. Ipmlemented
461 467 at the request of SAGE.
462 468
463 469 2006-10-14 Ville Vainio <vivainio@gmail.com>
464 470
465 471 * Magic.py, ipython.el: applied first "safe" part of Rocky
466 472 Bernstein's patch set for pydb integration.
467 473
468 474 * Magic.py (%unalias, %alias): %store'd aliases can now be
469 475 removed with '%unalias'. %alias w/o args now shows most
470 476 interesting (stored / manually defined) aliases last
471 477 where they catch the eye w/o scrolling.
472 478
473 479 * Magic.py (%rehashx), ext_rehashdir.py: files with
474 480 'py' extension are always considered executable, even
475 481 when not in PATHEXT environment variable.
476 482
477 483 2006-10-12 Ville Vainio <vivainio@gmail.com>
478 484
479 485 * jobctrl.py: Add new "jobctrl" extension for spawning background
480 486 processes with "&find /". 'import jobctrl' to try it out. Requires
481 487 'subprocess' module, standard in python 2.4+.
482 488
483 489 * iplib.py (expand_aliases, handle_alias): Aliases expand transitively,
484 490 so if foo -> bar and bar -> baz, then foo -> baz.
485 491
486 492 2006-10-09 Fernando Perez <Fernando.Perez@colorado.edu>
487 493
488 494 * IPython/Magic.py (Magic.parse_options): add a new posix option
489 495 to allow parsing of input args in magics that doesn't strip quotes
490 496 (if posix=False). This also closes %timeit bug reported by
491 497 Stefan.
492 498
493 499 2006-10-03 Ville Vainio <vivainio@gmail.com>
494 500
495 501 * iplib.py (raw_input, interact): Return ValueError catching for
496 502 raw_input. Fixes infinite loop for sys.stdin.close() or
497 503 sys.stdout.close().
498 504
499 505 2006-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
500 506
501 507 * IPython/irunner.py (InteractiveRunner.run_source): small fixes
502 508 to help in handling doctests. irunner is now pretty useful for
503 509 running standalone scripts and simulate a full interactive session
504 510 in a format that can be then pasted as a doctest.
505 511
506 512 * IPython/iplib.py (InteractiveShell.__init__): Install exit/quit
507 513 on top of the default (useless) ones. This also fixes the nasty
508 514 way in which 2.5's Quitter() exits (reverted [1785]).
509 515
510 516 * IPython/Debugger.py (Pdb.__init__): Fix ipdb to work with python
511 517 2.5.
512 518
513 519 * IPython/ultraTB.py (TBTools.set_colors): Make sure that ipdb
514 520 color scheme is updated as well when color scheme is changed
515 521 interactively.
516 522
517 523 2006-09-27 Ville Vainio <vivainio@gmail.com>
518 524
519 525 * iplib.py (raw_input): python 2.5 closes stdin on quit -> avoid
520 526 infinite loop and just exit. It's a hack, but will do for a while.
521 527
522 528 2006-08-25 Walter Doerwald <walter@livinglogic.de>
523 529
524 530 * IPython/Extensions/ipipe.py (ils): Add arguments dirs and files to
525 531 the constructor, this makes it possible to get a list of only directories
526 532 or only files.
527 533
528 534 2006-08-12 Ville Vainio <vivainio@gmail.com>
529 535
530 536 * Fakemodule.py, OInspect.py: Reverted 2006-08-11 mods,
531 537 they broke unittest
532 538
533 539 2006-08-11 Ville Vainio <vivainio@gmail.com>
534 540
535 541 * Fakemodule.py, OInspect.py: remove 2006-08-09 monkepatch
536 542 by resolving issue properly, i.e. by inheriting FakeModule
537 543 from types.ModuleType. Pickling ipython interactive data
538 544 should still work as usual (testing appreciated).
539 545
540 546 2006-08-09 Fernando Perez <Fernando.Perez@colorado.edu>
541 547
542 548 * IPython/OInspect.py: monkeypatch inspect from the stdlib if
543 549 running under python 2.3 with code from 2.4 to fix a bug with
544 550 help(). Reported by the Debian maintainers, Norbert Tretkowski
545 551 <norbert-AT-tretkowski.de> and Alexandre Fayolle
546 552 <afayolle-AT-debian.org>.
547 553
548 554 2006-08-04 Walter Doerwald <walter@livinglogic.de>
549 555
550 556 * IPython/Extensions/ibrowse.py: Fixed the help message in the footer
551 557 (which was displaying "quit" twice).
552 558
553 559 2006-07-28 Walter Doerwald <walter@livinglogic.de>
554 560
555 561 * IPython/Extensions/ipipe.py: Fix isort.__iter__() (was still using
556 562 the mode argument).
557 563
558 564 2006-07-27 Walter Doerwald <walter@livinglogic.de>
559 565
560 566 * IPython/Extensions/ipipe.py: Fix getglobals() if we're
561 567 not running under IPython.
562 568
563 569 * IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail
564 570 and make it iterable (iterating over the attribute itself). Add two new
565 571 magic strings for __xattrs__(): If the string starts with "-", the attribute
566 572 will not be displayed in ibrowse's detail view (but it can still be
567 573 iterated over). This makes it possible to add attributes that are large
568 574 lists or generator methods to the detail view. Replace magic attribute names
569 575 and _attrname() and _getattr() with "descriptors": For each type of magic
570 576 attribute name there's a subclass of Descriptor: None -> SelfDescriptor();
571 577 "foo" -> AttributeDescriptor("foo"); "foo()" -> MethodDescriptor("foo");
572 578 "-foo" -> IterAttributeDescriptor("foo"); "-foo()" -> IterMethodDescriptor("foo");
573 579 foo() -> FunctionDescriptor(foo). Magic strings returned from __xattrs__()
574 580 are still supported.
575 581
576 582 * IPython/Extensions/ibrowse.py: If fetching the next row from the input
577 583 fails in ibrowse.fetch(), the exception object is added as the last item
578 584 and item fetching is canceled. This prevents ibrowse from aborting if e.g.
579 585 a generator throws an exception midway through execution.
580 586
581 587 * IPython/Extensions/ipipe.py: Turn ifile's properties mimetype and
582 588 encoding into methods.
583 589
584 590 2006-07-26 Ville Vainio <vivainio@gmail.com>
585 591
586 592 * iplib.py: history now stores multiline input as single
587 593 history entries. Patch by Jorgen Cederlof.
588 594
589 595 2006-07-18 Walter Doerwald <walter@livinglogic.de>
590 596
591 597 * IPython/Extensions/ibrowse.py: Make cursor visible over
592 598 non existing attributes.
593 599
594 600 2006-07-14 Walter Doerwald <walter@livinglogic.de>
595 601
596 602 * IPython/Extensions/ipipe.py (ix): Use os.popen4() so that the
597 603 error output of the running command doesn't mess up the screen.
598 604
599 605 2006-07-13 Walter Doerwald <walter@livinglogic.de>
600 606
601 607 * IPython/Extensions/ipipe.py (isort): Make isort usable without
602 608 argument. This sorts the items themselves.
603 609
604 610 2006-07-12 Walter Doerwald <walter@livinglogic.de>
605 611
606 612 * IPython/Extensions/ipipe.py (eval, ifilter, isort, ieval):
607 613 Compile expression strings into code objects. This should speed
608 614 up ifilter and friends somewhat.
609 615
610 616 2006-07-08 Ville Vainio <vivainio@gmail.com>
611 617
612 618 * Magic.py: %cpaste now strips > from the beginning of lines
613 619 to ease pasting quoted code from emails. Contributed by
614 620 Stefan van der Walt.
615 621
616 622 2006-06-29 Ville Vainio <vivainio@gmail.com>
617 623
618 624 * ipmaker.py, Shell.py: qt4agg matplotlib backend support for pylab
619 625 mode, patch contributed by Darren Dale. NEEDS TESTING!
620 626
621 627 2006-06-28 Walter Doerwald <walter@livinglogic.de>
622 628
623 629 * IPython/Extensions/ibrowse.py: Give the ibrowse cursor row
624 630 a blue background. Fix fetching new display rows when the browser
625 631 scrolls more than a screenful (e.g. by using the goto command).
626 632
627 633 2006-06-27 Ville Vainio <vivainio@gmail.com>
628 634
629 635 * Magic.py (_inspect, _ofind) Apply David Huard's
630 636 patch for displaying the correct docstring for 'property'
631 637 attributes.
632 638
633 639 2006-06-23 Walter Doerwald <walter@livinglogic.de>
634 640
635 641 * IPython/Extensions/ibrowse.py: Put the documentation of the keyboard
636 642 commands into the methods implementing them.
637 643
638 644 2006-06-22 Fernando Perez <Fernando.Perez@colorado.edu>
639 645
640 646 * ipython.el (ipython-indentation-hook): cleanup patch, submitted
641 647 by Kov Chai <tchaikov-AT-gmail.com>. He notes that the original
642 648 autoindent support was authored by Jin Liu.
643 649
644 650 2006-06-22 Walter Doerwald <walter@livinglogic.de>
645 651
646 652 * IPython/Extensions/ibrowse.py: Replace the plain dictionaries used
647 653 for keymaps with a custom class that simplifies handling.
648 654
649 655 2006-06-19 Walter Doerwald <walter@livinglogic.de>
650 656
651 657 * IPython/Extensions/ibrowse.py: ibrowse now properly handles terminal
652 658 resizing. This requires Python 2.5 to work.
653 659
654 660 2006-06-16 Walter Doerwald <walter@livinglogic.de>
655 661
656 662 * IPython/Extensions/ibrowse.py: Add two new commands to
657 663 ibrowse: "hideattr" (mapped to "h") hides the attribute under
658 664 the cursor. "unhiderattrs" (mapped to "H") reveals all hidden
659 665 attributes again. Remapped the help command to "?". Display
660 666 keycodes in the range 0x01-0x1F as CTRL-xx. Add CTRL-a and CTRL-e
661 667 as keys for the "home" and "end" commands. Add three new commands
662 668 to the input mode for "find" and friends: "delend" (CTRL-K)
663 669 deletes to the end of line. "incsearchup" searches upwards in the
664 670 command history for an input that starts with the text before the cursor.
665 671 "incsearchdown" does the same downwards. Removed a bogus mapping of
666 672 the x key to "delete".
667 673
668 674 2006-06-15 Ville Vainio <vivainio@gmail.com>
669 675
670 676 * iplib.py, hooks.py: Added new generate_prompt hook that can be
671 677 used to create prompts dynamically, instead of the "old" way of
672 678 assigning "magic" strings to prompt_in1 and prompt_in2. The old
673 679 way still works (it's invoked by the default hook), of course.
674 680
675 681 * Prompts.py: added generate_output_prompt hook for altering output
676 682 prompt
677 683
678 684 * Release.py: Changed version string to 0.7.3.svn.
679 685
680 686 2006-06-15 Walter Doerwald <walter@livinglogic.de>
681 687
682 688 * IPython/Extensions/ibrowse.py: Change _BrowserLevel.moveto() so that
683 689 the call to fetch() always tries to fetch enough data for at least one
684 690 full screen. This makes it possible to simply call moveto(0,0,True) in
685 691 the constructor. Fix typos and removed the obsolete goto attribute.
686 692
687 693 2006-06-12 Ville Vainio <vivainio@gmail.com>
688 694
689 695 * ipy_profile_sh.py: applied Krisha Mohan Gundu's patch for
690 696 allowing $variable interpolation within multiline statements,
691 697 though so far only with "sh" profile for a testing period.
692 698 The patch also enables splitting long commands with \ but it
693 699 doesn't work properly yet.
694 700
695 701 2006-06-12 Walter Doerwald <walter@livinglogic.de>
696 702
697 703 * IPython/Extensions/ibrowse.py (_dodisplay): Display the length of the
698 704 input history and the position of the cursor in the input history for
699 705 the find, findbackwards and goto command.
700 706
701 707 2006-06-10 Walter Doerwald <walter@livinglogic.de>
702 708
703 709 * IPython/Extensions/ibrowse.py: Add a class _CommandInput that
704 710 implements the basic functionality of browser commands that require
705 711 input. Reimplement the goto, find and findbackwards commands as
706 712 subclasses of _CommandInput. Add an input history and keymaps to those
707 713 commands. Add "\r" as a keyboard shortcut for the enterdefault and
708 714 execute commands.
709 715
710 716 2006-06-07 Ville Vainio <vivainio@gmail.com>
711 717
712 718 * iplib.py: ipython mybatch.ipy exits ipython immediately after
713 719 running the batch files instead of leaving the session open.
714 720
715 721 2006-06-07 Fernando Perez <Fernando.Perez@colorado.edu>
716 722
717 723 * IPython/iplib.py (InteractiveShell.__init__): update BSD fix, as
718 724 the original fix was incomplete. Patch submitted by W. Maier.
719 725
720 726 2006-06-07 Ville Vainio <vivainio@gmail.com>
721 727
722 728 * iplib.py,Magic.py, ipmaker.py (magic_rehashx):
723 729 Confirmation prompts can be supressed by 'quiet' option.
724 730 _ip.options.quiet = 1 means "assume yes for all yes/no queries".
725 731
726 732 2006-06-06 *** Released version 0.7.2
727 733
728 734 2006-06-06 Fernando Perez <Fernando.Perez@colorado.edu>
729 735
730 736 * IPython/Release.py (version): Made 0.7.2 final for release.
731 737 Repo tagged and release cut.
732 738
733 739 2006-06-05 Ville Vainio <vivainio@gmail.com>
734 740
735 741 * Magic.py (magic_rehashx): Honor no_alias list earlier in
736 742 %rehashx, to avoid clobbering builtins in ipy_profile_sh.py
737 743
738 744 * upgrade_dir.py: try import 'path' module a bit harder
739 745 (for %upgrade)
740 746
741 747 2006-06-03 Fernando Perez <Fernando.Perez@colorado.edu>
742 748
743 749 * IPython/genutils.py (ask_yes_no): treat EOF as a default answer
744 750 instead of looping 20 times.
745 751
746 752 * IPython/ipmaker.py (make_IPython): honor -ipythondir flag
747 753 correctly at initialization time. Bug reported by Krishna Mohan
748 754 Gundu <gkmohan-AT-gmail.com> on the user list.
749 755
750 756 * IPython/Release.py (version): Mark 0.7.2 version to start
751 757 testing for release on 06/06.
752 758
753 759 2006-05-31 Fernando Perez <Fernando.Perez@colorado.edu>
754 760
755 761 * scripts/irunner: thin script interface so users don't have to
756 762 find the module and call it as an executable, since modules rarely
757 763 live in people's PATH.
758 764
759 765 * IPython/irunner.py (InteractiveRunner.__init__): added
760 766 delaybeforesend attribute to control delays with newer versions of
761 767 pexpect. Thanks to detailed help from pexpect's author, Noah
762 768 Spurrier <noah-AT-noah.org>. Noted how to use the SAGE runner
763 769 correctly (it works in NoColor mode).
764 770
765 771 * IPython/iplib.py (handle_normal): fix nasty crash reported on
766 772 SAGE list, from improper log() calls.
767 773
768 774 2006-05-31 Ville Vainio <vivainio@gmail.com>
769 775
770 776 * upgrade_dir.py, Magic.py (magic_upgrade): call upgrade_dir
771 777 with args in parens to work correctly with dirs that have spaces.
772 778
773 779 2006-05-30 Fernando Perez <Fernando.Perez@colorado.edu>
774 780
775 781 * IPython/Logger.py (Logger.logstart): add option to log raw input
776 782 instead of the processed one. A -r flag was added to the
777 783 %logstart magic used for controlling logging.
778 784
779 785 2006-05-29 Fernando Perez <Fernando.Perez@colorado.edu>
780 786
781 787 * IPython/iplib.py (InteractiveShell.__init__): add check for the
782 788 *BSDs to omit --color from all 'ls' aliases, since *BSD ls doesn't
783 789 recognize the option. After a bug report by Will Maier. This
784 790 closes #64 (will do it after confirmation from W. Maier).
785 791
786 792 * IPython/irunner.py: New module to run scripts as if manually
787 793 typed into an interactive environment, based on pexpect. After a
788 794 submission by Ken Schutte <kschutte-AT-csail.mit.edu> on the
789 795 ipython-user list. Simple unittests in the tests/ directory.
790 796
791 797 * tools/release: add Will Maier, OpenBSD port maintainer, to
792 798 recepients list. We are now officially part of the OpenBSD ports:
793 799 http://www.openbsd.org/ports.html ! Many thanks to Will for the
794 800 work.
795 801
796 802 2006-05-26 Fernando Perez <Fernando.Perez@colorado.edu>
797 803
798 804 * IPython/ipmaker.py (make_IPython): modify sys.argv fix (below)
799 805 so that it doesn't break tkinter apps.
800 806
801 807 * IPython/iplib.py (_prefilter): fix bug where aliases would
802 808 shadow variables when autocall was fully off. Reported by SAGE
803 809 author William Stein.
804 810
805 811 * IPython/OInspect.py (Inspector.__init__): add a flag to control
806 812 at what detail level strings are computed when foo? is requested.
807 813 This allows users to ask for example that the string form of an
808 814 object is only computed when foo?? is called, or even never, by
809 815 setting the object_info_string_level >= 2 in the configuration
810 816 file. This new option has been added and documented. After a
811 817 request by SAGE to be able to control the printing of very large
812 818 objects more easily.
813 819
814 820 2006-05-25 Fernando Perez <Fernando.Perez@colorado.edu>
815 821
816 822 * IPython/ipmaker.py (make_IPython): remove the ipython call path
817 823 from sys.argv, to be 100% consistent with how Python itself works
818 824 (as seen for example with python -i file.py). After a bug report
819 825 by Jeffrey Collins.
820 826
821 827 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix
822 828 nasty bug which was preventing custom namespaces with -pylab,
823 829 reported by M. Foord. Minor cleanup, remove old matplotlib.matlab
824 830 compatibility (long gone from mpl).
825 831
826 832 * IPython/ipapi.py (make_session): name change: create->make. We
827 833 use make in other places (ipmaker,...), it's shorter and easier to
828 834 type and say, etc. I'm trying to clean things before 0.7.2 so
829 835 that I can keep things stable wrt to ipapi in the chainsaw branch.
830 836
831 837 * ipython.el: fix the py-pdbtrack-input-prompt variable so that
832 838 python-mode recognizes our debugger mode. Add support for
833 839 autoindent inside (X)emacs. After a patch sent in by Jin Liu
834 840 <m.liu.jin-AT-gmail.com> originally written by
835 841 doxgen-AT-newsmth.net (with minor modifications for xemacs
836 842 compatibility)
837 843
838 844 * IPython/Debugger.py (Pdb.format_stack_entry): fix formatting of
839 845 tracebacks when walking the stack so that the stack tracking system
840 846 in emacs' python-mode can identify the frames correctly.
841 847
842 848 * IPython/ipmaker.py (make_IPython): make the internal (and
843 849 default config) autoedit_syntax value false by default. Too many
844 850 users have complained to me (both on and off-list) about problems
845 851 with this option being on by default, so I'm making it default to
846 852 off. It can still be enabled by anyone via the usual mechanisms.
847 853
848 854 * IPython/completer.py (Completer.attr_matches): add support for
849 855 PyCrust-style _getAttributeNames magic method. Patch contributed
850 856 by <mscott-AT-goldenspud.com>. Closes #50.
851 857
852 858 * IPython/iplib.py (InteractiveShell.__init__): remove the
853 859 deletion of exit/quit from __builtin__, which can break
854 860 third-party tools like the Zope debugging console. The
855 861 %exit/%quit magics remain. In general, it's probably a good idea
856 862 not to delete anything from __builtin__, since we never know what
857 863 that will break. In any case, python now (for 2.5) will support
858 864 'real' exit/quit, so this issue is moot. Closes #55.
859 865
860 866 * IPython/genutils.py (with_obj): rename the 'with' function to
861 867 'withobj' to avoid incompatibilities with Python 2.5, where 'with'
862 868 becomes a language keyword. Closes #53.
863 869
864 870 * IPython/FakeModule.py (FakeModule.__init__): add a proper
865 871 __file__ attribute to this so it fools more things into thinking
866 872 it is a real module. Closes #59.
867 873
868 874 * IPython/Magic.py (magic_edit): add -n option to open the editor
869 875 at a specific line number. After a patch by Stefan van der Walt.
870 876
871 877 2006-05-23 Fernando Perez <Fernando.Perez@colorado.edu>
872 878
873 879 * IPython/iplib.py (edit_syntax_error): fix crash when for some
874 880 reason the file could not be opened. After automatic crash
875 881 reports sent by James Graham <jgraham-AT-ast.cam.ac.uk> and
876 882 Charles Dolan <charlespatrickdolan-AT-yahoo.com>.
877 883 (_should_recompile): Don't fire editor if using %bg, since there
878 884 is no file in the first place. From the same report as above.
879 885 (raw_input): protect against faulty third-party prefilters. After
880 886 an automatic crash report sent by Dirk Laurie <dirk-AT-sun.ac.za>
881 887 while running under SAGE.
882 888
883 889 2006-05-23 Ville Vainio <vivainio@gmail.com>
884 890
885 891 * ipapi.py: Stripped down ip.to_user_ns() to work only as
886 892 ip.to_user_ns("x1 y1"), which exposes vars x1 and y1. ipapi.get()
887 893 now returns None (again), unless dummy is specifically allowed by
888 894 ipapi.get(allow_dummy=True).
889 895
890 896 2006-05-18 Fernando Perez <Fernando.Perez@colorado.edu>
891 897
892 898 * IPython: remove all 2.2-compatibility objects and hacks from
893 899 everywhere, since we only support 2.3 at this point. Docs
894 900 updated.
895 901
896 902 * IPython/ipapi.py (IPApi.__init__): Cleanup of all getters.
897 903 Anything requiring extra validation can be turned into a Python
898 904 property in the future. I used a property for the db one b/c
899 905 there was a nasty circularity problem with the initialization
900 906 order, which right now I don't have time to clean up.
901 907
902 908 * IPython/Shell.py (MTInteractiveShell.runcode): Fix, I think,
903 909 another locking bug reported by Jorgen. I'm not 100% sure though,
904 910 so more testing is needed...
905 911
906 912 2006-05-17 Fernando Perez <Fernando.Perez@colorado.edu>
907 913
908 914 * IPython/ipapi.py (IPApi.to_user_ns): New function to inject
909 915 local variables from any routine in user code (typically executed
910 916 with %run) directly into the interactive namespace. Very useful
911 917 when doing complex debugging.
912 918 (IPythonNotRunning): Changed the default None object to a dummy
913 919 whose attributes can be queried as well as called without
914 920 exploding, to ease writing code which works transparently both in
915 921 and out of ipython and uses some of this API.
916 922
917 923 2006-05-16 Fernando Perez <Fernando.Perez@colorado.edu>
918 924
919 925 * IPython/hooks.py (result_display): Fix the fact that our display
920 926 hook was using str() instead of repr(), as the default python
921 927 console does. This had gone unnoticed b/c it only happened if
922 928 %Pprint was off, but the inconsistency was there.
923 929
924 930 2006-05-15 Ville Vainio <vivainio@gmail.com>
925 931
926 932 * Oinspect.py: Only show docstring for nonexisting/binary files
927 933 when doing object??, closing ticket #62
928 934
929 935 2006-05-13 Fernando Perez <Fernando.Perez@colorado.edu>
930 936
931 937 * IPython/Shell.py (MTInteractiveShell.runsource): Fix threading
932 938 bug, closes http://www.scipy.net/roundup/ipython/issue55. A lock
933 939 was being released in a routine which hadn't checked if it had
934 940 been the one to acquire it.
935 941
936 942 2006-05-07 Fernando Perez <Fernando.Perez@colorado.edu>
937 943
938 944 * IPython/Release.py (version): put out 0.7.2.rc1 for testing.
939 945
940 946 2006-04-11 Ville Vainio <vivainio@gmail.com>
941 947
942 948 * iplib.py, ipmaker.py: .ipy extension now means "ipython batch file"
943 949 in command line. E.g. "ipython test.ipy" runs test.ipy with ipython
944 950 prefilters, allowing stuff like magics and aliases in the file.
945 951
946 952 * Prompts.py, Extensions/clearcmd.py, ipy_system_conf.py: %clear magic
947 953 added. Supported now are "%clear in" and "%clear out" (clear input and
948 954 output history, respectively). Also fixed CachedOutput.flush to
949 955 properly flush the output cache.
950 956
951 957 * Extensions/pspersistence.py: Fix %store to avoid "%store obj.attr"
952 958 half-success (and fail explicitly).
953 959
954 960 2006-03-28 Ville Vainio <vivainio@gmail.com>
955 961
956 962 * iplib.py: Fix quoting of aliases so that only argless ones
957 963 are quoted
958 964
959 965 2006-03-28 Ville Vainio <vivainio@gmail.com>
960 966
961 967 * iplib.py: Quote aliases with spaces in the name.
962 968 "c:\program files\blah\bin" is now legal alias target.
963 969
964 970 * ext_rehashdir.py: Space no longer allowed as arg
965 971 separator, since space is legal in path names.
966 972
967 973 2006-03-16 Ville Vainio <vivainio@gmail.com>
968 974
969 975 * upgrade_dir.py: Take path.py from Extensions, correcting
970 976 %upgrade magic
971 977
972 978 * ipmaker.py: Suggest using %upgrade if ipy_user_conf.py isn't found.
973 979
974 980 * hooks.py: Only enclose editor binary in quotes if legal and
975 981 necessary (space in the name, and is an existing file). Fixes a bug
976 982 reported by Zachary Pincus.
977 983
978 984 2006-03-13 Fernando Perez <Fernando.Perez@colorado.edu>
979 985
980 986 * Manual: thanks to a tip on proper color handling for Emacs, by
981 987 Eric J Haywiser <ejh1-AT-MIT.EDU>.
982 988
983 989 * ipython.el: close http://www.scipy.net/roundup/ipython/issue57
984 990 by applying the provided patch. Thanks to Liu Jin
985 991 <m.liu.jin-AT-gmail.com> for the contribution. No problems under
986 992 XEmacs/Linux, I'm trusting the submitter that it actually helps
987 993 under win32/GNU Emacs. Will revisit if any problems are reported.
988 994
989 995 2006-03-12 Fernando Perez <Fernando.Perez@colorado.edu>
990 996
991 997 * IPython/Gnuplot2.py (_FileClass): update for current Gnuplot.py
992 998 from SVN, thanks to a patch by Ryan Woodard <rywo@bas.ac.uk>.
993 999
994 1000 2006-03-12 Ville Vainio <vivainio@gmail.com>
995 1001
996 1002 * Magic.py (magic_timeit): Added %timeit magic, contributed by
997 1003 Torsten Marek.
998 1004
999 1005 2006-03-12 Fernando Perez <Fernando.Perez@colorado.edu>
1000 1006
1001 1007 * IPython/Magic.py (magic_macro): fix so that the n1-n2 syntax for
1002 1008 line ranges works again.
1003 1009
1004 1010 2006-03-11 Fernando Perez <Fernando.Perez@colorado.edu>
1005 1011
1006 1012 * IPython/iplib.py (showtraceback): add back sys.last_traceback
1007 1013 and friends, after a discussion with Zach Pincus on ipython-user.
1008 1014 I'm not 100% sure, but after thinking about it quite a bit, it may
1009 1015 be OK. Testing with the multithreaded shells didn't reveal any
1010 1016 problems, but let's keep an eye out.
1011 1017
1012 1018 In the process, I fixed a few things which were calling
1013 1019 self.InteractiveTB() directly (like safe_execfile), which is a
1014 1020 mistake: ALL exception reporting should be done by calling
1015 1021 self.showtraceback(), which handles state and tab-completion and
1016 1022 more.
1017 1023
1018 1024 2006-03-01 Ville Vainio <vivainio@gmail.com>
1019 1025
1020 1026 * Extensions/ipipe.py: Added Walter Doerwald's "ipipe" module.
1021 1027 To use, do "from ipipe import *".
1022 1028
1023 1029 2006-02-24 Ville Vainio <vivainio@gmail.com>
1024 1030
1025 1031 * Magic.py, upgrade_dir.py: %upgrade magic added. Does things more
1026 1032 "cleanly" and safely than the older upgrade mechanism.
1027 1033
1028 1034 2006-02-21 Ville Vainio <vivainio@gmail.com>
1029 1035
1030 1036 * Magic.py: %save works again.
1031 1037
1032 1038 2006-02-15 Ville Vainio <vivainio@gmail.com>
1033 1039
1034 1040 * Magic.py: %Pprint works again
1035 1041
1036 1042 * Extensions/ipy_sane_defaults.py: Provide everything provided
1037 1043 in default ipythonrc, to make it possible to have a completely empty
1038 1044 ipythonrc (and thus completely rc-file free configuration)
1039 1045
1040 1046 2006-02-11 Fernando Perez <Fernando.Perez@colorado.edu>
1041 1047
1042 1048 * IPython/hooks.py (editor): quote the call to the editor command,
1043 1049 to allow commands with spaces in them. Problem noted by watching
1044 1050 Ian Oswald's video about textpad under win32 at
1045 1051 http://showmedo.com/videoListPage?listKey=PythonIPythonSeries
1046 1052
1047 1053 * IPython/UserConfig/ipythonrc: Replace @ signs with % when
1048 1054 describing magics (we haven't used @ for a loong time).
1049 1055
1050 1056 * IPython/ultraTB.py (VerboseTB.text.text_repr): Added patch
1051 1057 contributed by marienz to close
1052 1058 http://www.scipy.net/roundup/ipython/issue53.
1053 1059
1054 1060 2006-02-10 Ville Vainio <vivainio@gmail.com>
1055 1061
1056 1062 * genutils.py: getoutput now works in win32 too
1057 1063
1058 1064 * completer.py: alias and magic completion only invoked
1059 1065 at the first "item" in the line, to avoid "cd %store"
1060 1066 nonsense.
1061 1067
1062 1068 2006-02-09 Ville Vainio <vivainio@gmail.com>
1063 1069
1064 1070 * test/*: Added a unit testing framework (finally).
1065 1071 '%run runtests.py' to run test_*.
1066 1072
1067 1073 * ipapi.py: Exposed runlines and set_custom_exc
1068 1074
1069 1075 2006-02-07 Ville Vainio <vivainio@gmail.com>
1070 1076
1071 1077 * iplib.py: don't split "f 1 2" to "f(1,2)" in autocall,
1072 1078 instead use "f(1 2)" as before.
1073 1079
1074 1080 2006-02-05 Fernando Perez <Fernando.Perez@colorado.edu>
1075 1081
1076 1082 * IPython/demo.py (IPythonDemo): Add new classes to the demo
1077 1083 facilities, for demos processed by the IPython input filter
1078 1084 (IPythonDemo), and for running a script one-line-at-a-time as a
1079 1085 demo, both for pure Python (LineDemo) and for IPython-processed
1080 1086 input (IPythonLineDemo). After a request by Dave Kohel, from the
1081 1087 SAGE team.
1082 1088 (Demo.edit): added an edit() method to the demo objects, to edit
1083 1089 the in-memory copy of the last executed block.
1084 1090
1085 1091 * IPython/Magic.py (magic_edit): add '-r' option for 'raw'
1086 1092 processing to %edit, %macro and %save. These commands can now be
1087 1093 invoked on the unprocessed input as it was typed by the user
1088 1094 (without any prefilters applied). After requests by the SAGE team
1089 1095 at SAGE days 2006: http://modular.ucsd.edu/sage/days1/schedule.html.
1090 1096
1091 1097 2006-02-01 Ville Vainio <vivainio@gmail.com>
1092 1098
1093 1099 * setup.py, eggsetup.py: easy_install ipython==dev works
1094 1100 correctly now (on Linux)
1095 1101
1096 1102 * ipy_user_conf,ipmaker: user config changes, removed spurious
1097 1103 warnings
1098 1104
1099 1105 * iplib: if rc.banner is string, use it as is.
1100 1106
1101 1107 * Magic: %pycat accepts a string argument and pages it's contents.
1102 1108
1103 1109
1104 1110 2006-01-30 Ville Vainio <vivainio@gmail.com>
1105 1111
1106 1112 * pickleshare,pspersistence,ipapi,Magic: persistence overhaul.
1107 1113 Now %store and bookmarks work through PickleShare, meaning that
1108 1114 concurrent access is possible and all ipython sessions see the
1109 1115 same database situation all the time, instead of snapshot of
1110 1116 the situation when the session was started. Hence, %bookmark
1111 1117 results are immediately accessible from othes sessions. The database
1112 1118 is also available for use by user extensions. See:
1113 1119 http://www.python.org/pypi/pickleshare
1114 1120
1115 1121 * hooks.py: Two new hooks, 'shutdown_hook' and 'late_startup_hook'.
1116 1122
1117 1123 * aliases can now be %store'd
1118 1124
1119 1125 * path.py moved to Extensions so that pickleshare does not need
1120 1126 IPython-specific import. Extensions added to pythonpath right
1121 1127 at __init__.
1122 1128
1123 1129 * iplib.py: ipalias deprecated/redundant; aliases are converted and
1124 1130 called with _ip.system and the pre-transformed command string.
1125 1131
1126 1132 2006-01-29 Fernando Perez <Fernando.Perez@colorado.edu>
1127 1133
1128 1134 * IPython/iplib.py (interact): Fix that we were not catching
1129 1135 KeyboardInterrupt exceptions properly. I'm not quite sure why the
1130 1136 logic here had to change, but it's fixed now.
1131 1137
1132 1138 2006-01-29 Ville Vainio <vivainio@gmail.com>
1133 1139
1134 1140 * iplib.py: Try to import pyreadline on Windows.
1135 1141
1136 1142 2006-01-27 Ville Vainio <vivainio@gmail.com>
1137 1143
1138 1144 * iplib.py: Expose ipapi as _ip in builtin namespace.
1139 1145 Makes ipmagic (-> _ip.magic), ipsystem (-> _ip.system)
1140 1146 and ip_set_hook (-> _ip.set_hook) redundant. % and !
1141 1147 syntax now produce _ip.* variant of the commands.
1142 1148
1143 1149 * "_ip.options().autoedit_syntax = 2" automatically throws
1144 1150 user to editor for syntax error correction without prompting.
1145 1151
1146 1152 2006-01-27 Ville Vainio <vivainio@gmail.com>
1147 1153
1148 1154 * ipmaker.py: Give "realistic" sys.argv for scripts (without
1149 1155 'ipython' at argv[0]) executed through command line.
1150 1156 NOTE: this DEPRECATES calling ipython with multiple scripts
1151 1157 ("ipython a.py b.py c.py")
1152 1158
1153 1159 * iplib.py, hooks.py: Added configurable input prefilter,
1154 1160 named 'input_prefilter'. See ext_rescapture.py for example
1155 1161 usage.
1156 1162
1157 1163 * ext_rescapture.py, Magic.py: Better system command output capture
1158 1164 through 'var = !ls' (deprecates user-visible %sc). Same notation
1159 1165 applies for magics, 'var = %alias' assigns alias list to var.
1160 1166
1161 1167 * ipapi.py: added meta() for accessing extension-usable data store.
1162 1168
1163 1169 * iplib.py: added InteractiveShell.getapi(). New magics should be
1164 1170 written doing self.getapi() instead of using the shell directly.
1165 1171
1166 1172 * Magic.py: %store now allows doing %store foo > ~/myfoo.txt and
1167 1173 %store foo >> ~/myfoo.txt to store variables to files (in clean
1168 1174 textual form, not a restorable pickle).
1169 1175
1170 1176 * ipmaker.py: now import ipy_profile_PROFILENAME automatically
1171 1177
1172 1178 * usage.py, Magic.py: added %quickref
1173 1179
1174 1180 * iplib.py: ESC_PAREN fixes: /f 1 2 -> f(1,2), not f(1 2).
1175 1181
1176 1182 * GetoptErrors when invoking magics etc. with wrong args
1177 1183 are now more helpful:
1178 1184 GetoptError: option -l not recognized (allowed: "qb" )
1179 1185
1180 1186 2006-01-25 Fernando Perez <Fernando.Perez@colorado.edu>
1181 1187
1182 1188 * IPython/demo.py (Demo.show): Flush stdout after each block, so
1183 1189 computationally intensive blocks don't appear to stall the demo.
1184 1190
1185 1191 2006-01-24 Ville Vainio <vivainio@gmail.com>
1186 1192
1187 1193 * iplib.py, hooks.py: 'result_display' hook can return a non-None
1188 1194 value to manipulate resulting history entry.
1189 1195
1190 1196 * ipapi.py: Moved TryNext here from hooks.py. Moved functions
1191 1197 to instance methods of IPApi class, to make extending an embedded
1192 1198 IPython feasible. See ext_rehashdir.py for example usage.
1193 1199
1194 1200 * Merged 1071-1076 from branches/0.7.1
1195 1201
1196 1202
1197 1203 2006-01-23 Fernando Perez <Fernando.Perez@colorado.edu>
1198 1204
1199 1205 * tools/release (daystamp): Fix build tools to use the new
1200 1206 eggsetup.py script to build lightweight eggs.
1201 1207
1202 1208 * Applied changesets 1062 and 1064 before 0.7.1 release.
1203 1209
1204 1210 * IPython/Magic.py (magic_history): Add '-r' option to %hist, to
1205 1211 see the raw input history (without conversions like %ls ->
1206 1212 ipmagic("ls")). After a request from W. Stein, SAGE
1207 1213 (http://modular.ucsd.edu/sage) developer. This information is
1208 1214 stored in the input_hist_raw attribute of the IPython instance, so
1209 1215 developers can access it if needed (it's an InputList instance).
1210 1216
1211 1217 * Versionstring = 0.7.2.svn
1212 1218
1213 1219 * eggsetup.py: A separate script for constructing eggs, creates
1214 1220 proper launch scripts even on Windows (an .exe file in
1215 1221 \python24\scripts).
1216 1222
1217 1223 * ipapi.py: launch_new_instance, launch entry point needed for the
1218 1224 egg.
1219 1225
1220 1226 2006-01-23 Ville Vainio <vivainio@gmail.com>
1221 1227
1222 1228 * Added %cpaste magic for pasting python code
1223 1229
1224 1230 2006-01-22 Ville Vainio <vivainio@gmail.com>
1225 1231
1226 1232 * Merge from branches/0.7.1 into trunk, revs 1052-1057
1227 1233
1228 1234 * Versionstring = 0.7.2.svn
1229 1235
1230 1236 * eggsetup.py: A separate script for constructing eggs, creates
1231 1237 proper launch scripts even on Windows (an .exe file in
1232 1238 \python24\scripts).
1233 1239
1234 1240 * ipapi.py: launch_new_instance, launch entry point needed for the
1235 1241 egg.
1236 1242
1237 1243 2006-01-22 Fernando Perez <Fernando.Perez@colorado.edu>
1238 1244
1239 1245 * IPython/OInspect.py (Inspector.pinfo): fix bug where foo?? or
1240 1246 %pfile foo would print the file for foo even if it was a binary.
1241 1247 Now, extensions '.so' and '.dll' are skipped.
1242 1248
1243 1249 * IPython/Shell.py (MTInteractiveShell.__init__): Fix threading
1244 1250 bug, where macros would fail in all threaded modes. I'm not 100%
1245 1251 sure, so I'm going to put out an rc instead of making a release
1246 1252 today, and wait for feedback for at least a few days.
1247 1253
1248 1254 * IPython/iplib.py (handle_normal): fix (finally? somehow I doubt
1249 1255 it...) the handling of pasting external code with autoindent on.
1250 1256 To get out of a multiline input, the rule will appear for most
1251 1257 users unchanged: two blank lines or change the indent level
1252 1258 proposed by IPython. But there is a twist now: you can
1253 1259 add/subtract only *one or two spaces*. If you add/subtract three
1254 1260 or more (unless you completely delete the line), IPython will
1255 1261 accept that line, and you'll need to enter a second one of pure
1256 1262 whitespace. I know it sounds complicated, but I can't find a
1257 1263 different solution that covers all the cases, with the right
1258 1264 heuristics. Hopefully in actual use, nobody will really notice
1259 1265 all these strange rules and things will 'just work'.
1260 1266
1261 1267 2006-01-21 Fernando Perez <Fernando.Perez@colorado.edu>
1262 1268
1263 1269 * IPython/iplib.py (interact): catch exceptions which can be
1264 1270 triggered asynchronously by signal handlers. Thanks to an
1265 1271 automatic crash report, submitted by Colin Kingsley
1266 1272 <tercel-AT-gentoo.org>.
1267 1273
1268 1274 2006-01-20 Ville Vainio <vivainio@gmail.com>
1269 1275
1270 1276 * Ipython/Extensions/ext_rehashdir.py: Created a usable example
1271 1277 (%rehashdir, very useful, try it out) of how to extend ipython
1272 1278 with new magics. Also added Extensions dir to pythonpath to make
1273 1279 importing extensions easy.
1274 1280
1275 1281 * %store now complains when trying to store interactively declared
1276 1282 classes / instances of those classes.
1277 1283
1278 1284 * Extensions/ipy_system_conf.py, UserConfig/ipy_user_conf.py,
1279 1285 ipmaker.py: Config rehaul. Now ipy_..._conf.py are always imported
1280 1286 if they exist, and ipy_user_conf.py with some defaults is created for
1281 1287 the user.
1282 1288
1283 1289 * Startup rehashing done by the config file, not InterpreterExec.
1284 1290 This means system commands are available even without selecting the
1285 1291 pysh profile. It's the sensible default after all.
1286 1292
1287 1293 2006-01-20 Fernando Perez <Fernando.Perez@colorado.edu>
1288 1294
1289 1295 * IPython/iplib.py (raw_input): I _think_ I got the pasting of
1290 1296 multiline code with autoindent on working. But I am really not
1291 1297 sure, so this needs more testing. Will commit a debug-enabled
1292 1298 version for now, while I test it some more, so that Ville and
1293 1299 others may also catch any problems. Also made
1294 1300 self.indent_current_str() a method, to ensure that there's no
1295 1301 chance of the indent space count and the corresponding string
1296 1302 falling out of sync. All code needing the string should just call
1297 1303 the method.
1298 1304
1299 1305 2006-01-18 Fernando Perez <Fernando.Perez@colorado.edu>
1300 1306
1301 1307 * IPython/Magic.py (magic_edit): fix check for when users don't
1302 1308 save their output files, the try/except was in the wrong section.
1303 1309
1304 1310 2006-01-17 Fernando Perez <Fernando.Perez@colorado.edu>
1305 1311
1306 1312 * IPython/Magic.py (magic_run): fix __file__ global missing from
1307 1313 script's namespace when executed via %run. After a report by
1308 1314 Vivian.
1309 1315
1310 1316 * IPython/Debugger.py (Pdb.__init__): Fix breakage with '%run -d'
1311 1317 when using python 2.4. The parent constructor changed in 2.4, and
1312 1318 we need to track it directly (we can't call it, as it messes up
1313 1319 readline and tab-completion inside our pdb would stop working).
1314 1320 After a bug report by R. Bernstein <rocky-AT-panix.com>.
1315 1321
1316 1322 2006-01-16 Ville Vainio <vivainio@gmail.com>
1317 1323
1318 1324 * Ipython/magic.py: Reverted back to old %edit functionality
1319 1325 that returns file contents on exit.
1320 1326
1321 1327 * IPython/path.py: Added Jason Orendorff's "path" module to
1322 1328 IPython tree, http://www.jorendorff.com/articles/python/path/.
1323 1329 You can get path objects conveniently through %sc, and !!, e.g.:
1324 1330 sc files=ls
1325 1331 for p in files.paths: # or files.p
1326 1332 print p,p.mtime
1327 1333
1328 1334 * Ipython/iplib.py:"," and ";" autoquoting-upon-autocall
1329 1335 now work again without considering the exclusion regexp -
1330 1336 hence, things like ',foo my/path' turn to 'foo("my/path")'
1331 1337 instead of syntax error.
1332 1338
1333 1339
1334 1340 2006-01-14 Ville Vainio <vivainio@gmail.com>
1335 1341
1336 1342 * IPython/ipapi.py (ashook, asmagic, options): Added convenience
1337 1343 ipapi decorators for python 2.4 users, options() provides access to rc
1338 1344 data.
1339 1345
1340 1346 * IPython/Magic.py (magic_cd): %cd now accepts backslashes
1341 1347 as path separators (even on Linux ;-). Space character after
1342 1348 backslash (as yielded by tab completer) is still space;
1343 1349 "%cd long\ name" works as expected.
1344 1350
1345 1351 * IPython/ipapi.py,hooks.py,iplib.py: Hooks now implemented
1346 1352 as "chain of command", with priority. API stays the same,
1347 1353 TryNext exception raised by a hook function signals that
1348 1354 current hook failed and next hook should try handling it, as
1349 1355 suggested by Walter DΓΆrwald <walter@livinglogic.de>. Walter also
1350 1356 requested configurable display hook, which is now implemented.
1351 1357
1352 1358 2006-01-13 Ville Vainio <vivainio@gmail.com>
1353 1359
1354 1360 * IPython/platutils*.py: platform specific utility functions,
1355 1361 so far only set_term_title is implemented (change terminal
1356 1362 label in windowing systems). %cd now changes the title to
1357 1363 current dir.
1358 1364
1359 1365 * IPython/Release.py: Added myself to "authors" list,
1360 1366 had to create new files.
1361 1367
1362 1368 * IPython/iplib.py (handle_shell_escape): fixed logical flaw in
1363 1369 shell escape; not a known bug but had potential to be one in the
1364 1370 future.
1365 1371
1366 1372 * IPython/ipapi.py (added),OInspect.py,iplib.py: "Public"
1367 1373 extension API for IPython! See the module for usage example. Fix
1368 1374 OInspect for docstring-less magic functions.
1369 1375
1370 1376
1371 1377 2006-01-13 Fernando Perez <Fernando.Perez@colorado.edu>
1372 1378
1373 1379 * IPython/iplib.py (raw_input): temporarily deactivate all
1374 1380 attempts at allowing pasting of code with autoindent on. It
1375 1381 introduced bugs (reported by Prabhu) and I can't seem to find a
1376 1382 robust combination which works in all cases. Will have to revisit
1377 1383 later.
1378 1384
1379 1385 * IPython/genutils.py: remove isspace() function. We've dropped
1380 1386 2.2 compatibility, so it's OK to use the string method.
1381 1387
1382 1388 2006-01-12 Fernando Perez <Fernando.Perez@colorado.edu>
1383 1389
1384 1390 * IPython/iplib.py (InteractiveShell.__init__): fix regexp
1385 1391 matching what NOT to autocall on, to include all python binary
1386 1392 operators (including things like 'and', 'or', 'is' and 'in').
1387 1393 Prompted by a bug report on 'foo & bar', but I realized we had
1388 1394 many more potential bug cases with other operators. The regexp is
1389 1395 self.re_exclude_auto, it's fairly commented.
1390 1396
1391 1397 2006-01-12 Ville Vainio <vivainio@gmail.com>
1392 1398
1393 1399 * IPython/iplib.py (make_quoted_expr,handle_shell_escape):
1394 1400 Prettified and hardened string/backslash quoting with ipsystem(),
1395 1401 ipalias() and ipmagic(). Now even \ characters are passed to
1396 1402 %magics, !shell escapes and aliases exactly as they are in the
1397 1403 ipython command line. Should improve backslash experience,
1398 1404 particularly in Windows (path delimiter for some commands that
1399 1405 won't understand '/'), but Unix benefits as well (regexps). %cd
1400 1406 magic still doesn't support backslash path delimiters, though. Also
1401 1407 deleted all pretense of supporting multiline command strings in
1402 1408 !system or %magic commands. Thanks to Jerry McRae for suggestions.
1403 1409
1404 1410 * doc/build_doc_instructions.txt added. Documentation on how to
1405 1411 use doc/update_manual.py, added yesterday. Both files contributed
1406 1412 by JΓΆrgen Stenarson <jorgen.stenarson-AT-bostream.nu>. This slates
1407 1413 doc/*.sh for deprecation at a later date.
1408 1414
1409 1415 * /ipython.py Added ipython.py to root directory for
1410 1416 zero-installation (tar xzvf ipython.tgz; cd ipython; python
1411 1417 ipython.py) and development convenience (no need to keep doing
1412 1418 "setup.py install" between changes).
1413 1419
1414 1420 * Made ! and !! shell escapes work (again) in multiline expressions:
1415 1421 if 1:
1416 1422 !ls
1417 1423 !!ls
1418 1424
1419 1425 2006-01-12 Fernando Perez <Fernando.Perez@colorado.edu>
1420 1426
1421 1427 * IPython/ipstruct.py (Struct): Rename IPython.Struct to
1422 1428 IPython.ipstruct, to avoid local shadowing of the stdlib 'struct'
1423 1429 module in case-insensitive installation. Was causing crashes
1424 1430 under win32. Closes http://www.scipy.net/roundup/ipython/issue49.
1425 1431
1426 1432 * IPython/Magic.py (magic_pycat): Fix pycat, patch by Marien Zwart
1427 1433 <marienz-AT-gentoo.org>, closes
1428 1434 http://www.scipy.net/roundup/ipython/issue51.
1429 1435
1430 1436 2006-01-11 Fernando Perez <Fernando.Perez@colorado.edu>
1431 1437
1432 1438 * IPython/Shell.py (IPShellGTK.on_timer): Finally fix the
1433 1439 problem of excessive CPU usage under *nix and keyboard lag under
1434 1440 win32.
1435 1441
1436 1442 2006-01-10 *** Released version 0.7.0
1437 1443
1438 1444 2006-01-10 Fernando Perez <Fernando.Perez@colorado.edu>
1439 1445
1440 1446 * IPython/Release.py (revision): tag version number to 0.7.0,
1441 1447 ready for release.
1442 1448
1443 1449 * IPython/Magic.py (magic_edit): Add print statement to %edit so
1444 1450 it informs the user of the name of the temp. file used. This can
1445 1451 help if you decide later to reuse that same file, so you know
1446 1452 where to copy the info from.
1447 1453
1448 1454 2006-01-09 Fernando Perez <Fernando.Perez@colorado.edu>
1449 1455
1450 1456 * setup_bdist_egg.py: little script to build an egg. Added
1451 1457 support in the release tools as well.
1452 1458
1453 1459 2006-01-08 Fernando Perez <Fernando.Perez@colorado.edu>
1454 1460
1455 1461 * IPython/Shell.py (IPShellWX.__init__): add support for WXPython
1456 1462 version selection (new -wxversion command line and ipythonrc
1457 1463 parameter). Patch contributed by Arnd Baecker
1458 1464 <arnd.baecker-AT-web.de>.
1459 1465
1460 1466 * IPython/iplib.py (embed_mainloop): fix tab-completion in
1461 1467 embedded instances, for variables defined at the interactive
1462 1468 prompt of the embedded ipython. Reported by Arnd.
1463 1469
1464 1470 * IPython/Magic.py (magic_autocall): Fix %autocall magic. Now
1465 1471 it can be used as a (stateful) toggle, or with a direct parameter.
1466 1472
1467 1473 * IPython/ultraTB.py (_fixed_getinnerframes): remove debug assert which
1468 1474 could be triggered in certain cases and cause the traceback
1469 1475 printer not to work.
1470 1476
1471 1477 2006-01-07 Fernando Perez <Fernando.Perez@colorado.edu>
1472 1478
1473 1479 * IPython/iplib.py (_should_recompile): Small fix, closes
1474 1480 http://www.scipy.net/roundup/ipython/issue48. Patch by Scott.
1475 1481
1476 1482 2006-01-04 Fernando Perez <Fernando.Perez@colorado.edu>
1477 1483
1478 1484 * IPython/Shell.py (IPShellGTK.mainloop): fix bug in the GTK
1479 1485 backend for matplotlib (100% cpu utiliziation). Thanks to Charlie
1480 1486 Moad for help with tracking it down.
1481 1487
1482 1488 * IPython/iplib.py (handle_auto): fix autocall handling for
1483 1489 objects which support BOTH __getitem__ and __call__ (so that f [x]
1484 1490 is left alone, instead of becoming f([x]) automatically).
1485 1491
1486 1492 * IPython/Magic.py (magic_cd): fix crash when cd -b was used.
1487 1493 Ville's patch.
1488 1494
1489 1495 2006-01-03 Fernando Perez <Fernando.Perez@colorado.edu>
1490 1496
1491 1497 * IPython/iplib.py (handle_auto): changed autocall semantics to
1492 1498 include 'smart' mode, where the autocall transformation is NOT
1493 1499 applied if there are no arguments on the line. This allows you to
1494 1500 just type 'foo' if foo is a callable to see its internal form,
1495 1501 instead of having it called with no arguments (typically a
1496 1502 mistake). The old 'full' autocall still exists: for that, you
1497 1503 need to set the 'autocall' parameter to 2 in your ipythonrc file.
1498 1504
1499 1505 * IPython/completer.py (Completer.attr_matches): add
1500 1506 tab-completion support for Enthoughts' traits. After a report by
1501 1507 Arnd and a patch by Prabhu.
1502 1508
1503 1509 2006-01-02 Fernando Perez <Fernando.Perez@colorado.edu>
1504 1510
1505 1511 * IPython/ultraTB.py (_fixed_getinnerframes): added Alex
1506 1512 Schmolck's patch to fix inspect.getinnerframes().
1507 1513
1508 1514 * IPython/iplib.py (InteractiveShell.__init__): significant fixes
1509 1515 for embedded instances, regarding handling of namespaces and items
1510 1516 added to the __builtin__ one. Multiple embedded instances and
1511 1517 recursive embeddings should work better now (though I'm not sure
1512 1518 I've got all the corner cases fixed, that code is a bit of a brain
1513 1519 twister).
1514 1520
1515 1521 * IPython/Magic.py (magic_edit): added support to edit in-memory
1516 1522 macros (automatically creates the necessary temp files). %edit
1517 1523 also doesn't return the file contents anymore, it's just noise.
1518 1524
1519 1525 * IPython/completer.py (Completer.attr_matches): revert change to
1520 1526 complete only on attributes listed in __all__. I realized it
1521 1527 cripples the tab-completion system as a tool for exploring the
1522 1528 internals of unknown libraries (it renders any non-__all__
1523 1529 attribute off-limits). I got bit by this when trying to see
1524 1530 something inside the dis module.
1525 1531
1526 1532 2005-12-31 Fernando Perez <Fernando.Perez@colorado.edu>
1527 1533
1528 1534 * IPython/iplib.py (InteractiveShell.__init__): add .meta
1529 1535 namespace for users and extension writers to hold data in. This
1530 1536 follows the discussion in
1531 1537 http://projects.scipy.org/ipython/ipython/wiki/RefactoringIPython.
1532 1538
1533 1539 * IPython/completer.py (IPCompleter.complete): small patch to help
1534 1540 tab-completion under Emacs, after a suggestion by John Barnard
1535 1541 <barnarj-AT-ccf.org>.
1536 1542
1537 1543 * IPython/Magic.py (Magic.extract_input_slices): added support for
1538 1544 the slice notation in magics to use N-M to represent numbers N...M
1539 1545 (closed endpoints). This is used by %macro and %save.
1540 1546
1541 1547 * IPython/completer.py (Completer.attr_matches): for modules which
1542 1548 define __all__, complete only on those. After a patch by Jeffrey
1543 1549 Collins <jcollins_boulder-AT-earthlink.net>. Also, clean up and
1544 1550 speed up this routine.
1545 1551
1546 1552 * IPython/Logger.py (Logger.log): fix a history handling bug. I
1547 1553 don't know if this is the end of it, but the behavior now is
1548 1554 certainly much more correct. Note that coupled with macros,
1549 1555 slightly surprising (at first) behavior may occur: a macro will in
1550 1556 general expand to multiple lines of input, so upon exiting, the
1551 1557 in/out counters will both be bumped by the corresponding amount
1552 1558 (as if the macro's contents had been typed interactively). Typing
1553 1559 %hist will reveal the intermediate (silently processed) lines.
1554 1560
1555 1561 * IPython/Magic.py (magic_run): fix a subtle bug which could cause
1556 1562 pickle to fail (%run was overwriting __main__ and not restoring
1557 1563 it, but pickle relies on __main__ to operate).
1558 1564
1559 1565 * IPython/iplib.py (InteractiveShell): fix pdb calling: I'm now
1560 1566 using properties, but forgot to make the main InteractiveShell
1561 1567 class a new-style class. Properties fail silently, and
1562 1568 mysteriously, with old-style class (getters work, but
1563 1569 setters don't do anything).
1564 1570
1565 1571 2005-12-30 Fernando Perez <Fernando.Perez@colorado.edu>
1566 1572
1567 1573 * IPython/Magic.py (magic_history): fix history reporting bug (I
1568 1574 know some nasties are still there, I just can't seem to find a
1569 1575 reproducible test case to track them down; the input history is
1570 1576 falling out of sync...)
1571 1577
1572 1578 * IPython/iplib.py (handle_shell_escape): fix bug where both
1573 1579 aliases and system accesses where broken for indented code (such
1574 1580 as loops).
1575 1581
1576 1582 * IPython/genutils.py (shell): fix small but critical bug for
1577 1583 win32 system access.
1578 1584
1579 1585 2005-12-29 Fernando Perez <Fernando.Perez@colorado.edu>
1580 1586
1581 1587 * IPython/iplib.py (showtraceback): remove use of the
1582 1588 sys.last_{type/value/traceback} structures, which are non
1583 1589 thread-safe.
1584 1590 (_prefilter): change control flow to ensure that we NEVER
1585 1591 introspect objects when autocall is off. This will guarantee that
1586 1592 having an input line of the form 'x.y', where access to attribute
1587 1593 'y' has side effects, doesn't trigger the side effect TWICE. It
1588 1594 is important to note that, with autocall on, these side effects
1589 1595 can still happen.
1590 1596 (ipsystem): new builtin, to complete the ip{magic/alias/system}
1591 1597 trio. IPython offers these three kinds of special calls which are
1592 1598 not python code, and it's a good thing to have their call method
1593 1599 be accessible as pure python functions (not just special syntax at
1594 1600 the command line). It gives us a better internal implementation
1595 1601 structure, as well as exposing these for user scripting more
1596 1602 cleanly.
1597 1603
1598 1604 * IPython/macro.py (Macro.__init__): moved macros to a standalone
1599 1605 file. Now that they'll be more likely to be used with the
1600 1606 persistance system (%store), I want to make sure their module path
1601 1607 doesn't change in the future, so that we don't break things for
1602 1608 users' persisted data.
1603 1609
1604 1610 * IPython/iplib.py (autoindent_update): move indentation
1605 1611 management into the _text_ processing loop, not the keyboard
1606 1612 interactive one. This is necessary to correctly process non-typed
1607 1613 multiline input (such as macros).
1608 1614
1609 1615 * IPython/Magic.py (Magic.format_latex): patch by Stefan van der
1610 1616 Walt <stefan-AT-sun.ac.za> to fix latex formatting of docstrings,
1611 1617 which was producing problems in the resulting manual.
1612 1618 (magic_whos): improve reporting of instances (show their class,
1613 1619 instead of simply printing 'instance' which isn't terribly
1614 1620 informative).
1615 1621
1616 1622 * IPython/genutils.py (shell): commit Jorgen Stenarson's patch
1617 1623 (minor mods) to support network shares under win32.
1618 1624
1619 1625 * IPython/winconsole.py (get_console_size): add new winconsole
1620 1626 module and fixes to page_dumb() to improve its behavior under
1621 1627 win32. Contributed by Alexander Belchenko <bialix-AT-ukr.net>.
1622 1628
1623 1629 * IPython/Magic.py (Macro): simplified Macro class to just
1624 1630 subclass list. We've had only 2.2 compatibility for a very long
1625 1631 time, yet I was still avoiding subclassing the builtin types. No
1626 1632 more (I'm also starting to use properties, though I won't shift to
1627 1633 2.3-specific features quite yet).
1628 1634 (magic_store): added Ville's patch for lightweight variable
1629 1635 persistence, after a request on the user list by Matt Wilkie
1630 1636 <maphew-AT-gmail.com>. The new %store magic's docstring has full
1631 1637 details.
1632 1638
1633 1639 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1634 1640 changed the default logfile name from 'ipython.log' to
1635 1641 'ipython_log.py'. These logs are real python files, and now that
1636 1642 we have much better multiline support, people are more likely to
1637 1643 want to use them as such. Might as well name them correctly.
1638 1644
1639 1645 * IPython/Magic.py: substantial cleanup. While we can't stop
1640 1646 using magics as mixins, due to the existing customizations 'out
1641 1647 there' which rely on the mixin naming conventions, at least I
1642 1648 cleaned out all cross-class name usage. So once we are OK with
1643 1649 breaking compatibility, the two systems can be separated.
1644 1650
1645 1651 * IPython/Logger.py: major cleanup. This one is NOT a mixin
1646 1652 anymore, and the class is a fair bit less hideous as well. New
1647 1653 features were also introduced: timestamping of input, and logging
1648 1654 of output results. These are user-visible with the -t and -o
1649 1655 options to %logstart. Closes
1650 1656 http://www.scipy.net/roundup/ipython/issue11 and a request by
1651 1657 William Stein (SAGE developer - http://modular.ucsd.edu/sage).
1652 1658
1653 1659 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
1654 1660
1655 1661 * IPython/iplib.py (handle_shell_escape): add Ville's patch to
1656 1662 better handle backslashes in paths. See the thread 'More Windows
1657 1663 questions part 2 - \/ characters revisited' on the iypthon user
1658 1664 list:
1659 1665 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
1660 1666
1661 1667 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
1662 1668
1663 1669 (InteractiveShell.__init__): change threaded shells to not use the
1664 1670 ipython crash handler. This was causing more problems than not,
1665 1671 as exceptions in the main thread (GUI code, typically) would
1666 1672 always show up as a 'crash', when they really weren't.
1667 1673
1668 1674 The colors and exception mode commands (%colors/%xmode) have been
1669 1675 synchronized to also take this into account, so users can get
1670 1676 verbose exceptions for their threaded code as well. I also added
1671 1677 support for activating pdb inside this exception handler as well,
1672 1678 so now GUI authors can use IPython's enhanced pdb at runtime.
1673 1679
1674 1680 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
1675 1681 true by default, and add it to the shipped ipythonrc file. Since
1676 1682 this asks the user before proceeding, I think it's OK to make it
1677 1683 true by default.
1678 1684
1679 1685 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
1680 1686 of the previous special-casing of input in the eval loop. I think
1681 1687 this is cleaner, as they really are commands and shouldn't have
1682 1688 a special role in the middle of the core code.
1683 1689
1684 1690 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
1685 1691
1686 1692 * IPython/iplib.py (edit_syntax_error): added support for
1687 1693 automatically reopening the editor if the file had a syntax error
1688 1694 in it. Thanks to scottt who provided the patch at:
1689 1695 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
1690 1696 version committed).
1691 1697
1692 1698 * IPython/iplib.py (handle_normal): add suport for multi-line
1693 1699 input with emtpy lines. This fixes
1694 1700 http://www.scipy.net/roundup/ipython/issue43 and a similar
1695 1701 discussion on the user list.
1696 1702
1697 1703 WARNING: a behavior change is necessarily introduced to support
1698 1704 blank lines: now a single blank line with whitespace does NOT
1699 1705 break the input loop, which means that when autoindent is on, by
1700 1706 default hitting return on the next (indented) line does NOT exit.
1701 1707
1702 1708 Instead, to exit a multiline input you can either have:
1703 1709
1704 1710 - TWO whitespace lines (just hit return again), or
1705 1711 - a single whitespace line of a different length than provided
1706 1712 by the autoindent (add or remove a space).
1707 1713
1708 1714 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
1709 1715 module to better organize all readline-related functionality.
1710 1716 I've deleted FlexCompleter and put all completion clases here.
1711 1717
1712 1718 * IPython/iplib.py (raw_input): improve indentation management.
1713 1719 It is now possible to paste indented code with autoindent on, and
1714 1720 the code is interpreted correctly (though it still looks bad on
1715 1721 screen, due to the line-oriented nature of ipython).
1716 1722 (MagicCompleter.complete): change behavior so that a TAB key on an
1717 1723 otherwise empty line actually inserts a tab, instead of completing
1718 1724 on the entire global namespace. This makes it easier to use the
1719 1725 TAB key for indentation. After a request by Hans Meine
1720 1726 <hans_meine-AT-gmx.net>
1721 1727 (_prefilter): add support so that typing plain 'exit' or 'quit'
1722 1728 does a sensible thing. Originally I tried to deviate as little as
1723 1729 possible from the default python behavior, but even that one may
1724 1730 change in this direction (thread on python-dev to that effect).
1725 1731 Regardless, ipython should do the right thing even if CPython's
1726 1732 '>>>' prompt doesn't.
1727 1733 (InteractiveShell): removed subclassing code.InteractiveConsole
1728 1734 class. By now we'd overridden just about all of its methods: I've
1729 1735 copied the remaining two over, and now ipython is a standalone
1730 1736 class. This will provide a clearer picture for the chainsaw
1731 1737 branch refactoring.
1732 1738
1733 1739 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
1734 1740
1735 1741 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
1736 1742 failures for objects which break when dir() is called on them.
1737 1743
1738 1744 * IPython/FlexCompleter.py (Completer.__init__): Added support for
1739 1745 distinct local and global namespaces in the completer API. This
1740 1746 change allows us to properly handle completion with distinct
1741 1747 scopes, including in embedded instances (this had never really
1742 1748 worked correctly).
1743 1749
1744 1750 Note: this introduces a change in the constructor for
1745 1751 MagicCompleter, as a new global_namespace parameter is now the
1746 1752 second argument (the others were bumped one position).
1747 1753
1748 1754 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
1749 1755
1750 1756 * IPython/iplib.py (embed_mainloop): fix tab-completion in
1751 1757 embedded instances (which can be done now thanks to Vivian's
1752 1758 frame-handling fixes for pdb).
1753 1759 (InteractiveShell.__init__): Fix namespace handling problem in
1754 1760 embedded instances. We were overwriting __main__ unconditionally,
1755 1761 and this should only be done for 'full' (non-embedded) IPython;
1756 1762 embedded instances must respect the caller's __main__. Thanks to
1757 1763 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
1758 1764
1759 1765 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
1760 1766
1761 1767 * setup.py: added download_url to setup(). This registers the
1762 1768 download address at PyPI, which is not only useful to humans
1763 1769 browsing the site, but is also picked up by setuptools (the Eggs
1764 1770 machinery). Thanks to Ville and R. Kern for the info/discussion
1765 1771 on this.
1766 1772
1767 1773 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
1768 1774
1769 1775 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
1770 1776 This brings a lot of nice functionality to the pdb mode, which now
1771 1777 has tab-completion, syntax highlighting, and better stack handling
1772 1778 than before. Many thanks to Vivian De Smedt
1773 1779 <vivian-AT-vdesmedt.com> for the original patches.
1774 1780
1775 1781 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
1776 1782
1777 1783 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
1778 1784 sequence to consistently accept the banner argument. The
1779 1785 inconsistency was tripping SAGE, thanks to Gary Zablackis
1780 1786 <gzabl-AT-yahoo.com> for the report.
1781 1787
1782 1788 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
1783 1789
1784 1790 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1785 1791 Fix bug where a naked 'alias' call in the ipythonrc file would
1786 1792 cause a crash. Bug reported by Jorgen Stenarson.
1787 1793
1788 1794 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
1789 1795
1790 1796 * IPython/ipmaker.py (make_IPython): cleanups which should improve
1791 1797 startup time.
1792 1798
1793 1799 * IPython/iplib.py (runcode): my globals 'fix' for embedded
1794 1800 instances had introduced a bug with globals in normal code. Now
1795 1801 it's working in all cases.
1796 1802
1797 1803 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
1798 1804 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
1799 1805 has been introduced to set the default case sensitivity of the
1800 1806 searches. Users can still select either mode at runtime on a
1801 1807 per-search basis.
1802 1808
1803 1809 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
1804 1810
1805 1811 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
1806 1812 attributes in wildcard searches for subclasses. Modified version
1807 1813 of a patch by Jorgen.
1808 1814
1809 1815 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
1810 1816
1811 1817 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
1812 1818 embedded instances. I added a user_global_ns attribute to the
1813 1819 InteractiveShell class to handle this.
1814 1820
1815 1821 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
1816 1822
1817 1823 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
1818 1824 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
1819 1825 (reported under win32, but may happen also in other platforms).
1820 1826 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
1821 1827
1822 1828 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
1823 1829
1824 1830 * IPython/Magic.py (magic_psearch): new support for wildcard
1825 1831 patterns. Now, typing ?a*b will list all names which begin with a
1826 1832 and end in b, for example. The %psearch magic has full
1827 1833 docstrings. Many thanks to JΓΆrgen Stenarson
1828 1834 <jorgen.stenarson-AT-bostream.nu>, author of the patches
1829 1835 implementing this functionality.
1830 1836
1831 1837 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
1832 1838
1833 1839 * Manual: fixed long-standing annoyance of double-dashes (as in
1834 1840 --prefix=~, for example) being stripped in the HTML version. This
1835 1841 is a latex2html bug, but a workaround was provided. Many thanks
1836 1842 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
1837 1843 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
1838 1844 rolling. This seemingly small issue had tripped a number of users
1839 1845 when first installing, so I'm glad to see it gone.
1840 1846
1841 1847 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
1842 1848
1843 1849 * IPython/Extensions/numeric_formats.py: fix missing import,
1844 1850 reported by Stephen Walton.
1845 1851
1846 1852 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
1847 1853
1848 1854 * IPython/demo.py: finish demo module, fully documented now.
1849 1855
1850 1856 * IPython/genutils.py (file_read): simple little utility to read a
1851 1857 file and ensure it's closed afterwards.
1852 1858
1853 1859 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
1854 1860
1855 1861 * IPython/demo.py (Demo.__init__): added support for individually
1856 1862 tagging blocks for automatic execution.
1857 1863
1858 1864 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
1859 1865 syntax-highlighted python sources, requested by John.
1860 1866
1861 1867 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
1862 1868
1863 1869 * IPython/demo.py (Demo.again): fix bug where again() blocks after
1864 1870 finishing.
1865 1871
1866 1872 * IPython/genutils.py (shlex_split): moved from Magic to here,
1867 1873 where all 2.2 compatibility stuff lives. I needed it for demo.py.
1868 1874
1869 1875 * IPython/demo.py (Demo.__init__): added support for silent
1870 1876 blocks, improved marks as regexps, docstrings written.
1871 1877 (Demo.__init__): better docstring, added support for sys.argv.
1872 1878
1873 1879 * IPython/genutils.py (marquee): little utility used by the demo
1874 1880 code, handy in general.
1875 1881
1876 1882 * IPython/demo.py (Demo.__init__): new class for interactive
1877 1883 demos. Not documented yet, I just wrote it in a hurry for
1878 1884 scipy'05. Will docstring later.
1879 1885
1880 1886 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
1881 1887
1882 1888 * IPython/Shell.py (sigint_handler): Drastic simplification which
1883 1889 also seems to make Ctrl-C work correctly across threads! This is
1884 1890 so simple, that I can't beleive I'd missed it before. Needs more
1885 1891 testing, though.
1886 1892 (KBINT): Never mind, revert changes. I'm sure I'd tried something
1887 1893 like this before...
1888 1894
1889 1895 * IPython/genutils.py (get_home_dir): add protection against
1890 1896 non-dirs in win32 registry.
1891 1897
1892 1898 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
1893 1899 bug where dict was mutated while iterating (pysh crash).
1894 1900
1895 1901 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
1896 1902
1897 1903 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
1898 1904 spurious newlines added by this routine. After a report by
1899 1905 F. Mantegazza.
1900 1906
1901 1907 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
1902 1908
1903 1909 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
1904 1910 calls. These were a leftover from the GTK 1.x days, and can cause
1905 1911 problems in certain cases (after a report by John Hunter).
1906 1912
1907 1913 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
1908 1914 os.getcwd() fails at init time. Thanks to patch from David Remahl
1909 1915 <chmod007-AT-mac.com>.
1910 1916 (InteractiveShell.__init__): prevent certain special magics from
1911 1917 being shadowed by aliases. Closes
1912 1918 http://www.scipy.net/roundup/ipython/issue41.
1913 1919
1914 1920 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
1915 1921
1916 1922 * IPython/iplib.py (InteractiveShell.complete): Added new
1917 1923 top-level completion method to expose the completion mechanism
1918 1924 beyond readline-based environments.
1919 1925
1920 1926 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
1921 1927
1922 1928 * tools/ipsvnc (svnversion): fix svnversion capture.
1923 1929
1924 1930 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
1925 1931 attribute to self, which was missing. Before, it was set by a
1926 1932 routine which in certain cases wasn't being called, so the
1927 1933 instance could end up missing the attribute. This caused a crash.
1928 1934 Closes http://www.scipy.net/roundup/ipython/issue40.
1929 1935
1930 1936 2005-08-16 Fernando Perez <fperez@colorado.edu>
1931 1937
1932 1938 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
1933 1939 contains non-string attribute. Closes
1934 1940 http://www.scipy.net/roundup/ipython/issue38.
1935 1941
1936 1942 2005-08-14 Fernando Perez <fperez@colorado.edu>
1937 1943
1938 1944 * tools/ipsvnc: Minor improvements, to add changeset info.
1939 1945
1940 1946 2005-08-12 Fernando Perez <fperez@colorado.edu>
1941 1947
1942 1948 * IPython/iplib.py (runsource): remove self.code_to_run_src
1943 1949 attribute. I realized this is nothing more than
1944 1950 '\n'.join(self.buffer), and having the same data in two different
1945 1951 places is just asking for synchronization bugs. This may impact
1946 1952 people who have custom exception handlers, so I need to warn
1947 1953 ipython-dev about it (F. Mantegazza may use them).
1948 1954
1949 1955 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
1950 1956
1951 1957 * IPython/genutils.py: fix 2.2 compatibility (generators)
1952 1958
1953 1959 2005-07-18 Fernando Perez <fperez@colorado.edu>
1954 1960
1955 1961 * IPython/genutils.py (get_home_dir): fix to help users with
1956 1962 invalid $HOME under win32.
1957 1963
1958 1964 2005-07-17 Fernando Perez <fperez@colorado.edu>
1959 1965
1960 1966 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
1961 1967 some old hacks and clean up a bit other routines; code should be
1962 1968 simpler and a bit faster.
1963 1969
1964 1970 * IPython/iplib.py (interact): removed some last-resort attempts
1965 1971 to survive broken stdout/stderr. That code was only making it
1966 1972 harder to abstract out the i/o (necessary for gui integration),
1967 1973 and the crashes it could prevent were extremely rare in practice
1968 1974 (besides being fully user-induced in a pretty violent manner).
1969 1975
1970 1976 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
1971 1977 Nothing major yet, but the code is simpler to read; this should
1972 1978 make it easier to do more serious modifications in the future.
1973 1979
1974 1980 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
1975 1981 which broke in .15 (thanks to a report by Ville).
1976 1982
1977 1983 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
1978 1984 be quite correct, I know next to nothing about unicode). This
1979 1985 will allow unicode strings to be used in prompts, amongst other
1980 1986 cases. It also will prevent ipython from crashing when unicode
1981 1987 shows up unexpectedly in many places. If ascii encoding fails, we
1982 1988 assume utf_8. Currently the encoding is not a user-visible
1983 1989 setting, though it could be made so if there is demand for it.
1984 1990
1985 1991 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
1986 1992
1987 1993 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
1988 1994
1989 1995 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
1990 1996
1991 1997 * IPython/genutils.py: Add 2.2 compatibility here, so all other
1992 1998 code can work transparently for 2.2/2.3.
1993 1999
1994 2000 2005-07-16 Fernando Perez <fperez@colorado.edu>
1995 2001
1996 2002 * IPython/ultraTB.py (ExceptionColors): Make a global variable
1997 2003 out of the color scheme table used for coloring exception
1998 2004 tracebacks. This allows user code to add new schemes at runtime.
1999 2005 This is a minimally modified version of the patch at
2000 2006 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
2001 2007 for the contribution.
2002 2008
2003 2009 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
2004 2010 slightly modified version of the patch in
2005 2011 http://www.scipy.net/roundup/ipython/issue34, which also allows me
2006 2012 to remove the previous try/except solution (which was costlier).
2007 2013 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
2008 2014
2009 2015 2005-06-08 Fernando Perez <fperez@colorado.edu>
2010 2016
2011 2017 * IPython/iplib.py (write/write_err): Add methods to abstract all
2012 2018 I/O a bit more.
2013 2019
2014 2020 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
2015 2021 warning, reported by Aric Hagberg, fix by JD Hunter.
2016 2022
2017 2023 2005-06-02 *** Released version 0.6.15
2018 2024
2019 2025 2005-06-01 Fernando Perez <fperez@colorado.edu>
2020 2026
2021 2027 * IPython/iplib.py (MagicCompleter.file_matches): Fix
2022 2028 tab-completion of filenames within open-quoted strings. Note that
2023 2029 this requires that in ~/.ipython/ipythonrc, users change the
2024 2030 readline delimiters configuration to read:
2025 2031
2026 2032 readline_remove_delims -/~
2027 2033
2028 2034
2029 2035 2005-05-31 *** Released version 0.6.14
2030 2036
2031 2037 2005-05-29 Fernando Perez <fperez@colorado.edu>
2032 2038
2033 2039 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
2034 2040 with files not on the filesystem. Reported by Eliyahu Sandler
2035 2041 <eli@gondolin.net>
2036 2042
2037 2043 2005-05-22 Fernando Perez <fperez@colorado.edu>
2038 2044
2039 2045 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
2040 2046 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
2041 2047
2042 2048 2005-05-19 Fernando Perez <fperez@colorado.edu>
2043 2049
2044 2050 * IPython/iplib.py (safe_execfile): close a file which could be
2045 2051 left open (causing problems in win32, which locks open files).
2046 2052 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
2047 2053
2048 2054 2005-05-18 Fernando Perez <fperez@colorado.edu>
2049 2055
2050 2056 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
2051 2057 keyword arguments correctly to safe_execfile().
2052 2058
2053 2059 2005-05-13 Fernando Perez <fperez@colorado.edu>
2054 2060
2055 2061 * ipython.1: Added info about Qt to manpage, and threads warning
2056 2062 to usage page (invoked with --help).
2057 2063
2058 2064 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
2059 2065 new matcher (it goes at the end of the priority list) to do
2060 2066 tab-completion on named function arguments. Submitted by George
2061 2067 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
2062 2068 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
2063 2069 for more details.
2064 2070
2065 2071 * IPython/Magic.py (magic_run): Added new -e flag to ignore
2066 2072 SystemExit exceptions in the script being run. Thanks to a report
2067 2073 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
2068 2074 producing very annoying behavior when running unit tests.
2069 2075
2070 2076 2005-05-12 Fernando Perez <fperez@colorado.edu>
2071 2077
2072 2078 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
2073 2079 which I'd broken (again) due to a changed regexp. In the process,
2074 2080 added ';' as an escape to auto-quote the whole line without
2075 2081 splitting its arguments. Thanks to a report by Jerry McRae
2076 2082 <qrs0xyc02-AT-sneakemail.com>.
2077 2083
2078 2084 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
2079 2085 possible crashes caused by a TokenError. Reported by Ed Schofield
2080 2086 <schofield-AT-ftw.at>.
2081 2087
2082 2088 2005-05-06 Fernando Perez <fperez@colorado.edu>
2083 2089
2084 2090 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
2085 2091
2086 2092 2005-04-29 Fernando Perez <fperez@colorado.edu>
2087 2093
2088 2094 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
2089 2095 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
2090 2096 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
2091 2097 which provides support for Qt interactive usage (similar to the
2092 2098 existing one for WX and GTK). This had been often requested.
2093 2099
2094 2100 2005-04-14 *** Released version 0.6.13
2095 2101
2096 2102 2005-04-08 Fernando Perez <fperez@colorado.edu>
2097 2103
2098 2104 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
2099 2105 from _ofind, which gets called on almost every input line. Now,
2100 2106 we only try to get docstrings if they are actually going to be
2101 2107 used (the overhead of fetching unnecessary docstrings can be
2102 2108 noticeable for certain objects, such as Pyro proxies).
2103 2109
2104 2110 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
2105 2111 for completers. For some reason I had been passing them the state
2106 2112 variable, which completers never actually need, and was in
2107 2113 conflict with the rlcompleter API. Custom completers ONLY need to
2108 2114 take the text parameter.
2109 2115
2110 2116 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
2111 2117 work correctly in pysh. I've also moved all the logic which used
2112 2118 to be in pysh.py here, which will prevent problems with future
2113 2119 upgrades. However, this time I must warn users to update their
2114 2120 pysh profile to include the line
2115 2121
2116 2122 import_all IPython.Extensions.InterpreterExec
2117 2123
2118 2124 because otherwise things won't work for them. They MUST also
2119 2125 delete pysh.py and the line
2120 2126
2121 2127 execfile pysh.py
2122 2128
2123 2129 from their ipythonrc-pysh.
2124 2130
2125 2131 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
2126 2132 robust in the face of objects whose dir() returns non-strings
2127 2133 (which it shouldn't, but some broken libs like ITK do). Thanks to
2128 2134 a patch by John Hunter (implemented differently, though). Also
2129 2135 minor improvements by using .extend instead of + on lists.
2130 2136
2131 2137 * pysh.py:
2132 2138
2133 2139 2005-04-06 Fernando Perez <fperez@colorado.edu>
2134 2140
2135 2141 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
2136 2142 by default, so that all users benefit from it. Those who don't
2137 2143 want it can still turn it off.
2138 2144
2139 2145 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
2140 2146 config file, I'd forgotten about this, so users were getting it
2141 2147 off by default.
2142 2148
2143 2149 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
2144 2150 consistency. Now magics can be called in multiline statements,
2145 2151 and python variables can be expanded in magic calls via $var.
2146 2152 This makes the magic system behave just like aliases or !system
2147 2153 calls.
2148 2154
2149 2155 2005-03-28 Fernando Perez <fperez@colorado.edu>
2150 2156
2151 2157 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
2152 2158 expensive string additions for building command. Add support for
2153 2159 trailing ';' when autocall is used.
2154 2160
2155 2161 2005-03-26 Fernando Perez <fperez@colorado.edu>
2156 2162
2157 2163 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
2158 2164 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
2159 2165 ipython.el robust against prompts with any number of spaces
2160 2166 (including 0) after the ':' character.
2161 2167
2162 2168 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
2163 2169 continuation prompt, which misled users to think the line was
2164 2170 already indented. Closes debian Bug#300847, reported to me by
2165 2171 Norbert Tretkowski <tretkowski-AT-inittab.de>.
2166 2172
2167 2173 2005-03-23 Fernando Perez <fperez@colorado.edu>
2168 2174
2169 2175 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
2170 2176 properly aligned if they have embedded newlines.
2171 2177
2172 2178 * IPython/iplib.py (runlines): Add a public method to expose
2173 2179 IPython's code execution machinery, so that users can run strings
2174 2180 as if they had been typed at the prompt interactively.
2175 2181 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
2176 2182 methods which can call the system shell, but with python variable
2177 2183 expansion. The three such methods are: __IPYTHON__.system,
2178 2184 .getoutput and .getoutputerror. These need to be documented in a
2179 2185 'public API' section (to be written) of the manual.
2180 2186
2181 2187 2005-03-20 Fernando Perez <fperez@colorado.edu>
2182 2188
2183 2189 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
2184 2190 for custom exception handling. This is quite powerful, and it
2185 2191 allows for user-installable exception handlers which can trap
2186 2192 custom exceptions at runtime and treat them separately from
2187 2193 IPython's default mechanisms. At the request of FrΓ©dΓ©ric
2188 2194 Mantegazza <mantegazza-AT-ill.fr>.
2189 2195 (InteractiveShell.set_custom_completer): public API function to
2190 2196 add new completers at runtime.
2191 2197
2192 2198 2005-03-19 Fernando Perez <fperez@colorado.edu>
2193 2199
2194 2200 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
2195 2201 allow objects which provide their docstrings via non-standard
2196 2202 mechanisms (like Pyro proxies) to still be inspected by ipython's
2197 2203 ? system.
2198 2204
2199 2205 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
2200 2206 automatic capture system. I tried quite hard to make it work
2201 2207 reliably, and simply failed. I tried many combinations with the
2202 2208 subprocess module, but eventually nothing worked in all needed
2203 2209 cases (not blocking stdin for the child, duplicating stdout
2204 2210 without blocking, etc). The new %sc/%sx still do capture to these
2205 2211 magical list/string objects which make shell use much more
2206 2212 conveninent, so not all is lost.
2207 2213
2208 2214 XXX - FIX MANUAL for the change above!
2209 2215
2210 2216 (runsource): I copied code.py's runsource() into ipython to modify
2211 2217 it a bit. Now the code object and source to be executed are
2212 2218 stored in ipython. This makes this info accessible to third-party
2213 2219 tools, like custom exception handlers. After a request by FrΓ©dΓ©ric
2214 2220 Mantegazza <mantegazza-AT-ill.fr>.
2215 2221
2216 2222 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
2217 2223 history-search via readline (like C-p/C-n). I'd wanted this for a
2218 2224 long time, but only recently found out how to do it. For users
2219 2225 who already have their ipythonrc files made and want this, just
2220 2226 add:
2221 2227
2222 2228 readline_parse_and_bind "\e[A": history-search-backward
2223 2229 readline_parse_and_bind "\e[B": history-search-forward
2224 2230
2225 2231 2005-03-18 Fernando Perez <fperez@colorado.edu>
2226 2232
2227 2233 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
2228 2234 LSString and SList classes which allow transparent conversions
2229 2235 between list mode and whitespace-separated string.
2230 2236 (magic_r): Fix recursion problem in %r.
2231 2237
2232 2238 * IPython/genutils.py (LSString): New class to be used for
2233 2239 automatic storage of the results of all alias/system calls in _o
2234 2240 and _e (stdout/err). These provide a .l/.list attribute which
2235 2241 does automatic splitting on newlines. This means that for most
2236 2242 uses, you'll never need to do capturing of output with %sc/%sx
2237 2243 anymore, since ipython keeps this always done for you. Note that
2238 2244 only the LAST results are stored, the _o/e variables are
2239 2245 overwritten on each call. If you need to save their contents
2240 2246 further, simply bind them to any other name.
2241 2247
2242 2248 2005-03-17 Fernando Perez <fperez@colorado.edu>
2243 2249
2244 2250 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
2245 2251 prompt namespace handling.
2246 2252
2247 2253 2005-03-16 Fernando Perez <fperez@colorado.edu>
2248 2254
2249 2255 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
2250 2256 classic prompts to be '>>> ' (final space was missing, and it
2251 2257 trips the emacs python mode).
2252 2258 (BasePrompt.__str__): Added safe support for dynamic prompt
2253 2259 strings. Now you can set your prompt string to be '$x', and the
2254 2260 value of x will be printed from your interactive namespace. The
2255 2261 interpolation syntax includes the full Itpl support, so
2256 2262 ${foo()+x+bar()} is a valid prompt string now, and the function
2257 2263 calls will be made at runtime.
2258 2264
2259 2265 2005-03-15 Fernando Perez <fperez@colorado.edu>
2260 2266
2261 2267 * IPython/Magic.py (magic_history): renamed %hist to %history, to
2262 2268 avoid name clashes in pylab. %hist still works, it just forwards
2263 2269 the call to %history.
2264 2270
2265 2271 2005-03-02 *** Released version 0.6.12
2266 2272
2267 2273 2005-03-02 Fernando Perez <fperez@colorado.edu>
2268 2274
2269 2275 * IPython/iplib.py (handle_magic): log magic calls properly as
2270 2276 ipmagic() function calls.
2271 2277
2272 2278 * IPython/Magic.py (magic_time): Improved %time to support
2273 2279 statements and provide wall-clock as well as CPU time.
2274 2280
2275 2281 2005-02-27 Fernando Perez <fperez@colorado.edu>
2276 2282
2277 2283 * IPython/hooks.py: New hooks module, to expose user-modifiable
2278 2284 IPython functionality in a clean manner. For now only the editor
2279 2285 hook is actually written, and other thigns which I intend to turn
2280 2286 into proper hooks aren't yet there. The display and prefilter
2281 2287 stuff, for example, should be hooks. But at least now the
2282 2288 framework is in place, and the rest can be moved here with more
2283 2289 time later. IPython had had a .hooks variable for a long time for
2284 2290 this purpose, but I'd never actually used it for anything.
2285 2291
2286 2292 2005-02-26 Fernando Perez <fperez@colorado.edu>
2287 2293
2288 2294 * IPython/ipmaker.py (make_IPython): make the default ipython
2289 2295 directory be called _ipython under win32, to follow more the
2290 2296 naming peculiarities of that platform (where buggy software like
2291 2297 Visual Sourcesafe breaks with .named directories). Reported by
2292 2298 Ville Vainio.
2293 2299
2294 2300 2005-02-23 Fernando Perez <fperez@colorado.edu>
2295 2301
2296 2302 * IPython/iplib.py (InteractiveShell.__init__): removed a few
2297 2303 auto_aliases for win32 which were causing problems. Users can
2298 2304 define the ones they personally like.
2299 2305
2300 2306 2005-02-21 Fernando Perez <fperez@colorado.edu>
2301 2307
2302 2308 * IPython/Magic.py (magic_time): new magic to time execution of
2303 2309 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
2304 2310
2305 2311 2005-02-19 Fernando Perez <fperez@colorado.edu>
2306 2312
2307 2313 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
2308 2314 into keys (for prompts, for example).
2309 2315
2310 2316 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
2311 2317 prompts in case users want them. This introduces a small behavior
2312 2318 change: ipython does not automatically add a space to all prompts
2313 2319 anymore. To get the old prompts with a space, users should add it
2314 2320 manually to their ipythonrc file, so for example prompt_in1 should
2315 2321 now read 'In [\#]: ' instead of 'In [\#]:'.
2316 2322 (BasePrompt.__init__): New option prompts_pad_left (only in rc
2317 2323 file) to control left-padding of secondary prompts.
2318 2324
2319 2325 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
2320 2326 the profiler can't be imported. Fix for Debian, which removed
2321 2327 profile.py because of License issues. I applied a slightly
2322 2328 modified version of the original Debian patch at
2323 2329 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
2324 2330
2325 2331 2005-02-17 Fernando Perez <fperez@colorado.edu>
2326 2332
2327 2333 * IPython/genutils.py (native_line_ends): Fix bug which would
2328 2334 cause improper line-ends under win32 b/c I was not opening files
2329 2335 in binary mode. Bug report and fix thanks to Ville.
2330 2336
2331 2337 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
2332 2338 trying to catch spurious foo[1] autocalls. My fix actually broke
2333 2339 ',/' autoquote/call with explicit escape (bad regexp).
2334 2340
2335 2341 2005-02-15 *** Released version 0.6.11
2336 2342
2337 2343 2005-02-14 Fernando Perez <fperez@colorado.edu>
2338 2344
2339 2345 * IPython/background_jobs.py: New background job management
2340 2346 subsystem. This is implemented via a new set of classes, and
2341 2347 IPython now provides a builtin 'jobs' object for background job
2342 2348 execution. A convenience %bg magic serves as a lightweight
2343 2349 frontend for starting the more common type of calls. This was
2344 2350 inspired by discussions with B. Granger and the BackgroundCommand
2345 2351 class described in the book Python Scripting for Computational
2346 2352 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
2347 2353 (although ultimately no code from this text was used, as IPython's
2348 2354 system is a separate implementation).
2349 2355
2350 2356 * IPython/iplib.py (MagicCompleter.python_matches): add new option
2351 2357 to control the completion of single/double underscore names
2352 2358 separately. As documented in the example ipytonrc file, the
2353 2359 readline_omit__names variable can now be set to 2, to omit even
2354 2360 single underscore names. Thanks to a patch by Brian Wong
2355 2361 <BrianWong-AT-AirgoNetworks.Com>.
2356 2362 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
2357 2363 be autocalled as foo([1]) if foo were callable. A problem for
2358 2364 things which are both callable and implement __getitem__.
2359 2365 (init_readline): Fix autoindentation for win32. Thanks to a patch
2360 2366 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
2361 2367
2362 2368 2005-02-12 Fernando Perez <fperez@colorado.edu>
2363 2369
2364 2370 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
2365 2371 which I had written long ago to sort out user error messages which
2366 2372 may occur during startup. This seemed like a good idea initially,
2367 2373 but it has proven a disaster in retrospect. I don't want to
2368 2374 change much code for now, so my fix is to set the internal 'debug'
2369 2375 flag to true everywhere, whose only job was precisely to control
2370 2376 this subsystem. This closes issue 28 (as well as avoiding all
2371 2377 sorts of strange hangups which occur from time to time).
2372 2378
2373 2379 2005-02-07 Fernando Perez <fperez@colorado.edu>
2374 2380
2375 2381 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
2376 2382 previous call produced a syntax error.
2377 2383
2378 2384 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
2379 2385 classes without constructor.
2380 2386
2381 2387 2005-02-06 Fernando Perez <fperez@colorado.edu>
2382 2388
2383 2389 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
2384 2390 completions with the results of each matcher, so we return results
2385 2391 to the user from all namespaces. This breaks with ipython
2386 2392 tradition, but I think it's a nicer behavior. Now you get all
2387 2393 possible completions listed, from all possible namespaces (python,
2388 2394 filesystem, magics...) After a request by John Hunter
2389 2395 <jdhunter-AT-nitace.bsd.uchicago.edu>.
2390 2396
2391 2397 2005-02-05 Fernando Perez <fperez@colorado.edu>
2392 2398
2393 2399 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
2394 2400 the call had quote characters in it (the quotes were stripped).
2395 2401
2396 2402 2005-01-31 Fernando Perez <fperez@colorado.edu>
2397 2403
2398 2404 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
2399 2405 Itpl.itpl() to make the code more robust against psyco
2400 2406 optimizations.
2401 2407
2402 2408 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
2403 2409 of causing an exception. Quicker, cleaner.
2404 2410
2405 2411 2005-01-28 Fernando Perez <fperez@colorado.edu>
2406 2412
2407 2413 * scripts/ipython_win_post_install.py (install): hardcode
2408 2414 sys.prefix+'python.exe' as the executable path. It turns out that
2409 2415 during the post-installation run, sys.executable resolves to the
2410 2416 name of the binary installer! I should report this as a distutils
2411 2417 bug, I think. I updated the .10 release with this tiny fix, to
2412 2418 avoid annoying the lists further.
2413 2419
2414 2420 2005-01-27 *** Released version 0.6.10
2415 2421
2416 2422 2005-01-27 Fernando Perez <fperez@colorado.edu>
2417 2423
2418 2424 * IPython/numutils.py (norm): Added 'inf' as optional name for
2419 2425 L-infinity norm, included references to mathworld.com for vector
2420 2426 norm definitions.
2421 2427 (amin/amax): added amin/amax for array min/max. Similar to what
2422 2428 pylab ships with after the recent reorganization of names.
2423 2429 (spike/spike_odd): removed deprecated spike/spike_odd functions.
2424 2430
2425 2431 * ipython.el: committed Alex's recent fixes and improvements.
2426 2432 Tested with python-mode from CVS, and it looks excellent. Since
2427 2433 python-mode hasn't released anything in a while, I'm temporarily
2428 2434 putting a copy of today's CVS (v 4.70) of python-mode in:
2429 2435 http://ipython.scipy.org/tmp/python-mode.el
2430 2436
2431 2437 * scripts/ipython_win_post_install.py (install): Win32 fix to use
2432 2438 sys.executable for the executable name, instead of assuming it's
2433 2439 called 'python.exe' (the post-installer would have produced broken
2434 2440 setups on systems with a differently named python binary).
2435 2441
2436 2442 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
2437 2443 references to os.linesep, to make the code more
2438 2444 platform-independent. This is also part of the win32 coloring
2439 2445 fixes.
2440 2446
2441 2447 * IPython/genutils.py (page_dumb): Remove attempts to chop long
2442 2448 lines, which actually cause coloring bugs because the length of
2443 2449 the line is very difficult to correctly compute with embedded
2444 2450 escapes. This was the source of all the coloring problems under
2445 2451 Win32. I think that _finally_, Win32 users have a properly
2446 2452 working ipython in all respects. This would never have happened
2447 2453 if not for Gary Bishop and Viktor Ransmayr's great help and work.
2448 2454
2449 2455 2005-01-26 *** Released version 0.6.9
2450 2456
2451 2457 2005-01-25 Fernando Perez <fperez@colorado.edu>
2452 2458
2453 2459 * setup.py: finally, we have a true Windows installer, thanks to
2454 2460 the excellent work of Viktor Ransmayr
2455 2461 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
2456 2462 Windows users. The setup routine is quite a bit cleaner thanks to
2457 2463 this, and the post-install script uses the proper functions to
2458 2464 allow a clean de-installation using the standard Windows Control
2459 2465 Panel.
2460 2466
2461 2467 * IPython/genutils.py (get_home_dir): changed to use the $HOME
2462 2468 environment variable under all OSes (including win32) if
2463 2469 available. This will give consistency to win32 users who have set
2464 2470 this variable for any reason. If os.environ['HOME'] fails, the
2465 2471 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
2466 2472
2467 2473 2005-01-24 Fernando Perez <fperez@colorado.edu>
2468 2474
2469 2475 * IPython/numutils.py (empty_like): add empty_like(), similar to
2470 2476 zeros_like() but taking advantage of the new empty() Numeric routine.
2471 2477
2472 2478 2005-01-23 *** Released version 0.6.8
2473 2479
2474 2480 2005-01-22 Fernando Perez <fperez@colorado.edu>
2475 2481
2476 2482 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
2477 2483 automatic show() calls. After discussing things with JDH, it
2478 2484 turns out there are too many corner cases where this can go wrong.
2479 2485 It's best not to try to be 'too smart', and simply have ipython
2480 2486 reproduce as much as possible the default behavior of a normal
2481 2487 python shell.
2482 2488
2483 2489 * IPython/iplib.py (InteractiveShell.__init__): Modified the
2484 2490 line-splitting regexp and _prefilter() to avoid calling getattr()
2485 2491 on assignments. This closes
2486 2492 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
2487 2493 readline uses getattr(), so a simple <TAB> keypress is still
2488 2494 enough to trigger getattr() calls on an object.
2489 2495
2490 2496 2005-01-21 Fernando Perez <fperez@colorado.edu>
2491 2497
2492 2498 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
2493 2499 docstring under pylab so it doesn't mask the original.
2494 2500
2495 2501 2005-01-21 *** Released version 0.6.7
2496 2502
2497 2503 2005-01-21 Fernando Perez <fperez@colorado.edu>
2498 2504
2499 2505 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
2500 2506 signal handling for win32 users in multithreaded mode.
2501 2507
2502 2508 2005-01-17 Fernando Perez <fperez@colorado.edu>
2503 2509
2504 2510 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
2505 2511 instances with no __init__. After a crash report by Norbert Nemec
2506 2512 <Norbert-AT-nemec-online.de>.
2507 2513
2508 2514 2005-01-14 Fernando Perez <fperez@colorado.edu>
2509 2515
2510 2516 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
2511 2517 names for verbose exceptions, when multiple dotted names and the
2512 2518 'parent' object were present on the same line.
2513 2519
2514 2520 2005-01-11 Fernando Perez <fperez@colorado.edu>
2515 2521
2516 2522 * IPython/genutils.py (flag_calls): new utility to trap and flag
2517 2523 calls in functions. I need it to clean up matplotlib support.
2518 2524 Also removed some deprecated code in genutils.
2519 2525
2520 2526 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
2521 2527 that matplotlib scripts called with %run, which don't call show()
2522 2528 themselves, still have their plotting windows open.
2523 2529
2524 2530 2005-01-05 Fernando Perez <fperez@colorado.edu>
2525 2531
2526 2532 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
2527 2533 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
2528 2534
2529 2535 2004-12-19 Fernando Perez <fperez@colorado.edu>
2530 2536
2531 2537 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
2532 2538 parent_runcode, which was an eyesore. The same result can be
2533 2539 obtained with Python's regular superclass mechanisms.
2534 2540
2535 2541 2004-12-17 Fernando Perez <fperez@colorado.edu>
2536 2542
2537 2543 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
2538 2544 reported by Prabhu.
2539 2545 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
2540 2546 sys.stderr) instead of explicitly calling sys.stderr. This helps
2541 2547 maintain our I/O abstractions clean, for future GUI embeddings.
2542 2548
2543 2549 * IPython/genutils.py (info): added new utility for sys.stderr
2544 2550 unified info message handling (thin wrapper around warn()).
2545 2551
2546 2552 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
2547 2553 composite (dotted) names on verbose exceptions.
2548 2554 (VerboseTB.nullrepr): harden against another kind of errors which
2549 2555 Python's inspect module can trigger, and which were crashing
2550 2556 IPython. Thanks to a report by Marco Lombardi
2551 2557 <mlombard-AT-ma010192.hq.eso.org>.
2552 2558
2553 2559 2004-12-13 *** Released version 0.6.6
2554 2560
2555 2561 2004-12-12 Fernando Perez <fperez@colorado.edu>
2556 2562
2557 2563 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
2558 2564 generated by pygtk upon initialization if it was built without
2559 2565 threads (for matplotlib users). After a crash reported by
2560 2566 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
2561 2567
2562 2568 * IPython/ipmaker.py (make_IPython): fix small bug in the
2563 2569 import_some parameter for multiple imports.
2564 2570
2565 2571 * IPython/iplib.py (ipmagic): simplified the interface of
2566 2572 ipmagic() to take a single string argument, just as it would be
2567 2573 typed at the IPython cmd line.
2568 2574 (ipalias): Added new ipalias() with an interface identical to
2569 2575 ipmagic(). This completes exposing a pure python interface to the
2570 2576 alias and magic system, which can be used in loops or more complex
2571 2577 code where IPython's automatic line mangling is not active.
2572 2578
2573 2579 * IPython/genutils.py (timing): changed interface of timing to
2574 2580 simply run code once, which is the most common case. timings()
2575 2581 remains unchanged, for the cases where you want multiple runs.
2576 2582
2577 2583 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
2578 2584 bug where Python2.2 crashes with exec'ing code which does not end
2579 2585 in a single newline. Python 2.3 is OK, so I hadn't noticed this
2580 2586 before.
2581 2587
2582 2588 2004-12-10 Fernando Perez <fperez@colorado.edu>
2583 2589
2584 2590 * IPython/Magic.py (Magic.magic_prun): changed name of option from
2585 2591 -t to -T, to accomodate the new -t flag in %run (the %run and
2586 2592 %prun options are kind of intermixed, and it's not easy to change
2587 2593 this with the limitations of python's getopt).
2588 2594
2589 2595 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
2590 2596 the execution of scripts. It's not as fine-tuned as timeit.py,
2591 2597 but it works from inside ipython (and under 2.2, which lacks
2592 2598 timeit.py). Optionally a number of runs > 1 can be given for
2593 2599 timing very short-running code.
2594 2600
2595 2601 * IPython/genutils.py (uniq_stable): new routine which returns a
2596 2602 list of unique elements in any iterable, but in stable order of
2597 2603 appearance. I needed this for the ultraTB fixes, and it's a handy
2598 2604 utility.
2599 2605
2600 2606 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
2601 2607 dotted names in Verbose exceptions. This had been broken since
2602 2608 the very start, now x.y will properly be printed in a Verbose
2603 2609 traceback, instead of x being shown and y appearing always as an
2604 2610 'undefined global'. Getting this to work was a bit tricky,
2605 2611 because by default python tokenizers are stateless. Saved by
2606 2612 python's ability to easily add a bit of state to an arbitrary
2607 2613 function (without needing to build a full-blown callable object).
2608 2614
2609 2615 Also big cleanup of this code, which had horrendous runtime
2610 2616 lookups of zillions of attributes for colorization. Moved all
2611 2617 this code into a few templates, which make it cleaner and quicker.
2612 2618
2613 2619 Printout quality was also improved for Verbose exceptions: one
2614 2620 variable per line, and memory addresses are printed (this can be
2615 2621 quite handy in nasty debugging situations, which is what Verbose
2616 2622 is for).
2617 2623
2618 2624 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
2619 2625 the command line as scripts to be loaded by embedded instances.
2620 2626 Doing so has the potential for an infinite recursion if there are
2621 2627 exceptions thrown in the process. This fixes a strange crash
2622 2628 reported by Philippe MULLER <muller-AT-irit.fr>.
2623 2629
2624 2630 2004-12-09 Fernando Perez <fperez@colorado.edu>
2625 2631
2626 2632 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
2627 2633 to reflect new names in matplotlib, which now expose the
2628 2634 matlab-compatible interface via a pylab module instead of the
2629 2635 'matlab' name. The new code is backwards compatible, so users of
2630 2636 all matplotlib versions are OK. Patch by J. Hunter.
2631 2637
2632 2638 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
2633 2639 of __init__ docstrings for instances (class docstrings are already
2634 2640 automatically printed). Instances with customized docstrings
2635 2641 (indep. of the class) are also recognized and all 3 separate
2636 2642 docstrings are printed (instance, class, constructor). After some
2637 2643 comments/suggestions by J. Hunter.
2638 2644
2639 2645 2004-12-05 Fernando Perez <fperez@colorado.edu>
2640 2646
2641 2647 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
2642 2648 warnings when tab-completion fails and triggers an exception.
2643 2649
2644 2650 2004-12-03 Fernando Perez <fperez@colorado.edu>
2645 2651
2646 2652 * IPython/Magic.py (magic_prun): Fix bug where an exception would
2647 2653 be triggered when using 'run -p'. An incorrect option flag was
2648 2654 being set ('d' instead of 'D').
2649 2655 (manpage): fix missing escaped \- sign.
2650 2656
2651 2657 2004-11-30 *** Released version 0.6.5
2652 2658
2653 2659 2004-11-30 Fernando Perez <fperez@colorado.edu>
2654 2660
2655 2661 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
2656 2662 setting with -d option.
2657 2663
2658 2664 * setup.py (docfiles): Fix problem where the doc glob I was using
2659 2665 was COMPLETELY BROKEN. It was giving the right files by pure
2660 2666 accident, but failed once I tried to include ipython.el. Note:
2661 2667 glob() does NOT allow you to do exclusion on multiple endings!
2662 2668
2663 2669 2004-11-29 Fernando Perez <fperez@colorado.edu>
2664 2670
2665 2671 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
2666 2672 the manpage as the source. Better formatting & consistency.
2667 2673
2668 2674 * IPython/Magic.py (magic_run): Added new -d option, to run
2669 2675 scripts under the control of the python pdb debugger. Note that
2670 2676 this required changing the %prun option -d to -D, to avoid a clash
2671 2677 (since %run must pass options to %prun, and getopt is too dumb to
2672 2678 handle options with string values with embedded spaces). Thanks
2673 2679 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
2674 2680 (magic_who_ls): added type matching to %who and %whos, so that one
2675 2681 can filter their output to only include variables of certain
2676 2682 types. Another suggestion by Matthew.
2677 2683 (magic_whos): Added memory summaries in kb and Mb for arrays.
2678 2684 (magic_who): Improve formatting (break lines every 9 vars).
2679 2685
2680 2686 2004-11-28 Fernando Perez <fperez@colorado.edu>
2681 2687
2682 2688 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
2683 2689 cache when empty lines were present.
2684 2690
2685 2691 2004-11-24 Fernando Perez <fperez@colorado.edu>
2686 2692
2687 2693 * IPython/usage.py (__doc__): document the re-activated threading
2688 2694 options for WX and GTK.
2689 2695
2690 2696 2004-11-23 Fernando Perez <fperez@colorado.edu>
2691 2697
2692 2698 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
2693 2699 the -wthread and -gthread options, along with a new -tk one to try
2694 2700 and coordinate Tk threading with wx/gtk. The tk support is very
2695 2701 platform dependent, since it seems to require Tcl and Tk to be
2696 2702 built with threads (Fedora1/2 appears NOT to have it, but in
2697 2703 Prabhu's Debian boxes it works OK). But even with some Tk
2698 2704 limitations, this is a great improvement.
2699 2705
2700 2706 * IPython/Prompts.py (prompt_specials_color): Added \t for time
2701 2707 info in user prompts. Patch by Prabhu.
2702 2708
2703 2709 2004-11-18 Fernando Perez <fperez@colorado.edu>
2704 2710
2705 2711 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
2706 2712 EOFErrors and bail, to avoid infinite loops if a non-terminating
2707 2713 file is fed into ipython. Patch submitted in issue 19 by user,
2708 2714 many thanks.
2709 2715
2710 2716 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
2711 2717 autoquote/parens in continuation prompts, which can cause lots of
2712 2718 problems. Closes roundup issue 20.
2713 2719
2714 2720 2004-11-17 Fernando Perez <fperez@colorado.edu>
2715 2721
2716 2722 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
2717 2723 reported as debian bug #280505. I'm not sure my local changelog
2718 2724 entry has the proper debian format (Jack?).
2719 2725
2720 2726 2004-11-08 *** Released version 0.6.4
2721 2727
2722 2728 2004-11-08 Fernando Perez <fperez@colorado.edu>
2723 2729
2724 2730 * IPython/iplib.py (init_readline): Fix exit message for Windows
2725 2731 when readline is active. Thanks to a report by Eric Jones
2726 2732 <eric-AT-enthought.com>.
2727 2733
2728 2734 2004-11-07 Fernando Perez <fperez@colorado.edu>
2729 2735
2730 2736 * IPython/genutils.py (page): Add a trap for OSError exceptions,
2731 2737 sometimes seen by win2k/cygwin users.
2732 2738
2733 2739 2004-11-06 Fernando Perez <fperez@colorado.edu>
2734 2740
2735 2741 * IPython/iplib.py (interact): Change the handling of %Exit from
2736 2742 trying to propagate a SystemExit to an internal ipython flag.
2737 2743 This is less elegant than using Python's exception mechanism, but
2738 2744 I can't get that to work reliably with threads, so under -pylab
2739 2745 %Exit was hanging IPython. Cross-thread exception handling is
2740 2746 really a bitch. Thaks to a bug report by Stephen Walton
2741 2747 <stephen.walton-AT-csun.edu>.
2742 2748
2743 2749 2004-11-04 Fernando Perez <fperez@colorado.edu>
2744 2750
2745 2751 * IPython/iplib.py (raw_input_original): store a pointer to the
2746 2752 true raw_input to harden against code which can modify it
2747 2753 (wx.py.PyShell does this and would otherwise crash ipython).
2748 2754 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
2749 2755
2750 2756 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
2751 2757 Ctrl-C problem, which does not mess up the input line.
2752 2758
2753 2759 2004-11-03 Fernando Perez <fperez@colorado.edu>
2754 2760
2755 2761 * IPython/Release.py: Changed licensing to BSD, in all files.
2756 2762 (name): lowercase name for tarball/RPM release.
2757 2763
2758 2764 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
2759 2765 use throughout ipython.
2760 2766
2761 2767 * IPython/Magic.py (Magic._ofind): Switch to using the new
2762 2768 OInspect.getdoc() function.
2763 2769
2764 2770 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
2765 2771 of the line currently being canceled via Ctrl-C. It's extremely
2766 2772 ugly, but I don't know how to do it better (the problem is one of
2767 2773 handling cross-thread exceptions).
2768 2774
2769 2775 2004-10-28 Fernando Perez <fperez@colorado.edu>
2770 2776
2771 2777 * IPython/Shell.py (signal_handler): add signal handlers to trap
2772 2778 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
2773 2779 report by Francesc Alted.
2774 2780
2775 2781 2004-10-21 Fernando Perez <fperez@colorado.edu>
2776 2782
2777 2783 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
2778 2784 to % for pysh syntax extensions.
2779 2785
2780 2786 2004-10-09 Fernando Perez <fperez@colorado.edu>
2781 2787
2782 2788 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
2783 2789 arrays to print a more useful summary, without calling str(arr).
2784 2790 This avoids the problem of extremely lengthy computations which
2785 2791 occur if arr is large, and appear to the user as a system lockup
2786 2792 with 100% cpu activity. After a suggestion by Kristian Sandberg
2787 2793 <Kristian.Sandberg@colorado.edu>.
2788 2794 (Magic.__init__): fix bug in global magic escapes not being
2789 2795 correctly set.
2790 2796
2791 2797 2004-10-08 Fernando Perez <fperez@colorado.edu>
2792 2798
2793 2799 * IPython/Magic.py (__license__): change to absolute imports of
2794 2800 ipython's own internal packages, to start adapting to the absolute
2795 2801 import requirement of PEP-328.
2796 2802
2797 2803 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
2798 2804 files, and standardize author/license marks through the Release
2799 2805 module instead of having per/file stuff (except for files with
2800 2806 particular licenses, like the MIT/PSF-licensed codes).
2801 2807
2802 2808 * IPython/Debugger.py: remove dead code for python 2.1
2803 2809
2804 2810 2004-10-04 Fernando Perez <fperez@colorado.edu>
2805 2811
2806 2812 * IPython/iplib.py (ipmagic): New function for accessing magics
2807 2813 via a normal python function call.
2808 2814
2809 2815 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
2810 2816 from '@' to '%', to accomodate the new @decorator syntax of python
2811 2817 2.4.
2812 2818
2813 2819 2004-09-29 Fernando Perez <fperez@colorado.edu>
2814 2820
2815 2821 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
2816 2822 matplotlib.use to prevent running scripts which try to switch
2817 2823 interactive backends from within ipython. This will just crash
2818 2824 the python interpreter, so we can't allow it (but a detailed error
2819 2825 is given to the user).
2820 2826
2821 2827 2004-09-28 Fernando Perez <fperez@colorado.edu>
2822 2828
2823 2829 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
2824 2830 matplotlib-related fixes so that using @run with non-matplotlib
2825 2831 scripts doesn't pop up spurious plot windows. This requires
2826 2832 matplotlib >= 0.63, where I had to make some changes as well.
2827 2833
2828 2834 * IPython/ipmaker.py (make_IPython): update version requirement to
2829 2835 python 2.2.
2830 2836
2831 2837 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
2832 2838 banner arg for embedded customization.
2833 2839
2834 2840 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
2835 2841 explicit uses of __IP as the IPython's instance name. Now things
2836 2842 are properly handled via the shell.name value. The actual code
2837 2843 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
2838 2844 is much better than before. I'll clean things completely when the
2839 2845 magic stuff gets a real overhaul.
2840 2846
2841 2847 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
2842 2848 minor changes to debian dir.
2843 2849
2844 2850 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
2845 2851 pointer to the shell itself in the interactive namespace even when
2846 2852 a user-supplied dict is provided. This is needed for embedding
2847 2853 purposes (found by tests with Michel Sanner).
2848 2854
2849 2855 2004-09-27 Fernando Perez <fperez@colorado.edu>
2850 2856
2851 2857 * IPython/UserConfig/ipythonrc: remove []{} from
2852 2858 readline_remove_delims, so that things like [modname.<TAB> do
2853 2859 proper completion. This disables [].TAB, but that's a less common
2854 2860 case than module names in list comprehensions, for example.
2855 2861 Thanks to a report by Andrea Riciputi.
2856 2862
2857 2863 2004-09-09 Fernando Perez <fperez@colorado.edu>
2858 2864
2859 2865 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
2860 2866 blocking problems in win32 and osx. Fix by John.
2861 2867
2862 2868 2004-09-08 Fernando Perez <fperez@colorado.edu>
2863 2869
2864 2870 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
2865 2871 for Win32 and OSX. Fix by John Hunter.
2866 2872
2867 2873 2004-08-30 *** Released version 0.6.3
2868 2874
2869 2875 2004-08-30 Fernando Perez <fperez@colorado.edu>
2870 2876
2871 2877 * setup.py (isfile): Add manpages to list of dependent files to be
2872 2878 updated.
2873 2879
2874 2880 2004-08-27 Fernando Perez <fperez@colorado.edu>
2875 2881
2876 2882 * IPython/Shell.py (start): I've disabled -wthread and -gthread
2877 2883 for now. They don't really work with standalone WX/GTK code
2878 2884 (though matplotlib IS working fine with both of those backends).
2879 2885 This will neeed much more testing. I disabled most things with
2880 2886 comments, so turning it back on later should be pretty easy.
2881 2887
2882 2888 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
2883 2889 autocalling of expressions like r'foo', by modifying the line
2884 2890 split regexp. Closes
2885 2891 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
2886 2892 Riley <ipythonbugs-AT-sabi.net>.
2887 2893 (InteractiveShell.mainloop): honor --nobanner with banner
2888 2894 extensions.
2889 2895
2890 2896 * IPython/Shell.py: Significant refactoring of all classes, so
2891 2897 that we can really support ALL matplotlib backends and threading
2892 2898 models (John spotted a bug with Tk which required this). Now we
2893 2899 should support single-threaded, WX-threads and GTK-threads, both
2894 2900 for generic code and for matplotlib.
2895 2901
2896 2902 * IPython/ipmaker.py (__call__): Changed -mpthread option to
2897 2903 -pylab, to simplify things for users. Will also remove the pylab
2898 2904 profile, since now all of matplotlib configuration is directly
2899 2905 handled here. This also reduces startup time.
2900 2906
2901 2907 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
2902 2908 shell wasn't being correctly called. Also in IPShellWX.
2903 2909
2904 2910 * IPython/iplib.py (InteractiveShell.__init__): Added option to
2905 2911 fine-tune banner.
2906 2912
2907 2913 * IPython/numutils.py (spike): Deprecate these spike functions,
2908 2914 delete (long deprecated) gnuplot_exec handler.
2909 2915
2910 2916 2004-08-26 Fernando Perez <fperez@colorado.edu>
2911 2917
2912 2918 * ipython.1: Update for threading options, plus some others which
2913 2919 were missing.
2914 2920
2915 2921 * IPython/ipmaker.py (__call__): Added -wthread option for
2916 2922 wxpython thread handling. Make sure threading options are only
2917 2923 valid at the command line.
2918 2924
2919 2925 * scripts/ipython: moved shell selection into a factory function
2920 2926 in Shell.py, to keep the starter script to a minimum.
2921 2927
2922 2928 2004-08-25 Fernando Perez <fperez@colorado.edu>
2923 2929
2924 2930 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
2925 2931 John. Along with some recent changes he made to matplotlib, the
2926 2932 next versions of both systems should work very well together.
2927 2933
2928 2934 2004-08-24 Fernando Perez <fperez@colorado.edu>
2929 2935
2930 2936 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
2931 2937 tried to switch the profiling to using hotshot, but I'm getting
2932 2938 strange errors from prof.runctx() there. I may be misreading the
2933 2939 docs, but it looks weird. For now the profiling code will
2934 2940 continue to use the standard profiler.
2935 2941
2936 2942 2004-08-23 Fernando Perez <fperez@colorado.edu>
2937 2943
2938 2944 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
2939 2945 threaded shell, by John Hunter. It's not quite ready yet, but
2940 2946 close.
2941 2947
2942 2948 2004-08-22 Fernando Perez <fperez@colorado.edu>
2943 2949
2944 2950 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
2945 2951 in Magic and ultraTB.
2946 2952
2947 2953 * ipython.1: document threading options in manpage.
2948 2954
2949 2955 * scripts/ipython: Changed name of -thread option to -gthread,
2950 2956 since this is GTK specific. I want to leave the door open for a
2951 2957 -wthread option for WX, which will most likely be necessary. This
2952 2958 change affects usage and ipmaker as well.
2953 2959
2954 2960 * IPython/Shell.py (matplotlib_shell): Add a factory function to
2955 2961 handle the matplotlib shell issues. Code by John Hunter
2956 2962 <jdhunter-AT-nitace.bsd.uchicago.edu>.
2957 2963 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
2958 2964 broken (and disabled for end users) for now, but it puts the
2959 2965 infrastructure in place.
2960 2966
2961 2967 2004-08-21 Fernando Perez <fperez@colorado.edu>
2962 2968
2963 2969 * ipythonrc-pylab: Add matplotlib support.
2964 2970
2965 2971 * matplotlib_config.py: new files for matplotlib support, part of
2966 2972 the pylab profile.
2967 2973
2968 2974 * IPython/usage.py (__doc__): documented the threading options.
2969 2975
2970 2976 2004-08-20 Fernando Perez <fperez@colorado.edu>
2971 2977
2972 2978 * ipython: Modified the main calling routine to handle the -thread
2973 2979 and -mpthread options. This needs to be done as a top-level hack,
2974 2980 because it determines which class to instantiate for IPython
2975 2981 itself.
2976 2982
2977 2983 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
2978 2984 classes to support multithreaded GTK operation without blocking,
2979 2985 and matplotlib with all backends. This is a lot of still very
2980 2986 experimental code, and threads are tricky. So it may still have a
2981 2987 few rough edges... This code owes a lot to
2982 2988 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
2983 2989 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
2984 2990 to John Hunter for all the matplotlib work.
2985 2991
2986 2992 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
2987 2993 options for gtk thread and matplotlib support.
2988 2994
2989 2995 2004-08-16 Fernando Perez <fperez@colorado.edu>
2990 2996
2991 2997 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
2992 2998 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
2993 2999 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
2994 3000
2995 3001 2004-08-11 Fernando Perez <fperez@colorado.edu>
2996 3002
2997 3003 * setup.py (isfile): Fix build so documentation gets updated for
2998 3004 rpms (it was only done for .tgz builds).
2999 3005
3000 3006 2004-08-10 Fernando Perez <fperez@colorado.edu>
3001 3007
3002 3008 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
3003 3009
3004 3010 * iplib.py : Silence syntax error exceptions in tab-completion.
3005 3011
3006 3012 2004-08-05 Fernando Perez <fperez@colorado.edu>
3007 3013
3008 3014 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
3009 3015 'color off' mark for continuation prompts. This was causing long
3010 3016 continuation lines to mis-wrap.
3011 3017
3012 3018 2004-08-01 Fernando Perez <fperez@colorado.edu>
3013 3019
3014 3020 * IPython/ipmaker.py (make_IPython): Allow the shell class used
3015 3021 for building ipython to be a parameter. All this is necessary
3016 3022 right now to have a multithreaded version, but this insane
3017 3023 non-design will be cleaned up soon. For now, it's a hack that
3018 3024 works.
3019 3025
3020 3026 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
3021 3027 args in various places. No bugs so far, but it's a dangerous
3022 3028 practice.
3023 3029
3024 3030 2004-07-31 Fernando Perez <fperez@colorado.edu>
3025 3031
3026 3032 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
3027 3033 fix completion of files with dots in their names under most
3028 3034 profiles (pysh was OK because the completion order is different).
3029 3035
3030 3036 2004-07-27 Fernando Perez <fperez@colorado.edu>
3031 3037
3032 3038 * IPython/iplib.py (InteractiveShell.__init__): build dict of
3033 3039 keywords manually, b/c the one in keyword.py was removed in python
3034 3040 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
3035 3041 This is NOT a bug under python 2.3 and earlier.
3036 3042
3037 3043 2004-07-26 Fernando Perez <fperez@colorado.edu>
3038 3044
3039 3045 * IPython/ultraTB.py (VerboseTB.text): Add another
3040 3046 linecache.checkcache() call to try to prevent inspect.py from
3041 3047 crashing under python 2.3. I think this fixes
3042 3048 http://www.scipy.net/roundup/ipython/issue17.
3043 3049
3044 3050 2004-07-26 *** Released version 0.6.2
3045 3051
3046 3052 2004-07-26 Fernando Perez <fperez@colorado.edu>
3047 3053
3048 3054 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
3049 3055 fail for any number.
3050 3056 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
3051 3057 empty bookmarks.
3052 3058
3053 3059 2004-07-26 *** Released version 0.6.1
3054 3060
3055 3061 2004-07-26 Fernando Perez <fperez@colorado.edu>
3056 3062
3057 3063 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
3058 3064
3059 3065 * IPython/iplib.py (protect_filename): Applied Ville's patch for
3060 3066 escaping '()[]{}' in filenames.
3061 3067
3062 3068 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
3063 3069 Python 2.2 users who lack a proper shlex.split.
3064 3070
3065 3071 2004-07-19 Fernando Perez <fperez@colorado.edu>
3066 3072
3067 3073 * IPython/iplib.py (InteractiveShell.init_readline): Add support
3068 3074 for reading readline's init file. I follow the normal chain:
3069 3075 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
3070 3076 report by Mike Heeter. This closes
3071 3077 http://www.scipy.net/roundup/ipython/issue16.
3072 3078
3073 3079 2004-07-18 Fernando Perez <fperez@colorado.edu>
3074 3080
3075 3081 * IPython/iplib.py (__init__): Add better handling of '\' under
3076 3082 Win32 for filenames. After a patch by Ville.
3077 3083
3078 3084 2004-07-17 Fernando Perez <fperez@colorado.edu>
3079 3085
3080 3086 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
3081 3087 autocalling would be triggered for 'foo is bar' if foo is
3082 3088 callable. I also cleaned up the autocall detection code to use a
3083 3089 regexp, which is faster. Bug reported by Alexander Schmolck.
3084 3090
3085 3091 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
3086 3092 '?' in them would confuse the help system. Reported by Alex
3087 3093 Schmolck.
3088 3094
3089 3095 2004-07-16 Fernando Perez <fperez@colorado.edu>
3090 3096
3091 3097 * IPython/GnuplotInteractive.py (__all__): added plot2.
3092 3098
3093 3099 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
3094 3100 plotting dictionaries, lists or tuples of 1d arrays.
3095 3101
3096 3102 * IPython/Magic.py (Magic.magic_hist): small clenaups and
3097 3103 optimizations.
3098 3104
3099 3105 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
3100 3106 the information which was there from Janko's original IPP code:
3101 3107
3102 3108 03.05.99 20:53 porto.ifm.uni-kiel.de
3103 3109 --Started changelog.
3104 3110 --make clear do what it say it does
3105 3111 --added pretty output of lines from inputcache
3106 3112 --Made Logger a mixin class, simplifies handling of switches
3107 3113 --Added own completer class. .string<TAB> expands to last history
3108 3114 line which starts with string. The new expansion is also present
3109 3115 with Ctrl-r from the readline library. But this shows, who this
3110 3116 can be done for other cases.
3111 3117 --Added convention that all shell functions should accept a
3112 3118 parameter_string This opens the door for different behaviour for
3113 3119 each function. @cd is a good example of this.
3114 3120
3115 3121 04.05.99 12:12 porto.ifm.uni-kiel.de
3116 3122 --added logfile rotation
3117 3123 --added new mainloop method which freezes first the namespace
3118 3124
3119 3125 07.05.99 21:24 porto.ifm.uni-kiel.de
3120 3126 --added the docreader classes. Now there is a help system.
3121 3127 -This is only a first try. Currently it's not easy to put new
3122 3128 stuff in the indices. But this is the way to go. Info would be
3123 3129 better, but HTML is every where and not everybody has an info
3124 3130 system installed and it's not so easy to change html-docs to info.
3125 3131 --added global logfile option
3126 3132 --there is now a hook for object inspection method pinfo needs to
3127 3133 be provided for this. Can be reached by two '??'.
3128 3134
3129 3135 08.05.99 20:51 porto.ifm.uni-kiel.de
3130 3136 --added a README
3131 3137 --bug in rc file. Something has changed so functions in the rc
3132 3138 file need to reference the shell and not self. Not clear if it's a
3133 3139 bug or feature.
3134 3140 --changed rc file for new behavior
3135 3141
3136 3142 2004-07-15 Fernando Perez <fperez@colorado.edu>
3137 3143
3138 3144 * IPython/Logger.py (Logger.log): fixed recent bug where the input
3139 3145 cache was falling out of sync in bizarre manners when multi-line
3140 3146 input was present. Minor optimizations and cleanup.
3141 3147
3142 3148 (Logger): Remove old Changelog info for cleanup. This is the
3143 3149 information which was there from Janko's original code:
3144 3150
3145 3151 Changes to Logger: - made the default log filename a parameter
3146 3152
3147 3153 - put a check for lines beginning with !@? in log(). Needed
3148 3154 (even if the handlers properly log their lines) for mid-session
3149 3155 logging activation to work properly. Without this, lines logged
3150 3156 in mid session, which get read from the cache, would end up
3151 3157 'bare' (with !@? in the open) in the log. Now they are caught
3152 3158 and prepended with a #.
3153 3159
3154 3160 * IPython/iplib.py (InteractiveShell.init_readline): added check
3155 3161 in case MagicCompleter fails to be defined, so we don't crash.
3156 3162
3157 3163 2004-07-13 Fernando Perez <fperez@colorado.edu>
3158 3164
3159 3165 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
3160 3166 of EPS if the requested filename ends in '.eps'.
3161 3167
3162 3168 2004-07-04 Fernando Perez <fperez@colorado.edu>
3163 3169
3164 3170 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
3165 3171 escaping of quotes when calling the shell.
3166 3172
3167 3173 2004-07-02 Fernando Perez <fperez@colorado.edu>
3168 3174
3169 3175 * IPython/Prompts.py (CachedOutput.update): Fix problem with
3170 3176 gettext not working because we were clobbering '_'. Fixes
3171 3177 http://www.scipy.net/roundup/ipython/issue6.
3172 3178
3173 3179 2004-07-01 Fernando Perez <fperez@colorado.edu>
3174 3180
3175 3181 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
3176 3182 into @cd. Patch by Ville.
3177 3183
3178 3184 * IPython/iplib.py (InteractiveShell.post_config_initialization):
3179 3185 new function to store things after ipmaker runs. Patch by Ville.
3180 3186 Eventually this will go away once ipmaker is removed and the class
3181 3187 gets cleaned up, but for now it's ok. Key functionality here is
3182 3188 the addition of the persistent storage mechanism, a dict for
3183 3189 keeping data across sessions (for now just bookmarks, but more can
3184 3190 be implemented later).
3185 3191
3186 3192 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
3187 3193 persistent across sections. Patch by Ville, I modified it
3188 3194 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
3189 3195 added a '-l' option to list all bookmarks.
3190 3196
3191 3197 * IPython/iplib.py (InteractiveShell.atexit_operations): new
3192 3198 center for cleanup. Registered with atexit.register(). I moved
3193 3199 here the old exit_cleanup(). After a patch by Ville.
3194 3200
3195 3201 * IPython/Magic.py (get_py_filename): added '~' to the accepted
3196 3202 characters in the hacked shlex_split for python 2.2.
3197 3203
3198 3204 * IPython/iplib.py (file_matches): more fixes to filenames with
3199 3205 whitespace in them. It's not perfect, but limitations in python's
3200 3206 readline make it impossible to go further.
3201 3207
3202 3208 2004-06-29 Fernando Perez <fperez@colorado.edu>
3203 3209
3204 3210 * IPython/iplib.py (file_matches): escape whitespace correctly in
3205 3211 filename completions. Bug reported by Ville.
3206 3212
3207 3213 2004-06-28 Fernando Perez <fperez@colorado.edu>
3208 3214
3209 3215 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
3210 3216 the history file will be called 'history-PROFNAME' (or just
3211 3217 'history' if no profile is loaded). I was getting annoyed at
3212 3218 getting my Numerical work history clobbered by pysh sessions.
3213 3219
3214 3220 * IPython/iplib.py (InteractiveShell.__init__): Internal
3215 3221 getoutputerror() function so that we can honor the system_verbose
3216 3222 flag for _all_ system calls. I also added escaping of #
3217 3223 characters here to avoid confusing Itpl.
3218 3224
3219 3225 * IPython/Magic.py (shlex_split): removed call to shell in
3220 3226 parse_options and replaced it with shlex.split(). The annoying
3221 3227 part was that in Python 2.2, shlex.split() doesn't exist, so I had
3222 3228 to backport it from 2.3, with several frail hacks (the shlex
3223 3229 module is rather limited in 2.2). Thanks to a suggestion by Ville
3224 3230 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
3225 3231 problem.
3226 3232
3227 3233 (Magic.magic_system_verbose): new toggle to print the actual
3228 3234 system calls made by ipython. Mainly for debugging purposes.
3229 3235
3230 3236 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
3231 3237 doesn't support persistence. Reported (and fix suggested) by
3232 3238 Travis Caldwell <travis_caldwell2000@yahoo.com>.
3233 3239
3234 3240 2004-06-26 Fernando Perez <fperez@colorado.edu>
3235 3241
3236 3242 * IPython/Logger.py (Logger.log): fix to handle correctly empty
3237 3243 continue prompts.
3238 3244
3239 3245 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
3240 3246 function (basically a big docstring) and a few more things here to
3241 3247 speedup startup. pysh.py is now very lightweight. We want because
3242 3248 it gets execfile'd, while InterpreterExec gets imported, so
3243 3249 byte-compilation saves time.
3244 3250
3245 3251 2004-06-25 Fernando Perez <fperez@colorado.edu>
3246 3252
3247 3253 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
3248 3254 -NUM', which was recently broken.
3249 3255
3250 3256 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
3251 3257 in multi-line input (but not !!, which doesn't make sense there).
3252 3258
3253 3259 * IPython/UserConfig/ipythonrc: made autoindent on by default.
3254 3260 It's just too useful, and people can turn it off in the less
3255 3261 common cases where it's a problem.
3256 3262
3257 3263 2004-06-24 Fernando Perez <fperez@colorado.edu>
3258 3264
3259 3265 * IPython/iplib.py (InteractiveShell._prefilter): big change -
3260 3266 special syntaxes (like alias calling) is now allied in multi-line
3261 3267 input. This is still _very_ experimental, but it's necessary for
3262 3268 efficient shell usage combining python looping syntax with system
3263 3269 calls. For now it's restricted to aliases, I don't think it
3264 3270 really even makes sense to have this for magics.
3265 3271
3266 3272 2004-06-23 Fernando Perez <fperez@colorado.edu>
3267 3273
3268 3274 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
3269 3275 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
3270 3276
3271 3277 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
3272 3278 extensions under Windows (after code sent by Gary Bishop). The
3273 3279 extensions considered 'executable' are stored in IPython's rc
3274 3280 structure as win_exec_ext.
3275 3281
3276 3282 * IPython/genutils.py (shell): new function, like system() but
3277 3283 without return value. Very useful for interactive shell work.
3278 3284
3279 3285 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
3280 3286 delete aliases.
3281 3287
3282 3288 * IPython/iplib.py (InteractiveShell.alias_table_update): make
3283 3289 sure that the alias table doesn't contain python keywords.
3284 3290
3285 3291 2004-06-21 Fernando Perez <fperez@colorado.edu>
3286 3292
3287 3293 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
3288 3294 non-existent items are found in $PATH. Reported by Thorsten.
3289 3295
3290 3296 2004-06-20 Fernando Perez <fperez@colorado.edu>
3291 3297
3292 3298 * IPython/iplib.py (complete): modified the completer so that the
3293 3299 order of priorities can be easily changed at runtime.
3294 3300
3295 3301 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
3296 3302 Modified to auto-execute all lines beginning with '~', '/' or '.'.
3297 3303
3298 3304 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
3299 3305 expand Python variables prepended with $ in all system calls. The
3300 3306 same was done to InteractiveShell.handle_shell_escape. Now all
3301 3307 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
3302 3308 expansion of python variables and expressions according to the
3303 3309 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
3304 3310
3305 3311 Though PEP-215 has been rejected, a similar (but simpler) one
3306 3312 seems like it will go into Python 2.4, PEP-292 -
3307 3313 http://www.python.org/peps/pep-0292.html.
3308 3314
3309 3315 I'll keep the full syntax of PEP-215, since IPython has since the
3310 3316 start used Ka-Ping Yee's reference implementation discussed there
3311 3317 (Itpl), and I actually like the powerful semantics it offers.
3312 3318
3313 3319 In order to access normal shell variables, the $ has to be escaped
3314 3320 via an extra $. For example:
3315 3321
3316 3322 In [7]: PATH='a python variable'
3317 3323
3318 3324 In [8]: !echo $PATH
3319 3325 a python variable
3320 3326
3321 3327 In [9]: !echo $$PATH
3322 3328 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
3323 3329
3324 3330 (Magic.parse_options): escape $ so the shell doesn't evaluate
3325 3331 things prematurely.
3326 3332
3327 3333 * IPython/iplib.py (InteractiveShell.call_alias): added the
3328 3334 ability for aliases to expand python variables via $.
3329 3335
3330 3336 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
3331 3337 system, now there's a @rehash/@rehashx pair of magics. These work
3332 3338 like the csh rehash command, and can be invoked at any time. They
3333 3339 build a table of aliases to everything in the user's $PATH
3334 3340 (@rehash uses everything, @rehashx is slower but only adds
3335 3341 executable files). With this, the pysh.py-based shell profile can
3336 3342 now simply call rehash upon startup, and full access to all
3337 3343 programs in the user's path is obtained.
3338 3344
3339 3345 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
3340 3346 functionality is now fully in place. I removed the old dynamic
3341 3347 code generation based approach, in favor of a much lighter one
3342 3348 based on a simple dict. The advantage is that this allows me to
3343 3349 now have thousands of aliases with negligible cost (unthinkable
3344 3350 with the old system).
3345 3351
3346 3352 2004-06-19 Fernando Perez <fperez@colorado.edu>
3347 3353
3348 3354 * IPython/iplib.py (__init__): extended MagicCompleter class to
3349 3355 also complete (last in priority) on user aliases.
3350 3356
3351 3357 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
3352 3358 call to eval.
3353 3359 (ItplNS.__init__): Added a new class which functions like Itpl,
3354 3360 but allows configuring the namespace for the evaluation to occur
3355 3361 in.
3356 3362
3357 3363 2004-06-18 Fernando Perez <fperez@colorado.edu>
3358 3364
3359 3365 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
3360 3366 better message when 'exit' or 'quit' are typed (a common newbie
3361 3367 confusion).
3362 3368
3363 3369 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
3364 3370 check for Windows users.
3365 3371
3366 3372 * IPython/iplib.py (InteractiveShell.user_setup): removed
3367 3373 disabling of colors for Windows. I'll test at runtime and issue a
3368 3374 warning if Gary's readline isn't found, as to nudge users to
3369 3375 download it.
3370 3376
3371 3377 2004-06-16 Fernando Perez <fperez@colorado.edu>
3372 3378
3373 3379 * IPython/genutils.py (Stream.__init__): changed to print errors
3374 3380 to sys.stderr. I had a circular dependency here. Now it's
3375 3381 possible to run ipython as IDLE's shell (consider this pre-alpha,
3376 3382 since true stdout things end up in the starting terminal instead
3377 3383 of IDLE's out).
3378 3384
3379 3385 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
3380 3386 users who haven't # updated their prompt_in2 definitions. Remove
3381 3387 eventually.
3382 3388 (multiple_replace): added credit to original ASPN recipe.
3383 3389
3384 3390 2004-06-15 Fernando Perez <fperez@colorado.edu>
3385 3391
3386 3392 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
3387 3393 list of auto-defined aliases.
3388 3394
3389 3395 2004-06-13 Fernando Perez <fperez@colorado.edu>
3390 3396
3391 3397 * setup.py (scriptfiles): Don't trigger win_post_install unless an
3392 3398 install was really requested (so setup.py can be used for other
3393 3399 things under Windows).
3394 3400
3395 3401 2004-06-10 Fernando Perez <fperez@colorado.edu>
3396 3402
3397 3403 * IPython/Logger.py (Logger.create_log): Manually remove any old
3398 3404 backup, since os.remove may fail under Windows. Fixes bug
3399 3405 reported by Thorsten.
3400 3406
3401 3407 2004-06-09 Fernando Perez <fperez@colorado.edu>
3402 3408
3403 3409 * examples/example-embed.py: fixed all references to %n (replaced
3404 3410 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
3405 3411 for all examples and the manual as well.
3406 3412
3407 3413 2004-06-08 Fernando Perez <fperez@colorado.edu>
3408 3414
3409 3415 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
3410 3416 alignment and color management. All 3 prompt subsystems now
3411 3417 inherit from BasePrompt.
3412 3418
3413 3419 * tools/release: updates for windows installer build and tag rpms
3414 3420 with python version (since paths are fixed).
3415 3421
3416 3422 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
3417 3423 which will become eventually obsolete. Also fixed the default
3418 3424 prompt_in2 to use \D, so at least new users start with the correct
3419 3425 defaults.
3420 3426 WARNING: Users with existing ipythonrc files will need to apply
3421 3427 this fix manually!
3422 3428
3423 3429 * setup.py: make windows installer (.exe). This is finally the
3424 3430 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
3425 3431 which I hadn't included because it required Python 2.3 (or recent
3426 3432 distutils).
3427 3433
3428 3434 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
3429 3435 usage of new '\D' escape.
3430 3436
3431 3437 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
3432 3438 lacks os.getuid())
3433 3439 (CachedOutput.set_colors): Added the ability to turn coloring
3434 3440 on/off with @colors even for manually defined prompt colors. It
3435 3441 uses a nasty global, but it works safely and via the generic color
3436 3442 handling mechanism.
3437 3443 (Prompt2.__init__): Introduced new escape '\D' for continuation
3438 3444 prompts. It represents the counter ('\#') as dots.
3439 3445 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
3440 3446 need to update their ipythonrc files and replace '%n' with '\D' in
3441 3447 their prompt_in2 settings everywhere. Sorry, but there's
3442 3448 otherwise no clean way to get all prompts to properly align. The
3443 3449 ipythonrc shipped with IPython has been updated.
3444 3450
3445 3451 2004-06-07 Fernando Perez <fperez@colorado.edu>
3446 3452
3447 3453 * setup.py (isfile): Pass local_icons option to latex2html, so the
3448 3454 resulting HTML file is self-contained. Thanks to
3449 3455 dryice-AT-liu.com.cn for the tip.
3450 3456
3451 3457 * pysh.py: I created a new profile 'shell', which implements a
3452 3458 _rudimentary_ IPython-based shell. This is in NO WAY a realy
3453 3459 system shell, nor will it become one anytime soon. It's mainly
3454 3460 meant to illustrate the use of the new flexible bash-like prompts.
3455 3461 I guess it could be used by hardy souls for true shell management,
3456 3462 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
3457 3463 profile. This uses the InterpreterExec extension provided by
3458 3464 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
3459 3465
3460 3466 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
3461 3467 auto-align itself with the length of the previous input prompt
3462 3468 (taking into account the invisible color escapes).
3463 3469 (CachedOutput.__init__): Large restructuring of this class. Now
3464 3470 all three prompts (primary1, primary2, output) are proper objects,
3465 3471 managed by the 'parent' CachedOutput class. The code is still a
3466 3472 bit hackish (all prompts share state via a pointer to the cache),
3467 3473 but it's overall far cleaner than before.
3468 3474
3469 3475 * IPython/genutils.py (getoutputerror): modified to add verbose,
3470 3476 debug and header options. This makes the interface of all getout*
3471 3477 functions uniform.
3472 3478 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
3473 3479
3474 3480 * IPython/Magic.py (Magic.default_option): added a function to
3475 3481 allow registering default options for any magic command. This
3476 3482 makes it easy to have profiles which customize the magics globally
3477 3483 for a certain use. The values set through this function are
3478 3484 picked up by the parse_options() method, which all magics should
3479 3485 use to parse their options.
3480 3486
3481 3487 * IPython/genutils.py (warn): modified the warnings framework to
3482 3488 use the Term I/O class. I'm trying to slowly unify all of
3483 3489 IPython's I/O operations to pass through Term.
3484 3490
3485 3491 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
3486 3492 the secondary prompt to correctly match the length of the primary
3487 3493 one for any prompt. Now multi-line code will properly line up
3488 3494 even for path dependent prompts, such as the new ones available
3489 3495 via the prompt_specials.
3490 3496
3491 3497 2004-06-06 Fernando Perez <fperez@colorado.edu>
3492 3498
3493 3499 * IPython/Prompts.py (prompt_specials): Added the ability to have
3494 3500 bash-like special sequences in the prompts, which get
3495 3501 automatically expanded. Things like hostname, current working
3496 3502 directory and username are implemented already, but it's easy to
3497 3503 add more in the future. Thanks to a patch by W.J. van der Laan
3498 3504 <gnufnork-AT-hetdigitalegat.nl>
3499 3505 (prompt_specials): Added color support for prompt strings, so
3500 3506 users can define arbitrary color setups for their prompts.
3501 3507
3502 3508 2004-06-05 Fernando Perez <fperez@colorado.edu>
3503 3509
3504 3510 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
3505 3511 code to load Gary Bishop's readline and configure it
3506 3512 automatically. Thanks to Gary for help on this.
3507 3513
3508 3514 2004-06-01 Fernando Perez <fperez@colorado.edu>
3509 3515
3510 3516 * IPython/Logger.py (Logger.create_log): fix bug for logging
3511 3517 with no filename (previous fix was incomplete).
3512 3518
3513 3519 2004-05-25 Fernando Perez <fperez@colorado.edu>
3514 3520
3515 3521 * IPython/Magic.py (Magic.parse_options): fix bug where naked
3516 3522 parens would get passed to the shell.
3517 3523
3518 3524 2004-05-20 Fernando Perez <fperez@colorado.edu>
3519 3525
3520 3526 * IPython/Magic.py (Magic.magic_prun): changed default profile
3521 3527 sort order to 'time' (the more common profiling need).
3522 3528
3523 3529 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
3524 3530 so that source code shown is guaranteed in sync with the file on
3525 3531 disk (also changed in psource). Similar fix to the one for
3526 3532 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
3527 3533 <yann.ledu-AT-noos.fr>.
3528 3534
3529 3535 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
3530 3536 with a single option would not be correctly parsed. Closes
3531 3537 http://www.scipy.net/roundup/ipython/issue14. This bug had been
3532 3538 introduced in 0.6.0 (on 2004-05-06).
3533 3539
3534 3540 2004-05-13 *** Released version 0.6.0
3535 3541
3536 3542 2004-05-13 Fernando Perez <fperez@colorado.edu>
3537 3543
3538 3544 * debian/: Added debian/ directory to CVS, so that debian support
3539 3545 is publicly accessible. The debian package is maintained by Jack
3540 3546 Moffit <jack-AT-xiph.org>.
3541 3547
3542 3548 * Documentation: included the notes about an ipython-based system
3543 3549 shell (the hypothetical 'pysh') into the new_design.pdf document,
3544 3550 so that these ideas get distributed to users along with the
3545 3551 official documentation.
3546 3552
3547 3553 2004-05-10 Fernando Perez <fperez@colorado.edu>
3548 3554
3549 3555 * IPython/Logger.py (Logger.create_log): fix recently introduced
3550 3556 bug (misindented line) where logstart would fail when not given an
3551 3557 explicit filename.
3552 3558
3553 3559 2004-05-09 Fernando Perez <fperez@colorado.edu>
3554 3560
3555 3561 * IPython/Magic.py (Magic.parse_options): skip system call when
3556 3562 there are no options to look for. Faster, cleaner for the common
3557 3563 case.
3558 3564
3559 3565 * Documentation: many updates to the manual: describing Windows
3560 3566 support better, Gnuplot updates, credits, misc small stuff. Also
3561 3567 updated the new_design doc a bit.
3562 3568
3563 3569 2004-05-06 *** Released version 0.6.0.rc1
3564 3570
3565 3571 2004-05-06 Fernando Perez <fperez@colorado.edu>
3566 3572
3567 3573 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
3568 3574 operations to use the vastly more efficient list/''.join() method.
3569 3575 (FormattedTB.text): Fix
3570 3576 http://www.scipy.net/roundup/ipython/issue12 - exception source
3571 3577 extract not updated after reload. Thanks to Mike Salib
3572 3578 <msalib-AT-mit.edu> for pinning the source of the problem.
3573 3579 Fortunately, the solution works inside ipython and doesn't require
3574 3580 any changes to python proper.
3575 3581
3576 3582 * IPython/Magic.py (Magic.parse_options): Improved to process the
3577 3583 argument list as a true shell would (by actually using the
3578 3584 underlying system shell). This way, all @magics automatically get
3579 3585 shell expansion for variables. Thanks to a comment by Alex
3580 3586 Schmolck.
3581 3587
3582 3588 2004-04-04 Fernando Perez <fperez@colorado.edu>
3583 3589
3584 3590 * IPython/iplib.py (InteractiveShell.interact): Added a special
3585 3591 trap for a debugger quit exception, which is basically impossible
3586 3592 to handle by normal mechanisms, given what pdb does to the stack.
3587 3593 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
3588 3594
3589 3595 2004-04-03 Fernando Perez <fperez@colorado.edu>
3590 3596
3591 3597 * IPython/genutils.py (Term): Standardized the names of the Term
3592 3598 class streams to cin/cout/cerr, following C++ naming conventions
3593 3599 (I can't use in/out/err because 'in' is not a valid attribute
3594 3600 name).
3595 3601
3596 3602 * IPython/iplib.py (InteractiveShell.interact): don't increment
3597 3603 the prompt if there's no user input. By Daniel 'Dang' Griffith
3598 3604 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
3599 3605 Francois Pinard.
3600 3606
3601 3607 2004-04-02 Fernando Perez <fperez@colorado.edu>
3602 3608
3603 3609 * IPython/genutils.py (Stream.__init__): Modified to survive at
3604 3610 least importing in contexts where stdin/out/err aren't true file
3605 3611 objects, such as PyCrust (they lack fileno() and mode). However,
3606 3612 the recovery facilities which rely on these things existing will
3607 3613 not work.
3608 3614
3609 3615 2004-04-01 Fernando Perez <fperez@colorado.edu>
3610 3616
3611 3617 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
3612 3618 use the new getoutputerror() function, so it properly
3613 3619 distinguishes stdout/err.
3614 3620
3615 3621 * IPython/genutils.py (getoutputerror): added a function to
3616 3622 capture separately the standard output and error of a command.
3617 3623 After a comment from dang on the mailing lists. This code is
3618 3624 basically a modified version of commands.getstatusoutput(), from
3619 3625 the standard library.
3620 3626
3621 3627 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
3622 3628 '!!' as a special syntax (shorthand) to access @sx.
3623 3629
3624 3630 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
3625 3631 command and return its output as a list split on '\n'.
3626 3632
3627 3633 2004-03-31 Fernando Perez <fperez@colorado.edu>
3628 3634
3629 3635 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
3630 3636 method to dictionaries used as FakeModule instances if they lack
3631 3637 it. At least pydoc in python2.3 breaks for runtime-defined
3632 3638 functions without this hack. At some point I need to _really_
3633 3639 understand what FakeModule is doing, because it's a gross hack.
3634 3640 But it solves Arnd's problem for now...
3635 3641
3636 3642 2004-02-27 Fernando Perez <fperez@colorado.edu>
3637 3643
3638 3644 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
3639 3645 mode would behave erratically. Also increased the number of
3640 3646 possible logs in rotate mod to 999. Thanks to Rod Holland
3641 3647 <rhh@StructureLABS.com> for the report and fixes.
3642 3648
3643 3649 2004-02-26 Fernando Perez <fperez@colorado.edu>
3644 3650
3645 3651 * IPython/genutils.py (page): Check that the curses module really
3646 3652 has the initscr attribute before trying to use it. For some
3647 3653 reason, the Solaris curses module is missing this. I think this
3648 3654 should be considered a Solaris python bug, but I'm not sure.
3649 3655
3650 3656 2004-01-17 Fernando Perez <fperez@colorado.edu>
3651 3657
3652 3658 * IPython/genutils.py (Stream.__init__): Changes to try to make
3653 3659 ipython robust against stdin/out/err being closed by the user.
3654 3660 This is 'user error' (and blocks a normal python session, at least
3655 3661 the stdout case). However, Ipython should be able to survive such
3656 3662 instances of abuse as gracefully as possible. To simplify the
3657 3663 coding and maintain compatibility with Gary Bishop's Term
3658 3664 contributions, I've made use of classmethods for this. I think
3659 3665 this introduces a dependency on python 2.2.
3660 3666
3661 3667 2004-01-13 Fernando Perez <fperez@colorado.edu>
3662 3668
3663 3669 * IPython/numutils.py (exp_safe): simplified the code a bit and
3664 3670 removed the need for importing the kinds module altogether.
3665 3671
3666 3672 2004-01-06 Fernando Perez <fperez@colorado.edu>
3667 3673
3668 3674 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
3669 3675 a magic function instead, after some community feedback. No
3670 3676 special syntax will exist for it, but its name is deliberately
3671 3677 very short.
3672 3678
3673 3679 2003-12-20 Fernando Perez <fperez@colorado.edu>
3674 3680
3675 3681 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
3676 3682 new functionality, to automagically assign the result of a shell
3677 3683 command to a variable. I'll solicit some community feedback on
3678 3684 this before making it permanent.
3679 3685
3680 3686 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
3681 3687 requested about callables for which inspect couldn't obtain a
3682 3688 proper argspec. Thanks to a crash report sent by Etienne
3683 3689 Posthumus <etienne-AT-apple01.cs.vu.nl>.
3684 3690
3685 3691 2003-12-09 Fernando Perez <fperez@colorado.edu>
3686 3692
3687 3693 * IPython/genutils.py (page): patch for the pager to work across
3688 3694 various versions of Windows. By Gary Bishop.
3689 3695
3690 3696 2003-12-04 Fernando Perez <fperez@colorado.edu>
3691 3697
3692 3698 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
3693 3699 Gnuplot.py version 1.7, whose internal names changed quite a bit.
3694 3700 While I tested this and it looks ok, there may still be corner
3695 3701 cases I've missed.
3696 3702
3697 3703 2003-12-01 Fernando Perez <fperez@colorado.edu>
3698 3704
3699 3705 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
3700 3706 where a line like 'p,q=1,2' would fail because the automagic
3701 3707 system would be triggered for @p.
3702 3708
3703 3709 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
3704 3710 cleanups, code unmodified.
3705 3711
3706 3712 * IPython/genutils.py (Term): added a class for IPython to handle
3707 3713 output. In most cases it will just be a proxy for stdout/err, but
3708 3714 having this allows modifications to be made for some platforms,
3709 3715 such as handling color escapes under Windows. All of this code
3710 3716 was contributed by Gary Bishop, with minor modifications by me.
3711 3717 The actual changes affect many files.
3712 3718
3713 3719 2003-11-30 Fernando Perez <fperez@colorado.edu>
3714 3720
3715 3721 * IPython/iplib.py (file_matches): new completion code, courtesy
3716 3722 of Jeff Collins. This enables filename completion again under
3717 3723 python 2.3, which disabled it at the C level.
3718 3724
3719 3725 2003-11-11 Fernando Perez <fperez@colorado.edu>
3720 3726
3721 3727 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
3722 3728 for Numeric.array(map(...)), but often convenient.
3723 3729
3724 3730 2003-11-05 Fernando Perez <fperez@colorado.edu>
3725 3731
3726 3732 * IPython/numutils.py (frange): Changed a call from int() to
3727 3733 int(round()) to prevent a problem reported with arange() in the
3728 3734 numpy list.
3729 3735
3730 3736 2003-10-06 Fernando Perez <fperez@colorado.edu>
3731 3737
3732 3738 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
3733 3739 prevent crashes if sys lacks an argv attribute (it happens with
3734 3740 embedded interpreters which build a bare-bones sys module).
3735 3741 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
3736 3742
3737 3743 2003-09-24 Fernando Perez <fperez@colorado.edu>
3738 3744
3739 3745 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
3740 3746 to protect against poorly written user objects where __getattr__
3741 3747 raises exceptions other than AttributeError. Thanks to a bug
3742 3748 report by Oliver Sander <osander-AT-gmx.de>.
3743 3749
3744 3750 * IPython/FakeModule.py (FakeModule.__repr__): this method was
3745 3751 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
3746 3752
3747 3753 2003-09-09 Fernando Perez <fperez@colorado.edu>
3748 3754
3749 3755 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
3750 3756 unpacking a list whith a callable as first element would
3751 3757 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
3752 3758 Collins.
3753 3759
3754 3760 2003-08-25 *** Released version 0.5.0
3755 3761
3756 3762 2003-08-22 Fernando Perez <fperez@colorado.edu>
3757 3763
3758 3764 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
3759 3765 improperly defined user exceptions. Thanks to feedback from Mark
3760 3766 Russell <mrussell-AT-verio.net>.
3761 3767
3762 3768 2003-08-20 Fernando Perez <fperez@colorado.edu>
3763 3769
3764 3770 * IPython/OInspect.py (Inspector.pinfo): changed String Form
3765 3771 printing so that it would print multi-line string forms starting
3766 3772 with a new line. This way the formatting is better respected for
3767 3773 objects which work hard to make nice string forms.
3768 3774
3769 3775 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
3770 3776 autocall would overtake data access for objects with both
3771 3777 __getitem__ and __call__.
3772 3778
3773 3779 2003-08-19 *** Released version 0.5.0-rc1
3774 3780
3775 3781 2003-08-19 Fernando Perez <fperez@colorado.edu>
3776 3782
3777 3783 * IPython/deep_reload.py (load_tail): single tiny change here
3778 3784 seems to fix the long-standing bug of dreload() failing to work
3779 3785 for dotted names. But this module is pretty tricky, so I may have
3780 3786 missed some subtlety. Needs more testing!.
3781 3787
3782 3788 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
3783 3789 exceptions which have badly implemented __str__ methods.
3784 3790 (VerboseTB.text): harden against inspect.getinnerframes crashing,
3785 3791 which I've been getting reports about from Python 2.3 users. I
3786 3792 wish I had a simple test case to reproduce the problem, so I could
3787 3793 either write a cleaner workaround or file a bug report if
3788 3794 necessary.
3789 3795
3790 3796 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
3791 3797 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
3792 3798 a bug report by Tjabo Kloppenburg.
3793 3799
3794 3800 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
3795 3801 crashes. Wrapped the pdb call in a blanket try/except, since pdb
3796 3802 seems rather unstable. Thanks to a bug report by Tjabo
3797 3803 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
3798 3804
3799 3805 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
3800 3806 this out soon because of the critical fixes in the inner loop for
3801 3807 generators.
3802 3808
3803 3809 * IPython/Magic.py (Magic.getargspec): removed. This (and
3804 3810 _get_def) have been obsoleted by OInspect for a long time, I
3805 3811 hadn't noticed that they were dead code.
3806 3812 (Magic._ofind): restored _ofind functionality for a few literals
3807 3813 (those in ["''",'""','[]','{}','()']). But it won't work anymore
3808 3814 for things like "hello".capitalize?, since that would require a
3809 3815 potentially dangerous eval() again.
3810 3816
3811 3817 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
3812 3818 logic a bit more to clean up the escapes handling and minimize the
3813 3819 use of _ofind to only necessary cases. The interactive 'feel' of
3814 3820 IPython should have improved quite a bit with the changes in
3815 3821 _prefilter and _ofind (besides being far safer than before).
3816 3822
3817 3823 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
3818 3824 obscure, never reported). Edit would fail to find the object to
3819 3825 edit under some circumstances.
3820 3826 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
3821 3827 which were causing double-calling of generators. Those eval calls
3822 3828 were _very_ dangerous, since code with side effects could be
3823 3829 triggered. As they say, 'eval is evil'... These were the
3824 3830 nastiest evals in IPython. Besides, _ofind is now far simpler,
3825 3831 and it should also be quite a bit faster. Its use of inspect is
3826 3832 also safer, so perhaps some of the inspect-related crashes I've
3827 3833 seen lately with Python 2.3 might be taken care of. That will
3828 3834 need more testing.
3829 3835
3830 3836 2003-08-17 Fernando Perez <fperez@colorado.edu>
3831 3837
3832 3838 * IPython/iplib.py (InteractiveShell._prefilter): significant
3833 3839 simplifications to the logic for handling user escapes. Faster
3834 3840 and simpler code.
3835 3841
3836 3842 2003-08-14 Fernando Perez <fperez@colorado.edu>
3837 3843
3838 3844 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
3839 3845 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
3840 3846 but it should be quite a bit faster. And the recursive version
3841 3847 generated O(log N) intermediate storage for all rank>1 arrays,
3842 3848 even if they were contiguous.
3843 3849 (l1norm): Added this function.
3844 3850 (norm): Added this function for arbitrary norms (including
3845 3851 l-infinity). l1 and l2 are still special cases for convenience
3846 3852 and speed.
3847 3853
3848 3854 2003-08-03 Fernando Perez <fperez@colorado.edu>
3849 3855
3850 3856 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
3851 3857 exceptions, which now raise PendingDeprecationWarnings in Python
3852 3858 2.3. There were some in Magic and some in Gnuplot2.
3853 3859
3854 3860 2003-06-30 Fernando Perez <fperez@colorado.edu>
3855 3861
3856 3862 * IPython/genutils.py (page): modified to call curses only for
3857 3863 terminals where TERM=='xterm'. After problems under many other
3858 3864 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
3859 3865
3860 3866 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
3861 3867 would be triggered when readline was absent. This was just an old
3862 3868 debugging statement I'd forgotten to take out.
3863 3869
3864 3870 2003-06-20 Fernando Perez <fperez@colorado.edu>
3865 3871
3866 3872 * IPython/genutils.py (clock): modified to return only user time
3867 3873 (not counting system time), after a discussion on scipy. While
3868 3874 system time may be a useful quantity occasionally, it may much
3869 3875 more easily be skewed by occasional swapping or other similar
3870 3876 activity.
3871 3877
3872 3878 2003-06-05 Fernando Perez <fperez@colorado.edu>
3873 3879
3874 3880 * IPython/numutils.py (identity): new function, for building
3875 3881 arbitrary rank Kronecker deltas (mostly backwards compatible with
3876 3882 Numeric.identity)
3877 3883
3878 3884 2003-06-03 Fernando Perez <fperez@colorado.edu>
3879 3885
3880 3886 * IPython/iplib.py (InteractiveShell.handle_magic): protect
3881 3887 arguments passed to magics with spaces, to allow trailing '\' to
3882 3888 work normally (mainly for Windows users).
3883 3889
3884 3890 2003-05-29 Fernando Perez <fperez@colorado.edu>
3885 3891
3886 3892 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
3887 3893 instead of pydoc.help. This fixes a bizarre behavior where
3888 3894 printing '%s' % locals() would trigger the help system. Now
3889 3895 ipython behaves like normal python does.
3890 3896
3891 3897 Note that if one does 'from pydoc import help', the bizarre
3892 3898 behavior returns, but this will also happen in normal python, so
3893 3899 it's not an ipython bug anymore (it has to do with how pydoc.help
3894 3900 is implemented).
3895 3901
3896 3902 2003-05-22 Fernando Perez <fperez@colorado.edu>
3897 3903
3898 3904 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
3899 3905 return [] instead of None when nothing matches, also match to end
3900 3906 of line. Patch by Gary Bishop.
3901 3907
3902 3908 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
3903 3909 protection as before, for files passed on the command line. This
3904 3910 prevents the CrashHandler from kicking in if user files call into
3905 3911 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
3906 3912 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
3907 3913
3908 3914 2003-05-20 *** Released version 0.4.0
3909 3915
3910 3916 2003-05-20 Fernando Perez <fperez@colorado.edu>
3911 3917
3912 3918 * setup.py: added support for manpages. It's a bit hackish b/c of
3913 3919 a bug in the way the bdist_rpm distutils target handles gzipped
3914 3920 manpages, but it works. After a patch by Jack.
3915 3921
3916 3922 2003-05-19 Fernando Perez <fperez@colorado.edu>
3917 3923
3918 3924 * IPython/numutils.py: added a mockup of the kinds module, since
3919 3925 it was recently removed from Numeric. This way, numutils will
3920 3926 work for all users even if they are missing kinds.
3921 3927
3922 3928 * IPython/Magic.py (Magic._ofind): Harden against an inspect
3923 3929 failure, which can occur with SWIG-wrapped extensions. After a
3924 3930 crash report from Prabhu.
3925 3931
3926 3932 2003-05-16 Fernando Perez <fperez@colorado.edu>
3927 3933
3928 3934 * IPython/iplib.py (InteractiveShell.excepthook): New method to
3929 3935 protect ipython from user code which may call directly
3930 3936 sys.excepthook (this looks like an ipython crash to the user, even
3931 3937 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
3932 3938 This is especially important to help users of WxWindows, but may
3933 3939 also be useful in other cases.
3934 3940
3935 3941 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
3936 3942 an optional tb_offset to be specified, and to preserve exception
3937 3943 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
3938 3944
3939 3945 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
3940 3946
3941 3947 2003-05-15 Fernando Perez <fperez@colorado.edu>
3942 3948
3943 3949 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
3944 3950 installing for a new user under Windows.
3945 3951
3946 3952 2003-05-12 Fernando Perez <fperez@colorado.edu>
3947 3953
3948 3954 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
3949 3955 handler for Emacs comint-based lines. Currently it doesn't do
3950 3956 much (but importantly, it doesn't update the history cache). In
3951 3957 the future it may be expanded if Alex needs more functionality
3952 3958 there.
3953 3959
3954 3960 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
3955 3961 info to crash reports.
3956 3962
3957 3963 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
3958 3964 just like Python's -c. Also fixed crash with invalid -color
3959 3965 option value at startup. Thanks to Will French
3960 3966 <wfrench-AT-bestweb.net> for the bug report.
3961 3967
3962 3968 2003-05-09 Fernando Perez <fperez@colorado.edu>
3963 3969
3964 3970 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
3965 3971 to EvalDict (it's a mapping, after all) and simplified its code
3966 3972 quite a bit, after a nice discussion on c.l.py where Gustavo
3967 3973 CΓ³rdova <gcordova-AT-sismex.com> suggested the new version.
3968 3974
3969 3975 2003-04-30 Fernando Perez <fperez@colorado.edu>
3970 3976
3971 3977 * IPython/genutils.py (timings_out): modified it to reduce its
3972 3978 overhead in the common reps==1 case.
3973 3979
3974 3980 2003-04-29 Fernando Perez <fperez@colorado.edu>
3975 3981
3976 3982 * IPython/genutils.py (timings_out): Modified to use the resource
3977 3983 module, which avoids the wraparound problems of time.clock().
3978 3984
3979 3985 2003-04-17 *** Released version 0.2.15pre4
3980 3986
3981 3987 2003-04-17 Fernando Perez <fperez@colorado.edu>
3982 3988
3983 3989 * setup.py (scriptfiles): Split windows-specific stuff over to a
3984 3990 separate file, in an attempt to have a Windows GUI installer.
3985 3991 That didn't work, but part of the groundwork is done.
3986 3992
3987 3993 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
3988 3994 indent/unindent with 4 spaces. Particularly useful in combination
3989 3995 with the new auto-indent option.
3990 3996
3991 3997 2003-04-16 Fernando Perez <fperez@colorado.edu>
3992 3998
3993 3999 * IPython/Magic.py: various replacements of self.rc for
3994 4000 self.shell.rc. A lot more remains to be done to fully disentangle
3995 4001 this class from the main Shell class.
3996 4002
3997 4003 * IPython/GnuplotRuntime.py: added checks for mouse support so
3998 4004 that we don't try to enable it if the current gnuplot doesn't
3999 4005 really support it. Also added checks so that we don't try to
4000 4006 enable persist under Windows (where Gnuplot doesn't recognize the
4001 4007 option).
4002 4008
4003 4009 * IPython/iplib.py (InteractiveShell.interact): Added optional
4004 4010 auto-indenting code, after a patch by King C. Shu
4005 4011 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
4006 4012 get along well with pasting indented code. If I ever figure out
4007 4013 how to make that part go well, it will become on by default.
4008 4014
4009 4015 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
4010 4016 crash ipython if there was an unmatched '%' in the user's prompt
4011 4017 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
4012 4018
4013 4019 * IPython/iplib.py (InteractiveShell.interact): removed the
4014 4020 ability to ask the user whether he wants to crash or not at the
4015 4021 'last line' exception handler. Calling functions at that point
4016 4022 changes the stack, and the error reports would have incorrect
4017 4023 tracebacks.
4018 4024
4019 4025 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
4020 4026 pass through a peger a pretty-printed form of any object. After a
4021 4027 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
4022 4028
4023 4029 2003-04-14 Fernando Perez <fperez@colorado.edu>
4024 4030
4025 4031 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
4026 4032 all files in ~ would be modified at first install (instead of
4027 4033 ~/.ipython). This could be potentially disastrous, as the
4028 4034 modification (make line-endings native) could damage binary files.
4029 4035
4030 4036 2003-04-10 Fernando Perez <fperez@colorado.edu>
4031 4037
4032 4038 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
4033 4039 handle only lines which are invalid python. This now means that
4034 4040 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
4035 4041 for the bug report.
4036 4042
4037 4043 2003-04-01 Fernando Perez <fperez@colorado.edu>
4038 4044
4039 4045 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
4040 4046 where failing to set sys.last_traceback would crash pdb.pm().
4041 4047 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
4042 4048 report.
4043 4049
4044 4050 2003-03-25 Fernando Perez <fperez@colorado.edu>
4045 4051
4046 4052 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
4047 4053 before printing it (it had a lot of spurious blank lines at the
4048 4054 end).
4049 4055
4050 4056 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
4051 4057 output would be sent 21 times! Obviously people don't use this
4052 4058 too often, or I would have heard about it.
4053 4059
4054 4060 2003-03-24 Fernando Perez <fperez@colorado.edu>
4055 4061
4056 4062 * setup.py (scriptfiles): renamed the data_files parameter from
4057 4063 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
4058 4064 for the patch.
4059 4065
4060 4066 2003-03-20 Fernando Perez <fperez@colorado.edu>
4061 4067
4062 4068 * IPython/genutils.py (error): added error() and fatal()
4063 4069 functions.
4064 4070
4065 4071 2003-03-18 *** Released version 0.2.15pre3
4066 4072
4067 4073 2003-03-18 Fernando Perez <fperez@colorado.edu>
4068 4074
4069 4075 * setupext/install_data_ext.py
4070 4076 (install_data_ext.initialize_options): Class contributed by Jack
4071 4077 Moffit for fixing the old distutils hack. He is sending this to
4072 4078 the distutils folks so in the future we may not need it as a
4073 4079 private fix.
4074 4080
4075 4081 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
4076 4082 changes for Debian packaging. See his patch for full details.
4077 4083 The old distutils hack of making the ipythonrc* files carry a
4078 4084 bogus .py extension is gone, at last. Examples were moved to a
4079 4085 separate subdir under doc/, and the separate executable scripts
4080 4086 now live in their own directory. Overall a great cleanup. The
4081 4087 manual was updated to use the new files, and setup.py has been
4082 4088 fixed for this setup.
4083 4089
4084 4090 * IPython/PyColorize.py (Parser.usage): made non-executable and
4085 4091 created a pycolor wrapper around it to be included as a script.
4086 4092
4087 4093 2003-03-12 *** Released version 0.2.15pre2
4088 4094
4089 4095 2003-03-12 Fernando Perez <fperez@colorado.edu>
4090 4096
4091 4097 * IPython/ColorANSI.py (make_color_table): Finally fixed the
4092 4098 long-standing problem with garbage characters in some terminals.
4093 4099 The issue was really that the \001 and \002 escapes must _only_ be
4094 4100 passed to input prompts (which call readline), but _never_ to
4095 4101 normal text to be printed on screen. I changed ColorANSI to have
4096 4102 two classes: TermColors and InputTermColors, each with the
4097 4103 appropriate escapes for input prompts or normal text. The code in
4098 4104 Prompts.py got slightly more complicated, but this very old and
4099 4105 annoying bug is finally fixed.
4100 4106
4101 4107 All the credit for nailing down the real origin of this problem
4102 4108 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
4103 4109 *Many* thanks to him for spending quite a bit of effort on this.
4104 4110
4105 4111 2003-03-05 *** Released version 0.2.15pre1
4106 4112
4107 4113 2003-03-03 Fernando Perez <fperez@colorado.edu>
4108 4114
4109 4115 * IPython/FakeModule.py: Moved the former _FakeModule to a
4110 4116 separate file, because it's also needed by Magic (to fix a similar
4111 4117 pickle-related issue in @run).
4112 4118
4113 4119 2003-03-02 Fernando Perez <fperez@colorado.edu>
4114 4120
4115 4121 * IPython/Magic.py (Magic.magic_autocall): new magic to control
4116 4122 the autocall option at runtime.
4117 4123 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
4118 4124 across Magic.py to start separating Magic from InteractiveShell.
4119 4125 (Magic._ofind): Fixed to return proper namespace for dotted
4120 4126 names. Before, a dotted name would always return 'not currently
4121 4127 defined', because it would find the 'parent'. s.x would be found,
4122 4128 but since 'x' isn't defined by itself, it would get confused.
4123 4129 (Magic.magic_run): Fixed pickling problems reported by Ralf
4124 4130 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
4125 4131 that I'd used when Mike Heeter reported similar issues at the
4126 4132 top-level, but now for @run. It boils down to injecting the
4127 4133 namespace where code is being executed with something that looks
4128 4134 enough like a module to fool pickle.dump(). Since a pickle stores
4129 4135 a named reference to the importing module, we need this for
4130 4136 pickles to save something sensible.
4131 4137
4132 4138 * IPython/ipmaker.py (make_IPython): added an autocall option.
4133 4139
4134 4140 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
4135 4141 the auto-eval code. Now autocalling is an option, and the code is
4136 4142 also vastly safer. There is no more eval() involved at all.
4137 4143
4138 4144 2003-03-01 Fernando Perez <fperez@colorado.edu>
4139 4145
4140 4146 * IPython/Magic.py (Magic._ofind): Changed interface to return a
4141 4147 dict with named keys instead of a tuple.
4142 4148
4143 4149 * IPython: Started using CVS for IPython as of 0.2.15pre1.
4144 4150
4145 4151 * setup.py (make_shortcut): Fixed message about directories
4146 4152 created during Windows installation (the directories were ok, just
4147 4153 the printed message was misleading). Thanks to Chris Liechti
4148 4154 <cliechti-AT-gmx.net> for the heads up.
4149 4155
4150 4156 2003-02-21 Fernando Perez <fperez@colorado.edu>
4151 4157
4152 4158 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
4153 4159 of ValueError exception when checking for auto-execution. This
4154 4160 one is raised by things like Numeric arrays arr.flat when the
4155 4161 array is non-contiguous.
4156 4162
4157 4163 2003-01-31 Fernando Perez <fperez@colorado.edu>
4158 4164
4159 4165 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
4160 4166 not return any value at all (even though the command would get
4161 4167 executed).
4162 4168 (xsys): Flush stdout right after printing the command to ensure
4163 4169 proper ordering of commands and command output in the total
4164 4170 output.
4165 4171 (SystemExec/xsys/bq): Switched the names of xsys/bq and
4166 4172 system/getoutput as defaults. The old ones are kept for
4167 4173 compatibility reasons, so no code which uses this library needs
4168 4174 changing.
4169 4175
4170 4176 2003-01-27 *** Released version 0.2.14
4171 4177
4172 4178 2003-01-25 Fernando Perez <fperez@colorado.edu>
4173 4179
4174 4180 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
4175 4181 functions defined in previous edit sessions could not be re-edited
4176 4182 (because the temp files were immediately removed). Now temp files
4177 4183 are removed only at IPython's exit.
4178 4184 (Magic.magic_run): Improved @run to perform shell-like expansions
4179 4185 on its arguments (~users and $VARS). With this, @run becomes more
4180 4186 like a normal command-line.
4181 4187
4182 4188 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
4183 4189 bugs related to embedding and cleaned up that code. A fairly
4184 4190 important one was the impossibility to access the global namespace
4185 4191 through the embedded IPython (only local variables were visible).
4186 4192
4187 4193 2003-01-14 Fernando Perez <fperez@colorado.edu>
4188 4194
4189 4195 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
4190 4196 auto-calling to be a bit more conservative. Now it doesn't get
4191 4197 triggered if any of '!=()<>' are in the rest of the input line, to
4192 4198 allow comparing callables. Thanks to Alex for the heads up.
4193 4199
4194 4200 2003-01-07 Fernando Perez <fperez@colorado.edu>
4195 4201
4196 4202 * IPython/genutils.py (page): fixed estimation of the number of
4197 4203 lines in a string to be paged to simply count newlines. This
4198 4204 prevents over-guessing due to embedded escape sequences. A better
4199 4205 long-term solution would involve stripping out the control chars
4200 4206 for the count, but it's potentially so expensive I just don't
4201 4207 think it's worth doing.
4202 4208
4203 4209 2002-12-19 *** Released version 0.2.14pre50
4204 4210
4205 4211 2002-12-19 Fernando Perez <fperez@colorado.edu>
4206 4212
4207 4213 * tools/release (version): Changed release scripts to inform
4208 4214 Andrea and build a NEWS file with a list of recent changes.
4209 4215
4210 4216 * IPython/ColorANSI.py (__all__): changed terminal detection
4211 4217 code. Seems to work better for xterms without breaking
4212 4218 konsole. Will need more testing to determine if WinXP and Mac OSX
4213 4219 also work ok.
4214 4220
4215 4221 2002-12-18 *** Released version 0.2.14pre49
4216 4222
4217 4223 2002-12-18 Fernando Perez <fperez@colorado.edu>
4218 4224
4219 4225 * Docs: added new info about Mac OSX, from Andrea.
4220 4226
4221 4227 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
4222 4228 allow direct plotting of python strings whose format is the same
4223 4229 of gnuplot data files.
4224 4230
4225 4231 2002-12-16 Fernando Perez <fperez@colorado.edu>
4226 4232
4227 4233 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
4228 4234 value of exit question to be acknowledged.
4229 4235
4230 4236 2002-12-03 Fernando Perez <fperez@colorado.edu>
4231 4237
4232 4238 * IPython/ipmaker.py: removed generators, which had been added
4233 4239 by mistake in an earlier debugging run. This was causing trouble
4234 4240 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
4235 4241 for pointing this out.
4236 4242
4237 4243 2002-11-17 Fernando Perez <fperez@colorado.edu>
4238 4244
4239 4245 * Manual: updated the Gnuplot section.
4240 4246
4241 4247 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
4242 4248 a much better split of what goes in Runtime and what goes in
4243 4249 Interactive.
4244 4250
4245 4251 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
4246 4252 being imported from iplib.
4247 4253
4248 4254 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
4249 4255 for command-passing. Now the global Gnuplot instance is called
4250 4256 'gp' instead of 'g', which was really a far too fragile and
4251 4257 common name.
4252 4258
4253 4259 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
4254 4260 bounding boxes generated by Gnuplot for square plots.
4255 4261
4256 4262 * IPython/genutils.py (popkey): new function added. I should
4257 4263 suggest this on c.l.py as a dict method, it seems useful.
4258 4264
4259 4265 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
4260 4266 to transparently handle PostScript generation. MUCH better than
4261 4267 the previous plot_eps/replot_eps (which I removed now). The code
4262 4268 is also fairly clean and well documented now (including
4263 4269 docstrings).
4264 4270
4265 4271 2002-11-13 Fernando Perez <fperez@colorado.edu>
4266 4272
4267 4273 * IPython/Magic.py (Magic.magic_edit): fixed docstring
4268 4274 (inconsistent with options).
4269 4275
4270 4276 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
4271 4277 manually disabled, I don't know why. Fixed it.
4272 4278 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
4273 4279 eps output.
4274 4280
4275 4281 2002-11-12 Fernando Perez <fperez@colorado.edu>
4276 4282
4277 4283 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
4278 4284 don't propagate up to caller. Fixes crash reported by François
4279 4285 Pinard.
4280 4286
4281 4287 2002-11-09 Fernando Perez <fperez@colorado.edu>
4282 4288
4283 4289 * IPython/ipmaker.py (make_IPython): fixed problem with writing
4284 4290 history file for new users.
4285 4291 (make_IPython): fixed bug where initial install would leave the
4286 4292 user running in the .ipython dir.
4287 4293 (make_IPython): fixed bug where config dir .ipython would be
4288 4294 created regardless of the given -ipythondir option. Thanks to Cory
4289 4295 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
4290 4296
4291 4297 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
4292 4298 type confirmations. Will need to use it in all of IPython's code
4293 4299 consistently.
4294 4300
4295 4301 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
4296 4302 context to print 31 lines instead of the default 5. This will make
4297 4303 the crash reports extremely detailed in case the problem is in
4298 4304 libraries I don't have access to.
4299 4305
4300 4306 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
4301 4307 line of defense' code to still crash, but giving users fair
4302 4308 warning. I don't want internal errors to go unreported: if there's
4303 4309 an internal problem, IPython should crash and generate a full
4304 4310 report.
4305 4311
4306 4312 2002-11-08 Fernando Perez <fperez@colorado.edu>
4307 4313
4308 4314 * IPython/iplib.py (InteractiveShell.interact): added code to trap
4309 4315 otherwise uncaught exceptions which can appear if people set
4310 4316 sys.stdout to something badly broken. Thanks to a crash report
4311 4317 from henni-AT-mail.brainbot.com.
4312 4318
4313 4319 2002-11-04 Fernando Perez <fperez@colorado.edu>
4314 4320
4315 4321 * IPython/iplib.py (InteractiveShell.interact): added
4316 4322 __IPYTHON__active to the builtins. It's a flag which goes on when
4317 4323 the interaction starts and goes off again when it stops. This
4318 4324 allows embedding code to detect being inside IPython. Before this
4319 4325 was done via __IPYTHON__, but that only shows that an IPython
4320 4326 instance has been created.
4321 4327
4322 4328 * IPython/Magic.py (Magic.magic_env): I realized that in a
4323 4329 UserDict, instance.data holds the data as a normal dict. So I
4324 4330 modified @env to return os.environ.data instead of rebuilding a
4325 4331 dict by hand.
4326 4332
4327 4333 2002-11-02 Fernando Perez <fperez@colorado.edu>
4328 4334
4329 4335 * IPython/genutils.py (warn): changed so that level 1 prints no
4330 4336 header. Level 2 is now the default (with 'WARNING' header, as
4331 4337 before). I think I tracked all places where changes were needed in
4332 4338 IPython, but outside code using the old level numbering may have
4333 4339 broken.
4334 4340
4335 4341 * IPython/iplib.py (InteractiveShell.runcode): added this to
4336 4342 handle the tracebacks in SystemExit traps correctly. The previous
4337 4343 code (through interact) was printing more of the stack than
4338 4344 necessary, showing IPython internal code to the user.
4339 4345
4340 4346 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
4341 4347 default. Now that the default at the confirmation prompt is yes,
4342 4348 it's not so intrusive. François' argument that ipython sessions
4343 4349 tend to be complex enough not to lose them from an accidental C-d,
4344 4350 is a valid one.
4345 4351
4346 4352 * IPython/iplib.py (InteractiveShell.interact): added a
4347 4353 showtraceback() call to the SystemExit trap, and modified the exit
4348 4354 confirmation to have yes as the default.
4349 4355
4350 4356 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
4351 4357 this file. It's been gone from the code for a long time, this was
4352 4358 simply leftover junk.
4353 4359
4354 4360 2002-11-01 Fernando Perez <fperez@colorado.edu>
4355 4361
4356 4362 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
4357 4363 added. If set, IPython now traps EOF and asks for
4358 4364 confirmation. After a request by François Pinard.
4359 4365
4360 4366 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
4361 4367 of @abort, and with a new (better) mechanism for handling the
4362 4368 exceptions.
4363 4369
4364 4370 2002-10-27 Fernando Perez <fperez@colorado.edu>
4365 4371
4366 4372 * IPython/usage.py (__doc__): updated the --help information and
4367 4373 the ipythonrc file to indicate that -log generates
4368 4374 ./ipython.log. Also fixed the corresponding info in @logstart.
4369 4375 This and several other fixes in the manuals thanks to reports by
4370 4376 François Pinard <pinard-AT-iro.umontreal.ca>.
4371 4377
4372 4378 * IPython/Logger.py (Logger.switch_log): Fixed error message to
4373 4379 refer to @logstart (instead of @log, which doesn't exist).
4374 4380
4375 4381 * IPython/iplib.py (InteractiveShell._prefilter): fixed
4376 4382 AttributeError crash. Thanks to Christopher Armstrong
4377 4383 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
4378 4384 introduced recently (in 0.2.14pre37) with the fix to the eval
4379 4385 problem mentioned below.
4380 4386
4381 4387 2002-10-17 Fernando Perez <fperez@colorado.edu>
4382 4388
4383 4389 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
4384 4390 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
4385 4391
4386 4392 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
4387 4393 this function to fix a problem reported by Alex Schmolck. He saw
4388 4394 it with list comprehensions and generators, which were getting
4389 4395 called twice. The real problem was an 'eval' call in testing for
4390 4396 automagic which was evaluating the input line silently.
4391 4397
4392 4398 This is a potentially very nasty bug, if the input has side
4393 4399 effects which must not be repeated. The code is much cleaner now,
4394 4400 without any blanket 'except' left and with a regexp test for
4395 4401 actual function names.
4396 4402
4397 4403 But an eval remains, which I'm not fully comfortable with. I just
4398 4404 don't know how to find out if an expression could be a callable in
4399 4405 the user's namespace without doing an eval on the string. However
4400 4406 that string is now much more strictly checked so that no code
4401 4407 slips by, so the eval should only happen for things that can
4402 4408 really be only function/method names.
4403 4409
4404 4410 2002-10-15 Fernando Perez <fperez@colorado.edu>
4405 4411
4406 4412 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
4407 4413 OSX information to main manual, removed README_Mac_OSX file from
4408 4414 distribution. Also updated credits for recent additions.
4409 4415
4410 4416 2002-10-10 Fernando Perez <fperez@colorado.edu>
4411 4417
4412 4418 * README_Mac_OSX: Added a README for Mac OSX users for fixing
4413 4419 terminal-related issues. Many thanks to Andrea Riciputi
4414 4420 <andrea.riciputi-AT-libero.it> for writing it.
4415 4421
4416 4422 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
4417 4423 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
4418 4424
4419 4425 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
4420 4426 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
4421 4427 <syver-en-AT-online.no> who both submitted patches for this problem.
4422 4428
4423 4429 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
4424 4430 global embedding to make sure that things don't overwrite user
4425 4431 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
4426 4432
4427 4433 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
4428 4434 compatibility. Thanks to Hayden Callow
4429 4435 <h.callow-AT-elec.canterbury.ac.nz>
4430 4436
4431 4437 2002-10-04 Fernando Perez <fperez@colorado.edu>
4432 4438
4433 4439 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
4434 4440 Gnuplot.File objects.
4435 4441
4436 4442 2002-07-23 Fernando Perez <fperez@colorado.edu>
4437 4443
4438 4444 * IPython/genutils.py (timing): Added timings() and timing() for
4439 4445 quick access to the most commonly needed data, the execution
4440 4446 times. Old timing() renamed to timings_out().
4441 4447
4442 4448 2002-07-18 Fernando Perez <fperez@colorado.edu>
4443 4449
4444 4450 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
4445 4451 bug with nested instances disrupting the parent's tab completion.
4446 4452
4447 4453 * IPython/iplib.py (all_completions): Added Alex Schmolck's
4448 4454 all_completions code to begin the emacs integration.
4449 4455
4450 4456 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
4451 4457 argument to allow titling individual arrays when plotting.
4452 4458
4453 4459 2002-07-15 Fernando Perez <fperez@colorado.edu>
4454 4460
4455 4461 * setup.py (make_shortcut): changed to retrieve the value of
4456 4462 'Program Files' directory from the registry (this value changes in
4457 4463 non-english versions of Windows). Thanks to Thomas Fanslau
4458 4464 <tfanslau-AT-gmx.de> for the report.
4459 4465
4460 4466 2002-07-10 Fernando Perez <fperez@colorado.edu>
4461 4467
4462 4468 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
4463 4469 a bug in pdb, which crashes if a line with only whitespace is
4464 4470 entered. Bug report submitted to sourceforge.
4465 4471
4466 4472 2002-07-09 Fernando Perez <fperez@colorado.edu>
4467 4473
4468 4474 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
4469 4475 reporting exceptions (it's a bug in inspect.py, I just set a
4470 4476 workaround).
4471 4477
4472 4478 2002-07-08 Fernando Perez <fperez@colorado.edu>
4473 4479
4474 4480 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
4475 4481 __IPYTHON__ in __builtins__ to show up in user_ns.
4476 4482
4477 4483 2002-07-03 Fernando Perez <fperez@colorado.edu>
4478 4484
4479 4485 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
4480 4486 name from @gp_set_instance to @gp_set_default.
4481 4487
4482 4488 * IPython/ipmaker.py (make_IPython): default editor value set to
4483 4489 '0' (a string), to match the rc file. Otherwise will crash when
4484 4490 .strip() is called on it.
4485 4491
4486 4492
4487 4493 2002-06-28 Fernando Perez <fperez@colorado.edu>
4488 4494
4489 4495 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
4490 4496 of files in current directory when a file is executed via
4491 4497 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
4492 4498
4493 4499 * setup.py (manfiles): fix for rpm builds, submitted by RA
4494 4500 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
4495 4501
4496 4502 * IPython/ipmaker.py (make_IPython): fixed lookup of default
4497 4503 editor when set to '0'. Problem was, '0' evaluates to True (it's a
4498 4504 string!). A. Schmolck caught this one.
4499 4505
4500 4506 2002-06-27 Fernando Perez <fperez@colorado.edu>
4501 4507
4502 4508 * IPython/ipmaker.py (make_IPython): fixed bug when running user
4503 4509 defined files at the cmd line. __name__ wasn't being set to
4504 4510 __main__.
4505 4511
4506 4512 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
4507 4513 regular lists and tuples besides Numeric arrays.
4508 4514
4509 4515 * IPython/Prompts.py (CachedOutput.__call__): Added output
4510 4516 supression for input ending with ';'. Similar to Mathematica and
4511 4517 Matlab. The _* vars and Out[] list are still updated, just like
4512 4518 Mathematica behaves.
4513 4519
4514 4520 2002-06-25 Fernando Perez <fperez@colorado.edu>
4515 4521
4516 4522 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
4517 4523 .ini extensions for profiels under Windows.
4518 4524
4519 4525 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
4520 4526 string form. Fix contributed by Alexander Schmolck
4521 4527 <a.schmolck-AT-gmx.net>
4522 4528
4523 4529 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
4524 4530 pre-configured Gnuplot instance.
4525 4531
4526 4532 2002-06-21 Fernando Perez <fperez@colorado.edu>
4527 4533
4528 4534 * IPython/numutils.py (exp_safe): new function, works around the
4529 4535 underflow problems in Numeric.
4530 4536 (log2): New fn. Safe log in base 2: returns exact integer answer
4531 4537 for exact integer powers of 2.
4532 4538
4533 4539 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
4534 4540 properly.
4535 4541
4536 4542 2002-06-20 Fernando Perez <fperez@colorado.edu>
4537 4543
4538 4544 * IPython/genutils.py (timing): new function like
4539 4545 Mathematica's. Similar to time_test, but returns more info.
4540 4546
4541 4547 2002-06-18 Fernando Perez <fperez@colorado.edu>
4542 4548
4543 4549 * IPython/Magic.py (Magic.magic_save): modified @save and @r
4544 4550 according to Mike Heeter's suggestions.
4545 4551
4546 4552 2002-06-16 Fernando Perez <fperez@colorado.edu>
4547 4553
4548 4554 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
4549 4555 system. GnuplotMagic is gone as a user-directory option. New files
4550 4556 make it easier to use all the gnuplot stuff both from external
4551 4557 programs as well as from IPython. Had to rewrite part of
4552 4558 hardcopy() b/c of a strange bug: often the ps files simply don't
4553 4559 get created, and require a repeat of the command (often several
4554 4560 times).
4555 4561
4556 4562 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
4557 4563 resolve output channel at call time, so that if sys.stderr has
4558 4564 been redirected by user this gets honored.
4559 4565
4560 4566 2002-06-13 Fernando Perez <fperez@colorado.edu>
4561 4567
4562 4568 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
4563 4569 IPShell. Kept a copy with the old names to avoid breaking people's
4564 4570 embedded code.
4565 4571
4566 4572 * IPython/ipython: simplified it to the bare minimum after
4567 4573 Holger's suggestions. Added info about how to use it in
4568 4574 PYTHONSTARTUP.
4569 4575
4570 4576 * IPython/Shell.py (IPythonShell): changed the options passing
4571 4577 from a string with funky %s replacements to a straight list. Maybe
4572 4578 a bit more typing, but it follows sys.argv conventions, so there's
4573 4579 less special-casing to remember.
4574 4580
4575 4581 2002-06-12 Fernando Perez <fperez@colorado.edu>
4576 4582
4577 4583 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
4578 4584 command. Thanks to a suggestion by Mike Heeter.
4579 4585 (Magic.magic_pfile): added behavior to look at filenames if given
4580 4586 arg is not a defined object.
4581 4587 (Magic.magic_save): New @save function to save code snippets. Also
4582 4588 a Mike Heeter idea.
4583 4589
4584 4590 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
4585 4591 plot() and replot(). Much more convenient now, especially for
4586 4592 interactive use.
4587 4593
4588 4594 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
4589 4595 filenames.
4590 4596
4591 4597 2002-06-02 Fernando Perez <fperez@colorado.edu>
4592 4598
4593 4599 * IPython/Struct.py (Struct.__init__): modified to admit
4594 4600 initialization via another struct.
4595 4601
4596 4602 * IPython/genutils.py (SystemExec.__init__): New stateful
4597 4603 interface to xsys and bq. Useful for writing system scripts.
4598 4604
4599 4605 2002-05-30 Fernando Perez <fperez@colorado.edu>
4600 4606
4601 4607 * MANIFEST.in: Changed docfile selection to exclude all the lyx
4602 4608 documents. This will make the user download smaller (it's getting
4603 4609 too big).
4604 4610
4605 4611 2002-05-29 Fernando Perez <fperez@colorado.edu>
4606 4612
4607 4613 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
4608 4614 fix problems with shelve and pickle. Seems to work, but I don't
4609 4615 know if corner cases break it. Thanks to Mike Heeter
4610 4616 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
4611 4617
4612 4618 2002-05-24 Fernando Perez <fperez@colorado.edu>
4613 4619
4614 4620 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
4615 4621 macros having broken.
4616 4622
4617 4623 2002-05-21 Fernando Perez <fperez@colorado.edu>
4618 4624
4619 4625 * IPython/Magic.py (Magic.magic_logstart): fixed recently
4620 4626 introduced logging bug: all history before logging started was
4621 4627 being written one character per line! This came from the redesign
4622 4628 of the input history as a special list which slices to strings,
4623 4629 not to lists.
4624 4630
4625 4631 2002-05-20 Fernando Perez <fperez@colorado.edu>
4626 4632
4627 4633 * IPython/Prompts.py (CachedOutput.__init__): made the color table
4628 4634 be an attribute of all classes in this module. The design of these
4629 4635 classes needs some serious overhauling.
4630 4636
4631 4637 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
4632 4638 which was ignoring '_' in option names.
4633 4639
4634 4640 * IPython/ultraTB.py (FormattedTB.__init__): Changed
4635 4641 'Verbose_novars' to 'Context' and made it the new default. It's a
4636 4642 bit more readable and also safer than verbose.
4637 4643
4638 4644 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
4639 4645 triple-quoted strings.
4640 4646
4641 4647 * IPython/OInspect.py (__all__): new module exposing the object
4642 4648 introspection facilities. Now the corresponding magics are dummy
4643 4649 wrappers around this. Having this module will make it much easier
4644 4650 to put these functions into our modified pdb.
4645 4651 This new object inspector system uses the new colorizing module,
4646 4652 so source code and other things are nicely syntax highlighted.
4647 4653
4648 4654 2002-05-18 Fernando Perez <fperez@colorado.edu>
4649 4655
4650 4656 * IPython/ColorANSI.py: Split the coloring tools into a separate
4651 4657 module so I can use them in other code easier (they were part of
4652 4658 ultraTB).
4653 4659
4654 4660 2002-05-17 Fernando Perez <fperez@colorado.edu>
4655 4661
4656 4662 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
4657 4663 fixed it to set the global 'g' also to the called instance, as
4658 4664 long as 'g' was still a gnuplot instance (so it doesn't overwrite
4659 4665 user's 'g' variables).
4660 4666
4661 4667 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
4662 4668 global variables (aliases to _ih,_oh) so that users which expect
4663 4669 In[5] or Out[7] to work aren't unpleasantly surprised.
4664 4670 (InputList.__getslice__): new class to allow executing slices of
4665 4671 input history directly. Very simple class, complements the use of
4666 4672 macros.
4667 4673
4668 4674 2002-05-16 Fernando Perez <fperez@colorado.edu>
4669 4675
4670 4676 * setup.py (docdirbase): make doc directory be just doc/IPython
4671 4677 without version numbers, it will reduce clutter for users.
4672 4678
4673 4679 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
4674 4680 execfile call to prevent possible memory leak. See for details:
4675 4681 http://mail.python.org/pipermail/python-list/2002-February/088476.html
4676 4682
4677 4683 2002-05-15 Fernando Perez <fperez@colorado.edu>
4678 4684
4679 4685 * IPython/Magic.py (Magic.magic_psource): made the object
4680 4686 introspection names be more standard: pdoc, pdef, pfile and
4681 4687 psource. They all print/page their output, and it makes
4682 4688 remembering them easier. Kept old names for compatibility as
4683 4689 aliases.
4684 4690
4685 4691 2002-05-14 Fernando Perez <fperez@colorado.edu>
4686 4692
4687 4693 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
4688 4694 what the mouse problem was. The trick is to use gnuplot with temp
4689 4695 files and NOT with pipes (for data communication), because having
4690 4696 both pipes and the mouse on is bad news.
4691 4697
4692 4698 2002-05-13 Fernando Perez <fperez@colorado.edu>
4693 4699
4694 4700 * IPython/Magic.py (Magic._ofind): fixed namespace order search
4695 4701 bug. Information would be reported about builtins even when
4696 4702 user-defined functions overrode them.
4697 4703
4698 4704 2002-05-11 Fernando Perez <fperez@colorado.edu>
4699 4705
4700 4706 * IPython/__init__.py (__all__): removed FlexCompleter from
4701 4707 __all__ so that things don't fail in platforms without readline.
4702 4708
4703 4709 2002-05-10 Fernando Perez <fperez@colorado.edu>
4704 4710
4705 4711 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
4706 4712 it requires Numeric, effectively making Numeric a dependency for
4707 4713 IPython.
4708 4714
4709 4715 * Released 0.2.13
4710 4716
4711 4717 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
4712 4718 profiler interface. Now all the major options from the profiler
4713 4719 module are directly supported in IPython, both for single
4714 4720 expressions (@prun) and for full programs (@run -p).
4715 4721
4716 4722 2002-05-09 Fernando Perez <fperez@colorado.edu>
4717 4723
4718 4724 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
4719 4725 magic properly formatted for screen.
4720 4726
4721 4727 * setup.py (make_shortcut): Changed things to put pdf version in
4722 4728 doc/ instead of doc/manual (had to change lyxport a bit).
4723 4729
4724 4730 * IPython/Magic.py (Profile.string_stats): made profile runs go
4725 4731 through pager (they are long and a pager allows searching, saving,
4726 4732 etc.)
4727 4733
4728 4734 2002-05-08 Fernando Perez <fperez@colorado.edu>
4729 4735
4730 4736 * Released 0.2.12
4731 4737
4732 4738 2002-05-06 Fernando Perez <fperez@colorado.edu>
4733 4739
4734 4740 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
4735 4741 introduced); 'hist n1 n2' was broken.
4736 4742 (Magic.magic_pdb): added optional on/off arguments to @pdb
4737 4743 (Magic.magic_run): added option -i to @run, which executes code in
4738 4744 the IPython namespace instead of a clean one. Also added @irun as
4739 4745 an alias to @run -i.
4740 4746
4741 4747 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
4742 4748 fixed (it didn't really do anything, the namespaces were wrong).
4743 4749
4744 4750 * IPython/Debugger.py (__init__): Added workaround for python 2.1
4745 4751
4746 4752 * IPython/__init__.py (__all__): Fixed package namespace, now
4747 4753 'import IPython' does give access to IPython.<all> as
4748 4754 expected. Also renamed __release__ to Release.
4749 4755
4750 4756 * IPython/Debugger.py (__license__): created new Pdb class which
4751 4757 functions like a drop-in for the normal pdb.Pdb but does NOT
4752 4758 import readline by default. This way it doesn't muck up IPython's
4753 4759 readline handling, and now tab-completion finally works in the
4754 4760 debugger -- sort of. It completes things globally visible, but the
4755 4761 completer doesn't track the stack as pdb walks it. That's a bit
4756 4762 tricky, and I'll have to implement it later.
4757 4763
4758 4764 2002-05-05 Fernando Perez <fperez@colorado.edu>
4759 4765
4760 4766 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
4761 4767 magic docstrings when printed via ? (explicit \'s were being
4762 4768 printed).
4763 4769
4764 4770 * IPython/ipmaker.py (make_IPython): fixed namespace
4765 4771 identification bug. Now variables loaded via logs or command-line
4766 4772 files are recognized in the interactive namespace by @who.
4767 4773
4768 4774 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
4769 4775 log replay system stemming from the string form of Structs.
4770 4776
4771 4777 * IPython/Magic.py (Macro.__init__): improved macros to properly
4772 4778 handle magic commands in them.
4773 4779 (Magic.magic_logstart): usernames are now expanded so 'logstart
4774 4780 ~/mylog' now works.
4775 4781
4776 4782 * IPython/iplib.py (complete): fixed bug where paths starting with
4777 4783 '/' would be completed as magic names.
4778 4784
4779 4785 2002-05-04 Fernando Perez <fperez@colorado.edu>
4780 4786
4781 4787 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
4782 4788 allow running full programs under the profiler's control.
4783 4789
4784 4790 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
4785 4791 mode to report exceptions verbosely but without formatting
4786 4792 variables. This addresses the issue of ipython 'freezing' (it's
4787 4793 not frozen, but caught in an expensive formatting loop) when huge
4788 4794 variables are in the context of an exception.
4789 4795 (VerboseTB.text): Added '--->' markers at line where exception was
4790 4796 triggered. Much clearer to read, especially in NoColor modes.
4791 4797
4792 4798 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
4793 4799 implemented in reverse when changing to the new parse_options().
4794 4800
4795 4801 2002-05-03 Fernando Perez <fperez@colorado.edu>
4796 4802
4797 4803 * IPython/Magic.py (Magic.parse_options): new function so that
4798 4804 magics can parse options easier.
4799 4805 (Magic.magic_prun): new function similar to profile.run(),
4800 4806 suggested by Chris Hart.
4801 4807 (Magic.magic_cd): fixed behavior so that it only changes if
4802 4808 directory actually is in history.
4803 4809
4804 4810 * IPython/usage.py (__doc__): added information about potential
4805 4811 slowness of Verbose exception mode when there are huge data
4806 4812 structures to be formatted (thanks to Archie Paulson).
4807 4813
4808 4814 * IPython/ipmaker.py (make_IPython): Changed default logging
4809 4815 (when simply called with -log) to use curr_dir/ipython.log in
4810 4816 rotate mode. Fixed crash which was occuring with -log before
4811 4817 (thanks to Jim Boyle).
4812 4818
4813 4819 2002-05-01 Fernando Perez <fperez@colorado.edu>
4814 4820
4815 4821 * Released 0.2.11 for these fixes (mainly the ultraTB one which
4816 4822 was nasty -- though somewhat of a corner case).
4817 4823
4818 4824 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
4819 4825 text (was a bug).
4820 4826
4821 4827 2002-04-30 Fernando Perez <fperez@colorado.edu>
4822 4828
4823 4829 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
4824 4830 a print after ^D or ^C from the user so that the In[] prompt
4825 4831 doesn't over-run the gnuplot one.
4826 4832
4827 4833 2002-04-29 Fernando Perez <fperez@colorado.edu>
4828 4834
4829 4835 * Released 0.2.10
4830 4836
4831 4837 * IPython/__release__.py (version): get date dynamically.
4832 4838
4833 4839 * Misc. documentation updates thanks to Arnd's comments. Also ran
4834 4840 a full spellcheck on the manual (hadn't been done in a while).
4835 4841
4836 4842 2002-04-27 Fernando Perez <fperez@colorado.edu>
4837 4843
4838 4844 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
4839 4845 starting a log in mid-session would reset the input history list.
4840 4846
4841 4847 2002-04-26 Fernando Perez <fperez@colorado.edu>
4842 4848
4843 4849 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
4844 4850 all files were being included in an update. Now anything in
4845 4851 UserConfig that matches [A-Za-z]*.py will go (this excludes
4846 4852 __init__.py)
4847 4853
4848 4854 2002-04-25 Fernando Perez <fperez@colorado.edu>
4849 4855
4850 4856 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
4851 4857 to __builtins__ so that any form of embedded or imported code can
4852 4858 test for being inside IPython.
4853 4859
4854 4860 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
4855 4861 changed to GnuplotMagic because it's now an importable module,
4856 4862 this makes the name follow that of the standard Gnuplot module.
4857 4863 GnuplotMagic can now be loaded at any time in mid-session.
4858 4864
4859 4865 2002-04-24 Fernando Perez <fperez@colorado.edu>
4860 4866
4861 4867 * IPython/numutils.py: removed SIUnits. It doesn't properly set
4862 4868 the globals (IPython has its own namespace) and the
4863 4869 PhysicalQuantity stuff is much better anyway.
4864 4870
4865 4871 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
4866 4872 embedding example to standard user directory for
4867 4873 distribution. Also put it in the manual.
4868 4874
4869 4875 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
4870 4876 instance as first argument (so it doesn't rely on some obscure
4871 4877 hidden global).
4872 4878
4873 4879 * IPython/UserConfig/ipythonrc.py: put () back in accepted
4874 4880 delimiters. While it prevents ().TAB from working, it allows
4875 4881 completions in open (... expressions. This is by far a more common
4876 4882 case.
4877 4883
4878 4884 2002-04-23 Fernando Perez <fperez@colorado.edu>
4879 4885
4880 4886 * IPython/Extensions/InterpreterPasteInput.py: new
4881 4887 syntax-processing module for pasting lines with >>> or ... at the
4882 4888 start.
4883 4889
4884 4890 * IPython/Extensions/PhysicalQ_Interactive.py
4885 4891 (PhysicalQuantityInteractive.__int__): fixed to work with either
4886 4892 Numeric or math.
4887 4893
4888 4894 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
4889 4895 provided profiles. Now we have:
4890 4896 -math -> math module as * and cmath with its own namespace.
4891 4897 -numeric -> Numeric as *, plus gnuplot & grace
4892 4898 -physics -> same as before
4893 4899
4894 4900 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
4895 4901 user-defined magics wouldn't be found by @magic if they were
4896 4902 defined as class methods. Also cleaned up the namespace search
4897 4903 logic and the string building (to use %s instead of many repeated
4898 4904 string adds).
4899 4905
4900 4906 * IPython/UserConfig/example-magic.py (magic_foo): updated example
4901 4907 of user-defined magics to operate with class methods (cleaner, in
4902 4908 line with the gnuplot code).
4903 4909
4904 4910 2002-04-22 Fernando Perez <fperez@colorado.edu>
4905 4911
4906 4912 * setup.py: updated dependency list so that manual is updated when
4907 4913 all included files change.
4908 4914
4909 4915 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
4910 4916 the delimiter removal option (the fix is ugly right now).
4911 4917
4912 4918 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
4913 4919 all of the math profile (quicker loading, no conflict between
4914 4920 g-9.8 and g-gnuplot).
4915 4921
4916 4922 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
4917 4923 name of post-mortem files to IPython_crash_report.txt.
4918 4924
4919 4925 * Cleanup/update of the docs. Added all the new readline info and
4920 4926 formatted all lists as 'real lists'.
4921 4927
4922 4928 * IPython/ipmaker.py (make_IPython): removed now-obsolete
4923 4929 tab-completion options, since the full readline parse_and_bind is
4924 4930 now accessible.
4925 4931
4926 4932 * IPython/iplib.py (InteractiveShell.init_readline): Changed
4927 4933 handling of readline options. Now users can specify any string to
4928 4934 be passed to parse_and_bind(), as well as the delimiters to be
4929 4935 removed.
4930 4936 (InteractiveShell.__init__): Added __name__ to the global
4931 4937 namespace so that things like Itpl which rely on its existence
4932 4938 don't crash.
4933 4939 (InteractiveShell._prefilter): Defined the default with a _ so
4934 4940 that prefilter() is easier to override, while the default one
4935 4941 remains available.
4936 4942
4937 4943 2002-04-18 Fernando Perez <fperez@colorado.edu>
4938 4944
4939 4945 * Added information about pdb in the docs.
4940 4946
4941 4947 2002-04-17 Fernando Perez <fperez@colorado.edu>
4942 4948
4943 4949 * IPython/ipmaker.py (make_IPython): added rc_override option to
4944 4950 allow passing config options at creation time which may override
4945 4951 anything set in the config files or command line. This is
4946 4952 particularly useful for configuring embedded instances.
4947 4953
4948 4954 2002-04-15 Fernando Perez <fperez@colorado.edu>
4949 4955
4950 4956 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
4951 4957 crash embedded instances because of the input cache falling out of
4952 4958 sync with the output counter.
4953 4959
4954 4960 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
4955 4961 mode which calls pdb after an uncaught exception in IPython itself.
4956 4962
4957 4963 2002-04-14 Fernando Perez <fperez@colorado.edu>
4958 4964
4959 4965 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
4960 4966 readline, fix it back after each call.
4961 4967
4962 4968 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
4963 4969 method to force all access via __call__(), which guarantees that
4964 4970 traceback references are properly deleted.
4965 4971
4966 4972 * IPython/Prompts.py (CachedOutput._display): minor fixes to
4967 4973 improve printing when pprint is in use.
4968 4974
4969 4975 2002-04-13 Fernando Perez <fperez@colorado.edu>
4970 4976
4971 4977 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
4972 4978 exceptions aren't caught anymore. If the user triggers one, he
4973 4979 should know why he's doing it and it should go all the way up,
4974 4980 just like any other exception. So now @abort will fully kill the
4975 4981 embedded interpreter and the embedding code (unless that happens
4976 4982 to catch SystemExit).
4977 4983
4978 4984 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
4979 4985 and a debugger() method to invoke the interactive pdb debugger
4980 4986 after printing exception information. Also added the corresponding
4981 4987 -pdb option and @pdb magic to control this feature, and updated
4982 4988 the docs. After a suggestion from Christopher Hart
4983 4989 (hart-AT-caltech.edu).
4984 4990
4985 4991 2002-04-12 Fernando Perez <fperez@colorado.edu>
4986 4992
4987 4993 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
4988 4994 the exception handlers defined by the user (not the CrashHandler)
4989 4995 so that user exceptions don't trigger an ipython bug report.
4990 4996
4991 4997 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
4992 4998 configurable (it should have always been so).
4993 4999
4994 5000 2002-03-26 Fernando Perez <fperez@colorado.edu>
4995 5001
4996 5002 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
4997 5003 and there to fix embedding namespace issues. This should all be
4998 5004 done in a more elegant way.
4999 5005
5000 5006 2002-03-25 Fernando Perez <fperez@colorado.edu>
5001 5007
5002 5008 * IPython/genutils.py (get_home_dir): Try to make it work under
5003 5009 win9x also.
5004 5010
5005 5011 2002-03-20 Fernando Perez <fperez@colorado.edu>
5006 5012
5007 5013 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
5008 5014 sys.displayhook untouched upon __init__.
5009 5015
5010 5016 2002-03-19 Fernando Perez <fperez@colorado.edu>
5011 5017
5012 5018 * Released 0.2.9 (for embedding bug, basically).
5013 5019
5014 5020 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
5015 5021 exceptions so that enclosing shell's state can be restored.
5016 5022
5017 5023 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
5018 5024 naming conventions in the .ipython/ dir.
5019 5025
5020 5026 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
5021 5027 from delimiters list so filenames with - in them get expanded.
5022 5028
5023 5029 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
5024 5030 sys.displayhook not being properly restored after an embedded call.
5025 5031
5026 5032 2002-03-18 Fernando Perez <fperez@colorado.edu>
5027 5033
5028 5034 * Released 0.2.8
5029 5035
5030 5036 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
5031 5037 some files weren't being included in a -upgrade.
5032 5038 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
5033 5039 on' so that the first tab completes.
5034 5040 (InteractiveShell.handle_magic): fixed bug with spaces around
5035 5041 quotes breaking many magic commands.
5036 5042
5037 5043 * setup.py: added note about ignoring the syntax error messages at
5038 5044 installation.
5039 5045
5040 5046 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
5041 5047 streamlining the gnuplot interface, now there's only one magic @gp.
5042 5048
5043 5049 2002-03-17 Fernando Perez <fperez@colorado.edu>
5044 5050
5045 5051 * IPython/UserConfig/magic_gnuplot.py: new name for the
5046 5052 example-magic_pm.py file. Much enhanced system, now with a shell
5047 5053 for communicating directly with gnuplot, one command at a time.
5048 5054
5049 5055 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
5050 5056 setting __name__=='__main__'.
5051 5057
5052 5058 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
5053 5059 mini-shell for accessing gnuplot from inside ipython. Should
5054 5060 extend it later for grace access too. Inspired by Arnd's
5055 5061 suggestion.
5056 5062
5057 5063 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
5058 5064 calling magic functions with () in their arguments. Thanks to Arnd
5059 5065 Baecker for pointing this to me.
5060 5066
5061 5067 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
5062 5068 infinitely for integer or complex arrays (only worked with floats).
5063 5069
5064 5070 2002-03-16 Fernando Perez <fperez@colorado.edu>
5065 5071
5066 5072 * setup.py: Merged setup and setup_windows into a single script
5067 5073 which properly handles things for windows users.
5068 5074
5069 5075 2002-03-15 Fernando Perez <fperez@colorado.edu>
5070 5076
5071 5077 * Big change to the manual: now the magics are all automatically
5072 5078 documented. This information is generated from their docstrings
5073 5079 and put in a latex file included by the manual lyx file. This way
5074 5080 we get always up to date information for the magics. The manual
5075 5081 now also has proper version information, also auto-synced.
5076 5082
5077 5083 For this to work, an undocumented --magic_docstrings option was added.
5078 5084
5079 5085 2002-03-13 Fernando Perez <fperez@colorado.edu>
5080 5086
5081 5087 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
5082 5088 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
5083 5089
5084 5090 2002-03-12 Fernando Perez <fperez@colorado.edu>
5085 5091
5086 5092 * IPython/ultraTB.py (TermColors): changed color escapes again to
5087 5093 fix the (old, reintroduced) line-wrapping bug. Basically, if
5088 5094 \001..\002 aren't given in the color escapes, lines get wrapped
5089 5095 weirdly. But giving those screws up old xterms and emacs terms. So
5090 5096 I added some logic for emacs terms to be ok, but I can't identify old
5091 5097 xterms separately ($TERM=='xterm' for many terminals, like konsole).
5092 5098
5093 5099 2002-03-10 Fernando Perez <fperez@colorado.edu>
5094 5100
5095 5101 * IPython/usage.py (__doc__): Various documentation cleanups and
5096 5102 updates, both in usage docstrings and in the manual.
5097 5103
5098 5104 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
5099 5105 handling of caching. Set minimum acceptabe value for having a
5100 5106 cache at 20 values.
5101 5107
5102 5108 * IPython/iplib.py (InteractiveShell.user_setup): moved the
5103 5109 install_first_time function to a method, renamed it and added an
5104 5110 'upgrade' mode. Now people can update their config directory with
5105 5111 a simple command line switch (-upgrade, also new).
5106 5112
5107 5113 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
5108 5114 @file (convenient for automagic users under Python >= 2.2).
5109 5115 Removed @files (it seemed more like a plural than an abbrev. of
5110 5116 'file show').
5111 5117
5112 5118 * IPython/iplib.py (install_first_time): Fixed crash if there were
5113 5119 backup files ('~') in .ipython/ install directory.
5114 5120
5115 5121 * IPython/ipmaker.py (make_IPython): fixes for new prompt
5116 5122 system. Things look fine, but these changes are fairly
5117 5123 intrusive. Test them for a few days.
5118 5124
5119 5125 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
5120 5126 the prompts system. Now all in/out prompt strings are user
5121 5127 controllable. This is particularly useful for embedding, as one
5122 5128 can tag embedded instances with particular prompts.
5123 5129
5124 5130 Also removed global use of sys.ps1/2, which now allows nested
5125 5131 embeddings without any problems. Added command-line options for
5126 5132 the prompt strings.
5127 5133
5128 5134 2002-03-08 Fernando Perez <fperez@colorado.edu>
5129 5135
5130 5136 * IPython/UserConfig/example-embed-short.py (ipshell): added
5131 5137 example file with the bare minimum code for embedding.
5132 5138
5133 5139 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
5134 5140 functionality for the embeddable shell to be activated/deactivated
5135 5141 either globally or at each call.
5136 5142
5137 5143 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
5138 5144 rewriting the prompt with '--->' for auto-inputs with proper
5139 5145 coloring. Now the previous UGLY hack in handle_auto() is gone, and
5140 5146 this is handled by the prompts class itself, as it should.
5141 5147
5142 5148 2002-03-05 Fernando Perez <fperez@colorado.edu>
5143 5149
5144 5150 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
5145 5151 @logstart to avoid name clashes with the math log function.
5146 5152
5147 5153 * Big updates to X/Emacs section of the manual.
5148 5154
5149 5155 * Removed ipython_emacs. Milan explained to me how to pass
5150 5156 arguments to ipython through Emacs. Some day I'm going to end up
5151 5157 learning some lisp...
5152 5158
5153 5159 2002-03-04 Fernando Perez <fperez@colorado.edu>
5154 5160
5155 5161 * IPython/ipython_emacs: Created script to be used as the
5156 5162 py-python-command Emacs variable so we can pass IPython
5157 5163 parameters. I can't figure out how to tell Emacs directly to pass
5158 5164 parameters to IPython, so a dummy shell script will do it.
5159 5165
5160 5166 Other enhancements made for things to work better under Emacs'
5161 5167 various types of terminals. Many thanks to Milan Zamazal
5162 5168 <pdm-AT-zamazal.org> for all the suggestions and pointers.
5163 5169
5164 5170 2002-03-01 Fernando Perez <fperez@colorado.edu>
5165 5171
5166 5172 * IPython/ipmaker.py (make_IPython): added a --readline! option so
5167 5173 that loading of readline is now optional. This gives better
5168 5174 control to emacs users.
5169 5175
5170 5176 * IPython/ultraTB.py (__date__): Modified color escape sequences
5171 5177 and now things work fine under xterm and in Emacs' term buffers
5172 5178 (though not shell ones). Well, in emacs you get colors, but all
5173 5179 seem to be 'light' colors (no difference between dark and light
5174 5180 ones). But the garbage chars are gone, and also in xterms. It
5175 5181 seems that now I'm using 'cleaner' ansi sequences.
5176 5182
5177 5183 2002-02-21 Fernando Perez <fperez@colorado.edu>
5178 5184
5179 5185 * Released 0.2.7 (mainly to publish the scoping fix).
5180 5186
5181 5187 * IPython/Logger.py (Logger.logstate): added. A corresponding
5182 5188 @logstate magic was created.
5183 5189
5184 5190 * IPython/Magic.py: fixed nested scoping problem under Python
5185 5191 2.1.x (automagic wasn't working).
5186 5192
5187 5193 2002-02-20 Fernando Perez <fperez@colorado.edu>
5188 5194
5189 5195 * Released 0.2.6.
5190 5196
5191 5197 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
5192 5198 option so that logs can come out without any headers at all.
5193 5199
5194 5200 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
5195 5201 SciPy.
5196 5202
5197 5203 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
5198 5204 that embedded IPython calls don't require vars() to be explicitly
5199 5205 passed. Now they are extracted from the caller's frame (code
5200 5206 snatched from Eric Jones' weave). Added better documentation to
5201 5207 the section on embedding and the example file.
5202 5208
5203 5209 * IPython/genutils.py (page): Changed so that under emacs, it just
5204 5210 prints the string. You can then page up and down in the emacs
5205 5211 buffer itself. This is how the builtin help() works.
5206 5212
5207 5213 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
5208 5214 macro scoping: macros need to be executed in the user's namespace
5209 5215 to work as if they had been typed by the user.
5210 5216
5211 5217 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
5212 5218 execute automatically (no need to type 'exec...'). They then
5213 5219 behave like 'true macros'. The printing system was also modified
5214 5220 for this to work.
5215 5221
5216 5222 2002-02-19 Fernando Perez <fperez@colorado.edu>
5217 5223
5218 5224 * IPython/genutils.py (page_file): new function for paging files
5219 5225 in an OS-independent way. Also necessary for file viewing to work
5220 5226 well inside Emacs buffers.
5221 5227 (page): Added checks for being in an emacs buffer.
5222 5228 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
5223 5229 same bug in iplib.
5224 5230
5225 5231 2002-02-18 Fernando Perez <fperez@colorado.edu>
5226 5232
5227 5233 * IPython/iplib.py (InteractiveShell.init_readline): modified use
5228 5234 of readline so that IPython can work inside an Emacs buffer.
5229 5235
5230 5236 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
5231 5237 method signatures (they weren't really bugs, but it looks cleaner
5232 5238 and keeps PyChecker happy).
5233 5239
5234 5240 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
5235 5241 for implementing various user-defined hooks. Currently only
5236 5242 display is done.
5237 5243
5238 5244 * IPython/Prompts.py (CachedOutput._display): changed display
5239 5245 functions so that they can be dynamically changed by users easily.
5240 5246
5241 5247 * IPython/Extensions/numeric_formats.py (num_display): added an
5242 5248 extension for printing NumPy arrays in flexible manners. It
5243 5249 doesn't do anything yet, but all the structure is in
5244 5250 place. Ultimately the plan is to implement output format control
5245 5251 like in Octave.
5246 5252
5247 5253 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
5248 5254 methods are found at run-time by all the automatic machinery.
5249 5255
5250 5256 2002-02-17 Fernando Perez <fperez@colorado.edu>
5251 5257
5252 5258 * setup_Windows.py (make_shortcut): documented. Cleaned up the
5253 5259 whole file a little.
5254 5260
5255 5261 * ToDo: closed this document. Now there's a new_design.lyx
5256 5262 document for all new ideas. Added making a pdf of it for the
5257 5263 end-user distro.
5258 5264
5259 5265 * IPython/Logger.py (Logger.switch_log): Created this to replace
5260 5266 logon() and logoff(). It also fixes a nasty crash reported by
5261 5267 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
5262 5268
5263 5269 * IPython/iplib.py (complete): got auto-completion to work with
5264 5270 automagic (I had wanted this for a long time).
5265 5271
5266 5272 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
5267 5273 to @file, since file() is now a builtin and clashes with automagic
5268 5274 for @file.
5269 5275
5270 5276 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
5271 5277 of this was previously in iplib, which had grown to more than 2000
5272 5278 lines, way too long. No new functionality, but it makes managing
5273 5279 the code a bit easier.
5274 5280
5275 5281 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
5276 5282 information to crash reports.
5277 5283
5278 5284 2002-02-12 Fernando Perez <fperez@colorado.edu>
5279 5285
5280 5286 * Released 0.2.5.
5281 5287
5282 5288 2002-02-11 Fernando Perez <fperez@colorado.edu>
5283 5289
5284 5290 * Wrote a relatively complete Windows installer. It puts
5285 5291 everything in place, creates Start Menu entries and fixes the
5286 5292 color issues. Nothing fancy, but it works.
5287 5293
5288 5294 2002-02-10 Fernando Perez <fperez@colorado.edu>
5289 5295
5290 5296 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
5291 5297 os.path.expanduser() call so that we can type @run ~/myfile.py and
5292 5298 have thigs work as expected.
5293 5299
5294 5300 * IPython/genutils.py (page): fixed exception handling so things
5295 5301 work both in Unix and Windows correctly. Quitting a pager triggers
5296 5302 an IOError/broken pipe in Unix, and in windows not finding a pager
5297 5303 is also an IOError, so I had to actually look at the return value
5298 5304 of the exception, not just the exception itself. Should be ok now.
5299 5305
5300 5306 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
5301 5307 modified to allow case-insensitive color scheme changes.
5302 5308
5303 5309 2002-02-09 Fernando Perez <fperez@colorado.edu>
5304 5310
5305 5311 * IPython/genutils.py (native_line_ends): new function to leave
5306 5312 user config files with os-native line-endings.
5307 5313
5308 5314 * README and manual updates.
5309 5315
5310 5316 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
5311 5317 instead of StringType to catch Unicode strings.
5312 5318
5313 5319 * IPython/genutils.py (filefind): fixed bug for paths with
5314 5320 embedded spaces (very common in Windows).
5315 5321
5316 5322 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
5317 5323 files under Windows, so that they get automatically associated
5318 5324 with a text editor. Windows makes it a pain to handle
5319 5325 extension-less files.
5320 5326
5321 5327 * IPython/iplib.py (InteractiveShell.init_readline): Made the
5322 5328 warning about readline only occur for Posix. In Windows there's no
5323 5329 way to get readline, so why bother with the warning.
5324 5330
5325 5331 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
5326 5332 for __str__ instead of dir(self), since dir() changed in 2.2.
5327 5333
5328 5334 * Ported to Windows! Tested on XP, I suspect it should work fine
5329 5335 on NT/2000, but I don't think it will work on 98 et al. That
5330 5336 series of Windows is such a piece of junk anyway that I won't try
5331 5337 porting it there. The XP port was straightforward, showed a few
5332 5338 bugs here and there (fixed all), in particular some string
5333 5339 handling stuff which required considering Unicode strings (which
5334 5340 Windows uses). This is good, but hasn't been too tested :) No
5335 5341 fancy installer yet, I'll put a note in the manual so people at
5336 5342 least make manually a shortcut.
5337 5343
5338 5344 * IPython/iplib.py (Magic.magic_colors): Unified the color options
5339 5345 into a single one, "colors". This now controls both prompt and
5340 5346 exception color schemes, and can be changed both at startup
5341 5347 (either via command-line switches or via ipythonrc files) and at
5342 5348 runtime, with @colors.
5343 5349 (Magic.magic_run): renamed @prun to @run and removed the old
5344 5350 @run. The two were too similar to warrant keeping both.
5345 5351
5346 5352 2002-02-03 Fernando Perez <fperez@colorado.edu>
5347 5353
5348 5354 * IPython/iplib.py (install_first_time): Added comment on how to
5349 5355 configure the color options for first-time users. Put a <return>
5350 5356 request at the end so that small-terminal users get a chance to
5351 5357 read the startup info.
5352 5358
5353 5359 2002-01-23 Fernando Perez <fperez@colorado.edu>
5354 5360
5355 5361 * IPython/iplib.py (CachedOutput.update): Changed output memory
5356 5362 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
5357 5363 input history we still use _i. Did this b/c these variable are
5358 5364 very commonly used in interactive work, so the less we need to
5359 5365 type the better off we are.
5360 5366 (Magic.magic_prun): updated @prun to better handle the namespaces
5361 5367 the file will run in, including a fix for __name__ not being set
5362 5368 before.
5363 5369
5364 5370 2002-01-20 Fernando Perez <fperez@colorado.edu>
5365 5371
5366 5372 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
5367 5373 extra garbage for Python 2.2. Need to look more carefully into
5368 5374 this later.
5369 5375
5370 5376 2002-01-19 Fernando Perez <fperez@colorado.edu>
5371 5377
5372 5378 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
5373 5379 display SyntaxError exceptions properly formatted when they occur
5374 5380 (they can be triggered by imported code).
5375 5381
5376 5382 2002-01-18 Fernando Perez <fperez@colorado.edu>
5377 5383
5378 5384 * IPython/iplib.py (InteractiveShell.safe_execfile): now
5379 5385 SyntaxError exceptions are reported nicely formatted, instead of
5380 5386 spitting out only offset information as before.
5381 5387 (Magic.magic_prun): Added the @prun function for executing
5382 5388 programs with command line args inside IPython.
5383 5389
5384 5390 2002-01-16 Fernando Perez <fperez@colorado.edu>
5385 5391
5386 5392 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
5387 5393 to *not* include the last item given in a range. This brings their
5388 5394 behavior in line with Python's slicing:
5389 5395 a[n1:n2] -> a[n1]...a[n2-1]
5390 5396 It may be a bit less convenient, but I prefer to stick to Python's
5391 5397 conventions *everywhere*, so users never have to wonder.
5392 5398 (Magic.magic_macro): Added @macro function to ease the creation of
5393 5399 macros.
5394 5400
5395 5401 2002-01-05 Fernando Perez <fperez@colorado.edu>
5396 5402
5397 5403 * Released 0.2.4.
5398 5404
5399 5405 * IPython/iplib.py (Magic.magic_pdef):
5400 5406 (InteractiveShell.safe_execfile): report magic lines and error
5401 5407 lines without line numbers so one can easily copy/paste them for
5402 5408 re-execution.
5403 5409
5404 5410 * Updated manual with recent changes.
5405 5411
5406 5412 * IPython/iplib.py (Magic.magic_oinfo): added constructor
5407 5413 docstring printing when class? is called. Very handy for knowing
5408 5414 how to create class instances (as long as __init__ is well
5409 5415 documented, of course :)
5410 5416 (Magic.magic_doc): print both class and constructor docstrings.
5411 5417 (Magic.magic_pdef): give constructor info if passed a class and
5412 5418 __call__ info for callable object instances.
5413 5419
5414 5420 2002-01-04 Fernando Perez <fperez@colorado.edu>
5415 5421
5416 5422 * Made deep_reload() off by default. It doesn't always work
5417 5423 exactly as intended, so it's probably safer to have it off. It's
5418 5424 still available as dreload() anyway, so nothing is lost.
5419 5425
5420 5426 2002-01-02 Fernando Perez <fperez@colorado.edu>
5421 5427
5422 5428 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
5423 5429 so I wanted an updated release).
5424 5430
5425 5431 2001-12-27 Fernando Perez <fperez@colorado.edu>
5426 5432
5427 5433 * IPython/iplib.py (InteractiveShell.interact): Added the original
5428 5434 code from 'code.py' for this module in order to change the
5429 5435 handling of a KeyboardInterrupt. This was necessary b/c otherwise
5430 5436 the history cache would break when the user hit Ctrl-C, and
5431 5437 interact() offers no way to add any hooks to it.
5432 5438
5433 5439 2001-12-23 Fernando Perez <fperez@colorado.edu>
5434 5440
5435 5441 * setup.py: added check for 'MANIFEST' before trying to remove
5436 5442 it. Thanks to Sean Reifschneider.
5437 5443
5438 5444 2001-12-22 Fernando Perez <fperez@colorado.edu>
5439 5445
5440 5446 * Released 0.2.2.
5441 5447
5442 5448 * Finished (reasonably) writing the manual. Later will add the
5443 5449 python-standard navigation stylesheets, but for the time being
5444 5450 it's fairly complete. Distribution will include html and pdf
5445 5451 versions.
5446 5452
5447 5453 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
5448 5454 (MayaVi author).
5449 5455
5450 5456 2001-12-21 Fernando Perez <fperez@colorado.edu>
5451 5457
5452 5458 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
5453 5459 good public release, I think (with the manual and the distutils
5454 5460 installer). The manual can use some work, but that can go
5455 5461 slowly. Otherwise I think it's quite nice for end users. Next
5456 5462 summer, rewrite the guts of it...
5457 5463
5458 5464 * Changed format of ipythonrc files to use whitespace as the
5459 5465 separator instead of an explicit '='. Cleaner.
5460 5466
5461 5467 2001-12-20 Fernando Perez <fperez@colorado.edu>
5462 5468
5463 5469 * Started a manual in LyX. For now it's just a quick merge of the
5464 5470 various internal docstrings and READMEs. Later it may grow into a
5465 5471 nice, full-blown manual.
5466 5472
5467 5473 * Set up a distutils based installer. Installation should now be
5468 5474 trivially simple for end-users.
5469 5475
5470 5476 2001-12-11 Fernando Perez <fperez@colorado.edu>
5471 5477
5472 5478 * Released 0.2.0. First public release, announced it at
5473 5479 comp.lang.python. From now on, just bugfixes...
5474 5480
5475 5481 * Went through all the files, set copyright/license notices and
5476 5482 cleaned up things. Ready for release.
5477 5483
5478 5484 2001-12-10 Fernando Perez <fperez@colorado.edu>
5479 5485
5480 5486 * Changed the first-time installer not to use tarfiles. It's more
5481 5487 robust now and less unix-dependent. Also makes it easier for
5482 5488 people to later upgrade versions.
5483 5489
5484 5490 * Changed @exit to @abort to reflect the fact that it's pretty
5485 5491 brutal (a sys.exit()). The difference between @abort and Ctrl-D
5486 5492 becomes significant only when IPyhton is embedded: in that case,
5487 5493 C-D closes IPython only, but @abort kills the enclosing program
5488 5494 too (unless it had called IPython inside a try catching
5489 5495 SystemExit).
5490 5496
5491 5497 * Created Shell module which exposes the actuall IPython Shell
5492 5498 classes, currently the normal and the embeddable one. This at
5493 5499 least offers a stable interface we won't need to change when
5494 5500 (later) the internals are rewritten. That rewrite will be confined
5495 5501 to iplib and ipmaker, but the Shell interface should remain as is.
5496 5502
5497 5503 * Added embed module which offers an embeddable IPShell object,
5498 5504 useful to fire up IPython *inside* a running program. Great for
5499 5505 debugging or dynamical data analysis.
5500 5506
5501 5507 2001-12-08 Fernando Perez <fperez@colorado.edu>
5502 5508
5503 5509 * Fixed small bug preventing seeing info from methods of defined
5504 5510 objects (incorrect namespace in _ofind()).
5505 5511
5506 5512 * Documentation cleanup. Moved the main usage docstrings to a
5507 5513 separate file, usage.py (cleaner to maintain, and hopefully in the
5508 5514 future some perlpod-like way of producing interactive, man and
5509 5515 html docs out of it will be found).
5510 5516
5511 5517 * Added @profile to see your profile at any time.
5512 5518
5513 5519 * Added @p as an alias for 'print'. It's especially convenient if
5514 5520 using automagic ('p x' prints x).
5515 5521
5516 5522 * Small cleanups and fixes after a pychecker run.
5517 5523
5518 5524 * Changed the @cd command to handle @cd - and @cd -<n> for
5519 5525 visiting any directory in _dh.
5520 5526
5521 5527 * Introduced _dh, a history of visited directories. @dhist prints
5522 5528 it out with numbers.
5523 5529
5524 5530 2001-12-07 Fernando Perez <fperez@colorado.edu>
5525 5531
5526 5532 * Released 0.1.22
5527 5533
5528 5534 * Made initialization a bit more robust against invalid color
5529 5535 options in user input (exit, not traceback-crash).
5530 5536
5531 5537 * Changed the bug crash reporter to write the report only in the
5532 5538 user's .ipython directory. That way IPython won't litter people's
5533 5539 hard disks with crash files all over the place. Also print on
5534 5540 screen the necessary mail command.
5535 5541
5536 5542 * With the new ultraTB, implemented LightBG color scheme for light
5537 5543 background terminals. A lot of people like white backgrounds, so I
5538 5544 guess we should at least give them something readable.
5539 5545
5540 5546 2001-12-06 Fernando Perez <fperez@colorado.edu>
5541 5547
5542 5548 * Modified the structure of ultraTB. Now there's a proper class
5543 5549 for tables of color schemes which allow adding schemes easily and
5544 5550 switching the active scheme without creating a new instance every
5545 5551 time (which was ridiculous). The syntax for creating new schemes
5546 5552 is also cleaner. I think ultraTB is finally done, with a clean
5547 5553 class structure. Names are also much cleaner (now there's proper
5548 5554 color tables, no need for every variable to also have 'color' in
5549 5555 its name).
5550 5556
5551 5557 * Broke down genutils into separate files. Now genutils only
5552 5558 contains utility functions, and classes have been moved to their
5553 5559 own files (they had enough independent functionality to warrant
5554 5560 it): ConfigLoader, OutputTrap, Struct.
5555 5561
5556 5562 2001-12-05 Fernando Perez <fperez@colorado.edu>
5557 5563
5558 5564 * IPython turns 21! Released version 0.1.21, as a candidate for
5559 5565 public consumption. If all goes well, release in a few days.
5560 5566
5561 5567 * Fixed path bug (files in Extensions/ directory wouldn't be found
5562 5568 unless IPython/ was explicitly in sys.path).
5563 5569
5564 5570 * Extended the FlexCompleter class as MagicCompleter to allow
5565 5571 completion of @-starting lines.
5566 5572
5567 5573 * Created __release__.py file as a central repository for release
5568 5574 info that other files can read from.
5569 5575
5570 5576 * Fixed small bug in logging: when logging was turned on in
5571 5577 mid-session, old lines with special meanings (!@?) were being
5572 5578 logged without the prepended comment, which is necessary since
5573 5579 they are not truly valid python syntax. This should make session
5574 5580 restores produce less errors.
5575 5581
5576 5582 * The namespace cleanup forced me to make a FlexCompleter class
5577 5583 which is nothing but a ripoff of rlcompleter, but with selectable
5578 5584 namespace (rlcompleter only works in __main__.__dict__). I'll try
5579 5585 to submit a note to the authors to see if this change can be
5580 5586 incorporated in future rlcompleter releases (Dec.6: done)
5581 5587
5582 5588 * More fixes to namespace handling. It was a mess! Now all
5583 5589 explicit references to __main__.__dict__ are gone (except when
5584 5590 really needed) and everything is handled through the namespace
5585 5591 dicts in the IPython instance. We seem to be getting somewhere
5586 5592 with this, finally...
5587 5593
5588 5594 * Small documentation updates.
5589 5595
5590 5596 * Created the Extensions directory under IPython (with an
5591 5597 __init__.py). Put the PhysicalQ stuff there. This directory should
5592 5598 be used for all special-purpose extensions.
5593 5599
5594 5600 * File renaming:
5595 5601 ipythonlib --> ipmaker
5596 5602 ipplib --> iplib
5597 5603 This makes a bit more sense in terms of what these files actually do.
5598 5604
5599 5605 * Moved all the classes and functions in ipythonlib to ipplib, so
5600 5606 now ipythonlib only has make_IPython(). This will ease up its
5601 5607 splitting in smaller functional chunks later.
5602 5608
5603 5609 * Cleaned up (done, I think) output of @whos. Better column
5604 5610 formatting, and now shows str(var) for as much as it can, which is
5605 5611 typically what one gets with a 'print var'.
5606 5612
5607 5613 2001-12-04 Fernando Perez <fperez@colorado.edu>
5608 5614
5609 5615 * Fixed namespace problems. Now builtin/IPyhton/user names get
5610 5616 properly reported in their namespace. Internal namespace handling
5611 5617 is finally getting decent (not perfect yet, but much better than
5612 5618 the ad-hoc mess we had).
5613 5619
5614 5620 * Removed -exit option. If people just want to run a python
5615 5621 script, that's what the normal interpreter is for. Less
5616 5622 unnecessary options, less chances for bugs.
5617 5623
5618 5624 * Added a crash handler which generates a complete post-mortem if
5619 5625 IPython crashes. This will help a lot in tracking bugs down the
5620 5626 road.
5621 5627
5622 5628 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
5623 5629 which were boud to functions being reassigned would bypass the
5624 5630 logger, breaking the sync of _il with the prompt counter. This
5625 5631 would then crash IPython later when a new line was logged.
5626 5632
5627 5633 2001-12-02 Fernando Perez <fperez@colorado.edu>
5628 5634
5629 5635 * Made IPython a package. This means people don't have to clutter
5630 5636 their sys.path with yet another directory. Changed the INSTALL
5631 5637 file accordingly.
5632 5638
5633 5639 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
5634 5640 sorts its output (so @who shows it sorted) and @whos formats the
5635 5641 table according to the width of the first column. Nicer, easier to
5636 5642 read. Todo: write a generic table_format() which takes a list of
5637 5643 lists and prints it nicely formatted, with optional row/column
5638 5644 separators and proper padding and justification.
5639 5645
5640 5646 * Released 0.1.20
5641 5647
5642 5648 * Fixed bug in @log which would reverse the inputcache list (a
5643 5649 copy operation was missing).
5644 5650
5645 5651 * Code cleanup. @config was changed to use page(). Better, since
5646 5652 its output is always quite long.
5647 5653
5648 5654 * Itpl is back as a dependency. I was having too many problems
5649 5655 getting the parametric aliases to work reliably, and it's just
5650 5656 easier to code weird string operations with it than playing %()s
5651 5657 games. It's only ~6k, so I don't think it's too big a deal.
5652 5658
5653 5659 * Found (and fixed) a very nasty bug with history. !lines weren't
5654 5660 getting cached, and the out of sync caches would crash
5655 5661 IPython. Fixed it by reorganizing the prefilter/handlers/logger
5656 5662 division of labor a bit better. Bug fixed, cleaner structure.
5657 5663
5658 5664 2001-12-01 Fernando Perez <fperez@colorado.edu>
5659 5665
5660 5666 * Released 0.1.19
5661 5667
5662 5668 * Added option -n to @hist to prevent line number printing. Much
5663 5669 easier to copy/paste code this way.
5664 5670
5665 5671 * Created global _il to hold the input list. Allows easy
5666 5672 re-execution of blocks of code by slicing it (inspired by Janko's
5667 5673 comment on 'macros').
5668 5674
5669 5675 * Small fixes and doc updates.
5670 5676
5671 5677 * Rewrote @history function (was @h). Renamed it to @hist, @h is
5672 5678 much too fragile with automagic. Handles properly multi-line
5673 5679 statements and takes parameters.
5674 5680
5675 5681 2001-11-30 Fernando Perez <fperez@colorado.edu>
5676 5682
5677 5683 * Version 0.1.18 released.
5678 5684
5679 5685 * Fixed nasty namespace bug in initial module imports.
5680 5686
5681 5687 * Added copyright/license notes to all code files (except
5682 5688 DPyGetOpt). For the time being, LGPL. That could change.
5683 5689
5684 5690 * Rewrote a much nicer README, updated INSTALL, cleaned up
5685 5691 ipythonrc-* samples.
5686 5692
5687 5693 * Overall code/documentation cleanup. Basically ready for
5688 5694 release. Only remaining thing: licence decision (LGPL?).
5689 5695
5690 5696 * Converted load_config to a class, ConfigLoader. Now recursion
5691 5697 control is better organized. Doesn't include the same file twice.
5692 5698
5693 5699 2001-11-29 Fernando Perez <fperez@colorado.edu>
5694 5700
5695 5701 * Got input history working. Changed output history variables from
5696 5702 _p to _o so that _i is for input and _o for output. Just cleaner
5697 5703 convention.
5698 5704
5699 5705 * Implemented parametric aliases. This pretty much allows the
5700 5706 alias system to offer full-blown shell convenience, I think.
5701 5707
5702 5708 * Version 0.1.17 released, 0.1.18 opened.
5703 5709
5704 5710 * dot_ipython/ipythonrc (alias): added documentation.
5705 5711 (xcolor): Fixed small bug (xcolors -> xcolor)
5706 5712
5707 5713 * Changed the alias system. Now alias is a magic command to define
5708 5714 aliases just like the shell. Rationale: the builtin magics should
5709 5715 be there for things deeply connected to IPython's
5710 5716 architecture. And this is a much lighter system for what I think
5711 5717 is the really important feature: allowing users to define quickly
5712 5718 magics that will do shell things for them, so they can customize
5713 5719 IPython easily to match their work habits. If someone is really
5714 5720 desperate to have another name for a builtin alias, they can
5715 5721 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
5716 5722 works.
5717 5723
5718 5724 2001-11-28 Fernando Perez <fperez@colorado.edu>
5719 5725
5720 5726 * Changed @file so that it opens the source file at the proper
5721 5727 line. Since it uses less, if your EDITOR environment is
5722 5728 configured, typing v will immediately open your editor of choice
5723 5729 right at the line where the object is defined. Not as quick as
5724 5730 having a direct @edit command, but for all intents and purposes it
5725 5731 works. And I don't have to worry about writing @edit to deal with
5726 5732 all the editors, less does that.
5727 5733
5728 5734 * Version 0.1.16 released, 0.1.17 opened.
5729 5735
5730 5736 * Fixed some nasty bugs in the page/page_dumb combo that could
5731 5737 crash IPython.
5732 5738
5733 5739 2001-11-27 Fernando Perez <fperez@colorado.edu>
5734 5740
5735 5741 * Version 0.1.15 released, 0.1.16 opened.
5736 5742
5737 5743 * Finally got ? and ?? to work for undefined things: now it's
5738 5744 possible to type {}.get? and get information about the get method
5739 5745 of dicts, or os.path? even if only os is defined (so technically
5740 5746 os.path isn't). Works at any level. For example, after import os,
5741 5747 os?, os.path?, os.path.abspath? all work. This is great, took some
5742 5748 work in _ofind.
5743 5749
5744 5750 * Fixed more bugs with logging. The sanest way to do it was to add
5745 5751 to @log a 'mode' parameter. Killed two in one shot (this mode
5746 5752 option was a request of Janko's). I think it's finally clean
5747 5753 (famous last words).
5748 5754
5749 5755 * Added a page_dumb() pager which does a decent job of paging on
5750 5756 screen, if better things (like less) aren't available. One less
5751 5757 unix dependency (someday maybe somebody will port this to
5752 5758 windows).
5753 5759
5754 5760 * Fixed problem in magic_log: would lock of logging out if log
5755 5761 creation failed (because it would still think it had succeeded).
5756 5762
5757 5763 * Improved the page() function using curses to auto-detect screen
5758 5764 size. Now it can make a much better decision on whether to print
5759 5765 or page a string. Option screen_length was modified: a value 0
5760 5766 means auto-detect, and that's the default now.
5761 5767
5762 5768 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
5763 5769 go out. I'll test it for a few days, then talk to Janko about
5764 5770 licences and announce it.
5765 5771
5766 5772 * Fixed the length of the auto-generated ---> prompt which appears
5767 5773 for auto-parens and auto-quotes. Getting this right isn't trivial,
5768 5774 with all the color escapes, different prompt types and optional
5769 5775 separators. But it seems to be working in all the combinations.
5770 5776
5771 5777 2001-11-26 Fernando Perez <fperez@colorado.edu>
5772 5778
5773 5779 * Wrote a regexp filter to get option types from the option names
5774 5780 string. This eliminates the need to manually keep two duplicate
5775 5781 lists.
5776 5782
5777 5783 * Removed the unneeded check_option_names. Now options are handled
5778 5784 in a much saner manner and it's easy to visually check that things
5779 5785 are ok.
5780 5786
5781 5787 * Updated version numbers on all files I modified to carry a
5782 5788 notice so Janko and Nathan have clear version markers.
5783 5789
5784 5790 * Updated docstring for ultraTB with my changes. I should send
5785 5791 this to Nathan.
5786 5792
5787 5793 * Lots of small fixes. Ran everything through pychecker again.
5788 5794
5789 5795 * Made loading of deep_reload an cmd line option. If it's not too
5790 5796 kosher, now people can just disable it. With -nodeep_reload it's
5791 5797 still available as dreload(), it just won't overwrite reload().
5792 5798
5793 5799 * Moved many options to the no| form (-opt and -noopt
5794 5800 accepted). Cleaner.
5795 5801
5796 5802 * Changed magic_log so that if called with no parameters, it uses
5797 5803 'rotate' mode. That way auto-generated logs aren't automatically
5798 5804 over-written. For normal logs, now a backup is made if it exists
5799 5805 (only 1 level of backups). A new 'backup' mode was added to the
5800 5806 Logger class to support this. This was a request by Janko.
5801 5807
5802 5808 * Added @logoff/@logon to stop/restart an active log.
5803 5809
5804 5810 * Fixed a lot of bugs in log saving/replay. It was pretty
5805 5811 broken. Now special lines (!@,/) appear properly in the command
5806 5812 history after a log replay.
5807 5813
5808 5814 * Tried and failed to implement full session saving via pickle. My
5809 5815 idea was to pickle __main__.__dict__, but modules can't be
5810 5816 pickled. This would be a better alternative to replaying logs, but
5811 5817 seems quite tricky to get to work. Changed -session to be called
5812 5818 -logplay, which more accurately reflects what it does. And if we
5813 5819 ever get real session saving working, -session is now available.
5814 5820
5815 5821 * Implemented color schemes for prompts also. As for tracebacks,
5816 5822 currently only NoColor and Linux are supported. But now the
5817 5823 infrastructure is in place, based on a generic ColorScheme
5818 5824 class. So writing and activating new schemes both for the prompts
5819 5825 and the tracebacks should be straightforward.
5820 5826
5821 5827 * Version 0.1.13 released, 0.1.14 opened.
5822 5828
5823 5829 * Changed handling of options for output cache. Now counter is
5824 5830 hardwired starting at 1 and one specifies the maximum number of
5825 5831 entries *in the outcache* (not the max prompt counter). This is
5826 5832 much better, since many statements won't increase the cache
5827 5833 count. It also eliminated some confusing options, now there's only
5828 5834 one: cache_size.
5829 5835
5830 5836 * Added 'alias' magic function and magic_alias option in the
5831 5837 ipythonrc file. Now the user can easily define whatever names he
5832 5838 wants for the magic functions without having to play weird
5833 5839 namespace games. This gives IPython a real shell-like feel.
5834 5840
5835 5841 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
5836 5842 @ or not).
5837 5843
5838 5844 This was one of the last remaining 'visible' bugs (that I know
5839 5845 of). I think if I can clean up the session loading so it works
5840 5846 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
5841 5847 about licensing).
5842 5848
5843 5849 2001-11-25 Fernando Perez <fperez@colorado.edu>
5844 5850
5845 5851 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
5846 5852 there's a cleaner distinction between what ? and ?? show.
5847 5853
5848 5854 * Added screen_length option. Now the user can define his own
5849 5855 screen size for page() operations.
5850 5856
5851 5857 * Implemented magic shell-like functions with automatic code
5852 5858 generation. Now adding another function is just a matter of adding
5853 5859 an entry to a dict, and the function is dynamically generated at
5854 5860 run-time. Python has some really cool features!
5855 5861
5856 5862 * Renamed many options to cleanup conventions a little. Now all
5857 5863 are lowercase, and only underscores where needed. Also in the code
5858 5864 option name tables are clearer.
5859 5865
5860 5866 * Changed prompts a little. Now input is 'In [n]:' instead of
5861 5867 'In[n]:='. This allows it the numbers to be aligned with the
5862 5868 Out[n] numbers, and removes usage of ':=' which doesn't exist in
5863 5869 Python (it was a Mathematica thing). The '...' continuation prompt
5864 5870 was also changed a little to align better.
5865 5871
5866 5872 * Fixed bug when flushing output cache. Not all _p<n> variables
5867 5873 exist, so their deletion needs to be wrapped in a try:
5868 5874
5869 5875 * Figured out how to properly use inspect.formatargspec() (it
5870 5876 requires the args preceded by *). So I removed all the code from
5871 5877 _get_pdef in Magic, which was just replicating that.
5872 5878
5873 5879 * Added test to prefilter to allow redefining magic function names
5874 5880 as variables. This is ok, since the @ form is always available,
5875 5881 but whe should allow the user to define a variable called 'ls' if
5876 5882 he needs it.
5877 5883
5878 5884 * Moved the ToDo information from README into a separate ToDo.
5879 5885
5880 5886 * General code cleanup and small bugfixes. I think it's close to a
5881 5887 state where it can be released, obviously with a big 'beta'
5882 5888 warning on it.
5883 5889
5884 5890 * Got the magic function split to work. Now all magics are defined
5885 5891 in a separate class. It just organizes things a bit, and now
5886 5892 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
5887 5893 was too long).
5888 5894
5889 5895 * Changed @clear to @reset to avoid potential confusions with
5890 5896 the shell command clear. Also renamed @cl to @clear, which does
5891 5897 exactly what people expect it to from their shell experience.
5892 5898
5893 5899 Added a check to the @reset command (since it's so
5894 5900 destructive, it's probably a good idea to ask for confirmation).
5895 5901 But now reset only works for full namespace resetting. Since the
5896 5902 del keyword is already there for deleting a few specific
5897 5903 variables, I don't see the point of having a redundant magic
5898 5904 function for the same task.
5899 5905
5900 5906 2001-11-24 Fernando Perez <fperez@colorado.edu>
5901 5907
5902 5908 * Updated the builtin docs (esp. the ? ones).
5903 5909
5904 5910 * Ran all the code through pychecker. Not terribly impressed with
5905 5911 it: lots of spurious warnings and didn't really find anything of
5906 5912 substance (just a few modules being imported and not used).
5907 5913
5908 5914 * Implemented the new ultraTB functionality into IPython. New
5909 5915 option: xcolors. This chooses color scheme. xmode now only selects
5910 5916 between Plain and Verbose. Better orthogonality.
5911 5917
5912 5918 * Large rewrite of ultraTB. Much cleaner now, with a separation of
5913 5919 mode and color scheme for the exception handlers. Now it's
5914 5920 possible to have the verbose traceback with no coloring.
5915 5921
5916 5922 2001-11-23 Fernando Perez <fperez@colorado.edu>
5917 5923
5918 5924 * Version 0.1.12 released, 0.1.13 opened.
5919 5925
5920 5926 * Removed option to set auto-quote and auto-paren escapes by
5921 5927 user. The chances of breaking valid syntax are just too high. If
5922 5928 someone *really* wants, they can always dig into the code.
5923 5929
5924 5930 * Made prompt separators configurable.
5925 5931
5926 5932 2001-11-22 Fernando Perez <fperez@colorado.edu>
5927 5933
5928 5934 * Small bugfixes in many places.
5929 5935
5930 5936 * Removed the MyCompleter class from ipplib. It seemed redundant
5931 5937 with the C-p,C-n history search functionality. Less code to
5932 5938 maintain.
5933 5939
5934 5940 * Moved all the original ipython.py code into ipythonlib.py. Right
5935 5941 now it's just one big dump into a function called make_IPython, so
5936 5942 no real modularity has been gained. But at least it makes the
5937 5943 wrapper script tiny, and since ipythonlib is a module, it gets
5938 5944 compiled and startup is much faster.
5939 5945
5940 5946 This is a reasobably 'deep' change, so we should test it for a
5941 5947 while without messing too much more with the code.
5942 5948
5943 5949 2001-11-21 Fernando Perez <fperez@colorado.edu>
5944 5950
5945 5951 * Version 0.1.11 released, 0.1.12 opened for further work.
5946 5952
5947 5953 * Removed dependency on Itpl. It was only needed in one place. It
5948 5954 would be nice if this became part of python, though. It makes life
5949 5955 *a lot* easier in some cases.
5950 5956
5951 5957 * Simplified the prefilter code a bit. Now all handlers are
5952 5958 expected to explicitly return a value (at least a blank string).
5953 5959
5954 5960 * Heavy edits in ipplib. Removed the help system altogether. Now
5955 5961 obj?/?? is used for inspecting objects, a magic @doc prints
5956 5962 docstrings, and full-blown Python help is accessed via the 'help'
5957 5963 keyword. This cleans up a lot of code (less to maintain) and does
5958 5964 the job. Since 'help' is now a standard Python component, might as
5959 5965 well use it and remove duplicate functionality.
5960 5966
5961 5967 Also removed the option to use ipplib as a standalone program. By
5962 5968 now it's too dependent on other parts of IPython to function alone.
5963 5969
5964 5970 * Fixed bug in genutils.pager. It would crash if the pager was
5965 5971 exited immediately after opening (broken pipe).
5966 5972
5967 5973 * Trimmed down the VerboseTB reporting a little. The header is
5968 5974 much shorter now and the repeated exception arguments at the end
5969 5975 have been removed. For interactive use the old header seemed a bit
5970 5976 excessive.
5971 5977
5972 5978 * Fixed small bug in output of @whos for variables with multi-word
5973 5979 types (only first word was displayed).
5974 5980
5975 5981 2001-11-17 Fernando Perez <fperez@colorado.edu>
5976 5982
5977 5983 * Version 0.1.10 released, 0.1.11 opened for further work.
5978 5984
5979 5985 * Modified dirs and friends. dirs now *returns* the stack (not
5980 5986 prints), so one can manipulate it as a variable. Convenient to
5981 5987 travel along many directories.
5982 5988
5983 5989 * Fixed bug in magic_pdef: would only work with functions with
5984 5990 arguments with default values.
5985 5991
5986 5992 2001-11-14 Fernando Perez <fperez@colorado.edu>
5987 5993
5988 5994 * Added the PhysicsInput stuff to dot_ipython so it ships as an
5989 5995 example with IPython. Various other minor fixes and cleanups.
5990 5996
5991 5997 * Version 0.1.9 released, 0.1.10 opened for further work.
5992 5998
5993 5999 * Added sys.path to the list of directories searched in the
5994 6000 execfile= option. It used to be the current directory and the
5995 6001 user's IPYTHONDIR only.
5996 6002
5997 6003 2001-11-13 Fernando Perez <fperez@colorado.edu>
5998 6004
5999 6005 * Reinstated the raw_input/prefilter separation that Janko had
6000 6006 initially. This gives a more convenient setup for extending the
6001 6007 pre-processor from the outside: raw_input always gets a string,
6002 6008 and prefilter has to process it. We can then redefine prefilter
6003 6009 from the outside and implement extensions for special
6004 6010 purposes.
6005 6011
6006 6012 Today I got one for inputting PhysicalQuantity objects
6007 6013 (from Scientific) without needing any function calls at
6008 6014 all. Extremely convenient, and it's all done as a user-level
6009 6015 extension (no IPython code was touched). Now instead of:
6010 6016 a = PhysicalQuantity(4.2,'m/s**2')
6011 6017 one can simply say
6012 6018 a = 4.2 m/s**2
6013 6019 or even
6014 6020 a = 4.2 m/s^2
6015 6021
6016 6022 I use this, but it's also a proof of concept: IPython really is
6017 6023 fully user-extensible, even at the level of the parsing of the
6018 6024 command line. It's not trivial, but it's perfectly doable.
6019 6025
6020 6026 * Added 'add_flip' method to inclusion conflict resolver. Fixes
6021 6027 the problem of modules being loaded in the inverse order in which
6022 6028 they were defined in
6023 6029
6024 6030 * Version 0.1.8 released, 0.1.9 opened for further work.
6025 6031
6026 6032 * Added magics pdef, source and file. They respectively show the
6027 6033 definition line ('prototype' in C), source code and full python
6028 6034 file for any callable object. The object inspector oinfo uses
6029 6035 these to show the same information.
6030 6036
6031 6037 * Version 0.1.7 released, 0.1.8 opened for further work.
6032 6038
6033 6039 * Separated all the magic functions into a class called Magic. The
6034 6040 InteractiveShell class was becoming too big for Xemacs to handle
6035 6041 (de-indenting a line would lock it up for 10 seconds while it
6036 6042 backtracked on the whole class!)
6037 6043
6038 6044 FIXME: didn't work. It can be done, but right now namespaces are
6039 6045 all messed up. Do it later (reverted it for now, so at least
6040 6046 everything works as before).
6041 6047
6042 6048 * Got the object introspection system (magic_oinfo) working! I
6043 6049 think this is pretty much ready for release to Janko, so he can
6044 6050 test it for a while and then announce it. Pretty much 100% of what
6045 6051 I wanted for the 'phase 1' release is ready. Happy, tired.
6046 6052
6047 6053 2001-11-12 Fernando Perez <fperez@colorado.edu>
6048 6054
6049 6055 * Version 0.1.6 released, 0.1.7 opened for further work.
6050 6056
6051 6057 * Fixed bug in printing: it used to test for truth before
6052 6058 printing, so 0 wouldn't print. Now checks for None.
6053 6059
6054 6060 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
6055 6061 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
6056 6062 reaches by hand into the outputcache. Think of a better way to do
6057 6063 this later.
6058 6064
6059 6065 * Various small fixes thanks to Nathan's comments.
6060 6066
6061 6067 * Changed magic_pprint to magic_Pprint. This way it doesn't
6062 6068 collide with pprint() and the name is consistent with the command
6063 6069 line option.
6064 6070
6065 6071 * Changed prompt counter behavior to be fully like
6066 6072 Mathematica's. That is, even input that doesn't return a result
6067 6073 raises the prompt counter. The old behavior was kind of confusing
6068 6074 (getting the same prompt number several times if the operation
6069 6075 didn't return a result).
6070 6076
6071 6077 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
6072 6078
6073 6079 * Fixed -Classic mode (wasn't working anymore).
6074 6080
6075 6081 * Added colored prompts using Nathan's new code. Colors are
6076 6082 currently hardwired, they can be user-configurable. For
6077 6083 developers, they can be chosen in file ipythonlib.py, at the
6078 6084 beginning of the CachedOutput class def.
6079 6085
6080 6086 2001-11-11 Fernando Perez <fperez@colorado.edu>
6081 6087
6082 6088 * Version 0.1.5 released, 0.1.6 opened for further work.
6083 6089
6084 6090 * Changed magic_env to *return* the environment as a dict (not to
6085 6091 print it). This way it prints, but it can also be processed.
6086 6092
6087 6093 * Added Verbose exception reporting to interactive
6088 6094 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
6089 6095 traceback. Had to make some changes to the ultraTB file. This is
6090 6096 probably the last 'big' thing in my mental todo list. This ties
6091 6097 in with the next entry:
6092 6098
6093 6099 * Changed -Xi and -Xf to a single -xmode option. Now all the user
6094 6100 has to specify is Plain, Color or Verbose for all exception
6095 6101 handling.
6096 6102
6097 6103 * Removed ShellServices option. All this can really be done via
6098 6104 the magic system. It's easier to extend, cleaner and has automatic
6099 6105 namespace protection and documentation.
6100 6106
6101 6107 2001-11-09 Fernando Perez <fperez@colorado.edu>
6102 6108
6103 6109 * Fixed bug in output cache flushing (missing parameter to
6104 6110 __init__). Other small bugs fixed (found using pychecker).
6105 6111
6106 6112 * Version 0.1.4 opened for bugfixing.
6107 6113
6108 6114 2001-11-07 Fernando Perez <fperez@colorado.edu>
6109 6115
6110 6116 * Version 0.1.3 released, mainly because of the raw_input bug.
6111 6117
6112 6118 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
6113 6119 and when testing for whether things were callable, a call could
6114 6120 actually be made to certain functions. They would get called again
6115 6121 once 'really' executed, with a resulting double call. A disaster
6116 6122 in many cases (list.reverse() would never work!).
6117 6123
6118 6124 * Removed prefilter() function, moved its code to raw_input (which
6119 6125 after all was just a near-empty caller for prefilter). This saves
6120 6126 a function call on every prompt, and simplifies the class a tiny bit.
6121 6127
6122 6128 * Fix _ip to __ip name in magic example file.
6123 6129
6124 6130 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
6125 6131 work with non-gnu versions of tar.
6126 6132
6127 6133 2001-11-06 Fernando Perez <fperez@colorado.edu>
6128 6134
6129 6135 * Version 0.1.2. Just to keep track of the recent changes.
6130 6136
6131 6137 * Fixed nasty bug in output prompt routine. It used to check 'if
6132 6138 arg != None...'. Problem is, this fails if arg implements a
6133 6139 special comparison (__cmp__) which disallows comparing to
6134 6140 None. Found it when trying to use the PhysicalQuantity module from
6135 6141 ScientificPython.
6136 6142
6137 6143 2001-11-05 Fernando Perez <fperez@colorado.edu>
6138 6144
6139 6145 * Also added dirs. Now the pushd/popd/dirs family functions
6140 6146 basically like the shell, with the added convenience of going home
6141 6147 when called with no args.
6142 6148
6143 6149 * pushd/popd slightly modified to mimic shell behavior more
6144 6150 closely.
6145 6151
6146 6152 * Added env,pushd,popd from ShellServices as magic functions. I
6147 6153 think the cleanest will be to port all desired functions from
6148 6154 ShellServices as magics and remove ShellServices altogether. This
6149 6155 will provide a single, clean way of adding functionality
6150 6156 (shell-type or otherwise) to IP.
6151 6157
6152 6158 2001-11-04 Fernando Perez <fperez@colorado.edu>
6153 6159
6154 6160 * Added .ipython/ directory to sys.path. This way users can keep
6155 6161 customizations there and access them via import.
6156 6162
6157 6163 2001-11-03 Fernando Perez <fperez@colorado.edu>
6158 6164
6159 6165 * Opened version 0.1.1 for new changes.
6160 6166
6161 6167 * Changed version number to 0.1.0: first 'public' release, sent to
6162 6168 Nathan and Janko.
6163 6169
6164 6170 * Lots of small fixes and tweaks.
6165 6171
6166 6172 * Minor changes to whos format. Now strings are shown, snipped if
6167 6173 too long.
6168 6174
6169 6175 * Changed ShellServices to work on __main__ so they show up in @who
6170 6176
6171 6177 * Help also works with ? at the end of a line:
6172 6178 ?sin and sin?
6173 6179 both produce the same effect. This is nice, as often I use the
6174 6180 tab-complete to find the name of a method, but I used to then have
6175 6181 to go to the beginning of the line to put a ? if I wanted more
6176 6182 info. Now I can just add the ? and hit return. Convenient.
6177 6183
6178 6184 2001-11-02 Fernando Perez <fperez@colorado.edu>
6179 6185
6180 6186 * Python version check (>=2.1) added.
6181 6187
6182 6188 * Added LazyPython documentation. At this point the docs are quite
6183 6189 a mess. A cleanup is in order.
6184 6190
6185 6191 * Auto-installer created. For some bizarre reason, the zipfiles
6186 6192 module isn't working on my system. So I made a tar version
6187 6193 (hopefully the command line options in various systems won't kill
6188 6194 me).
6189 6195
6190 6196 * Fixes to Struct in genutils. Now all dictionary-like methods are
6191 6197 protected (reasonably).
6192 6198
6193 6199 * Added pager function to genutils and changed ? to print usage
6194 6200 note through it (it was too long).
6195 6201
6196 6202 * Added the LazyPython functionality. Works great! I changed the
6197 6203 auto-quote escape to ';', it's on home row and next to '. But
6198 6204 both auto-quote and auto-paren (still /) escapes are command-line
6199 6205 parameters.
6200 6206
6201 6207
6202 6208 2001-11-01 Fernando Perez <fperez@colorado.edu>
6203 6209
6204 6210 * Version changed to 0.0.7. Fairly large change: configuration now
6205 6211 is all stored in a directory, by default .ipython. There, all
6206 6212 config files have normal looking names (not .names)
6207 6213
6208 6214 * Version 0.0.6 Released first to Lucas and Archie as a test
6209 6215 run. Since it's the first 'semi-public' release, change version to
6210 6216 > 0.0.6 for any changes now.
6211 6217
6212 6218 * Stuff I had put in the ipplib.py changelog:
6213 6219
6214 6220 Changes to InteractiveShell:
6215 6221
6216 6222 - Made the usage message a parameter.
6217 6223
6218 6224 - Require the name of the shell variable to be given. It's a bit
6219 6225 of a hack, but allows the name 'shell' not to be hardwired in the
6220 6226 magic (@) handler, which is problematic b/c it requires
6221 6227 polluting the global namespace with 'shell'. This in turn is
6222 6228 fragile: if a user redefines a variable called shell, things
6223 6229 break.
6224 6230
6225 6231 - magic @: all functions available through @ need to be defined
6226 6232 as magic_<name>, even though they can be called simply as
6227 6233 @<name>. This allows the special command @magic to gather
6228 6234 information automatically about all existing magic functions,
6229 6235 even if they are run-time user extensions, by parsing the shell
6230 6236 instance __dict__ looking for special magic_ names.
6231 6237
6232 6238 - mainloop: added *two* local namespace parameters. This allows
6233 6239 the class to differentiate between parameters which were there
6234 6240 before and after command line initialization was processed. This
6235 6241 way, later @who can show things loaded at startup by the
6236 6242 user. This trick was necessary to make session saving/reloading
6237 6243 really work: ideally after saving/exiting/reloading a session,
6238 6244 *everything* should look the same, including the output of @who. I
6239 6245 was only able to make this work with this double namespace
6240 6246 trick.
6241 6247
6242 6248 - added a header to the logfile which allows (almost) full
6243 6249 session restoring.
6244 6250
6245 6251 - prepend lines beginning with @ or !, with a and log
6246 6252 them. Why? !lines: may be useful to know what you did @lines:
6247 6253 they may affect session state. So when restoring a session, at
6248 6254 least inform the user of their presence. I couldn't quite get
6249 6255 them to properly re-execute, but at least the user is warned.
6250 6256
6251 6257 * Started ChangeLog.
General Comments 0
You need to be logged in to leave comments. Login now