##// END OF EJS Templates
_tentative_ fixes to pasting of multiline code with autoindent on. Needs...
fperez -
Show More

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

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