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