##// END OF EJS Templates
Ready for 0.7.0 release!...
fperez -
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,2736 +1,2741
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 994 2006-01-08 08:29:44Z fperez $"""
4 $Id: Magic.py 1000 2006-01-10 08:06:04Z 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 from cStringIO import StringIO
35 35 from getopt import getopt
36 36 from pprint import pprint, pformat
37 37
38 38 # profile isn't bundled by default in Debian for license reasons
39 39 try:
40 40 import profile,pstats
41 41 except ImportError:
42 42 profile = pstats = None
43 43
44 44 # Homebrewed
45 45 from IPython import Debugger, OInspect, wildcard
46 46 from IPython.FakeModule import FakeModule
47 47 from IPython.Itpl import Itpl, itpl, printpl,itplns
48 48 from IPython.PyColorize import Parser
49 49 from IPython.Struct import Struct
50 50 from IPython.macro import Macro
51 51 from IPython.genutils import *
52 52
53 53 #***************************************************************************
54 54 # Utility functions
55 55 def on_off(tag):
56 56 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
57 57 return ['OFF','ON'][tag]
58 58
59 59 class Bunch: pass
60 60
61 61 #***************************************************************************
62 62 # Main class implementing Magic functionality
63 63 class Magic:
64 64 """Magic functions for InteractiveShell.
65 65
66 66 Shell functions which can be reached as %function_name. All magic
67 67 functions should accept a string, which they can parse for their own
68 68 needs. This can make some functions easier to type, eg `%cd ../`
69 69 vs. `%cd("../")`
70 70
71 71 ALL definitions MUST begin with the prefix magic_. The user won't need it
72 72 at the command line, but it is is needed in the definition. """
73 73
74 74 # class globals
75 75 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
76 76 'Automagic is ON, % prefix NOT needed for magic functions.']
77 77
78 78 #......................................................................
79 79 # some utility functions
80 80
81 81 def __init__(self,shell):
82 82
83 83 self.options_table = {}
84 84 if profile is None:
85 85 self.magic_prun = self.profile_missing_notice
86 86 self.shell = shell
87 87
88 88 # namespace for holding state we may need
89 89 self._magic_state = Bunch()
90 90
91 91 def profile_missing_notice(self, *args, **kwargs):
92 92 error("""\
93 93 The profile module could not be found. If you are a Debian user,
94 94 it has been removed from the standard Debian package because of its non-free
95 95 license. To use profiling, please install"python2.3-profiler" from non-free.""")
96 96
97 97 def default_option(self,fn,optstr):
98 98 """Make an entry in the options_table for fn, with value optstr"""
99 99
100 100 if fn not in self.lsmagic():
101 101 error("%s is not a magic function" % fn)
102 102 self.options_table[fn] = optstr
103 103
104 104 def lsmagic(self):
105 105 """Return a list of currently available magic functions.
106 106
107 107 Gives a list of the bare names after mangling (['ls','cd', ...], not
108 108 ['magic_ls','magic_cd',...]"""
109 109
110 110 # FIXME. This needs a cleanup, in the way the magics list is built.
111 111
112 112 # magics in class definition
113 113 class_magic = lambda fn: fn.startswith('magic_') and \
114 114 callable(Magic.__dict__[fn])
115 115 # in instance namespace (run-time user additions)
116 116 inst_magic = lambda fn: fn.startswith('magic_') and \
117 117 callable(self.__dict__[fn])
118 118 # and bound magics by user (so they can access self):
119 119 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
120 120 callable(self.__class__.__dict__[fn])
121 121 magics = filter(class_magic,Magic.__dict__.keys()) + \
122 122 filter(inst_magic,self.__dict__.keys()) + \
123 123 filter(inst_bound_magic,self.__class__.__dict__.keys())
124 124 out = []
125 125 for fn in magics:
126 126 out.append(fn.replace('magic_','',1))
127 127 out.sort()
128 128 return out
129 129
130 130 def extract_input_slices(self,slices):
131 131 """Return as a string a set of input history slices.
132 132
133 133 The set of slices is given as a list of strings (like ['1','4:8','9'],
134 134 since this function is for use by magic functions which get their
135 135 arguments as strings.
136 136
137 137 Note that slices can be called with two notations:
138 138
139 139 N:M -> standard python form, means including items N...(M-1).
140 140
141 141 N-M -> include items N..M (closed endpoint)."""
142 142
143 143 cmds = []
144 144 for chunk in slices:
145 145 if ':' in chunk:
146 146 ini,fin = map(int,chunk.split(':'))
147 147 elif '-' in chunk:
148 148 ini,fin = map(int,chunk.split('-'))
149 149 fin += 1
150 150 else:
151 151 ini = int(chunk)
152 152 fin = ini+1
153 153 cmds.append(self.shell.input_hist[ini:fin])
154 154 return cmds
155 155
156 156 def _ofind(self,oname):
157 157 """Find an object in the available namespaces.
158 158
159 159 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
160 160
161 161 Has special code to detect magic functions.
162 162 """
163 163
164 164 oname = oname.strip()
165 165
166 166 # Namespaces to search in:
167 167 user_ns = self.shell.user_ns
168 168 internal_ns = self.shell.internal_ns
169 169 builtin_ns = __builtin__.__dict__
170 170 alias_ns = self.shell.alias_table
171 171
172 172 # Put them in a list. The order is important so that we find things in
173 173 # the same order that Python finds them.
174 174 namespaces = [ ('Interactive',user_ns),
175 175 ('IPython internal',internal_ns),
176 176 ('Python builtin',builtin_ns),
177 177 ('Alias',alias_ns),
178 178 ]
179 179
180 180 # initialize results to 'null'
181 181 found = 0; obj = None; ospace = None; ds = None;
182 182 ismagic = 0; isalias = 0
183 183
184 184 # Look for the given name by splitting it in parts. If the head is
185 185 # found, then we look for all the remaining parts as members, and only
186 186 # declare success if we can find them all.
187 187 oname_parts = oname.split('.')
188 188 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
189 189 for nsname,ns in namespaces:
190 190 try:
191 191 obj = ns[oname_head]
192 192 except KeyError:
193 193 continue
194 194 else:
195 195 for part in oname_rest:
196 196 try:
197 197 obj = getattr(obj,part)
198 198 except:
199 199 # Blanket except b/c some badly implemented objects
200 200 # allow __getattr__ to raise exceptions other than
201 201 # AttributeError, which then crashes IPython.
202 202 break
203 203 else:
204 204 # If we finish the for loop (no break), we got all members
205 205 found = 1
206 206 ospace = nsname
207 207 if ns == alias_ns:
208 208 isalias = 1
209 209 break # namespace loop
210 210
211 211 # Try to see if it's magic
212 212 if not found:
213 213 if oname.startswith(self.shell.ESC_MAGIC):
214 214 oname = oname[1:]
215 215 obj = getattr(self,'magic_'+oname,None)
216 216 if obj is not None:
217 217 found = 1
218 218 ospace = 'IPython internal'
219 219 ismagic = 1
220 220
221 221 # Last try: special-case some literals like '', [], {}, etc:
222 222 if not found and oname_head in ["''",'""','[]','{}','()']:
223 223 obj = eval(oname_head)
224 224 found = 1
225 225 ospace = 'Interactive'
226 226
227 227 return {'found':found, 'obj':obj, 'namespace':ospace,
228 228 'ismagic':ismagic, 'isalias':isalias}
229 229
230 230 def arg_err(self,func):
231 231 """Print docstring if incorrect arguments were passed"""
232 232 print 'Error in arguments:'
233 233 print OInspect.getdoc(func)
234 234
235 235 def format_latex(self,strng):
236 236 """Format a string for latex inclusion."""
237 237
238 238 # Characters that need to be escaped for latex:
239 239 escape_re = re.compile(r'(%|_|\$|#)',re.MULTILINE)
240 240 # Magic command names as headers:
241 241 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
242 242 re.MULTILINE)
243 243 # Magic commands
244 244 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
245 245 re.MULTILINE)
246 246 # Paragraph continue
247 247 par_re = re.compile(r'\\$',re.MULTILINE)
248 248
249 249 # The "\n" symbol
250 250 newline_re = re.compile(r'\\n')
251 251
252 252 # Now build the string for output:
253 strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
253 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
254 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
255 strng)
254 256 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
255 257 strng = par_re.sub(r'\\\\',strng)
256 258 strng = escape_re.sub(r'\\\1',strng)
257 259 strng = newline_re.sub(r'\\textbackslash{}n',strng)
258 260 return strng
259 261
260 262 def format_screen(self,strng):
261 263 """Format a string for screen printing.
262 264
263 265 This removes some latex-type format codes."""
264 266 # Paragraph continue
265 267 par_re = re.compile(r'\\$',re.MULTILINE)
266 268 strng = par_re.sub('',strng)
267 269 return strng
268 270
269 271 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
270 272 """Parse options passed to an argument string.
271 273
272 274 The interface is similar to that of getopt(), but it returns back a
273 275 Struct with the options as keys and the stripped argument string still
274 276 as a string.
275 277
276 278 arg_str is quoted as a true sys.argv vector by using shlex.split.
277 279 This allows us to easily expand variables, glob files, quote
278 280 arguments, etc.
279 281
280 282 Options:
281 283 -mode: default 'string'. If given as 'list', the argument string is
282 284 returned as a list (split on whitespace) instead of a string.
283 285
284 286 -list_all: put all option values in lists. Normally only options
285 287 appearing more than once are put in a list."""
286 288
287 289 # inject default options at the beginning of the input line
288 290 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
289 291 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
290 292
291 293 mode = kw.get('mode','string')
292 294 if mode not in ['string','list']:
293 295 raise ValueError,'incorrect mode given: %s' % mode
294 296 # Get options
295 297 list_all = kw.get('list_all',0)
296 298
297 299 # Check if we have more than one argument to warrant extra processing:
298 300 odict = {} # Dictionary with options
299 301 args = arg_str.split()
300 302 if len(args) >= 1:
301 303 # If the list of inputs only has 0 or 1 thing in it, there's no
302 304 # need to look for options
303 305 argv = shlex_split(arg_str)
304 306 # Do regular option processing
305 307 opts,args = getopt(argv,opt_str,*long_opts)
306 308 for o,a in opts:
307 309 if o.startswith('--'):
308 310 o = o[2:]
309 311 else:
310 312 o = o[1:]
311 313 try:
312 314 odict[o].append(a)
313 315 except AttributeError:
314 316 odict[o] = [odict[o],a]
315 317 except KeyError:
316 318 if list_all:
317 319 odict[o] = [a]
318 320 else:
319 321 odict[o] = a
320 322
321 323 # Prepare opts,args for return
322 324 opts = Struct(odict)
323 325 if mode == 'string':
324 326 args = ' '.join(args)
325 327
326 328 return opts,args
327 329
328 330 #......................................................................
329 331 # And now the actual magic functions
330 332
331 333 # Functions for IPython shell work (vars,funcs, config, etc)
332 334 def magic_lsmagic(self, parameter_s = ''):
333 335 """List currently available magic functions."""
334 336 mesc = self.shell.ESC_MAGIC
335 337 print 'Available magic functions:\n'+mesc+\
336 338 (' '+mesc).join(self.lsmagic())
337 339 print '\n' + Magic.auto_status[self.shell.rc.automagic]
338 340 return None
339 341
340 342 def magic_magic(self, parameter_s = ''):
341 343 """Print information about the magic function system."""
342 344
343 345 mode = ''
344 346 try:
345 347 if parameter_s.split()[0] == '-latex':
346 348 mode = 'latex'
347 349 except:
348 350 pass
349 351
350 352 magic_docs = []
351 353 for fname in self.lsmagic():
352 354 mname = 'magic_' + fname
353 355 for space in (Magic,self,self.__class__):
354 356 try:
355 357 fn = space.__dict__[mname]
356 358 except KeyError:
357 359 pass
358 360 else:
359 361 break
360 362 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
361 363 fname,fn.__doc__))
362 364 magic_docs = ''.join(magic_docs)
363 365
364 366 if mode == 'latex':
365 367 print self.format_latex(magic_docs)
366 368 return
367 369 else:
368 370 magic_docs = self.format_screen(magic_docs)
369 371
370 372 outmsg = """
371 373 IPython's 'magic' functions
372 374 ===========================
373 375
374 376 The magic function system provides a series of functions which allow you to
375 377 control the behavior of IPython itself, plus a lot of system-type
376 378 features. All these functions are prefixed with a % character, but parameters
377 379 are given without parentheses or quotes.
378 380
379 381 NOTE: If you have 'automagic' enabled (via the command line option or with the
380 382 %automagic function), you don't need to type in the % explicitly. By default,
381 383 IPython ships with automagic on, so you should only rarely need the % escape.
382 384
383 385 Example: typing '%cd mydir' (without the quotes) changes you working directory
384 386 to 'mydir', if it exists.
385 387
386 388 You can define your own magic functions to extend the system. See the supplied
387 389 ipythonrc and example-magic.py files for details (in your ipython
388 390 configuration directory, typically $HOME/.ipython/).
389 391
390 392 You can also define your own aliased names for magic functions. In your
391 393 ipythonrc file, placing a line like:
392 394
393 395 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
394 396
395 397 will define %pf as a new name for %profile.
396 398
397 399 You can also call magics in code using the ipmagic() function, which IPython
398 400 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
399 401
400 402 For a list of the available magic functions, use %lsmagic. For a description
401 403 of any of them, type %magic_name?, e.g. '%cd?'.
402 404
403 405 Currently the magic system has the following functions:\n"""
404 406
405 407 mesc = self.shell.ESC_MAGIC
406 408 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
407 409 "\n\n%s%s\n\n%s" % (outmsg,
408 410 magic_docs,mesc,mesc,
409 411 (' '+mesc).join(self.lsmagic()),
410 412 Magic.auto_status[self.shell.rc.automagic] ) )
411 413
412 414 page(outmsg,screen_lines=self.shell.rc.screen_length)
413 415
414 416 def magic_automagic(self, parameter_s = ''):
415 417 """Make magic functions callable without having to type the initial %.
416 418
417 419 Toggles on/off (when off, you must call it as %automagic, of
418 420 course). Note that magic functions have lowest priority, so if there's
419 421 a variable whose name collides with that of a magic fn, automagic
420 422 won't work for that function (you get the variable instead). However,
421 423 if you delete the variable (del var), the previously shadowed magic
422 424 function becomes visible to automagic again."""
423 425
424 426 rc = self.shell.rc
425 427 rc.automagic = not rc.automagic
426 428 print '\n' + Magic.auto_status[rc.automagic]
427 429
428 430 def magic_autocall(self, parameter_s = ''):
429 431 """Make functions callable without having to type parentheses.
430 432
431 433 Usage:
432 434
433 435 %autocall [mode]
434 436
435 437 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
436 438 value is toggled on and off (remembering the previous state)."""
437 439
438 440 rc = self.shell.rc
439 441
440 442 if parameter_s:
441 443 arg = int(parameter_s)
442 444 else:
443 445 arg = 'toggle'
444 446
445 447 if not arg in (0,1,2,'toggle'):
446 448 error('Valid modes: (0->Off, 1->Smart, 2->Full')
447 449 return
448 450
449 451 if arg in (0,1,2):
450 452 rc.autocall = arg
451 453 else: # toggle
452 454 if rc.autocall:
453 455 self._magic_state.autocall_save = rc.autocall
454 456 rc.autocall = 0
455 457 else:
456 458 try:
457 459 rc.autocall = self._magic_state.autocall_save
458 460 except AttributeError:
459 461 rc.autocall = self._magic_state.autocall_save = 1
460 462
461 463 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
462 464
463 465 def magic_autoindent(self, parameter_s = ''):
464 466 """Toggle autoindent on/off (if available)."""
465 467
466 468 self.shell.set_autoindent()
467 469 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
468 470
469 471 def magic_system_verbose(self, parameter_s = ''):
470 472 """Toggle verbose printing of system calls on/off."""
471 473
472 474 self.shell.rc_set_toggle('system_verbose')
473 475 print "System verbose printing is:",\
474 476 ['OFF','ON'][self.shell.rc.system_verbose]
475 477
476 478 def magic_history(self, parameter_s = ''):
477 479 """Print input history (_i<n> variables), with most recent last.
478 480
479 481 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
480 482 %history [-n] n -> print at most n inputs\\
481 483 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
482 484
483 485 Each input's number <n> is shown, and is accessible as the
484 486 automatically generated variable _i<n>. Multi-line statements are
485 487 printed starting at a new line for easy copy/paste.
486 488
487 489 If option -n is used, input numbers are not printed. This is useful if
488 490 you want to get a printout of many lines which can be directly pasted
489 491 into a text editor.
490 492
491 493 This feature is only available if numbered prompts are in use."""
492 494
493 495 shell = self.shell
494 496 if not shell.outputcache.do_full_cache:
495 497 print 'This feature is only available if numbered prompts are in use.'
496 498 return
497 499 opts,args = self.parse_options(parameter_s,'n',mode='list')
498 500
499 501 input_hist = shell.input_hist
500 502 default_length = 40
501 503 if len(args) == 0:
502 504 final = len(input_hist)
503 505 init = max(1,final-default_length)
504 506 elif len(args) == 1:
505 507 final = len(input_hist)
506 508 init = max(1,final-int(args[0]))
507 509 elif len(args) == 2:
508 510 init,final = map(int,args)
509 511 else:
510 512 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
511 513 print self.magic_hist.__doc__
512 514 return
513 515 width = len(str(final))
514 516 line_sep = ['','\n']
515 517 print_nums = not opts.has_key('n')
516 518 for in_num in range(init,final):
517 519 inline = input_hist[in_num]
518 520 multiline = int(inline.count('\n') > 1)
519 521 if print_nums:
520 522 print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
521 523 print inline,
522 524
523 525 def magic_hist(self, parameter_s=''):
524 526 """Alternate name for %history."""
525 527 return self.magic_history(parameter_s)
526 528
527 529 def magic_p(self, parameter_s=''):
528 530 """Just a short alias for Python's 'print'."""
529 531 exec 'print ' + parameter_s in self.shell.user_ns
530 532
531 533 def magic_r(self, parameter_s=''):
532 534 """Repeat previous input.
533 535
534 536 If given an argument, repeats the previous command which starts with
535 537 the same string, otherwise it just repeats the previous input.
536 538
537 539 Shell escaped commands (with ! as first character) are not recognized
538 540 by this system, only pure python code and magic commands.
539 541 """
540 542
541 543 start = parameter_s.strip()
542 544 esc_magic = self.shell.ESC_MAGIC
543 545 # Identify magic commands even if automagic is on (which means
544 546 # the in-memory version is different from that typed by the user).
545 547 if self.shell.rc.automagic:
546 548 start_magic = esc_magic+start
547 549 else:
548 550 start_magic = start
549 551 # Look through the input history in reverse
550 552 for n in range(len(self.shell.input_hist)-2,0,-1):
551 553 input = self.shell.input_hist[n]
552 554 # skip plain 'r' lines so we don't recurse to infinity
553 555 if input != 'ipmagic("r")\n' and \
554 556 (input.startswith(start) or input.startswith(start_magic)):
555 557 #print 'match',`input` # dbg
556 558 print 'Executing:',input,
557 559 self.shell.runlines(input)
558 560 return
559 561 print 'No previous input matching `%s` found.' % start
560 562
561 563 def magic_page(self, parameter_s=''):
562 564 """Pretty print the object and display it through a pager.
563 565
564 566 If no parameter is given, use _ (last output)."""
565 567 # After a function contributed by Olivier Aubert, slightly modified.
566 568
567 569 oname = parameter_s and parameter_s or '_'
568 570 info = self._ofind(oname)
569 571 if info['found']:
570 572 page(pformat(info['obj']))
571 573 else:
572 574 print 'Object `%s` not found' % oname
573 575
574 576 def magic_profile(self, parameter_s=''):
575 577 """Print your currently active IPyhton profile."""
576 578 if self.shell.rc.profile:
577 579 printpl('Current IPython profile: $self.shell.rc.profile.')
578 580 else:
579 581 print 'No profile active.'
580 582
581 583 def _inspect(self,meth,oname,**kw):
582 584 """Generic interface to the inspector system.
583 585
584 586 This function is meant to be called by pdef, pdoc & friends."""
585 587
586 588 oname = oname.strip()
587 589 info = Struct(self._ofind(oname))
588 590 if info.found:
589 591 pmethod = getattr(self.shell.inspector,meth)
590 592 formatter = info.ismagic and self.format_screen or None
591 593 if meth == 'pdoc':
592 594 pmethod(info.obj,oname,formatter)
593 595 elif meth == 'pinfo':
594 596 pmethod(info.obj,oname,formatter,info,**kw)
595 597 else:
596 598 pmethod(info.obj,oname)
597 599 else:
598 600 print 'Object `%s` not found.' % oname
599 601 return 'not found' # so callers can take other action
600 602
601 603 def magic_pdef(self, parameter_s=''):
602 604 """Print the definition header for any callable object.
603 605
604 606 If the object is a class, print the constructor information."""
605 607 self._inspect('pdef',parameter_s)
606 608
607 609 def magic_pdoc(self, parameter_s=''):
608 610 """Print the docstring for an object.
609 611
610 612 If the given object is a class, it will print both the class and the
611 613 constructor docstrings."""
612 614 self._inspect('pdoc',parameter_s)
613 615
614 616 def magic_psource(self, parameter_s=''):
615 617 """Print (or run through pager) the source code for an object."""
616 618 self._inspect('psource',parameter_s)
617 619
618 620 def magic_pfile(self, parameter_s=''):
619 621 """Print (or run through pager) the file where an object is defined.
620 622
621 623 The file opens at the line where the object definition begins. IPython
622 624 will honor the environment variable PAGER if set, and otherwise will
623 625 do its best to print the file in a convenient form.
624 626
625 627 If the given argument is not an object currently defined, IPython will
626 628 try to interpret it as a filename (automatically adding a .py extension
627 629 if needed). You can thus use %pfile as a syntax highlighting code
628 630 viewer."""
629 631
630 632 # first interpret argument as an object name
631 633 out = self._inspect('pfile',parameter_s)
632 634 # if not, try the input as a filename
633 635 if out == 'not found':
634 636 try:
635 637 filename = get_py_filename(parameter_s)
636 638 except IOError,msg:
637 639 print msg
638 640 return
639 641 page(self.shell.inspector.format(file(filename).read()))
640 642
641 643 def magic_pinfo(self, parameter_s=''):
642 644 """Provide detailed information about an object.
643 645
644 646 '%pinfo object' is just a synonym for object? or ?object."""
645 647
646 648 #print 'pinfo par: <%s>' % parameter_s # dbg
647 649
648 650 # detail_level: 0 -> obj? , 1 -> obj??
649 651 detail_level = 0
650 652 # We need to detect if we got called as 'pinfo pinfo foo', which can
651 653 # happen if the user types 'pinfo foo?' at the cmd line.
652 654 pinfo,qmark1,oname,qmark2 = \
653 655 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
654 656 if pinfo or qmark1 or qmark2:
655 657 detail_level = 1
656 658 if "*" in oname:
657 659 self.magic_psearch(oname)
658 660 else:
659 661 self._inspect('pinfo',oname,detail_level=detail_level)
660 662
661 663 def magic_psearch(self, parameter_s=''):
662 664 """Search for object in namespaces by wildcard.
663 665
664 666 %psearch [options] PATTERN [OBJECT TYPE]
665 667
666 668 Note: ? can be used as a synonym for %psearch, at the beginning or at
667 669 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
668 670 rest of the command line must be unchanged (options come first), so
669 671 for example the following forms are equivalent
670 672
671 673 %psearch -i a* function
672 674 -i a* function?
673 675 ?-i a* function
674 676
675 677 Arguments:
676 678
677 679 PATTERN
678 680
679 681 where PATTERN is a string containing * as a wildcard similar to its
680 682 use in a shell. The pattern is matched in all namespaces on the
681 683 search path. By default objects starting with a single _ are not
682 684 matched, many IPython generated objects have a single
683 685 underscore. The default is case insensitive matching. Matching is
684 686 also done on the attributes of objects and not only on the objects
685 687 in a module.
686 688
687 689 [OBJECT TYPE]
688 690
689 691 Is the name of a python type from the types module. The name is
690 692 given in lowercase without the ending type, ex. StringType is
691 693 written string. By adding a type here only objects matching the
692 694 given type are matched. Using all here makes the pattern match all
693 695 types (this is the default).
694 696
695 697 Options:
696 698
697 699 -a: makes the pattern match even objects whose names start with a
698 700 single underscore. These names are normally ommitted from the
699 701 search.
700 702
701 703 -i/-c: make the pattern case insensitive/sensitive. If neither of
702 704 these options is given, the default is read from your ipythonrc
703 705 file. The option name which sets this value is
704 706 'wildcards_case_sensitive'. If this option is not specified in your
705 707 ipythonrc file, IPython's internal default is to do a case sensitive
706 708 search.
707 709
708 710 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
709 711 specifiy can be searched in any of the following namespaces:
710 712 'builtin', 'user', 'user_global','internal', 'alias', where
711 713 'builtin' and 'user' are the search defaults. Note that you should
712 714 not use quotes when specifying namespaces.
713 715
714 716 'Builtin' contains the python module builtin, 'user' contains all
715 717 user data, 'alias' only contain the shell aliases and no python
716 718 objects, 'internal' contains objects used by IPython. The
717 719 'user_global' namespace is only used by embedded IPython instances,
718 720 and it contains module-level globals. You can add namespaces to the
719 721 search with -s or exclude them with -e (these options can be given
720 722 more than once).
721 723
722 724 Examples:
723 725
724 726 %psearch a* -> objects beginning with an a
725 727 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
726 728 %psearch a* function -> all functions beginning with an a
727 729 %psearch re.e* -> objects beginning with an e in module re
728 730 %psearch r*.e* -> objects that start with e in modules starting in r
729 731 %psearch r*.* string -> all strings in modules beginning with r
730 732
731 733 Case sensitve search:
732 734
733 735 %psearch -c a* list all object beginning with lower case a
734 736
735 737 Show objects beginning with a single _:
736 738
737 739 %psearch -a _* list objects beginning with a single underscore"""
738 740
739 741 # default namespaces to be searched
740 742 def_search = ['user','builtin']
741 743
742 744 # Process options/args
743 745 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
744 746 opt = opts.get
745 747 shell = self.shell
746 748 psearch = shell.inspector.psearch
747 749
748 750 # select case options
749 751 if opts.has_key('i'):
750 752 ignore_case = True
751 753 elif opts.has_key('c'):
752 754 ignore_case = False
753 755 else:
754 756 ignore_case = not shell.rc.wildcards_case_sensitive
755 757
756 758 # Build list of namespaces to search from user options
757 759 def_search.extend(opt('s',[]))
758 760 ns_exclude = ns_exclude=opt('e',[])
759 761 ns_search = [nm for nm in def_search if nm not in ns_exclude]
760 762
761 763 # Call the actual search
762 764 try:
763 765 psearch(args,shell.ns_table,ns_search,
764 766 show_all=opt('a'),ignore_case=ignore_case)
765 767 except:
766 768 shell.showtraceback()
767 769
768 770 def magic_who_ls(self, parameter_s=''):
769 771 """Return a sorted list of all interactive variables.
770 772
771 773 If arguments are given, only variables of types matching these
772 774 arguments are returned."""
773 775
774 776 user_ns = self.shell.user_ns
775 777 internal_ns = self.shell.internal_ns
776 778 user_config_ns = self.shell.user_config_ns
777 779 out = []
778 780 typelist = parameter_s.split()
779 781
780 782 for i in user_ns:
781 783 if not (i.startswith('_') or i.startswith('_i')) \
782 784 and not (i in internal_ns or i in user_config_ns):
783 785 if typelist:
784 786 if type(user_ns[i]).__name__ in typelist:
785 787 out.append(i)
786 788 else:
787 789 out.append(i)
788 790 out.sort()
789 791 return out
790 792
791 793 def magic_who(self, parameter_s=''):
792 794 """Print all interactive variables, with some minimal formatting.
793 795
794 796 If any arguments are given, only variables whose type matches one of
795 797 these are printed. For example:
796 798
797 799 %who function str
798 800
799 801 will only list functions and strings, excluding all other types of
800 802 variables. To find the proper type names, simply use type(var) at a
801 803 command line to see how python prints type names. For example:
802 804
803 805 In [1]: type('hello')\\
804 806 Out[1]: <type 'str'>
805 807
806 808 indicates that the type name for strings is 'str'.
807 809
808 810 %who always excludes executed names loaded through your configuration
809 811 file and things which are internal to IPython.
810 812
811 813 This is deliberate, as typically you may load many modules and the
812 814 purpose of %who is to show you only what you've manually defined."""
813 815
814 816 varlist = self.magic_who_ls(parameter_s)
815 817 if not varlist:
816 818 print 'Interactive namespace is empty.'
817 819 return
818 820
819 821 # if we have variables, move on...
820 822
821 823 # stupid flushing problem: when prompts have no separators, stdout is
822 824 # getting lost. I'm starting to think this is a python bug. I'm having
823 825 # to force a flush with a print because even a sys.stdout.flush
824 826 # doesn't seem to do anything!
825 827
826 828 count = 0
827 829 for i in varlist:
828 830 print i+'\t',
829 831 count += 1
830 832 if count > 8:
831 833 count = 0
832 834 print
833 835 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
834 836
835 837 print # well, this does force a flush at the expense of an extra \n
836 838
837 839 def magic_whos(self, parameter_s=''):
838 840 """Like %who, but gives some extra information about each variable.
839 841
840 842 The same type filtering of %who can be applied here.
841 843
842 844 For all variables, the type is printed. Additionally it prints:
843 845
844 846 - For {},[],(): their length.
845 847
846 848 - For Numeric arrays, a summary with shape, number of elements,
847 849 typecode and size in memory.
848 850
849 851 - Everything else: a string representation, snipping their middle if
850 852 too long."""
851 853
852 854 varnames = self.magic_who_ls(parameter_s)
853 855 if not varnames:
854 856 print 'Interactive namespace is empty.'
855 857 return
856 858
857 859 # if we have variables, move on...
858 860
859 861 # for these types, show len() instead of data:
860 862 seq_types = [types.DictType,types.ListType,types.TupleType]
861 863
862 864 # for Numeric arrays, display summary info
863 865 try:
864 866 import Numeric
865 867 except ImportError:
866 868 array_type = None
867 869 else:
868 870 array_type = Numeric.ArrayType.__name__
869 871
870 872 # Find all variable names and types so we can figure out column sizes
871 873 get_vars = lambda i: self.shell.user_ns[i]
872 874 type_name = lambda v: type(v).__name__
873 875 varlist = map(get_vars,varnames)
874 876
875 877 typelist = []
876 878 for vv in varlist:
877 879 tt = type_name(vv)
878 880 if tt=='instance':
879 881 typelist.append(str(vv.__class__))
880 882 else:
881 883 typelist.append(tt)
882 884
883 885 # column labels and # of spaces as separator
884 886 varlabel = 'Variable'
885 887 typelabel = 'Type'
886 888 datalabel = 'Data/Info'
887 889 colsep = 3
888 890 # variable format strings
889 891 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
890 892 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
891 893 aformat = "%s: %s elems, type `%s`, %s bytes"
892 894 # find the size of the columns to format the output nicely
893 895 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
894 896 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
895 897 # table header
896 898 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
897 899 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
898 900 # and the table itself
899 901 kb = 1024
900 902 Mb = 1048576 # kb**2
901 903 for vname,var,vtype in zip(varnames,varlist,typelist):
902 904 print itpl(vformat),
903 905 if vtype in seq_types:
904 906 print len(var)
905 907 elif vtype==array_type:
906 908 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
907 909 vsize = Numeric.size(var)
908 910 vbytes = vsize*var.itemsize()
909 911 if vbytes < 100000:
910 912 print aformat % (vshape,vsize,var.typecode(),vbytes)
911 913 else:
912 914 print aformat % (vshape,vsize,var.typecode(),vbytes),
913 915 if vbytes < Mb:
914 916 print '(%s kb)' % (vbytes/kb,)
915 917 else:
916 918 print '(%s Mb)' % (vbytes/Mb,)
917 919 else:
918 920 vstr = str(var).replace('\n','\\n')
919 921 if len(vstr) < 50:
920 922 print vstr
921 923 else:
922 924 printpl(vfmt_short)
923 925
924 926 def magic_reset(self, parameter_s=''):
925 927 """Resets the namespace by removing all names defined by the user.
926 928
927 929 Input/Output history are left around in case you need them."""
928 930
929 931 ans = raw_input(
930 932 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
931 933 if not ans.lower() == 'y':
932 934 print 'Nothing done.'
933 935 return
934 936 user_ns = self.shell.user_ns
935 937 for i in self.magic_who_ls():
936 938 del(user_ns[i])
937 939
938 940 def magic_config(self,parameter_s=''):
939 941 """Show IPython's internal configuration."""
940 942
941 943 page('Current configuration structure:\n'+
942 944 pformat(self.shell.rc.dict()))
943 945
944 946 def magic_logstart(self,parameter_s=''):
945 947 """Start logging anywhere in a session.
946 948
947 949 %logstart [-o|-t] [log_name [log_mode]]
948 950
949 951 If no name is given, it defaults to a file named 'ipython_log.py' in your
950 952 current directory, in 'rotate' mode (see below).
951 953
952 954 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
953 955 history up to that point and then continues logging.
954 956
955 957 %logstart takes a second optional parameter: logging mode. This can be one
956 958 of (note that the modes are given unquoted):\\
957 959 append: well, that says it.\\
958 960 backup: rename (if exists) to name~ and start name.\\
959 961 global: single logfile in your home dir, appended to.\\
960 962 over : overwrite existing log.\\
961 963 rotate: create rotating logs name.1~, name.2~, etc.
962 964
963 965 Options:
964 966
965 967 -o: log also IPython's output. In this mode, all commands which
966 968 generate an Out[NN] prompt are recorded to the logfile, right after
967 969 their corresponding input line. The output lines are always
968 970 prepended with a '#[Out]# ' marker, so that the log remains valid
969 971 Python code.
970 972
971 973 Since this marker is always the same, filtering only the output from
972 974 a log is very easy, using for example a simple awk call:
973 975
974 976 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
975 977
976 978 -t: put timestamps before each input line logged (these are put in
977 979 comments)."""
978 980
979 981 opts,par = self.parse_options(parameter_s,'ot')
980 982 log_output = 'o' in opts
981 983 timestamp = 't' in opts
982 984
983 985 rc = self.shell.rc
984 986 logger = self.shell.logger
985 987
986 988 # if no args are given, the defaults set in the logger constructor by
987 989 # ipytohn remain valid
988 990 if par:
989 991 try:
990 992 logfname,logmode = par.split()
991 993 except:
992 994 logfname = par
993 995 logmode = 'backup'
994 996 else:
995 997 logfname = logger.logfname
996 998 logmode = logger.logmode
997 999 # put logfname into rc struct as if it had been called on the command
998 1000 # line, so it ends up saved in the log header Save it in case we need
999 1001 # to restore it...
1000 1002 old_logfile = rc.opts.get('logfile','')
1001 1003 if logfname:
1002 1004 logfname = os.path.expanduser(logfname)
1003 1005 rc.opts.logfile = logfname
1004 1006 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
1005 1007 try:
1006 1008 started = logger.logstart(logfname,loghead,logmode,
1007 1009 log_output,timestamp)
1008 1010 except:
1009 1011 rc.opts.logfile = old_logfile
1010 1012 warn("Couldn't start log: %s" % sys.exc_info()[1])
1011 1013 else:
1012 1014 # log input history up to this point, optionally interleaving
1013 1015 # output if requested
1014 1016
1015 1017 if timestamp:
1016 1018 # disable timestamping for the previous history, since we've
1017 1019 # lost those already (no time machine here).
1018 1020 logger.timestamp = False
1019 1021 if log_output:
1020 1022 log_write = logger.log_write
1021 1023 input_hist = self.shell.input_hist
1022 1024 output_hist = self.shell.output_hist
1023 1025 for n in range(1,len(input_hist)-1):
1024 1026 log_write(input_hist[n].rstrip())
1025 1027 if n in output_hist:
1026 1028 log_write(repr(output_hist[n]),'output')
1027 1029 else:
1028 1030 logger.log_write(self.shell.input_hist[1:])
1029 1031 if timestamp:
1030 1032 # re-enable timestamping
1031 1033 logger.timestamp = True
1032 1034
1033 1035 print ('Activating auto-logging. '
1034 1036 'Current session state plus future input saved.')
1035 1037 logger.logstate()
1036 1038
1037 1039 def magic_logoff(self,parameter_s=''):
1038 1040 """Temporarily stop logging.
1039 1041
1040 1042 You must have previously started logging."""
1041 1043 self.shell.logger.switch_log(0)
1042 1044
1043 1045 def magic_logon(self,parameter_s=''):
1044 1046 """Restart logging.
1045 1047
1046 1048 This function is for restarting logging which you've temporarily
1047 1049 stopped with %logoff. For starting logging for the first time, you
1048 1050 must use the %logstart function, which allows you to specify an
1049 1051 optional log filename."""
1050 1052
1051 1053 self.shell.logger.switch_log(1)
1052 1054
1053 1055 def magic_logstate(self,parameter_s=''):
1054 1056 """Print the status of the logging system."""
1055 1057
1056 1058 self.shell.logger.logstate()
1057 1059
1058 1060 def magic_pdb(self, parameter_s=''):
1059 1061 """Control the calling of the pdb interactive debugger.
1060 1062
1061 1063 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1062 1064 argument it works as a toggle.
1063 1065
1064 1066 When an exception is triggered, IPython can optionally call the
1065 1067 interactive pdb debugger after the traceback printout. %pdb toggles
1066 1068 this feature on and off."""
1067 1069
1068 1070 par = parameter_s.strip().lower()
1069 1071
1070 1072 if par:
1071 1073 try:
1072 1074 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1073 1075 except KeyError:
1074 1076 print ('Incorrect argument. Use on/1, off/0, '
1075 1077 'or nothing for a toggle.')
1076 1078 return
1077 1079 else:
1078 1080 # toggle
1079 1081 new_pdb = not self.shell.InteractiveTB.call_pdb
1080 1082
1081 1083 # set on the shell
1082 1084 self.shell.call_pdb = new_pdb
1083 1085 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1084 1086
1085 1087 def magic_prun(self, parameter_s ='',user_mode=1,
1086 1088 opts=None,arg_lst=None,prog_ns=None):
1087 1089
1088 1090 """Run a statement through the python code profiler.
1089 1091
1090 1092 Usage:\\
1091 1093 %prun [options] statement
1092 1094
1093 1095 The given statement (which doesn't require quote marks) is run via the
1094 1096 python profiler in a manner similar to the profile.run() function.
1095 1097 Namespaces are internally managed to work correctly; profile.run
1096 1098 cannot be used in IPython because it makes certain assumptions about
1097 1099 namespaces which do not hold under IPython.
1098 1100
1099 1101 Options:
1100 1102
1101 1103 -l <limit>: you can place restrictions on what or how much of the
1102 1104 profile gets printed. The limit value can be:
1103 1105
1104 1106 * A string: only information for function names containing this string
1105 1107 is printed.
1106 1108
1107 1109 * An integer: only these many lines are printed.
1108 1110
1109 1111 * A float (between 0 and 1): this fraction of the report is printed
1110 1112 (for example, use a limit of 0.4 to see the topmost 40% only).
1111 1113
1112 1114 You can combine several limits with repeated use of the option. For
1113 1115 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1114 1116 information about class constructors.
1115 1117
1116 1118 -r: return the pstats.Stats object generated by the profiling. This
1117 1119 object has all the information about the profile in it, and you can
1118 1120 later use it for further analysis or in other functions.
1119 1121
1120 1122 Since magic functions have a particular form of calling which prevents
1121 1123 you from writing something like:\\
1122 1124 In [1]: p = %prun -r print 4 # invalid!\\
1123 1125 you must instead use IPython's automatic variables to assign this:\\
1124 1126 In [1]: %prun -r print 4 \\
1125 1127 Out[1]: <pstats.Stats instance at 0x8222cec>\\
1126 1128 In [2]: stats = _
1127 1129
1128 1130 If you really need to assign this value via an explicit function call,
1129 1131 you can always tap directly into the true name of the magic function
1130 1132 by using the ipmagic function (which IPython automatically adds to the
1131 1133 builtins):\\
1132 1134 In [3]: stats = ipmagic('prun','-r print 4')
1133 1135
1134 1136 You can type ipmagic? for more details on ipmagic.
1135 1137
1136 1138 -s <key>: sort profile by given key. You can provide more than one key
1137 1139 by using the option several times: '-s key1 -s key2 -s key3...'. The
1138 1140 default sorting key is 'time'.
1139 1141
1140 1142 The following is copied verbatim from the profile documentation
1141 1143 referenced below:
1142 1144
1143 1145 When more than one key is provided, additional keys are used as
1144 1146 secondary criteria when the there is equality in all keys selected
1145 1147 before them.
1146 1148
1147 1149 Abbreviations can be used for any key names, as long as the
1148 1150 abbreviation is unambiguous. The following are the keys currently
1149 1151 defined:
1150 1152
1151 1153 Valid Arg Meaning\\
1152 1154 "calls" call count\\
1153 1155 "cumulative" cumulative time\\
1154 1156 "file" file name\\
1155 1157 "module" file name\\
1156 1158 "pcalls" primitive call count\\
1157 1159 "line" line number\\
1158 1160 "name" function name\\
1159 1161 "nfl" name/file/line\\
1160 1162 "stdname" standard name\\
1161 1163 "time" internal time
1162 1164
1163 1165 Note that all sorts on statistics are in descending order (placing
1164 1166 most time consuming items first), where as name, file, and line number
1165 1167 searches are in ascending order (i.e., alphabetical). The subtle
1166 1168 distinction between "nfl" and "stdname" is that the standard name is a
1167 1169 sort of the name as printed, which means that the embedded line
1168 1170 numbers get compared in an odd way. For example, lines 3, 20, and 40
1169 1171 would (if the file names were the same) appear in the string order
1170 1172 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1171 1173 line numbers. In fact, sort_stats("nfl") is the same as
1172 1174 sort_stats("name", "file", "line").
1173 1175
1174 1176 -T <filename>: save profile results as shown on screen to a text
1175 1177 file. The profile is still shown on screen.
1176 1178
1177 1179 -D <filename>: save (via dump_stats) profile statistics to given
1178 1180 filename. This data is in a format understod by the pstats module, and
1179 1181 is generated by a call to the dump_stats() method of profile
1180 1182 objects. The profile is still shown on screen.
1181 1183
1182 1184 If you want to run complete programs under the profiler's control, use
1183 1185 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1184 1186 contains profiler specific options as described here.
1185 1187
1186 1188 You can read the complete documentation for the profile module with:\\
1187 1189 In [1]: import profile; profile.help() """
1188 1190
1189 1191 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1190 1192 # protect user quote marks
1191 1193 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1192 1194
1193 1195 if user_mode: # regular user call
1194 1196 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1195 1197 list_all=1)
1196 1198 namespace = self.shell.user_ns
1197 1199 else: # called to run a program by %run -p
1198 1200 try:
1199 1201 filename = get_py_filename(arg_lst[0])
1200 1202 except IOError,msg:
1201 1203 error(msg)
1202 1204 return
1203 1205
1204 1206 arg_str = 'execfile(filename,prog_ns)'
1205 1207 namespace = locals()
1206 1208
1207 1209 opts.merge(opts_def)
1208 1210
1209 1211 prof = profile.Profile()
1210 1212 try:
1211 1213 prof = prof.runctx(arg_str,namespace,namespace)
1212 1214 sys_exit = ''
1213 1215 except SystemExit:
1214 1216 sys_exit = """*** SystemExit exception caught in code being profiled."""
1215 1217
1216 1218 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1217 1219
1218 1220 lims = opts.l
1219 1221 if lims:
1220 1222 lims = [] # rebuild lims with ints/floats/strings
1221 1223 for lim in opts.l:
1222 1224 try:
1223 1225 lims.append(int(lim))
1224 1226 except ValueError:
1225 1227 try:
1226 1228 lims.append(float(lim))
1227 1229 except ValueError:
1228 1230 lims.append(lim)
1229 1231
1230 1232 # trap output
1231 1233 sys_stdout = sys.stdout
1232 1234 stdout_trap = StringIO()
1233 1235 try:
1234 1236 sys.stdout = stdout_trap
1235 1237 stats.print_stats(*lims)
1236 1238 finally:
1237 1239 sys.stdout = sys_stdout
1238 1240 output = stdout_trap.getvalue()
1239 1241 output = output.rstrip()
1240 1242
1241 1243 page(output,screen_lines=self.shell.rc.screen_length)
1242 1244 print sys_exit,
1243 1245
1244 1246 dump_file = opts.D[0]
1245 1247 text_file = opts.T[0]
1246 1248 if dump_file:
1247 1249 prof.dump_stats(dump_file)
1248 1250 print '\n*** Profile stats marshalled to file',\
1249 1251 `dump_file`+'.',sys_exit
1250 1252 if text_file:
1251 1253 file(text_file,'w').write(output)
1252 1254 print '\n*** Profile printout saved to text file',\
1253 1255 `text_file`+'.',sys_exit
1254 1256
1255 1257 if opts.has_key('r'):
1256 1258 return stats
1257 1259 else:
1258 1260 return None
1259 1261
1260 1262 def magic_run(self, parameter_s ='',runner=None):
1261 1263 """Run the named file inside IPython as a program.
1262 1264
1263 1265 Usage:\\
1264 1266 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1265 1267
1266 1268 Parameters after the filename are passed as command-line arguments to
1267 1269 the program (put in sys.argv). Then, control returns to IPython's
1268 1270 prompt.
1269 1271
1270 1272 This is similar to running at a system prompt:\\
1271 1273 $ python file args\\
1272 1274 but with the advantage of giving you IPython's tracebacks, and of
1273 1275 loading all variables into your interactive namespace for further use
1274 1276 (unless -p is used, see below).
1275 1277
1276 1278 The file is executed in a namespace initially consisting only of
1277 1279 __name__=='__main__' and sys.argv constructed as indicated. It thus
1278 1280 sees its environment as if it were being run as a stand-alone
1279 1281 program. But after execution, the IPython interactive namespace gets
1280 1282 updated with all variables defined in the program (except for __name__
1281 1283 and sys.argv). This allows for very convenient loading of code for
1282 1284 interactive work, while giving each program a 'clean sheet' to run in.
1283 1285
1284 1286 Options:
1285 1287
1286 1288 -n: __name__ is NOT set to '__main__', but to the running file's name
1287 1289 without extension (as python does under import). This allows running
1288 1290 scripts and reloading the definitions in them without calling code
1289 1291 protected by an ' if __name__ == "__main__" ' clause.
1290 1292
1291 1293 -i: run the file in IPython's namespace instead of an empty one. This
1292 1294 is useful if you are experimenting with code written in a text editor
1293 1295 which depends on variables defined interactively.
1294 1296
1295 1297 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1296 1298 being run. This is particularly useful if IPython is being used to
1297 1299 run unittests, which always exit with a sys.exit() call. In such
1298 1300 cases you are interested in the output of the test results, not in
1299 1301 seeing a traceback of the unittest module.
1300 1302
1301 1303 -t: print timing information at the end of the run. IPython will give
1302 1304 you an estimated CPU time consumption for your script, which under
1303 1305 Unix uses the resource module to avoid the wraparound problems of
1304 1306 time.clock(). Under Unix, an estimate of time spent on system tasks
1305 1307 is also given (for Windows platforms this is reported as 0.0).
1306 1308
1307 1309 If -t is given, an additional -N<N> option can be given, where <N>
1308 1310 must be an integer indicating how many times you want the script to
1309 1311 run. The final timing report will include total and per run results.
1310 1312
1311 1313 For example (testing the script uniq_stable.py):
1312 1314
1313 1315 In [1]: run -t uniq_stable
1314 1316
1315 1317 IPython CPU timings (estimated):\\
1316 1318 User : 0.19597 s.\\
1317 1319 System: 0.0 s.\\
1318 1320
1319 1321 In [2]: run -t -N5 uniq_stable
1320 1322
1321 1323 IPython CPU timings (estimated):\\
1322 1324 Total runs performed: 5\\
1323 1325 Times : Total Per run\\
1324 1326 User : 0.910862 s, 0.1821724 s.\\
1325 1327 System: 0.0 s, 0.0 s.
1326 1328
1327 1329 -d: run your program under the control of pdb, the Python debugger.
1328 1330 This allows you to execute your program step by step, watch variables,
1329 1331 etc. Internally, what IPython does is similar to calling:
1330 1332
1331 1333 pdb.run('execfile("YOURFILENAME")')
1332 1334
1333 1335 with a breakpoint set on line 1 of your file. You can change the line
1334 1336 number for this automatic breakpoint to be <N> by using the -bN option
1335 1337 (where N must be an integer). For example:
1336 1338
1337 1339 %run -d -b40 myscript
1338 1340
1339 1341 will set the first breakpoint at line 40 in myscript.py. Note that
1340 1342 the first breakpoint must be set on a line which actually does
1341 1343 something (not a comment or docstring) for it to stop execution.
1342 1344
1343 1345 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1344 1346 first enter 'c' (without qoutes) to start execution up to the first
1345 1347 breakpoint.
1346 1348
1347 1349 Entering 'help' gives information about the use of the debugger. You
1348 1350 can easily see pdb's full documentation with "import pdb;pdb.help()"
1349 1351 at a prompt.
1350 1352
1351 1353 -p: run program under the control of the Python profiler module (which
1352 1354 prints a detailed report of execution times, function calls, etc).
1353 1355
1354 1356 You can pass other options after -p which affect the behavior of the
1355 1357 profiler itself. See the docs for %prun for details.
1356 1358
1357 1359 In this mode, the program's variables do NOT propagate back to the
1358 1360 IPython interactive namespace (because they remain in the namespace
1359 1361 where the profiler executes them).
1360 1362
1361 1363 Internally this triggers a call to %prun, see its documentation for
1362 1364 details on the options available specifically for profiling."""
1363 1365
1364 1366 # get arguments and set sys.argv for program to be run.
1365 1367 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1366 1368 mode='list',list_all=1)
1367 1369
1368 1370 try:
1369 1371 filename = get_py_filename(arg_lst[0])
1370 1372 except IndexError:
1371 1373 warn('you must provide at least a filename.')
1372 1374 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1373 1375 return
1374 1376 except IOError,msg:
1375 1377 error(msg)
1376 1378 return
1377 1379
1378 1380 # Control the response to exit() calls made by the script being run
1379 1381 exit_ignore = opts.has_key('e')
1380 1382
1381 1383 # Make sure that the running script gets a proper sys.argv as if it
1382 1384 # were run from a system shell.
1383 1385 save_argv = sys.argv # save it for later restoring
1384 1386 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1385 1387
1386 1388 if opts.has_key('i'):
1387 1389 prog_ns = self.shell.user_ns
1388 1390 __name__save = self.shell.user_ns['__name__']
1389 1391 prog_ns['__name__'] = '__main__'
1390 1392 else:
1391 1393 if opts.has_key('n'):
1392 1394 name = os.path.splitext(os.path.basename(filename))[0]
1393 1395 else:
1394 1396 name = '__main__'
1395 1397 prog_ns = {'__name__':name}
1396 1398
1397 1399 # pickle fix. See iplib for an explanation. But we need to make sure
1398 1400 # that, if we overwrite __main__, we replace it at the end
1399 1401 if prog_ns['__name__'] == '__main__':
1400 1402 restore_main = sys.modules['__main__']
1401 1403 else:
1402 1404 restore_main = False
1403 1405
1404 1406 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1405 1407
1406 1408 stats = None
1407 1409 try:
1408 1410 if opts.has_key('p'):
1409 1411 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1410 1412 else:
1411 1413 if opts.has_key('d'):
1412 1414 deb = Debugger.Pdb(self.shell.rc.colors)
1413 1415 # reset Breakpoint state, which is moronically kept
1414 1416 # in a class
1415 1417 bdb.Breakpoint.next = 1
1416 1418 bdb.Breakpoint.bplist = {}
1417 1419 bdb.Breakpoint.bpbynumber = [None]
1418 1420 # Set an initial breakpoint to stop execution
1419 1421 maxtries = 10
1420 1422 bp = int(opts.get('b',[1])[0])
1421 1423 checkline = deb.checkline(filename,bp)
1422 1424 if not checkline:
1423 1425 for bp in range(bp+1,bp+maxtries+1):
1424 1426 if deb.checkline(filename,bp):
1425 1427 break
1426 1428 else:
1427 1429 msg = ("\nI failed to find a valid line to set "
1428 1430 "a breakpoint\n"
1429 1431 "after trying up to line: %s.\n"
1430 1432 "Please set a valid breakpoint manually "
1431 1433 "with the -b option." % bp)
1432 1434 error(msg)
1433 1435 return
1434 1436 # if we find a good linenumber, set the breakpoint
1435 1437 deb.do_break('%s:%s' % (filename,bp))
1436 1438 # Start file run
1437 1439 print "NOTE: Enter 'c' at the",
1438 1440 print "ipdb> prompt to start your script."
1439 1441 try:
1440 1442 deb.run('execfile("%s")' % filename,prog_ns)
1441 1443 except:
1442 1444 etype, value, tb = sys.exc_info()
1443 1445 # Skip three frames in the traceback: the %run one,
1444 1446 # one inside bdb.py, and the command-line typed by the
1445 1447 # user (run by exec in pdb itself).
1446 1448 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1447 1449 else:
1448 1450 if runner is None:
1449 1451 runner = self.shell.safe_execfile
1450 1452 if opts.has_key('t'):
1451 1453 try:
1452 1454 nruns = int(opts['N'][0])
1453 1455 if nruns < 1:
1454 1456 error('Number of runs must be >=1')
1455 1457 return
1456 1458 except (KeyError):
1457 1459 nruns = 1
1458 1460 if nruns == 1:
1459 1461 t0 = clock2()
1460 1462 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1461 1463 t1 = clock2()
1462 1464 t_usr = t1[0]-t0[0]
1463 1465 t_sys = t1[1]-t1[1]
1464 1466 print "\nIPython CPU timings (estimated):"
1465 1467 print " User : %10s s." % t_usr
1466 1468 print " System: %10s s." % t_sys
1467 1469 else:
1468 1470 runs = range(nruns)
1469 1471 t0 = clock2()
1470 1472 for nr in runs:
1471 1473 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1472 1474 t1 = clock2()
1473 1475 t_usr = t1[0]-t0[0]
1474 1476 t_sys = t1[1]-t1[1]
1475 1477 print "\nIPython CPU timings (estimated):"
1476 1478 print "Total runs performed:",nruns
1477 1479 print " Times : %10s %10s" % ('Total','Per run')
1478 1480 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1479 1481 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1480 1482
1481 1483 else:
1482 1484 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1483 1485 if opts.has_key('i'):
1484 1486 self.shell.user_ns['__name__'] = __name__save
1485 1487 else:
1486 1488 # update IPython interactive namespace
1487 1489 del prog_ns['__name__']
1488 1490 self.shell.user_ns.update(prog_ns)
1489 1491 finally:
1490 1492 sys.argv = save_argv
1491 1493 if restore_main:
1492 1494 sys.modules['__main__'] = restore_main
1493 1495 return stats
1494 1496
1495 1497 def magic_runlog(self, parameter_s =''):
1496 1498 """Run files as logs.
1497 1499
1498 1500 Usage:\\
1499 1501 %runlog file1 file2 ...
1500 1502
1501 1503 Run the named files (treating them as log files) in sequence inside
1502 1504 the interpreter, and return to the prompt. This is much slower than
1503 1505 %run because each line is executed in a try/except block, but it
1504 1506 allows running files with syntax errors in them.
1505 1507
1506 1508 Normally IPython will guess when a file is one of its own logfiles, so
1507 1509 you can typically use %run even for logs. This shorthand allows you to
1508 1510 force any file to be treated as a log file."""
1509 1511
1510 1512 for f in parameter_s.split():
1511 1513 self.shell.safe_execfile(f,self.shell.user_ns,
1512 1514 self.shell.user_ns,islog=1)
1513 1515
1514 1516 def magic_time(self,parameter_s = ''):
1515 1517 """Time execution of a Python statement or expression.
1516 1518
1517 1519 The CPU and wall clock times are printed, and the value of the
1518 1520 expression (if any) is returned. Note that under Win32, system time
1519 1521 is always reported as 0, since it can not be measured.
1520 1522
1521 1523 This function provides very basic timing functionality. In Python
1522 1524 2.3, the timeit module offers more control and sophistication, but for
1523 1525 now IPython supports Python 2.2, so we can not rely on timeit being
1524 1526 present.
1525 1527
1526 1528 Some examples:
1527 1529
1528 1530 In [1]: time 2**128
1529 1531 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1530 1532 Wall time: 0.00
1531 1533 Out[1]: 340282366920938463463374607431768211456L
1532 1534
1533 1535 In [2]: n = 1000000
1534 1536
1535 1537 In [3]: time sum(range(n))
1536 1538 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1537 1539 Wall time: 1.37
1538 1540 Out[3]: 499999500000L
1539 1541
1540 1542 In [4]: time print 'hello world'
1541 1543 hello world
1542 1544 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1543 1545 Wall time: 0.00
1544 1546 """
1545 1547
1546 1548 # fail immediately if the given expression can't be compiled
1547 1549 try:
1548 1550 mode = 'eval'
1549 1551 code = compile(parameter_s,'<timed eval>',mode)
1550 1552 except SyntaxError:
1551 1553 mode = 'exec'
1552 1554 code = compile(parameter_s,'<timed exec>',mode)
1553 1555 # skew measurement as little as possible
1554 1556 glob = self.shell.user_ns
1555 1557 clk = clock2
1556 1558 wtime = time.time
1557 1559 # time execution
1558 1560 wall_st = wtime()
1559 1561 if mode=='eval':
1560 1562 st = clk()
1561 1563 out = eval(code,glob)
1562 1564 end = clk()
1563 1565 else:
1564 1566 st = clk()
1565 1567 exec code in glob
1566 1568 end = clk()
1567 1569 out = None
1568 1570 wall_end = wtime()
1569 1571 # Compute actual times and report
1570 1572 wall_time = wall_end-wall_st
1571 1573 cpu_user = end[0]-st[0]
1572 1574 cpu_sys = end[1]-st[1]
1573 1575 cpu_tot = cpu_user+cpu_sys
1574 1576 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1575 1577 (cpu_user,cpu_sys,cpu_tot)
1576 1578 print "Wall time: %.2f" % wall_time
1577 1579 return out
1578 1580
1579 1581 def magic_macro(self,parameter_s = ''):
1580 1582 """Define a set of input lines as a macro for future re-execution.
1581 1583
1582 1584 Usage:\\
1583 1585 %macro name n1-n2 n3-n4 ... n5 .. n6 ...
1584 1586
1585 1587 This will define a global variable called `name` which is a string
1586 1588 made of joining the slices and lines you specify (n1,n2,... numbers
1587 1589 above) from your input history into a single string. This variable
1588 1590 acts like an automatic function which re-executes those lines as if
1589 1591 you had typed them. You just type 'name' at the prompt and the code
1590 1592 executes.
1591 1593
1592 1594 The notation for indicating number ranges is: n1-n2 means 'use line
1593 1595 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1594 1596 using the lines numbered 5,6 and 7.
1595 1597
1596 1598 Note: as a 'hidden' feature, you can also use traditional python slice
1597 1599 notation, where N:M means numbers N through M-1.
1598 1600
1599 1601 For example, if your history contains (%hist prints it):
1600 1602
1601 1603 44: x=1\\
1602 1604 45: y=3\\
1603 1605 46: z=x+y\\
1604 1606 47: print x\\
1605 1607 48: a=5\\
1606 1608 49: print 'x',x,'y',y\\
1607 1609
1608 1610 you can create a macro with lines 44 through 47 (included) and line 49
1609 1611 called my_macro with:
1610 1612
1611 1613 In [51]: %macro my_macro 44-47 49
1612 1614
1613 1615 Now, typing `my_macro` (without quotes) will re-execute all this code
1614 1616 in one pass.
1615 1617
1616 1618 You don't need to give the line-numbers in order, and any given line
1617 1619 number can appear multiple times. You can assemble macros with any
1618 1620 lines from your input history in any order.
1619 1621
1620 1622 The macro is a simple object which holds its value in an attribute,
1621 1623 but IPython's display system checks for macros and executes them as
1622 1624 code instead of printing them when you type their name.
1623 1625
1624 1626 You can view a macro's contents by explicitly printing it with:
1625 1627
1626 1628 'print macro_name'.
1627 1629
1628 1630 For one-off cases which DON'T contain magic function calls in them you
1629 1631 can obtain similar results by explicitly executing slices from your
1630 1632 input history with:
1631 1633
1632 1634 In [60]: exec In[44:48]+In[49]"""
1633 1635
1634 1636 args = parameter_s.split()
1635 1637 name,ranges = args[0], args[1:]
1636 1638 #print 'rng',ranges # dbg
1637 1639 lines = self.extract_input_slices(ranges)
1638 1640 macro = Macro(lines)
1639 1641 self.shell.user_ns.update({name:macro})
1640 1642 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1641 1643 print 'Macro contents:'
1642 1644 print macro,
1643 1645
1644 1646 def magic_save(self,parameter_s = ''):
1645 1647 """Save a set of lines to a given filename.
1646 1648
1647 1649 Usage:\\
1648 1650 %save filename n1-n2 n3-n4 ... n5 .. n6 ...
1649 1651
1650 1652 This function uses the same syntax as %macro for line extraction, but
1651 1653 instead of creating a macro it saves the resulting string to the
1652 1654 filename you specify.
1653 1655
1654 1656 It adds a '.py' extension to the file if you don't do so yourself, and
1655 1657 it asks for confirmation before overwriting existing files."""
1656 1658
1657 1659 args = parameter_s.split()
1658 1660 fname,ranges = args[0], args[1:]
1659 1661 if not fname.endswith('.py'):
1660 1662 fname += '.py'
1661 1663 if os.path.isfile(fname):
1662 1664 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1663 1665 if ans.lower() not in ['y','yes']:
1664 1666 print 'Operation cancelled.'
1665 1667 return
1666 1668 cmds = ''.join(self.extract_input_slices(ranges))
1667 1669 f = file(fname,'w')
1668 1670 f.write(cmds)
1669 1671 f.close()
1670 1672 print 'The following commands were written to file `%s`:' % fname
1671 1673 print cmds
1672 1674
1673 1675 def _edit_macro(self,mname,macro):
1674 1676 """open an editor with the macro data in a file"""
1675 1677 filename = self.shell.mktempfile(macro.value)
1676 1678 self.shell.hooks.editor(filename)
1677 1679
1678 1680 # and make a new macro object, to replace the old one
1679 1681 mfile = open(filename)
1680 1682 mvalue = mfile.read()
1681 1683 mfile.close()
1682 1684 self.shell.user_ns[mname] = Macro(mvalue)
1683 1685
1684 1686 def magic_ed(self,parameter_s=''):
1685 1687 """Alias to %edit."""
1686 1688 return self.magic_edit(parameter_s)
1687 1689
1688 1690 def magic_edit(self,parameter_s='',last_call=['','']):
1689 1691 """Bring up an editor and execute the resulting code.
1690 1692
1691 1693 Usage:
1692 1694 %edit [options] [args]
1693 1695
1694 1696 %edit runs IPython's editor hook. The default version of this hook is
1695 1697 set to call the __IPYTHON__.rc.editor command. This is read from your
1696 1698 environment variable $EDITOR. If this isn't found, it will default to
1697 1699 vi under Linux/Unix and to notepad under Windows. See the end of this
1698 1700 docstring for how to change the editor hook.
1699 1701
1700 1702 You can also set the value of this editor via the command line option
1701 1703 '-editor' or in your ipythonrc file. This is useful if you wish to use
1702 1704 specifically for IPython an editor different from your typical default
1703 1705 (and for Windows users who typically don't set environment variables).
1704 1706
1705 1707 This command allows you to conveniently edit multi-line code right in
1706 1708 your IPython session.
1707 1709
1708 1710 If called without arguments, %edit opens up an empty editor with a
1709 1711 temporary file and will execute the contents of this file when you
1710 1712 close it (don't forget to save it!).
1711 1713
1714
1712 1715 Options:
1713 1716
1714 1717 -p: this will call the editor with the same data as the previous time
1715 1718 it was used, regardless of how long ago (in your current session) it
1716 1719 was.
1717 1720
1718 1721 -x: do not execute the edited code immediately upon exit. This is
1719 1722 mainly useful if you are editing programs which need to be called with
1720 1723 command line arguments, which you can then do using %run.
1721 1724
1725
1722 1726 Arguments:
1723 1727
1724 1728 If arguments are given, the following possibilites exist:
1725 1729
1726 1730 - The arguments are numbers or pairs of colon-separated numbers (like
1727 1731 1 4:8 9). These are interpreted as lines of previous input to be
1728 1732 loaded into the editor. The syntax is the same of the %macro command.
1729 1733
1730 1734 - If the argument doesn't start with a number, it is evaluated as a
1731 1735 variable and its contents loaded into the editor. You can thus edit
1732 1736 any string which contains python code (including the result of
1733 1737 previous edits).
1734 1738
1735 1739 - If the argument is the name of an object (other than a string),
1736 1740 IPython will try to locate the file where it was defined and open the
1737 1741 editor at the point where it is defined. You can use `%edit function`
1738 1742 to load an editor exactly at the point where 'function' is defined,
1739 1743 edit it and have the file be executed automatically.
1740 1744
1741 1745 If the object is a macro (see %macro for details), this opens up your
1742 1746 specified editor with a temporary file containing the macro's data.
1743 1747 Upon exit, the macro is reloaded with the contents of the file.
1744 1748
1745 1749 Note: opening at an exact line is only supported under Unix, and some
1746 1750 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1747 1751 '+NUMBER' parameter necessary for this feature. Good editors like
1748 1752 (X)Emacs, vi, jed, pico and joe all do.
1749 1753
1750 1754 - If the argument is not found as a variable, IPython will look for a
1751 1755 file with that name (adding .py if necessary) and load it into the
1752 1756 editor. It will execute its contents with execfile() when you exit,
1753 1757 loading any code in the file into your interactive namespace.
1754 1758
1755 1759 After executing your code, %edit will return as output the code you
1756 1760 typed in the editor (except when it was an existing file). This way
1757 1761 you can reload the code in further invocations of %edit as a variable,
1758 1762 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1759 1763 the output.
1760 1764
1761 1765 Note that %edit is also available through the alias %ed.
1762 1766
1763 1767 This is an example of creating a simple function inside the editor and
1764 1768 then modifying it. First, start up the editor:
1765 1769
1766 1770 In [1]: ed\\
1767 1771 Editing... done. Executing edited code...\\
1768 1772 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1769 1773
1770 1774 We can then call the function foo():
1771 1775
1772 1776 In [2]: foo()\\
1773 1777 foo() was defined in an editing session
1774 1778
1775 1779 Now we edit foo. IPython automatically loads the editor with the
1776 1780 (temporary) file where foo() was previously defined:
1777 1781
1778 1782 In [3]: ed foo\\
1779 1783 Editing... done. Executing edited code...
1780 1784
1781 1785 And if we call foo() again we get the modified version:
1782 1786
1783 1787 In [4]: foo()\\
1784 1788 foo() has now been changed!
1785 1789
1786 1790 Here is an example of how to edit a code snippet successive
1787 1791 times. First we call the editor:
1788 1792
1789 1793 In [8]: ed\\
1790 1794 Editing... done. Executing edited code...\\
1791 1795 hello\\
1792 1796 Out[8]: "print 'hello'\\n"
1793 1797
1794 1798 Now we call it again with the previous output (stored in _):
1795 1799
1796 1800 In [9]: ed _\\
1797 1801 Editing... done. Executing edited code...\\
1798 1802 hello world\\
1799 1803 Out[9]: "print 'hello world'\\n"
1800 1804
1801 1805 Now we call it with the output #8 (stored in _8, also as Out[8]):
1802 1806
1803 1807 In [10]: ed _8\\
1804 1808 Editing... done. Executing edited code...\\
1805 1809 hello again\\
1806 1810 Out[10]: "print 'hello again'\\n"
1807 1811
1808 1812
1809 1813 Changing the default editor hook:
1810 1814
1811 1815 If you wish to write your own editor hook, you can put it in a
1812 1816 configuration file which you load at startup time. The default hook
1813 1817 is defined in the IPython.hooks module, and you can use that as a
1814 1818 starting example for further modifications. That file also has
1815 1819 general instructions on how to set a new hook for use once you've
1816 1820 defined it."""
1817 1821
1818 1822 # FIXME: This function has become a convoluted mess. It needs a
1819 1823 # ground-up rewrite with clean, simple logic.
1820 1824
1821 1825 def make_filename(arg):
1822 1826 "Make a filename from the given args"
1823 1827 try:
1824 1828 filename = get_py_filename(arg)
1825 1829 except IOError:
1826 1830 if args.endswith('.py'):
1827 1831 filename = arg
1828 1832 else:
1829 1833 filename = None
1830 1834 return filename
1831 1835
1832 1836 # custom exceptions
1833 1837 class DataIsObject(Exception): pass
1834 1838
1835 1839 opts,args = self.parse_options(parameter_s,'px')
1836 1840
1837 1841 # Default line number value
1838 1842 lineno = None
1839 1843 if opts.has_key('p'):
1840 1844 args = '_%s' % last_call[0]
1841 1845 if not self.shell.user_ns.has_key(args):
1842 1846 args = last_call[1]
1843 1847
1844 1848 # use last_call to remember the state of the previous call, but don't
1845 1849 # let it be clobbered by successive '-p' calls.
1846 1850 try:
1847 1851 last_call[0] = self.shell.outputcache.prompt_count
1848 1852 if not opts.has_key('p'):
1849 1853 last_call[1] = parameter_s
1850 1854 except:
1851 1855 pass
1852 1856
1853 1857 # by default this is done with temp files, except when the given
1854 1858 # arg is a filename
1855 1859 use_temp = 1
1856 1860
1857 1861 if re.match(r'\d',args):
1858 1862 # Mode where user specifies ranges of lines, like in %macro.
1859 1863 # This means that you can't edit files whose names begin with
1860 1864 # numbers this way. Tough.
1861 1865 ranges = args.split()
1862 1866 data = ''.join(self.extract_input_slices(ranges))
1863 1867 elif args.endswith('.py'):
1864 1868 filename = make_filename(args)
1865 1869 data = ''
1866 1870 use_temp = 0
1867 1871 elif args:
1868 1872 try:
1869 1873 # Load the parameter given as a variable. If not a string,
1870 1874 # process it as an object instead (below)
1871 1875
1872 1876 #print '*** args',args,'type',type(args) # dbg
1873 1877 data = eval(args,self.shell.user_ns)
1874 1878 if not type(data) in StringTypes:
1875 1879 raise DataIsObject
1876 1880
1877 1881 except (NameError,SyntaxError):
1878 1882 # given argument is not a variable, try as a filename
1879 1883 filename = make_filename(args)
1880 1884 if filename is None:
1881 1885 warn("Argument given (%s) can't be found as a variable "
1882 1886 "or as a filename." % args)
1883 1887 return
1884 1888
1885 1889 data = ''
1886 1890 use_temp = 0
1887 1891 except DataIsObject:
1888 1892
1889 1893 # macros have a special edit function
1890 1894 if isinstance(data,Macro):
1891 1895 self._edit_macro(args,data)
1892 1896 return
1893 1897
1894 1898 # For objects, try to edit the file where they are defined
1895 1899 try:
1896 1900 filename = inspect.getabsfile(data)
1897 1901 datafile = 1
1898 1902 except TypeError:
1899 1903 filename = make_filename(args)
1900 1904 datafile = 1
1901 1905 warn('Could not find file where `%s` is defined.\n'
1902 1906 'Opening a file named `%s`' % (args,filename))
1903 1907 # Now, make sure we can actually read the source (if it was in
1904 1908 # a temp file it's gone by now).
1905 1909 if datafile:
1906 1910 try:
1907 1911 lineno = inspect.getsourcelines(data)[1]
1908 1912 except IOError:
1909 1913 filename = make_filename(args)
1910 1914 if filename is None:
1911 1915 warn('The file `%s` where `%s` was defined cannot '
1912 1916 'be read.' % (filename,data))
1913 1917 return
1914 1918 use_temp = 0
1915 1919 else:
1916 1920 data = ''
1917 1921
1918 1922 if use_temp:
1919 1923 filename = self.shell.mktempfile(data)
1924 print 'IPython will make a temporary file named:',filename
1920 1925
1921 1926 # do actual editing here
1922 1927 print 'Editing...',
1923 1928 sys.stdout.flush()
1924 1929 self.shell.hooks.editor(filename,lineno)
1925 1930 if opts.has_key('x'): # -x prevents actual execution
1926 1931 print
1927 1932 else:
1928 1933 print 'done. Executing edited code...'
1929 1934 try:
1930 1935 self.shell.safe_execfile(filename,self.shell.user_ns)
1931 1936 except IOError,msg:
1932 1937 if msg.filename == filename:
1933 1938 warn('File not found. Did you forget to save?')
1934 1939 return
1935 1940 else:
1936 1941 self.shell.showtraceback()
1937 1942 except:
1938 1943 self.shell.showtraceback()
1939 1944
1940 1945 def magic_xmode(self,parameter_s = ''):
1941 1946 """Switch modes for the exception handlers.
1942 1947
1943 1948 Valid modes: Plain, Context and Verbose.
1944 1949
1945 1950 If called without arguments, acts as a toggle."""
1946 1951
1947 1952 def xmode_switch_err(name):
1948 1953 warn('Error changing %s exception modes.\n%s' %
1949 1954 (name,sys.exc_info()[1]))
1950 1955
1951 1956 shell = self.shell
1952 1957 new_mode = parameter_s.strip().capitalize()
1953 1958 try:
1954 1959 shell.InteractiveTB.set_mode(mode=new_mode)
1955 1960 print 'Exception reporting mode:',shell.InteractiveTB.mode
1956 1961 except:
1957 1962 xmode_switch_err('user')
1958 1963
1959 1964 # threaded shells use a special handler in sys.excepthook
1960 1965 if shell.isthreaded:
1961 1966 try:
1962 1967 shell.sys_excepthook.set_mode(mode=new_mode)
1963 1968 except:
1964 1969 xmode_switch_err('threaded')
1965 1970
1966 1971 def magic_colors(self,parameter_s = ''):
1967 1972 """Switch color scheme for prompts, info system and exception handlers.
1968 1973
1969 1974 Currently implemented schemes: NoColor, Linux, LightBG.
1970 1975
1971 1976 Color scheme names are not case-sensitive."""
1972 1977
1973 1978 def color_switch_err(name):
1974 1979 warn('Error changing %s color schemes.\n%s' %
1975 1980 (name,sys.exc_info()[1]))
1976 1981
1977 1982
1978 1983 new_scheme = parameter_s.strip()
1979 1984 if not new_scheme:
1980 1985 print 'You must specify a color scheme.'
1981 1986 return
1982 1987 # Under Windows, check for Gary Bishop's readline, which is necessary
1983 1988 # for ANSI coloring
1984 1989 if os.name in ['nt','dos']:
1985 1990 try:
1986 1991 import readline
1987 1992 except ImportError:
1988 1993 has_readline = 0
1989 1994 else:
1990 1995 try:
1991 1996 readline.GetOutputFile()
1992 1997 except AttributeError:
1993 1998 has_readline = 0
1994 1999 else:
1995 2000 has_readline = 1
1996 2001 if not has_readline:
1997 2002 msg = """\
1998 2003 Proper color support under MS Windows requires Gary Bishop's readline library.
1999 2004 You can find it at:
2000 2005 http://sourceforge.net/projects/uncpythontools
2001 2006 Gary's readline needs the ctypes module, from:
2002 2007 http://starship.python.net/crew/theller/ctypes
2003 2008
2004 2009 Defaulting color scheme to 'NoColor'"""
2005 2010 new_scheme = 'NoColor'
2006 2011 warn(msg)
2007 2012 # local shortcut
2008 2013 shell = self.shell
2009 2014
2010 2015 # Set prompt colors
2011 2016 try:
2012 2017 shell.outputcache.set_colors(new_scheme)
2013 2018 except:
2014 2019 color_switch_err('prompt')
2015 2020 else:
2016 2021 shell.rc.colors = \
2017 2022 shell.outputcache.color_table.active_scheme_name
2018 2023 # Set exception colors
2019 2024 try:
2020 2025 shell.InteractiveTB.set_colors(scheme = new_scheme)
2021 2026 shell.SyntaxTB.set_colors(scheme = new_scheme)
2022 2027 except:
2023 2028 color_switch_err('exception')
2024 2029
2025 2030 # threaded shells use a verbose traceback in sys.excepthook
2026 2031 if shell.isthreaded:
2027 2032 try:
2028 2033 shell.sys_excepthook.set_colors(scheme=new_scheme)
2029 2034 except:
2030 2035 color_switch_err('system exception handler')
2031 2036
2032 2037 # Set info (for 'object?') colors
2033 2038 if shell.rc.color_info:
2034 2039 try:
2035 2040 shell.inspector.set_active_scheme(new_scheme)
2036 2041 except:
2037 2042 color_switch_err('object inspector')
2038 2043 else:
2039 2044 shell.inspector.set_active_scheme('NoColor')
2040 2045
2041 2046 def magic_color_info(self,parameter_s = ''):
2042 2047 """Toggle color_info.
2043 2048
2044 2049 The color_info configuration parameter controls whether colors are
2045 2050 used for displaying object details (by things like %psource, %pfile or
2046 2051 the '?' system). This function toggles this value with each call.
2047 2052
2048 2053 Note that unless you have a fairly recent pager (less works better
2049 2054 than more) in your system, using colored object information displays
2050 2055 will not work properly. Test it and see."""
2051 2056
2052 2057 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2053 2058 self.magic_colors(self.shell.rc.colors)
2054 2059 print 'Object introspection functions have now coloring:',
2055 2060 print ['OFF','ON'][self.shell.rc.color_info]
2056 2061
2057 2062 def magic_Pprint(self, parameter_s=''):
2058 2063 """Toggle pretty printing on/off."""
2059 2064
2060 2065 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
2061 2066 print 'Pretty printing has been turned', \
2062 2067 ['OFF','ON'][self.shell.outputcache.Pprint]
2063 2068
2064 2069 def magic_exit(self, parameter_s=''):
2065 2070 """Exit IPython, confirming if configured to do so.
2066 2071
2067 2072 You can configure whether IPython asks for confirmation upon exit by
2068 2073 setting the confirm_exit flag in the ipythonrc file."""
2069 2074
2070 2075 self.shell.exit()
2071 2076
2072 2077 def magic_quit(self, parameter_s=''):
2073 2078 """Exit IPython, confirming if configured to do so (like %exit)"""
2074 2079
2075 2080 self.shell.exit()
2076 2081
2077 2082 def magic_Exit(self, parameter_s=''):
2078 2083 """Exit IPython without confirmation."""
2079 2084
2080 2085 self.shell.exit_now = True
2081 2086
2082 2087 def magic_Quit(self, parameter_s=''):
2083 2088 """Exit IPython without confirmation (like %Exit)."""
2084 2089
2085 2090 self.shell.exit_now = True
2086 2091
2087 2092 #......................................................................
2088 2093 # Functions to implement unix shell-type things
2089 2094
2090 2095 def magic_alias(self, parameter_s = ''):
2091 2096 """Define an alias for a system command.
2092 2097
2093 2098 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2094 2099
2095 2100 Then, typing 'alias_name params' will execute the system command 'cmd
2096 2101 params' (from your underlying operating system).
2097 2102
2098 2103 Aliases have lower precedence than magic functions and Python normal
2099 2104 variables, so if 'foo' is both a Python variable and an alias, the
2100 2105 alias can not be executed until 'del foo' removes the Python variable.
2101 2106
2102 2107 You can use the %l specifier in an alias definition to represent the
2103 2108 whole line when the alias is called. For example:
2104 2109
2105 2110 In [2]: alias all echo "Input in brackets: <%l>"\\
2106 2111 In [3]: all hello world\\
2107 2112 Input in brackets: <hello world>
2108 2113
2109 2114 You can also define aliases with parameters using %s specifiers (one
2110 2115 per parameter):
2111 2116
2112 2117 In [1]: alias parts echo first %s second %s\\
2113 2118 In [2]: %parts A B\\
2114 2119 first A second B\\
2115 2120 In [3]: %parts A\\
2116 2121 Incorrect number of arguments: 2 expected.\\
2117 2122 parts is an alias to: 'echo first %s second %s'
2118 2123
2119 2124 Note that %l and %s are mutually exclusive. You can only use one or
2120 2125 the other in your aliases.
2121 2126
2122 2127 Aliases expand Python variables just like system calls using ! or !!
2123 2128 do: all expressions prefixed with '$' get expanded. For details of
2124 2129 the semantic rules, see PEP-215:
2125 2130 http://www.python.org/peps/pep-0215.html. This is the library used by
2126 2131 IPython for variable expansion. If you want to access a true shell
2127 2132 variable, an extra $ is necessary to prevent its expansion by IPython:
2128 2133
2129 2134 In [6]: alias show echo\\
2130 2135 In [7]: PATH='A Python string'\\
2131 2136 In [8]: show $PATH\\
2132 2137 A Python string\\
2133 2138 In [9]: show $$PATH\\
2134 2139 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2135 2140
2136 2141 You can use the alias facility to acess all of $PATH. See the %rehash
2137 2142 and %rehashx functions, which automatically create aliases for the
2138 2143 contents of your $PATH.
2139 2144
2140 2145 If called with no parameters, %alias prints the current alias table."""
2141 2146
2142 2147 par = parameter_s.strip()
2143 2148 if not par:
2144 2149 if self.shell.rc.automagic:
2145 2150 prechar = ''
2146 2151 else:
2147 2152 prechar = self.shell.ESC_MAGIC
2148 2153 print 'Alias\t\tSystem Command\n'+'-'*30
2149 2154 atab = self.shell.alias_table
2150 2155 aliases = atab.keys()
2151 2156 aliases.sort()
2152 2157 for alias in aliases:
2153 2158 print prechar+alias+'\t\t'+atab[alias][1]
2154 2159 print '-'*30+'\nTotal number of aliases:',len(aliases)
2155 2160 return
2156 2161 try:
2157 2162 alias,cmd = par.split(None,1)
2158 2163 except:
2159 2164 print OInspect.getdoc(self.magic_alias)
2160 2165 else:
2161 2166 nargs = cmd.count('%s')
2162 2167 if nargs>0 and cmd.find('%l')>=0:
2163 2168 error('The %s and %l specifiers are mutually exclusive '
2164 2169 'in alias definitions.')
2165 2170 else: # all looks OK
2166 2171 self.shell.alias_table[alias] = (nargs,cmd)
2167 2172 self.shell.alias_table_validate(verbose=1)
2168 2173 # end magic_alias
2169 2174
2170 2175 def magic_unalias(self, parameter_s = ''):
2171 2176 """Remove an alias"""
2172 2177
2173 2178 aname = parameter_s.strip()
2174 2179 if aname in self.shell.alias_table:
2175 2180 del self.shell.alias_table[aname]
2176 2181
2177 2182 def magic_rehash(self, parameter_s = ''):
2178 2183 """Update the alias table with all entries in $PATH.
2179 2184
2180 2185 This version does no checks on execute permissions or whether the
2181 2186 contents of $PATH are truly files (instead of directories or something
2182 2187 else). For such a safer (but slower) version, use %rehashx."""
2183 2188
2184 2189 # This function (and rehashx) manipulate the alias_table directly
2185 2190 # rather than calling magic_alias, for speed reasons. A rehash on a
2186 2191 # typical Linux box involves several thousand entries, so efficiency
2187 2192 # here is a top concern.
2188 2193
2189 2194 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2190 2195 alias_table = self.shell.alias_table
2191 2196 for pdir in path:
2192 2197 for ff in os.listdir(pdir):
2193 2198 # each entry in the alias table must be (N,name), where
2194 2199 # N is the number of positional arguments of the alias.
2195 2200 alias_table[ff] = (0,ff)
2196 2201 # Make sure the alias table doesn't contain keywords or builtins
2197 2202 self.shell.alias_table_validate()
2198 2203 # Call again init_auto_alias() so we get 'rm -i' and other modified
2199 2204 # aliases since %rehash will probably clobber them
2200 2205 self.shell.init_auto_alias()
2201 2206
2202 2207 def magic_rehashx(self, parameter_s = ''):
2203 2208 """Update the alias table with all executable files in $PATH.
2204 2209
2205 2210 This version explicitly checks that every entry in $PATH is a file
2206 2211 with execute access (os.X_OK), so it is much slower than %rehash.
2207 2212
2208 2213 Under Windows, it checks executability as a match agains a
2209 2214 '|'-separated string of extensions, stored in the IPython config
2210 2215 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2211 2216
2212 2217 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2213 2218 alias_table = self.shell.alias_table
2214 2219
2215 2220 if os.name == 'posix':
2216 2221 isexec = lambda fname:os.path.isfile(fname) and \
2217 2222 os.access(fname,os.X_OK)
2218 2223 else:
2219 2224
2220 2225 try:
2221 2226 winext = os.environ['pathext'].replace(';','|').replace('.','')
2222 2227 except KeyError:
2223 2228 winext = 'exe|com|bat'
2224 2229
2225 2230 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2226 2231 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2227 2232 savedir = os.getcwd()
2228 2233 try:
2229 2234 # write the whole loop for posix/Windows so we don't have an if in
2230 2235 # the innermost part
2231 2236 if os.name == 'posix':
2232 2237 for pdir in path:
2233 2238 os.chdir(pdir)
2234 2239 for ff in os.listdir(pdir):
2235 2240 if isexec(ff):
2236 2241 # each entry in the alias table must be (N,name),
2237 2242 # where N is the number of positional arguments of the
2238 2243 # alias.
2239 2244 alias_table[ff] = (0,ff)
2240 2245 else:
2241 2246 for pdir in path:
2242 2247 os.chdir(pdir)
2243 2248 for ff in os.listdir(pdir):
2244 2249 if isexec(ff):
2245 2250 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2246 2251 # Make sure the alias table doesn't contain keywords or builtins
2247 2252 self.shell.alias_table_validate()
2248 2253 # Call again init_auto_alias() so we get 'rm -i' and other
2249 2254 # modified aliases since %rehashx will probably clobber them
2250 2255 self.shell.init_auto_alias()
2251 2256 finally:
2252 2257 os.chdir(savedir)
2253 2258
2254 2259 def magic_pwd(self, parameter_s = ''):
2255 2260 """Return the current working directory path."""
2256 2261 return os.getcwd()
2257 2262
2258 2263 def magic_cd(self, parameter_s=''):
2259 2264 """Change the current working directory.
2260 2265
2261 2266 This command automatically maintains an internal list of directories
2262 2267 you visit during your IPython session, in the variable _dh. The
2263 2268 command %dhist shows this history nicely formatted.
2264 2269
2265 2270 Usage:
2266 2271
2267 2272 cd 'dir': changes to directory 'dir'.
2268 2273
2269 2274 cd -: changes to the last visited directory.
2270 2275
2271 2276 cd -<n>: changes to the n-th directory in the directory history.
2272 2277
2273 2278 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2274 2279 (note: cd <bookmark_name> is enough if there is no
2275 2280 directory <bookmark_name>, but a bookmark with the name exists.)
2276 2281
2277 2282 Options:
2278 2283
2279 2284 -q: quiet. Do not print the working directory after the cd command is
2280 2285 executed. By default IPython's cd command does print this directory,
2281 2286 since the default prompts do not display path information.
2282 2287
2283 2288 Note that !cd doesn't work for this purpose because the shell where
2284 2289 !command runs is immediately discarded after executing 'command'."""
2285 2290
2286 2291 parameter_s = parameter_s.strip()
2287 2292 bkms = self.shell.persist.get("bookmarks",{})
2288 2293
2289 2294 numcd = re.match(r'(-)(\d+)$',parameter_s)
2290 2295 # jump in directory history by number
2291 2296 if numcd:
2292 2297 nn = int(numcd.group(2))
2293 2298 try:
2294 2299 ps = self.shell.user_ns['_dh'][nn]
2295 2300 except IndexError:
2296 2301 print 'The requested directory does not exist in history.'
2297 2302 return
2298 2303 else:
2299 2304 opts = {}
2300 2305 else:
2301 2306 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2302 2307 # jump to previous
2303 2308 if ps == '-':
2304 2309 try:
2305 2310 ps = self.shell.user_ns['_dh'][-2]
2306 2311 except IndexError:
2307 2312 print 'No previous directory to change to.'
2308 2313 return
2309 2314 # jump to bookmark
2310 2315 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2311 2316 if bkms.has_key(ps):
2312 2317 target = bkms[ps]
2313 2318 print '(bookmark:%s) -> %s' % (ps,target)
2314 2319 ps = target
2315 2320 else:
2316 2321 if bkms:
2317 2322 error("Bookmark '%s' not found. "
2318 2323 "Use '%%bookmark -l' to see your bookmarks." % ps)
2319 2324 else:
2320 2325 print "Bookmarks not set - use %bookmark <bookmarkname>"
2321 2326 return
2322 2327
2323 2328 # at this point ps should point to the target dir
2324 2329 if ps:
2325 2330 try:
2326 2331 os.chdir(os.path.expanduser(ps))
2327 2332 except OSError:
2328 2333 print sys.exc_info()[1]
2329 2334 else:
2330 2335 self.shell.user_ns['_dh'].append(os.getcwd())
2331 2336 else:
2332 2337 os.chdir(self.shell.home_dir)
2333 2338 self.shell.user_ns['_dh'].append(os.getcwd())
2334 2339 if not 'q' in opts:
2335 2340 print self.shell.user_ns['_dh'][-1]
2336 2341
2337 2342 def magic_dhist(self, parameter_s=''):
2338 2343 """Print your history of visited directories.
2339 2344
2340 2345 %dhist -> print full history\\
2341 2346 %dhist n -> print last n entries only\\
2342 2347 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2343 2348
2344 2349 This history is automatically maintained by the %cd command, and
2345 2350 always available as the global list variable _dh. You can use %cd -<n>
2346 2351 to go to directory number <n>."""
2347 2352
2348 2353 dh = self.shell.user_ns['_dh']
2349 2354 if parameter_s:
2350 2355 try:
2351 2356 args = map(int,parameter_s.split())
2352 2357 except:
2353 2358 self.arg_err(Magic.magic_dhist)
2354 2359 return
2355 2360 if len(args) == 1:
2356 2361 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2357 2362 elif len(args) == 2:
2358 2363 ini,fin = args
2359 2364 else:
2360 2365 self.arg_err(Magic.magic_dhist)
2361 2366 return
2362 2367 else:
2363 2368 ini,fin = 0,len(dh)
2364 2369 nlprint(dh,
2365 2370 header = 'Directory history (kept in _dh)',
2366 2371 start=ini,stop=fin)
2367 2372
2368 2373 def magic_env(self, parameter_s=''):
2369 2374 """List environment variables."""
2370 2375
2371 2376 return os.environ.data
2372 2377
2373 2378 def magic_pushd(self, parameter_s=''):
2374 2379 """Place the current dir on stack and change directory.
2375 2380
2376 2381 Usage:\\
2377 2382 %pushd ['dirname']
2378 2383
2379 2384 %pushd with no arguments does a %pushd to your home directory.
2380 2385 """
2381 2386 if parameter_s == '': parameter_s = '~'
2382 2387 dir_s = self.shell.dir_stack
2383 2388 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2384 2389 os.path.expanduser(self.shell.dir_stack[0]):
2385 2390 try:
2386 2391 self.magic_cd(parameter_s)
2387 2392 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2388 2393 self.magic_dirs()
2389 2394 except:
2390 2395 print 'Invalid directory'
2391 2396 else:
2392 2397 print 'You are already there!'
2393 2398
2394 2399 def magic_popd(self, parameter_s=''):
2395 2400 """Change to directory popped off the top of the stack.
2396 2401 """
2397 2402 if len (self.shell.dir_stack) > 1:
2398 2403 self.shell.dir_stack.pop(0)
2399 2404 self.magic_cd(self.shell.dir_stack[0])
2400 2405 print self.shell.dir_stack[0]
2401 2406 else:
2402 2407 print "You can't remove the starting directory from the stack:",\
2403 2408 self.shell.dir_stack
2404 2409
2405 2410 def magic_dirs(self, parameter_s=''):
2406 2411 """Return the current directory stack."""
2407 2412
2408 2413 return self.shell.dir_stack[:]
2409 2414
2410 2415 def magic_sc(self, parameter_s=''):
2411 2416 """Shell capture - execute a shell command and capture its output.
2412 2417
2413 2418 %sc [options] varname=command
2414 2419
2415 2420 IPython will run the given command using commands.getoutput(), and
2416 2421 will then update the user's interactive namespace with a variable
2417 2422 called varname, containing the value of the call. Your command can
2418 2423 contain shell wildcards, pipes, etc.
2419 2424
2420 2425 The '=' sign in the syntax is mandatory, and the variable name you
2421 2426 supply must follow Python's standard conventions for valid names.
2422 2427
2423 2428 Options:
2424 2429
2425 2430 -l: list output. Split the output on newlines into a list before
2426 2431 assigning it to the given variable. By default the output is stored
2427 2432 as a single string.
2428 2433
2429 2434 -v: verbose. Print the contents of the variable.
2430 2435
2431 2436 In most cases you should not need to split as a list, because the
2432 2437 returned value is a special type of string which can automatically
2433 2438 provide its contents either as a list (split on newlines) or as a
2434 2439 space-separated string. These are convenient, respectively, either
2435 2440 for sequential processing or to be passed to a shell command.
2436 2441
2437 2442 For example:
2438 2443
2439 2444 # Capture into variable a
2440 2445 In [9]: sc a=ls *py
2441 2446
2442 2447 # a is a string with embedded newlines
2443 2448 In [10]: a
2444 2449 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2445 2450
2446 2451 # which can be seen as a list:
2447 2452 In [11]: a.l
2448 2453 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2449 2454
2450 2455 # or as a whitespace-separated string:
2451 2456 In [12]: a.s
2452 2457 Out[12]: 'setup.py win32_manual_post_install.py'
2453 2458
2454 2459 # a.s is useful to pass as a single command line:
2455 2460 In [13]: !wc -l $a.s
2456 2461 146 setup.py
2457 2462 130 win32_manual_post_install.py
2458 2463 276 total
2459 2464
2460 2465 # while the list form is useful to loop over:
2461 2466 In [14]: for f in a.l:
2462 2467 ....: !wc -l $f
2463 2468 ....:
2464 2469 146 setup.py
2465 2470 130 win32_manual_post_install.py
2466 2471
2467 2472 Similiarly, the lists returned by the -l option are also special, in
2468 2473 the sense that you can equally invoke the .s attribute on them to
2469 2474 automatically get a whitespace-separated string from their contents:
2470 2475
2471 2476 In [1]: sc -l b=ls *py
2472 2477
2473 2478 In [2]: b
2474 2479 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2475 2480
2476 2481 In [3]: b.s
2477 2482 Out[3]: 'setup.py win32_manual_post_install.py'
2478 2483
2479 2484 In summary, both the lists and strings used for ouptut capture have
2480 2485 the following special attributes:
2481 2486
2482 2487 .l (or .list) : value as list.
2483 2488 .n (or .nlstr): value as newline-separated string.
2484 2489 .s (or .spstr): value as space-separated string.
2485 2490 """
2486 2491
2487 2492 opts,args = self.parse_options(parameter_s,'lv')
2488 2493 # Try to get a variable name and command to run
2489 2494 try:
2490 2495 # the variable name must be obtained from the parse_options
2491 2496 # output, which uses shlex.split to strip options out.
2492 2497 var,_ = args.split('=',1)
2493 2498 var = var.strip()
2494 2499 # But the the command has to be extracted from the original input
2495 2500 # parameter_s, not on what parse_options returns, to avoid the
2496 2501 # quote stripping which shlex.split performs on it.
2497 2502 _,cmd = parameter_s.split('=',1)
2498 2503 except ValueError:
2499 2504 var,cmd = '',''
2500 2505 if not var:
2501 2506 error('you must specify a variable to assign the command to.')
2502 2507 return
2503 2508 # If all looks ok, proceed
2504 2509 out,err = self.shell.getoutputerror(cmd)
2505 2510 if err:
2506 2511 print >> Term.cerr,err
2507 2512 if opts.has_key('l'):
2508 2513 out = SList(out.split('\n'))
2509 2514 else:
2510 2515 out = LSString(out)
2511 2516 if opts.has_key('v'):
2512 2517 print '%s ==\n%s' % (var,pformat(out))
2513 2518 self.shell.user_ns.update({var:out})
2514 2519
2515 2520 def magic_sx(self, parameter_s=''):
2516 2521 """Shell execute - run a shell command and capture its output.
2517 2522
2518 2523 %sx command
2519 2524
2520 2525 IPython will run the given command using commands.getoutput(), and
2521 2526 return the result formatted as a list (split on '\\n'). Since the
2522 2527 output is _returned_, it will be stored in ipython's regular output
2523 2528 cache Out[N] and in the '_N' automatic variables.
2524 2529
2525 2530 Notes:
2526 2531
2527 2532 1) If an input line begins with '!!', then %sx is automatically
2528 2533 invoked. That is, while:
2529 2534 !ls
2530 2535 causes ipython to simply issue system('ls'), typing
2531 2536 !!ls
2532 2537 is a shorthand equivalent to:
2533 2538 %sx ls
2534 2539
2535 2540 2) %sx differs from %sc in that %sx automatically splits into a list,
2536 2541 like '%sc -l'. The reason for this is to make it as easy as possible
2537 2542 to process line-oriented shell output via further python commands.
2538 2543 %sc is meant to provide much finer control, but requires more
2539 2544 typing.
2540 2545
2541 2546 3) Just like %sc -l, this is a list with special attributes:
2542 2547
2543 2548 .l (or .list) : value as list.
2544 2549 .n (or .nlstr): value as newline-separated string.
2545 2550 .s (or .spstr): value as whitespace-separated string.
2546 2551
2547 2552 This is very useful when trying to use such lists as arguments to
2548 2553 system commands."""
2549 2554
2550 2555 if parameter_s:
2551 2556 out,err = self.shell.getoutputerror(parameter_s)
2552 2557 if err:
2553 2558 print >> Term.cerr,err
2554 2559 return SList(out.split('\n'))
2555 2560
2556 2561 def magic_bg(self, parameter_s=''):
2557 2562 """Run a job in the background, in a separate thread.
2558 2563
2559 2564 For example,
2560 2565
2561 2566 %bg myfunc(x,y,z=1)
2562 2567
2563 2568 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2564 2569 execution starts, a message will be printed indicating the job
2565 2570 number. If your job number is 5, you can use
2566 2571
2567 2572 myvar = jobs.result(5) or myvar = jobs[5].result
2568 2573
2569 2574 to assign this result to variable 'myvar'.
2570 2575
2571 2576 IPython has a job manager, accessible via the 'jobs' object. You can
2572 2577 type jobs? to get more information about it, and use jobs.<TAB> to see
2573 2578 its attributes. All attributes not starting with an underscore are
2574 2579 meant for public use.
2575 2580
2576 2581 In particular, look at the jobs.new() method, which is used to create
2577 2582 new jobs. This magic %bg function is just a convenience wrapper
2578 2583 around jobs.new(), for expression-based jobs. If you want to create a
2579 2584 new job with an explicit function object and arguments, you must call
2580 2585 jobs.new() directly.
2581 2586
2582 2587 The jobs.new docstring also describes in detail several important
2583 2588 caveats associated with a thread-based model for background job
2584 2589 execution. Type jobs.new? for details.
2585 2590
2586 2591 You can check the status of all jobs with jobs.status().
2587 2592
2588 2593 The jobs variable is set by IPython into the Python builtin namespace.
2589 2594 If you ever declare a variable named 'jobs', you will shadow this
2590 2595 name. You can either delete your global jobs variable to regain
2591 2596 access to the job manager, or make a new name and assign it manually
2592 2597 to the manager (stored in IPython's namespace). For example, to
2593 2598 assign the job manager to the Jobs name, use:
2594 2599
2595 2600 Jobs = __builtins__.jobs"""
2596 2601
2597 2602 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2598 2603
2599 2604 def magic_store(self, parameter_s=''):
2600 2605 """Lightweight persistence for python variables.
2601 2606
2602 2607 Example:
2603 2608
2604 2609 ville@badger[~]|1> A = ['hello',10,'world']\\
2605 2610 ville@badger[~]|2> %store A\\
2606 2611 ville@badger[~]|3> Exit
2607 2612
2608 2613 (IPython session is closed and started again...)
2609 2614
2610 2615 ville@badger:~$ ipython -p pysh\\
2611 2616 ville@badger[~]|1> print A
2612 2617
2613 2618 ['hello', 10, 'world']
2614 2619
2615 2620 Usage:
2616 2621
2617 2622 %store - Show list of all variables and their current values\\
2618 2623 %store <var> - Store the *current* value of the variable to disk\\
2619 2624 %store -d <var> - Remove the variable and its value from storage\\
2620 2625 %store -r - Remove all variables from storage
2621 2626
2622 2627 It should be noted that if you change the value of a variable, you
2623 2628 need to %store it again if you want to persist the new value.
2624 2629
2625 2630 Note also that the variables will need to be pickleable; most basic
2626 2631 python types can be safely %stored.
2627 2632 """
2628 2633
2629 2634 opts,args = self.parse_options(parameter_s,'dr',mode='list')
2630 2635 # delete
2631 2636 if opts.has_key('d'):
2632 2637 try:
2633 2638 todel = args[0]
2634 2639 except IndexError:
2635 2640 error('You must provide the variable to forget')
2636 2641 else:
2637 2642 try:
2638 2643 del self.shell.persist['S:' + todel]
2639 2644 except:
2640 2645 error("Can't delete variable '%s'" % todel)
2641 2646 # reset
2642 2647 elif opts.has_key('r'):
2643 2648 for k in self.shell.persist.keys():
2644 2649 if k.startswith('S:'):
2645 2650 del self.shell.persist[k]
2646 2651
2647 2652 # run without arguments -> list variables & values
2648 2653 elif not args:
2649 2654 vars = [v[2:] for v in self.shell.persist.keys()
2650 2655 if v.startswith('S:')]
2651 2656 vars.sort()
2652 2657 if vars:
2653 2658 size = max(map(len,vars))
2654 2659 else:
2655 2660 size = 0
2656 2661
2657 2662 print 'Stored variables and their in-memory values:'
2658 2663 fmt = '%-'+str(size)+'s -> %s'
2659 2664 get = self.shell.user_ns.get
2660 2665 for var in vars:
2661 2666 # print 30 first characters from every var
2662 2667 print fmt % (var,repr(get(var,'<unavailable>'))[:50])
2663 2668
2664 2669 # default action - store the variable
2665 2670 else:
2666 2671 pickled = pickle.dumps(self.shell.user_ns[args[0] ])
2667 2672 self.shell.persist[ 'S:' + args[0] ] = pickled
2668 2673 print "Stored '%s' (%d bytes)" % (args[0], len(pickled))
2669 2674
2670 2675 def magic_bookmark(self, parameter_s=''):
2671 2676 """Manage IPython's bookmark system.
2672 2677
2673 2678 %bookmark <name> - set bookmark to current dir
2674 2679 %bookmark <name> <dir> - set bookmark to <dir>
2675 2680 %bookmark -l - list all bookmarks
2676 2681 %bookmark -d <name> - remove bookmark
2677 2682 %bookmark -r - remove all bookmarks
2678 2683
2679 2684 You can later on access a bookmarked folder with:
2680 2685 %cd -b <name>
2681 2686 or simply '%cd <name>' if there is no directory called <name> AND
2682 2687 there is such a bookmark defined.
2683 2688
2684 2689 Your bookmarks persist through IPython sessions, but they are
2685 2690 associated with each profile."""
2686 2691
2687 2692 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2688 2693 if len(args) > 2:
2689 2694 error('You can only give at most two arguments')
2690 2695 return
2691 2696
2692 2697 bkms = self.shell.persist.get('bookmarks',{})
2693 2698
2694 2699 if opts.has_key('d'):
2695 2700 try:
2696 2701 todel = args[0]
2697 2702 except IndexError:
2698 2703 error('You must provide a bookmark to delete')
2699 2704 else:
2700 2705 try:
2701 2706 del bkms[todel]
2702 2707 except:
2703 2708 error("Can't delete bookmark '%s'" % todel)
2704 2709 elif opts.has_key('r'):
2705 2710 bkms = {}
2706 2711 elif opts.has_key('l'):
2707 2712 bks = bkms.keys()
2708 2713 bks.sort()
2709 2714 if bks:
2710 2715 size = max(map(len,bks))
2711 2716 else:
2712 2717 size = 0
2713 2718 fmt = '%-'+str(size)+'s -> %s'
2714 2719 print 'Current bookmarks:'
2715 2720 for bk in bks:
2716 2721 print fmt % (bk,bkms[bk])
2717 2722 else:
2718 2723 if not args:
2719 2724 error("You must specify the bookmark name")
2720 2725 elif len(args)==1:
2721 2726 bkms[args[0]] = os.getcwd()
2722 2727 elif len(args)==2:
2723 2728 bkms[args[0]] = args[1]
2724 2729 self.shell.persist['bookmarks'] = bkms
2725 2730
2726 2731 def magic_pycat(self, parameter_s=''):
2727 2732 """Show a syntax-highlighted file through a pager.
2728 2733
2729 2734 This magic is similar to the cat utility, but it will assume the file
2730 2735 to be Python source and will show it with syntax highlighting. """
2731 2736
2732 2737 filename = get_py_filename(parameter_s)
2733 2738 page(self.shell.colorize(file_read(filename)),
2734 2739 screen_lines=self.shell.rc.screen_length)
2735 2740
2736 2741 # end Magic
@@ -1,76 +1,76
1 1 # -*- coding: utf-8 -*-
2 2 """Release data for the IPython project.
3 3
4 $Id: Release.py 994 2006-01-08 08:29:44Z fperez $"""
4 $Id: Release.py 1000 2006-01-10 08:06:04Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
8 8 #
9 9 # Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and Nathaniel Gray
10 10 # <n8gray@caltech.edu>
11 11 #
12 12 # Distributed under the terms of the BSD License. The full license is in
13 13 # the file COPYING, distributed as part of this software.
14 14 #*****************************************************************************
15 15
16 16 # Name of the package for release purposes. This is the name which labels
17 17 # the tarballs and RPMs made by distutils, so it's best to lowercase it.
18 18 name = 'ipython'
19 19
20 20 # For versions with substrings (like 0.6.16.svn), use an extra . to separate
21 21 # the new substring. We have to avoid using either dashes or underscores,
22 22 # because bdist_rpm does not accept dashes (an RPM) convention, and
23 23 # bdist_deb does not accept underscores (a Debian convention).
24 24
25 version = '0.7.0.rc8'
25 version = '0.7.0'
26 26
27 revision = '$Revision: 994 $'
27 revision = '$Revision: 1000 $'
28 28
29 29 description = "An enhanced interactive Python shell."
30 30
31 31 long_description = \
32 32 """
33 33 IPython provides a replacement for the interactive Python interpreter with
34 34 extra functionality.
35 35
36 36 Main features:
37 37
38 38 * Comprehensive object introspection.
39 39
40 40 * Input history, persistent across sessions.
41 41
42 42 * Caching of output results during a session with automatically generated
43 43 references.
44 44
45 45 * Readline based name completion.
46 46
47 47 * Extensible system of 'magic' commands for controlling the environment and
48 48 performing many tasks related either to IPython or the operating system.
49 49
50 50 * Configuration system with easy switching between different setups (simpler
51 51 than changing $PYTHONSTARTUP environment variables every time).
52 52
53 53 * Session logging and reloading.
54 54
55 55 * Extensible syntax processing for special purpose situations.
56 56
57 57 * Access to the system shell with user-extensible alias system.
58 58
59 59 * Easily embeddable in other Python programs.
60 60
61 61 * Integrated access to the pdb debugger and the Python profiler. """
62 62
63 63 license = 'BSD'
64 64
65 65 authors = {'Fernando' : ('Fernando Perez','fperez@colorado.edu'),
66 66 'Janko' : ('Janko Hauser','jhauser@zscout.de'),
67 67 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu')
68 68 }
69 69
70 70 url = 'http://ipython.scipy.org'
71 71
72 72 download_url = 'http://ipython.scipy.org/dist'
73 73
74 74 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
75 75
76 76 keywords = ['Interactive','Interpreter','Shell']
@@ -1,2165 +1,2165
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 IPython -- An enhanced Interactive Python
4 4
5 5 Requires Python 2.1 or newer.
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 995 2006-01-08 16:23:20Z fperez $
9 $Id: iplib.py 1000 2006-01-10 08:06:04Z 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 __future__ import generators # for 2.2 backwards-compatibility
32 32
33 33 from IPython import Release
34 34 __author__ = '%s <%s>\n%s <%s>' % \
35 35 ( Release.authors['Janko'] + Release.authors['Fernando'] )
36 36 __license__ = Release.license
37 37 __version__ = Release.version
38 38
39 39 # Python standard modules
40 40 import __main__
41 41 import __builtin__
42 42 import StringIO
43 43 import bdb
44 44 import cPickle as pickle
45 45 import codeop
46 46 import exceptions
47 47 import glob
48 48 import inspect
49 49 import keyword
50 50 import new
51 51 import os
52 52 import pdb
53 53 import pydoc
54 54 import re
55 55 import shutil
56 56 import string
57 57 import sys
58 58 import tempfile
59 59 import traceback
60 60 import types
61 61
62 62 from pprint import pprint, pformat
63 63
64 64 # IPython's own modules
65 65 import IPython
66 66 from IPython import OInspect,PyColorize,ultraTB
67 67 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
68 68 from IPython.FakeModule import FakeModule
69 69 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
70 70 from IPython.Logger import Logger
71 71 from IPython.Magic import Magic
72 72 from IPython.Prompts import CachedOutput
73 73 from IPython.Struct import Struct
74 74 from IPython.background_jobs import BackgroundJobManager
75 75 from IPython.usage import cmd_line_usage,interactive_usage
76 76 from IPython.genutils import *
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 ini_spaces_re = re.compile(r'^(\s+)')
86 86 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
87 87
88 88
89 89 #****************************************************************************
90 90 # Some utility function definitions
91 91
92 92 def softspace(file, newvalue):
93 93 """Copied from code.py, to remove the dependency"""
94 94 oldvalue = 0
95 95 try:
96 96 oldvalue = file.softspace
97 97 except AttributeError:
98 98 pass
99 99 try:
100 100 file.softspace = newvalue
101 101 except (AttributeError, TypeError):
102 102 # "attribute-less object" or "read-only attributes"
103 103 pass
104 104 return oldvalue
105 105
106 106
107 107 #****************************************************************************
108 108 # Local use exceptions
109 109 class SpaceInInput(exceptions.Exception): pass
110 110
111 111
112 112 #****************************************************************************
113 113 # Local use classes
114 114 class Bunch: pass
115 115
116 116 class Undefined: pass
117 117
118 118 class InputList(list):
119 119 """Class to store user input.
120 120
121 121 It's basically a list, but slices return a string instead of a list, thus
122 122 allowing things like (assuming 'In' is an instance):
123 123
124 124 exec In[4:7]
125 125
126 126 or
127 127
128 128 exec In[5:9] + In[14] + In[21:25]"""
129 129
130 130 def __getslice__(self,i,j):
131 131 return ''.join(list.__getslice__(self,i,j))
132 132
133 133 class SyntaxTB(ultraTB.ListTB):
134 134 """Extension which holds some state: the last exception value"""
135 135
136 136 def __init__(self,color_scheme = 'NoColor'):
137 137 ultraTB.ListTB.__init__(self,color_scheme)
138 138 self.last_syntax_error = None
139 139
140 140 def __call__(self, etype, value, elist):
141 141 self.last_syntax_error = value
142 142 ultraTB.ListTB.__call__(self,etype,value,elist)
143 143
144 144 def clear_err_state(self):
145 145 """Return the current error state and clear it"""
146 146 e = self.last_syntax_error
147 147 self.last_syntax_error = None
148 148 return e
149 149
150 150 #****************************************************************************
151 151 # Main IPython class
152 152
153 153 # FIXME: the Magic class is a mixin for now, and will unfortunately remain so
154 154 # until a full rewrite is made. I've cleaned all cross-class uses of
155 155 # attributes and methods, but too much user code out there relies on the
156 156 # equlity %foo == __IP.magic_foo, so I can't actually remove the mixin usage.
157 157 #
158 158 # But at least now, all the pieces have been separated and we could, in
159 159 # principle, stop using the mixin. This will ease the transition to the
160 160 # chainsaw branch.
161 161
162 162 # For reference, the following is the list of 'self.foo' uses in the Magic
163 163 # class as of 2005-12-28. These are names we CAN'T use in the main ipython
164 164 # class, to prevent clashes.
165 165
166 166 # ['self.__class__', 'self.__dict__', 'self._inspect', 'self._ofind',
167 167 # 'self.arg_err', 'self.extract_input', 'self.format_', 'self.lsmagic',
168 168 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
169 169 # 'self.value']
170 170
171 171 class InteractiveShell(object,Magic):
172 172 """An enhanced console for Python."""
173 173
174 174 # class attribute to indicate whether the class supports threads or not.
175 175 # Subclasses with thread support should override this as needed.
176 176 isthreaded = False
177 177
178 178 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
179 179 user_ns = None,user_global_ns=None,banner2='',
180 180 custom_exceptions=((),None),embedded=False):
181 181
182 182 # some minimal strict typechecks. For some core data structures, I
183 183 # want actual basic python types, not just anything that looks like
184 184 # one. This is especially true for namespaces.
185 185 for ns in (user_ns,user_global_ns):
186 186 if ns is not None and type(ns) != types.DictType:
187 187 raise TypeError,'namespace must be a dictionary'
188 188
189 189 # Job manager (for jobs run as background threads)
190 190 self.jobs = BackgroundJobManager()
191 191
192 192 # track which builtins we add, so we can clean up later
193 193 self.builtins_added = {}
194 194 # This method will add the necessary builtins for operation, but
195 195 # tracking what it did via the builtins_added dict.
196 196 self.add_builtins()
197 197
198 198 # Do the intuitively correct thing for quit/exit: we remove the
199 199 # builtins if they exist, and our own magics will deal with this
200 200 try:
201 201 del __builtin__.exit, __builtin__.quit
202 202 except AttributeError:
203 203 pass
204 204
205 205 # Store the actual shell's name
206 206 self.name = name
207 207
208 208 # We need to know whether the instance is meant for embedding, since
209 209 # global/local namespaces need to be handled differently in that case
210 210 self.embedded = embedded
211 211
212 212 # command compiler
213 213 self.compile = codeop.CommandCompiler()
214 214
215 215 # User input buffer
216 216 self.buffer = []
217 217
218 218 # Default name given in compilation of code
219 219 self.filename = '<ipython console>'
220 220
221 221 # Make an empty namespace, which extension writers can rely on both
222 222 # existing and NEVER being used by ipython itself. This gives them a
223 223 # convenient location for storing additional information and state
224 224 # their extensions may require, without fear of collisions with other
225 225 # ipython names that may develop later.
226 226 self.meta = Bunch()
227 227
228 228 # Create the namespace where the user will operate. user_ns is
229 229 # normally the only one used, and it is passed to the exec calls as
230 230 # the locals argument. But we do carry a user_global_ns namespace
231 231 # given as the exec 'globals' argument, This is useful in embedding
232 232 # situations where the ipython shell opens in a context where the
233 233 # distinction between locals and globals is meaningful.
234 234
235 235 # FIXME. For some strange reason, __builtins__ is showing up at user
236 236 # level as a dict instead of a module. This is a manual fix, but I
237 237 # should really track down where the problem is coming from. Alex
238 238 # Schmolck reported this problem first.
239 239
240 240 # A useful post by Alex Martelli on this topic:
241 241 # Re: inconsistent value from __builtins__
242 242 # Von: Alex Martelli <aleaxit@yahoo.com>
243 243 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
244 244 # Gruppen: comp.lang.python
245 245
246 246 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
247 247 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
248 248 # > <type 'dict'>
249 249 # > >>> print type(__builtins__)
250 250 # > <type 'module'>
251 251 # > Is this difference in return value intentional?
252 252
253 253 # Well, it's documented that '__builtins__' can be either a dictionary
254 254 # or a module, and it's been that way for a long time. Whether it's
255 255 # intentional (or sensible), I don't know. In any case, the idea is
256 256 # that if you need to access the built-in namespace directly, you
257 257 # should start with "import __builtin__" (note, no 's') which will
258 258 # definitely give you a module. Yeah, it's somewhat confusing:-(.
259 259
260 260 if user_ns is None:
261 261 # Set __name__ to __main__ to better match the behavior of the
262 262 # normal interpreter.
263 263 user_ns = {'__name__' :'__main__',
264 264 '__builtins__' : __builtin__,
265 265 }
266 266
267 267 if user_global_ns is None:
268 268 user_global_ns = {}
269 269
270 270 # Assign namespaces
271 271 # This is the namespace where all normal user variables live
272 272 self.user_ns = user_ns
273 273 # Embedded instances require a separate namespace for globals.
274 274 # Normally this one is unused by non-embedded instances.
275 275 self.user_global_ns = user_global_ns
276 276 # A namespace to keep track of internal data structures to prevent
277 277 # them from cluttering user-visible stuff. Will be updated later
278 278 self.internal_ns = {}
279 279
280 280 # Namespace of system aliases. Each entry in the alias
281 281 # table must be a 2-tuple of the form (N,name), where N is the number
282 282 # of positional arguments of the alias.
283 283 self.alias_table = {}
284 284
285 285 # A table holding all the namespaces IPython deals with, so that
286 286 # introspection facilities can search easily.
287 287 self.ns_table = {'user':user_ns,
288 288 'user_global':user_global_ns,
289 289 'alias':self.alias_table,
290 290 'internal':self.internal_ns,
291 291 'builtin':__builtin__.__dict__
292 292 }
293 293
294 294 # The user namespace MUST have a pointer to the shell itself.
295 295 self.user_ns[name] = self
296 296
297 297 # We need to insert into sys.modules something that looks like a
298 298 # module but which accesses the IPython namespace, for shelve and
299 299 # pickle to work interactively. Normally they rely on getting
300 300 # everything out of __main__, but for embedding purposes each IPython
301 301 # instance has its own private namespace, so we can't go shoving
302 302 # everything into __main__.
303 303
304 304 # note, however, that we should only do this for non-embedded
305 305 # ipythons, which really mimic the __main__.__dict__ with their own
306 306 # namespace. Embedded instances, on the other hand, should not do
307 307 # this because they need to manage the user local/global namespaces
308 308 # only, but they live within a 'normal' __main__ (meaning, they
309 309 # shouldn't overtake the execution environment of the script they're
310 310 # embedded in).
311 311
312 312 if not embedded:
313 313 try:
314 314 main_name = self.user_ns['__name__']
315 315 except KeyError:
316 316 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
317 317 else:
318 318 #print "pickle hack in place" # dbg
319 319 #print 'main_name:',main_name # dbg
320 320 sys.modules[main_name] = FakeModule(self.user_ns)
321 321
322 322 # List of input with multi-line handling.
323 323 # Fill its zero entry, user counter starts at 1
324 324 self.input_hist = InputList(['\n'])
325 325
326 326 # list of visited directories
327 327 try:
328 328 self.dir_hist = [os.getcwd()]
329 329 except IOError, e:
330 330 self.dir_hist = []
331 331
332 332 # dict of output history
333 333 self.output_hist = {}
334 334
335 335 # dict of things NOT to alias (keywords, builtins and some magics)
336 336 no_alias = {}
337 337 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
338 338 for key in keyword.kwlist + no_alias_magics:
339 339 no_alias[key] = 1
340 340 no_alias.update(__builtin__.__dict__)
341 341 self.no_alias = no_alias
342 342
343 343 # make global variables for user access to these
344 344 self.user_ns['_ih'] = self.input_hist
345 345 self.user_ns['_oh'] = self.output_hist
346 346 self.user_ns['_dh'] = self.dir_hist
347 347
348 348 # user aliases to input and output histories
349 349 self.user_ns['In'] = self.input_hist
350 350 self.user_ns['Out'] = self.output_hist
351 351
352 352 # Object variable to store code object waiting execution. This is
353 353 # used mainly by the multithreaded shells, but it can come in handy in
354 354 # other situations. No need to use a Queue here, since it's a single
355 355 # item which gets cleared once run.
356 356 self.code_to_run = None
357 357
358 358 # escapes for automatic behavior on the command line
359 359 self.ESC_SHELL = '!'
360 360 self.ESC_HELP = '?'
361 361 self.ESC_MAGIC = '%'
362 362 self.ESC_QUOTE = ','
363 363 self.ESC_QUOTE2 = ';'
364 364 self.ESC_PAREN = '/'
365 365
366 366 # And their associated handlers
367 367 self.esc_handlers = {self.ESC_PAREN : self.handle_auto,
368 368 self.ESC_QUOTE : self.handle_auto,
369 369 self.ESC_QUOTE2 : self.handle_auto,
370 370 self.ESC_MAGIC : self.handle_magic,
371 371 self.ESC_HELP : self.handle_help,
372 372 self.ESC_SHELL : self.handle_shell_escape,
373 373 }
374 374
375 375 # class initializations
376 376 Magic.__init__(self,self)
377 377
378 378 # Python source parser/formatter for syntax highlighting
379 379 pyformat = PyColorize.Parser().format
380 380 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
381 381
382 382 # hooks holds pointers used for user-side customizations
383 383 self.hooks = Struct()
384 384
385 385 # Set all default hooks, defined in the IPython.hooks module.
386 386 hooks = IPython.hooks
387 387 for hook_name in hooks.__all__:
388 388 self.set_hook(hook_name,getattr(hooks,hook_name))
389 389
390 390 # Flag to mark unconditional exit
391 391 self.exit_now = False
392 392
393 393 self.usage_min = """\
394 394 An enhanced console for Python.
395 395 Some of its features are:
396 396 - Readline support if the readline library is present.
397 397 - Tab completion in the local namespace.
398 398 - Logging of input, see command-line options.
399 399 - System shell escape via ! , eg !ls.
400 400 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
401 401 - Keeps track of locally defined variables via %who, %whos.
402 402 - Show object information with a ? eg ?x or x? (use ?? for more info).
403 403 """
404 404 if usage: self.usage = usage
405 405 else: self.usage = self.usage_min
406 406
407 407 # Storage
408 408 self.rc = rc # This will hold all configuration information
409 409 self.pager = 'less'
410 410 # temporary files used for various purposes. Deleted at exit.
411 411 self.tempfiles = []
412 412
413 413 # Keep track of readline usage (later set by init_readline)
414 414 self.has_readline = False
415 415
416 416 # template for logfile headers. It gets resolved at runtime by the
417 417 # logstart method.
418 418 self.loghead_tpl = \
419 419 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
420 420 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
421 421 #log# opts = %s
422 422 #log# args = %s
423 423 #log# It is safe to make manual edits below here.
424 424 #log#-----------------------------------------------------------------------
425 425 """
426 426 # for pushd/popd management
427 427 try:
428 428 self.home_dir = get_home_dir()
429 429 except HomeDirError,msg:
430 430 fatal(msg)
431 431
432 432 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
433 433
434 434 # Functions to call the underlying shell.
435 435
436 436 # utility to expand user variables via Itpl
437 437 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
438 438 self.user_ns))
439 439 # The first is similar to os.system, but it doesn't return a value,
440 440 # and it allows interpolation of variables in the user's namespace.
441 441 self.system = lambda cmd: shell(self.var_expand(cmd),
442 442 header='IPython system call: ',
443 443 verbose=self.rc.system_verbose)
444 444 # These are for getoutput and getoutputerror:
445 445 self.getoutput = lambda cmd: \
446 446 getoutput(self.var_expand(cmd),
447 447 header='IPython system call: ',
448 448 verbose=self.rc.system_verbose)
449 449 self.getoutputerror = lambda cmd: \
450 450 getoutputerror(str(ItplNS(cmd.replace('#','\#'),
451 451 self.user_ns)),
452 452 header='IPython system call: ',
453 453 verbose=self.rc.system_verbose)
454 454
455 455 # RegExp for splitting line contents into pre-char//first
456 456 # word-method//rest. For clarity, each group in on one line.
457 457
458 458 # WARNING: update the regexp if the above escapes are changed, as they
459 459 # are hardwired in.
460 460
461 461 # Don't get carried away with trying to make the autocalling catch too
462 462 # much: it's better to be conservative rather than to trigger hidden
463 463 # evals() somewhere and end up causing side effects.
464 464
465 465 self.line_split = re.compile(r'^([\s*,;/])'
466 466 r'([\?\w\.]+\w*\s*)'
467 467 r'(\(?.*$)')
468 468
469 469 # Original re, keep around for a while in case changes break something
470 470 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
471 471 # r'(\s*[\?\w\.]+\w*\s*)'
472 472 # r'(\(?.*$)')
473 473
474 474 # RegExp to identify potential function names
475 475 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
476 476 # RegExp to exclude strings with this start from autocalling
477 477 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
478 478
479 479 # try to catch also methods for stuff in lists/tuples/dicts: off
480 480 # (experimental). For this to work, the line_split regexp would need
481 481 # to be modified so it wouldn't break things at '['. That line is
482 482 # nasty enough that I shouldn't change it until I can test it _well_.
483 483 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
484 484
485 485 # keep track of where we started running (mainly for crash post-mortem)
486 486 self.starting_dir = os.getcwd()
487 487
488 488 # Various switches which can be set
489 489 self.CACHELENGTH = 5000 # this is cheap, it's just text
490 490 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
491 491 self.banner2 = banner2
492 492
493 493 # TraceBack handlers:
494 494
495 495 # Syntax error handler.
496 496 self.SyntaxTB = SyntaxTB(color_scheme='NoColor')
497 497
498 498 # The interactive one is initialized with an offset, meaning we always
499 499 # want to remove the topmost item in the traceback, which is our own
500 500 # internal code. Valid modes: ['Plain','Context','Verbose']
501 501 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
502 502 color_scheme='NoColor',
503 503 tb_offset = 1)
504 504
505 505 # IPython itself shouldn't crash. This will produce a detailed
506 506 # post-mortem if it does. But we only install the crash handler for
507 507 # non-threaded shells, the threaded ones use a normal verbose reporter
508 508 # and lose the crash handler. This is because exceptions in the main
509 509 # thread (such as in GUI code) propagate directly to sys.excepthook,
510 510 # and there's no point in printing crash dumps for every user exception.
511 511 if self.isthreaded:
512 512 sys.excepthook = ultraTB.FormattedTB()
513 513 else:
514 514 from IPython import CrashHandler
515 515 sys.excepthook = CrashHandler.CrashHandler(self)
516 516
517 517 # The instance will store a pointer to this, so that runtime code
518 518 # (such as magics) can access it. This is because during the
519 519 # read-eval loop, it gets temporarily overwritten (to deal with GUI
520 520 # frameworks).
521 521 self.sys_excepthook = sys.excepthook
522 522
523 523 # and add any custom exception handlers the user may have specified
524 524 self.set_custom_exc(*custom_exceptions)
525 525
526 526 # Object inspector
527 527 self.inspector = OInspect.Inspector(OInspect.InspectColors,
528 528 PyColorize.ANSICodeColors,
529 529 'NoColor')
530 530 # indentation management
531 531 self.autoindent = False
532 532 self.indent_current_nsp = 0
533 533 self.indent_current = '' # actual indent string
534 534
535 535 # Make some aliases automatically
536 536 # Prepare list of shell aliases to auto-define
537 537 if os.name == 'posix':
538 538 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
539 539 'mv mv -i','rm rm -i','cp cp -i',
540 540 'cat cat','less less','clear clear',
541 541 # a better ls
542 542 'ls ls -F',
543 543 # long ls
544 544 'll ls -lF',
545 545 # color ls
546 546 'lc ls -F -o --color',
547 547 # ls normal files only
548 548 'lf ls -F -o --color %l | grep ^-',
549 549 # ls symbolic links
550 550 'lk ls -F -o --color %l | grep ^l',
551 551 # directories or links to directories,
552 552 'ldir ls -F -o --color %l | grep /$',
553 553 # things which are executable
554 554 'lx ls -F -o --color %l | grep ^-..x',
555 555 )
556 556 elif os.name in ['nt','dos']:
557 557 auto_alias = ('dir dir /on', 'ls dir /on',
558 558 'ddir dir /ad /on', 'ldir dir /ad /on',
559 559 'mkdir mkdir','rmdir rmdir','echo echo',
560 560 'ren ren','cls cls','copy copy')
561 561 else:
562 562 auto_alias = ()
563 563 self.auto_alias = map(lambda s:s.split(None,1),auto_alias)
564 564 # Call the actual (public) initializer
565 565 self.init_auto_alias()
566 566 # end __init__
567 567
568 568 def post_config_initialization(self):
569 569 """Post configuration init method
570 570
571 571 This is called after the configuration files have been processed to
572 572 'finalize' the initialization."""
573 573
574 574 rc = self.rc
575 575
576 576 # Load readline proper
577 577 if rc.readline:
578 578 self.init_readline()
579 579
580 580 # log system
581 581 self.logger = Logger(self,logfname='ipython_log.py',logmode='rotate')
582 582 # local shortcut, this is used a LOT
583 583 self.log = self.logger.log
584 584
585 585 # Initialize cache, set in/out prompts and printing system
586 586 self.outputcache = CachedOutput(self,
587 587 rc.cache_size,
588 588 rc.pprint,
589 589 input_sep = rc.separate_in,
590 590 output_sep = rc.separate_out,
591 591 output_sep2 = rc.separate_out2,
592 592 ps1 = rc.prompt_in1,
593 593 ps2 = rc.prompt_in2,
594 594 ps_out = rc.prompt_out,
595 595 pad_left = rc.prompts_pad_left)
596 596
597 597 # user may have over-ridden the default print hook:
598 598 try:
599 599 self.outputcache.__class__.display = self.hooks.display
600 600 except AttributeError:
601 601 pass
602 602
603 603 # I don't like assigning globally to sys, because it means when embedding
604 604 # instances, each embedded instance overrides the previous choice. But
605 605 # sys.displayhook seems to be called internally by exec, so I don't see a
606 606 # way around it.
607 607 sys.displayhook = self.outputcache
608 608
609 609 # Set user colors (don't do it in the constructor above so that it
610 610 # doesn't crash if colors option is invalid)
611 611 self.magic_colors(rc.colors)
612 612
613 613 # Set calling of pdb on exceptions
614 614 self.call_pdb = rc.pdb
615 615
616 616 # Load user aliases
617 617 for alias in rc.alias:
618 618 self.magic_alias(alias)
619 619
620 620 # dynamic data that survives through sessions
621 621 # XXX make the filename a config option?
622 622 persist_base = 'persist'
623 623 if rc.profile:
624 624 persist_base += '_%s' % rc.profile
625 625 self.persist_fname = os.path.join(rc.ipythondir,persist_base)
626 626
627 627 try:
628 628 self.persist = pickle.load(file(self.persist_fname))
629 629 except:
630 630 self.persist = {}
631 631
632 632
633 633 for (key, value) in [(k[2:],v) for (k,v) in self.persist.items() if k.startswith('S:')]:
634 634 try:
635 635 obj = pickle.loads(value)
636 636 except:
637 637
638 638 print "Unable to restore variable '%s', ignoring (use %%store -d to forget!)" % key
639 639 print "The error was:",sys.exc_info()[0]
640 640 continue
641 641
642 642
643 643 self.user_ns[key] = obj
644 644
645 645 def add_builtins(self):
646 646 """Store ipython references into the builtin namespace.
647 647
648 648 Some parts of ipython operate via builtins injected here, which hold a
649 649 reference to IPython itself."""
650 650
651 651 builtins_new = dict(__IPYTHON__ = self,
652 652 ip_set_hook = self.set_hook,
653 653 jobs = self.jobs,
654 654 ipmagic = self.ipmagic,
655 655 ipalias = self.ipalias,
656 656 ipsystem = self.ipsystem,
657 657 )
658 658 for biname,bival in builtins_new.items():
659 659 try:
660 660 # store the orignal value so we can restore it
661 661 self.builtins_added[biname] = __builtin__.__dict__[biname]
662 662 except KeyError:
663 663 # or mark that it wasn't defined, and we'll just delete it at
664 664 # cleanup
665 665 self.builtins_added[biname] = Undefined
666 666 __builtin__.__dict__[biname] = bival
667 667
668 668 # Keep in the builtins a flag for when IPython is active. We set it
669 669 # with setdefault so that multiple nested IPythons don't clobber one
670 670 # another. Each will increase its value by one upon being activated,
671 671 # which also gives us a way to determine the nesting level.
672 672 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
673 673
674 674 def clean_builtins(self):
675 675 """Remove any builtins which might have been added by add_builtins, or
676 676 restore overwritten ones to their previous values."""
677 677 for biname,bival in self.builtins_added.items():
678 678 if bival is Undefined:
679 679 del __builtin__.__dict__[biname]
680 680 else:
681 681 __builtin__.__dict__[biname] = bival
682 682 self.builtins_added.clear()
683 683
684 684 def set_hook(self,name,hook):
685 685 """set_hook(name,hook) -> sets an internal IPython hook.
686 686
687 687 IPython exposes some of its internal API as user-modifiable hooks. By
688 688 resetting one of these hooks, you can modify IPython's behavior to
689 689 call at runtime your own routines."""
690 690
691 691 # At some point in the future, this should validate the hook before it
692 692 # accepts it. Probably at least check that the hook takes the number
693 693 # of args it's supposed to.
694 694 setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
695 695
696 696 def set_custom_exc(self,exc_tuple,handler):
697 697 """set_custom_exc(exc_tuple,handler)
698 698
699 699 Set a custom exception handler, which will be called if any of the
700 700 exceptions in exc_tuple occur in the mainloop (specifically, in the
701 701 runcode() method.
702 702
703 703 Inputs:
704 704
705 705 - exc_tuple: a *tuple* of valid exceptions to call the defined
706 706 handler for. It is very important that you use a tuple, and NOT A
707 707 LIST here, because of the way Python's except statement works. If
708 708 you only want to trap a single exception, use a singleton tuple:
709 709
710 710 exc_tuple == (MyCustomException,)
711 711
712 712 - handler: this must be defined as a function with the following
713 713 basic interface: def my_handler(self,etype,value,tb).
714 714
715 715 This will be made into an instance method (via new.instancemethod)
716 716 of IPython itself, and it will be called if any of the exceptions
717 717 listed in the exc_tuple are caught. If the handler is None, an
718 718 internal basic one is used, which just prints basic info.
719 719
720 720 WARNING: by putting in your own exception handler into IPython's main
721 721 execution loop, you run a very good chance of nasty crashes. This
722 722 facility should only be used if you really know what you are doing."""
723 723
724 724 assert type(exc_tuple)==type(()) , \
725 725 "The custom exceptions must be given AS A TUPLE."
726 726
727 727 def dummy_handler(self,etype,value,tb):
728 728 print '*** Simple custom exception handler ***'
729 729 print 'Exception type :',etype
730 730 print 'Exception value:',value
731 731 print 'Traceback :',tb
732 732 print 'Source code :','\n'.join(self.buffer)
733 733
734 734 if handler is None: handler = dummy_handler
735 735
736 736 self.CustomTB = new.instancemethod(handler,self,self.__class__)
737 737 self.custom_exceptions = exc_tuple
738 738
739 739 def set_custom_completer(self,completer,pos=0):
740 740 """set_custom_completer(completer,pos=0)
741 741
742 742 Adds a new custom completer function.
743 743
744 744 The position argument (defaults to 0) is the index in the completers
745 745 list where you want the completer to be inserted."""
746 746
747 747 newcomp = new.instancemethod(completer,self.Completer,
748 748 self.Completer.__class__)
749 749 self.Completer.matchers.insert(pos,newcomp)
750 750
751 751 def _get_call_pdb(self):
752 752 return self._call_pdb
753 753
754 754 def _set_call_pdb(self,val):
755 755
756 756 if val not in (0,1,False,True):
757 757 raise ValueError,'new call_pdb value must be boolean'
758 758
759 759 # store value in instance
760 760 self._call_pdb = val
761 761
762 762 # notify the actual exception handlers
763 763 self.InteractiveTB.call_pdb = val
764 764 if self.isthreaded:
765 765 try:
766 766 self.sys_excepthook.call_pdb = val
767 767 except:
768 768 warn('Failed to activate pdb for threaded exception handler')
769 769
770 770 call_pdb = property(_get_call_pdb,_set_call_pdb,None,
771 771 'Control auto-activation of pdb at exceptions')
772 772
773 773
774 774 # These special functions get installed in the builtin namespace, to
775 775 # provide programmatic (pure python) access to magics, aliases and system
776 776 # calls. This is important for logging, user scripting, and more.
777 777
778 778 # We are basically exposing, via normal python functions, the three
779 779 # mechanisms in which ipython offers special call modes (magics for
780 780 # internal control, aliases for direct system access via pre-selected
781 781 # names, and !cmd for calling arbitrary system commands).
782 782
783 783 def ipmagic(self,arg_s):
784 784 """Call a magic function by name.
785 785
786 786 Input: a string containing the name of the magic function to call and any
787 787 additional arguments to be passed to the magic.
788 788
789 789 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
790 790 prompt:
791 791
792 792 In[1]: %name -opt foo bar
793 793
794 794 To call a magic without arguments, simply use ipmagic('name').
795 795
796 796 This provides a proper Python function to call IPython's magics in any
797 797 valid Python code you can type at the interpreter, including loops and
798 798 compound statements. It is added by IPython to the Python builtin
799 799 namespace upon initialization."""
800 800
801 801 args = arg_s.split(' ',1)
802 802 magic_name = args[0]
803 803 if magic_name.startswith(self.ESC_MAGIC):
804 804 magic_name = magic_name[1:]
805 805 try:
806 806 magic_args = args[1]
807 807 except IndexError:
808 808 magic_args = ''
809 809 fn = getattr(self,'magic_'+magic_name,None)
810 810 if fn is None:
811 811 error("Magic function `%s` not found." % magic_name)
812 812 else:
813 813 magic_args = self.var_expand(magic_args)
814 814 return fn(magic_args)
815 815
816 816 def ipalias(self,arg_s):
817 817 """Call an alias by name.
818 818
819 819 Input: a string containing the name of the alias to call and any
820 820 additional arguments to be passed to the magic.
821 821
822 822 ipalias('name -opt foo bar') is equivalent to typing at the ipython
823 823 prompt:
824 824
825 825 In[1]: name -opt foo bar
826 826
827 827 To call an alias without arguments, simply use ipalias('name').
828 828
829 829 This provides a proper Python function to call IPython's aliases in any
830 830 valid Python code you can type at the interpreter, including loops and
831 831 compound statements. It is added by IPython to the Python builtin
832 832 namespace upon initialization."""
833 833
834 834 args = arg_s.split(' ',1)
835 835 alias_name = args[0]
836 836 try:
837 837 alias_args = args[1]
838 838 except IndexError:
839 839 alias_args = ''
840 840 if alias_name in self.alias_table:
841 841 self.call_alias(alias_name,alias_args)
842 842 else:
843 843 error("Alias `%s` not found." % alias_name)
844 844
845 845 def ipsystem(self,arg_s):
846 846 """Make a system call, using IPython."""
847 847
848 848 self.system(arg_s)
849 849
850 850 def complete(self,text):
851 851 """Return a sorted list of all possible completions on text.
852 852
853 853 Inputs:
854 854
855 855 - text: a string of text to be completed on.
856 856
857 857 This is a wrapper around the completion mechanism, similar to what
858 858 readline does at the command line when the TAB key is hit. By
859 859 exposing it as a method, it can be used by other non-readline
860 860 environments (such as GUIs) for text completion.
861 861
862 862 Simple usage example:
863 863
864 864 In [1]: x = 'hello'
865 865
866 866 In [2]: __IP.complete('x.l')
867 867 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
868 868
869 869 complete = self.Completer.complete
870 870 state = 0
871 871 # use a dict so we get unique keys, since ipyhton's multiple
872 872 # completers can return duplicates.
873 873 comps = {}
874 874 while True:
875 875 newcomp = complete(text,state)
876 876 if newcomp is None:
877 877 break
878 878 comps[newcomp] = 1
879 879 state += 1
880 880 outcomps = comps.keys()
881 881 outcomps.sort()
882 882 return outcomps
883 883
884 884 def set_completer_frame(self, frame=None):
885 885 if frame:
886 886 self.Completer.namespace = frame.f_locals
887 887 self.Completer.global_namespace = frame.f_globals
888 888 else:
889 889 self.Completer.namespace = self.user_ns
890 890 self.Completer.global_namespace = self.user_global_ns
891 891
892 892 def init_auto_alias(self):
893 893 """Define some aliases automatically.
894 894
895 895 These are ALL parameter-less aliases"""
896 896
897 897 for alias,cmd in self.auto_alias:
898 898 self.alias_table[alias] = (0,cmd)
899 899
900 900 def alias_table_validate(self,verbose=0):
901 901 """Update information about the alias table.
902 902
903 903 In particular, make sure no Python keywords/builtins are in it."""
904 904
905 905 no_alias = self.no_alias
906 906 for k in self.alias_table.keys():
907 907 if k in no_alias:
908 908 del self.alias_table[k]
909 909 if verbose:
910 910 print ("Deleting alias <%s>, it's a Python "
911 911 "keyword or builtin." % k)
912 912
913 913 def set_autoindent(self,value=None):
914 914 """Set the autoindent flag, checking for readline support.
915 915
916 916 If called with no arguments, it acts as a toggle."""
917 917
918 918 if not self.has_readline:
919 919 if os.name == 'posix':
920 920 warn("The auto-indent feature requires the readline library")
921 921 self.autoindent = 0
922 922 return
923 923 if value is None:
924 924 self.autoindent = not self.autoindent
925 925 else:
926 926 self.autoindent = value
927 927
928 928 def rc_set_toggle(self,rc_field,value=None):
929 929 """Set or toggle a field in IPython's rc config. structure.
930 930
931 931 If called with no arguments, it acts as a toggle.
932 932
933 933 If called with a non-existent field, the resulting AttributeError
934 934 exception will propagate out."""
935 935
936 936 rc_val = getattr(self.rc,rc_field)
937 937 if value is None:
938 938 value = not rc_val
939 939 setattr(self.rc,rc_field,value)
940 940
941 941 def user_setup(self,ipythondir,rc_suffix,mode='install'):
942 942 """Install the user configuration directory.
943 943
944 944 Can be called when running for the first time or to upgrade the user's
945 945 .ipython/ directory with the mode parameter. Valid modes are 'install'
946 946 and 'upgrade'."""
947 947
948 948 def wait():
949 949 try:
950 950 raw_input("Please press <RETURN> to start IPython.")
951 951 except EOFError:
952 952 print >> Term.cout
953 953 print '*'*70
954 954
955 955 cwd = os.getcwd() # remember where we started
956 956 glb = glob.glob
957 957 print '*'*70
958 958 if mode == 'install':
959 959 print \
960 960 """Welcome to IPython. I will try to create a personal configuration directory
961 961 where you can customize many aspects of IPython's functionality in:\n"""
962 962 else:
963 963 print 'I am going to upgrade your configuration in:'
964 964
965 965 print ipythondir
966 966
967 967 rcdirend = os.path.join('IPython','UserConfig')
968 968 cfg = lambda d: os.path.join(d,rcdirend)
969 969 try:
970 970 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
971 971 except IOError:
972 972 warning = """
973 973 Installation error. IPython's directory was not found.
974 974
975 975 Check the following:
976 976
977 977 The ipython/IPython directory should be in a directory belonging to your
978 978 PYTHONPATH environment variable (that is, it should be in a directory
979 979 belonging to sys.path). You can copy it explicitly there or just link to it.
980 980
981 981 IPython will proceed with builtin defaults.
982 982 """
983 983 warn(warning)
984 984 wait()
985 985 return
986 986
987 987 if mode == 'install':
988 988 try:
989 989 shutil.copytree(rcdir,ipythondir)
990 990 os.chdir(ipythondir)
991 991 rc_files = glb("ipythonrc*")
992 992 for rc_file in rc_files:
993 993 os.rename(rc_file,rc_file+rc_suffix)
994 994 except:
995 995 warning = """
996 996
997 997 There was a problem with the installation:
998 998 %s
999 999 Try to correct it or contact the developers if you think it's a bug.
1000 1000 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
1001 1001 warn(warning)
1002 1002 wait()
1003 1003 return
1004 1004
1005 1005 elif mode == 'upgrade':
1006 1006 try:
1007 1007 os.chdir(ipythondir)
1008 1008 except:
1009 1009 print """
1010 1010 Can not upgrade: changing to directory %s failed. Details:
1011 1011 %s
1012 1012 """ % (ipythondir,sys.exc_info()[1])
1013 1013 wait()
1014 1014 return
1015 1015 else:
1016 1016 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
1017 1017 for new_full_path in sources:
1018 1018 new_filename = os.path.basename(new_full_path)
1019 1019 if new_filename.startswith('ipythonrc'):
1020 1020 new_filename = new_filename + rc_suffix
1021 1021 # The config directory should only contain files, skip any
1022 1022 # directories which may be there (like CVS)
1023 1023 if os.path.isdir(new_full_path):
1024 1024 continue
1025 1025 if os.path.exists(new_filename):
1026 1026 old_file = new_filename+'.old'
1027 1027 if os.path.exists(old_file):
1028 1028 os.remove(old_file)
1029 1029 os.rename(new_filename,old_file)
1030 1030 shutil.copy(new_full_path,new_filename)
1031 1031 else:
1032 1032 raise ValueError,'unrecognized mode for install:',`mode`
1033 1033
1034 1034 # Fix line-endings to those native to each platform in the config
1035 1035 # directory.
1036 1036 try:
1037 1037 os.chdir(ipythondir)
1038 1038 except:
1039 1039 print """
1040 1040 Problem: changing to directory %s failed.
1041 1041 Details:
1042 1042 %s
1043 1043
1044 1044 Some configuration files may have incorrect line endings. This should not
1045 1045 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
1046 1046 wait()
1047 1047 else:
1048 1048 for fname in glb('ipythonrc*'):
1049 1049 try:
1050 1050 native_line_ends(fname,backup=0)
1051 1051 except IOError:
1052 1052 pass
1053 1053
1054 1054 if mode == 'install':
1055 1055 print """
1056 1056 Successful installation!
1057 1057
1058 1058 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
1059 1059 IPython manual (there are both HTML and PDF versions supplied with the
1060 1060 distribution) to make sure that your system environment is properly configured
1061 1061 to take advantage of IPython's features."""
1062 1062 else:
1063 1063 print """
1064 1064 Successful upgrade!
1065 1065
1066 1066 All files in your directory:
1067 1067 %(ipythondir)s
1068 1068 which would have been overwritten by the upgrade were backed up with a .old
1069 1069 extension. If you had made particular customizations in those files you may
1070 1070 want to merge them back into the new files.""" % locals()
1071 1071 wait()
1072 1072 os.chdir(cwd)
1073 1073 # end user_setup()
1074 1074
1075 1075 def atexit_operations(self):
1076 1076 """This will be executed at the time of exit.
1077 1077
1078 1078 Saving of persistent data should be performed here. """
1079 1079
1080 1080 # input history
1081 1081 self.savehist()
1082 1082
1083 1083 # Cleanup all tempfiles left around
1084 1084 for tfile in self.tempfiles:
1085 1085 try:
1086 1086 os.unlink(tfile)
1087 1087 except OSError:
1088 1088 pass
1089 1089
1090 1090 # save the "persistent data" catch-all dictionary
1091 1091 try:
1092 1092 pickle.dump(self.persist, open(self.persist_fname,"w"))
1093 1093 except:
1094 1094 print "*** ERROR *** persistent data saving failed."
1095 1095
1096 1096 def savehist(self):
1097 1097 """Save input history to a file (via readline library)."""
1098 1098 try:
1099 1099 self.readline.write_history_file(self.histfile)
1100 1100 except:
1101 1101 print 'Unable to save IPython command history to file: ' + \
1102 1102 `self.histfile`
1103 1103
1104 1104 def pre_readline(self):
1105 1105 """readline hook to be used at the start of each line.
1106 1106
1107 1107 Currently it handles auto-indent only."""
1108 1108
1109 1109 self.readline.insert_text(self.indent_current)
1110 1110
1111 1111 def init_readline(self):
1112 1112 """Command history completion/saving/reloading."""
1113 1113 try:
1114 1114 import readline
1115 1115 except ImportError:
1116 1116 self.has_readline = 0
1117 1117 self.readline = None
1118 1118 # no point in bugging windows users with this every time:
1119 1119 if os.name == 'posix':
1120 1120 warn('Readline services not available on this platform.')
1121 1121 else:
1122 1122 import atexit
1123 1123 from IPython.completer import IPCompleter
1124 1124 self.Completer = IPCompleter(self,
1125 1125 self.user_ns,
1126 1126 self.user_global_ns,
1127 1127 self.rc.readline_omit__names,
1128 1128 self.alias_table)
1129 1129
1130 1130 # Platform-specific configuration
1131 1131 if os.name == 'nt':
1132 1132 self.readline_startup_hook = readline.set_pre_input_hook
1133 1133 else:
1134 1134 self.readline_startup_hook = readline.set_startup_hook
1135 1135
1136 1136 # Load user's initrc file (readline config)
1137 1137 inputrc_name = os.environ.get('INPUTRC')
1138 1138 if inputrc_name is None:
1139 1139 home_dir = get_home_dir()
1140 1140 if home_dir is not None:
1141 1141 inputrc_name = os.path.join(home_dir,'.inputrc')
1142 1142 if os.path.isfile(inputrc_name):
1143 1143 try:
1144 1144 readline.read_init_file(inputrc_name)
1145 1145 except:
1146 1146 warn('Problems reading readline initialization file <%s>'
1147 1147 % inputrc_name)
1148 1148
1149 1149 self.has_readline = 1
1150 1150 self.readline = readline
1151 1151 # save this in sys so embedded copies can restore it properly
1152 1152 sys.ipcompleter = self.Completer.complete
1153 1153 readline.set_completer(self.Completer.complete)
1154 1154
1155 1155 # Configure readline according to user's prefs
1156 1156 for rlcommand in self.rc.readline_parse_and_bind:
1157 1157 readline.parse_and_bind(rlcommand)
1158 1158
1159 1159 # remove some chars from the delimiters list
1160 1160 delims = readline.get_completer_delims()
1161 1161 delims = delims.translate(string._idmap,
1162 1162 self.rc.readline_remove_delims)
1163 1163 readline.set_completer_delims(delims)
1164 1164 # otherwise we end up with a monster history after a while:
1165 1165 readline.set_history_length(1000)
1166 1166 try:
1167 1167 #print '*** Reading readline history' # dbg
1168 1168 readline.read_history_file(self.histfile)
1169 1169 except IOError:
1170 1170 pass # It doesn't exist yet.
1171 1171
1172 1172 atexit.register(self.atexit_operations)
1173 1173 del atexit
1174 1174
1175 1175 # Configure auto-indent for all platforms
1176 1176 self.set_autoindent(self.rc.autoindent)
1177 1177
1178 1178 def _should_recompile(self,e):
1179 1179 """Utility routine for edit_syntax_error"""
1180 1180
1181 1181 if e.filename in ('<ipython console>','<input>','<string>',
1182 1182 '<console>'):
1183 1183 return False
1184 1184 try:
1185 1185 if not ask_yes_no('Return to editor to correct syntax error? '
1186 1186 '[Y/n] ','y'):
1187 1187 return False
1188 1188 except EOFError:
1189 1189 return False
1190 1190
1191 1191 def int0(x):
1192 1192 try:
1193 1193 return int(x)
1194 1194 except TypeError:
1195 1195 return 0
1196 1196 # always pass integer line and offset values to editor hook
1197 1197 self.hooks.fix_error_editor(e.filename,
1198 1198 int0(e.lineno),int0(e.offset),e.msg)
1199 1199 return True
1200 1200
1201 1201 def edit_syntax_error(self):
1202 1202 """The bottom half of the syntax error handler called in the main loop.
1203 1203
1204 1204 Loop until syntax error is fixed or user cancels.
1205 1205 """
1206 1206
1207 1207 while self.SyntaxTB.last_syntax_error:
1208 1208 # copy and clear last_syntax_error
1209 1209 err = self.SyntaxTB.clear_err_state()
1210 1210 if not self._should_recompile(err):
1211 1211 return
1212 1212 try:
1213 1213 # may set last_syntax_error again if a SyntaxError is raised
1214 1214 self.safe_execfile(err.filename,self.shell.user_ns)
1215 1215 except:
1216 1216 self.showtraceback()
1217 1217 else:
1218 1218 f = file(err.filename)
1219 1219 try:
1220 1220 sys.displayhook(f.read())
1221 1221 finally:
1222 1222 f.close()
1223 1223
1224 1224 def showsyntaxerror(self, filename=None):
1225 1225 """Display the syntax error that just occurred.
1226 1226
1227 1227 This doesn't display a stack trace because there isn't one.
1228 1228
1229 1229 If a filename is given, it is stuffed in the exception instead
1230 1230 of what was there before (because Python's parser always uses
1231 1231 "<string>" when reading from a string).
1232 1232 """
1233 1233 etype, value, last_traceback = sys.exc_info()
1234 1234 if filename and etype is SyntaxError:
1235 1235 # Work hard to stuff the correct filename in the exception
1236 1236 try:
1237 1237 msg, (dummy_filename, lineno, offset, line) = value
1238 1238 except:
1239 1239 # Not the format we expect; leave it alone
1240 1240 pass
1241 1241 else:
1242 1242 # Stuff in the right filename
1243 1243 try:
1244 1244 # Assume SyntaxError is a class exception
1245 1245 value = SyntaxError(msg, (filename, lineno, offset, line))
1246 1246 except:
1247 1247 # If that failed, assume SyntaxError is a string
1248 1248 value = msg, (filename, lineno, offset, line)
1249 1249 self.SyntaxTB(etype,value,[])
1250 1250
1251 1251 def debugger(self):
1252 1252 """Call the pdb debugger."""
1253 1253
1254 1254 if not self.rc.pdb:
1255 1255 return
1256 1256 pdb.pm()
1257 1257
1258 1258 def showtraceback(self,exc_tuple = None,filename=None):
1259 1259 """Display the exception that just occurred."""
1260 1260
1261 1261 # Though this won't be called by syntax errors in the input line,
1262 1262 # there may be SyntaxError cases whith imported code.
1263 1263 if exc_tuple is None:
1264 1264 type, value, tb = sys.exc_info()
1265 1265 else:
1266 1266 type, value, tb = exc_tuple
1267 1267 if type is SyntaxError:
1268 1268 self.showsyntaxerror(filename)
1269 1269 else:
1270 1270 self.InteractiveTB()
1271 1271 if self.InteractiveTB.call_pdb and self.has_readline:
1272 1272 # pdb mucks up readline, fix it back
1273 1273 self.readline.set_completer(self.Completer.complete)
1274 1274
1275 1275 def mainloop(self,banner=None):
1276 1276 """Creates the local namespace and starts the mainloop.
1277 1277
1278 1278 If an optional banner argument is given, it will override the
1279 1279 internally created default banner."""
1280 1280
1281 1281 if self.rc.c: # Emulate Python's -c option
1282 1282 self.exec_init_cmd()
1283 1283 if banner is None:
1284 1284 if self.rc.banner:
1285 1285 banner = self.BANNER+self.banner2
1286 1286 else:
1287 1287 banner = ''
1288 1288 self.interact(banner)
1289 1289
1290 1290 def exec_init_cmd(self):
1291 1291 """Execute a command given at the command line.
1292 1292
1293 1293 This emulates Python's -c option."""
1294 1294
1295 1295 sys.argv = ['-c']
1296 1296 self.push(self.rc.c)
1297 1297
1298 1298 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1299 1299 """Embeds IPython into a running python program.
1300 1300
1301 1301 Input:
1302 1302
1303 1303 - header: An optional header message can be specified.
1304 1304
1305 1305 - local_ns, global_ns: working namespaces. If given as None, the
1306 1306 IPython-initialized one is updated with __main__.__dict__, so that
1307 1307 program variables become visible but user-specific configuration
1308 1308 remains possible.
1309 1309
1310 1310 - stack_depth: specifies how many levels in the stack to go to
1311 1311 looking for namespaces (when local_ns and global_ns are None). This
1312 1312 allows an intermediate caller to make sure that this function gets
1313 1313 the namespace from the intended level in the stack. By default (0)
1314 1314 it will get its locals and globals from the immediate caller.
1315 1315
1316 1316 Warning: it's possible to use this in a program which is being run by
1317 1317 IPython itself (via %run), but some funny things will happen (a few
1318 1318 globals get overwritten). In the future this will be cleaned up, as
1319 1319 there is no fundamental reason why it can't work perfectly."""
1320 1320
1321 1321 # Get locals and globals from caller
1322 1322 if local_ns is None or global_ns is None:
1323 1323 call_frame = sys._getframe(stack_depth).f_back
1324 1324
1325 1325 if local_ns is None:
1326 1326 local_ns = call_frame.f_locals
1327 1327 if global_ns is None:
1328 1328 global_ns = call_frame.f_globals
1329 1329
1330 1330 # Update namespaces and fire up interpreter
1331 1331
1332 1332 # The global one is easy, we can just throw it in
1333 1333 self.user_global_ns = global_ns
1334 1334
1335 1335 # but the user/local one is tricky: ipython needs it to store internal
1336 1336 # data, but we also need the locals. We'll copy locals in the user
1337 1337 # one, but will track what got copied so we can delete them at exit.
1338 1338 # This is so that a later embedded call doesn't see locals from a
1339 1339 # previous call (which most likely existed in a separate scope).
1340 1340 local_varnames = local_ns.keys()
1341 1341 self.user_ns.update(local_ns)
1342 1342
1343 1343 # Patch for global embedding to make sure that things don't overwrite
1344 1344 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1345 1345 # FIXME. Test this a bit more carefully (the if.. is new)
1346 1346 if local_ns is None and global_ns is None:
1347 1347 self.user_global_ns.update(__main__.__dict__)
1348 1348
1349 1349 # make sure the tab-completer has the correct frame information, so it
1350 1350 # actually completes using the frame's locals/globals
1351 1351 self.set_completer_frame()
1352 1352
1353 1353 # before activating the interactive mode, we need to make sure that
1354 1354 # all names in the builtin namespace needed by ipython point to
1355 1355 # ourselves, and not to other instances.
1356 1356 self.add_builtins()
1357 1357
1358 1358 self.interact(header)
1359 1359
1360 1360 # now, purge out the user namespace from anything we might have added
1361 1361 # from the caller's local namespace
1362 1362 delvar = self.user_ns.pop
1363 1363 for var in local_varnames:
1364 1364 delvar(var,None)
1365 1365 # and clean builtins we may have overridden
1366 1366 self.clean_builtins()
1367 1367
1368 1368 def interact(self, banner=None):
1369 1369 """Closely emulate the interactive Python console.
1370 1370
1371 1371 The optional banner argument specify the banner to print
1372 1372 before the first interaction; by default it prints a banner
1373 1373 similar to the one printed by the real Python interpreter,
1374 1374 followed by the current class name in parentheses (so as not
1375 1375 to confuse this with the real interpreter -- since it's so
1376 1376 close!).
1377 1377
1378 1378 """
1379 1379 cprt = 'Type "copyright", "credits" or "license" for more information.'
1380 1380 if banner is None:
1381 1381 self.write("Python %s on %s\n%s\n(%s)\n" %
1382 1382 (sys.version, sys.platform, cprt,
1383 1383 self.__class__.__name__))
1384 1384 else:
1385 1385 self.write(banner)
1386 1386
1387 1387 more = 0
1388 1388
1389 1389 # Mark activity in the builtins
1390 1390 __builtin__.__dict__['__IPYTHON__active'] += 1
1391 1391
1392 1392 # exit_now is set by a call to %Exit or %Quit
1393 1393 self.exit_now = False
1394 1394 while not self.exit_now:
1395 1395
1396 1396 try:
1397 1397 if more:
1398 1398 prompt = self.outputcache.prompt2
1399 1399 if self.autoindent:
1400 1400 self.readline_startup_hook(self.pre_readline)
1401 1401 else:
1402 1402 prompt = self.outputcache.prompt1
1403 1403 try:
1404 1404 line = self.raw_input(prompt,more)
1405 1405 if self.autoindent:
1406 1406 self.readline_startup_hook(None)
1407 1407 except EOFError:
1408 1408 if self.autoindent:
1409 1409 self.readline_startup_hook(None)
1410 1410 self.write("\n")
1411 1411 self.exit()
1412 1412 else:
1413 1413 more = self.push(line)
1414 1414
1415 1415 if (self.SyntaxTB.last_syntax_error and
1416 1416 self.rc.autoedit_syntax):
1417 1417 self.edit_syntax_error()
1418 1418
1419 1419 except KeyboardInterrupt:
1420 1420 self.write("\nKeyboardInterrupt\n")
1421 1421 self.resetbuffer()
1422 1422 more = 0
1423 1423 # keep cache in sync with the prompt counter:
1424 1424 self.outputcache.prompt_count -= 1
1425 1425
1426 1426 if self.autoindent:
1427 1427 self.indent_current_nsp = 0
1428 1428 self.indent_current = ' '* self.indent_current_nsp
1429 1429
1430 1430 except bdb.BdbQuit:
1431 1431 warn("The Python debugger has exited with a BdbQuit exception.\n"
1432 1432 "Because of how pdb handles the stack, it is impossible\n"
1433 1433 "for IPython to properly format this particular exception.\n"
1434 1434 "IPython will resume normal operation.")
1435 1435
1436 1436 # We are off again...
1437 1437 __builtin__.__dict__['__IPYTHON__active'] -= 1
1438 1438
1439 1439 def excepthook(self, type, value, tb):
1440 1440 """One more defense for GUI apps that call sys.excepthook.
1441 1441
1442 1442 GUI frameworks like wxPython trap exceptions and call
1443 1443 sys.excepthook themselves. I guess this is a feature that
1444 1444 enables them to keep running after exceptions that would
1445 1445 otherwise kill their mainloop. This is a bother for IPython
1446 1446 which excepts to catch all of the program exceptions with a try:
1447 1447 except: statement.
1448 1448
1449 1449 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1450 1450 any app directly invokes sys.excepthook, it will look to the user like
1451 1451 IPython crashed. In order to work around this, we can disable the
1452 1452 CrashHandler and replace it with this excepthook instead, which prints a
1453 1453 regular traceback using our InteractiveTB. In this fashion, apps which
1454 1454 call sys.excepthook will generate a regular-looking exception from
1455 1455 IPython, and the CrashHandler will only be triggered by real IPython
1456 1456 crashes.
1457 1457
1458 1458 This hook should be used sparingly, only in places which are not likely
1459 1459 to be true IPython errors.
1460 1460 """
1461 1461
1462 1462 self.InteractiveTB(type, value, tb, tb_offset=0)
1463 1463 if self.InteractiveTB.call_pdb and self.has_readline:
1464 1464 self.readline.set_completer(self.Completer.complete)
1465 1465
1466 1466 def call_alias(self,alias,rest=''):
1467 1467 """Call an alias given its name and the rest of the line.
1468 1468
1469 1469 This function MUST be given a proper alias, because it doesn't make
1470 1470 any checks when looking up into the alias table. The caller is
1471 1471 responsible for invoking it only with a valid alias."""
1472 1472
1473 1473 #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg
1474 1474 nargs,cmd = self.alias_table[alias]
1475 1475 # Expand the %l special to be the user's input line
1476 1476 if cmd.find('%l') >= 0:
1477 1477 cmd = cmd.replace('%l',rest)
1478 1478 rest = ''
1479 1479 if nargs==0:
1480 1480 # Simple, argument-less aliases
1481 1481 cmd = '%s %s' % (cmd,rest)
1482 1482 else:
1483 1483 # Handle aliases with positional arguments
1484 1484 args = rest.split(None,nargs)
1485 1485 if len(args)< nargs:
1486 1486 error('Alias <%s> requires %s arguments, %s given.' %
1487 1487 (alias,nargs,len(args)))
1488 1488 return
1489 1489 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1490 1490 # Now call the macro, evaluating in the user's namespace
1491 1491 try:
1492 1492 self.system(cmd)
1493 1493 except:
1494 1494 self.showtraceback()
1495 1495
1496 1496 def autoindent_update(self,line):
1497 1497 """Keep track of the indent level."""
1498 1498 if self.autoindent:
1499 1499 if line:
1500 1500 ini_spaces = ini_spaces_re.match(line)
1501 1501 if ini_spaces:
1502 1502 nspaces = ini_spaces.end()
1503 1503 else:
1504 1504 nspaces = 0
1505 1505 self.indent_current_nsp = nspaces
1506 1506
1507 1507 if line[-1] == ':':
1508 1508 self.indent_current_nsp += 4
1509 1509 elif dedent_re.match(line):
1510 1510 self.indent_current_nsp -= 4
1511 1511 else:
1512 1512 self.indent_current_nsp = 0
1513 1513
1514 1514 # indent_current is the actual string to be inserted
1515 1515 # by the readline hooks for indentation
1516 1516 self.indent_current = ' '* self.indent_current_nsp
1517 1517
1518 1518 def runlines(self,lines):
1519 1519 """Run a string of one or more lines of source.
1520 1520
1521 1521 This method is capable of running a string containing multiple source
1522 1522 lines, as if they had been entered at the IPython prompt. Since it
1523 1523 exposes IPython's processing machinery, the given strings can contain
1524 1524 magic calls (%magic), special shell access (!cmd), etc."""
1525 1525
1526 1526 # We must start with a clean buffer, in case this is run from an
1527 1527 # interactive IPython session (via a magic, for example).
1528 1528 self.resetbuffer()
1529 1529 lines = lines.split('\n')
1530 1530 more = 0
1531 1531 for line in lines:
1532 1532 # skip blank lines so we don't mess up the prompt counter, but do
1533 1533 # NOT skip even a blank line if we are in a code block (more is
1534 1534 # true)
1535 1535 if line or more:
1536 1536 more = self.push(self.prefilter(line,more))
1537 1537 # IPython's runsource returns None if there was an error
1538 1538 # compiling the code. This allows us to stop processing right
1539 1539 # away, so the user gets the error message at the right place.
1540 1540 if more is None:
1541 1541 break
1542 1542 # final newline in case the input didn't have it, so that the code
1543 1543 # actually does get executed
1544 1544 if more:
1545 1545 self.push('\n')
1546 1546
1547 1547 def runsource(self, source, filename='<input>', symbol='single'):
1548 1548 """Compile and run some source in the interpreter.
1549 1549
1550 1550 Arguments are as for compile_command().
1551 1551
1552 1552 One several things can happen:
1553 1553
1554 1554 1) The input is incorrect; compile_command() raised an
1555 1555 exception (SyntaxError or OverflowError). A syntax traceback
1556 1556 will be printed by calling the showsyntaxerror() method.
1557 1557
1558 1558 2) The input is incomplete, and more input is required;
1559 1559 compile_command() returned None. Nothing happens.
1560 1560
1561 1561 3) The input is complete; compile_command() returned a code
1562 1562 object. The code is executed by calling self.runcode() (which
1563 1563 also handles run-time exceptions, except for SystemExit).
1564 1564
1565 1565 The return value is:
1566 1566
1567 1567 - True in case 2
1568 1568
1569 1569 - False in the other cases, unless an exception is raised, where
1570 1570 None is returned instead. This can be used by external callers to
1571 1571 know whether to continue feeding input or not.
1572 1572
1573 1573 The return value can be used to decide whether to use sys.ps1 or
1574 1574 sys.ps2 to prompt the next line."""
1575 1575
1576 1576 try:
1577 1577 code = self.compile(source,filename,symbol)
1578 1578 except (OverflowError, SyntaxError, ValueError):
1579 1579 # Case 1
1580 1580 self.showsyntaxerror(filename)
1581 1581 return None
1582 1582
1583 1583 if code is None:
1584 1584 # Case 2
1585 1585 return True
1586 1586
1587 1587 # Case 3
1588 1588 # We store the code object so that threaded shells and
1589 1589 # custom exception handlers can access all this info if needed.
1590 1590 # The source corresponding to this can be obtained from the
1591 1591 # buffer attribute as '\n'.join(self.buffer).
1592 1592 self.code_to_run = code
1593 1593 # now actually execute the code object
1594 1594 if self.runcode(code) == 0:
1595 1595 return False
1596 1596 else:
1597 1597 return None
1598 1598
1599 1599 def runcode(self,code_obj):
1600 1600 """Execute a code object.
1601 1601
1602 1602 When an exception occurs, self.showtraceback() is called to display a
1603 1603 traceback.
1604 1604
1605 1605 Return value: a flag indicating whether the code to be run completed
1606 1606 successfully:
1607 1607
1608 1608 - 0: successful execution.
1609 1609 - 1: an error occurred.
1610 1610 """
1611 1611
1612 1612 # Set our own excepthook in case the user code tries to call it
1613 1613 # directly, so that the IPython crash handler doesn't get triggered
1614 1614 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1615 1615
1616 1616 # we save the original sys.excepthook in the instance, in case config
1617 1617 # code (such as magics) needs access to it.
1618 1618 self.sys_excepthook = old_excepthook
1619 1619 outflag = 1 # happens in more places, so it's easier as default
1620 1620 try:
1621 1621 try:
1622 1622 # Embedded instances require separate global/local namespaces
1623 1623 # so they can see both the surrounding (local) namespace and
1624 1624 # the module-level globals when called inside another function.
1625 1625 if self.embedded:
1626 1626 exec code_obj in self.user_global_ns, self.user_ns
1627 1627 # Normal (non-embedded) instances should only have a single
1628 1628 # namespace for user code execution, otherwise functions won't
1629 1629 # see interactive top-level globals.
1630 1630 else:
1631 1631 exec code_obj in self.user_ns
1632 1632 finally:
1633 1633 # Reset our crash handler in place
1634 1634 sys.excepthook = old_excepthook
1635 1635 except SystemExit:
1636 1636 self.resetbuffer()
1637 1637 self.showtraceback()
1638 1638 warn("Type exit or quit to exit IPython "
1639 1639 "(%Exit or %Quit do so unconditionally).",level=1)
1640 1640 except self.custom_exceptions:
1641 1641 etype,value,tb = sys.exc_info()
1642 1642 self.CustomTB(etype,value,tb)
1643 1643 except:
1644 1644 self.showtraceback()
1645 1645 else:
1646 1646 outflag = 0
1647 1647 if softspace(sys.stdout, 0):
1648 1648 print
1649 1649 # Flush out code object which has been run (and source)
1650 1650 self.code_to_run = None
1651 1651 return outflag
1652 1652
1653 1653 def push(self, line):
1654 1654 """Push a line to the interpreter.
1655 1655
1656 1656 The line should not have a trailing newline; it may have
1657 1657 internal newlines. The line is appended to a buffer and the
1658 1658 interpreter's runsource() method is called with the
1659 1659 concatenated contents of the buffer as source. If this
1660 1660 indicates that the command was executed or invalid, the buffer
1661 1661 is reset; otherwise, the command is incomplete, and the buffer
1662 1662 is left as it was after the line was appended. The return
1663 1663 value is 1 if more input is required, 0 if the line was dealt
1664 1664 with in some way (this is the same as runsource()).
1665 1665 """
1666 1666
1667 1667 # autoindent management should be done here, and not in the
1668 1668 # interactive loop, since that one is only seen by keyboard input. We
1669 1669 # need this done correctly even for code run via runlines (which uses
1670 1670 # push).
1671 1671
1672 1672 #print 'push line: <%s>' % line # dbg
1673 1673 self.autoindent_update(line)
1674 1674
1675 1675 self.buffer.append(line)
1676 1676 more = self.runsource('\n'.join(self.buffer), self.filename)
1677 1677 if not more:
1678 1678 self.resetbuffer()
1679 1679 return more
1680 1680
1681 1681 def resetbuffer(self):
1682 1682 """Reset the input buffer."""
1683 1683 self.buffer[:] = []
1684 1684
1685 1685 def raw_input(self,prompt='',continue_prompt=False):
1686 1686 """Write a prompt and read a line.
1687 1687
1688 1688 The returned line does not include the trailing newline.
1689 1689 When the user enters the EOF key sequence, EOFError is raised.
1690 1690
1691 1691 Optional inputs:
1692 1692
1693 1693 - prompt(''): a string to be printed to prompt the user.
1694 1694
1695 1695 - continue_prompt(False): whether this line is the first one or a
1696 1696 continuation in a sequence of inputs.
1697 1697 """
1698 1698
1699 1699 line = raw_input_original(prompt)
1700 1700 # Try to be reasonably smart about not re-indenting pasted input more
1701 1701 # than necessary. We do this by trimming out the auto-indent initial
1702 1702 # spaces, if the user's actual input started itself with whitespace.
1703 1703 if self.autoindent:
1704 1704 line2 = line[self.indent_current_nsp:]
1705 1705 if line2[0:1] in (' ','\t'):
1706 1706 line = line2
1707 1707 return self.prefilter(line,continue_prompt)
1708 1708
1709 1709 def split_user_input(self,line):
1710 1710 """Split user input into pre-char, function part and rest."""
1711 1711
1712 1712 lsplit = self.line_split.match(line)
1713 1713 if lsplit is None: # no regexp match returns None
1714 1714 try:
1715 1715 iFun,theRest = line.split(None,1)
1716 1716 except ValueError:
1717 1717 iFun,theRest = line,''
1718 1718 pre = re.match('^(\s*)(.*)',line).groups()[0]
1719 1719 else:
1720 1720 pre,iFun,theRest = lsplit.groups()
1721 1721
1722 1722 #print 'line:<%s>' % line # dbg
1723 1723 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
1724 1724 return pre,iFun.strip(),theRest
1725 1725
1726 1726 def _prefilter(self, line, continue_prompt):
1727 1727 """Calls different preprocessors, depending on the form of line."""
1728 1728
1729 1729 # All handlers *must* return a value, even if it's blank ('').
1730 1730
1731 1731 # Lines are NOT logged here. Handlers should process the line as
1732 1732 # needed, update the cache AND log it (so that the input cache array
1733 1733 # stays synced).
1734 1734
1735 1735 # This function is _very_ delicate, and since it's also the one which
1736 1736 # determines IPython's response to user input, it must be as efficient
1737 1737 # as possible. For this reason it has _many_ returns in it, trying
1738 1738 # always to exit as quickly as it can figure out what it needs to do.
1739 1739
1740 1740 # This function is the main responsible for maintaining IPython's
1741 1741 # behavior respectful of Python's semantics. So be _very_ careful if
1742 1742 # making changes to anything here.
1743 1743
1744 1744 #.....................................................................
1745 1745 # Code begins
1746 1746
1747 1747 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
1748 1748
1749 1749 # save the line away in case we crash, so the post-mortem handler can
1750 1750 # record it
1751 1751 self._last_input_line = line
1752 1752
1753 1753 #print '***line: <%s>' % line # dbg
1754 1754
1755 1755 # the input history needs to track even empty lines
1756 1756 if not line.strip():
1757 1757 if not continue_prompt:
1758 1758 self.outputcache.prompt_count -= 1
1759 1759 return self.handle_normal(line,continue_prompt)
1760 1760 #return self.handle_normal('',continue_prompt)
1761 1761
1762 1762 # print '***cont',continue_prompt # dbg
1763 1763 # special handlers are only allowed for single line statements
1764 1764 if continue_prompt and not self.rc.multi_line_specials:
1765 1765 return self.handle_normal(line,continue_prompt)
1766 1766
1767 1767 # For the rest, we need the structure of the input
1768 1768 pre,iFun,theRest = self.split_user_input(line)
1769 1769 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1770 1770
1771 1771 # First check for explicit escapes in the last/first character
1772 1772 handler = None
1773 1773 if line[-1] == self.ESC_HELP:
1774 1774 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
1775 1775 if handler is None:
1776 1776 # look at the first character of iFun, NOT of line, so we skip
1777 1777 # leading whitespace in multiline input
1778 1778 handler = self.esc_handlers.get(iFun[0:1])
1779 1779 if handler is not None:
1780 1780 return handler(line,continue_prompt,pre,iFun,theRest)
1781 1781 # Emacs ipython-mode tags certain input lines
1782 1782 if line.endswith('# PYTHON-MODE'):
1783 1783 return self.handle_emacs(line,continue_prompt)
1784 1784
1785 1785 # Next, check if we can automatically execute this thing
1786 1786
1787 1787 # Allow ! in multi-line statements if multi_line_specials is on:
1788 1788 if continue_prompt and self.rc.multi_line_specials and \
1789 1789 iFun.startswith(self.ESC_SHELL):
1790 1790 return self.handle_shell_escape(line,continue_prompt,
1791 1791 pre=pre,iFun=iFun,
1792 1792 theRest=theRest)
1793 1793
1794 1794 # Let's try to find if the input line is a magic fn
1795 1795 oinfo = None
1796 1796 if hasattr(self,'magic_'+iFun):
1797 1797 # WARNING: _ofind uses getattr(), so it can consume generators and
1798 1798 # cause other side effects.
1799 1799 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1800 1800 if oinfo['ismagic']:
1801 1801 # Be careful not to call magics when a variable assignment is
1802 1802 # being made (ls='hi', for example)
1803 1803 if self.rc.automagic and \
1804 1804 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
1805 1805 (self.rc.multi_line_specials or not continue_prompt):
1806 1806 return self.handle_magic(line,continue_prompt,
1807 1807 pre,iFun,theRest)
1808 1808 else:
1809 1809 return self.handle_normal(line,continue_prompt)
1810 1810
1811 1811 # If the rest of the line begins with an (in)equality, assginment or
1812 1812 # function call, we should not call _ofind but simply execute it.
1813 1813 # This avoids spurious geattr() accesses on objects upon assignment.
1814 1814 #
1815 1815 # It also allows users to assign to either alias or magic names true
1816 1816 # python variables (the magic/alias systems always take second seat to
1817 1817 # true python code).
1818 1818 if theRest and theRest[0] in '!=()':
1819 1819 return self.handle_normal(line,continue_prompt)
1820 1820
1821 1821 if oinfo is None:
1822 1822 # let's try to ensure that _oinfo is ONLY called when autocall is
1823 1823 # on. Since it has inevitable potential side effects, at least
1824 1824 # having autocall off should be a guarantee to the user that no
1825 1825 # weird things will happen.
1826 1826
1827 1827 if self.rc.autocall:
1828 1828 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1829 1829 else:
1830 1830 # in this case, all that's left is either an alias or
1831 1831 # processing the line normally.
1832 1832 if iFun in self.alias_table:
1833 1833 return self.handle_alias(line,continue_prompt,
1834 1834 pre,iFun,theRest)
1835 1835 else:
1836 1836 return self.handle_normal(line,continue_prompt)
1837 1837
1838 1838 if not oinfo['found']:
1839 1839 return self.handle_normal(line,continue_prompt)
1840 1840 else:
1841 1841 #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg
1842 1842 if oinfo['isalias']:
1843 1843 return self.handle_alias(line,continue_prompt,
1844 1844 pre,iFun,theRest)
1845 1845
1846 1846 if self.rc.autocall and \
1847 1847 not self.re_exclude_auto.match(theRest) and \
1848 1848 self.re_fun_name.match(iFun) and \
1849 1849 callable(oinfo['obj']) :
1850 1850 #print 'going auto' # dbg
1851 1851 return self.handle_auto(line,continue_prompt,
1852 1852 pre,iFun,theRest,oinfo['obj'])
1853 1853 else:
1854 1854 #print 'was callable?', callable(oinfo['obj']) # dbg
1855 1855 return self.handle_normal(line,continue_prompt)
1856 1856
1857 1857 # If we get here, we have a normal Python line. Log and return.
1858 1858 return self.handle_normal(line,continue_prompt)
1859 1859
1860 1860 def _prefilter_dumb(self, line, continue_prompt):
1861 1861 """simple prefilter function, for debugging"""
1862 1862 return self.handle_normal(line,continue_prompt)
1863 1863
1864 1864 # Set the default prefilter() function (this can be user-overridden)
1865 1865 prefilter = _prefilter
1866 1866
1867 1867 def handle_normal(self,line,continue_prompt=None,
1868 1868 pre=None,iFun=None,theRest=None):
1869 1869 """Handle normal input lines. Use as a template for handlers."""
1870 1870
1871 1871 # With autoindent on, we need some way to exit the input loop, and I
1872 1872 # don't want to force the user to have to backspace all the way to
1873 1873 # clear the line. The rule will be in this case, that either two
1874 1874 # lines of pure whitespace in a row, or a line of pure whitespace but
1875 1875 # of a size different to the indent level, will exit the input loop.
1876 1876
1877 1877 if (continue_prompt and self.autoindent and isspace(line) and
1878 1878 (line != self.indent_current or isspace(self.buffer[-1]))):
1879 1879 line = ''
1880 1880
1881 1881 self.log(line,continue_prompt)
1882 1882 return line
1883 1883
1884 1884 def handle_alias(self,line,continue_prompt=None,
1885 1885 pre=None,iFun=None,theRest=None):
1886 1886 """Handle alias input lines. """
1887 1887
1888 1888 # pre is needed, because it carries the leading whitespace. Otherwise
1889 1889 # aliases won't work in indented sections.
1890 1890 line_out = '%sipalias("%s %s")' % (pre,iFun,esc_quotes(theRest))
1891 1891 self.log(line_out,continue_prompt)
1892 1892 return line_out
1893 1893
1894 1894 def handle_shell_escape(self, line, continue_prompt=None,
1895 1895 pre=None,iFun=None,theRest=None):
1896 1896 """Execute the line in a shell, empty return value"""
1897 1897
1898 1898 #print 'line in :', `line` # dbg
1899 1899 # Example of a special handler. Others follow a similar pattern.
1900 1900 if continue_prompt: # multi-line statements
1901 1901 if iFun.startswith('!!'):
1902 1902 print 'SyntaxError: !! is not allowed in multiline statements'
1903 1903 return pre
1904 1904 else:
1905 1905 cmd = ("%s %s" % (iFun[1:],theRest))
1906 1906 line_out = '%sipsystem(r"""%s"""[:-1])' % (pre,cmd + "_")
1907 1907 else: # single-line input
1908 1908 if line.startswith('!!'):
1909 1909 # rewrite iFun/theRest to properly hold the call to %sx and
1910 1910 # the actual command to be executed, so handle_magic can work
1911 1911 # correctly
1912 1912 theRest = '%s %s' % (iFun[2:],theRest)
1913 1913 iFun = 'sx'
1914 1914 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]),
1915 1915 continue_prompt,pre,iFun,theRest)
1916 1916 else:
1917 1917 cmd=line[1:]
1918 1918 line_out = '%sipsystem(r"""%s"""[:-1])' % (pre,cmd +"_")
1919 1919 # update cache/log and return
1920 1920 self.log(line_out,continue_prompt)
1921 1921 return line_out
1922 1922
1923 1923 def handle_magic(self, line, continue_prompt=None,
1924 1924 pre=None,iFun=None,theRest=None):
1925 1925 """Execute magic functions.
1926 1926
1927 1927 Also log them with a prepended # so the log is clean Python."""
1928 1928
1929 1929 cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest)))
1930 1930 self.log(cmd,continue_prompt)
1931 1931 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
1932 1932 return cmd
1933 1933
1934 1934 def handle_auto(self, line, continue_prompt=None,
1935 1935 pre=None,iFun=None,theRest=None,obj=None):
1936 1936 """Hande lines which can be auto-executed, quoting if requested."""
1937 1937
1938 1938 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1939 1939
1940 1940 # This should only be active for single-line input!
1941 1941 if continue_prompt:
1942 1942 self.log(line,continue_prompt)
1943 1943 return line
1944 1944
1945 1945 auto_rewrite = True
1946 1946 if pre == self.ESC_QUOTE:
1947 1947 # Auto-quote splitting on whitespace
1948 1948 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
1949 1949 elif pre == self.ESC_QUOTE2:
1950 1950 # Auto-quote whole string
1951 1951 newcmd = '%s("%s")' % (iFun,theRest)
1952 1952 else:
1953 1953 # Auto-paren.
1954 1954 # We only apply it to argument-less calls if the autocall
1955 1955 # parameter is set to 2. We only need to check that autocall is <
1956 1956 # 2, since this function isn't called unless it's at least 1.
1957 1957 if not theRest and (self.rc.autocall < 2):
1958 1958 newcmd = '%s %s' % (iFun,theRest)
1959 1959 auto_rewrite = False
1960 1960 else:
1961 1961 if theRest.startswith('['):
1962 1962 if hasattr(obj,'__getitem__'):
1963 1963 # Don't autocall in this case: item access for an object
1964 1964 # which is BOTH callable and implements __getitem__.
1965 1965 newcmd = '%s %s' % (iFun,theRest)
1966 1966 auto_rewrite = False
1967 1967 else:
1968 1968 # if the object doesn't support [] access, go ahead and
1969 1969 # autocall
1970 1970 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1971 1971 elif theRest.endswith(';'):
1972 1972 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
1973 1973 else:
1974 1974 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1975 1975
1976 1976 if auto_rewrite:
1977 1977 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
1978 1978 # log what is now valid Python, not the actual user input (without the
1979 1979 # final newline)
1980 1980 self.log(newcmd,continue_prompt)
1981 1981 return newcmd
1982 1982
1983 1983 def handle_help(self, line, continue_prompt=None,
1984 1984 pre=None,iFun=None,theRest=None):
1985 1985 """Try to get some help for the object.
1986 1986
1987 1987 obj? or ?obj -> basic information.
1988 1988 obj?? or ??obj -> more details.
1989 1989 """
1990 1990
1991 1991 # We need to make sure that we don't process lines which would be
1992 1992 # otherwise valid python, such as "x=1 # what?"
1993 1993 try:
1994 1994 codeop.compile_command(line)
1995 1995 except SyntaxError:
1996 1996 # We should only handle as help stuff which is NOT valid syntax
1997 1997 if line[0]==self.ESC_HELP:
1998 1998 line = line[1:]
1999 1999 elif line[-1]==self.ESC_HELP:
2000 2000 line = line[:-1]
2001 2001 self.log('#?'+line)
2002 2002 if line:
2003 2003 self.magic_pinfo(line)
2004 2004 else:
2005 2005 page(self.usage,screen_lines=self.rc.screen_length)
2006 2006 return '' # Empty string is needed here!
2007 2007 except:
2008 2008 # Pass any other exceptions through to the normal handler
2009 2009 return self.handle_normal(line,continue_prompt)
2010 2010 else:
2011 2011 # If the code compiles ok, we should handle it normally
2012 2012 return self.handle_normal(line,continue_prompt)
2013 2013
2014 2014 def handle_emacs(self,line,continue_prompt=None,
2015 2015 pre=None,iFun=None,theRest=None):
2016 2016 """Handle input lines marked by python-mode."""
2017 2017
2018 2018 # Currently, nothing is done. Later more functionality can be added
2019 2019 # here if needed.
2020 2020
2021 2021 # The input cache shouldn't be updated
2022 2022
2023 2023 return line
2024 2024
2025 2025 def mktempfile(self,data=None):
2026 2026 """Make a new tempfile and return its filename.
2027 2027
2028 2028 This makes a call to tempfile.mktemp, but it registers the created
2029 2029 filename internally so ipython cleans it up at exit time.
2030 2030
2031 2031 Optional inputs:
2032 2032
2033 2033 - data(None): if data is given, it gets written out to the temp file
2034 2034 immediately, and the file is closed again."""
2035 2035
2036 filename = tempfile.mktemp('.py')
2036 filename = tempfile.mktemp('.py','ipython_edit_')
2037 2037 self.tempfiles.append(filename)
2038 2038
2039 2039 if data:
2040 2040 tmp_file = open(filename,'w')
2041 2041 tmp_file.write(data)
2042 2042 tmp_file.close()
2043 2043 return filename
2044 2044
2045 2045 def write(self,data):
2046 2046 """Write a string to the default output"""
2047 2047 Term.cout.write(data)
2048 2048
2049 2049 def write_err(self,data):
2050 2050 """Write a string to the default error output"""
2051 2051 Term.cerr.write(data)
2052 2052
2053 2053 def exit(self):
2054 2054 """Handle interactive exit.
2055 2055
2056 2056 This method sets the exit_now attribute."""
2057 2057
2058 2058 if self.rc.confirm_exit:
2059 2059 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
2060 2060 self.exit_now = True
2061 2061 else:
2062 2062 self.exit_now = True
2063 2063 return self.exit_now
2064 2064
2065 2065 def safe_execfile(self,fname,*where,**kw):
2066 2066 fname = os.path.expanduser(fname)
2067 2067
2068 2068 # find things also in current directory
2069 2069 dname = os.path.dirname(fname)
2070 2070 if not sys.path.count(dname):
2071 2071 sys.path.append(dname)
2072 2072
2073 2073 try:
2074 2074 xfile = open(fname)
2075 2075 except:
2076 2076 print >> Term.cerr, \
2077 2077 'Could not open file <%s> for safe execution.' % fname
2078 2078 return None
2079 2079
2080 2080 kw.setdefault('islog',0)
2081 2081 kw.setdefault('quiet',1)
2082 2082 kw.setdefault('exit_ignore',0)
2083 2083 first = xfile.readline()
2084 2084 loghead = str(self.loghead_tpl).split('\n',1)[0].strip()
2085 2085 xfile.close()
2086 2086 # line by line execution
2087 2087 if first.startswith(loghead) or kw['islog']:
2088 2088 print 'Loading log file <%s> one line at a time...' % fname
2089 2089 if kw['quiet']:
2090 2090 stdout_save = sys.stdout
2091 2091 sys.stdout = StringIO.StringIO()
2092 2092 try:
2093 2093 globs,locs = where[0:2]
2094 2094 except:
2095 2095 try:
2096 2096 globs = locs = where[0]
2097 2097 except:
2098 2098 globs = locs = globals()
2099 2099 badblocks = []
2100 2100
2101 2101 # we also need to identify indented blocks of code when replaying
2102 2102 # logs and put them together before passing them to an exec
2103 2103 # statement. This takes a bit of regexp and look-ahead work in the
2104 2104 # file. It's easiest if we swallow the whole thing in memory
2105 2105 # first, and manually walk through the lines list moving the
2106 2106 # counter ourselves.
2107 2107 indent_re = re.compile('\s+\S')
2108 2108 xfile = open(fname)
2109 2109 filelines = xfile.readlines()
2110 2110 xfile.close()
2111 2111 nlines = len(filelines)
2112 2112 lnum = 0
2113 2113 while lnum < nlines:
2114 2114 line = filelines[lnum]
2115 2115 lnum += 1
2116 2116 # don't re-insert logger status info into cache
2117 2117 if line.startswith('#log#'):
2118 2118 continue
2119 2119 else:
2120 2120 # build a block of code (maybe a single line) for execution
2121 2121 block = line
2122 2122 try:
2123 2123 next = filelines[lnum] # lnum has already incremented
2124 2124 except:
2125 2125 next = None
2126 2126 while next and indent_re.match(next):
2127 2127 block += next
2128 2128 lnum += 1
2129 2129 try:
2130 2130 next = filelines[lnum]
2131 2131 except:
2132 2132 next = None
2133 2133 # now execute the block of one or more lines
2134 2134 try:
2135 2135 exec block in globs,locs
2136 2136 except SystemExit:
2137 2137 pass
2138 2138 except:
2139 2139 badblocks.append(block.rstrip())
2140 2140 if kw['quiet']: # restore stdout
2141 2141 sys.stdout.close()
2142 2142 sys.stdout = stdout_save
2143 2143 print 'Finished replaying log file <%s>' % fname
2144 2144 if badblocks:
2145 2145 print >> sys.stderr, ('\nThe following lines/blocks in file '
2146 2146 '<%s> reported errors:' % fname)
2147 2147
2148 2148 for badline in badblocks:
2149 2149 print >> sys.stderr, badline
2150 2150 else: # regular file execution
2151 2151 try:
2152 2152 execfile(fname,*where)
2153 2153 except SyntaxError:
2154 2154 etype,evalue = sys.exc_info()[:2]
2155 2155 self.SyntaxTB(etype,evalue,[])
2156 2156 warn('Failure executing file: <%s>' % fname)
2157 2157 except SystemExit,status:
2158 2158 if not kw['exit_ignore']:
2159 2159 self.InteractiveTB()
2160 2160 warn('Failure executing file: <%s>' % fname)
2161 2161 except:
2162 2162 self.InteractiveTB()
2163 2163 warn('Failure executing file: <%s>' % fname)
2164 2164
2165 2165 #************************* end of file <iplib.py> *****************************
@@ -1,4804 +1,4814
1 2006-01-10 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/Release.py (revision): tag version number to 0.7.0,
4 ready for release.
5
6 * IPython/Magic.py (magic_edit): Add print statement to %edit so
7 it informs the user of the name of the temp. file used. This can
8 help if you decide later to reuse that same file, so you know
9 where to copy the info from.
10
1 11 2006-01-09 Fernando Perez <Fernando.Perez@colorado.edu>
2 12
3 13 * setup_bdist_egg.py: little script to build an egg. Added
4 14 support in the release tools as well.
5 15
6 16 2006-01-08 Fernando Perez <Fernando.Perez@colorado.edu>
7 17
8 18 * IPython/Shell.py (IPShellWX.__init__): add support for WXPython
9 19 version selection (new -wxversion command line and ipythonrc
10 20 parameter). Patch contributed by Arnd Baecker
11 21 <arnd.baecker-AT-web.de>.
12 22
13 23 * IPython/iplib.py (embed_mainloop): fix tab-completion in
14 24 embedded instances, for variables defined at the interactive
15 25 prompt of the embedded ipython. Reported by Arnd.
16 26
17 27 * IPython/Magic.py (magic_autocall): Fix %autocall magic. Now
18 28 it can be used as a (stateful) toggle, or with a direct parameter.
19 29
20 30 * IPython/ultraTB.py (_fixed_getinnerframes): remove debug assert which
21 31 could be triggered in certain cases and cause the traceback
22 32 printer not to work.
23 33
24 34 2006-01-07 Fernando Perez <Fernando.Perez@colorado.edu>
25 35
26 36 * IPython/iplib.py (_should_recompile): Small fix, closes
27 37 http://www.scipy.net/roundup/ipython/issue48. Patch by Scott.
28 38
29 39 2006-01-04 Fernando Perez <Fernando.Perez@colorado.edu>
30 40
31 41 * IPython/Shell.py (IPShellGTK.mainloop): fix bug in the GTK
32 42 backend for matplotlib (100% cpu utiliziation). Thanks to Charlie
33 43 Moad for help with tracking it down.
34 44
35 45 * IPython/iplib.py (handle_auto): fix autocall handling for
36 46 objects which support BOTH __getitem__ and __call__ (so that f [x]
37 47 is left alone, instead of becoming f([x]) automatically).
38 48
39 49 * IPython/Magic.py (magic_cd): fix crash when cd -b was used.
40 50 Ville's patch.
41 51
42 52 2006-01-03 Fernando Perez <Fernando.Perez@colorado.edu>
43 53
44 54 * IPython/iplib.py (handle_auto): changed autocall semantics to
45 55 include 'smart' mode, where the autocall transformation is NOT
46 56 applied if there are no arguments on the line. This allows you to
47 57 just type 'foo' if foo is a callable to see its internal form,
48 58 instead of having it called with no arguments (typically a
49 59 mistake). The old 'full' autocall still exists: for that, you
50 60 need to set the 'autocall' parameter to 2 in your ipythonrc file.
51 61
52 62 * IPython/completer.py (Completer.attr_matches): add
53 63 tab-completion support for Enthoughts' traits. After a report by
54 64 Arnd and a patch by Prabhu.
55 65
56 66 2006-01-02 Fernando Perez <Fernando.Perez@colorado.edu>
57 67
58 68 * IPython/ultraTB.py (_fixed_getinnerframes): added Alex
59 69 Schmolck's patch to fix inspect.getinnerframes().
60 70
61 71 * IPython/iplib.py (InteractiveShell.__init__): significant fixes
62 72 for embedded instances, regarding handling of namespaces and items
63 73 added to the __builtin__ one. Multiple embedded instances and
64 74 recursive embeddings should work better now (though I'm not sure
65 75 I've got all the corner cases fixed, that code is a bit of a brain
66 76 twister).
67 77
68 78 * IPython/Magic.py (magic_edit): added support to edit in-memory
69 79 macros (automatically creates the necessary temp files). %edit
70 80 also doesn't return the file contents anymore, it's just noise.
71 81
72 82 * IPython/completer.py (Completer.attr_matches): revert change to
73 83 complete only on attributes listed in __all__. I realized it
74 84 cripples the tab-completion system as a tool for exploring the
75 85 internals of unknown libraries (it renders any non-__all__
76 86 attribute off-limits). I got bit by this when trying to see
77 87 something inside the dis module.
78 88
79 89 2005-12-31 Fernando Perez <Fernando.Perez@colorado.edu>
80 90
81 91 * IPython/iplib.py (InteractiveShell.__init__): add .meta
82 92 namespace for users and extension writers to hold data in. This
83 93 follows the discussion in
84 94 http://projects.scipy.org/ipython/ipython/wiki/RefactoringIPython.
85 95
86 96 * IPython/completer.py (IPCompleter.complete): small patch to help
87 97 tab-completion under Emacs, after a suggestion by John Barnard
88 98 <barnarj-AT-ccf.org>.
89 99
90 100 * IPython/Magic.py (Magic.extract_input_slices): added support for
91 101 the slice notation in magics to use N-M to represent numbers N...M
92 102 (closed endpoints). This is used by %macro and %save.
93 103
94 104 * IPython/completer.py (Completer.attr_matches): for modules which
95 105 define __all__, complete only on those. After a patch by Jeffrey
96 106 Collins <jcollins_boulder-AT-earthlink.net>. Also, clean up and
97 107 speed up this routine.
98 108
99 109 * IPython/Logger.py (Logger.log): fix a history handling bug. I
100 110 don't know if this is the end of it, but the behavior now is
101 111 certainly much more correct. Note that coupled with macros,
102 112 slightly surprising (at first) behavior may occur: a macro will in
103 113 general expand to multiple lines of input, so upon exiting, the
104 114 in/out counters will both be bumped by the corresponding amount
105 115 (as if the macro's contents had been typed interactively). Typing
106 116 %hist will reveal the intermediate (silently processed) lines.
107 117
108 118 * IPython/Magic.py (magic_run): fix a subtle bug which could cause
109 119 pickle to fail (%run was overwriting __main__ and not restoring
110 120 it, but pickle relies on __main__ to operate).
111 121
112 122 * IPython/iplib.py (InteractiveShell): fix pdb calling: I'm now
113 123 using properties, but forgot to make the main InteractiveShell
114 124 class a new-style class. Properties fail silently, and
115 125 misteriously, with old-style class (getters work, but
116 126 setters don't do anything).
117 127
118 128 2005-12-30 Fernando Perez <Fernando.Perez@colorado.edu>
119 129
120 130 * IPython/Magic.py (magic_history): fix history reporting bug (I
121 131 know some nasties are still there, I just can't seem to find a
122 132 reproducible test case to track them down; the input history is
123 133 falling out of sync...)
124 134
125 135 * IPython/iplib.py (handle_shell_escape): fix bug where both
126 136 aliases and system accesses where broken for indented code (such
127 137 as loops).
128 138
129 139 * IPython/genutils.py (shell): fix small but critical bug for
130 140 win32 system access.
131 141
132 142 2005-12-29 Fernando Perez <Fernando.Perez@colorado.edu>
133 143
134 144 * IPython/iplib.py (showtraceback): remove use of the
135 145 sys.last_{type/value/traceback} structures, which are non
136 146 thread-safe.
137 147 (_prefilter): change control flow to ensure that we NEVER
138 148 introspect objects when autocall is off. This will guarantee that
139 149 having an input line of the form 'x.y', where access to attribute
140 150 'y' has side effects, doesn't trigger the side effect TWICE. It
141 151 is important to note that, with autocall on, these side effects
142 152 can still happen.
143 153 (ipsystem): new builtin, to complete the ip{magic/alias/system}
144 154 trio. IPython offers these three kinds of special calls which are
145 155 not python code, and it's a good thing to have their call method
146 156 be accessible as pure python functions (not just special syntax at
147 157 the command line). It gives us a better internal implementation
148 158 structure, as well as exposing these for user scripting more
149 159 cleanly.
150 160
151 161 * IPython/macro.py (Macro.__init__): moved macros to a standalone
152 162 file. Now that they'll be more likely to be used with the
153 163 persistance system (%store), I want to make sure their module path
154 164 doesn't change in the future, so that we don't break things for
155 165 users' persisted data.
156 166
157 167 * IPython/iplib.py (autoindent_update): move indentation
158 168 management into the _text_ processing loop, not the keyboard
159 169 interactive one. This is necessary to correctly process non-typed
160 170 multiline input (such as macros).
161 171
162 172 * IPython/Magic.py (Magic.format_latex): patch by Stefan van der
163 173 Walt <stefan-AT-sun.ac.za> to fix latex formatting of docstrings,
164 174 which was producing problems in the resulting manual.
165 175 (magic_whos): improve reporting of instances (show their class,
166 176 instead of simply printing 'instance' which isn't terribly
167 177 informative).
168 178
169 179 * IPython/genutils.py (shell): commit Jorgen Stenarson's patch
170 180 (minor mods) to support network shares under win32.
171 181
172 182 * IPython/winconsole.py (get_console_size): add new winconsole
173 183 module and fixes to page_dumb() to improve its behavior under
174 184 win32. Contributed by Alexander Belchenko <bialix-AT-ukr.net>.
175 185
176 186 * IPython/Magic.py (Macro): simplified Macro class to just
177 187 subclass list. We've had only 2.2 compatibility for a very long
178 188 time, yet I was still avoiding subclassing the builtin types. No
179 189 more (I'm also starting to use properties, though I won't shift to
180 190 2.3-specific features quite yet).
181 191 (magic_store): added Ville's patch for lightweight variable
182 192 persistence, after a request on the user list by Matt Wilkie
183 193 <maphew-AT-gmail.com>. The new %store magic's docstring has full
184 194 details.
185 195
186 196 * IPython/iplib.py (InteractiveShell.post_config_initialization):
187 197 changed the default logfile name from 'ipython.log' to
188 198 'ipython_log.py'. These logs are real python files, and now that
189 199 we have much better multiline support, people are more likely to
190 200 want to use them as such. Might as well name them correctly.
191 201
192 202 * IPython/Magic.py: substantial cleanup. While we can't stop
193 203 using magics as mixins, due to the existing customizations 'out
194 204 there' which rely on the mixin naming conventions, at least I
195 205 cleaned out all cross-class name usage. So once we are OK with
196 206 breaking compatibility, the two systems can be separated.
197 207
198 208 * IPython/Logger.py: major cleanup. This one is NOT a mixin
199 209 anymore, and the class is a fair bit less hideous as well. New
200 210 features were also introduced: timestamping of input, and logging
201 211 of output results. These are user-visible with the -t and -o
202 212 options to %logstart. Closes
203 213 http://www.scipy.net/roundup/ipython/issue11 and a request by
204 214 William Stein (SAGE developer - http://modular.ucsd.edu/sage).
205 215
206 216 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
207 217
208 218 * IPython/iplib.py (handle_shell_escape): add Ville's patch to
209 219 better hadnle backslashes in paths. See the thread 'More Windows
210 220 questions part 2 - \/ characters revisited' on the iypthon user
211 221 list:
212 222 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
213 223
214 224 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
215 225
216 226 (InteractiveShell.__init__): change threaded shells to not use the
217 227 ipython crash handler. This was causing more problems than not,
218 228 as exceptions in the main thread (GUI code, typically) would
219 229 always show up as a 'crash', when they really weren't.
220 230
221 231 The colors and exception mode commands (%colors/%xmode) have been
222 232 synchronized to also take this into account, so users can get
223 233 verbose exceptions for their threaded code as well. I also added
224 234 support for activating pdb inside this exception handler as well,
225 235 so now GUI authors can use IPython's enhanced pdb at runtime.
226 236
227 237 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
228 238 true by default, and add it to the shipped ipythonrc file. Since
229 239 this asks the user before proceeding, I think it's OK to make it
230 240 true by default.
231 241
232 242 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
233 243 of the previous special-casing of input in the eval loop. I think
234 244 this is cleaner, as they really are commands and shouldn't have
235 245 a special role in the middle of the core code.
236 246
237 247 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
238 248
239 249 * IPython/iplib.py (edit_syntax_error): added support for
240 250 automatically reopening the editor if the file had a syntax error
241 251 in it. Thanks to scottt who provided the patch at:
242 252 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
243 253 version committed).
244 254
245 255 * IPython/iplib.py (handle_normal): add suport for multi-line
246 256 input with emtpy lines. This fixes
247 257 http://www.scipy.net/roundup/ipython/issue43 and a similar
248 258 discussion on the user list.
249 259
250 260 WARNING: a behavior change is necessarily introduced to support
251 261 blank lines: now a single blank line with whitespace does NOT
252 262 break the input loop, which means that when autoindent is on, by
253 263 default hitting return on the next (indented) line does NOT exit.
254 264
255 265 Instead, to exit a multiline input you can either have:
256 266
257 267 - TWO whitespace lines (just hit return again), or
258 268 - a single whitespace line of a different length than provided
259 269 by the autoindent (add or remove a space).
260 270
261 271 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
262 272 module to better organize all readline-related functionality.
263 273 I've deleted FlexCompleter and put all completion clases here.
264 274
265 275 * IPython/iplib.py (raw_input): improve indentation management.
266 276 It is now possible to paste indented code with autoindent on, and
267 277 the code is interpreted correctly (though it still looks bad on
268 278 screen, due to the line-oriented nature of ipython).
269 279 (MagicCompleter.complete): change behavior so that a TAB key on an
270 280 otherwise empty line actually inserts a tab, instead of completing
271 281 on the entire global namespace. This makes it easier to use the
272 282 TAB key for indentation. After a request by Hans Meine
273 283 <hans_meine-AT-gmx.net>
274 284 (_prefilter): add support so that typing plain 'exit' or 'quit'
275 285 does a sensible thing. Originally I tried to deviate as little as
276 286 possible from the default python behavior, but even that one may
277 287 change in this direction (thread on python-dev to that effect).
278 288 Regardless, ipython should do the right thing even if CPython's
279 289 '>>>' prompt doesn't.
280 290 (InteractiveShell): removed subclassing code.InteractiveConsole
281 291 class. By now we'd overridden just about all of its methods: I've
282 292 copied the remaining two over, and now ipython is a standalone
283 293 class. This will provide a clearer picture for the chainsaw
284 294 branch refactoring.
285 295
286 296 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
287 297
288 298 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
289 299 failures for objects which break when dir() is called on them.
290 300
291 301 * IPython/FlexCompleter.py (Completer.__init__): Added support for
292 302 distinct local and global namespaces in the completer API. This
293 303 change allows us top properly handle completion with distinct
294 304 scopes, including in embedded instances (this had never really
295 305 worked correctly).
296 306
297 307 Note: this introduces a change in the constructor for
298 308 MagicCompleter, as a new global_namespace parameter is now the
299 309 second argument (the others were bumped one position).
300 310
301 311 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
302 312
303 313 * IPython/iplib.py (embed_mainloop): fix tab-completion in
304 314 embedded instances (which can be done now thanks to Vivian's
305 315 frame-handling fixes for pdb).
306 316 (InteractiveShell.__init__): Fix namespace handling problem in
307 317 embedded instances. We were overwriting __main__ unconditionally,
308 318 and this should only be done for 'full' (non-embedded) IPython;
309 319 embedded instances must respect the caller's __main__. Thanks to
310 320 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
311 321
312 322 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
313 323
314 324 * setup.py: added download_url to setup(). This registers the
315 325 download address at PyPI, which is not only useful to humans
316 326 browsing the site, but is also picked up by setuptools (the Eggs
317 327 machinery). Thanks to Ville and R. Kern for the info/discussion
318 328 on this.
319 329
320 330 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
321 331
322 332 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
323 333 This brings a lot of nice functionality to the pdb mode, which now
324 334 has tab-completion, syntax highlighting, and better stack handling
325 335 than before. Many thanks to Vivian De Smedt
326 336 <vivian-AT-vdesmedt.com> for the original patches.
327 337
328 338 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
329 339
330 340 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
331 341 sequence to consistently accept the banner argument. The
332 342 inconsistency was tripping SAGE, thanks to Gary Zablackis
333 343 <gzabl-AT-yahoo.com> for the report.
334 344
335 345 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
336 346
337 347 * IPython/iplib.py (InteractiveShell.post_config_initialization):
338 348 Fix bug where a naked 'alias' call in the ipythonrc file would
339 349 cause a crash. Bug reported by Jorgen Stenarson.
340 350
341 351 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
342 352
343 353 * IPython/ipmaker.py (make_IPython): cleanups which should improve
344 354 startup time.
345 355
346 356 * IPython/iplib.py (runcode): my globals 'fix' for embedded
347 357 instances had introduced a bug with globals in normal code. Now
348 358 it's working in all cases.
349 359
350 360 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
351 361 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
352 362 has been introduced to set the default case sensitivity of the
353 363 searches. Users can still select either mode at runtime on a
354 364 per-search basis.
355 365
356 366 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
357 367
358 368 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
359 369 attributes in wildcard searches for subclasses. Modified version
360 370 of a patch by Jorgen.
361 371
362 372 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
363 373
364 374 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
365 375 embedded instances. I added a user_global_ns attribute to the
366 376 InteractiveShell class to handle this.
367 377
368 378 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
369 379
370 380 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
371 381 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
372 382 (reported under win32, but may happen also in other platforms).
373 383 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
374 384
375 385 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
376 386
377 387 * IPython/Magic.py (magic_psearch): new support for wildcard
378 388 patterns. Now, typing ?a*b will list all names which begin with a
379 389 and end in b, for example. The %psearch magic has full
380 390 docstrings. Many thanks to Jörgen Stenarson
381 391 <jorgen.stenarson-AT-bostream.nu>, author of the patches
382 392 implementing this functionality.
383 393
384 394 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
385 395
386 396 * Manual: fixed long-standing annoyance of double-dashes (as in
387 397 --prefix=~, for example) being stripped in the HTML version. This
388 398 is a latex2html bug, but a workaround was provided. Many thanks
389 399 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
390 400 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
391 401 rolling. This seemingly small issue had tripped a number of users
392 402 when first installing, so I'm glad to see it gone.
393 403
394 404 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
395 405
396 406 * IPython/Extensions/numeric_formats.py: fix missing import,
397 407 reported by Stephen Walton.
398 408
399 409 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
400 410
401 411 * IPython/demo.py: finish demo module, fully documented now.
402 412
403 413 * IPython/genutils.py (file_read): simple little utility to read a
404 414 file and ensure it's closed afterwards.
405 415
406 416 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
407 417
408 418 * IPython/demo.py (Demo.__init__): added support for individually
409 419 tagging blocks for automatic execution.
410 420
411 421 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
412 422 syntax-highlighted python sources, requested by John.
413 423
414 424 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
415 425
416 426 * IPython/demo.py (Demo.again): fix bug where again() blocks after
417 427 finishing.
418 428
419 429 * IPython/genutils.py (shlex_split): moved from Magic to here,
420 430 where all 2.2 compatibility stuff lives. I needed it for demo.py.
421 431
422 432 * IPython/demo.py (Demo.__init__): added support for silent
423 433 blocks, improved marks as regexps, docstrings written.
424 434 (Demo.__init__): better docstring, added support for sys.argv.
425 435
426 436 * IPython/genutils.py (marquee): little utility used by the demo
427 437 code, handy in general.
428 438
429 439 * IPython/demo.py (Demo.__init__): new class for interactive
430 440 demos. Not documented yet, I just wrote it in a hurry for
431 441 scipy'05. Will docstring later.
432 442
433 443 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
434 444
435 445 * IPython/Shell.py (sigint_handler): Drastic simplification which
436 446 also seems to make Ctrl-C work correctly across threads! This is
437 447 so simple, that I can't beleive I'd missed it before. Needs more
438 448 testing, though.
439 449 (KBINT): Never mind, revert changes. I'm sure I'd tried something
440 450 like this before...
441 451
442 452 * IPython/genutils.py (get_home_dir): add protection against
443 453 non-dirs in win32 registry.
444 454
445 455 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
446 456 bug where dict was mutated while iterating (pysh crash).
447 457
448 458 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
449 459
450 460 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
451 461 spurious newlines added by this routine. After a report by
452 462 F. Mantegazza.
453 463
454 464 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
455 465
456 466 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
457 467 calls. These were a leftover from the GTK 1.x days, and can cause
458 468 problems in certain cases (after a report by John Hunter).
459 469
460 470 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
461 471 os.getcwd() fails at init time. Thanks to patch from David Remahl
462 472 <chmod007-AT-mac.com>.
463 473 (InteractiveShell.__init__): prevent certain special magics from
464 474 being shadowed by aliases. Closes
465 475 http://www.scipy.net/roundup/ipython/issue41.
466 476
467 477 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
468 478
469 479 * IPython/iplib.py (InteractiveShell.complete): Added new
470 480 top-level completion method to expose the completion mechanism
471 481 beyond readline-based environments.
472 482
473 483 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
474 484
475 485 * tools/ipsvnc (svnversion): fix svnversion capture.
476 486
477 487 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
478 488 attribute to self, which was missing. Before, it was set by a
479 489 routine which in certain cases wasn't being called, so the
480 490 instance could end up missing the attribute. This caused a crash.
481 491 Closes http://www.scipy.net/roundup/ipython/issue40.
482 492
483 493 2005-08-16 Fernando Perez <fperez@colorado.edu>
484 494
485 495 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
486 496 contains non-string attribute. Closes
487 497 http://www.scipy.net/roundup/ipython/issue38.
488 498
489 499 2005-08-14 Fernando Perez <fperez@colorado.edu>
490 500
491 501 * tools/ipsvnc: Minor improvements, to add changeset info.
492 502
493 503 2005-08-12 Fernando Perez <fperez@colorado.edu>
494 504
495 505 * IPython/iplib.py (runsource): remove self.code_to_run_src
496 506 attribute. I realized this is nothing more than
497 507 '\n'.join(self.buffer), and having the same data in two different
498 508 places is just asking for synchronization bugs. This may impact
499 509 people who have custom exception handlers, so I need to warn
500 510 ipython-dev about it (F. Mantegazza may use them).
501 511
502 512 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
503 513
504 514 * IPython/genutils.py: fix 2.2 compatibility (generators)
505 515
506 516 2005-07-18 Fernando Perez <fperez@colorado.edu>
507 517
508 518 * IPython/genutils.py (get_home_dir): fix to help users with
509 519 invalid $HOME under win32.
510 520
511 521 2005-07-17 Fernando Perez <fperez@colorado.edu>
512 522
513 523 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
514 524 some old hacks and clean up a bit other routines; code should be
515 525 simpler and a bit faster.
516 526
517 527 * IPython/iplib.py (interact): removed some last-resort attempts
518 528 to survive broken stdout/stderr. That code was only making it
519 529 harder to abstract out the i/o (necessary for gui integration),
520 530 and the crashes it could prevent were extremely rare in practice
521 531 (besides being fully user-induced in a pretty violent manner).
522 532
523 533 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
524 534 Nothing major yet, but the code is simpler to read; this should
525 535 make it easier to do more serious modifications in the future.
526 536
527 537 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
528 538 which broke in .15 (thanks to a report by Ville).
529 539
530 540 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
531 541 be quite correct, I know next to nothing about unicode). This
532 542 will allow unicode strings to be used in prompts, amongst other
533 543 cases. It also will prevent ipython from crashing when unicode
534 544 shows up unexpectedly in many places. If ascii encoding fails, we
535 545 assume utf_8. Currently the encoding is not a user-visible
536 546 setting, though it could be made so if there is demand for it.
537 547
538 548 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
539 549
540 550 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
541 551
542 552 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
543 553
544 554 * IPython/genutils.py: Add 2.2 compatibility here, so all other
545 555 code can work transparently for 2.2/2.3.
546 556
547 557 2005-07-16 Fernando Perez <fperez@colorado.edu>
548 558
549 559 * IPython/ultraTB.py (ExceptionColors): Make a global variable
550 560 out of the color scheme table used for coloring exception
551 561 tracebacks. This allows user code to add new schemes at runtime.
552 562 This is a minimally modified version of the patch at
553 563 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
554 564 for the contribution.
555 565
556 566 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
557 567 slightly modified version of the patch in
558 568 http://www.scipy.net/roundup/ipython/issue34, which also allows me
559 569 to remove the previous try/except solution (which was costlier).
560 570 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
561 571
562 572 2005-06-08 Fernando Perez <fperez@colorado.edu>
563 573
564 574 * IPython/iplib.py (write/write_err): Add methods to abstract all
565 575 I/O a bit more.
566 576
567 577 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
568 578 warning, reported by Aric Hagberg, fix by JD Hunter.
569 579
570 580 2005-06-02 *** Released version 0.6.15
571 581
572 582 2005-06-01 Fernando Perez <fperez@colorado.edu>
573 583
574 584 * IPython/iplib.py (MagicCompleter.file_matches): Fix
575 585 tab-completion of filenames within open-quoted strings. Note that
576 586 this requires that in ~/.ipython/ipythonrc, users change the
577 587 readline delimiters configuration to read:
578 588
579 589 readline_remove_delims -/~
580 590
581 591
582 592 2005-05-31 *** Released version 0.6.14
583 593
584 594 2005-05-29 Fernando Perez <fperez@colorado.edu>
585 595
586 596 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
587 597 with files not on the filesystem. Reported by Eliyahu Sandler
588 598 <eli@gondolin.net>
589 599
590 600 2005-05-22 Fernando Perez <fperez@colorado.edu>
591 601
592 602 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
593 603 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
594 604
595 605 2005-05-19 Fernando Perez <fperez@colorado.edu>
596 606
597 607 * IPython/iplib.py (safe_execfile): close a file which could be
598 608 left open (causing problems in win32, which locks open files).
599 609 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
600 610
601 611 2005-05-18 Fernando Perez <fperez@colorado.edu>
602 612
603 613 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
604 614 keyword arguments correctly to safe_execfile().
605 615
606 616 2005-05-13 Fernando Perez <fperez@colorado.edu>
607 617
608 618 * ipython.1: Added info about Qt to manpage, and threads warning
609 619 to usage page (invoked with --help).
610 620
611 621 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
612 622 new matcher (it goes at the end of the priority list) to do
613 623 tab-completion on named function arguments. Submitted by George
614 624 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
615 625 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
616 626 for more details.
617 627
618 628 * IPython/Magic.py (magic_run): Added new -e flag to ignore
619 629 SystemExit exceptions in the script being run. Thanks to a report
620 630 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
621 631 producing very annoying behavior when running unit tests.
622 632
623 633 2005-05-12 Fernando Perez <fperez@colorado.edu>
624 634
625 635 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
626 636 which I'd broken (again) due to a changed regexp. In the process,
627 637 added ';' as an escape to auto-quote the whole line without
628 638 splitting its arguments. Thanks to a report by Jerry McRae
629 639 <qrs0xyc02-AT-sneakemail.com>.
630 640
631 641 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
632 642 possible crashes caused by a TokenError. Reported by Ed Schofield
633 643 <schofield-AT-ftw.at>.
634 644
635 645 2005-05-06 Fernando Perez <fperez@colorado.edu>
636 646
637 647 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
638 648
639 649 2005-04-29 Fernando Perez <fperez@colorado.edu>
640 650
641 651 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
642 652 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
643 653 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
644 654 which provides support for Qt interactive usage (similar to the
645 655 existing one for WX and GTK). This had been often requested.
646 656
647 657 2005-04-14 *** Released version 0.6.13
648 658
649 659 2005-04-08 Fernando Perez <fperez@colorado.edu>
650 660
651 661 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
652 662 from _ofind, which gets called on almost every input line. Now,
653 663 we only try to get docstrings if they are actually going to be
654 664 used (the overhead of fetching unnecessary docstrings can be
655 665 noticeable for certain objects, such as Pyro proxies).
656 666
657 667 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
658 668 for completers. For some reason I had been passing them the state
659 669 variable, which completers never actually need, and was in
660 670 conflict with the rlcompleter API. Custom completers ONLY need to
661 671 take the text parameter.
662 672
663 673 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
664 674 work correctly in pysh. I've also moved all the logic which used
665 675 to be in pysh.py here, which will prevent problems with future
666 676 upgrades. However, this time I must warn users to update their
667 677 pysh profile to include the line
668 678
669 679 import_all IPython.Extensions.InterpreterExec
670 680
671 681 because otherwise things won't work for them. They MUST also
672 682 delete pysh.py and the line
673 683
674 684 execfile pysh.py
675 685
676 686 from their ipythonrc-pysh.
677 687
678 688 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
679 689 robust in the face of objects whose dir() returns non-strings
680 690 (which it shouldn't, but some broken libs like ITK do). Thanks to
681 691 a patch by John Hunter (implemented differently, though). Also
682 692 minor improvements by using .extend instead of + on lists.
683 693
684 694 * pysh.py:
685 695
686 696 2005-04-06 Fernando Perez <fperez@colorado.edu>
687 697
688 698 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
689 699 by default, so that all users benefit from it. Those who don't
690 700 want it can still turn it off.
691 701
692 702 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
693 703 config file, I'd forgotten about this, so users were getting it
694 704 off by default.
695 705
696 706 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
697 707 consistency. Now magics can be called in multiline statements,
698 708 and python variables can be expanded in magic calls via $var.
699 709 This makes the magic system behave just like aliases or !system
700 710 calls.
701 711
702 712 2005-03-28 Fernando Perez <fperez@colorado.edu>
703 713
704 714 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
705 715 expensive string additions for building command. Add support for
706 716 trailing ';' when autocall is used.
707 717
708 718 2005-03-26 Fernando Perez <fperez@colorado.edu>
709 719
710 720 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
711 721 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
712 722 ipython.el robust against prompts with any number of spaces
713 723 (including 0) after the ':' character.
714 724
715 725 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
716 726 continuation prompt, which misled users to think the line was
717 727 already indented. Closes debian Bug#300847, reported to me by
718 728 Norbert Tretkowski <tretkowski-AT-inittab.de>.
719 729
720 730 2005-03-23 Fernando Perez <fperez@colorado.edu>
721 731
722 732 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
723 733 properly aligned if they have embedded newlines.
724 734
725 735 * IPython/iplib.py (runlines): Add a public method to expose
726 736 IPython's code execution machinery, so that users can run strings
727 737 as if they had been typed at the prompt interactively.
728 738 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
729 739 methods which can call the system shell, but with python variable
730 740 expansion. The three such methods are: __IPYTHON__.system,
731 741 .getoutput and .getoutputerror. These need to be documented in a
732 742 'public API' section (to be written) of the manual.
733 743
734 744 2005-03-20 Fernando Perez <fperez@colorado.edu>
735 745
736 746 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
737 747 for custom exception handling. This is quite powerful, and it
738 748 allows for user-installable exception handlers which can trap
739 749 custom exceptions at runtime and treat them separately from
740 750 IPython's default mechanisms. At the request of Frédéric
741 751 Mantegazza <mantegazza-AT-ill.fr>.
742 752 (InteractiveShell.set_custom_completer): public API function to
743 753 add new completers at runtime.
744 754
745 755 2005-03-19 Fernando Perez <fperez@colorado.edu>
746 756
747 757 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
748 758 allow objects which provide their docstrings via non-standard
749 759 mechanisms (like Pyro proxies) to still be inspected by ipython's
750 760 ? system.
751 761
752 762 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
753 763 automatic capture system. I tried quite hard to make it work
754 764 reliably, and simply failed. I tried many combinations with the
755 765 subprocess module, but eventually nothing worked in all needed
756 766 cases (not blocking stdin for the child, duplicating stdout
757 767 without blocking, etc). The new %sc/%sx still do capture to these
758 768 magical list/string objects which make shell use much more
759 769 conveninent, so not all is lost.
760 770
761 771 XXX - FIX MANUAL for the change above!
762 772
763 773 (runsource): I copied code.py's runsource() into ipython to modify
764 774 it a bit. Now the code object and source to be executed are
765 775 stored in ipython. This makes this info accessible to third-party
766 776 tools, like custom exception handlers. After a request by Frédéric
767 777 Mantegazza <mantegazza-AT-ill.fr>.
768 778
769 779 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
770 780 history-search via readline (like C-p/C-n). I'd wanted this for a
771 781 long time, but only recently found out how to do it. For users
772 782 who already have their ipythonrc files made and want this, just
773 783 add:
774 784
775 785 readline_parse_and_bind "\e[A": history-search-backward
776 786 readline_parse_and_bind "\e[B": history-search-forward
777 787
778 788 2005-03-18 Fernando Perez <fperez@colorado.edu>
779 789
780 790 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
781 791 LSString and SList classes which allow transparent conversions
782 792 between list mode and whitespace-separated string.
783 793 (magic_r): Fix recursion problem in %r.
784 794
785 795 * IPython/genutils.py (LSString): New class to be used for
786 796 automatic storage of the results of all alias/system calls in _o
787 797 and _e (stdout/err). These provide a .l/.list attribute which
788 798 does automatic splitting on newlines. This means that for most
789 799 uses, you'll never need to do capturing of output with %sc/%sx
790 800 anymore, since ipython keeps this always done for you. Note that
791 801 only the LAST results are stored, the _o/e variables are
792 802 overwritten on each call. If you need to save their contents
793 803 further, simply bind them to any other name.
794 804
795 805 2005-03-17 Fernando Perez <fperez@colorado.edu>
796 806
797 807 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
798 808 prompt namespace handling.
799 809
800 810 2005-03-16 Fernando Perez <fperez@colorado.edu>
801 811
802 812 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
803 813 classic prompts to be '>>> ' (final space was missing, and it
804 814 trips the emacs python mode).
805 815 (BasePrompt.__str__): Added safe support for dynamic prompt
806 816 strings. Now you can set your prompt string to be '$x', and the
807 817 value of x will be printed from your interactive namespace. The
808 818 interpolation syntax includes the full Itpl support, so
809 819 ${foo()+x+bar()} is a valid prompt string now, and the function
810 820 calls will be made at runtime.
811 821
812 822 2005-03-15 Fernando Perez <fperez@colorado.edu>
813 823
814 824 * IPython/Magic.py (magic_history): renamed %hist to %history, to
815 825 avoid name clashes in pylab. %hist still works, it just forwards
816 826 the call to %history.
817 827
818 828 2005-03-02 *** Released version 0.6.12
819 829
820 830 2005-03-02 Fernando Perez <fperez@colorado.edu>
821 831
822 832 * IPython/iplib.py (handle_magic): log magic calls properly as
823 833 ipmagic() function calls.
824 834
825 835 * IPython/Magic.py (magic_time): Improved %time to support
826 836 statements and provide wall-clock as well as CPU time.
827 837
828 838 2005-02-27 Fernando Perez <fperez@colorado.edu>
829 839
830 840 * IPython/hooks.py: New hooks module, to expose user-modifiable
831 841 IPython functionality in a clean manner. For now only the editor
832 842 hook is actually written, and other thigns which I intend to turn
833 843 into proper hooks aren't yet there. The display and prefilter
834 844 stuff, for example, should be hooks. But at least now the
835 845 framework is in place, and the rest can be moved here with more
836 846 time later. IPython had had a .hooks variable for a long time for
837 847 this purpose, but I'd never actually used it for anything.
838 848
839 849 2005-02-26 Fernando Perez <fperez@colorado.edu>
840 850
841 851 * IPython/ipmaker.py (make_IPython): make the default ipython
842 852 directory be called _ipython under win32, to follow more the
843 853 naming peculiarities of that platform (where buggy software like
844 854 Visual Sourcesafe breaks with .named directories). Reported by
845 855 Ville Vainio.
846 856
847 857 2005-02-23 Fernando Perez <fperez@colorado.edu>
848 858
849 859 * IPython/iplib.py (InteractiveShell.__init__): removed a few
850 860 auto_aliases for win32 which were causing problems. Users can
851 861 define the ones they personally like.
852 862
853 863 2005-02-21 Fernando Perez <fperez@colorado.edu>
854 864
855 865 * IPython/Magic.py (magic_time): new magic to time execution of
856 866 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
857 867
858 868 2005-02-19 Fernando Perez <fperez@colorado.edu>
859 869
860 870 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
861 871 into keys (for prompts, for example).
862 872
863 873 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
864 874 prompts in case users want them. This introduces a small behavior
865 875 change: ipython does not automatically add a space to all prompts
866 876 anymore. To get the old prompts with a space, users should add it
867 877 manually to their ipythonrc file, so for example prompt_in1 should
868 878 now read 'In [\#]: ' instead of 'In [\#]:'.
869 879 (BasePrompt.__init__): New option prompts_pad_left (only in rc
870 880 file) to control left-padding of secondary prompts.
871 881
872 882 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
873 883 the profiler can't be imported. Fix for Debian, which removed
874 884 profile.py because of License issues. I applied a slightly
875 885 modified version of the original Debian patch at
876 886 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
877 887
878 888 2005-02-17 Fernando Perez <fperez@colorado.edu>
879 889
880 890 * IPython/genutils.py (native_line_ends): Fix bug which would
881 891 cause improper line-ends under win32 b/c I was not opening files
882 892 in binary mode. Bug report and fix thanks to Ville.
883 893
884 894 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
885 895 trying to catch spurious foo[1] autocalls. My fix actually broke
886 896 ',/' autoquote/call with explicit escape (bad regexp).
887 897
888 898 2005-02-15 *** Released version 0.6.11
889 899
890 900 2005-02-14 Fernando Perez <fperez@colorado.edu>
891 901
892 902 * IPython/background_jobs.py: New background job management
893 903 subsystem. This is implemented via a new set of classes, and
894 904 IPython now provides a builtin 'jobs' object for background job
895 905 execution. A convenience %bg magic serves as a lightweight
896 906 frontend for starting the more common type of calls. This was
897 907 inspired by discussions with B. Granger and the BackgroundCommand
898 908 class described in the book Python Scripting for Computational
899 909 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
900 910 (although ultimately no code from this text was used, as IPython's
901 911 system is a separate implementation).
902 912
903 913 * IPython/iplib.py (MagicCompleter.python_matches): add new option
904 914 to control the completion of single/double underscore names
905 915 separately. As documented in the example ipytonrc file, the
906 916 readline_omit__names variable can now be set to 2, to omit even
907 917 single underscore names. Thanks to a patch by Brian Wong
908 918 <BrianWong-AT-AirgoNetworks.Com>.
909 919 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
910 920 be autocalled as foo([1]) if foo were callable. A problem for
911 921 things which are both callable and implement __getitem__.
912 922 (init_readline): Fix autoindentation for win32. Thanks to a patch
913 923 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
914 924
915 925 2005-02-12 Fernando Perez <fperez@colorado.edu>
916 926
917 927 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
918 928 which I had written long ago to sort out user error messages which
919 929 may occur during startup. This seemed like a good idea initially,
920 930 but it has proven a disaster in retrospect. I don't want to
921 931 change much code for now, so my fix is to set the internal 'debug'
922 932 flag to true everywhere, whose only job was precisely to control
923 933 this subsystem. This closes issue 28 (as well as avoiding all
924 934 sorts of strange hangups which occur from time to time).
925 935
926 936 2005-02-07 Fernando Perez <fperez@colorado.edu>
927 937
928 938 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
929 939 previous call produced a syntax error.
930 940
931 941 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
932 942 classes without constructor.
933 943
934 944 2005-02-06 Fernando Perez <fperez@colorado.edu>
935 945
936 946 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
937 947 completions with the results of each matcher, so we return results
938 948 to the user from all namespaces. This breaks with ipython
939 949 tradition, but I think it's a nicer behavior. Now you get all
940 950 possible completions listed, from all possible namespaces (python,
941 951 filesystem, magics...) After a request by John Hunter
942 952 <jdhunter-AT-nitace.bsd.uchicago.edu>.
943 953
944 954 2005-02-05 Fernando Perez <fperez@colorado.edu>
945 955
946 956 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
947 957 the call had quote characters in it (the quotes were stripped).
948 958
949 959 2005-01-31 Fernando Perez <fperez@colorado.edu>
950 960
951 961 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
952 962 Itpl.itpl() to make the code more robust against psyco
953 963 optimizations.
954 964
955 965 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
956 966 of causing an exception. Quicker, cleaner.
957 967
958 968 2005-01-28 Fernando Perez <fperez@colorado.edu>
959 969
960 970 * scripts/ipython_win_post_install.py (install): hardcode
961 971 sys.prefix+'python.exe' as the executable path. It turns out that
962 972 during the post-installation run, sys.executable resolves to the
963 973 name of the binary installer! I should report this as a distutils
964 974 bug, I think. I updated the .10 release with this tiny fix, to
965 975 avoid annoying the lists further.
966 976
967 977 2005-01-27 *** Released version 0.6.10
968 978
969 979 2005-01-27 Fernando Perez <fperez@colorado.edu>
970 980
971 981 * IPython/numutils.py (norm): Added 'inf' as optional name for
972 982 L-infinity norm, included references to mathworld.com for vector
973 983 norm definitions.
974 984 (amin/amax): added amin/amax for array min/max. Similar to what
975 985 pylab ships with after the recent reorganization of names.
976 986 (spike/spike_odd): removed deprecated spike/spike_odd functions.
977 987
978 988 * ipython.el: committed Alex's recent fixes and improvements.
979 989 Tested with python-mode from CVS, and it looks excellent. Since
980 990 python-mode hasn't released anything in a while, I'm temporarily
981 991 putting a copy of today's CVS (v 4.70) of python-mode in:
982 992 http://ipython.scipy.org/tmp/python-mode.el
983 993
984 994 * scripts/ipython_win_post_install.py (install): Win32 fix to use
985 995 sys.executable for the executable name, instead of assuming it's
986 996 called 'python.exe' (the post-installer would have produced broken
987 997 setups on systems with a differently named python binary).
988 998
989 999 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
990 1000 references to os.linesep, to make the code more
991 1001 platform-independent. This is also part of the win32 coloring
992 1002 fixes.
993 1003
994 1004 * IPython/genutils.py (page_dumb): Remove attempts to chop long
995 1005 lines, which actually cause coloring bugs because the length of
996 1006 the line is very difficult to correctly compute with embedded
997 1007 escapes. This was the source of all the coloring problems under
998 1008 Win32. I think that _finally_, Win32 users have a properly
999 1009 working ipython in all respects. This would never have happened
1000 1010 if not for Gary Bishop and Viktor Ransmayr's great help and work.
1001 1011
1002 1012 2005-01-26 *** Released version 0.6.9
1003 1013
1004 1014 2005-01-25 Fernando Perez <fperez@colorado.edu>
1005 1015
1006 1016 * setup.py: finally, we have a true Windows installer, thanks to
1007 1017 the excellent work of Viktor Ransmayr
1008 1018 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
1009 1019 Windows users. The setup routine is quite a bit cleaner thanks to
1010 1020 this, and the post-install script uses the proper functions to
1011 1021 allow a clean de-installation using the standard Windows Control
1012 1022 Panel.
1013 1023
1014 1024 * IPython/genutils.py (get_home_dir): changed to use the $HOME
1015 1025 environment variable under all OSes (including win32) if
1016 1026 available. This will give consistency to win32 users who have set
1017 1027 this variable for any reason. If os.environ['HOME'] fails, the
1018 1028 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
1019 1029
1020 1030 2005-01-24 Fernando Perez <fperez@colorado.edu>
1021 1031
1022 1032 * IPython/numutils.py (empty_like): add empty_like(), similar to
1023 1033 zeros_like() but taking advantage of the new empty() Numeric routine.
1024 1034
1025 1035 2005-01-23 *** Released version 0.6.8
1026 1036
1027 1037 2005-01-22 Fernando Perez <fperez@colorado.edu>
1028 1038
1029 1039 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
1030 1040 automatic show() calls. After discussing things with JDH, it
1031 1041 turns out there are too many corner cases where this can go wrong.
1032 1042 It's best not to try to be 'too smart', and simply have ipython
1033 1043 reproduce as much as possible the default behavior of a normal
1034 1044 python shell.
1035 1045
1036 1046 * IPython/iplib.py (InteractiveShell.__init__): Modified the
1037 1047 line-splitting regexp and _prefilter() to avoid calling getattr()
1038 1048 on assignments. This closes
1039 1049 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
1040 1050 readline uses getattr(), so a simple <TAB> keypress is still
1041 1051 enough to trigger getattr() calls on an object.
1042 1052
1043 1053 2005-01-21 Fernando Perez <fperez@colorado.edu>
1044 1054
1045 1055 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
1046 1056 docstring under pylab so it doesn't mask the original.
1047 1057
1048 1058 2005-01-21 *** Released version 0.6.7
1049 1059
1050 1060 2005-01-21 Fernando Perez <fperez@colorado.edu>
1051 1061
1052 1062 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
1053 1063 signal handling for win32 users in multithreaded mode.
1054 1064
1055 1065 2005-01-17 Fernando Perez <fperez@colorado.edu>
1056 1066
1057 1067 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
1058 1068 instances with no __init__. After a crash report by Norbert Nemec
1059 1069 <Norbert-AT-nemec-online.de>.
1060 1070
1061 1071 2005-01-14 Fernando Perez <fperez@colorado.edu>
1062 1072
1063 1073 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
1064 1074 names for verbose exceptions, when multiple dotted names and the
1065 1075 'parent' object were present on the same line.
1066 1076
1067 1077 2005-01-11 Fernando Perez <fperez@colorado.edu>
1068 1078
1069 1079 * IPython/genutils.py (flag_calls): new utility to trap and flag
1070 1080 calls in functions. I need it to clean up matplotlib support.
1071 1081 Also removed some deprecated code in genutils.
1072 1082
1073 1083 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
1074 1084 that matplotlib scripts called with %run, which don't call show()
1075 1085 themselves, still have their plotting windows open.
1076 1086
1077 1087 2005-01-05 Fernando Perez <fperez@colorado.edu>
1078 1088
1079 1089 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
1080 1090 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
1081 1091
1082 1092 2004-12-19 Fernando Perez <fperez@colorado.edu>
1083 1093
1084 1094 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
1085 1095 parent_runcode, which was an eyesore. The same result can be
1086 1096 obtained with Python's regular superclass mechanisms.
1087 1097
1088 1098 2004-12-17 Fernando Perez <fperez@colorado.edu>
1089 1099
1090 1100 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
1091 1101 reported by Prabhu.
1092 1102 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
1093 1103 sys.stderr) instead of explicitly calling sys.stderr. This helps
1094 1104 maintain our I/O abstractions clean, for future GUI embeddings.
1095 1105
1096 1106 * IPython/genutils.py (info): added new utility for sys.stderr
1097 1107 unified info message handling (thin wrapper around warn()).
1098 1108
1099 1109 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
1100 1110 composite (dotted) names on verbose exceptions.
1101 1111 (VerboseTB.nullrepr): harden against another kind of errors which
1102 1112 Python's inspect module can trigger, and which were crashing
1103 1113 IPython. Thanks to a report by Marco Lombardi
1104 1114 <mlombard-AT-ma010192.hq.eso.org>.
1105 1115
1106 1116 2004-12-13 *** Released version 0.6.6
1107 1117
1108 1118 2004-12-12 Fernando Perez <fperez@colorado.edu>
1109 1119
1110 1120 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
1111 1121 generated by pygtk upon initialization if it was built without
1112 1122 threads (for matplotlib users). After a crash reported by
1113 1123 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
1114 1124
1115 1125 * IPython/ipmaker.py (make_IPython): fix small bug in the
1116 1126 import_some parameter for multiple imports.
1117 1127
1118 1128 * IPython/iplib.py (ipmagic): simplified the interface of
1119 1129 ipmagic() to take a single string argument, just as it would be
1120 1130 typed at the IPython cmd line.
1121 1131 (ipalias): Added new ipalias() with an interface identical to
1122 1132 ipmagic(). This completes exposing a pure python interface to the
1123 1133 alias and magic system, which can be used in loops or more complex
1124 1134 code where IPython's automatic line mangling is not active.
1125 1135
1126 1136 * IPython/genutils.py (timing): changed interface of timing to
1127 1137 simply run code once, which is the most common case. timings()
1128 1138 remains unchanged, for the cases where you want multiple runs.
1129 1139
1130 1140 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
1131 1141 bug where Python2.2 crashes with exec'ing code which does not end
1132 1142 in a single newline. Python 2.3 is OK, so I hadn't noticed this
1133 1143 before.
1134 1144
1135 1145 2004-12-10 Fernando Perez <fperez@colorado.edu>
1136 1146
1137 1147 * IPython/Magic.py (Magic.magic_prun): changed name of option from
1138 1148 -t to -T, to accomodate the new -t flag in %run (the %run and
1139 1149 %prun options are kind of intermixed, and it's not easy to change
1140 1150 this with the limitations of python's getopt).
1141 1151
1142 1152 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
1143 1153 the execution of scripts. It's not as fine-tuned as timeit.py,
1144 1154 but it works from inside ipython (and under 2.2, which lacks
1145 1155 timeit.py). Optionally a number of runs > 1 can be given for
1146 1156 timing very short-running code.
1147 1157
1148 1158 * IPython/genutils.py (uniq_stable): new routine which returns a
1149 1159 list of unique elements in any iterable, but in stable order of
1150 1160 appearance. I needed this for the ultraTB fixes, and it's a handy
1151 1161 utility.
1152 1162
1153 1163 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
1154 1164 dotted names in Verbose exceptions. This had been broken since
1155 1165 the very start, now x.y will properly be printed in a Verbose
1156 1166 traceback, instead of x being shown and y appearing always as an
1157 1167 'undefined global'. Getting this to work was a bit tricky,
1158 1168 because by default python tokenizers are stateless. Saved by
1159 1169 python's ability to easily add a bit of state to an arbitrary
1160 1170 function (without needing to build a full-blown callable object).
1161 1171
1162 1172 Also big cleanup of this code, which had horrendous runtime
1163 1173 lookups of zillions of attributes for colorization. Moved all
1164 1174 this code into a few templates, which make it cleaner and quicker.
1165 1175
1166 1176 Printout quality was also improved for Verbose exceptions: one
1167 1177 variable per line, and memory addresses are printed (this can be
1168 1178 quite handy in nasty debugging situations, which is what Verbose
1169 1179 is for).
1170 1180
1171 1181 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
1172 1182 the command line as scripts to be loaded by embedded instances.
1173 1183 Doing so has the potential for an infinite recursion if there are
1174 1184 exceptions thrown in the process. This fixes a strange crash
1175 1185 reported by Philippe MULLER <muller-AT-irit.fr>.
1176 1186
1177 1187 2004-12-09 Fernando Perez <fperez@colorado.edu>
1178 1188
1179 1189 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
1180 1190 to reflect new names in matplotlib, which now expose the
1181 1191 matlab-compatible interface via a pylab module instead of the
1182 1192 'matlab' name. The new code is backwards compatible, so users of
1183 1193 all matplotlib versions are OK. Patch by J. Hunter.
1184 1194
1185 1195 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
1186 1196 of __init__ docstrings for instances (class docstrings are already
1187 1197 automatically printed). Instances with customized docstrings
1188 1198 (indep. of the class) are also recognized and all 3 separate
1189 1199 docstrings are printed (instance, class, constructor). After some
1190 1200 comments/suggestions by J. Hunter.
1191 1201
1192 1202 2004-12-05 Fernando Perez <fperez@colorado.edu>
1193 1203
1194 1204 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
1195 1205 warnings when tab-completion fails and triggers an exception.
1196 1206
1197 1207 2004-12-03 Fernando Perez <fperez@colorado.edu>
1198 1208
1199 1209 * IPython/Magic.py (magic_prun): Fix bug where an exception would
1200 1210 be triggered when using 'run -p'. An incorrect option flag was
1201 1211 being set ('d' instead of 'D').
1202 1212 (manpage): fix missing escaped \- sign.
1203 1213
1204 1214 2004-11-30 *** Released version 0.6.5
1205 1215
1206 1216 2004-11-30 Fernando Perez <fperez@colorado.edu>
1207 1217
1208 1218 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
1209 1219 setting with -d option.
1210 1220
1211 1221 * setup.py (docfiles): Fix problem where the doc glob I was using
1212 1222 was COMPLETELY BROKEN. It was giving the right files by pure
1213 1223 accident, but failed once I tried to include ipython.el. Note:
1214 1224 glob() does NOT allow you to do exclusion on multiple endings!
1215 1225
1216 1226 2004-11-29 Fernando Perez <fperez@colorado.edu>
1217 1227
1218 1228 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
1219 1229 the manpage as the source. Better formatting & consistency.
1220 1230
1221 1231 * IPython/Magic.py (magic_run): Added new -d option, to run
1222 1232 scripts under the control of the python pdb debugger. Note that
1223 1233 this required changing the %prun option -d to -D, to avoid a clash
1224 1234 (since %run must pass options to %prun, and getopt is too dumb to
1225 1235 handle options with string values with embedded spaces). Thanks
1226 1236 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
1227 1237 (magic_who_ls): added type matching to %who and %whos, so that one
1228 1238 can filter their output to only include variables of certain
1229 1239 types. Another suggestion by Matthew.
1230 1240 (magic_whos): Added memory summaries in kb and Mb for arrays.
1231 1241 (magic_who): Improve formatting (break lines every 9 vars).
1232 1242
1233 1243 2004-11-28 Fernando Perez <fperez@colorado.edu>
1234 1244
1235 1245 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
1236 1246 cache when empty lines were present.
1237 1247
1238 1248 2004-11-24 Fernando Perez <fperez@colorado.edu>
1239 1249
1240 1250 * IPython/usage.py (__doc__): document the re-activated threading
1241 1251 options for WX and GTK.
1242 1252
1243 1253 2004-11-23 Fernando Perez <fperez@colorado.edu>
1244 1254
1245 1255 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
1246 1256 the -wthread and -gthread options, along with a new -tk one to try
1247 1257 and coordinate Tk threading with wx/gtk. The tk support is very
1248 1258 platform dependent, since it seems to require Tcl and Tk to be
1249 1259 built with threads (Fedora1/2 appears NOT to have it, but in
1250 1260 Prabhu's Debian boxes it works OK). But even with some Tk
1251 1261 limitations, this is a great improvement.
1252 1262
1253 1263 * IPython/Prompts.py (prompt_specials_color): Added \t for time
1254 1264 info in user prompts. Patch by Prabhu.
1255 1265
1256 1266 2004-11-18 Fernando Perez <fperez@colorado.edu>
1257 1267
1258 1268 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
1259 1269 EOFErrors and bail, to avoid infinite loops if a non-terminating
1260 1270 file is fed into ipython. Patch submitted in issue 19 by user,
1261 1271 many thanks.
1262 1272
1263 1273 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
1264 1274 autoquote/parens in continuation prompts, which can cause lots of
1265 1275 problems. Closes roundup issue 20.
1266 1276
1267 1277 2004-11-17 Fernando Perez <fperez@colorado.edu>
1268 1278
1269 1279 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
1270 1280 reported as debian bug #280505. I'm not sure my local changelog
1271 1281 entry has the proper debian format (Jack?).
1272 1282
1273 1283 2004-11-08 *** Released version 0.6.4
1274 1284
1275 1285 2004-11-08 Fernando Perez <fperez@colorado.edu>
1276 1286
1277 1287 * IPython/iplib.py (init_readline): Fix exit message for Windows
1278 1288 when readline is active. Thanks to a report by Eric Jones
1279 1289 <eric-AT-enthought.com>.
1280 1290
1281 1291 2004-11-07 Fernando Perez <fperez@colorado.edu>
1282 1292
1283 1293 * IPython/genutils.py (page): Add a trap for OSError exceptions,
1284 1294 sometimes seen by win2k/cygwin users.
1285 1295
1286 1296 2004-11-06 Fernando Perez <fperez@colorado.edu>
1287 1297
1288 1298 * IPython/iplib.py (interact): Change the handling of %Exit from
1289 1299 trying to propagate a SystemExit to an internal ipython flag.
1290 1300 This is less elegant than using Python's exception mechanism, but
1291 1301 I can't get that to work reliably with threads, so under -pylab
1292 1302 %Exit was hanging IPython. Cross-thread exception handling is
1293 1303 really a bitch. Thaks to a bug report by Stephen Walton
1294 1304 <stephen.walton-AT-csun.edu>.
1295 1305
1296 1306 2004-11-04 Fernando Perez <fperez@colorado.edu>
1297 1307
1298 1308 * IPython/iplib.py (raw_input_original): store a pointer to the
1299 1309 true raw_input to harden against code which can modify it
1300 1310 (wx.py.PyShell does this and would otherwise crash ipython).
1301 1311 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
1302 1312
1303 1313 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
1304 1314 Ctrl-C problem, which does not mess up the input line.
1305 1315
1306 1316 2004-11-03 Fernando Perez <fperez@colorado.edu>
1307 1317
1308 1318 * IPython/Release.py: Changed licensing to BSD, in all files.
1309 1319 (name): lowercase name for tarball/RPM release.
1310 1320
1311 1321 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
1312 1322 use throughout ipython.
1313 1323
1314 1324 * IPython/Magic.py (Magic._ofind): Switch to using the new
1315 1325 OInspect.getdoc() function.
1316 1326
1317 1327 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
1318 1328 of the line currently being canceled via Ctrl-C. It's extremely
1319 1329 ugly, but I don't know how to do it better (the problem is one of
1320 1330 handling cross-thread exceptions).
1321 1331
1322 1332 2004-10-28 Fernando Perez <fperez@colorado.edu>
1323 1333
1324 1334 * IPython/Shell.py (signal_handler): add signal handlers to trap
1325 1335 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
1326 1336 report by Francesc Alted.
1327 1337
1328 1338 2004-10-21 Fernando Perez <fperez@colorado.edu>
1329 1339
1330 1340 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
1331 1341 to % for pysh syntax extensions.
1332 1342
1333 1343 2004-10-09 Fernando Perez <fperez@colorado.edu>
1334 1344
1335 1345 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
1336 1346 arrays to print a more useful summary, without calling str(arr).
1337 1347 This avoids the problem of extremely lengthy computations which
1338 1348 occur if arr is large, and appear to the user as a system lockup
1339 1349 with 100% cpu activity. After a suggestion by Kristian Sandberg
1340 1350 <Kristian.Sandberg@colorado.edu>.
1341 1351 (Magic.__init__): fix bug in global magic escapes not being
1342 1352 correctly set.
1343 1353
1344 1354 2004-10-08 Fernando Perez <fperez@colorado.edu>
1345 1355
1346 1356 * IPython/Magic.py (__license__): change to absolute imports of
1347 1357 ipython's own internal packages, to start adapting to the absolute
1348 1358 import requirement of PEP-328.
1349 1359
1350 1360 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
1351 1361 files, and standardize author/license marks through the Release
1352 1362 module instead of having per/file stuff (except for files with
1353 1363 particular licenses, like the MIT/PSF-licensed codes).
1354 1364
1355 1365 * IPython/Debugger.py: remove dead code for python 2.1
1356 1366
1357 1367 2004-10-04 Fernando Perez <fperez@colorado.edu>
1358 1368
1359 1369 * IPython/iplib.py (ipmagic): New function for accessing magics
1360 1370 via a normal python function call.
1361 1371
1362 1372 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
1363 1373 from '@' to '%', to accomodate the new @decorator syntax of python
1364 1374 2.4.
1365 1375
1366 1376 2004-09-29 Fernando Perez <fperez@colorado.edu>
1367 1377
1368 1378 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
1369 1379 matplotlib.use to prevent running scripts which try to switch
1370 1380 interactive backends from within ipython. This will just crash
1371 1381 the python interpreter, so we can't allow it (but a detailed error
1372 1382 is given to the user).
1373 1383
1374 1384 2004-09-28 Fernando Perez <fperez@colorado.edu>
1375 1385
1376 1386 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
1377 1387 matplotlib-related fixes so that using @run with non-matplotlib
1378 1388 scripts doesn't pop up spurious plot windows. This requires
1379 1389 matplotlib >= 0.63, where I had to make some changes as well.
1380 1390
1381 1391 * IPython/ipmaker.py (make_IPython): update version requirement to
1382 1392 python 2.2.
1383 1393
1384 1394 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
1385 1395 banner arg for embedded customization.
1386 1396
1387 1397 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
1388 1398 explicit uses of __IP as the IPython's instance name. Now things
1389 1399 are properly handled via the shell.name value. The actual code
1390 1400 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
1391 1401 is much better than before. I'll clean things completely when the
1392 1402 magic stuff gets a real overhaul.
1393 1403
1394 1404 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
1395 1405 minor changes to debian dir.
1396 1406
1397 1407 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
1398 1408 pointer to the shell itself in the interactive namespace even when
1399 1409 a user-supplied dict is provided. This is needed for embedding
1400 1410 purposes (found by tests with Michel Sanner).
1401 1411
1402 1412 2004-09-27 Fernando Perez <fperez@colorado.edu>
1403 1413
1404 1414 * IPython/UserConfig/ipythonrc: remove []{} from
1405 1415 readline_remove_delims, so that things like [modname.<TAB> do
1406 1416 proper completion. This disables [].TAB, but that's a less common
1407 1417 case than module names in list comprehensions, for example.
1408 1418 Thanks to a report by Andrea Riciputi.
1409 1419
1410 1420 2004-09-09 Fernando Perez <fperez@colorado.edu>
1411 1421
1412 1422 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1413 1423 blocking problems in win32 and osx. Fix by John.
1414 1424
1415 1425 2004-09-08 Fernando Perez <fperez@colorado.edu>
1416 1426
1417 1427 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1418 1428 for Win32 and OSX. Fix by John Hunter.
1419 1429
1420 1430 2004-08-30 *** Released version 0.6.3
1421 1431
1422 1432 2004-08-30 Fernando Perez <fperez@colorado.edu>
1423 1433
1424 1434 * setup.py (isfile): Add manpages to list of dependent files to be
1425 1435 updated.
1426 1436
1427 1437 2004-08-27 Fernando Perez <fperez@colorado.edu>
1428 1438
1429 1439 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1430 1440 for now. They don't really work with standalone WX/GTK code
1431 1441 (though matplotlib IS working fine with both of those backends).
1432 1442 This will neeed much more testing. I disabled most things with
1433 1443 comments, so turning it back on later should be pretty easy.
1434 1444
1435 1445 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1436 1446 autocalling of expressions like r'foo', by modifying the line
1437 1447 split regexp. Closes
1438 1448 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1439 1449 Riley <ipythonbugs-AT-sabi.net>.
1440 1450 (InteractiveShell.mainloop): honor --nobanner with banner
1441 1451 extensions.
1442 1452
1443 1453 * IPython/Shell.py: Significant refactoring of all classes, so
1444 1454 that we can really support ALL matplotlib backends and threading
1445 1455 models (John spotted a bug with Tk which required this). Now we
1446 1456 should support single-threaded, WX-threads and GTK-threads, both
1447 1457 for generic code and for matplotlib.
1448 1458
1449 1459 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1450 1460 -pylab, to simplify things for users. Will also remove the pylab
1451 1461 profile, since now all of matplotlib configuration is directly
1452 1462 handled here. This also reduces startup time.
1453 1463
1454 1464 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1455 1465 shell wasn't being correctly called. Also in IPShellWX.
1456 1466
1457 1467 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1458 1468 fine-tune banner.
1459 1469
1460 1470 * IPython/numutils.py (spike): Deprecate these spike functions,
1461 1471 delete (long deprecated) gnuplot_exec handler.
1462 1472
1463 1473 2004-08-26 Fernando Perez <fperez@colorado.edu>
1464 1474
1465 1475 * ipython.1: Update for threading options, plus some others which
1466 1476 were missing.
1467 1477
1468 1478 * IPython/ipmaker.py (__call__): Added -wthread option for
1469 1479 wxpython thread handling. Make sure threading options are only
1470 1480 valid at the command line.
1471 1481
1472 1482 * scripts/ipython: moved shell selection into a factory function
1473 1483 in Shell.py, to keep the starter script to a minimum.
1474 1484
1475 1485 2004-08-25 Fernando Perez <fperez@colorado.edu>
1476 1486
1477 1487 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1478 1488 John. Along with some recent changes he made to matplotlib, the
1479 1489 next versions of both systems should work very well together.
1480 1490
1481 1491 2004-08-24 Fernando Perez <fperez@colorado.edu>
1482 1492
1483 1493 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1484 1494 tried to switch the profiling to using hotshot, but I'm getting
1485 1495 strange errors from prof.runctx() there. I may be misreading the
1486 1496 docs, but it looks weird. For now the profiling code will
1487 1497 continue to use the standard profiler.
1488 1498
1489 1499 2004-08-23 Fernando Perez <fperez@colorado.edu>
1490 1500
1491 1501 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1492 1502 threaded shell, by John Hunter. It's not quite ready yet, but
1493 1503 close.
1494 1504
1495 1505 2004-08-22 Fernando Perez <fperez@colorado.edu>
1496 1506
1497 1507 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1498 1508 in Magic and ultraTB.
1499 1509
1500 1510 * ipython.1: document threading options in manpage.
1501 1511
1502 1512 * scripts/ipython: Changed name of -thread option to -gthread,
1503 1513 since this is GTK specific. I want to leave the door open for a
1504 1514 -wthread option for WX, which will most likely be necessary. This
1505 1515 change affects usage and ipmaker as well.
1506 1516
1507 1517 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1508 1518 handle the matplotlib shell issues. Code by John Hunter
1509 1519 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1510 1520 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1511 1521 broken (and disabled for end users) for now, but it puts the
1512 1522 infrastructure in place.
1513 1523
1514 1524 2004-08-21 Fernando Perez <fperez@colorado.edu>
1515 1525
1516 1526 * ipythonrc-pylab: Add matplotlib support.
1517 1527
1518 1528 * matplotlib_config.py: new files for matplotlib support, part of
1519 1529 the pylab profile.
1520 1530
1521 1531 * IPython/usage.py (__doc__): documented the threading options.
1522 1532
1523 1533 2004-08-20 Fernando Perez <fperez@colorado.edu>
1524 1534
1525 1535 * ipython: Modified the main calling routine to handle the -thread
1526 1536 and -mpthread options. This needs to be done as a top-level hack,
1527 1537 because it determines which class to instantiate for IPython
1528 1538 itself.
1529 1539
1530 1540 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1531 1541 classes to support multithreaded GTK operation without blocking,
1532 1542 and matplotlib with all backends. This is a lot of still very
1533 1543 experimental code, and threads are tricky. So it may still have a
1534 1544 few rough edges... This code owes a lot to
1535 1545 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1536 1546 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1537 1547 to John Hunter for all the matplotlib work.
1538 1548
1539 1549 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1540 1550 options for gtk thread and matplotlib support.
1541 1551
1542 1552 2004-08-16 Fernando Perez <fperez@colorado.edu>
1543 1553
1544 1554 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1545 1555 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1546 1556 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1547 1557
1548 1558 2004-08-11 Fernando Perez <fperez@colorado.edu>
1549 1559
1550 1560 * setup.py (isfile): Fix build so documentation gets updated for
1551 1561 rpms (it was only done for .tgz builds).
1552 1562
1553 1563 2004-08-10 Fernando Perez <fperez@colorado.edu>
1554 1564
1555 1565 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1556 1566
1557 1567 * iplib.py : Silence syntax error exceptions in tab-completion.
1558 1568
1559 1569 2004-08-05 Fernando Perez <fperez@colorado.edu>
1560 1570
1561 1571 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1562 1572 'color off' mark for continuation prompts. This was causing long
1563 1573 continuation lines to mis-wrap.
1564 1574
1565 1575 2004-08-01 Fernando Perez <fperez@colorado.edu>
1566 1576
1567 1577 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1568 1578 for building ipython to be a parameter. All this is necessary
1569 1579 right now to have a multithreaded version, but this insane
1570 1580 non-design will be cleaned up soon. For now, it's a hack that
1571 1581 works.
1572 1582
1573 1583 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1574 1584 args in various places. No bugs so far, but it's a dangerous
1575 1585 practice.
1576 1586
1577 1587 2004-07-31 Fernando Perez <fperez@colorado.edu>
1578 1588
1579 1589 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1580 1590 fix completion of files with dots in their names under most
1581 1591 profiles (pysh was OK because the completion order is different).
1582 1592
1583 1593 2004-07-27 Fernando Perez <fperez@colorado.edu>
1584 1594
1585 1595 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1586 1596 keywords manually, b/c the one in keyword.py was removed in python
1587 1597 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1588 1598 This is NOT a bug under python 2.3 and earlier.
1589 1599
1590 1600 2004-07-26 Fernando Perez <fperez@colorado.edu>
1591 1601
1592 1602 * IPython/ultraTB.py (VerboseTB.text): Add another
1593 1603 linecache.checkcache() call to try to prevent inspect.py from
1594 1604 crashing under python 2.3. I think this fixes
1595 1605 http://www.scipy.net/roundup/ipython/issue17.
1596 1606
1597 1607 2004-07-26 *** Released version 0.6.2
1598 1608
1599 1609 2004-07-26 Fernando Perez <fperez@colorado.edu>
1600 1610
1601 1611 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1602 1612 fail for any number.
1603 1613 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1604 1614 empty bookmarks.
1605 1615
1606 1616 2004-07-26 *** Released version 0.6.1
1607 1617
1608 1618 2004-07-26 Fernando Perez <fperez@colorado.edu>
1609 1619
1610 1620 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1611 1621
1612 1622 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1613 1623 escaping '()[]{}' in filenames.
1614 1624
1615 1625 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1616 1626 Python 2.2 users who lack a proper shlex.split.
1617 1627
1618 1628 2004-07-19 Fernando Perez <fperez@colorado.edu>
1619 1629
1620 1630 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1621 1631 for reading readline's init file. I follow the normal chain:
1622 1632 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1623 1633 report by Mike Heeter. This closes
1624 1634 http://www.scipy.net/roundup/ipython/issue16.
1625 1635
1626 1636 2004-07-18 Fernando Perez <fperez@colorado.edu>
1627 1637
1628 1638 * IPython/iplib.py (__init__): Add better handling of '\' under
1629 1639 Win32 for filenames. After a patch by Ville.
1630 1640
1631 1641 2004-07-17 Fernando Perez <fperez@colorado.edu>
1632 1642
1633 1643 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1634 1644 autocalling would be triggered for 'foo is bar' if foo is
1635 1645 callable. I also cleaned up the autocall detection code to use a
1636 1646 regexp, which is faster. Bug reported by Alexander Schmolck.
1637 1647
1638 1648 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1639 1649 '?' in them would confuse the help system. Reported by Alex
1640 1650 Schmolck.
1641 1651
1642 1652 2004-07-16 Fernando Perez <fperez@colorado.edu>
1643 1653
1644 1654 * IPython/GnuplotInteractive.py (__all__): added plot2.
1645 1655
1646 1656 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1647 1657 plotting dictionaries, lists or tuples of 1d arrays.
1648 1658
1649 1659 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1650 1660 optimizations.
1651 1661
1652 1662 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1653 1663 the information which was there from Janko's original IPP code:
1654 1664
1655 1665 03.05.99 20:53 porto.ifm.uni-kiel.de
1656 1666 --Started changelog.
1657 1667 --make clear do what it say it does
1658 1668 --added pretty output of lines from inputcache
1659 1669 --Made Logger a mixin class, simplifies handling of switches
1660 1670 --Added own completer class. .string<TAB> expands to last history
1661 1671 line which starts with string. The new expansion is also present
1662 1672 with Ctrl-r from the readline library. But this shows, who this
1663 1673 can be done for other cases.
1664 1674 --Added convention that all shell functions should accept a
1665 1675 parameter_string This opens the door for different behaviour for
1666 1676 each function. @cd is a good example of this.
1667 1677
1668 1678 04.05.99 12:12 porto.ifm.uni-kiel.de
1669 1679 --added logfile rotation
1670 1680 --added new mainloop method which freezes first the namespace
1671 1681
1672 1682 07.05.99 21:24 porto.ifm.uni-kiel.de
1673 1683 --added the docreader classes. Now there is a help system.
1674 1684 -This is only a first try. Currently it's not easy to put new
1675 1685 stuff in the indices. But this is the way to go. Info would be
1676 1686 better, but HTML is every where and not everybody has an info
1677 1687 system installed and it's not so easy to change html-docs to info.
1678 1688 --added global logfile option
1679 1689 --there is now a hook for object inspection method pinfo needs to
1680 1690 be provided for this. Can be reached by two '??'.
1681 1691
1682 1692 08.05.99 20:51 porto.ifm.uni-kiel.de
1683 1693 --added a README
1684 1694 --bug in rc file. Something has changed so functions in the rc
1685 1695 file need to reference the shell and not self. Not clear if it's a
1686 1696 bug or feature.
1687 1697 --changed rc file for new behavior
1688 1698
1689 1699 2004-07-15 Fernando Perez <fperez@colorado.edu>
1690 1700
1691 1701 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1692 1702 cache was falling out of sync in bizarre manners when multi-line
1693 1703 input was present. Minor optimizations and cleanup.
1694 1704
1695 1705 (Logger): Remove old Changelog info for cleanup. This is the
1696 1706 information which was there from Janko's original code:
1697 1707
1698 1708 Changes to Logger: - made the default log filename a parameter
1699 1709
1700 1710 - put a check for lines beginning with !@? in log(). Needed
1701 1711 (even if the handlers properly log their lines) for mid-session
1702 1712 logging activation to work properly. Without this, lines logged
1703 1713 in mid session, which get read from the cache, would end up
1704 1714 'bare' (with !@? in the open) in the log. Now they are caught
1705 1715 and prepended with a #.
1706 1716
1707 1717 * IPython/iplib.py (InteractiveShell.init_readline): added check
1708 1718 in case MagicCompleter fails to be defined, so we don't crash.
1709 1719
1710 1720 2004-07-13 Fernando Perez <fperez@colorado.edu>
1711 1721
1712 1722 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1713 1723 of EPS if the requested filename ends in '.eps'.
1714 1724
1715 1725 2004-07-04 Fernando Perez <fperez@colorado.edu>
1716 1726
1717 1727 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1718 1728 escaping of quotes when calling the shell.
1719 1729
1720 1730 2004-07-02 Fernando Perez <fperez@colorado.edu>
1721 1731
1722 1732 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1723 1733 gettext not working because we were clobbering '_'. Fixes
1724 1734 http://www.scipy.net/roundup/ipython/issue6.
1725 1735
1726 1736 2004-07-01 Fernando Perez <fperez@colorado.edu>
1727 1737
1728 1738 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1729 1739 into @cd. Patch by Ville.
1730 1740
1731 1741 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1732 1742 new function to store things after ipmaker runs. Patch by Ville.
1733 1743 Eventually this will go away once ipmaker is removed and the class
1734 1744 gets cleaned up, but for now it's ok. Key functionality here is
1735 1745 the addition of the persistent storage mechanism, a dict for
1736 1746 keeping data across sessions (for now just bookmarks, but more can
1737 1747 be implemented later).
1738 1748
1739 1749 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1740 1750 persistent across sections. Patch by Ville, I modified it
1741 1751 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1742 1752 added a '-l' option to list all bookmarks.
1743 1753
1744 1754 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1745 1755 center for cleanup. Registered with atexit.register(). I moved
1746 1756 here the old exit_cleanup(). After a patch by Ville.
1747 1757
1748 1758 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1749 1759 characters in the hacked shlex_split for python 2.2.
1750 1760
1751 1761 * IPython/iplib.py (file_matches): more fixes to filenames with
1752 1762 whitespace in them. It's not perfect, but limitations in python's
1753 1763 readline make it impossible to go further.
1754 1764
1755 1765 2004-06-29 Fernando Perez <fperez@colorado.edu>
1756 1766
1757 1767 * IPython/iplib.py (file_matches): escape whitespace correctly in
1758 1768 filename completions. Bug reported by Ville.
1759 1769
1760 1770 2004-06-28 Fernando Perez <fperez@colorado.edu>
1761 1771
1762 1772 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1763 1773 the history file will be called 'history-PROFNAME' (or just
1764 1774 'history' if no profile is loaded). I was getting annoyed at
1765 1775 getting my Numerical work history clobbered by pysh sessions.
1766 1776
1767 1777 * IPython/iplib.py (InteractiveShell.__init__): Internal
1768 1778 getoutputerror() function so that we can honor the system_verbose
1769 1779 flag for _all_ system calls. I also added escaping of #
1770 1780 characters here to avoid confusing Itpl.
1771 1781
1772 1782 * IPython/Magic.py (shlex_split): removed call to shell in
1773 1783 parse_options and replaced it with shlex.split(). The annoying
1774 1784 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1775 1785 to backport it from 2.3, with several frail hacks (the shlex
1776 1786 module is rather limited in 2.2). Thanks to a suggestion by Ville
1777 1787 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1778 1788 problem.
1779 1789
1780 1790 (Magic.magic_system_verbose): new toggle to print the actual
1781 1791 system calls made by ipython. Mainly for debugging purposes.
1782 1792
1783 1793 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1784 1794 doesn't support persistence. Reported (and fix suggested) by
1785 1795 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1786 1796
1787 1797 2004-06-26 Fernando Perez <fperez@colorado.edu>
1788 1798
1789 1799 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1790 1800 continue prompts.
1791 1801
1792 1802 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1793 1803 function (basically a big docstring) and a few more things here to
1794 1804 speedup startup. pysh.py is now very lightweight. We want because
1795 1805 it gets execfile'd, while InterpreterExec gets imported, so
1796 1806 byte-compilation saves time.
1797 1807
1798 1808 2004-06-25 Fernando Perez <fperez@colorado.edu>
1799 1809
1800 1810 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1801 1811 -NUM', which was recently broken.
1802 1812
1803 1813 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1804 1814 in multi-line input (but not !!, which doesn't make sense there).
1805 1815
1806 1816 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1807 1817 It's just too useful, and people can turn it off in the less
1808 1818 common cases where it's a problem.
1809 1819
1810 1820 2004-06-24 Fernando Perez <fperez@colorado.edu>
1811 1821
1812 1822 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1813 1823 special syntaxes (like alias calling) is now allied in multi-line
1814 1824 input. This is still _very_ experimental, but it's necessary for
1815 1825 efficient shell usage combining python looping syntax with system
1816 1826 calls. For now it's restricted to aliases, I don't think it
1817 1827 really even makes sense to have this for magics.
1818 1828
1819 1829 2004-06-23 Fernando Perez <fperez@colorado.edu>
1820 1830
1821 1831 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1822 1832 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1823 1833
1824 1834 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1825 1835 extensions under Windows (after code sent by Gary Bishop). The
1826 1836 extensions considered 'executable' are stored in IPython's rc
1827 1837 structure as win_exec_ext.
1828 1838
1829 1839 * IPython/genutils.py (shell): new function, like system() but
1830 1840 without return value. Very useful for interactive shell work.
1831 1841
1832 1842 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1833 1843 delete aliases.
1834 1844
1835 1845 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1836 1846 sure that the alias table doesn't contain python keywords.
1837 1847
1838 1848 2004-06-21 Fernando Perez <fperez@colorado.edu>
1839 1849
1840 1850 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1841 1851 non-existent items are found in $PATH. Reported by Thorsten.
1842 1852
1843 1853 2004-06-20 Fernando Perez <fperez@colorado.edu>
1844 1854
1845 1855 * IPython/iplib.py (complete): modified the completer so that the
1846 1856 order of priorities can be easily changed at runtime.
1847 1857
1848 1858 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1849 1859 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1850 1860
1851 1861 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1852 1862 expand Python variables prepended with $ in all system calls. The
1853 1863 same was done to InteractiveShell.handle_shell_escape. Now all
1854 1864 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1855 1865 expansion of python variables and expressions according to the
1856 1866 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1857 1867
1858 1868 Though PEP-215 has been rejected, a similar (but simpler) one
1859 1869 seems like it will go into Python 2.4, PEP-292 -
1860 1870 http://www.python.org/peps/pep-0292.html.
1861 1871
1862 1872 I'll keep the full syntax of PEP-215, since IPython has since the
1863 1873 start used Ka-Ping Yee's reference implementation discussed there
1864 1874 (Itpl), and I actually like the powerful semantics it offers.
1865 1875
1866 1876 In order to access normal shell variables, the $ has to be escaped
1867 1877 via an extra $. For example:
1868 1878
1869 1879 In [7]: PATH='a python variable'
1870 1880
1871 1881 In [8]: !echo $PATH
1872 1882 a python variable
1873 1883
1874 1884 In [9]: !echo $$PATH
1875 1885 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1876 1886
1877 1887 (Magic.parse_options): escape $ so the shell doesn't evaluate
1878 1888 things prematurely.
1879 1889
1880 1890 * IPython/iplib.py (InteractiveShell.call_alias): added the
1881 1891 ability for aliases to expand python variables via $.
1882 1892
1883 1893 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1884 1894 system, now there's a @rehash/@rehashx pair of magics. These work
1885 1895 like the csh rehash command, and can be invoked at any time. They
1886 1896 build a table of aliases to everything in the user's $PATH
1887 1897 (@rehash uses everything, @rehashx is slower but only adds
1888 1898 executable files). With this, the pysh.py-based shell profile can
1889 1899 now simply call rehash upon startup, and full access to all
1890 1900 programs in the user's path is obtained.
1891 1901
1892 1902 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1893 1903 functionality is now fully in place. I removed the old dynamic
1894 1904 code generation based approach, in favor of a much lighter one
1895 1905 based on a simple dict. The advantage is that this allows me to
1896 1906 now have thousands of aliases with negligible cost (unthinkable
1897 1907 with the old system).
1898 1908
1899 1909 2004-06-19 Fernando Perez <fperez@colorado.edu>
1900 1910
1901 1911 * IPython/iplib.py (__init__): extended MagicCompleter class to
1902 1912 also complete (last in priority) on user aliases.
1903 1913
1904 1914 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1905 1915 call to eval.
1906 1916 (ItplNS.__init__): Added a new class which functions like Itpl,
1907 1917 but allows configuring the namespace for the evaluation to occur
1908 1918 in.
1909 1919
1910 1920 2004-06-18 Fernando Perez <fperez@colorado.edu>
1911 1921
1912 1922 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1913 1923 better message when 'exit' or 'quit' are typed (a common newbie
1914 1924 confusion).
1915 1925
1916 1926 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1917 1927 check for Windows users.
1918 1928
1919 1929 * IPython/iplib.py (InteractiveShell.user_setup): removed
1920 1930 disabling of colors for Windows. I'll test at runtime and issue a
1921 1931 warning if Gary's readline isn't found, as to nudge users to
1922 1932 download it.
1923 1933
1924 1934 2004-06-16 Fernando Perez <fperez@colorado.edu>
1925 1935
1926 1936 * IPython/genutils.py (Stream.__init__): changed to print errors
1927 1937 to sys.stderr. I had a circular dependency here. Now it's
1928 1938 possible to run ipython as IDLE's shell (consider this pre-alpha,
1929 1939 since true stdout things end up in the starting terminal instead
1930 1940 of IDLE's out).
1931 1941
1932 1942 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1933 1943 users who haven't # updated their prompt_in2 definitions. Remove
1934 1944 eventually.
1935 1945 (multiple_replace): added credit to original ASPN recipe.
1936 1946
1937 1947 2004-06-15 Fernando Perez <fperez@colorado.edu>
1938 1948
1939 1949 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1940 1950 list of auto-defined aliases.
1941 1951
1942 1952 2004-06-13 Fernando Perez <fperez@colorado.edu>
1943 1953
1944 1954 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1945 1955 install was really requested (so setup.py can be used for other
1946 1956 things under Windows).
1947 1957
1948 1958 2004-06-10 Fernando Perez <fperez@colorado.edu>
1949 1959
1950 1960 * IPython/Logger.py (Logger.create_log): Manually remove any old
1951 1961 backup, since os.remove may fail under Windows. Fixes bug
1952 1962 reported by Thorsten.
1953 1963
1954 1964 2004-06-09 Fernando Perez <fperez@colorado.edu>
1955 1965
1956 1966 * examples/example-embed.py: fixed all references to %n (replaced
1957 1967 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1958 1968 for all examples and the manual as well.
1959 1969
1960 1970 2004-06-08 Fernando Perez <fperez@colorado.edu>
1961 1971
1962 1972 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1963 1973 alignment and color management. All 3 prompt subsystems now
1964 1974 inherit from BasePrompt.
1965 1975
1966 1976 * tools/release: updates for windows installer build and tag rpms
1967 1977 with python version (since paths are fixed).
1968 1978
1969 1979 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1970 1980 which will become eventually obsolete. Also fixed the default
1971 1981 prompt_in2 to use \D, so at least new users start with the correct
1972 1982 defaults.
1973 1983 WARNING: Users with existing ipythonrc files will need to apply
1974 1984 this fix manually!
1975 1985
1976 1986 * setup.py: make windows installer (.exe). This is finally the
1977 1987 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1978 1988 which I hadn't included because it required Python 2.3 (or recent
1979 1989 distutils).
1980 1990
1981 1991 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1982 1992 usage of new '\D' escape.
1983 1993
1984 1994 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1985 1995 lacks os.getuid())
1986 1996 (CachedOutput.set_colors): Added the ability to turn coloring
1987 1997 on/off with @colors even for manually defined prompt colors. It
1988 1998 uses a nasty global, but it works safely and via the generic color
1989 1999 handling mechanism.
1990 2000 (Prompt2.__init__): Introduced new escape '\D' for continuation
1991 2001 prompts. It represents the counter ('\#') as dots.
1992 2002 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1993 2003 need to update their ipythonrc files and replace '%n' with '\D' in
1994 2004 their prompt_in2 settings everywhere. Sorry, but there's
1995 2005 otherwise no clean way to get all prompts to properly align. The
1996 2006 ipythonrc shipped with IPython has been updated.
1997 2007
1998 2008 2004-06-07 Fernando Perez <fperez@colorado.edu>
1999 2009
2000 2010 * setup.py (isfile): Pass local_icons option to latex2html, so the
2001 2011 resulting HTML file is self-contained. Thanks to
2002 2012 dryice-AT-liu.com.cn for the tip.
2003 2013
2004 2014 * pysh.py: I created a new profile 'shell', which implements a
2005 2015 _rudimentary_ IPython-based shell. This is in NO WAY a realy
2006 2016 system shell, nor will it become one anytime soon. It's mainly
2007 2017 meant to illustrate the use of the new flexible bash-like prompts.
2008 2018 I guess it could be used by hardy souls for true shell management,
2009 2019 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
2010 2020 profile. This uses the InterpreterExec extension provided by
2011 2021 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
2012 2022
2013 2023 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
2014 2024 auto-align itself with the length of the previous input prompt
2015 2025 (taking into account the invisible color escapes).
2016 2026 (CachedOutput.__init__): Large restructuring of this class. Now
2017 2027 all three prompts (primary1, primary2, output) are proper objects,
2018 2028 managed by the 'parent' CachedOutput class. The code is still a
2019 2029 bit hackish (all prompts share state via a pointer to the cache),
2020 2030 but it's overall far cleaner than before.
2021 2031
2022 2032 * IPython/genutils.py (getoutputerror): modified to add verbose,
2023 2033 debug and header options. This makes the interface of all getout*
2024 2034 functions uniform.
2025 2035 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
2026 2036
2027 2037 * IPython/Magic.py (Magic.default_option): added a function to
2028 2038 allow registering default options for any magic command. This
2029 2039 makes it easy to have profiles which customize the magics globally
2030 2040 for a certain use. The values set through this function are
2031 2041 picked up by the parse_options() method, which all magics should
2032 2042 use to parse their options.
2033 2043
2034 2044 * IPython/genutils.py (warn): modified the warnings framework to
2035 2045 use the Term I/O class. I'm trying to slowly unify all of
2036 2046 IPython's I/O operations to pass through Term.
2037 2047
2038 2048 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
2039 2049 the secondary prompt to correctly match the length of the primary
2040 2050 one for any prompt. Now multi-line code will properly line up
2041 2051 even for path dependent prompts, such as the new ones available
2042 2052 via the prompt_specials.
2043 2053
2044 2054 2004-06-06 Fernando Perez <fperez@colorado.edu>
2045 2055
2046 2056 * IPython/Prompts.py (prompt_specials): Added the ability to have
2047 2057 bash-like special sequences in the prompts, which get
2048 2058 automatically expanded. Things like hostname, current working
2049 2059 directory and username are implemented already, but it's easy to
2050 2060 add more in the future. Thanks to a patch by W.J. van der Laan
2051 2061 <gnufnork-AT-hetdigitalegat.nl>
2052 2062 (prompt_specials): Added color support for prompt strings, so
2053 2063 users can define arbitrary color setups for their prompts.
2054 2064
2055 2065 2004-06-05 Fernando Perez <fperez@colorado.edu>
2056 2066
2057 2067 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
2058 2068 code to load Gary Bishop's readline and configure it
2059 2069 automatically. Thanks to Gary for help on this.
2060 2070
2061 2071 2004-06-01 Fernando Perez <fperez@colorado.edu>
2062 2072
2063 2073 * IPython/Logger.py (Logger.create_log): fix bug for logging
2064 2074 with no filename (previous fix was incomplete).
2065 2075
2066 2076 2004-05-25 Fernando Perez <fperez@colorado.edu>
2067 2077
2068 2078 * IPython/Magic.py (Magic.parse_options): fix bug where naked
2069 2079 parens would get passed to the shell.
2070 2080
2071 2081 2004-05-20 Fernando Perez <fperez@colorado.edu>
2072 2082
2073 2083 * IPython/Magic.py (Magic.magic_prun): changed default profile
2074 2084 sort order to 'time' (the more common profiling need).
2075 2085
2076 2086 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
2077 2087 so that source code shown is guaranteed in sync with the file on
2078 2088 disk (also changed in psource). Similar fix to the one for
2079 2089 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
2080 2090 <yann.ledu-AT-noos.fr>.
2081 2091
2082 2092 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
2083 2093 with a single option would not be correctly parsed. Closes
2084 2094 http://www.scipy.net/roundup/ipython/issue14. This bug had been
2085 2095 introduced in 0.6.0 (on 2004-05-06).
2086 2096
2087 2097 2004-05-13 *** Released version 0.6.0
2088 2098
2089 2099 2004-05-13 Fernando Perez <fperez@colorado.edu>
2090 2100
2091 2101 * debian/: Added debian/ directory to CVS, so that debian support
2092 2102 is publicly accessible. The debian package is maintained by Jack
2093 2103 Moffit <jack-AT-xiph.org>.
2094 2104
2095 2105 * Documentation: included the notes about an ipython-based system
2096 2106 shell (the hypothetical 'pysh') into the new_design.pdf document,
2097 2107 so that these ideas get distributed to users along with the
2098 2108 official documentation.
2099 2109
2100 2110 2004-05-10 Fernando Perez <fperez@colorado.edu>
2101 2111
2102 2112 * IPython/Logger.py (Logger.create_log): fix recently introduced
2103 2113 bug (misindented line) where logstart would fail when not given an
2104 2114 explicit filename.
2105 2115
2106 2116 2004-05-09 Fernando Perez <fperez@colorado.edu>
2107 2117
2108 2118 * IPython/Magic.py (Magic.parse_options): skip system call when
2109 2119 there are no options to look for. Faster, cleaner for the common
2110 2120 case.
2111 2121
2112 2122 * Documentation: many updates to the manual: describing Windows
2113 2123 support better, Gnuplot updates, credits, misc small stuff. Also
2114 2124 updated the new_design doc a bit.
2115 2125
2116 2126 2004-05-06 *** Released version 0.6.0.rc1
2117 2127
2118 2128 2004-05-06 Fernando Perez <fperez@colorado.edu>
2119 2129
2120 2130 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
2121 2131 operations to use the vastly more efficient list/''.join() method.
2122 2132 (FormattedTB.text): Fix
2123 2133 http://www.scipy.net/roundup/ipython/issue12 - exception source
2124 2134 extract not updated after reload. Thanks to Mike Salib
2125 2135 <msalib-AT-mit.edu> for pinning the source of the problem.
2126 2136 Fortunately, the solution works inside ipython and doesn't require
2127 2137 any changes to python proper.
2128 2138
2129 2139 * IPython/Magic.py (Magic.parse_options): Improved to process the
2130 2140 argument list as a true shell would (by actually using the
2131 2141 underlying system shell). This way, all @magics automatically get
2132 2142 shell expansion for variables. Thanks to a comment by Alex
2133 2143 Schmolck.
2134 2144
2135 2145 2004-04-04 Fernando Perez <fperez@colorado.edu>
2136 2146
2137 2147 * IPython/iplib.py (InteractiveShell.interact): Added a special
2138 2148 trap for a debugger quit exception, which is basically impossible
2139 2149 to handle by normal mechanisms, given what pdb does to the stack.
2140 2150 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
2141 2151
2142 2152 2004-04-03 Fernando Perez <fperez@colorado.edu>
2143 2153
2144 2154 * IPython/genutils.py (Term): Standardized the names of the Term
2145 2155 class streams to cin/cout/cerr, following C++ naming conventions
2146 2156 (I can't use in/out/err because 'in' is not a valid attribute
2147 2157 name).
2148 2158
2149 2159 * IPython/iplib.py (InteractiveShell.interact): don't increment
2150 2160 the prompt if there's no user input. By Daniel 'Dang' Griffith
2151 2161 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
2152 2162 Francois Pinard.
2153 2163
2154 2164 2004-04-02 Fernando Perez <fperez@colorado.edu>
2155 2165
2156 2166 * IPython/genutils.py (Stream.__init__): Modified to survive at
2157 2167 least importing in contexts where stdin/out/err aren't true file
2158 2168 objects, such as PyCrust (they lack fileno() and mode). However,
2159 2169 the recovery facilities which rely on these things existing will
2160 2170 not work.
2161 2171
2162 2172 2004-04-01 Fernando Perez <fperez@colorado.edu>
2163 2173
2164 2174 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
2165 2175 use the new getoutputerror() function, so it properly
2166 2176 distinguishes stdout/err.
2167 2177
2168 2178 * IPython/genutils.py (getoutputerror): added a function to
2169 2179 capture separately the standard output and error of a command.
2170 2180 After a comment from dang on the mailing lists. This code is
2171 2181 basically a modified version of commands.getstatusoutput(), from
2172 2182 the standard library.
2173 2183
2174 2184 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
2175 2185 '!!' as a special syntax (shorthand) to access @sx.
2176 2186
2177 2187 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
2178 2188 command and return its output as a list split on '\n'.
2179 2189
2180 2190 2004-03-31 Fernando Perez <fperez@colorado.edu>
2181 2191
2182 2192 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
2183 2193 method to dictionaries used as FakeModule instances if they lack
2184 2194 it. At least pydoc in python2.3 breaks for runtime-defined
2185 2195 functions without this hack. At some point I need to _really_
2186 2196 understand what FakeModule is doing, because it's a gross hack.
2187 2197 But it solves Arnd's problem for now...
2188 2198
2189 2199 2004-02-27 Fernando Perez <fperez@colorado.edu>
2190 2200
2191 2201 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
2192 2202 mode would behave erratically. Also increased the number of
2193 2203 possible logs in rotate mod to 999. Thanks to Rod Holland
2194 2204 <rhh@StructureLABS.com> for the report and fixes.
2195 2205
2196 2206 2004-02-26 Fernando Perez <fperez@colorado.edu>
2197 2207
2198 2208 * IPython/genutils.py (page): Check that the curses module really
2199 2209 has the initscr attribute before trying to use it. For some
2200 2210 reason, the Solaris curses module is missing this. I think this
2201 2211 should be considered a Solaris python bug, but I'm not sure.
2202 2212
2203 2213 2004-01-17 Fernando Perez <fperez@colorado.edu>
2204 2214
2205 2215 * IPython/genutils.py (Stream.__init__): Changes to try to make
2206 2216 ipython robust against stdin/out/err being closed by the user.
2207 2217 This is 'user error' (and blocks a normal python session, at least
2208 2218 the stdout case). However, Ipython should be able to survive such
2209 2219 instances of abuse as gracefully as possible. To simplify the
2210 2220 coding and maintain compatibility with Gary Bishop's Term
2211 2221 contributions, I've made use of classmethods for this. I think
2212 2222 this introduces a dependency on python 2.2.
2213 2223
2214 2224 2004-01-13 Fernando Perez <fperez@colorado.edu>
2215 2225
2216 2226 * IPython/numutils.py (exp_safe): simplified the code a bit and
2217 2227 removed the need for importing the kinds module altogether.
2218 2228
2219 2229 2004-01-06 Fernando Perez <fperez@colorado.edu>
2220 2230
2221 2231 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
2222 2232 a magic function instead, after some community feedback. No
2223 2233 special syntax will exist for it, but its name is deliberately
2224 2234 very short.
2225 2235
2226 2236 2003-12-20 Fernando Perez <fperez@colorado.edu>
2227 2237
2228 2238 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
2229 2239 new functionality, to automagically assign the result of a shell
2230 2240 command to a variable. I'll solicit some community feedback on
2231 2241 this before making it permanent.
2232 2242
2233 2243 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
2234 2244 requested about callables for which inspect couldn't obtain a
2235 2245 proper argspec. Thanks to a crash report sent by Etienne
2236 2246 Posthumus <etienne-AT-apple01.cs.vu.nl>.
2237 2247
2238 2248 2003-12-09 Fernando Perez <fperez@colorado.edu>
2239 2249
2240 2250 * IPython/genutils.py (page): patch for the pager to work across
2241 2251 various versions of Windows. By Gary Bishop.
2242 2252
2243 2253 2003-12-04 Fernando Perez <fperez@colorado.edu>
2244 2254
2245 2255 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
2246 2256 Gnuplot.py version 1.7, whose internal names changed quite a bit.
2247 2257 While I tested this and it looks ok, there may still be corner
2248 2258 cases I've missed.
2249 2259
2250 2260 2003-12-01 Fernando Perez <fperez@colorado.edu>
2251 2261
2252 2262 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
2253 2263 where a line like 'p,q=1,2' would fail because the automagic
2254 2264 system would be triggered for @p.
2255 2265
2256 2266 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
2257 2267 cleanups, code unmodified.
2258 2268
2259 2269 * IPython/genutils.py (Term): added a class for IPython to handle
2260 2270 output. In most cases it will just be a proxy for stdout/err, but
2261 2271 having this allows modifications to be made for some platforms,
2262 2272 such as handling color escapes under Windows. All of this code
2263 2273 was contributed by Gary Bishop, with minor modifications by me.
2264 2274 The actual changes affect many files.
2265 2275
2266 2276 2003-11-30 Fernando Perez <fperez@colorado.edu>
2267 2277
2268 2278 * IPython/iplib.py (file_matches): new completion code, courtesy
2269 2279 of Jeff Collins. This enables filename completion again under
2270 2280 python 2.3, which disabled it at the C level.
2271 2281
2272 2282 2003-11-11 Fernando Perez <fperez@colorado.edu>
2273 2283
2274 2284 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
2275 2285 for Numeric.array(map(...)), but often convenient.
2276 2286
2277 2287 2003-11-05 Fernando Perez <fperez@colorado.edu>
2278 2288
2279 2289 * IPython/numutils.py (frange): Changed a call from int() to
2280 2290 int(round()) to prevent a problem reported with arange() in the
2281 2291 numpy list.
2282 2292
2283 2293 2003-10-06 Fernando Perez <fperez@colorado.edu>
2284 2294
2285 2295 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
2286 2296 prevent crashes if sys lacks an argv attribute (it happens with
2287 2297 embedded interpreters which build a bare-bones sys module).
2288 2298 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
2289 2299
2290 2300 2003-09-24 Fernando Perez <fperez@colorado.edu>
2291 2301
2292 2302 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
2293 2303 to protect against poorly written user objects where __getattr__
2294 2304 raises exceptions other than AttributeError. Thanks to a bug
2295 2305 report by Oliver Sander <osander-AT-gmx.de>.
2296 2306
2297 2307 * IPython/FakeModule.py (FakeModule.__repr__): this method was
2298 2308 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
2299 2309
2300 2310 2003-09-09 Fernando Perez <fperez@colorado.edu>
2301 2311
2302 2312 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
2303 2313 unpacking a list whith a callable as first element would
2304 2314 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
2305 2315 Collins.
2306 2316
2307 2317 2003-08-25 *** Released version 0.5.0
2308 2318
2309 2319 2003-08-22 Fernando Perez <fperez@colorado.edu>
2310 2320
2311 2321 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
2312 2322 improperly defined user exceptions. Thanks to feedback from Mark
2313 2323 Russell <mrussell-AT-verio.net>.
2314 2324
2315 2325 2003-08-20 Fernando Perez <fperez@colorado.edu>
2316 2326
2317 2327 * IPython/OInspect.py (Inspector.pinfo): changed String Form
2318 2328 printing so that it would print multi-line string forms starting
2319 2329 with a new line. This way the formatting is better respected for
2320 2330 objects which work hard to make nice string forms.
2321 2331
2322 2332 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
2323 2333 autocall would overtake data access for objects with both
2324 2334 __getitem__ and __call__.
2325 2335
2326 2336 2003-08-19 *** Released version 0.5.0-rc1
2327 2337
2328 2338 2003-08-19 Fernando Perez <fperez@colorado.edu>
2329 2339
2330 2340 * IPython/deep_reload.py (load_tail): single tiny change here
2331 2341 seems to fix the long-standing bug of dreload() failing to work
2332 2342 for dotted names. But this module is pretty tricky, so I may have
2333 2343 missed some subtlety. Needs more testing!.
2334 2344
2335 2345 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
2336 2346 exceptions which have badly implemented __str__ methods.
2337 2347 (VerboseTB.text): harden against inspect.getinnerframes crashing,
2338 2348 which I've been getting reports about from Python 2.3 users. I
2339 2349 wish I had a simple test case to reproduce the problem, so I could
2340 2350 either write a cleaner workaround or file a bug report if
2341 2351 necessary.
2342 2352
2343 2353 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
2344 2354 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
2345 2355 a bug report by Tjabo Kloppenburg.
2346 2356
2347 2357 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
2348 2358 crashes. Wrapped the pdb call in a blanket try/except, since pdb
2349 2359 seems rather unstable. Thanks to a bug report by Tjabo
2350 2360 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
2351 2361
2352 2362 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
2353 2363 this out soon because of the critical fixes in the inner loop for
2354 2364 generators.
2355 2365
2356 2366 * IPython/Magic.py (Magic.getargspec): removed. This (and
2357 2367 _get_def) have been obsoleted by OInspect for a long time, I
2358 2368 hadn't noticed that they were dead code.
2359 2369 (Magic._ofind): restored _ofind functionality for a few literals
2360 2370 (those in ["''",'""','[]','{}','()']). But it won't work anymore
2361 2371 for things like "hello".capitalize?, since that would require a
2362 2372 potentially dangerous eval() again.
2363 2373
2364 2374 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
2365 2375 logic a bit more to clean up the escapes handling and minimize the
2366 2376 use of _ofind to only necessary cases. The interactive 'feel' of
2367 2377 IPython should have improved quite a bit with the changes in
2368 2378 _prefilter and _ofind (besides being far safer than before).
2369 2379
2370 2380 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
2371 2381 obscure, never reported). Edit would fail to find the object to
2372 2382 edit under some circumstances.
2373 2383 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
2374 2384 which were causing double-calling of generators. Those eval calls
2375 2385 were _very_ dangerous, since code with side effects could be
2376 2386 triggered. As they say, 'eval is evil'... These were the
2377 2387 nastiest evals in IPython. Besides, _ofind is now far simpler,
2378 2388 and it should also be quite a bit faster. Its use of inspect is
2379 2389 also safer, so perhaps some of the inspect-related crashes I've
2380 2390 seen lately with Python 2.3 might be taken care of. That will
2381 2391 need more testing.
2382 2392
2383 2393 2003-08-17 Fernando Perez <fperez@colorado.edu>
2384 2394
2385 2395 * IPython/iplib.py (InteractiveShell._prefilter): significant
2386 2396 simplifications to the logic for handling user escapes. Faster
2387 2397 and simpler code.
2388 2398
2389 2399 2003-08-14 Fernando Perez <fperez@colorado.edu>
2390 2400
2391 2401 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
2392 2402 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
2393 2403 but it should be quite a bit faster. And the recursive version
2394 2404 generated O(log N) intermediate storage for all rank>1 arrays,
2395 2405 even if they were contiguous.
2396 2406 (l1norm): Added this function.
2397 2407 (norm): Added this function for arbitrary norms (including
2398 2408 l-infinity). l1 and l2 are still special cases for convenience
2399 2409 and speed.
2400 2410
2401 2411 2003-08-03 Fernando Perez <fperez@colorado.edu>
2402 2412
2403 2413 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
2404 2414 exceptions, which now raise PendingDeprecationWarnings in Python
2405 2415 2.3. There were some in Magic and some in Gnuplot2.
2406 2416
2407 2417 2003-06-30 Fernando Perez <fperez@colorado.edu>
2408 2418
2409 2419 * IPython/genutils.py (page): modified to call curses only for
2410 2420 terminals where TERM=='xterm'. After problems under many other
2411 2421 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2412 2422
2413 2423 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2414 2424 would be triggered when readline was absent. This was just an old
2415 2425 debugging statement I'd forgotten to take out.
2416 2426
2417 2427 2003-06-20 Fernando Perez <fperez@colorado.edu>
2418 2428
2419 2429 * IPython/genutils.py (clock): modified to return only user time
2420 2430 (not counting system time), after a discussion on scipy. While
2421 2431 system time may be a useful quantity occasionally, it may much
2422 2432 more easily be skewed by occasional swapping or other similar
2423 2433 activity.
2424 2434
2425 2435 2003-06-05 Fernando Perez <fperez@colorado.edu>
2426 2436
2427 2437 * IPython/numutils.py (identity): new function, for building
2428 2438 arbitrary rank Kronecker deltas (mostly backwards compatible with
2429 2439 Numeric.identity)
2430 2440
2431 2441 2003-06-03 Fernando Perez <fperez@colorado.edu>
2432 2442
2433 2443 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2434 2444 arguments passed to magics with spaces, to allow trailing '\' to
2435 2445 work normally (mainly for Windows users).
2436 2446
2437 2447 2003-05-29 Fernando Perez <fperez@colorado.edu>
2438 2448
2439 2449 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2440 2450 instead of pydoc.help. This fixes a bizarre behavior where
2441 2451 printing '%s' % locals() would trigger the help system. Now
2442 2452 ipython behaves like normal python does.
2443 2453
2444 2454 Note that if one does 'from pydoc import help', the bizarre
2445 2455 behavior returns, but this will also happen in normal python, so
2446 2456 it's not an ipython bug anymore (it has to do with how pydoc.help
2447 2457 is implemented).
2448 2458
2449 2459 2003-05-22 Fernando Perez <fperez@colorado.edu>
2450 2460
2451 2461 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2452 2462 return [] instead of None when nothing matches, also match to end
2453 2463 of line. Patch by Gary Bishop.
2454 2464
2455 2465 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2456 2466 protection as before, for files passed on the command line. This
2457 2467 prevents the CrashHandler from kicking in if user files call into
2458 2468 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2459 2469 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2460 2470
2461 2471 2003-05-20 *** Released version 0.4.0
2462 2472
2463 2473 2003-05-20 Fernando Perez <fperez@colorado.edu>
2464 2474
2465 2475 * setup.py: added support for manpages. It's a bit hackish b/c of
2466 2476 a bug in the way the bdist_rpm distutils target handles gzipped
2467 2477 manpages, but it works. After a patch by Jack.
2468 2478
2469 2479 2003-05-19 Fernando Perez <fperez@colorado.edu>
2470 2480
2471 2481 * IPython/numutils.py: added a mockup of the kinds module, since
2472 2482 it was recently removed from Numeric. This way, numutils will
2473 2483 work for all users even if they are missing kinds.
2474 2484
2475 2485 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2476 2486 failure, which can occur with SWIG-wrapped extensions. After a
2477 2487 crash report from Prabhu.
2478 2488
2479 2489 2003-05-16 Fernando Perez <fperez@colorado.edu>
2480 2490
2481 2491 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2482 2492 protect ipython from user code which may call directly
2483 2493 sys.excepthook (this looks like an ipython crash to the user, even
2484 2494 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2485 2495 This is especially important to help users of WxWindows, but may
2486 2496 also be useful in other cases.
2487 2497
2488 2498 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2489 2499 an optional tb_offset to be specified, and to preserve exception
2490 2500 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2491 2501
2492 2502 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2493 2503
2494 2504 2003-05-15 Fernando Perez <fperez@colorado.edu>
2495 2505
2496 2506 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2497 2507 installing for a new user under Windows.
2498 2508
2499 2509 2003-05-12 Fernando Perez <fperez@colorado.edu>
2500 2510
2501 2511 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2502 2512 handler for Emacs comint-based lines. Currently it doesn't do
2503 2513 much (but importantly, it doesn't update the history cache). In
2504 2514 the future it may be expanded if Alex needs more functionality
2505 2515 there.
2506 2516
2507 2517 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2508 2518 info to crash reports.
2509 2519
2510 2520 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2511 2521 just like Python's -c. Also fixed crash with invalid -color
2512 2522 option value at startup. Thanks to Will French
2513 2523 <wfrench-AT-bestweb.net> for the bug report.
2514 2524
2515 2525 2003-05-09 Fernando Perez <fperez@colorado.edu>
2516 2526
2517 2527 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2518 2528 to EvalDict (it's a mapping, after all) and simplified its code
2519 2529 quite a bit, after a nice discussion on c.l.py where Gustavo
2520 2530 Córdova <gcordova-AT-sismex.com> suggested the new version.
2521 2531
2522 2532 2003-04-30 Fernando Perez <fperez@colorado.edu>
2523 2533
2524 2534 * IPython/genutils.py (timings_out): modified it to reduce its
2525 2535 overhead in the common reps==1 case.
2526 2536
2527 2537 2003-04-29 Fernando Perez <fperez@colorado.edu>
2528 2538
2529 2539 * IPython/genutils.py (timings_out): Modified to use the resource
2530 2540 module, which avoids the wraparound problems of time.clock().
2531 2541
2532 2542 2003-04-17 *** Released version 0.2.15pre4
2533 2543
2534 2544 2003-04-17 Fernando Perez <fperez@colorado.edu>
2535 2545
2536 2546 * setup.py (scriptfiles): Split windows-specific stuff over to a
2537 2547 separate file, in an attempt to have a Windows GUI installer.
2538 2548 That didn't work, but part of the groundwork is done.
2539 2549
2540 2550 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2541 2551 indent/unindent with 4 spaces. Particularly useful in combination
2542 2552 with the new auto-indent option.
2543 2553
2544 2554 2003-04-16 Fernando Perez <fperez@colorado.edu>
2545 2555
2546 2556 * IPython/Magic.py: various replacements of self.rc for
2547 2557 self.shell.rc. A lot more remains to be done to fully disentangle
2548 2558 this class from the main Shell class.
2549 2559
2550 2560 * IPython/GnuplotRuntime.py: added checks for mouse support so
2551 2561 that we don't try to enable it if the current gnuplot doesn't
2552 2562 really support it. Also added checks so that we don't try to
2553 2563 enable persist under Windows (where Gnuplot doesn't recognize the
2554 2564 option).
2555 2565
2556 2566 * IPython/iplib.py (InteractiveShell.interact): Added optional
2557 2567 auto-indenting code, after a patch by King C. Shu
2558 2568 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2559 2569 get along well with pasting indented code. If I ever figure out
2560 2570 how to make that part go well, it will become on by default.
2561 2571
2562 2572 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2563 2573 crash ipython if there was an unmatched '%' in the user's prompt
2564 2574 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2565 2575
2566 2576 * IPython/iplib.py (InteractiveShell.interact): removed the
2567 2577 ability to ask the user whether he wants to crash or not at the
2568 2578 'last line' exception handler. Calling functions at that point
2569 2579 changes the stack, and the error reports would have incorrect
2570 2580 tracebacks.
2571 2581
2572 2582 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2573 2583 pass through a peger a pretty-printed form of any object. After a
2574 2584 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2575 2585
2576 2586 2003-04-14 Fernando Perez <fperez@colorado.edu>
2577 2587
2578 2588 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2579 2589 all files in ~ would be modified at first install (instead of
2580 2590 ~/.ipython). This could be potentially disastrous, as the
2581 2591 modification (make line-endings native) could damage binary files.
2582 2592
2583 2593 2003-04-10 Fernando Perez <fperez@colorado.edu>
2584 2594
2585 2595 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2586 2596 handle only lines which are invalid python. This now means that
2587 2597 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2588 2598 for the bug report.
2589 2599
2590 2600 2003-04-01 Fernando Perez <fperez@colorado.edu>
2591 2601
2592 2602 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2593 2603 where failing to set sys.last_traceback would crash pdb.pm().
2594 2604 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2595 2605 report.
2596 2606
2597 2607 2003-03-25 Fernando Perez <fperez@colorado.edu>
2598 2608
2599 2609 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2600 2610 before printing it (it had a lot of spurious blank lines at the
2601 2611 end).
2602 2612
2603 2613 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2604 2614 output would be sent 21 times! Obviously people don't use this
2605 2615 too often, or I would have heard about it.
2606 2616
2607 2617 2003-03-24 Fernando Perez <fperez@colorado.edu>
2608 2618
2609 2619 * setup.py (scriptfiles): renamed the data_files parameter from
2610 2620 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2611 2621 for the patch.
2612 2622
2613 2623 2003-03-20 Fernando Perez <fperez@colorado.edu>
2614 2624
2615 2625 * IPython/genutils.py (error): added error() and fatal()
2616 2626 functions.
2617 2627
2618 2628 2003-03-18 *** Released version 0.2.15pre3
2619 2629
2620 2630 2003-03-18 Fernando Perez <fperez@colorado.edu>
2621 2631
2622 2632 * setupext/install_data_ext.py
2623 2633 (install_data_ext.initialize_options): Class contributed by Jack
2624 2634 Moffit for fixing the old distutils hack. He is sending this to
2625 2635 the distutils folks so in the future we may not need it as a
2626 2636 private fix.
2627 2637
2628 2638 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2629 2639 changes for Debian packaging. See his patch for full details.
2630 2640 The old distutils hack of making the ipythonrc* files carry a
2631 2641 bogus .py extension is gone, at last. Examples were moved to a
2632 2642 separate subdir under doc/, and the separate executable scripts
2633 2643 now live in their own directory. Overall a great cleanup. The
2634 2644 manual was updated to use the new files, and setup.py has been
2635 2645 fixed for this setup.
2636 2646
2637 2647 * IPython/PyColorize.py (Parser.usage): made non-executable and
2638 2648 created a pycolor wrapper around it to be included as a script.
2639 2649
2640 2650 2003-03-12 *** Released version 0.2.15pre2
2641 2651
2642 2652 2003-03-12 Fernando Perez <fperez@colorado.edu>
2643 2653
2644 2654 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2645 2655 long-standing problem with garbage characters in some terminals.
2646 2656 The issue was really that the \001 and \002 escapes must _only_ be
2647 2657 passed to input prompts (which call readline), but _never_ to
2648 2658 normal text to be printed on screen. I changed ColorANSI to have
2649 2659 two classes: TermColors and InputTermColors, each with the
2650 2660 appropriate escapes for input prompts or normal text. The code in
2651 2661 Prompts.py got slightly more complicated, but this very old and
2652 2662 annoying bug is finally fixed.
2653 2663
2654 2664 All the credit for nailing down the real origin of this problem
2655 2665 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2656 2666 *Many* thanks to him for spending quite a bit of effort on this.
2657 2667
2658 2668 2003-03-05 *** Released version 0.2.15pre1
2659 2669
2660 2670 2003-03-03 Fernando Perez <fperez@colorado.edu>
2661 2671
2662 2672 * IPython/FakeModule.py: Moved the former _FakeModule to a
2663 2673 separate file, because it's also needed by Magic (to fix a similar
2664 2674 pickle-related issue in @run).
2665 2675
2666 2676 2003-03-02 Fernando Perez <fperez@colorado.edu>
2667 2677
2668 2678 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2669 2679 the autocall option at runtime.
2670 2680 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2671 2681 across Magic.py to start separating Magic from InteractiveShell.
2672 2682 (Magic._ofind): Fixed to return proper namespace for dotted
2673 2683 names. Before, a dotted name would always return 'not currently
2674 2684 defined', because it would find the 'parent'. s.x would be found,
2675 2685 but since 'x' isn't defined by itself, it would get confused.
2676 2686 (Magic.magic_run): Fixed pickling problems reported by Ralf
2677 2687 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2678 2688 that I'd used when Mike Heeter reported similar issues at the
2679 2689 top-level, but now for @run. It boils down to injecting the
2680 2690 namespace where code is being executed with something that looks
2681 2691 enough like a module to fool pickle.dump(). Since a pickle stores
2682 2692 a named reference to the importing module, we need this for
2683 2693 pickles to save something sensible.
2684 2694
2685 2695 * IPython/ipmaker.py (make_IPython): added an autocall option.
2686 2696
2687 2697 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2688 2698 the auto-eval code. Now autocalling is an option, and the code is
2689 2699 also vastly safer. There is no more eval() involved at all.
2690 2700
2691 2701 2003-03-01 Fernando Perez <fperez@colorado.edu>
2692 2702
2693 2703 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2694 2704 dict with named keys instead of a tuple.
2695 2705
2696 2706 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2697 2707
2698 2708 * setup.py (make_shortcut): Fixed message about directories
2699 2709 created during Windows installation (the directories were ok, just
2700 2710 the printed message was misleading). Thanks to Chris Liechti
2701 2711 <cliechti-AT-gmx.net> for the heads up.
2702 2712
2703 2713 2003-02-21 Fernando Perez <fperez@colorado.edu>
2704 2714
2705 2715 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2706 2716 of ValueError exception when checking for auto-execution. This
2707 2717 one is raised by things like Numeric arrays arr.flat when the
2708 2718 array is non-contiguous.
2709 2719
2710 2720 2003-01-31 Fernando Perez <fperez@colorado.edu>
2711 2721
2712 2722 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2713 2723 not return any value at all (even though the command would get
2714 2724 executed).
2715 2725 (xsys): Flush stdout right after printing the command to ensure
2716 2726 proper ordering of commands and command output in the total
2717 2727 output.
2718 2728 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2719 2729 system/getoutput as defaults. The old ones are kept for
2720 2730 compatibility reasons, so no code which uses this library needs
2721 2731 changing.
2722 2732
2723 2733 2003-01-27 *** Released version 0.2.14
2724 2734
2725 2735 2003-01-25 Fernando Perez <fperez@colorado.edu>
2726 2736
2727 2737 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2728 2738 functions defined in previous edit sessions could not be re-edited
2729 2739 (because the temp files were immediately removed). Now temp files
2730 2740 are removed only at IPython's exit.
2731 2741 (Magic.magic_run): Improved @run to perform shell-like expansions
2732 2742 on its arguments (~users and $VARS). With this, @run becomes more
2733 2743 like a normal command-line.
2734 2744
2735 2745 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2736 2746 bugs related to embedding and cleaned up that code. A fairly
2737 2747 important one was the impossibility to access the global namespace
2738 2748 through the embedded IPython (only local variables were visible).
2739 2749
2740 2750 2003-01-14 Fernando Perez <fperez@colorado.edu>
2741 2751
2742 2752 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2743 2753 auto-calling to be a bit more conservative. Now it doesn't get
2744 2754 triggered if any of '!=()<>' are in the rest of the input line, to
2745 2755 allow comparing callables. Thanks to Alex for the heads up.
2746 2756
2747 2757 2003-01-07 Fernando Perez <fperez@colorado.edu>
2748 2758
2749 2759 * IPython/genutils.py (page): fixed estimation of the number of
2750 2760 lines in a string to be paged to simply count newlines. This
2751 2761 prevents over-guessing due to embedded escape sequences. A better
2752 2762 long-term solution would involve stripping out the control chars
2753 2763 for the count, but it's potentially so expensive I just don't
2754 2764 think it's worth doing.
2755 2765
2756 2766 2002-12-19 *** Released version 0.2.14pre50
2757 2767
2758 2768 2002-12-19 Fernando Perez <fperez@colorado.edu>
2759 2769
2760 2770 * tools/release (version): Changed release scripts to inform
2761 2771 Andrea and build a NEWS file with a list of recent changes.
2762 2772
2763 2773 * IPython/ColorANSI.py (__all__): changed terminal detection
2764 2774 code. Seems to work better for xterms without breaking
2765 2775 konsole. Will need more testing to determine if WinXP and Mac OSX
2766 2776 also work ok.
2767 2777
2768 2778 2002-12-18 *** Released version 0.2.14pre49
2769 2779
2770 2780 2002-12-18 Fernando Perez <fperez@colorado.edu>
2771 2781
2772 2782 * Docs: added new info about Mac OSX, from Andrea.
2773 2783
2774 2784 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2775 2785 allow direct plotting of python strings whose format is the same
2776 2786 of gnuplot data files.
2777 2787
2778 2788 2002-12-16 Fernando Perez <fperez@colorado.edu>
2779 2789
2780 2790 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2781 2791 value of exit question to be acknowledged.
2782 2792
2783 2793 2002-12-03 Fernando Perez <fperez@colorado.edu>
2784 2794
2785 2795 * IPython/ipmaker.py: removed generators, which had been added
2786 2796 by mistake in an earlier debugging run. This was causing trouble
2787 2797 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2788 2798 for pointing this out.
2789 2799
2790 2800 2002-11-17 Fernando Perez <fperez@colorado.edu>
2791 2801
2792 2802 * Manual: updated the Gnuplot section.
2793 2803
2794 2804 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2795 2805 a much better split of what goes in Runtime and what goes in
2796 2806 Interactive.
2797 2807
2798 2808 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2799 2809 being imported from iplib.
2800 2810
2801 2811 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2802 2812 for command-passing. Now the global Gnuplot instance is called
2803 2813 'gp' instead of 'g', which was really a far too fragile and
2804 2814 common name.
2805 2815
2806 2816 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2807 2817 bounding boxes generated by Gnuplot for square plots.
2808 2818
2809 2819 * IPython/genutils.py (popkey): new function added. I should
2810 2820 suggest this on c.l.py as a dict method, it seems useful.
2811 2821
2812 2822 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2813 2823 to transparently handle PostScript generation. MUCH better than
2814 2824 the previous plot_eps/replot_eps (which I removed now). The code
2815 2825 is also fairly clean and well documented now (including
2816 2826 docstrings).
2817 2827
2818 2828 2002-11-13 Fernando Perez <fperez@colorado.edu>
2819 2829
2820 2830 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2821 2831 (inconsistent with options).
2822 2832
2823 2833 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2824 2834 manually disabled, I don't know why. Fixed it.
2825 2835 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2826 2836 eps output.
2827 2837
2828 2838 2002-11-12 Fernando Perez <fperez@colorado.edu>
2829 2839
2830 2840 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2831 2841 don't propagate up to caller. Fixes crash reported by François
2832 2842 Pinard.
2833 2843
2834 2844 2002-11-09 Fernando Perez <fperez@colorado.edu>
2835 2845
2836 2846 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2837 2847 history file for new users.
2838 2848 (make_IPython): fixed bug where initial install would leave the
2839 2849 user running in the .ipython dir.
2840 2850 (make_IPython): fixed bug where config dir .ipython would be
2841 2851 created regardless of the given -ipythondir option. Thanks to Cory
2842 2852 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2843 2853
2844 2854 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2845 2855 type confirmations. Will need to use it in all of IPython's code
2846 2856 consistently.
2847 2857
2848 2858 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2849 2859 context to print 31 lines instead of the default 5. This will make
2850 2860 the crash reports extremely detailed in case the problem is in
2851 2861 libraries I don't have access to.
2852 2862
2853 2863 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2854 2864 line of defense' code to still crash, but giving users fair
2855 2865 warning. I don't want internal errors to go unreported: if there's
2856 2866 an internal problem, IPython should crash and generate a full
2857 2867 report.
2858 2868
2859 2869 2002-11-08 Fernando Perez <fperez@colorado.edu>
2860 2870
2861 2871 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2862 2872 otherwise uncaught exceptions which can appear if people set
2863 2873 sys.stdout to something badly broken. Thanks to a crash report
2864 2874 from henni-AT-mail.brainbot.com.
2865 2875
2866 2876 2002-11-04 Fernando Perez <fperez@colorado.edu>
2867 2877
2868 2878 * IPython/iplib.py (InteractiveShell.interact): added
2869 2879 __IPYTHON__active to the builtins. It's a flag which goes on when
2870 2880 the interaction starts and goes off again when it stops. This
2871 2881 allows embedding code to detect being inside IPython. Before this
2872 2882 was done via __IPYTHON__, but that only shows that an IPython
2873 2883 instance has been created.
2874 2884
2875 2885 * IPython/Magic.py (Magic.magic_env): I realized that in a
2876 2886 UserDict, instance.data holds the data as a normal dict. So I
2877 2887 modified @env to return os.environ.data instead of rebuilding a
2878 2888 dict by hand.
2879 2889
2880 2890 2002-11-02 Fernando Perez <fperez@colorado.edu>
2881 2891
2882 2892 * IPython/genutils.py (warn): changed so that level 1 prints no
2883 2893 header. Level 2 is now the default (with 'WARNING' header, as
2884 2894 before). I think I tracked all places where changes were needed in
2885 2895 IPython, but outside code using the old level numbering may have
2886 2896 broken.
2887 2897
2888 2898 * IPython/iplib.py (InteractiveShell.runcode): added this to
2889 2899 handle the tracebacks in SystemExit traps correctly. The previous
2890 2900 code (through interact) was printing more of the stack than
2891 2901 necessary, showing IPython internal code to the user.
2892 2902
2893 2903 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2894 2904 default. Now that the default at the confirmation prompt is yes,
2895 2905 it's not so intrusive. François' argument that ipython sessions
2896 2906 tend to be complex enough not to lose them from an accidental C-d,
2897 2907 is a valid one.
2898 2908
2899 2909 * IPython/iplib.py (InteractiveShell.interact): added a
2900 2910 showtraceback() call to the SystemExit trap, and modified the exit
2901 2911 confirmation to have yes as the default.
2902 2912
2903 2913 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2904 2914 this file. It's been gone from the code for a long time, this was
2905 2915 simply leftover junk.
2906 2916
2907 2917 2002-11-01 Fernando Perez <fperez@colorado.edu>
2908 2918
2909 2919 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2910 2920 added. If set, IPython now traps EOF and asks for
2911 2921 confirmation. After a request by François Pinard.
2912 2922
2913 2923 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2914 2924 of @abort, and with a new (better) mechanism for handling the
2915 2925 exceptions.
2916 2926
2917 2927 2002-10-27 Fernando Perez <fperez@colorado.edu>
2918 2928
2919 2929 * IPython/usage.py (__doc__): updated the --help information and
2920 2930 the ipythonrc file to indicate that -log generates
2921 2931 ./ipython.log. Also fixed the corresponding info in @logstart.
2922 2932 This and several other fixes in the manuals thanks to reports by
2923 2933 François Pinard <pinard-AT-iro.umontreal.ca>.
2924 2934
2925 2935 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2926 2936 refer to @logstart (instead of @log, which doesn't exist).
2927 2937
2928 2938 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2929 2939 AttributeError crash. Thanks to Christopher Armstrong
2930 2940 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2931 2941 introduced recently (in 0.2.14pre37) with the fix to the eval
2932 2942 problem mentioned below.
2933 2943
2934 2944 2002-10-17 Fernando Perez <fperez@colorado.edu>
2935 2945
2936 2946 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2937 2947 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2938 2948
2939 2949 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2940 2950 this function to fix a problem reported by Alex Schmolck. He saw
2941 2951 it with list comprehensions and generators, which were getting
2942 2952 called twice. The real problem was an 'eval' call in testing for
2943 2953 automagic which was evaluating the input line silently.
2944 2954
2945 2955 This is a potentially very nasty bug, if the input has side
2946 2956 effects which must not be repeated. The code is much cleaner now,
2947 2957 without any blanket 'except' left and with a regexp test for
2948 2958 actual function names.
2949 2959
2950 2960 But an eval remains, which I'm not fully comfortable with. I just
2951 2961 don't know how to find out if an expression could be a callable in
2952 2962 the user's namespace without doing an eval on the string. However
2953 2963 that string is now much more strictly checked so that no code
2954 2964 slips by, so the eval should only happen for things that can
2955 2965 really be only function/method names.
2956 2966
2957 2967 2002-10-15 Fernando Perez <fperez@colorado.edu>
2958 2968
2959 2969 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2960 2970 OSX information to main manual, removed README_Mac_OSX file from
2961 2971 distribution. Also updated credits for recent additions.
2962 2972
2963 2973 2002-10-10 Fernando Perez <fperez@colorado.edu>
2964 2974
2965 2975 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2966 2976 terminal-related issues. Many thanks to Andrea Riciputi
2967 2977 <andrea.riciputi-AT-libero.it> for writing it.
2968 2978
2969 2979 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2970 2980 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2971 2981
2972 2982 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2973 2983 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2974 2984 <syver-en-AT-online.no> who both submitted patches for this problem.
2975 2985
2976 2986 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2977 2987 global embedding to make sure that things don't overwrite user
2978 2988 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2979 2989
2980 2990 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2981 2991 compatibility. Thanks to Hayden Callow
2982 2992 <h.callow-AT-elec.canterbury.ac.nz>
2983 2993
2984 2994 2002-10-04 Fernando Perez <fperez@colorado.edu>
2985 2995
2986 2996 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2987 2997 Gnuplot.File objects.
2988 2998
2989 2999 2002-07-23 Fernando Perez <fperez@colorado.edu>
2990 3000
2991 3001 * IPython/genutils.py (timing): Added timings() and timing() for
2992 3002 quick access to the most commonly needed data, the execution
2993 3003 times. Old timing() renamed to timings_out().
2994 3004
2995 3005 2002-07-18 Fernando Perez <fperez@colorado.edu>
2996 3006
2997 3007 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2998 3008 bug with nested instances disrupting the parent's tab completion.
2999 3009
3000 3010 * IPython/iplib.py (all_completions): Added Alex Schmolck's
3001 3011 all_completions code to begin the emacs integration.
3002 3012
3003 3013 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
3004 3014 argument to allow titling individual arrays when plotting.
3005 3015
3006 3016 2002-07-15 Fernando Perez <fperez@colorado.edu>
3007 3017
3008 3018 * setup.py (make_shortcut): changed to retrieve the value of
3009 3019 'Program Files' directory from the registry (this value changes in
3010 3020 non-english versions of Windows). Thanks to Thomas Fanslau
3011 3021 <tfanslau-AT-gmx.de> for the report.
3012 3022
3013 3023 2002-07-10 Fernando Perez <fperez@colorado.edu>
3014 3024
3015 3025 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
3016 3026 a bug in pdb, which crashes if a line with only whitespace is
3017 3027 entered. Bug report submitted to sourceforge.
3018 3028
3019 3029 2002-07-09 Fernando Perez <fperez@colorado.edu>
3020 3030
3021 3031 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
3022 3032 reporting exceptions (it's a bug in inspect.py, I just set a
3023 3033 workaround).
3024 3034
3025 3035 2002-07-08 Fernando Perez <fperez@colorado.edu>
3026 3036
3027 3037 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
3028 3038 __IPYTHON__ in __builtins__ to show up in user_ns.
3029 3039
3030 3040 2002-07-03 Fernando Perez <fperez@colorado.edu>
3031 3041
3032 3042 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
3033 3043 name from @gp_set_instance to @gp_set_default.
3034 3044
3035 3045 * IPython/ipmaker.py (make_IPython): default editor value set to
3036 3046 '0' (a string), to match the rc file. Otherwise will crash when
3037 3047 .strip() is called on it.
3038 3048
3039 3049
3040 3050 2002-06-28 Fernando Perez <fperez@colorado.edu>
3041 3051
3042 3052 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
3043 3053 of files in current directory when a file is executed via
3044 3054 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
3045 3055
3046 3056 * setup.py (manfiles): fix for rpm builds, submitted by RA
3047 3057 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
3048 3058
3049 3059 * IPython/ipmaker.py (make_IPython): fixed lookup of default
3050 3060 editor when set to '0'. Problem was, '0' evaluates to True (it's a
3051 3061 string!). A. Schmolck caught this one.
3052 3062
3053 3063 2002-06-27 Fernando Perez <fperez@colorado.edu>
3054 3064
3055 3065 * IPython/ipmaker.py (make_IPython): fixed bug when running user
3056 3066 defined files at the cmd line. __name__ wasn't being set to
3057 3067 __main__.
3058 3068
3059 3069 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
3060 3070 regular lists and tuples besides Numeric arrays.
3061 3071
3062 3072 * IPython/Prompts.py (CachedOutput.__call__): Added output
3063 3073 supression for input ending with ';'. Similar to Mathematica and
3064 3074 Matlab. The _* vars and Out[] list are still updated, just like
3065 3075 Mathematica behaves.
3066 3076
3067 3077 2002-06-25 Fernando Perez <fperez@colorado.edu>
3068 3078
3069 3079 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
3070 3080 .ini extensions for profiels under Windows.
3071 3081
3072 3082 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
3073 3083 string form. Fix contributed by Alexander Schmolck
3074 3084 <a.schmolck-AT-gmx.net>
3075 3085
3076 3086 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
3077 3087 pre-configured Gnuplot instance.
3078 3088
3079 3089 2002-06-21 Fernando Perez <fperez@colorado.edu>
3080 3090
3081 3091 * IPython/numutils.py (exp_safe): new function, works around the
3082 3092 underflow problems in Numeric.
3083 3093 (log2): New fn. Safe log in base 2: returns exact integer answer
3084 3094 for exact integer powers of 2.
3085 3095
3086 3096 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
3087 3097 properly.
3088 3098
3089 3099 2002-06-20 Fernando Perez <fperez@colorado.edu>
3090 3100
3091 3101 * IPython/genutils.py (timing): new function like
3092 3102 Mathematica's. Similar to time_test, but returns more info.
3093 3103
3094 3104 2002-06-18 Fernando Perez <fperez@colorado.edu>
3095 3105
3096 3106 * IPython/Magic.py (Magic.magic_save): modified @save and @r
3097 3107 according to Mike Heeter's suggestions.
3098 3108
3099 3109 2002-06-16 Fernando Perez <fperez@colorado.edu>
3100 3110
3101 3111 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
3102 3112 system. GnuplotMagic is gone as a user-directory option. New files
3103 3113 make it easier to use all the gnuplot stuff both from external
3104 3114 programs as well as from IPython. Had to rewrite part of
3105 3115 hardcopy() b/c of a strange bug: often the ps files simply don't
3106 3116 get created, and require a repeat of the command (often several
3107 3117 times).
3108 3118
3109 3119 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
3110 3120 resolve output channel at call time, so that if sys.stderr has
3111 3121 been redirected by user this gets honored.
3112 3122
3113 3123 2002-06-13 Fernando Perez <fperez@colorado.edu>
3114 3124
3115 3125 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
3116 3126 IPShell. Kept a copy with the old names to avoid breaking people's
3117 3127 embedded code.
3118 3128
3119 3129 * IPython/ipython: simplified it to the bare minimum after
3120 3130 Holger's suggestions. Added info about how to use it in
3121 3131 PYTHONSTARTUP.
3122 3132
3123 3133 * IPython/Shell.py (IPythonShell): changed the options passing
3124 3134 from a string with funky %s replacements to a straight list. Maybe
3125 3135 a bit more typing, but it follows sys.argv conventions, so there's
3126 3136 less special-casing to remember.
3127 3137
3128 3138 2002-06-12 Fernando Perez <fperez@colorado.edu>
3129 3139
3130 3140 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
3131 3141 command. Thanks to a suggestion by Mike Heeter.
3132 3142 (Magic.magic_pfile): added behavior to look at filenames if given
3133 3143 arg is not a defined object.
3134 3144 (Magic.magic_save): New @save function to save code snippets. Also
3135 3145 a Mike Heeter idea.
3136 3146
3137 3147 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
3138 3148 plot() and replot(). Much more convenient now, especially for
3139 3149 interactive use.
3140 3150
3141 3151 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
3142 3152 filenames.
3143 3153
3144 3154 2002-06-02 Fernando Perez <fperez@colorado.edu>
3145 3155
3146 3156 * IPython/Struct.py (Struct.__init__): modified to admit
3147 3157 initialization via another struct.
3148 3158
3149 3159 * IPython/genutils.py (SystemExec.__init__): New stateful
3150 3160 interface to xsys and bq. Useful for writing system scripts.
3151 3161
3152 3162 2002-05-30 Fernando Perez <fperez@colorado.edu>
3153 3163
3154 3164 * MANIFEST.in: Changed docfile selection to exclude all the lyx
3155 3165 documents. This will make the user download smaller (it's getting
3156 3166 too big).
3157 3167
3158 3168 2002-05-29 Fernando Perez <fperez@colorado.edu>
3159 3169
3160 3170 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
3161 3171 fix problems with shelve and pickle. Seems to work, but I don't
3162 3172 know if corner cases break it. Thanks to Mike Heeter
3163 3173 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
3164 3174
3165 3175 2002-05-24 Fernando Perez <fperez@colorado.edu>
3166 3176
3167 3177 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
3168 3178 macros having broken.
3169 3179
3170 3180 2002-05-21 Fernando Perez <fperez@colorado.edu>
3171 3181
3172 3182 * IPython/Magic.py (Magic.magic_logstart): fixed recently
3173 3183 introduced logging bug: all history before logging started was
3174 3184 being written one character per line! This came from the redesign
3175 3185 of the input history as a special list which slices to strings,
3176 3186 not to lists.
3177 3187
3178 3188 2002-05-20 Fernando Perez <fperez@colorado.edu>
3179 3189
3180 3190 * IPython/Prompts.py (CachedOutput.__init__): made the color table
3181 3191 be an attribute of all classes in this module. The design of these
3182 3192 classes needs some serious overhauling.
3183 3193
3184 3194 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
3185 3195 which was ignoring '_' in option names.
3186 3196
3187 3197 * IPython/ultraTB.py (FormattedTB.__init__): Changed
3188 3198 'Verbose_novars' to 'Context' and made it the new default. It's a
3189 3199 bit more readable and also safer than verbose.
3190 3200
3191 3201 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
3192 3202 triple-quoted strings.
3193 3203
3194 3204 * IPython/OInspect.py (__all__): new module exposing the object
3195 3205 introspection facilities. Now the corresponding magics are dummy
3196 3206 wrappers around this. Having this module will make it much easier
3197 3207 to put these functions into our modified pdb.
3198 3208 This new object inspector system uses the new colorizing module,
3199 3209 so source code and other things are nicely syntax highlighted.
3200 3210
3201 3211 2002-05-18 Fernando Perez <fperez@colorado.edu>
3202 3212
3203 3213 * IPython/ColorANSI.py: Split the coloring tools into a separate
3204 3214 module so I can use them in other code easier (they were part of
3205 3215 ultraTB).
3206 3216
3207 3217 2002-05-17 Fernando Perez <fperez@colorado.edu>
3208 3218
3209 3219 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3210 3220 fixed it to set the global 'g' also to the called instance, as
3211 3221 long as 'g' was still a gnuplot instance (so it doesn't overwrite
3212 3222 user's 'g' variables).
3213 3223
3214 3224 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
3215 3225 global variables (aliases to _ih,_oh) so that users which expect
3216 3226 In[5] or Out[7] to work aren't unpleasantly surprised.
3217 3227 (InputList.__getslice__): new class to allow executing slices of
3218 3228 input history directly. Very simple class, complements the use of
3219 3229 macros.
3220 3230
3221 3231 2002-05-16 Fernando Perez <fperez@colorado.edu>
3222 3232
3223 3233 * setup.py (docdirbase): make doc directory be just doc/IPython
3224 3234 without version numbers, it will reduce clutter for users.
3225 3235
3226 3236 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
3227 3237 execfile call to prevent possible memory leak. See for details:
3228 3238 http://mail.python.org/pipermail/python-list/2002-February/088476.html
3229 3239
3230 3240 2002-05-15 Fernando Perez <fperez@colorado.edu>
3231 3241
3232 3242 * IPython/Magic.py (Magic.magic_psource): made the object
3233 3243 introspection names be more standard: pdoc, pdef, pfile and
3234 3244 psource. They all print/page their output, and it makes
3235 3245 remembering them easier. Kept old names for compatibility as
3236 3246 aliases.
3237 3247
3238 3248 2002-05-14 Fernando Perez <fperez@colorado.edu>
3239 3249
3240 3250 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
3241 3251 what the mouse problem was. The trick is to use gnuplot with temp
3242 3252 files and NOT with pipes (for data communication), because having
3243 3253 both pipes and the mouse on is bad news.
3244 3254
3245 3255 2002-05-13 Fernando Perez <fperez@colorado.edu>
3246 3256
3247 3257 * IPython/Magic.py (Magic._ofind): fixed namespace order search
3248 3258 bug. Information would be reported about builtins even when
3249 3259 user-defined functions overrode them.
3250 3260
3251 3261 2002-05-11 Fernando Perez <fperez@colorado.edu>
3252 3262
3253 3263 * IPython/__init__.py (__all__): removed FlexCompleter from
3254 3264 __all__ so that things don't fail in platforms without readline.
3255 3265
3256 3266 2002-05-10 Fernando Perez <fperez@colorado.edu>
3257 3267
3258 3268 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
3259 3269 it requires Numeric, effectively making Numeric a dependency for
3260 3270 IPython.
3261 3271
3262 3272 * Released 0.2.13
3263 3273
3264 3274 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
3265 3275 profiler interface. Now all the major options from the profiler
3266 3276 module are directly supported in IPython, both for single
3267 3277 expressions (@prun) and for full programs (@run -p).
3268 3278
3269 3279 2002-05-09 Fernando Perez <fperez@colorado.edu>
3270 3280
3271 3281 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
3272 3282 magic properly formatted for screen.
3273 3283
3274 3284 * setup.py (make_shortcut): Changed things to put pdf version in
3275 3285 doc/ instead of doc/manual (had to change lyxport a bit).
3276 3286
3277 3287 * IPython/Magic.py (Profile.string_stats): made profile runs go
3278 3288 through pager (they are long and a pager allows searching, saving,
3279 3289 etc.)
3280 3290
3281 3291 2002-05-08 Fernando Perez <fperez@colorado.edu>
3282 3292
3283 3293 * Released 0.2.12
3284 3294
3285 3295 2002-05-06 Fernando Perez <fperez@colorado.edu>
3286 3296
3287 3297 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
3288 3298 introduced); 'hist n1 n2' was broken.
3289 3299 (Magic.magic_pdb): added optional on/off arguments to @pdb
3290 3300 (Magic.magic_run): added option -i to @run, which executes code in
3291 3301 the IPython namespace instead of a clean one. Also added @irun as
3292 3302 an alias to @run -i.
3293 3303
3294 3304 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3295 3305 fixed (it didn't really do anything, the namespaces were wrong).
3296 3306
3297 3307 * IPython/Debugger.py (__init__): Added workaround for python 2.1
3298 3308
3299 3309 * IPython/__init__.py (__all__): Fixed package namespace, now
3300 3310 'import IPython' does give access to IPython.<all> as
3301 3311 expected. Also renamed __release__ to Release.
3302 3312
3303 3313 * IPython/Debugger.py (__license__): created new Pdb class which
3304 3314 functions like a drop-in for the normal pdb.Pdb but does NOT
3305 3315 import readline by default. This way it doesn't muck up IPython's
3306 3316 readline handling, and now tab-completion finally works in the
3307 3317 debugger -- sort of. It completes things globally visible, but the
3308 3318 completer doesn't track the stack as pdb walks it. That's a bit
3309 3319 tricky, and I'll have to implement it later.
3310 3320
3311 3321 2002-05-05 Fernando Perez <fperez@colorado.edu>
3312 3322
3313 3323 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
3314 3324 magic docstrings when printed via ? (explicit \'s were being
3315 3325 printed).
3316 3326
3317 3327 * IPython/ipmaker.py (make_IPython): fixed namespace
3318 3328 identification bug. Now variables loaded via logs or command-line
3319 3329 files are recognized in the interactive namespace by @who.
3320 3330
3321 3331 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
3322 3332 log replay system stemming from the string form of Structs.
3323 3333
3324 3334 * IPython/Magic.py (Macro.__init__): improved macros to properly
3325 3335 handle magic commands in them.
3326 3336 (Magic.magic_logstart): usernames are now expanded so 'logstart
3327 3337 ~/mylog' now works.
3328 3338
3329 3339 * IPython/iplib.py (complete): fixed bug where paths starting with
3330 3340 '/' would be completed as magic names.
3331 3341
3332 3342 2002-05-04 Fernando Perez <fperez@colorado.edu>
3333 3343
3334 3344 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
3335 3345 allow running full programs under the profiler's control.
3336 3346
3337 3347 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
3338 3348 mode to report exceptions verbosely but without formatting
3339 3349 variables. This addresses the issue of ipython 'freezing' (it's
3340 3350 not frozen, but caught in an expensive formatting loop) when huge
3341 3351 variables are in the context of an exception.
3342 3352 (VerboseTB.text): Added '--->' markers at line where exception was
3343 3353 triggered. Much clearer to read, especially in NoColor modes.
3344 3354
3345 3355 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
3346 3356 implemented in reverse when changing to the new parse_options().
3347 3357
3348 3358 2002-05-03 Fernando Perez <fperez@colorado.edu>
3349 3359
3350 3360 * IPython/Magic.py (Magic.parse_options): new function so that
3351 3361 magics can parse options easier.
3352 3362 (Magic.magic_prun): new function similar to profile.run(),
3353 3363 suggested by Chris Hart.
3354 3364 (Magic.magic_cd): fixed behavior so that it only changes if
3355 3365 directory actually is in history.
3356 3366
3357 3367 * IPython/usage.py (__doc__): added information about potential
3358 3368 slowness of Verbose exception mode when there are huge data
3359 3369 structures to be formatted (thanks to Archie Paulson).
3360 3370
3361 3371 * IPython/ipmaker.py (make_IPython): Changed default logging
3362 3372 (when simply called with -log) to use curr_dir/ipython.log in
3363 3373 rotate mode. Fixed crash which was occuring with -log before
3364 3374 (thanks to Jim Boyle).
3365 3375
3366 3376 2002-05-01 Fernando Perez <fperez@colorado.edu>
3367 3377
3368 3378 * Released 0.2.11 for these fixes (mainly the ultraTB one which
3369 3379 was nasty -- though somewhat of a corner case).
3370 3380
3371 3381 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
3372 3382 text (was a bug).
3373 3383
3374 3384 2002-04-30 Fernando Perez <fperez@colorado.edu>
3375 3385
3376 3386 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
3377 3387 a print after ^D or ^C from the user so that the In[] prompt
3378 3388 doesn't over-run the gnuplot one.
3379 3389
3380 3390 2002-04-29 Fernando Perez <fperez@colorado.edu>
3381 3391
3382 3392 * Released 0.2.10
3383 3393
3384 3394 * IPython/__release__.py (version): get date dynamically.
3385 3395
3386 3396 * Misc. documentation updates thanks to Arnd's comments. Also ran
3387 3397 a full spellcheck on the manual (hadn't been done in a while).
3388 3398
3389 3399 2002-04-27 Fernando Perez <fperez@colorado.edu>
3390 3400
3391 3401 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
3392 3402 starting a log in mid-session would reset the input history list.
3393 3403
3394 3404 2002-04-26 Fernando Perez <fperez@colorado.edu>
3395 3405
3396 3406 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
3397 3407 all files were being included in an update. Now anything in
3398 3408 UserConfig that matches [A-Za-z]*.py will go (this excludes
3399 3409 __init__.py)
3400 3410
3401 3411 2002-04-25 Fernando Perez <fperez@colorado.edu>
3402 3412
3403 3413 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
3404 3414 to __builtins__ so that any form of embedded or imported code can
3405 3415 test for being inside IPython.
3406 3416
3407 3417 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3408 3418 changed to GnuplotMagic because it's now an importable module,
3409 3419 this makes the name follow that of the standard Gnuplot module.
3410 3420 GnuplotMagic can now be loaded at any time in mid-session.
3411 3421
3412 3422 2002-04-24 Fernando Perez <fperez@colorado.edu>
3413 3423
3414 3424 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3415 3425 the globals (IPython has its own namespace) and the
3416 3426 PhysicalQuantity stuff is much better anyway.
3417 3427
3418 3428 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3419 3429 embedding example to standard user directory for
3420 3430 distribution. Also put it in the manual.
3421 3431
3422 3432 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3423 3433 instance as first argument (so it doesn't rely on some obscure
3424 3434 hidden global).
3425 3435
3426 3436 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3427 3437 delimiters. While it prevents ().TAB from working, it allows
3428 3438 completions in open (... expressions. This is by far a more common
3429 3439 case.
3430 3440
3431 3441 2002-04-23 Fernando Perez <fperez@colorado.edu>
3432 3442
3433 3443 * IPython/Extensions/InterpreterPasteInput.py: new
3434 3444 syntax-processing module for pasting lines with >>> or ... at the
3435 3445 start.
3436 3446
3437 3447 * IPython/Extensions/PhysicalQ_Interactive.py
3438 3448 (PhysicalQuantityInteractive.__int__): fixed to work with either
3439 3449 Numeric or math.
3440 3450
3441 3451 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3442 3452 provided profiles. Now we have:
3443 3453 -math -> math module as * and cmath with its own namespace.
3444 3454 -numeric -> Numeric as *, plus gnuplot & grace
3445 3455 -physics -> same as before
3446 3456
3447 3457 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3448 3458 user-defined magics wouldn't be found by @magic if they were
3449 3459 defined as class methods. Also cleaned up the namespace search
3450 3460 logic and the string building (to use %s instead of many repeated
3451 3461 string adds).
3452 3462
3453 3463 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3454 3464 of user-defined magics to operate with class methods (cleaner, in
3455 3465 line with the gnuplot code).
3456 3466
3457 3467 2002-04-22 Fernando Perez <fperez@colorado.edu>
3458 3468
3459 3469 * setup.py: updated dependency list so that manual is updated when
3460 3470 all included files change.
3461 3471
3462 3472 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3463 3473 the delimiter removal option (the fix is ugly right now).
3464 3474
3465 3475 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3466 3476 all of the math profile (quicker loading, no conflict between
3467 3477 g-9.8 and g-gnuplot).
3468 3478
3469 3479 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3470 3480 name of post-mortem files to IPython_crash_report.txt.
3471 3481
3472 3482 * Cleanup/update of the docs. Added all the new readline info and
3473 3483 formatted all lists as 'real lists'.
3474 3484
3475 3485 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3476 3486 tab-completion options, since the full readline parse_and_bind is
3477 3487 now accessible.
3478 3488
3479 3489 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3480 3490 handling of readline options. Now users can specify any string to
3481 3491 be passed to parse_and_bind(), as well as the delimiters to be
3482 3492 removed.
3483 3493 (InteractiveShell.__init__): Added __name__ to the global
3484 3494 namespace so that things like Itpl which rely on its existence
3485 3495 don't crash.
3486 3496 (InteractiveShell._prefilter): Defined the default with a _ so
3487 3497 that prefilter() is easier to override, while the default one
3488 3498 remains available.
3489 3499
3490 3500 2002-04-18 Fernando Perez <fperez@colorado.edu>
3491 3501
3492 3502 * Added information about pdb in the docs.
3493 3503
3494 3504 2002-04-17 Fernando Perez <fperez@colorado.edu>
3495 3505
3496 3506 * IPython/ipmaker.py (make_IPython): added rc_override option to
3497 3507 allow passing config options at creation time which may override
3498 3508 anything set in the config files or command line. This is
3499 3509 particularly useful for configuring embedded instances.
3500 3510
3501 3511 2002-04-15 Fernando Perez <fperez@colorado.edu>
3502 3512
3503 3513 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3504 3514 crash embedded instances because of the input cache falling out of
3505 3515 sync with the output counter.
3506 3516
3507 3517 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3508 3518 mode which calls pdb after an uncaught exception in IPython itself.
3509 3519
3510 3520 2002-04-14 Fernando Perez <fperez@colorado.edu>
3511 3521
3512 3522 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3513 3523 readline, fix it back after each call.
3514 3524
3515 3525 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3516 3526 method to force all access via __call__(), which guarantees that
3517 3527 traceback references are properly deleted.
3518 3528
3519 3529 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3520 3530 improve printing when pprint is in use.
3521 3531
3522 3532 2002-04-13 Fernando Perez <fperez@colorado.edu>
3523 3533
3524 3534 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3525 3535 exceptions aren't caught anymore. If the user triggers one, he
3526 3536 should know why he's doing it and it should go all the way up,
3527 3537 just like any other exception. So now @abort will fully kill the
3528 3538 embedded interpreter and the embedding code (unless that happens
3529 3539 to catch SystemExit).
3530 3540
3531 3541 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3532 3542 and a debugger() method to invoke the interactive pdb debugger
3533 3543 after printing exception information. Also added the corresponding
3534 3544 -pdb option and @pdb magic to control this feature, and updated
3535 3545 the docs. After a suggestion from Christopher Hart
3536 3546 (hart-AT-caltech.edu).
3537 3547
3538 3548 2002-04-12 Fernando Perez <fperez@colorado.edu>
3539 3549
3540 3550 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3541 3551 the exception handlers defined by the user (not the CrashHandler)
3542 3552 so that user exceptions don't trigger an ipython bug report.
3543 3553
3544 3554 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3545 3555 configurable (it should have always been so).
3546 3556
3547 3557 2002-03-26 Fernando Perez <fperez@colorado.edu>
3548 3558
3549 3559 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3550 3560 and there to fix embedding namespace issues. This should all be
3551 3561 done in a more elegant way.
3552 3562
3553 3563 2002-03-25 Fernando Perez <fperez@colorado.edu>
3554 3564
3555 3565 * IPython/genutils.py (get_home_dir): Try to make it work under
3556 3566 win9x also.
3557 3567
3558 3568 2002-03-20 Fernando Perez <fperez@colorado.edu>
3559 3569
3560 3570 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3561 3571 sys.displayhook untouched upon __init__.
3562 3572
3563 3573 2002-03-19 Fernando Perez <fperez@colorado.edu>
3564 3574
3565 3575 * Released 0.2.9 (for embedding bug, basically).
3566 3576
3567 3577 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3568 3578 exceptions so that enclosing shell's state can be restored.
3569 3579
3570 3580 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3571 3581 naming conventions in the .ipython/ dir.
3572 3582
3573 3583 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3574 3584 from delimiters list so filenames with - in them get expanded.
3575 3585
3576 3586 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3577 3587 sys.displayhook not being properly restored after an embedded call.
3578 3588
3579 3589 2002-03-18 Fernando Perez <fperez@colorado.edu>
3580 3590
3581 3591 * Released 0.2.8
3582 3592
3583 3593 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3584 3594 some files weren't being included in a -upgrade.
3585 3595 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3586 3596 on' so that the first tab completes.
3587 3597 (InteractiveShell.handle_magic): fixed bug with spaces around
3588 3598 quotes breaking many magic commands.
3589 3599
3590 3600 * setup.py: added note about ignoring the syntax error messages at
3591 3601 installation.
3592 3602
3593 3603 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3594 3604 streamlining the gnuplot interface, now there's only one magic @gp.
3595 3605
3596 3606 2002-03-17 Fernando Perez <fperez@colorado.edu>
3597 3607
3598 3608 * IPython/UserConfig/magic_gnuplot.py: new name for the
3599 3609 example-magic_pm.py file. Much enhanced system, now with a shell
3600 3610 for communicating directly with gnuplot, one command at a time.
3601 3611
3602 3612 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3603 3613 setting __name__=='__main__'.
3604 3614
3605 3615 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3606 3616 mini-shell for accessing gnuplot from inside ipython. Should
3607 3617 extend it later for grace access too. Inspired by Arnd's
3608 3618 suggestion.
3609 3619
3610 3620 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3611 3621 calling magic functions with () in their arguments. Thanks to Arnd
3612 3622 Baecker for pointing this to me.
3613 3623
3614 3624 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3615 3625 infinitely for integer or complex arrays (only worked with floats).
3616 3626
3617 3627 2002-03-16 Fernando Perez <fperez@colorado.edu>
3618 3628
3619 3629 * setup.py: Merged setup and setup_windows into a single script
3620 3630 which properly handles things for windows users.
3621 3631
3622 3632 2002-03-15 Fernando Perez <fperez@colorado.edu>
3623 3633
3624 3634 * Big change to the manual: now the magics are all automatically
3625 3635 documented. This information is generated from their docstrings
3626 3636 and put in a latex file included by the manual lyx file. This way
3627 3637 we get always up to date information for the magics. The manual
3628 3638 now also has proper version information, also auto-synced.
3629 3639
3630 3640 For this to work, an undocumented --magic_docstrings option was added.
3631 3641
3632 3642 2002-03-13 Fernando Perez <fperez@colorado.edu>
3633 3643
3634 3644 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3635 3645 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3636 3646
3637 3647 2002-03-12 Fernando Perez <fperez@colorado.edu>
3638 3648
3639 3649 * IPython/ultraTB.py (TermColors): changed color escapes again to
3640 3650 fix the (old, reintroduced) line-wrapping bug. Basically, if
3641 3651 \001..\002 aren't given in the color escapes, lines get wrapped
3642 3652 weirdly. But giving those screws up old xterms and emacs terms. So
3643 3653 I added some logic for emacs terms to be ok, but I can't identify old
3644 3654 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3645 3655
3646 3656 2002-03-10 Fernando Perez <fperez@colorado.edu>
3647 3657
3648 3658 * IPython/usage.py (__doc__): Various documentation cleanups and
3649 3659 updates, both in usage docstrings and in the manual.
3650 3660
3651 3661 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3652 3662 handling of caching. Set minimum acceptabe value for having a
3653 3663 cache at 20 values.
3654 3664
3655 3665 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3656 3666 install_first_time function to a method, renamed it and added an
3657 3667 'upgrade' mode. Now people can update their config directory with
3658 3668 a simple command line switch (-upgrade, also new).
3659 3669
3660 3670 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3661 3671 @file (convenient for automagic users under Python >= 2.2).
3662 3672 Removed @files (it seemed more like a plural than an abbrev. of
3663 3673 'file show').
3664 3674
3665 3675 * IPython/iplib.py (install_first_time): Fixed crash if there were
3666 3676 backup files ('~') in .ipython/ install directory.
3667 3677
3668 3678 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3669 3679 system. Things look fine, but these changes are fairly
3670 3680 intrusive. Test them for a few days.
3671 3681
3672 3682 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3673 3683 the prompts system. Now all in/out prompt strings are user
3674 3684 controllable. This is particularly useful for embedding, as one
3675 3685 can tag embedded instances with particular prompts.
3676 3686
3677 3687 Also removed global use of sys.ps1/2, which now allows nested
3678 3688 embeddings without any problems. Added command-line options for
3679 3689 the prompt strings.
3680 3690
3681 3691 2002-03-08 Fernando Perez <fperez@colorado.edu>
3682 3692
3683 3693 * IPython/UserConfig/example-embed-short.py (ipshell): added
3684 3694 example file with the bare minimum code for embedding.
3685 3695
3686 3696 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3687 3697 functionality for the embeddable shell to be activated/deactivated
3688 3698 either globally or at each call.
3689 3699
3690 3700 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3691 3701 rewriting the prompt with '--->' for auto-inputs with proper
3692 3702 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3693 3703 this is handled by the prompts class itself, as it should.
3694 3704
3695 3705 2002-03-05 Fernando Perez <fperez@colorado.edu>
3696 3706
3697 3707 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3698 3708 @logstart to avoid name clashes with the math log function.
3699 3709
3700 3710 * Big updates to X/Emacs section of the manual.
3701 3711
3702 3712 * Removed ipython_emacs. Milan explained to me how to pass
3703 3713 arguments to ipython through Emacs. Some day I'm going to end up
3704 3714 learning some lisp...
3705 3715
3706 3716 2002-03-04 Fernando Perez <fperez@colorado.edu>
3707 3717
3708 3718 * IPython/ipython_emacs: Created script to be used as the
3709 3719 py-python-command Emacs variable so we can pass IPython
3710 3720 parameters. I can't figure out how to tell Emacs directly to pass
3711 3721 parameters to IPython, so a dummy shell script will do it.
3712 3722
3713 3723 Other enhancements made for things to work better under Emacs'
3714 3724 various types of terminals. Many thanks to Milan Zamazal
3715 3725 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3716 3726
3717 3727 2002-03-01 Fernando Perez <fperez@colorado.edu>
3718 3728
3719 3729 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3720 3730 that loading of readline is now optional. This gives better
3721 3731 control to emacs users.
3722 3732
3723 3733 * IPython/ultraTB.py (__date__): Modified color escape sequences
3724 3734 and now things work fine under xterm and in Emacs' term buffers
3725 3735 (though not shell ones). Well, in emacs you get colors, but all
3726 3736 seem to be 'light' colors (no difference between dark and light
3727 3737 ones). But the garbage chars are gone, and also in xterms. It
3728 3738 seems that now I'm using 'cleaner' ansi sequences.
3729 3739
3730 3740 2002-02-21 Fernando Perez <fperez@colorado.edu>
3731 3741
3732 3742 * Released 0.2.7 (mainly to publish the scoping fix).
3733 3743
3734 3744 * IPython/Logger.py (Logger.logstate): added. A corresponding
3735 3745 @logstate magic was created.
3736 3746
3737 3747 * IPython/Magic.py: fixed nested scoping problem under Python
3738 3748 2.1.x (automagic wasn't working).
3739 3749
3740 3750 2002-02-20 Fernando Perez <fperez@colorado.edu>
3741 3751
3742 3752 * Released 0.2.6.
3743 3753
3744 3754 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3745 3755 option so that logs can come out without any headers at all.
3746 3756
3747 3757 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3748 3758 SciPy.
3749 3759
3750 3760 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3751 3761 that embedded IPython calls don't require vars() to be explicitly
3752 3762 passed. Now they are extracted from the caller's frame (code
3753 3763 snatched from Eric Jones' weave). Added better documentation to
3754 3764 the section on embedding and the example file.
3755 3765
3756 3766 * IPython/genutils.py (page): Changed so that under emacs, it just
3757 3767 prints the string. You can then page up and down in the emacs
3758 3768 buffer itself. This is how the builtin help() works.
3759 3769
3760 3770 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3761 3771 macro scoping: macros need to be executed in the user's namespace
3762 3772 to work as if they had been typed by the user.
3763 3773
3764 3774 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3765 3775 execute automatically (no need to type 'exec...'). They then
3766 3776 behave like 'true macros'. The printing system was also modified
3767 3777 for this to work.
3768 3778
3769 3779 2002-02-19 Fernando Perez <fperez@colorado.edu>
3770 3780
3771 3781 * IPython/genutils.py (page_file): new function for paging files
3772 3782 in an OS-independent way. Also necessary for file viewing to work
3773 3783 well inside Emacs buffers.
3774 3784 (page): Added checks for being in an emacs buffer.
3775 3785 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3776 3786 same bug in iplib.
3777 3787
3778 3788 2002-02-18 Fernando Perez <fperez@colorado.edu>
3779 3789
3780 3790 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3781 3791 of readline so that IPython can work inside an Emacs buffer.
3782 3792
3783 3793 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3784 3794 method signatures (they weren't really bugs, but it looks cleaner
3785 3795 and keeps PyChecker happy).
3786 3796
3787 3797 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3788 3798 for implementing various user-defined hooks. Currently only
3789 3799 display is done.
3790 3800
3791 3801 * IPython/Prompts.py (CachedOutput._display): changed display
3792 3802 functions so that they can be dynamically changed by users easily.
3793 3803
3794 3804 * IPython/Extensions/numeric_formats.py (num_display): added an
3795 3805 extension for printing NumPy arrays in flexible manners. It
3796 3806 doesn't do anything yet, but all the structure is in
3797 3807 place. Ultimately the plan is to implement output format control
3798 3808 like in Octave.
3799 3809
3800 3810 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3801 3811 methods are found at run-time by all the automatic machinery.
3802 3812
3803 3813 2002-02-17 Fernando Perez <fperez@colorado.edu>
3804 3814
3805 3815 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3806 3816 whole file a little.
3807 3817
3808 3818 * ToDo: closed this document. Now there's a new_design.lyx
3809 3819 document for all new ideas. Added making a pdf of it for the
3810 3820 end-user distro.
3811 3821
3812 3822 * IPython/Logger.py (Logger.switch_log): Created this to replace
3813 3823 logon() and logoff(). It also fixes a nasty crash reported by
3814 3824 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3815 3825
3816 3826 * IPython/iplib.py (complete): got auto-completion to work with
3817 3827 automagic (I had wanted this for a long time).
3818 3828
3819 3829 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3820 3830 to @file, since file() is now a builtin and clashes with automagic
3821 3831 for @file.
3822 3832
3823 3833 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3824 3834 of this was previously in iplib, which had grown to more than 2000
3825 3835 lines, way too long. No new functionality, but it makes managing
3826 3836 the code a bit easier.
3827 3837
3828 3838 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3829 3839 information to crash reports.
3830 3840
3831 3841 2002-02-12 Fernando Perez <fperez@colorado.edu>
3832 3842
3833 3843 * Released 0.2.5.
3834 3844
3835 3845 2002-02-11 Fernando Perez <fperez@colorado.edu>
3836 3846
3837 3847 * Wrote a relatively complete Windows installer. It puts
3838 3848 everything in place, creates Start Menu entries and fixes the
3839 3849 color issues. Nothing fancy, but it works.
3840 3850
3841 3851 2002-02-10 Fernando Perez <fperez@colorado.edu>
3842 3852
3843 3853 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3844 3854 os.path.expanduser() call so that we can type @run ~/myfile.py and
3845 3855 have thigs work as expected.
3846 3856
3847 3857 * IPython/genutils.py (page): fixed exception handling so things
3848 3858 work both in Unix and Windows correctly. Quitting a pager triggers
3849 3859 an IOError/broken pipe in Unix, and in windows not finding a pager
3850 3860 is also an IOError, so I had to actually look at the return value
3851 3861 of the exception, not just the exception itself. Should be ok now.
3852 3862
3853 3863 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3854 3864 modified to allow case-insensitive color scheme changes.
3855 3865
3856 3866 2002-02-09 Fernando Perez <fperez@colorado.edu>
3857 3867
3858 3868 * IPython/genutils.py (native_line_ends): new function to leave
3859 3869 user config files with os-native line-endings.
3860 3870
3861 3871 * README and manual updates.
3862 3872
3863 3873 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3864 3874 instead of StringType to catch Unicode strings.
3865 3875
3866 3876 * IPython/genutils.py (filefind): fixed bug for paths with
3867 3877 embedded spaces (very common in Windows).
3868 3878
3869 3879 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3870 3880 files under Windows, so that they get automatically associated
3871 3881 with a text editor. Windows makes it a pain to handle
3872 3882 extension-less files.
3873 3883
3874 3884 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3875 3885 warning about readline only occur for Posix. In Windows there's no
3876 3886 way to get readline, so why bother with the warning.
3877 3887
3878 3888 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3879 3889 for __str__ instead of dir(self), since dir() changed in 2.2.
3880 3890
3881 3891 * Ported to Windows! Tested on XP, I suspect it should work fine
3882 3892 on NT/2000, but I don't think it will work on 98 et al. That
3883 3893 series of Windows is such a piece of junk anyway that I won't try
3884 3894 porting it there. The XP port was straightforward, showed a few
3885 3895 bugs here and there (fixed all), in particular some string
3886 3896 handling stuff which required considering Unicode strings (which
3887 3897 Windows uses). This is good, but hasn't been too tested :) No
3888 3898 fancy installer yet, I'll put a note in the manual so people at
3889 3899 least make manually a shortcut.
3890 3900
3891 3901 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3892 3902 into a single one, "colors". This now controls both prompt and
3893 3903 exception color schemes, and can be changed both at startup
3894 3904 (either via command-line switches or via ipythonrc files) and at
3895 3905 runtime, with @colors.
3896 3906 (Magic.magic_run): renamed @prun to @run and removed the old
3897 3907 @run. The two were too similar to warrant keeping both.
3898 3908
3899 3909 2002-02-03 Fernando Perez <fperez@colorado.edu>
3900 3910
3901 3911 * IPython/iplib.py (install_first_time): Added comment on how to
3902 3912 configure the color options for first-time users. Put a <return>
3903 3913 request at the end so that small-terminal users get a chance to
3904 3914 read the startup info.
3905 3915
3906 3916 2002-01-23 Fernando Perez <fperez@colorado.edu>
3907 3917
3908 3918 * IPython/iplib.py (CachedOutput.update): Changed output memory
3909 3919 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3910 3920 input history we still use _i. Did this b/c these variable are
3911 3921 very commonly used in interactive work, so the less we need to
3912 3922 type the better off we are.
3913 3923 (Magic.magic_prun): updated @prun to better handle the namespaces
3914 3924 the file will run in, including a fix for __name__ not being set
3915 3925 before.
3916 3926
3917 3927 2002-01-20 Fernando Perez <fperez@colorado.edu>
3918 3928
3919 3929 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3920 3930 extra garbage for Python 2.2. Need to look more carefully into
3921 3931 this later.
3922 3932
3923 3933 2002-01-19 Fernando Perez <fperez@colorado.edu>
3924 3934
3925 3935 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3926 3936 display SyntaxError exceptions properly formatted when they occur
3927 3937 (they can be triggered by imported code).
3928 3938
3929 3939 2002-01-18 Fernando Perez <fperez@colorado.edu>
3930 3940
3931 3941 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3932 3942 SyntaxError exceptions are reported nicely formatted, instead of
3933 3943 spitting out only offset information as before.
3934 3944 (Magic.magic_prun): Added the @prun function for executing
3935 3945 programs with command line args inside IPython.
3936 3946
3937 3947 2002-01-16 Fernando Perez <fperez@colorado.edu>
3938 3948
3939 3949 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3940 3950 to *not* include the last item given in a range. This brings their
3941 3951 behavior in line with Python's slicing:
3942 3952 a[n1:n2] -> a[n1]...a[n2-1]
3943 3953 It may be a bit less convenient, but I prefer to stick to Python's
3944 3954 conventions *everywhere*, so users never have to wonder.
3945 3955 (Magic.magic_macro): Added @macro function to ease the creation of
3946 3956 macros.
3947 3957
3948 3958 2002-01-05 Fernando Perez <fperez@colorado.edu>
3949 3959
3950 3960 * Released 0.2.4.
3951 3961
3952 3962 * IPython/iplib.py (Magic.magic_pdef):
3953 3963 (InteractiveShell.safe_execfile): report magic lines and error
3954 3964 lines without line numbers so one can easily copy/paste them for
3955 3965 re-execution.
3956 3966
3957 3967 * Updated manual with recent changes.
3958 3968
3959 3969 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3960 3970 docstring printing when class? is called. Very handy for knowing
3961 3971 how to create class instances (as long as __init__ is well
3962 3972 documented, of course :)
3963 3973 (Magic.magic_doc): print both class and constructor docstrings.
3964 3974 (Magic.magic_pdef): give constructor info if passed a class and
3965 3975 __call__ info for callable object instances.
3966 3976
3967 3977 2002-01-04 Fernando Perez <fperez@colorado.edu>
3968 3978
3969 3979 * Made deep_reload() off by default. It doesn't always work
3970 3980 exactly as intended, so it's probably safer to have it off. It's
3971 3981 still available as dreload() anyway, so nothing is lost.
3972 3982
3973 3983 2002-01-02 Fernando Perez <fperez@colorado.edu>
3974 3984
3975 3985 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3976 3986 so I wanted an updated release).
3977 3987
3978 3988 2001-12-27 Fernando Perez <fperez@colorado.edu>
3979 3989
3980 3990 * IPython/iplib.py (InteractiveShell.interact): Added the original
3981 3991 code from 'code.py' for this module in order to change the
3982 3992 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3983 3993 the history cache would break when the user hit Ctrl-C, and
3984 3994 interact() offers no way to add any hooks to it.
3985 3995
3986 3996 2001-12-23 Fernando Perez <fperez@colorado.edu>
3987 3997
3988 3998 * setup.py: added check for 'MANIFEST' before trying to remove
3989 3999 it. Thanks to Sean Reifschneider.
3990 4000
3991 4001 2001-12-22 Fernando Perez <fperez@colorado.edu>
3992 4002
3993 4003 * Released 0.2.2.
3994 4004
3995 4005 * Finished (reasonably) writing the manual. Later will add the
3996 4006 python-standard navigation stylesheets, but for the time being
3997 4007 it's fairly complete. Distribution will include html and pdf
3998 4008 versions.
3999 4009
4000 4010 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
4001 4011 (MayaVi author).
4002 4012
4003 4013 2001-12-21 Fernando Perez <fperez@colorado.edu>
4004 4014
4005 4015 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
4006 4016 good public release, I think (with the manual and the distutils
4007 4017 installer). The manual can use some work, but that can go
4008 4018 slowly. Otherwise I think it's quite nice for end users. Next
4009 4019 summer, rewrite the guts of it...
4010 4020
4011 4021 * Changed format of ipythonrc files to use whitespace as the
4012 4022 separator instead of an explicit '='. Cleaner.
4013 4023
4014 4024 2001-12-20 Fernando Perez <fperez@colorado.edu>
4015 4025
4016 4026 * Started a manual in LyX. For now it's just a quick merge of the
4017 4027 various internal docstrings and READMEs. Later it may grow into a
4018 4028 nice, full-blown manual.
4019 4029
4020 4030 * Set up a distutils based installer. Installation should now be
4021 4031 trivially simple for end-users.
4022 4032
4023 4033 2001-12-11 Fernando Perez <fperez@colorado.edu>
4024 4034
4025 4035 * Released 0.2.0. First public release, announced it at
4026 4036 comp.lang.python. From now on, just bugfixes...
4027 4037
4028 4038 * Went through all the files, set copyright/license notices and
4029 4039 cleaned up things. Ready for release.
4030 4040
4031 4041 2001-12-10 Fernando Perez <fperez@colorado.edu>
4032 4042
4033 4043 * Changed the first-time installer not to use tarfiles. It's more
4034 4044 robust now and less unix-dependent. Also makes it easier for
4035 4045 people to later upgrade versions.
4036 4046
4037 4047 * Changed @exit to @abort to reflect the fact that it's pretty
4038 4048 brutal (a sys.exit()). The difference between @abort and Ctrl-D
4039 4049 becomes significant only when IPyhton is embedded: in that case,
4040 4050 C-D closes IPython only, but @abort kills the enclosing program
4041 4051 too (unless it had called IPython inside a try catching
4042 4052 SystemExit).
4043 4053
4044 4054 * Created Shell module which exposes the actuall IPython Shell
4045 4055 classes, currently the normal and the embeddable one. This at
4046 4056 least offers a stable interface we won't need to change when
4047 4057 (later) the internals are rewritten. That rewrite will be confined
4048 4058 to iplib and ipmaker, but the Shell interface should remain as is.
4049 4059
4050 4060 * Added embed module which offers an embeddable IPShell object,
4051 4061 useful to fire up IPython *inside* a running program. Great for
4052 4062 debugging or dynamical data analysis.
4053 4063
4054 4064 2001-12-08 Fernando Perez <fperez@colorado.edu>
4055 4065
4056 4066 * Fixed small bug preventing seeing info from methods of defined
4057 4067 objects (incorrect namespace in _ofind()).
4058 4068
4059 4069 * Documentation cleanup. Moved the main usage docstrings to a
4060 4070 separate file, usage.py (cleaner to maintain, and hopefully in the
4061 4071 future some perlpod-like way of producing interactive, man and
4062 4072 html docs out of it will be found).
4063 4073
4064 4074 * Added @profile to see your profile at any time.
4065 4075
4066 4076 * Added @p as an alias for 'print'. It's especially convenient if
4067 4077 using automagic ('p x' prints x).
4068 4078
4069 4079 * Small cleanups and fixes after a pychecker run.
4070 4080
4071 4081 * Changed the @cd command to handle @cd - and @cd -<n> for
4072 4082 visiting any directory in _dh.
4073 4083
4074 4084 * Introduced _dh, a history of visited directories. @dhist prints
4075 4085 it out with numbers.
4076 4086
4077 4087 2001-12-07 Fernando Perez <fperez@colorado.edu>
4078 4088
4079 4089 * Released 0.1.22
4080 4090
4081 4091 * Made initialization a bit more robust against invalid color
4082 4092 options in user input (exit, not traceback-crash).
4083 4093
4084 4094 * Changed the bug crash reporter to write the report only in the
4085 4095 user's .ipython directory. That way IPython won't litter people's
4086 4096 hard disks with crash files all over the place. Also print on
4087 4097 screen the necessary mail command.
4088 4098
4089 4099 * With the new ultraTB, implemented LightBG color scheme for light
4090 4100 background terminals. A lot of people like white backgrounds, so I
4091 4101 guess we should at least give them something readable.
4092 4102
4093 4103 2001-12-06 Fernando Perez <fperez@colorado.edu>
4094 4104
4095 4105 * Modified the structure of ultraTB. Now there's a proper class
4096 4106 for tables of color schemes which allow adding schemes easily and
4097 4107 switching the active scheme without creating a new instance every
4098 4108 time (which was ridiculous). The syntax for creating new schemes
4099 4109 is also cleaner. I think ultraTB is finally done, with a clean
4100 4110 class structure. Names are also much cleaner (now there's proper
4101 4111 color tables, no need for every variable to also have 'color' in
4102 4112 its name).
4103 4113
4104 4114 * Broke down genutils into separate files. Now genutils only
4105 4115 contains utility functions, and classes have been moved to their
4106 4116 own files (they had enough independent functionality to warrant
4107 4117 it): ConfigLoader, OutputTrap, Struct.
4108 4118
4109 4119 2001-12-05 Fernando Perez <fperez@colorado.edu>
4110 4120
4111 4121 * IPython turns 21! Released version 0.1.21, as a candidate for
4112 4122 public consumption. If all goes well, release in a few days.
4113 4123
4114 4124 * Fixed path bug (files in Extensions/ directory wouldn't be found
4115 4125 unless IPython/ was explicitly in sys.path).
4116 4126
4117 4127 * Extended the FlexCompleter class as MagicCompleter to allow
4118 4128 completion of @-starting lines.
4119 4129
4120 4130 * Created __release__.py file as a central repository for release
4121 4131 info that other files can read from.
4122 4132
4123 4133 * Fixed small bug in logging: when logging was turned on in
4124 4134 mid-session, old lines with special meanings (!@?) were being
4125 4135 logged without the prepended comment, which is necessary since
4126 4136 they are not truly valid python syntax. This should make session
4127 4137 restores produce less errors.
4128 4138
4129 4139 * The namespace cleanup forced me to make a FlexCompleter class
4130 4140 which is nothing but a ripoff of rlcompleter, but with selectable
4131 4141 namespace (rlcompleter only works in __main__.__dict__). I'll try
4132 4142 to submit a note to the authors to see if this change can be
4133 4143 incorporated in future rlcompleter releases (Dec.6: done)
4134 4144
4135 4145 * More fixes to namespace handling. It was a mess! Now all
4136 4146 explicit references to __main__.__dict__ are gone (except when
4137 4147 really needed) and everything is handled through the namespace
4138 4148 dicts in the IPython instance. We seem to be getting somewhere
4139 4149 with this, finally...
4140 4150
4141 4151 * Small documentation updates.
4142 4152
4143 4153 * Created the Extensions directory under IPython (with an
4144 4154 __init__.py). Put the PhysicalQ stuff there. This directory should
4145 4155 be used for all special-purpose extensions.
4146 4156
4147 4157 * File renaming:
4148 4158 ipythonlib --> ipmaker
4149 4159 ipplib --> iplib
4150 4160 This makes a bit more sense in terms of what these files actually do.
4151 4161
4152 4162 * Moved all the classes and functions in ipythonlib to ipplib, so
4153 4163 now ipythonlib only has make_IPython(). This will ease up its
4154 4164 splitting in smaller functional chunks later.
4155 4165
4156 4166 * Cleaned up (done, I think) output of @whos. Better column
4157 4167 formatting, and now shows str(var) for as much as it can, which is
4158 4168 typically what one gets with a 'print var'.
4159 4169
4160 4170 2001-12-04 Fernando Perez <fperez@colorado.edu>
4161 4171
4162 4172 * Fixed namespace problems. Now builtin/IPyhton/user names get
4163 4173 properly reported in their namespace. Internal namespace handling
4164 4174 is finally getting decent (not perfect yet, but much better than
4165 4175 the ad-hoc mess we had).
4166 4176
4167 4177 * Removed -exit option. If people just want to run a python
4168 4178 script, that's what the normal interpreter is for. Less
4169 4179 unnecessary options, less chances for bugs.
4170 4180
4171 4181 * Added a crash handler which generates a complete post-mortem if
4172 4182 IPython crashes. This will help a lot in tracking bugs down the
4173 4183 road.
4174 4184
4175 4185 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
4176 4186 which were boud to functions being reassigned would bypass the
4177 4187 logger, breaking the sync of _il with the prompt counter. This
4178 4188 would then crash IPython later when a new line was logged.
4179 4189
4180 4190 2001-12-02 Fernando Perez <fperez@colorado.edu>
4181 4191
4182 4192 * Made IPython a package. This means people don't have to clutter
4183 4193 their sys.path with yet another directory. Changed the INSTALL
4184 4194 file accordingly.
4185 4195
4186 4196 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
4187 4197 sorts its output (so @who shows it sorted) and @whos formats the
4188 4198 table according to the width of the first column. Nicer, easier to
4189 4199 read. Todo: write a generic table_format() which takes a list of
4190 4200 lists and prints it nicely formatted, with optional row/column
4191 4201 separators and proper padding and justification.
4192 4202
4193 4203 * Released 0.1.20
4194 4204
4195 4205 * Fixed bug in @log which would reverse the inputcache list (a
4196 4206 copy operation was missing).
4197 4207
4198 4208 * Code cleanup. @config was changed to use page(). Better, since
4199 4209 its output is always quite long.
4200 4210
4201 4211 * Itpl is back as a dependency. I was having too many problems
4202 4212 getting the parametric aliases to work reliably, and it's just
4203 4213 easier to code weird string operations with it than playing %()s
4204 4214 games. It's only ~6k, so I don't think it's too big a deal.
4205 4215
4206 4216 * Found (and fixed) a very nasty bug with history. !lines weren't
4207 4217 getting cached, and the out of sync caches would crash
4208 4218 IPython. Fixed it by reorganizing the prefilter/handlers/logger
4209 4219 division of labor a bit better. Bug fixed, cleaner structure.
4210 4220
4211 4221 2001-12-01 Fernando Perez <fperez@colorado.edu>
4212 4222
4213 4223 * Released 0.1.19
4214 4224
4215 4225 * Added option -n to @hist to prevent line number printing. Much
4216 4226 easier to copy/paste code this way.
4217 4227
4218 4228 * Created global _il to hold the input list. Allows easy
4219 4229 re-execution of blocks of code by slicing it (inspired by Janko's
4220 4230 comment on 'macros').
4221 4231
4222 4232 * Small fixes and doc updates.
4223 4233
4224 4234 * Rewrote @history function (was @h). Renamed it to @hist, @h is
4225 4235 much too fragile with automagic. Handles properly multi-line
4226 4236 statements and takes parameters.
4227 4237
4228 4238 2001-11-30 Fernando Perez <fperez@colorado.edu>
4229 4239
4230 4240 * Version 0.1.18 released.
4231 4241
4232 4242 * Fixed nasty namespace bug in initial module imports.
4233 4243
4234 4244 * Added copyright/license notes to all code files (except
4235 4245 DPyGetOpt). For the time being, LGPL. That could change.
4236 4246
4237 4247 * Rewrote a much nicer README, updated INSTALL, cleaned up
4238 4248 ipythonrc-* samples.
4239 4249
4240 4250 * Overall code/documentation cleanup. Basically ready for
4241 4251 release. Only remaining thing: licence decision (LGPL?).
4242 4252
4243 4253 * Converted load_config to a class, ConfigLoader. Now recursion
4244 4254 control is better organized. Doesn't include the same file twice.
4245 4255
4246 4256 2001-11-29 Fernando Perez <fperez@colorado.edu>
4247 4257
4248 4258 * Got input history working. Changed output history variables from
4249 4259 _p to _o so that _i is for input and _o for output. Just cleaner
4250 4260 convention.
4251 4261
4252 4262 * Implemented parametric aliases. This pretty much allows the
4253 4263 alias system to offer full-blown shell convenience, I think.
4254 4264
4255 4265 * Version 0.1.17 released, 0.1.18 opened.
4256 4266
4257 4267 * dot_ipython/ipythonrc (alias): added documentation.
4258 4268 (xcolor): Fixed small bug (xcolors -> xcolor)
4259 4269
4260 4270 * Changed the alias system. Now alias is a magic command to define
4261 4271 aliases just like the shell. Rationale: the builtin magics should
4262 4272 be there for things deeply connected to IPython's
4263 4273 architecture. And this is a much lighter system for what I think
4264 4274 is the really important feature: allowing users to define quickly
4265 4275 magics that will do shell things for them, so they can customize
4266 4276 IPython easily to match their work habits. If someone is really
4267 4277 desperate to have another name for a builtin alias, they can
4268 4278 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
4269 4279 works.
4270 4280
4271 4281 2001-11-28 Fernando Perez <fperez@colorado.edu>
4272 4282
4273 4283 * Changed @file so that it opens the source file at the proper
4274 4284 line. Since it uses less, if your EDITOR environment is
4275 4285 configured, typing v will immediately open your editor of choice
4276 4286 right at the line where the object is defined. Not as quick as
4277 4287 having a direct @edit command, but for all intents and purposes it
4278 4288 works. And I don't have to worry about writing @edit to deal with
4279 4289 all the editors, less does that.
4280 4290
4281 4291 * Version 0.1.16 released, 0.1.17 opened.
4282 4292
4283 4293 * Fixed some nasty bugs in the page/page_dumb combo that could
4284 4294 crash IPython.
4285 4295
4286 4296 2001-11-27 Fernando Perez <fperez@colorado.edu>
4287 4297
4288 4298 * Version 0.1.15 released, 0.1.16 opened.
4289 4299
4290 4300 * Finally got ? and ?? to work for undefined things: now it's
4291 4301 possible to type {}.get? and get information about the get method
4292 4302 of dicts, or os.path? even if only os is defined (so technically
4293 4303 os.path isn't). Works at any level. For example, after import os,
4294 4304 os?, os.path?, os.path.abspath? all work. This is great, took some
4295 4305 work in _ofind.
4296 4306
4297 4307 * Fixed more bugs with logging. The sanest way to do it was to add
4298 4308 to @log a 'mode' parameter. Killed two in one shot (this mode
4299 4309 option was a request of Janko's). I think it's finally clean
4300 4310 (famous last words).
4301 4311
4302 4312 * Added a page_dumb() pager which does a decent job of paging on
4303 4313 screen, if better things (like less) aren't available. One less
4304 4314 unix dependency (someday maybe somebody will port this to
4305 4315 windows).
4306 4316
4307 4317 * Fixed problem in magic_log: would lock of logging out if log
4308 4318 creation failed (because it would still think it had succeeded).
4309 4319
4310 4320 * Improved the page() function using curses to auto-detect screen
4311 4321 size. Now it can make a much better decision on whether to print
4312 4322 or page a string. Option screen_length was modified: a value 0
4313 4323 means auto-detect, and that's the default now.
4314 4324
4315 4325 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
4316 4326 go out. I'll test it for a few days, then talk to Janko about
4317 4327 licences and announce it.
4318 4328
4319 4329 * Fixed the length of the auto-generated ---> prompt which appears
4320 4330 for auto-parens and auto-quotes. Getting this right isn't trivial,
4321 4331 with all the color escapes, different prompt types and optional
4322 4332 separators. But it seems to be working in all the combinations.
4323 4333
4324 4334 2001-11-26 Fernando Perez <fperez@colorado.edu>
4325 4335
4326 4336 * Wrote a regexp filter to get option types from the option names
4327 4337 string. This eliminates the need to manually keep two duplicate
4328 4338 lists.
4329 4339
4330 4340 * Removed the unneeded check_option_names. Now options are handled
4331 4341 in a much saner manner and it's easy to visually check that things
4332 4342 are ok.
4333 4343
4334 4344 * Updated version numbers on all files I modified to carry a
4335 4345 notice so Janko and Nathan have clear version markers.
4336 4346
4337 4347 * Updated docstring for ultraTB with my changes. I should send
4338 4348 this to Nathan.
4339 4349
4340 4350 * Lots of small fixes. Ran everything through pychecker again.
4341 4351
4342 4352 * Made loading of deep_reload an cmd line option. If it's not too
4343 4353 kosher, now people can just disable it. With -nodeep_reload it's
4344 4354 still available as dreload(), it just won't overwrite reload().
4345 4355
4346 4356 * Moved many options to the no| form (-opt and -noopt
4347 4357 accepted). Cleaner.
4348 4358
4349 4359 * Changed magic_log so that if called with no parameters, it uses
4350 4360 'rotate' mode. That way auto-generated logs aren't automatically
4351 4361 over-written. For normal logs, now a backup is made if it exists
4352 4362 (only 1 level of backups). A new 'backup' mode was added to the
4353 4363 Logger class to support this. This was a request by Janko.
4354 4364
4355 4365 * Added @logoff/@logon to stop/restart an active log.
4356 4366
4357 4367 * Fixed a lot of bugs in log saving/replay. It was pretty
4358 4368 broken. Now special lines (!@,/) appear properly in the command
4359 4369 history after a log replay.
4360 4370
4361 4371 * Tried and failed to implement full session saving via pickle. My
4362 4372 idea was to pickle __main__.__dict__, but modules can't be
4363 4373 pickled. This would be a better alternative to replaying logs, but
4364 4374 seems quite tricky to get to work. Changed -session to be called
4365 4375 -logplay, which more accurately reflects what it does. And if we
4366 4376 ever get real session saving working, -session is now available.
4367 4377
4368 4378 * Implemented color schemes for prompts also. As for tracebacks,
4369 4379 currently only NoColor and Linux are supported. But now the
4370 4380 infrastructure is in place, based on a generic ColorScheme
4371 4381 class. So writing and activating new schemes both for the prompts
4372 4382 and the tracebacks should be straightforward.
4373 4383
4374 4384 * Version 0.1.13 released, 0.1.14 opened.
4375 4385
4376 4386 * Changed handling of options for output cache. Now counter is
4377 4387 hardwired starting at 1 and one specifies the maximum number of
4378 4388 entries *in the outcache* (not the max prompt counter). This is
4379 4389 much better, since many statements won't increase the cache
4380 4390 count. It also eliminated some confusing options, now there's only
4381 4391 one: cache_size.
4382 4392
4383 4393 * Added 'alias' magic function and magic_alias option in the
4384 4394 ipythonrc file. Now the user can easily define whatever names he
4385 4395 wants for the magic functions without having to play weird
4386 4396 namespace games. This gives IPython a real shell-like feel.
4387 4397
4388 4398 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
4389 4399 @ or not).
4390 4400
4391 4401 This was one of the last remaining 'visible' bugs (that I know
4392 4402 of). I think if I can clean up the session loading so it works
4393 4403 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
4394 4404 about licensing).
4395 4405
4396 4406 2001-11-25 Fernando Perez <fperez@colorado.edu>
4397 4407
4398 4408 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
4399 4409 there's a cleaner distinction between what ? and ?? show.
4400 4410
4401 4411 * Added screen_length option. Now the user can define his own
4402 4412 screen size for page() operations.
4403 4413
4404 4414 * Implemented magic shell-like functions with automatic code
4405 4415 generation. Now adding another function is just a matter of adding
4406 4416 an entry to a dict, and the function is dynamically generated at
4407 4417 run-time. Python has some really cool features!
4408 4418
4409 4419 * Renamed many options to cleanup conventions a little. Now all
4410 4420 are lowercase, and only underscores where needed. Also in the code
4411 4421 option name tables are clearer.
4412 4422
4413 4423 * Changed prompts a little. Now input is 'In [n]:' instead of
4414 4424 'In[n]:='. This allows it the numbers to be aligned with the
4415 4425 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4416 4426 Python (it was a Mathematica thing). The '...' continuation prompt
4417 4427 was also changed a little to align better.
4418 4428
4419 4429 * Fixed bug when flushing output cache. Not all _p<n> variables
4420 4430 exist, so their deletion needs to be wrapped in a try:
4421 4431
4422 4432 * Figured out how to properly use inspect.formatargspec() (it
4423 4433 requires the args preceded by *). So I removed all the code from
4424 4434 _get_pdef in Magic, which was just replicating that.
4425 4435
4426 4436 * Added test to prefilter to allow redefining magic function names
4427 4437 as variables. This is ok, since the @ form is always available,
4428 4438 but whe should allow the user to define a variable called 'ls' if
4429 4439 he needs it.
4430 4440
4431 4441 * Moved the ToDo information from README into a separate ToDo.
4432 4442
4433 4443 * General code cleanup and small bugfixes. I think it's close to a
4434 4444 state where it can be released, obviously with a big 'beta'
4435 4445 warning on it.
4436 4446
4437 4447 * Got the magic function split to work. Now all magics are defined
4438 4448 in a separate class. It just organizes things a bit, and now
4439 4449 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4440 4450 was too long).
4441 4451
4442 4452 * Changed @clear to @reset to avoid potential confusions with
4443 4453 the shell command clear. Also renamed @cl to @clear, which does
4444 4454 exactly what people expect it to from their shell experience.
4445 4455
4446 4456 Added a check to the @reset command (since it's so
4447 4457 destructive, it's probably a good idea to ask for confirmation).
4448 4458 But now reset only works for full namespace resetting. Since the
4449 4459 del keyword is already there for deleting a few specific
4450 4460 variables, I don't see the point of having a redundant magic
4451 4461 function for the same task.
4452 4462
4453 4463 2001-11-24 Fernando Perez <fperez@colorado.edu>
4454 4464
4455 4465 * Updated the builtin docs (esp. the ? ones).
4456 4466
4457 4467 * Ran all the code through pychecker. Not terribly impressed with
4458 4468 it: lots of spurious warnings and didn't really find anything of
4459 4469 substance (just a few modules being imported and not used).
4460 4470
4461 4471 * Implemented the new ultraTB functionality into IPython. New
4462 4472 option: xcolors. This chooses color scheme. xmode now only selects
4463 4473 between Plain and Verbose. Better orthogonality.
4464 4474
4465 4475 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4466 4476 mode and color scheme for the exception handlers. Now it's
4467 4477 possible to have the verbose traceback with no coloring.
4468 4478
4469 4479 2001-11-23 Fernando Perez <fperez@colorado.edu>
4470 4480
4471 4481 * Version 0.1.12 released, 0.1.13 opened.
4472 4482
4473 4483 * Removed option to set auto-quote and auto-paren escapes by
4474 4484 user. The chances of breaking valid syntax are just too high. If
4475 4485 someone *really* wants, they can always dig into the code.
4476 4486
4477 4487 * Made prompt separators configurable.
4478 4488
4479 4489 2001-11-22 Fernando Perez <fperez@colorado.edu>
4480 4490
4481 4491 * Small bugfixes in many places.
4482 4492
4483 4493 * Removed the MyCompleter class from ipplib. It seemed redundant
4484 4494 with the C-p,C-n history search functionality. Less code to
4485 4495 maintain.
4486 4496
4487 4497 * Moved all the original ipython.py code into ipythonlib.py. Right
4488 4498 now it's just one big dump into a function called make_IPython, so
4489 4499 no real modularity has been gained. But at least it makes the
4490 4500 wrapper script tiny, and since ipythonlib is a module, it gets
4491 4501 compiled and startup is much faster.
4492 4502
4493 4503 This is a reasobably 'deep' change, so we should test it for a
4494 4504 while without messing too much more with the code.
4495 4505
4496 4506 2001-11-21 Fernando Perez <fperez@colorado.edu>
4497 4507
4498 4508 * Version 0.1.11 released, 0.1.12 opened for further work.
4499 4509
4500 4510 * Removed dependency on Itpl. It was only needed in one place. It
4501 4511 would be nice if this became part of python, though. It makes life
4502 4512 *a lot* easier in some cases.
4503 4513
4504 4514 * Simplified the prefilter code a bit. Now all handlers are
4505 4515 expected to explicitly return a value (at least a blank string).
4506 4516
4507 4517 * Heavy edits in ipplib. Removed the help system altogether. Now
4508 4518 obj?/?? is used for inspecting objects, a magic @doc prints
4509 4519 docstrings, and full-blown Python help is accessed via the 'help'
4510 4520 keyword. This cleans up a lot of code (less to maintain) and does
4511 4521 the job. Since 'help' is now a standard Python component, might as
4512 4522 well use it and remove duplicate functionality.
4513 4523
4514 4524 Also removed the option to use ipplib as a standalone program. By
4515 4525 now it's too dependent on other parts of IPython to function alone.
4516 4526
4517 4527 * Fixed bug in genutils.pager. It would crash if the pager was
4518 4528 exited immediately after opening (broken pipe).
4519 4529
4520 4530 * Trimmed down the VerboseTB reporting a little. The header is
4521 4531 much shorter now and the repeated exception arguments at the end
4522 4532 have been removed. For interactive use the old header seemed a bit
4523 4533 excessive.
4524 4534
4525 4535 * Fixed small bug in output of @whos for variables with multi-word
4526 4536 types (only first word was displayed).
4527 4537
4528 4538 2001-11-17 Fernando Perez <fperez@colorado.edu>
4529 4539
4530 4540 * Version 0.1.10 released, 0.1.11 opened for further work.
4531 4541
4532 4542 * Modified dirs and friends. dirs now *returns* the stack (not
4533 4543 prints), so one can manipulate it as a variable. Convenient to
4534 4544 travel along many directories.
4535 4545
4536 4546 * Fixed bug in magic_pdef: would only work with functions with
4537 4547 arguments with default values.
4538 4548
4539 4549 2001-11-14 Fernando Perez <fperez@colorado.edu>
4540 4550
4541 4551 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4542 4552 example with IPython. Various other minor fixes and cleanups.
4543 4553
4544 4554 * Version 0.1.9 released, 0.1.10 opened for further work.
4545 4555
4546 4556 * Added sys.path to the list of directories searched in the
4547 4557 execfile= option. It used to be the current directory and the
4548 4558 user's IPYTHONDIR only.
4549 4559
4550 4560 2001-11-13 Fernando Perez <fperez@colorado.edu>
4551 4561
4552 4562 * Reinstated the raw_input/prefilter separation that Janko had
4553 4563 initially. This gives a more convenient setup for extending the
4554 4564 pre-processor from the outside: raw_input always gets a string,
4555 4565 and prefilter has to process it. We can then redefine prefilter
4556 4566 from the outside and implement extensions for special
4557 4567 purposes.
4558 4568
4559 4569 Today I got one for inputting PhysicalQuantity objects
4560 4570 (from Scientific) without needing any function calls at
4561 4571 all. Extremely convenient, and it's all done as a user-level
4562 4572 extension (no IPython code was touched). Now instead of:
4563 4573 a = PhysicalQuantity(4.2,'m/s**2')
4564 4574 one can simply say
4565 4575 a = 4.2 m/s**2
4566 4576 or even
4567 4577 a = 4.2 m/s^2
4568 4578
4569 4579 I use this, but it's also a proof of concept: IPython really is
4570 4580 fully user-extensible, even at the level of the parsing of the
4571 4581 command line. It's not trivial, but it's perfectly doable.
4572 4582
4573 4583 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4574 4584 the problem of modules being loaded in the inverse order in which
4575 4585 they were defined in
4576 4586
4577 4587 * Version 0.1.8 released, 0.1.9 opened for further work.
4578 4588
4579 4589 * Added magics pdef, source and file. They respectively show the
4580 4590 definition line ('prototype' in C), source code and full python
4581 4591 file for any callable object. The object inspector oinfo uses
4582 4592 these to show the same information.
4583 4593
4584 4594 * Version 0.1.7 released, 0.1.8 opened for further work.
4585 4595
4586 4596 * Separated all the magic functions into a class called Magic. The
4587 4597 InteractiveShell class was becoming too big for Xemacs to handle
4588 4598 (de-indenting a line would lock it up for 10 seconds while it
4589 4599 backtracked on the whole class!)
4590 4600
4591 4601 FIXME: didn't work. It can be done, but right now namespaces are
4592 4602 all messed up. Do it later (reverted it for now, so at least
4593 4603 everything works as before).
4594 4604
4595 4605 * Got the object introspection system (magic_oinfo) working! I
4596 4606 think this is pretty much ready for release to Janko, so he can
4597 4607 test it for a while and then announce it. Pretty much 100% of what
4598 4608 I wanted for the 'phase 1' release is ready. Happy, tired.
4599 4609
4600 4610 2001-11-12 Fernando Perez <fperez@colorado.edu>
4601 4611
4602 4612 * Version 0.1.6 released, 0.1.7 opened for further work.
4603 4613
4604 4614 * Fixed bug in printing: it used to test for truth before
4605 4615 printing, so 0 wouldn't print. Now checks for None.
4606 4616
4607 4617 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4608 4618 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4609 4619 reaches by hand into the outputcache. Think of a better way to do
4610 4620 this later.
4611 4621
4612 4622 * Various small fixes thanks to Nathan's comments.
4613 4623
4614 4624 * Changed magic_pprint to magic_Pprint. This way it doesn't
4615 4625 collide with pprint() and the name is consistent with the command
4616 4626 line option.
4617 4627
4618 4628 * Changed prompt counter behavior to be fully like
4619 4629 Mathematica's. That is, even input that doesn't return a result
4620 4630 raises the prompt counter. The old behavior was kind of confusing
4621 4631 (getting the same prompt number several times if the operation
4622 4632 didn't return a result).
4623 4633
4624 4634 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4625 4635
4626 4636 * Fixed -Classic mode (wasn't working anymore).
4627 4637
4628 4638 * Added colored prompts using Nathan's new code. Colors are
4629 4639 currently hardwired, they can be user-configurable. For
4630 4640 developers, they can be chosen in file ipythonlib.py, at the
4631 4641 beginning of the CachedOutput class def.
4632 4642
4633 4643 2001-11-11 Fernando Perez <fperez@colorado.edu>
4634 4644
4635 4645 * Version 0.1.5 released, 0.1.6 opened for further work.
4636 4646
4637 4647 * Changed magic_env to *return* the environment as a dict (not to
4638 4648 print it). This way it prints, but it can also be processed.
4639 4649
4640 4650 * Added Verbose exception reporting to interactive
4641 4651 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4642 4652 traceback. Had to make some changes to the ultraTB file. This is
4643 4653 probably the last 'big' thing in my mental todo list. This ties
4644 4654 in with the next entry:
4645 4655
4646 4656 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4647 4657 has to specify is Plain, Color or Verbose for all exception
4648 4658 handling.
4649 4659
4650 4660 * Removed ShellServices option. All this can really be done via
4651 4661 the magic system. It's easier to extend, cleaner and has automatic
4652 4662 namespace protection and documentation.
4653 4663
4654 4664 2001-11-09 Fernando Perez <fperez@colorado.edu>
4655 4665
4656 4666 * Fixed bug in output cache flushing (missing parameter to
4657 4667 __init__). Other small bugs fixed (found using pychecker).
4658 4668
4659 4669 * Version 0.1.4 opened for bugfixing.
4660 4670
4661 4671 2001-11-07 Fernando Perez <fperez@colorado.edu>
4662 4672
4663 4673 * Version 0.1.3 released, mainly because of the raw_input bug.
4664 4674
4665 4675 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4666 4676 and when testing for whether things were callable, a call could
4667 4677 actually be made to certain functions. They would get called again
4668 4678 once 'really' executed, with a resulting double call. A disaster
4669 4679 in many cases (list.reverse() would never work!).
4670 4680
4671 4681 * Removed prefilter() function, moved its code to raw_input (which
4672 4682 after all was just a near-empty caller for prefilter). This saves
4673 4683 a function call on every prompt, and simplifies the class a tiny bit.
4674 4684
4675 4685 * Fix _ip to __ip name in magic example file.
4676 4686
4677 4687 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4678 4688 work with non-gnu versions of tar.
4679 4689
4680 4690 2001-11-06 Fernando Perez <fperez@colorado.edu>
4681 4691
4682 4692 * Version 0.1.2. Just to keep track of the recent changes.
4683 4693
4684 4694 * Fixed nasty bug in output prompt routine. It used to check 'if
4685 4695 arg != None...'. Problem is, this fails if arg implements a
4686 4696 special comparison (__cmp__) which disallows comparing to
4687 4697 None. Found it when trying to use the PhysicalQuantity module from
4688 4698 ScientificPython.
4689 4699
4690 4700 2001-11-05 Fernando Perez <fperez@colorado.edu>
4691 4701
4692 4702 * Also added dirs. Now the pushd/popd/dirs family functions
4693 4703 basically like the shell, with the added convenience of going home
4694 4704 when called with no args.
4695 4705
4696 4706 * pushd/popd slightly modified to mimic shell behavior more
4697 4707 closely.
4698 4708
4699 4709 * Added env,pushd,popd from ShellServices as magic functions. I
4700 4710 think the cleanest will be to port all desired functions from
4701 4711 ShellServices as magics and remove ShellServices altogether. This
4702 4712 will provide a single, clean way of adding functionality
4703 4713 (shell-type or otherwise) to IP.
4704 4714
4705 4715 2001-11-04 Fernando Perez <fperez@colorado.edu>
4706 4716
4707 4717 * Added .ipython/ directory to sys.path. This way users can keep
4708 4718 customizations there and access them via import.
4709 4719
4710 4720 2001-11-03 Fernando Perez <fperez@colorado.edu>
4711 4721
4712 4722 * Opened version 0.1.1 for new changes.
4713 4723
4714 4724 * Changed version number to 0.1.0: first 'public' release, sent to
4715 4725 Nathan and Janko.
4716 4726
4717 4727 * Lots of small fixes and tweaks.
4718 4728
4719 4729 * Minor changes to whos format. Now strings are shown, snipped if
4720 4730 too long.
4721 4731
4722 4732 * Changed ShellServices to work on __main__ so they show up in @who
4723 4733
4724 4734 * Help also works with ? at the end of a line:
4725 4735 ?sin and sin?
4726 4736 both produce the same effect. This is nice, as often I use the
4727 4737 tab-complete to find the name of a method, but I used to then have
4728 4738 to go to the beginning of the line to put a ? if I wanted more
4729 4739 info. Now I can just add the ? and hit return. Convenient.
4730 4740
4731 4741 2001-11-02 Fernando Perez <fperez@colorado.edu>
4732 4742
4733 4743 * Python version check (>=2.1) added.
4734 4744
4735 4745 * Added LazyPython documentation. At this point the docs are quite
4736 4746 a mess. A cleanup is in order.
4737 4747
4738 4748 * Auto-installer created. For some bizarre reason, the zipfiles
4739 4749 module isn't working on my system. So I made a tar version
4740 4750 (hopefully the command line options in various systems won't kill
4741 4751 me).
4742 4752
4743 4753 * Fixes to Struct in genutils. Now all dictionary-like methods are
4744 4754 protected (reasonably).
4745 4755
4746 4756 * Added pager function to genutils and changed ? to print usage
4747 4757 note through it (it was too long).
4748 4758
4749 4759 * Added the LazyPython functionality. Works great! I changed the
4750 4760 auto-quote escape to ';', it's on home row and next to '. But
4751 4761 both auto-quote and auto-paren (still /) escapes are command-line
4752 4762 parameters.
4753 4763
4754 4764
4755 4765 2001-11-01 Fernando Perez <fperez@colorado.edu>
4756 4766
4757 4767 * Version changed to 0.0.7. Fairly large change: configuration now
4758 4768 is all stored in a directory, by default .ipython. There, all
4759 4769 config files have normal looking names (not .names)
4760 4770
4761 4771 * Version 0.0.6 Released first to Lucas and Archie as a test
4762 4772 run. Since it's the first 'semi-public' release, change version to
4763 4773 > 0.0.6 for any changes now.
4764 4774
4765 4775 * Stuff I had put in the ipplib.py changelog:
4766 4776
4767 4777 Changes to InteractiveShell:
4768 4778
4769 4779 - Made the usage message a parameter.
4770 4780
4771 4781 - Require the name of the shell variable to be given. It's a bit
4772 4782 of a hack, but allows the name 'shell' not to be hardwire in the
4773 4783 magic (@) handler, which is problematic b/c it requires
4774 4784 polluting the global namespace with 'shell'. This in turn is
4775 4785 fragile: if a user redefines a variable called shell, things
4776 4786 break.
4777 4787
4778 4788 - magic @: all functions available through @ need to be defined
4779 4789 as magic_<name>, even though they can be called simply as
4780 4790 @<name>. This allows the special command @magic to gather
4781 4791 information automatically about all existing magic functions,
4782 4792 even if they are run-time user extensions, by parsing the shell
4783 4793 instance __dict__ looking for special magic_ names.
4784 4794
4785 4795 - mainloop: added *two* local namespace parameters. This allows
4786 4796 the class to differentiate between parameters which were there
4787 4797 before and after command line initialization was processed. This
4788 4798 way, later @who can show things loaded at startup by the
4789 4799 user. This trick was necessary to make session saving/reloading
4790 4800 really work: ideally after saving/exiting/reloading a session,
4791 4801 *everythin* should look the same, including the output of @who. I
4792 4802 was only able to make this work with this double namespace
4793 4803 trick.
4794 4804
4795 4805 - added a header to the logfile which allows (almost) full
4796 4806 session restoring.
4797 4807
4798 4808 - prepend lines beginning with @ or !, with a and log
4799 4809 them. Why? !lines: may be useful to know what you did @lines:
4800 4810 they may affect session state. So when restoring a session, at
4801 4811 least inform the user of their presence. I couldn't quite get
4802 4812 them to properly re-execute, but at least the user is warned.
4803 4813
4804 4814 * Started ChangeLog.
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now