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