##// END OF EJS Templates
Changes for demos and access to raw history in %macro, %save and %edit....
fperez -
Show More
@@ -1,2765 +1,2804 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 1121 2006-02-01 21:12:20Z vivainio $"""
4 $Id: Magic.py 1126 2006-02-06 02:31:40Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
8 8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 9 #
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #*****************************************************************************
13 13
14 14 #****************************************************************************
15 15 # Modules and globals
16 16
17 17 from IPython import Release
18 18 __author__ = '%s <%s>\n%s <%s>' % \
19 19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
20 20 __license__ = Release.license
21 21
22 22 # Python standard modules
23 23 import __builtin__
24 24 import bdb
25 25 import inspect
26 26 import os
27 27 import pdb
28 28 import pydoc
29 29 import sys
30 30 import re
31 31 import tempfile
32 32 import time
33 33 import cPickle as pickle
34 34 import textwrap
35 35 from cStringIO import StringIO
36 36 from getopt import getopt,GetoptError
37 37 from pprint import pprint, pformat
38 38
39 39 # profile isn't bundled by default in Debian for license reasons
40 40 try:
41 41 import profile,pstats
42 42 except ImportError:
43 43 profile = pstats = None
44 44
45 45 # Homebrewed
46 46 from IPython import Debugger, OInspect, wildcard
47 47 from IPython.FakeModule import FakeModule
48 48 from IPython.Itpl import Itpl, itpl, printpl,itplns
49 49 from IPython.PyColorize import Parser
50 50 from IPython.ipstruct import Struct
51 51 from IPython.macro import Macro
52 52 from IPython.genutils import *
53 53 from IPython import platutils
54 54
55 55 #***************************************************************************
56 56 # Utility functions
57 57 def on_off(tag):
58 58 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
59 59 return ['OFF','ON'][tag]
60 60
61 61 class Bunch: pass
62 62
63 63 #***************************************************************************
64 64 # Main class implementing Magic functionality
65 65 class Magic:
66 66 """Magic functions for InteractiveShell.
67 67
68 68 Shell functions which can be reached as %function_name. All magic
69 69 functions should accept a string, which they can parse for their own
70 70 needs. This can make some functions easier to type, eg `%cd ../`
71 71 vs. `%cd("../")`
72 72
73 73 ALL definitions MUST begin with the prefix magic_. The user won't need it
74 74 at the command line, but it is is needed in the definition. """
75 75
76 76 # class globals
77 77 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
78 78 'Automagic is ON, % prefix NOT needed for magic functions.']
79 79
80 80 #......................................................................
81 81 # some utility functions
82 82
83 83 def __init__(self,shell):
84 84
85 85 self.options_table = {}
86 86 if profile is None:
87 87 self.magic_prun = self.profile_missing_notice
88 88 self.shell = shell
89 89
90 90 # namespace for holding state we may need
91 91 self._magic_state = Bunch()
92 92
93 93 def profile_missing_notice(self, *args, **kwargs):
94 94 error("""\
95 95 The profile module could not be found. If you are a Debian user,
96 96 it has been removed from the standard Debian package because of its non-free
97 97 license. To use profiling, please install"python2.3-profiler" from non-free.""")
98 98
99 99 def default_option(self,fn,optstr):
100 100 """Make an entry in the options_table for fn, with value optstr"""
101
101
102 102 if fn not in self.lsmagic():
103 103 error("%s is not a magic function" % fn)
104 104 self.options_table[fn] = optstr
105 105
106 106 def lsmagic(self):
107 107 """Return a list of currently available magic functions.
108 108
109 109 Gives a list of the bare names after mangling (['ls','cd', ...], not
110 110 ['magic_ls','magic_cd',...]"""
111 111
112 112 # FIXME. This needs a cleanup, in the way the magics list is built.
113 113
114 114 # magics in class definition
115 115 class_magic = lambda fn: fn.startswith('magic_') and \
116 116 callable(Magic.__dict__[fn])
117 117 # in instance namespace (run-time user additions)
118 118 inst_magic = lambda fn: fn.startswith('magic_') and \
119 119 callable(self.__dict__[fn])
120 120 # and bound magics by user (so they can access self):
121 121 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
122 122 callable(self.__class__.__dict__[fn])
123 123 magics = filter(class_magic,Magic.__dict__.keys()) + \
124 124 filter(inst_magic,self.__dict__.keys()) + \
125 125 filter(inst_bound_magic,self.__class__.__dict__.keys())
126 126 out = []
127 127 for fn in magics:
128 128 out.append(fn.replace('magic_','',1))
129 129 out.sort()
130 130 return out
131 131
132 def extract_input_slices(self,slices):
132 def extract_input_slices(self,slices,raw=False):
133 133 """Return as a string a set of input history slices.
134 134
135 The set of slices is given as a list of strings (like ['1','4:8','9'],
136 since this function is for use by magic functions which get their
137 arguments as strings.
135 Inputs:
136
137 - slices: the set of slices is given as a list of strings (like
138 ['1','4:8','9'], since this function is for use by magic functions
139 which get their arguments as strings.
140
141 Optional inputs:
142
143 - raw(False): by default, the processed input is used. If this is
144 true, the raw input history is used instead.
138 145
139 146 Note that slices can be called with two notations:
140 147
141 148 N:M -> standard python form, means including items N...(M-1).
142 149
143 150 N-M -> include items N..M (closed endpoint)."""
144 151
152 if raw:
153 hist = self.shell.input_hist_raw
154 else:
155 hist = self.shell.input_hist
156
145 157 cmds = []
146 158 for chunk in slices:
147 159 if ':' in chunk:
148 160 ini,fin = map(int,chunk.split(':'))
149 161 elif '-' in chunk:
150 162 ini,fin = map(int,chunk.split('-'))
151 163 fin += 1
152 164 else:
153 165 ini = int(chunk)
154 166 fin = ini+1
155 cmds.append(self.shell.input_hist[ini:fin])
167 cmds.append(hist[ini:fin])
156 168 return cmds
157 169
158 170 def _ofind(self,oname):
159 171 """Find an object in the available namespaces.
160 172
161 173 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
162 174
163 175 Has special code to detect magic functions.
164 176 """
165 177
166 178 oname = oname.strip()
167 179
168 180 # Namespaces to search in:
169 181 user_ns = self.shell.user_ns
170 182 internal_ns = self.shell.internal_ns
171 183 builtin_ns = __builtin__.__dict__
172 184 alias_ns = self.shell.alias_table
173 185
174 186 # Put them in a list. The order is important so that we find things in
175 187 # the same order that Python finds them.
176 188 namespaces = [ ('Interactive',user_ns),
177 189 ('IPython internal',internal_ns),
178 190 ('Python builtin',builtin_ns),
179 191 ('Alias',alias_ns),
180 192 ]
181 193
182 194 # initialize results to 'null'
183 195 found = 0; obj = None; ospace = None; ds = None;
184 196 ismagic = 0; isalias = 0
185 197
186 198 # Look for the given name by splitting it in parts. If the head is
187 199 # found, then we look for all the remaining parts as members, and only
188 200 # declare success if we can find them all.
189 201 oname_parts = oname.split('.')
190 202 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
191 203 for nsname,ns in namespaces:
192 204 try:
193 205 obj = ns[oname_head]
194 206 except KeyError:
195 207 continue
196 208 else:
197 209 for part in oname_rest:
198 210 try:
199 211 obj = getattr(obj,part)
200 212 except:
201 213 # Blanket except b/c some badly implemented objects
202 214 # allow __getattr__ to raise exceptions other than
203 215 # AttributeError, which then crashes IPython.
204 216 break
205 217 else:
206 218 # If we finish the for loop (no break), we got all members
207 219 found = 1
208 220 ospace = nsname
209 221 if ns == alias_ns:
210 222 isalias = 1
211 223 break # namespace loop
212 224
213 225 # Try to see if it's magic
214 226 if not found:
215 227 if oname.startswith(self.shell.ESC_MAGIC):
216 228 oname = oname[1:]
217 229 obj = getattr(self,'magic_'+oname,None)
218 230 if obj is not None:
219 231 found = 1
220 232 ospace = 'IPython internal'
221 233 ismagic = 1
222 234
223 235 # Last try: special-case some literals like '', [], {}, etc:
224 236 if not found and oname_head in ["''",'""','[]','{}','()']:
225 237 obj = eval(oname_head)
226 238 found = 1
227 239 ospace = 'Interactive'
228 240
229 241 return {'found':found, 'obj':obj, 'namespace':ospace,
230 242 'ismagic':ismagic, 'isalias':isalias}
231 243
232 244 def arg_err(self,func):
233 245 """Print docstring if incorrect arguments were passed"""
234 246 print 'Error in arguments:'
235 247 print OInspect.getdoc(func)
236 248
237 249 def format_latex(self,strng):
238 250 """Format a string for latex inclusion."""
239 251
240 252 # Characters that need to be escaped for latex:
241 253 escape_re = re.compile(r'(%|_|\$|#)',re.MULTILINE)
242 254 # Magic command names as headers:
243 255 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
244 256 re.MULTILINE)
245 257 # Magic commands
246 258 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
247 259 re.MULTILINE)
248 260 # Paragraph continue
249 261 par_re = re.compile(r'\\$',re.MULTILINE)
250 262
251 263 # The "\n" symbol
252 264 newline_re = re.compile(r'\\n')
253 265
254 266 # Now build the string for output:
255 267 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
256 268 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
257 269 strng)
258 270 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
259 271 strng = par_re.sub(r'\\\\',strng)
260 272 strng = escape_re.sub(r'\\\1',strng)
261 273 strng = newline_re.sub(r'\\textbackslash{}n',strng)
262 274 return strng
263 275
264 276 def format_screen(self,strng):
265 277 """Format a string for screen printing.
266 278
267 279 This removes some latex-type format codes."""
268 280 # Paragraph continue
269 281 par_re = re.compile(r'\\$',re.MULTILINE)
270 282 strng = par_re.sub('',strng)
271 283 return strng
272 284
273 285 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
274 286 """Parse options passed to an argument string.
275 287
276 288 The interface is similar to that of getopt(), but it returns back a
277 289 Struct with the options as keys and the stripped argument string still
278 290 as a string.
279 291
280 292 arg_str is quoted as a true sys.argv vector by using shlex.split.
281 293 This allows us to easily expand variables, glob files, quote
282 294 arguments, etc.
283 295
284 296 Options:
285 297 -mode: default 'string'. If given as 'list', the argument string is
286 298 returned as a list (split on whitespace) instead of a string.
287 299
288 300 -list_all: put all option values in lists. Normally only options
289 301 appearing more than once are put in a list."""
290 302
291 303 # inject default options at the beginning of the input line
292 304 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
293 305 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
294 306
295 307 mode = kw.get('mode','string')
296 308 if mode not in ['string','list']:
297 309 raise ValueError,'incorrect mode given: %s' % mode
298 310 # Get options
299 311 list_all = kw.get('list_all',0)
300 312
301 313 # Check if we have more than one argument to warrant extra processing:
302 314 odict = {} # Dictionary with options
303 315 args = arg_str.split()
304 316 if len(args) >= 1:
305 317 # If the list of inputs only has 0 or 1 thing in it, there's no
306 318 # need to look for options
307 319 argv = shlex_split(arg_str)
308 320 # Do regular option processing
309 321 try:
310 322 opts,args = getopt(argv,opt_str,*long_opts)
311 323 except GetoptError,e:
312 324 raise GetoptError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
313 325 " ".join(long_opts)))
314 326 for o,a in opts:
315 327 if o.startswith('--'):
316 328 o = o[2:]
317 329 else:
318 330 o = o[1:]
319 331 try:
320 332 odict[o].append(a)
321 333 except AttributeError:
322 334 odict[o] = [odict[o],a]
323 335 except KeyError:
324 336 if list_all:
325 337 odict[o] = [a]
326 338 else:
327 339 odict[o] = a
328 340
329 341 # Prepare opts,args for return
330 342 opts = Struct(odict)
331 343 if mode == 'string':
332 344 args = ' '.join(args)
333 345
334 346 return opts,args
335 347
336 348 #......................................................................
337 349 # And now the actual magic functions
338 350
339 351 # Functions for IPython shell work (vars,funcs, config, etc)
340 352 def magic_lsmagic(self, parameter_s = ''):
341 353 """List currently available magic functions."""
342 354 mesc = self.shell.ESC_MAGIC
343 355 print 'Available magic functions:\n'+mesc+\
344 356 (' '+mesc).join(self.lsmagic())
345 357 print '\n' + Magic.auto_status[self.shell.rc.automagic]
346 358 return None
347 359
348 360 def magic_magic(self, parameter_s = ''):
349 361 """Print information about the magic function system."""
350 362
351 363 mode = ''
352 364 try:
353 365 if parameter_s.split()[0] == '-latex':
354 366 mode = 'latex'
355 367 except:
356 368 pass
357 369
358 370 magic_docs = []
359 371 for fname in self.lsmagic():
360 372 mname = 'magic_' + fname
361 373 for space in (Magic,self,self.__class__):
362 374 try:
363 375 fn = space.__dict__[mname]
364 376 except KeyError:
365 377 pass
366 378 else:
367 379 break
368 380 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
369 381 fname,fn.__doc__))
370 382 magic_docs = ''.join(magic_docs)
371 383
372 384 if mode == 'latex':
373 385 print self.format_latex(magic_docs)
374 386 return
375 387 else:
376 388 magic_docs = self.format_screen(magic_docs)
377 389
378 390 outmsg = """
379 391 IPython's 'magic' functions
380 392 ===========================
381 393
382 394 The magic function system provides a series of functions which allow you to
383 395 control the behavior of IPython itself, plus a lot of system-type
384 396 features. All these functions are prefixed with a % character, but parameters
385 397 are given without parentheses or quotes.
386 398
387 399 NOTE: If you have 'automagic' enabled (via the command line option or with the
388 400 %automagic function), you don't need to type in the % explicitly. By default,
389 401 IPython ships with automagic on, so you should only rarely need the % escape.
390 402
391 403 Example: typing '%cd mydir' (without the quotes) changes you working directory
392 404 to 'mydir', if it exists.
393 405
394 406 You can define your own magic functions to extend the system. See the supplied
395 407 ipythonrc and example-magic.py files for details (in your ipython
396 408 configuration directory, typically $HOME/.ipython/).
397 409
398 410 You can also define your own aliased names for magic functions. In your
399 411 ipythonrc file, placing a line like:
400 412
401 413 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
402 414
403 415 will define %pf as a new name for %profile.
404 416
405 417 You can also call magics in code using the ipmagic() function, which IPython
406 418 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
407 419
408 420 For a list of the available magic functions, use %lsmagic. For a description
409 421 of any of them, type %magic_name?, e.g. '%cd?'.
410 422
411 423 Currently the magic system has the following functions:\n"""
412 424
413 425 mesc = self.shell.ESC_MAGIC
414 426 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
415 427 "\n\n%s%s\n\n%s" % (outmsg,
416 428 magic_docs,mesc,mesc,
417 429 (' '+mesc).join(self.lsmagic()),
418 430 Magic.auto_status[self.shell.rc.automagic] ) )
419 431
420 432 page(outmsg,screen_lines=self.shell.rc.screen_length)
421 433
422 434 def magic_automagic(self, parameter_s = ''):
423 435 """Make magic functions callable without having to type the initial %.
424 436
425 437 Toggles on/off (when off, you must call it as %automagic, of
426 438 course). Note that magic functions have lowest priority, so if there's
427 439 a variable whose name collides with that of a magic fn, automagic
428 440 won't work for that function (you get the variable instead). However,
429 441 if you delete the variable (del var), the previously shadowed magic
430 442 function becomes visible to automagic again."""
431 443
432 444 rc = self.shell.rc
433 445 rc.automagic = not rc.automagic
434 446 print '\n' + Magic.auto_status[rc.automagic]
435 447
436 448 def magic_autocall(self, parameter_s = ''):
437 449 """Make functions callable without having to type parentheses.
438 450
439 451 Usage:
440 452
441 453 %autocall [mode]
442 454
443 455 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
444 456 value is toggled on and off (remembering the previous state)."""
445 457
446 458 rc = self.shell.rc
447 459
448 460 if parameter_s:
449 461 arg = int(parameter_s)
450 462 else:
451 463 arg = 'toggle'
452 464
453 465 if not arg in (0,1,2,'toggle'):
454 466 error('Valid modes: (0->Off, 1->Smart, 2->Full')
455 467 return
456 468
457 469 if arg in (0,1,2):
458 470 rc.autocall = arg
459 471 else: # toggle
460 472 if rc.autocall:
461 473 self._magic_state.autocall_save = rc.autocall
462 474 rc.autocall = 0
463 475 else:
464 476 try:
465 477 rc.autocall = self._magic_state.autocall_save
466 478 except AttributeError:
467 479 rc.autocall = self._magic_state.autocall_save = 1
468 480
469 481 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
470 482
471 483 def magic_autoindent(self, parameter_s = ''):
472 484 """Toggle autoindent on/off (if available)."""
473 485
474 486 self.shell.set_autoindent()
475 487 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
476 488
477 489 def magic_system_verbose(self, parameter_s = ''):
478 490 """Toggle verbose printing of system calls on/off."""
479 491
480 492 self.shell.rc_set_toggle('system_verbose')
481 493 print "System verbose printing is:",\
482 494 ['OFF','ON'][self.shell.rc.system_verbose]
483 495
484 496 def magic_history(self, parameter_s = ''):
485 497 """Print input history (_i<n> variables), with most recent last.
486 498
487 499 %history -> print at most 40 inputs (some may be multi-line)\\
488 500 %history n -> print at most n inputs\\
489 501 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
490 502
491 503 Each input's number <n> is shown, and is accessible as the
492 504 automatically generated variable _i<n>. Multi-line statements are
493 505 printed starting at a new line for easy copy/paste.
494 506
495 507
496 508 Options:
497 509
498 510 -n: do NOT print line numbers. This is useful if you want to get a
499 511 printout of many lines which can be directly pasted into a text
500 512 editor.
501 513
502 514 This feature is only available if numbered prompts are in use.
503 515
504 516 -r: print the 'raw' history. IPython filters your input and
505 517 converts it all into valid Python source before executing it (things
506 518 like magics or aliases are turned into function calls, for
507 519 example). With this option, you'll see the unfiltered history
508 520 instead of the filtered version: '%cd /' will be seen as '%cd /'
509 521 instead of '_ip.magic("%cd /")'.
510 522 """
511 523
512 524 shell = self.shell
513 525 if not shell.outputcache.do_full_cache:
514 526 print 'This feature is only available if numbered prompts are in use.'
515 527 return
516 528 opts,args = self.parse_options(parameter_s,'nr',mode='list')
517 529
518 530 if opts.has_key('r'):
519 531 input_hist = shell.input_hist_raw
520 532 else:
521 533 input_hist = shell.input_hist
522 534
523 535 default_length = 40
524 536 if len(args) == 0:
525 537 final = len(input_hist)
526 538 init = max(1,final-default_length)
527 539 elif len(args) == 1:
528 540 final = len(input_hist)
529 541 init = max(1,final-int(args[0]))
530 542 elif len(args) == 2:
531 543 init,final = map(int,args)
532 544 else:
533 545 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
534 546 print self.magic_hist.__doc__
535 547 return
536 548 width = len(str(final))
537 549 line_sep = ['','\n']
538 550 print_nums = not opts.has_key('n')
539 551 for in_num in range(init,final):
540 552 inline = input_hist[in_num]
541 553 multiline = int(inline.count('\n') > 1)
542 554 if print_nums:
543 555 print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
544 556 print inline,
545 557
546 558 def magic_hist(self, parameter_s=''):
547 559 """Alternate name for %history."""
548 560 return self.magic_history(parameter_s)
549 561
550 562 def magic_p(self, parameter_s=''):
551 563 """Just a short alias for Python's 'print'."""
552 564 exec 'print ' + parameter_s in self.shell.user_ns
553 565
554 566 def magic_r(self, parameter_s=''):
555 567 """Repeat previous input.
556 568
557 569 If given an argument, repeats the previous command which starts with
558 570 the same string, otherwise it just repeats the previous input.
559 571
560 572 Shell escaped commands (with ! as first character) are not recognized
561 573 by this system, only pure python code and magic commands.
562 574 """
563 575
564 576 start = parameter_s.strip()
565 577 esc_magic = self.shell.ESC_MAGIC
566 578 # Identify magic commands even if automagic is on (which means
567 579 # the in-memory version is different from that typed by the user).
568 580 if self.shell.rc.automagic:
569 581 start_magic = esc_magic+start
570 582 else:
571 583 start_magic = start
572 584 # Look through the input history in reverse
573 585 for n in range(len(self.shell.input_hist)-2,0,-1):
574 586 input = self.shell.input_hist[n]
575 587 # skip plain 'r' lines so we don't recurse to infinity
576 588 if input != '_ip.magic("r")\n' and \
577 589 (input.startswith(start) or input.startswith(start_magic)):
578 590 #print 'match',`input` # dbg
579 591 print 'Executing:',input,
580 592 self.shell.runlines(input)
581 593 return
582 594 print 'No previous input matching `%s` found.' % start
583 595
584 596 def magic_page(self, parameter_s=''):
585 597 """Pretty print the object and display it through a pager.
586 598
587 599 If no parameter is given, use _ (last output)."""
588 600 # After a function contributed by Olivier Aubert, slightly modified.
589 601
590 602 oname = parameter_s and parameter_s or '_'
591 603 info = self._ofind(oname)
592 604 if info['found']:
593 605 page(pformat(info['obj']))
594 606 else:
595 607 print 'Object `%s` not found' % oname
596 608
597 609 def magic_profile(self, parameter_s=''):
598 610 """Print your currently active IPyhton profile."""
599 611 if self.shell.rc.profile:
600 612 printpl('Current IPython profile: $self.shell.rc.profile.')
601 613 else:
602 614 print 'No profile active.'
603 615
604 616 def _inspect(self,meth,oname,**kw):
605 617 """Generic interface to the inspector system.
606 618
607 619 This function is meant to be called by pdef, pdoc & friends."""
608 620
609 621 oname = oname.strip()
610 622 info = Struct(self._ofind(oname))
611 623 if info.found:
612 624 pmethod = getattr(self.shell.inspector,meth)
613 625 formatter = info.ismagic and self.format_screen or None
614 626 if meth == 'pdoc':
615 627 pmethod(info.obj,oname,formatter)
616 628 elif meth == 'pinfo':
617 629 pmethod(info.obj,oname,formatter,info,**kw)
618 630 else:
619 631 pmethod(info.obj,oname)
620 632 else:
621 633 print 'Object `%s` not found.' % oname
622 634 return 'not found' # so callers can take other action
623 635
624 636 def magic_pdef(self, parameter_s=''):
625 637 """Print the definition header for any callable object.
626 638
627 639 If the object is a class, print the constructor information."""
628 640 self._inspect('pdef',parameter_s)
629 641
630 642 def magic_pdoc(self, parameter_s=''):
631 643 """Print the docstring for an object.
632 644
633 645 If the given object is a class, it will print both the class and the
634 646 constructor docstrings."""
635 647 self._inspect('pdoc',parameter_s)
636 648
637 649 def magic_psource(self, parameter_s=''):
638 650 """Print (or run through pager) the source code for an object."""
639 651 self._inspect('psource',parameter_s)
640 652
641 653 def magic_pfile(self, parameter_s=''):
642 654 """Print (or run through pager) the file where an object is defined.
643 655
644 656 The file opens at the line where the object definition begins. IPython
645 657 will honor the environment variable PAGER if set, and otherwise will
646 658 do its best to print the file in a convenient form.
647 659
648 660 If the given argument is not an object currently defined, IPython will
649 661 try to interpret it as a filename (automatically adding a .py extension
650 662 if needed). You can thus use %pfile as a syntax highlighting code
651 663 viewer."""
652 664
653 665 # first interpret argument as an object name
654 666 out = self._inspect('pfile',parameter_s)
655 667 # if not, try the input as a filename
656 668 if out == 'not found':
657 669 try:
658 670 filename = get_py_filename(parameter_s)
659 671 except IOError,msg:
660 672 print msg
661 673 return
662 674 page(self.shell.inspector.format(file(filename).read()))
663 675
664 676 def magic_pinfo(self, parameter_s=''):
665 677 """Provide detailed information about an object.
666 678
667 679 '%pinfo object' is just a synonym for object? or ?object."""
668 680
669 681 #print 'pinfo par: <%s>' % parameter_s # dbg
670 682
671 683 # detail_level: 0 -> obj? , 1 -> obj??
672 684 detail_level = 0
673 685 # We need to detect if we got called as 'pinfo pinfo foo', which can
674 686 # happen if the user types 'pinfo foo?' at the cmd line.
675 687 pinfo,qmark1,oname,qmark2 = \
676 688 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
677 689 if pinfo or qmark1 or qmark2:
678 690 detail_level = 1
679 691 if "*" in oname:
680 692 self.magic_psearch(oname)
681 693 else:
682 694 self._inspect('pinfo',oname,detail_level=detail_level)
683 695
684 696 def magic_psearch(self, parameter_s=''):
685 697 """Search for object in namespaces by wildcard.
686 698
687 699 %psearch [options] PATTERN [OBJECT TYPE]
688 700
689 701 Note: ? can be used as a synonym for %psearch, at the beginning or at
690 702 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
691 703 rest of the command line must be unchanged (options come first), so
692 704 for example the following forms are equivalent
693 705
694 706 %psearch -i a* function
695 707 -i a* function?
696 708 ?-i a* function
697 709
698 710 Arguments:
699 711
700 712 PATTERN
701 713
702 714 where PATTERN is a string containing * as a wildcard similar to its
703 715 use in a shell. The pattern is matched in all namespaces on the
704 716 search path. By default objects starting with a single _ are not
705 717 matched, many IPython generated objects have a single
706 718 underscore. The default is case insensitive matching. Matching is
707 719 also done on the attributes of objects and not only on the objects
708 720 in a module.
709 721
710 722 [OBJECT TYPE]
711 723
712 724 Is the name of a python type from the types module. The name is
713 725 given in lowercase without the ending type, ex. StringType is
714 726 written string. By adding a type here only objects matching the
715 727 given type are matched. Using all here makes the pattern match all
716 728 types (this is the default).
717 729
718 730 Options:
719 731
720 732 -a: makes the pattern match even objects whose names start with a
721 733 single underscore. These names are normally ommitted from the
722 734 search.
723 735
724 736 -i/-c: make the pattern case insensitive/sensitive. If neither of
725 737 these options is given, the default is read from your ipythonrc
726 738 file. The option name which sets this value is
727 739 'wildcards_case_sensitive'. If this option is not specified in your
728 740 ipythonrc file, IPython's internal default is to do a case sensitive
729 741 search.
730 742
731 743 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
732 744 specifiy can be searched in any of the following namespaces:
733 745 'builtin', 'user', 'user_global','internal', 'alias', where
734 746 'builtin' and 'user' are the search defaults. Note that you should
735 747 not use quotes when specifying namespaces.
736 748
737 749 'Builtin' contains the python module builtin, 'user' contains all
738 750 user data, 'alias' only contain the shell aliases and no python
739 751 objects, 'internal' contains objects used by IPython. The
740 752 'user_global' namespace is only used by embedded IPython instances,
741 753 and it contains module-level globals. You can add namespaces to the
742 754 search with -s or exclude them with -e (these options can be given
743 755 more than once).
744 756
745 757 Examples:
746 758
747 759 %psearch a* -> objects beginning with an a
748 760 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
749 761 %psearch a* function -> all functions beginning with an a
750 762 %psearch re.e* -> objects beginning with an e in module re
751 763 %psearch r*.e* -> objects that start with e in modules starting in r
752 764 %psearch r*.* string -> all strings in modules beginning with r
753 765
754 766 Case sensitve search:
755 767
756 768 %psearch -c a* list all object beginning with lower case a
757 769
758 770 Show objects beginning with a single _:
759 771
760 772 %psearch -a _* list objects beginning with a single underscore"""
761 773
762 774 # default namespaces to be searched
763 775 def_search = ['user','builtin']
764 776
765 777 # Process options/args
766 778 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
767 779 opt = opts.get
768 780 shell = self.shell
769 781 psearch = shell.inspector.psearch
770 782
771 783 # select case options
772 784 if opts.has_key('i'):
773 785 ignore_case = True
774 786 elif opts.has_key('c'):
775 787 ignore_case = False
776 788 else:
777 789 ignore_case = not shell.rc.wildcards_case_sensitive
778 790
779 791 # Build list of namespaces to search from user options
780 792 def_search.extend(opt('s',[]))
781 793 ns_exclude = ns_exclude=opt('e',[])
782 794 ns_search = [nm for nm in def_search if nm not in ns_exclude]
783 795
784 796 # Call the actual search
785 797 try:
786 798 psearch(args,shell.ns_table,ns_search,
787 799 show_all=opt('a'),ignore_case=ignore_case)
788 800 except:
789 801 shell.showtraceback()
790 802
791 803 def magic_who_ls(self, parameter_s=''):
792 804 """Return a sorted list of all interactive variables.
793 805
794 806 If arguments are given, only variables of types matching these
795 807 arguments are returned."""
796 808
797 809 user_ns = self.shell.user_ns
798 810 internal_ns = self.shell.internal_ns
799 811 user_config_ns = self.shell.user_config_ns
800 812 out = []
801 813 typelist = parameter_s.split()
802 814
803 815 for i in user_ns:
804 816 if not (i.startswith('_') or i.startswith('_i')) \
805 817 and not (i in internal_ns or i in user_config_ns):
806 818 if typelist:
807 819 if type(user_ns[i]).__name__ in typelist:
808 820 out.append(i)
809 821 else:
810 822 out.append(i)
811 823 out.sort()
812 824 return out
813 825
814 826 def magic_who(self, parameter_s=''):
815 827 """Print all interactive variables, with some minimal formatting.
816 828
817 829 If any arguments are given, only variables whose type matches one of
818 830 these are printed. For example:
819 831
820 832 %who function str
821 833
822 834 will only list functions and strings, excluding all other types of
823 835 variables. To find the proper type names, simply use type(var) at a
824 836 command line to see how python prints type names. For example:
825 837
826 838 In [1]: type('hello')\\
827 839 Out[1]: <type 'str'>
828 840
829 841 indicates that the type name for strings is 'str'.
830 842
831 843 %who always excludes executed names loaded through your configuration
832 844 file and things which are internal to IPython.
833 845
834 846 This is deliberate, as typically you may load many modules and the
835 847 purpose of %who is to show you only what you've manually defined."""
836 848
837 849 varlist = self.magic_who_ls(parameter_s)
838 850 if not varlist:
839 851 print 'Interactive namespace is empty.'
840 852 return
841 853
842 854 # if we have variables, move on...
843 855
844 856 # stupid flushing problem: when prompts have no separators, stdout is
845 857 # getting lost. I'm starting to think this is a python bug. I'm having
846 858 # to force a flush with a print because even a sys.stdout.flush
847 859 # doesn't seem to do anything!
848 860
849 861 count = 0
850 862 for i in varlist:
851 863 print i+'\t',
852 864 count += 1
853 865 if count > 8:
854 866 count = 0
855 867 print
856 868 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
857 869
858 870 print # well, this does force a flush at the expense of an extra \n
859 871
860 872 def magic_whos(self, parameter_s=''):
861 873 """Like %who, but gives some extra information about each variable.
862 874
863 875 The same type filtering of %who can be applied here.
864 876
865 877 For all variables, the type is printed. Additionally it prints:
866 878
867 879 - For {},[],(): their length.
868 880
869 881 - For Numeric arrays, a summary with shape, number of elements,
870 882 typecode and size in memory.
871 883
872 884 - Everything else: a string representation, snipping their middle if
873 885 too long."""
874 886
875 887 varnames = self.magic_who_ls(parameter_s)
876 888 if not varnames:
877 889 print 'Interactive namespace is empty.'
878 890 return
879 891
880 892 # if we have variables, move on...
881 893
882 894 # for these types, show len() instead of data:
883 895 seq_types = [types.DictType,types.ListType,types.TupleType]
884 896
885 897 # for Numeric arrays, display summary info
886 898 try:
887 899 import Numeric
888 900 except ImportError:
889 901 array_type = None
890 902 else:
891 903 array_type = Numeric.ArrayType.__name__
892 904
893 905 # Find all variable names and types so we can figure out column sizes
894 906 get_vars = lambda i: self.shell.user_ns[i]
895 907 type_name = lambda v: type(v).__name__
896 908 varlist = map(get_vars,varnames)
897 909
898 910 typelist = []
899 911 for vv in varlist:
900 912 tt = type_name(vv)
901 913 if tt=='instance':
902 914 typelist.append(str(vv.__class__))
903 915 else:
904 916 typelist.append(tt)
905 917
906 918 # column labels and # of spaces as separator
907 919 varlabel = 'Variable'
908 920 typelabel = 'Type'
909 921 datalabel = 'Data/Info'
910 922 colsep = 3
911 923 # variable format strings
912 924 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
913 925 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
914 926 aformat = "%s: %s elems, type `%s`, %s bytes"
915 927 # find the size of the columns to format the output nicely
916 928 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
917 929 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
918 930 # table header
919 931 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
920 932 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
921 933 # and the table itself
922 934 kb = 1024
923 935 Mb = 1048576 # kb**2
924 936 for vname,var,vtype in zip(varnames,varlist,typelist):
925 937 print itpl(vformat),
926 938 if vtype in seq_types:
927 939 print len(var)
928 940 elif vtype==array_type:
929 941 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
930 942 vsize = Numeric.size(var)
931 943 vbytes = vsize*var.itemsize()
932 944 if vbytes < 100000:
933 945 print aformat % (vshape,vsize,var.typecode(),vbytes)
934 946 else:
935 947 print aformat % (vshape,vsize,var.typecode(),vbytes),
936 948 if vbytes < Mb:
937 949 print '(%s kb)' % (vbytes/kb,)
938 950 else:
939 951 print '(%s Mb)' % (vbytes/Mb,)
940 952 else:
941 953 vstr = str(var).replace('\n','\\n')
942 954 if len(vstr) < 50:
943 955 print vstr
944 956 else:
945 957 printpl(vfmt_short)
946 958
947 959 def magic_reset(self, parameter_s=''):
948 960 """Resets the namespace by removing all names defined by the user.
949 961
950 962 Input/Output history are left around in case you need them."""
951 963
952 964 ans = raw_input(
953 965 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
954 966 if not ans.lower() == 'y':
955 967 print 'Nothing done.'
956 968 return
957 969 user_ns = self.shell.user_ns
958 970 for i in self.magic_who_ls():
959 971 del(user_ns[i])
960 972
961 973 def magic_config(self,parameter_s=''):
962 974 """Show IPython's internal configuration."""
963 975
964 976 page('Current configuration structure:\n'+
965 977 pformat(self.shell.rc.dict()))
966 978
967 979 def magic_logstart(self,parameter_s=''):
968 980 """Start logging anywhere in a session.
969 981
970 982 %logstart [-o|-t] [log_name [log_mode]]
971 983
972 984 If no name is given, it defaults to a file named 'ipython_log.py' in your
973 985 current directory, in 'rotate' mode (see below).
974 986
975 987 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
976 988 history up to that point and then continues logging.
977 989
978 990 %logstart takes a second optional parameter: logging mode. This can be one
979 991 of (note that the modes are given unquoted):\\
980 992 append: well, that says it.\\
981 993 backup: rename (if exists) to name~ and start name.\\
982 994 global: single logfile in your home dir, appended to.\\
983 995 over : overwrite existing log.\\
984 996 rotate: create rotating logs name.1~, name.2~, etc.
985 997
986 998 Options:
987 999
988 1000 -o: log also IPython's output. In this mode, all commands which
989 1001 generate an Out[NN] prompt are recorded to the logfile, right after
990 1002 their corresponding input line. The output lines are always
991 1003 prepended with a '#[Out]# ' marker, so that the log remains valid
992 1004 Python code.
993 1005
994 1006 Since this marker is always the same, filtering only the output from
995 1007 a log is very easy, using for example a simple awk call:
996 1008
997 1009 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
998 1010
999 1011 -t: put timestamps before each input line logged (these are put in
1000 1012 comments)."""
1001 1013
1002 1014 opts,par = self.parse_options(parameter_s,'ot')
1003 1015 log_output = 'o' in opts
1004 1016 timestamp = 't' in opts
1005 1017
1006 1018 rc = self.shell.rc
1007 1019 logger = self.shell.logger
1008 1020
1009 1021 # if no args are given, the defaults set in the logger constructor by
1010 1022 # ipytohn remain valid
1011 1023 if par:
1012 1024 try:
1013 1025 logfname,logmode = par.split()
1014 1026 except:
1015 1027 logfname = par
1016 1028 logmode = 'backup'
1017 1029 else:
1018 1030 logfname = logger.logfname
1019 1031 logmode = logger.logmode
1020 1032 # put logfname into rc struct as if it had been called on the command
1021 1033 # line, so it ends up saved in the log header Save it in case we need
1022 1034 # to restore it...
1023 1035 old_logfile = rc.opts.get('logfile','')
1024 1036 if logfname:
1025 1037 logfname = os.path.expanduser(logfname)
1026 1038 rc.opts.logfile = logfname
1027 1039 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
1028 1040 try:
1029 1041 started = logger.logstart(logfname,loghead,logmode,
1030 1042 log_output,timestamp)
1031 1043 except:
1032 1044 rc.opts.logfile = old_logfile
1033 1045 warn("Couldn't start log: %s" % sys.exc_info()[1])
1034 1046 else:
1035 1047 # log input history up to this point, optionally interleaving
1036 1048 # output if requested
1037 1049
1038 1050 if timestamp:
1039 1051 # disable timestamping for the previous history, since we've
1040 1052 # lost those already (no time machine here).
1041 1053 logger.timestamp = False
1042 1054 if log_output:
1043 1055 log_write = logger.log_write
1044 1056 input_hist = self.shell.input_hist
1045 1057 output_hist = self.shell.output_hist
1046 1058 for n in range(1,len(input_hist)-1):
1047 1059 log_write(input_hist[n].rstrip())
1048 1060 if n in output_hist:
1049 1061 log_write(repr(output_hist[n]),'output')
1050 1062 else:
1051 1063 logger.log_write(self.shell.input_hist[1:])
1052 1064 if timestamp:
1053 1065 # re-enable timestamping
1054 1066 logger.timestamp = True
1055 1067
1056 1068 print ('Activating auto-logging. '
1057 1069 'Current session state plus future input saved.')
1058 1070 logger.logstate()
1059 1071
1060 1072 def magic_logoff(self,parameter_s=''):
1061 1073 """Temporarily stop logging.
1062 1074
1063 1075 You must have previously started logging."""
1064 1076 self.shell.logger.switch_log(0)
1065 1077
1066 1078 def magic_logon(self,parameter_s=''):
1067 1079 """Restart logging.
1068 1080
1069 1081 This function is for restarting logging which you've temporarily
1070 1082 stopped with %logoff. For starting logging for the first time, you
1071 1083 must use the %logstart function, which allows you to specify an
1072 1084 optional log filename."""
1073 1085
1074 1086 self.shell.logger.switch_log(1)
1075 1087
1076 1088 def magic_logstate(self,parameter_s=''):
1077 1089 """Print the status of the logging system."""
1078 1090
1079 1091 self.shell.logger.logstate()
1080 1092
1081 1093 def magic_pdb(self, parameter_s=''):
1082 1094 """Control the calling of the pdb interactive debugger.
1083 1095
1084 1096 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1085 1097 argument it works as a toggle.
1086 1098
1087 1099 When an exception is triggered, IPython can optionally call the
1088 1100 interactive pdb debugger after the traceback printout. %pdb toggles
1089 1101 this feature on and off."""
1090 1102
1091 1103 par = parameter_s.strip().lower()
1092 1104
1093 1105 if par:
1094 1106 try:
1095 1107 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1096 1108 except KeyError:
1097 1109 print ('Incorrect argument. Use on/1, off/0, '
1098 1110 'or nothing for a toggle.')
1099 1111 return
1100 1112 else:
1101 1113 # toggle
1102 1114 new_pdb = not self.shell.InteractiveTB.call_pdb
1103 1115
1104 1116 # set on the shell
1105 1117 self.shell.call_pdb = new_pdb
1106 1118 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1107 1119
1108 1120 def magic_prun(self, parameter_s ='',user_mode=1,
1109 1121 opts=None,arg_lst=None,prog_ns=None):
1110 1122
1111 1123 """Run a statement through the python code profiler.
1112 1124
1113 1125 Usage:\\
1114 1126 %prun [options] statement
1115 1127
1116 1128 The given statement (which doesn't require quote marks) is run via the
1117 1129 python profiler in a manner similar to the profile.run() function.
1118 1130 Namespaces are internally managed to work correctly; profile.run
1119 1131 cannot be used in IPython because it makes certain assumptions about
1120 1132 namespaces which do not hold under IPython.
1121 1133
1122 1134 Options:
1123 1135
1124 1136 -l <limit>: you can place restrictions on what or how much of the
1125 1137 profile gets printed. The limit value can be:
1126 1138
1127 1139 * A string: only information for function names containing this string
1128 1140 is printed.
1129 1141
1130 1142 * An integer: only these many lines are printed.
1131 1143
1132 1144 * A float (between 0 and 1): this fraction of the report is printed
1133 1145 (for example, use a limit of 0.4 to see the topmost 40% only).
1134 1146
1135 1147 You can combine several limits with repeated use of the option. For
1136 1148 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1137 1149 information about class constructors.
1138 1150
1139 1151 -r: return the pstats.Stats object generated by the profiling. This
1140 1152 object has all the information about the profile in it, and you can
1141 1153 later use it for further analysis or in other functions.
1142 1154
1143 1155 Since magic functions have a particular form of calling which prevents
1144 1156 you from writing something like:\\
1145 1157 In [1]: p = %prun -r print 4 # invalid!\\
1146 1158 you must instead use IPython's automatic variables to assign this:\\
1147 1159 In [1]: %prun -r print 4 \\
1148 1160 Out[1]: <pstats.Stats instance at 0x8222cec>\\
1149 1161 In [2]: stats = _
1150 1162
1151 1163 If you really need to assign this value via an explicit function call,
1152 1164 you can always tap directly into the true name of the magic function
1153 1165 by using the _ip.magic function:\\
1154 1166 In [3]: stats = _ip.magic('prun','-r print 4')
1155 1167
1156 1168 You can type _ip.magic? for more details.
1157 1169
1158 1170 -s <key>: sort profile by given key. You can provide more than one key
1159 1171 by using the option several times: '-s key1 -s key2 -s key3...'. The
1160 1172 default sorting key is 'time'.
1161 1173
1162 1174 The following is copied verbatim from the profile documentation
1163 1175 referenced below:
1164 1176
1165 1177 When more than one key is provided, additional keys are used as
1166 1178 secondary criteria when the there is equality in all keys selected
1167 1179 before them.
1168 1180
1169 1181 Abbreviations can be used for any key names, as long as the
1170 1182 abbreviation is unambiguous. The following are the keys currently
1171 1183 defined:
1172 1184
1173 1185 Valid Arg Meaning\\
1174 1186 "calls" call count\\
1175 1187 "cumulative" cumulative time\\
1176 1188 "file" file name\\
1177 1189 "module" file name\\
1178 1190 "pcalls" primitive call count\\
1179 1191 "line" line number\\
1180 1192 "name" function name\\
1181 1193 "nfl" name/file/line\\
1182 1194 "stdname" standard name\\
1183 1195 "time" internal time
1184 1196
1185 1197 Note that all sorts on statistics are in descending order (placing
1186 1198 most time consuming items first), where as name, file, and line number
1187 1199 searches are in ascending order (i.e., alphabetical). The subtle
1188 1200 distinction between "nfl" and "stdname" is that the standard name is a
1189 1201 sort of the name as printed, which means that the embedded line
1190 1202 numbers get compared in an odd way. For example, lines 3, 20, and 40
1191 1203 would (if the file names were the same) appear in the string order
1192 1204 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1193 1205 line numbers. In fact, sort_stats("nfl") is the same as
1194 1206 sort_stats("name", "file", "line").
1195 1207
1196 1208 -T <filename>: save profile results as shown on screen to a text
1197 1209 file. The profile is still shown on screen.
1198 1210
1199 1211 -D <filename>: save (via dump_stats) profile statistics to given
1200 1212 filename. This data is in a format understod by the pstats module, and
1201 1213 is generated by a call to the dump_stats() method of profile
1202 1214 objects. The profile is still shown on screen.
1203 1215
1204 1216 If you want to run complete programs under the profiler's control, use
1205 1217 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1206 1218 contains profiler specific options as described here.
1207 1219
1208 1220 You can read the complete documentation for the profile module with:\\
1209 1221 In [1]: import profile; profile.help() """
1210 1222
1211 1223 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1212 1224 # protect user quote marks
1213 1225 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1214 1226
1215 1227 if user_mode: # regular user call
1216 1228 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1217 1229 list_all=1)
1218 1230 namespace = self.shell.user_ns
1219 1231 else: # called to run a program by %run -p
1220 1232 try:
1221 1233 filename = get_py_filename(arg_lst[0])
1222 1234 except IOError,msg:
1223 1235 error(msg)
1224 1236 return
1225 1237
1226 1238 arg_str = 'execfile(filename,prog_ns)'
1227 1239 namespace = locals()
1228 1240
1229 1241 opts.merge(opts_def)
1230 1242
1231 1243 prof = profile.Profile()
1232 1244 try:
1233 1245 prof = prof.runctx(arg_str,namespace,namespace)
1234 1246 sys_exit = ''
1235 1247 except SystemExit:
1236 1248 sys_exit = """*** SystemExit exception caught in code being profiled."""
1237 1249
1238 1250 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1239 1251
1240 1252 lims = opts.l
1241 1253 if lims:
1242 1254 lims = [] # rebuild lims with ints/floats/strings
1243 1255 for lim in opts.l:
1244 1256 try:
1245 1257 lims.append(int(lim))
1246 1258 except ValueError:
1247 1259 try:
1248 1260 lims.append(float(lim))
1249 1261 except ValueError:
1250 1262 lims.append(lim)
1251 1263
1252 1264 # trap output
1253 1265 sys_stdout = sys.stdout
1254 1266 stdout_trap = StringIO()
1255 1267 try:
1256 1268 sys.stdout = stdout_trap
1257 1269 stats.print_stats(*lims)
1258 1270 finally:
1259 1271 sys.stdout = sys_stdout
1260 1272 output = stdout_trap.getvalue()
1261 1273 output = output.rstrip()
1262 1274
1263 1275 page(output,screen_lines=self.shell.rc.screen_length)
1264 1276 print sys_exit,
1265 1277
1266 1278 dump_file = opts.D[0]
1267 1279 text_file = opts.T[0]
1268 1280 if dump_file:
1269 1281 prof.dump_stats(dump_file)
1270 1282 print '\n*** Profile stats marshalled to file',\
1271 1283 `dump_file`+'.',sys_exit
1272 1284 if text_file:
1273 1285 file(text_file,'w').write(output)
1274 1286 print '\n*** Profile printout saved to text file',\
1275 1287 `text_file`+'.',sys_exit
1276 1288
1277 1289 if opts.has_key('r'):
1278 1290 return stats
1279 1291 else:
1280 1292 return None
1281 1293
1282 1294 def magic_run(self, parameter_s ='',runner=None):
1283 1295 """Run the named file inside IPython as a program.
1284 1296
1285 1297 Usage:\\
1286 1298 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1287 1299
1288 1300 Parameters after the filename are passed as command-line arguments to
1289 1301 the program (put in sys.argv). Then, control returns to IPython's
1290 1302 prompt.
1291 1303
1292 1304 This is similar to running at a system prompt:\\
1293 1305 $ python file args\\
1294 1306 but with the advantage of giving you IPython's tracebacks, and of
1295 1307 loading all variables into your interactive namespace for further use
1296 1308 (unless -p is used, see below).
1297 1309
1298 1310 The file is executed in a namespace initially consisting only of
1299 1311 __name__=='__main__' and sys.argv constructed as indicated. It thus
1300 1312 sees its environment as if it were being run as a stand-alone
1301 1313 program. But after execution, the IPython interactive namespace gets
1302 1314 updated with all variables defined in the program (except for __name__
1303 1315 and sys.argv). This allows for very convenient loading of code for
1304 1316 interactive work, while giving each program a 'clean sheet' to run in.
1305 1317
1306 1318 Options:
1307 1319
1308 1320 -n: __name__ is NOT set to '__main__', but to the running file's name
1309 1321 without extension (as python does under import). This allows running
1310 1322 scripts and reloading the definitions in them without calling code
1311 1323 protected by an ' if __name__ == "__main__" ' clause.
1312 1324
1313 1325 -i: run the file in IPython's namespace instead of an empty one. This
1314 1326 is useful if you are experimenting with code written in a text editor
1315 1327 which depends on variables defined interactively.
1316 1328
1317 1329 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1318 1330 being run. This is particularly useful if IPython is being used to
1319 1331 run unittests, which always exit with a sys.exit() call. In such
1320 1332 cases you are interested in the output of the test results, not in
1321 1333 seeing a traceback of the unittest module.
1322 1334
1323 1335 -t: print timing information at the end of the run. IPython will give
1324 1336 you an estimated CPU time consumption for your script, which under
1325 1337 Unix uses the resource module to avoid the wraparound problems of
1326 1338 time.clock(). Under Unix, an estimate of time spent on system tasks
1327 1339 is also given (for Windows platforms this is reported as 0.0).
1328 1340
1329 1341 If -t is given, an additional -N<N> option can be given, where <N>
1330 1342 must be an integer indicating how many times you want the script to
1331 1343 run. The final timing report will include total and per run results.
1332 1344
1333 1345 For example (testing the script uniq_stable.py):
1334 1346
1335 1347 In [1]: run -t uniq_stable
1336 1348
1337 1349 IPython CPU timings (estimated):\\
1338 1350 User : 0.19597 s.\\
1339 1351 System: 0.0 s.\\
1340 1352
1341 1353 In [2]: run -t -N5 uniq_stable
1342 1354
1343 1355 IPython CPU timings (estimated):\\
1344 1356 Total runs performed: 5\\
1345 1357 Times : Total Per run\\
1346 1358 User : 0.910862 s, 0.1821724 s.\\
1347 1359 System: 0.0 s, 0.0 s.
1348 1360
1349 1361 -d: run your program under the control of pdb, the Python debugger.
1350 1362 This allows you to execute your program step by step, watch variables,
1351 1363 etc. Internally, what IPython does is similar to calling:
1352 1364
1353 1365 pdb.run('execfile("YOURFILENAME")')
1354 1366
1355 1367 with a breakpoint set on line 1 of your file. You can change the line
1356 1368 number for this automatic breakpoint to be <N> by using the -bN option
1357 1369 (where N must be an integer). For example:
1358 1370
1359 1371 %run -d -b40 myscript
1360 1372
1361 1373 will set the first breakpoint at line 40 in myscript.py. Note that
1362 1374 the first breakpoint must be set on a line which actually does
1363 1375 something (not a comment or docstring) for it to stop execution.
1364 1376
1365 1377 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1366 1378 first enter 'c' (without qoutes) to start execution up to the first
1367 1379 breakpoint.
1368 1380
1369 1381 Entering 'help' gives information about the use of the debugger. You
1370 1382 can easily see pdb's full documentation with "import pdb;pdb.help()"
1371 1383 at a prompt.
1372 1384
1373 1385 -p: run program under the control of the Python profiler module (which
1374 1386 prints a detailed report of execution times, function calls, etc).
1375 1387
1376 1388 You can pass other options after -p which affect the behavior of the
1377 1389 profiler itself. See the docs for %prun for details.
1378 1390
1379 1391 In this mode, the program's variables do NOT propagate back to the
1380 1392 IPython interactive namespace (because they remain in the namespace
1381 1393 where the profiler executes them).
1382 1394
1383 1395 Internally this triggers a call to %prun, see its documentation for
1384 1396 details on the options available specifically for profiling."""
1385 1397
1386 1398 # get arguments and set sys.argv for program to be run.
1387 1399 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1388 1400 mode='list',list_all=1)
1389 1401
1390 1402 try:
1391 1403 filename = get_py_filename(arg_lst[0])
1392 1404 except IndexError:
1393 1405 warn('you must provide at least a filename.')
1394 1406 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1395 1407 return
1396 1408 except IOError,msg:
1397 1409 error(msg)
1398 1410 return
1399 1411
1400 1412 # Control the response to exit() calls made by the script being run
1401 1413 exit_ignore = opts.has_key('e')
1402 1414
1403 1415 # Make sure that the running script gets a proper sys.argv as if it
1404 1416 # were run from a system shell.
1405 1417 save_argv = sys.argv # save it for later restoring
1406 1418 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1407 1419
1408 1420 if opts.has_key('i'):
1409 1421 prog_ns = self.shell.user_ns
1410 1422 __name__save = self.shell.user_ns['__name__']
1411 1423 prog_ns['__name__'] = '__main__'
1412 1424 else:
1413 1425 if opts.has_key('n'):
1414 1426 name = os.path.splitext(os.path.basename(filename))[0]
1415 1427 else:
1416 1428 name = '__main__'
1417 1429 prog_ns = {'__name__':name}
1418 1430
1419 1431 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1420 1432 # set the __file__ global in the script's namespace
1421 1433 prog_ns['__file__'] = filename
1422 1434
1423 1435 # pickle fix. See iplib for an explanation. But we need to make sure
1424 1436 # that, if we overwrite __main__, we replace it at the end
1425 1437 if prog_ns['__name__'] == '__main__':
1426 1438 restore_main = sys.modules['__main__']
1427 1439 else:
1428 1440 restore_main = False
1429 1441
1430 1442 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1431 1443
1432 1444 stats = None
1433 1445 try:
1434 1446 if opts.has_key('p'):
1435 1447 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1436 1448 else:
1437 1449 if opts.has_key('d'):
1438 1450 deb = Debugger.Pdb(self.shell.rc.colors)
1439 1451 # reset Breakpoint state, which is moronically kept
1440 1452 # in a class
1441 1453 bdb.Breakpoint.next = 1
1442 1454 bdb.Breakpoint.bplist = {}
1443 1455 bdb.Breakpoint.bpbynumber = [None]
1444 1456 # Set an initial breakpoint to stop execution
1445 1457 maxtries = 10
1446 1458 bp = int(opts.get('b',[1])[0])
1447 1459 checkline = deb.checkline(filename,bp)
1448 1460 if not checkline:
1449 1461 for bp in range(bp+1,bp+maxtries+1):
1450 1462 if deb.checkline(filename,bp):
1451 1463 break
1452 1464 else:
1453 1465 msg = ("\nI failed to find a valid line to set "
1454 1466 "a breakpoint\n"
1455 1467 "after trying up to line: %s.\n"
1456 1468 "Please set a valid breakpoint manually "
1457 1469 "with the -b option." % bp)
1458 1470 error(msg)
1459 1471 return
1460 1472 # if we find a good linenumber, set the breakpoint
1461 1473 deb.do_break('%s:%s' % (filename,bp))
1462 1474 # Start file run
1463 1475 print "NOTE: Enter 'c' at the",
1464 1476 print "ipdb> prompt to start your script."
1465 1477 try:
1466 1478 deb.run('execfile("%s")' % filename,prog_ns)
1467 1479 except:
1468 1480 etype, value, tb = sys.exc_info()
1469 1481 # Skip three frames in the traceback: the %run one,
1470 1482 # one inside bdb.py, and the command-line typed by the
1471 1483 # user (run by exec in pdb itself).
1472 1484 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1473 1485 else:
1474 1486 if runner is None:
1475 1487 runner = self.shell.safe_execfile
1476 1488 if opts.has_key('t'):
1477 1489 try:
1478 1490 nruns = int(opts['N'][0])
1479 1491 if nruns < 1:
1480 1492 error('Number of runs must be >=1')
1481 1493 return
1482 1494 except (KeyError):
1483 1495 nruns = 1
1484 1496 if nruns == 1:
1485 1497 t0 = clock2()
1486 1498 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1487 1499 t1 = clock2()
1488 1500 t_usr = t1[0]-t0[0]
1489 1501 t_sys = t1[1]-t1[1]
1490 1502 print "\nIPython CPU timings (estimated):"
1491 1503 print " User : %10s s." % t_usr
1492 1504 print " System: %10s s." % t_sys
1493 1505 else:
1494 1506 runs = range(nruns)
1495 1507 t0 = clock2()
1496 1508 for nr in runs:
1497 1509 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1498 1510 t1 = clock2()
1499 1511 t_usr = t1[0]-t0[0]
1500 1512 t_sys = t1[1]-t1[1]
1501 1513 print "\nIPython CPU timings (estimated):"
1502 1514 print "Total runs performed:",nruns
1503 1515 print " Times : %10s %10s" % ('Total','Per run')
1504 1516 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1505 1517 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1506 1518
1507 1519 else:
1508 1520 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1509 1521 if opts.has_key('i'):
1510 1522 self.shell.user_ns['__name__'] = __name__save
1511 1523 else:
1512 1524 # update IPython interactive namespace
1513 1525 del prog_ns['__name__']
1514 1526 self.shell.user_ns.update(prog_ns)
1515 1527 finally:
1516 1528 sys.argv = save_argv
1517 1529 if restore_main:
1518 1530 sys.modules['__main__'] = restore_main
1519 1531 return stats
1520 1532
1521 1533 def magic_runlog(self, parameter_s =''):
1522 1534 """Run files as logs.
1523 1535
1524 1536 Usage:\\
1525 1537 %runlog file1 file2 ...
1526 1538
1527 1539 Run the named files (treating them as log files) in sequence inside
1528 1540 the interpreter, and return to the prompt. This is much slower than
1529 1541 %run because each line is executed in a try/except block, but it
1530 1542 allows running files with syntax errors in them.
1531 1543
1532 1544 Normally IPython will guess when a file is one of its own logfiles, so
1533 1545 you can typically use %run even for logs. This shorthand allows you to
1534 1546 force any file to be treated as a log file."""
1535 1547
1536 1548 for f in parameter_s.split():
1537 1549 self.shell.safe_execfile(f,self.shell.user_ns,
1538 1550 self.shell.user_ns,islog=1)
1539 1551
1540 1552 def magic_time(self,parameter_s = ''):
1541 1553 """Time execution of a Python statement or expression.
1542 1554
1543 1555 The CPU and wall clock times are printed, and the value of the
1544 1556 expression (if any) is returned. Note that under Win32, system time
1545 1557 is always reported as 0, since it can not be measured.
1546 1558
1547 1559 This function provides very basic timing functionality. In Python
1548 1560 2.3, the timeit module offers more control and sophistication, but for
1549 1561 now IPython supports Python 2.2, so we can not rely on timeit being
1550 1562 present.
1551 1563
1552 1564 Some examples:
1553 1565
1554 1566 In [1]: time 2**128
1555 1567 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1556 1568 Wall time: 0.00
1557 1569 Out[1]: 340282366920938463463374607431768211456L
1558 1570
1559 1571 In [2]: n = 1000000
1560 1572
1561 1573 In [3]: time sum(range(n))
1562 1574 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1563 1575 Wall time: 1.37
1564 1576 Out[3]: 499999500000L
1565 1577
1566 1578 In [4]: time print 'hello world'
1567 1579 hello world
1568 1580 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1569 1581 Wall time: 0.00
1570 1582 """
1571 1583
1572 1584 # fail immediately if the given expression can't be compiled
1573 1585 try:
1574 1586 mode = 'eval'
1575 1587 code = compile(parameter_s,'<timed eval>',mode)
1576 1588 except SyntaxError:
1577 1589 mode = 'exec'
1578 1590 code = compile(parameter_s,'<timed exec>',mode)
1579 1591 # skew measurement as little as possible
1580 1592 glob = self.shell.user_ns
1581 1593 clk = clock2
1582 1594 wtime = time.time
1583 1595 # time execution
1584 1596 wall_st = wtime()
1585 1597 if mode=='eval':
1586 1598 st = clk()
1587 1599 out = eval(code,glob)
1588 1600 end = clk()
1589 1601 else:
1590 1602 st = clk()
1591 1603 exec code in glob
1592 1604 end = clk()
1593 1605 out = None
1594 1606 wall_end = wtime()
1595 1607 # Compute actual times and report
1596 1608 wall_time = wall_end-wall_st
1597 1609 cpu_user = end[0]-st[0]
1598 1610 cpu_sys = end[1]-st[1]
1599 1611 cpu_tot = cpu_user+cpu_sys
1600 1612 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1601 1613 (cpu_user,cpu_sys,cpu_tot)
1602 1614 print "Wall time: %.2f" % wall_time
1603 1615 return out
1604 1616
1605 1617 def magic_macro(self,parameter_s = ''):
1606 1618 """Define a set of input lines as a macro for future re-execution.
1607 1619
1608 1620 Usage:\\
1609 %macro name n1-n2 n3-n4 ... n5 .. n6 ...
1621 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
1622
1623 Options:
1624
1625 -r: use 'raw' input. By default, the 'processed' history is used,
1626 so that magics are loaded in their transformed version to valid
1627 Python. If this option is given, the raw input as typed as the
1628 command line is used instead.
1610 1629
1611 1630 This will define a global variable called `name` which is a string
1612 1631 made of joining the slices and lines you specify (n1,n2,... numbers
1613 1632 above) from your input history into a single string. This variable
1614 1633 acts like an automatic function which re-executes those lines as if
1615 1634 you had typed them. You just type 'name' at the prompt and the code
1616 1635 executes.
1617 1636
1618 1637 The notation for indicating number ranges is: n1-n2 means 'use line
1619 1638 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1620 1639 using the lines numbered 5,6 and 7.
1621 1640
1622 1641 Note: as a 'hidden' feature, you can also use traditional python slice
1623 1642 notation, where N:M means numbers N through M-1.
1624 1643
1625 1644 For example, if your history contains (%hist prints it):
1626 1645
1627 1646 44: x=1\\
1628 1647 45: y=3\\
1629 1648 46: z=x+y\\
1630 1649 47: print x\\
1631 1650 48: a=5\\
1632 1651 49: print 'x',x,'y',y\\
1633 1652
1634 1653 you can create a macro with lines 44 through 47 (included) and line 49
1635 1654 called my_macro with:
1636 1655
1637 1656 In [51]: %macro my_macro 44-47 49
1638 1657
1639 1658 Now, typing `my_macro` (without quotes) will re-execute all this code
1640 1659 in one pass.
1641 1660
1642 1661 You don't need to give the line-numbers in order, and any given line
1643 1662 number can appear multiple times. You can assemble macros with any
1644 1663 lines from your input history in any order.
1645 1664
1646 1665 The macro is a simple object which holds its value in an attribute,
1647 1666 but IPython's display system checks for macros and executes them as
1648 1667 code instead of printing them when you type their name.
1649 1668
1650 1669 You can view a macro's contents by explicitly printing it with:
1651 1670
1652 1671 'print macro_name'.
1653 1672
1654 1673 For one-off cases which DON'T contain magic function calls in them you
1655 1674 can obtain similar results by explicitly executing slices from your
1656 1675 input history with:
1657 1676
1658 1677 In [60]: exec In[44:48]+In[49]"""
1659 1678
1660 args = parameter_s.split()
1679 opts,args = self.parse_options(parameter_s,'r')
1661 1680 name,ranges = args[0], args[1:]
1662 1681 #print 'rng',ranges # dbg
1663 lines = self.extract_input_slices(ranges)
1682 lines = self.extract_input_slices(ranges,opts.has_key('r'))
1664 1683 macro = Macro(lines)
1665 1684 self.shell.user_ns.update({name:macro})
1666 1685 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1667 1686 print 'Macro contents:'
1668 1687 print macro,
1669 1688
1670 1689 def magic_save(self,parameter_s = ''):
1671 1690 """Save a set of lines to a given filename.
1672 1691
1673 1692 Usage:\\
1674 %save filename n1-n2 n3-n4 ... n5 .. n6 ...
1693 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
1694
1695 Options:
1696
1697 -r: use 'raw' input. By default, the 'processed' history is used,
1698 so that magics are loaded in their transformed version to valid
1699 Python. If this option is given, the raw input as typed as the
1700 command line is used instead.
1675 1701
1676 1702 This function uses the same syntax as %macro for line extraction, but
1677 1703 instead of creating a macro it saves the resulting string to the
1678 1704 filename you specify.
1679 1705
1680 1706 It adds a '.py' extension to the file if you don't do so yourself, and
1681 1707 it asks for confirmation before overwriting existing files."""
1682 1708
1683 args = parameter_s.split()
1709 opts,args = self.parse_options(parameter_s,'r')
1684 1710 fname,ranges = args[0], args[1:]
1685 1711 if not fname.endswith('.py'):
1686 1712 fname += '.py'
1687 1713 if os.path.isfile(fname):
1688 1714 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1689 1715 if ans.lower() not in ['y','yes']:
1690 1716 print 'Operation cancelled.'
1691 1717 return
1692 cmds = ''.join(self.extract_input_slices(ranges))
1718 cmds = ''.join(self.extract_input_slices(ranges,opts.has_key('r')))
1693 1719 f = file(fname,'w')
1694 1720 f.write(cmds)
1695 1721 f.close()
1696 1722 print 'The following commands were written to file `%s`:' % fname
1697 1723 print cmds
1698 1724
1699 1725 def _edit_macro(self,mname,macro):
1700 1726 """open an editor with the macro data in a file"""
1701 1727 filename = self.shell.mktempfile(macro.value)
1702 1728 self.shell.hooks.editor(filename)
1703 1729
1704 1730 # and make a new macro object, to replace the old one
1705 1731 mfile = open(filename)
1706 1732 mvalue = mfile.read()
1707 1733 mfile.close()
1708 1734 self.shell.user_ns[mname] = Macro(mvalue)
1709 1735
1710 1736 def magic_ed(self,parameter_s=''):
1711 1737 """Alias to %edit."""
1712 1738 return self.magic_edit(parameter_s)
1713 1739
1714 1740 def magic_edit(self,parameter_s='',last_call=['','']):
1715 1741 """Bring up an editor and execute the resulting code.
1716 1742
1717 1743 Usage:
1718 1744 %edit [options] [args]
1719 1745
1720 1746 %edit runs IPython's editor hook. The default version of this hook is
1721 1747 set to call the __IPYTHON__.rc.editor command. This is read from your
1722 1748 environment variable $EDITOR. If this isn't found, it will default to
1723 1749 vi under Linux/Unix and to notepad under Windows. See the end of this
1724 1750 docstring for how to change the editor hook.
1725 1751
1726 1752 You can also set the value of this editor via the command line option
1727 1753 '-editor' or in your ipythonrc file. This is useful if you wish to use
1728 1754 specifically for IPython an editor different from your typical default
1729 1755 (and for Windows users who typically don't set environment variables).
1730 1756
1731 1757 This command allows you to conveniently edit multi-line code right in
1732 1758 your IPython session.
1733 1759
1734 1760 If called without arguments, %edit opens up an empty editor with a
1735 1761 temporary file and will execute the contents of this file when you
1736 1762 close it (don't forget to save it!).
1737 1763
1738 1764
1739 1765 Options:
1740 1766
1741 1767 -p: this will call the editor with the same data as the previous time
1742 1768 it was used, regardless of how long ago (in your current session) it
1743 1769 was.
1744 1770
1771 -r: use 'raw' input. This option only applies to input taken from the
1772 user's history. By default, the 'processed' history is used, so that
1773 magics are loaded in their transformed version to valid Python. If
1774 this option is given, the raw input as typed as the command line is
1775 used instead. When you exit the editor, it will be executed by
1776 IPython's own processor.
1777
1745 1778 -x: do not execute the edited code immediately upon exit. This is
1746 1779 mainly useful if you are editing programs which need to be called with
1747 1780 command line arguments, which you can then do using %run.
1748 1781
1749 1782
1750 1783 Arguments:
1751 1784
1752 1785 If arguments are given, the following possibilites exist:
1753 1786
1754 1787 - The arguments are numbers or pairs of colon-separated numbers (like
1755 1788 1 4:8 9). These are interpreted as lines of previous input to be
1756 1789 loaded into the editor. The syntax is the same of the %macro command.
1757 1790
1758 1791 - If the argument doesn't start with a number, it is evaluated as a
1759 1792 variable and its contents loaded into the editor. You can thus edit
1760 1793 any string which contains python code (including the result of
1761 1794 previous edits).
1762 1795
1763 1796 - If the argument is the name of an object (other than a string),
1764 1797 IPython will try to locate the file where it was defined and open the
1765 1798 editor at the point where it is defined. You can use `%edit function`
1766 1799 to load an editor exactly at the point where 'function' is defined,
1767 1800 edit it and have the file be executed automatically.
1768 1801
1769 1802 If the object is a macro (see %macro for details), this opens up your
1770 1803 specified editor with a temporary file containing the macro's data.
1771 1804 Upon exit, the macro is reloaded with the contents of the file.
1772 1805
1773 1806 Note: opening at an exact line is only supported under Unix, and some
1774 1807 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1775 1808 '+NUMBER' parameter necessary for this feature. Good editors like
1776 1809 (X)Emacs, vi, jed, pico and joe all do.
1777 1810
1778 1811 - If the argument is not found as a variable, IPython will look for a
1779 1812 file with that name (adding .py if necessary) and load it into the
1780 1813 editor. It will execute its contents with execfile() when you exit,
1781 1814 loading any code in the file into your interactive namespace.
1782 1815
1783 1816 After executing your code, %edit will return as output the code you
1784 1817 typed in the editor (except when it was an existing file). This way
1785 1818 you can reload the code in further invocations of %edit as a variable,
1786 1819 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1787 1820 the output.
1788 1821
1789 1822 Note that %edit is also available through the alias %ed.
1790 1823
1791 1824 This is an example of creating a simple function inside the editor and
1792 1825 then modifying it. First, start up the editor:
1793 1826
1794 1827 In [1]: ed\\
1795 1828 Editing... done. Executing edited code...\\
1796 1829 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1797 1830
1798 1831 We can then call the function foo():
1799 1832
1800 1833 In [2]: foo()\\
1801 1834 foo() was defined in an editing session
1802 1835
1803 1836 Now we edit foo. IPython automatically loads the editor with the
1804 1837 (temporary) file where foo() was previously defined:
1805 1838
1806 1839 In [3]: ed foo\\
1807 1840 Editing... done. Executing edited code...
1808 1841
1809 1842 And if we call foo() again we get the modified version:
1810 1843
1811 1844 In [4]: foo()\\
1812 1845 foo() has now been changed!
1813 1846
1814 1847 Here is an example of how to edit a code snippet successive
1815 1848 times. First we call the editor:
1816 1849
1817 1850 In [8]: ed\\
1818 1851 Editing... done. Executing edited code...\\
1819 1852 hello\\
1820 1853 Out[8]: "print 'hello'\\n"
1821 1854
1822 1855 Now we call it again with the previous output (stored in _):
1823 1856
1824 1857 In [9]: ed _\\
1825 1858 Editing... done. Executing edited code...\\
1826 1859 hello world\\
1827 1860 Out[9]: "print 'hello world'\\n"
1828 1861
1829 1862 Now we call it with the output #8 (stored in _8, also as Out[8]):
1830 1863
1831 1864 In [10]: ed _8\\
1832 1865 Editing... done. Executing edited code...\\
1833 1866 hello again\\
1834 1867 Out[10]: "print 'hello again'\\n"
1835 1868
1836 1869
1837 1870 Changing the default editor hook:
1838 1871
1839 1872 If you wish to write your own editor hook, you can put it in a
1840 1873 configuration file which you load at startup time. The default hook
1841 1874 is defined in the IPython.hooks module, and you can use that as a
1842 1875 starting example for further modifications. That file also has
1843 1876 general instructions on how to set a new hook for use once you've
1844 1877 defined it."""
1845 1878
1846 1879 # FIXME: This function has become a convoluted mess. It needs a
1847 1880 # ground-up rewrite with clean, simple logic.
1848 1881
1849 1882 def make_filename(arg):
1850 1883 "Make a filename from the given args"
1851 1884 try:
1852 1885 filename = get_py_filename(arg)
1853 1886 except IOError:
1854 1887 if args.endswith('.py'):
1855 1888 filename = arg
1856 1889 else:
1857 1890 filename = None
1858 1891 return filename
1859 1892
1860 1893 # custom exceptions
1861 1894 class DataIsObject(Exception): pass
1862 1895
1863 opts,args = self.parse_options(parameter_s,'px')
1896 opts,args = self.parse_options(parameter_s,'prx')
1897 # Set a few locals from the options for convenience:
1898 opts_p = opts.has_key('p')
1899 opts_r = opts.has_key('r')
1864 1900
1865 1901 # Default line number value
1866 1902 lineno = None
1867 if opts.has_key('p'):
1903 if opts_p:
1868 1904 args = '_%s' % last_call[0]
1869 1905 if not self.shell.user_ns.has_key(args):
1870 1906 args = last_call[1]
1871 1907
1872 1908 # use last_call to remember the state of the previous call, but don't
1873 1909 # let it be clobbered by successive '-p' calls.
1874 1910 try:
1875 1911 last_call[0] = self.shell.outputcache.prompt_count
1876 if not opts.has_key('p'):
1912 if not opts_p:
1877 1913 last_call[1] = parameter_s
1878 1914 except:
1879 1915 pass
1880 1916
1881 1917 # by default this is done with temp files, except when the given
1882 1918 # arg is a filename
1883 1919 use_temp = 1
1884 1920
1885 1921 if re.match(r'\d',args):
1886 1922 # Mode where user specifies ranges of lines, like in %macro.
1887 1923 # This means that you can't edit files whose names begin with
1888 1924 # numbers this way. Tough.
1889 1925 ranges = args.split()
1890 data = ''.join(self.extract_input_slices(ranges))
1926 data = ''.join(self.extract_input_slices(ranges,opts_r))
1891 1927 elif args.endswith('.py'):
1892 1928 filename = make_filename(args)
1893 1929 data = ''
1894 1930 use_temp = 0
1895 1931 elif args:
1896 1932 try:
1897 1933 # Load the parameter given as a variable. If not a string,
1898 1934 # process it as an object instead (below)
1899 1935
1900 1936 #print '*** args',args,'type',type(args) # dbg
1901 1937 data = eval(args,self.shell.user_ns)
1902 1938 if not type(data) in StringTypes:
1903 1939 raise DataIsObject
1904 1940
1905 1941 except (NameError,SyntaxError):
1906 1942 # given argument is not a variable, try as a filename
1907 1943 filename = make_filename(args)
1908 1944 if filename is None:
1909 1945 warn("Argument given (%s) can't be found as a variable "
1910 1946 "or as a filename." % args)
1911 1947 return
1912 1948
1913 1949 data = ''
1914 1950 use_temp = 0
1915 1951 except DataIsObject:
1916 1952
1917 1953 # macros have a special edit function
1918 1954 if isinstance(data,Macro):
1919 1955 self._edit_macro(args,data)
1920 1956 return
1921 1957
1922 1958 # For objects, try to edit the file where they are defined
1923 1959 try:
1924 1960 filename = inspect.getabsfile(data)
1925 1961 datafile = 1
1926 1962 except TypeError:
1927 1963 filename = make_filename(args)
1928 1964 datafile = 1
1929 1965 warn('Could not find file where `%s` is defined.\n'
1930 1966 'Opening a file named `%s`' % (args,filename))
1931 1967 # Now, make sure we can actually read the source (if it was in
1932 1968 # a temp file it's gone by now).
1933 1969 if datafile:
1934 1970 try:
1935 1971 lineno = inspect.getsourcelines(data)[1]
1936 1972 except IOError:
1937 1973 filename = make_filename(args)
1938 1974 if filename is None:
1939 1975 warn('The file `%s` where `%s` was defined cannot '
1940 1976 'be read.' % (filename,data))
1941 1977 return
1942 1978 use_temp = 0
1943 1979 else:
1944 1980 data = ''
1945 1981
1946 1982 if use_temp:
1947 1983 filename = self.shell.mktempfile(data)
1948 1984 print 'IPython will make a temporary file named:',filename
1949 1985
1950 1986 # do actual editing here
1951 1987 print 'Editing...',
1952 1988 sys.stdout.flush()
1953 1989 self.shell.hooks.editor(filename,lineno)
1954 1990 if opts.has_key('x'): # -x prevents actual execution
1955 1991 print
1956 1992 else:
1957 1993 print 'done. Executing edited code...'
1958 self.shell.safe_execfile(filename,self.shell.user_ns)
1994 if opts_r:
1995 self.shell.runlines(file_read(filename))
1996 else:
1997 self.shell.safe_execfile(filename,self.shell.user_ns)
1959 1998 if use_temp:
1960 1999 try:
1961 2000 return open(filename).read()
1962 2001 except IOError,msg:
1963 2002 if msg.filename == filename:
1964 2003 warn('File not found. Did you forget to save?')
1965 2004 return
1966 2005 else:
1967 2006 self.shell.showtraceback()
1968 2007
1969 2008 def magic_xmode(self,parameter_s = ''):
1970 2009 """Switch modes for the exception handlers.
1971 2010
1972 2011 Valid modes: Plain, Context and Verbose.
1973 2012
1974 2013 If called without arguments, acts as a toggle."""
1975 2014
1976 2015 def xmode_switch_err(name):
1977 2016 warn('Error changing %s exception modes.\n%s' %
1978 2017 (name,sys.exc_info()[1]))
1979 2018
1980 2019 shell = self.shell
1981 2020 new_mode = parameter_s.strip().capitalize()
1982 2021 try:
1983 2022 shell.InteractiveTB.set_mode(mode=new_mode)
1984 2023 print 'Exception reporting mode:',shell.InteractiveTB.mode
1985 2024 except:
1986 2025 xmode_switch_err('user')
1987 2026
1988 2027 # threaded shells use a special handler in sys.excepthook
1989 2028 if shell.isthreaded:
1990 2029 try:
1991 2030 shell.sys_excepthook.set_mode(mode=new_mode)
1992 2031 except:
1993 2032 xmode_switch_err('threaded')
1994 2033
1995 2034 def magic_colors(self,parameter_s = ''):
1996 2035 """Switch color scheme for prompts, info system and exception handlers.
1997 2036
1998 2037 Currently implemented schemes: NoColor, Linux, LightBG.
1999 2038
2000 2039 Color scheme names are not case-sensitive."""
2001 2040
2002 2041 def color_switch_err(name):
2003 2042 warn('Error changing %s color schemes.\n%s' %
2004 2043 (name,sys.exc_info()[1]))
2005 2044
2006 2045
2007 2046 new_scheme = parameter_s.strip()
2008 2047 if not new_scheme:
2009 2048 print 'You must specify a color scheme.'
2010 2049 return
2011 2050 import IPython.rlineimpl as readline
2012 2051 if not readline.have_readline:
2013 2052 msg = """\
2014 2053 Proper color support under MS Windows requires Gary Bishop's readline library.
2015 2054 You can find it at:
2016 2055 http://sourceforge.net/projects/uncpythontools
2017 2056 Gary's readline needs the ctypes module, from:
2018 2057 http://starship.python.net/crew/theller/ctypes
2019 2058
2020 2059 Defaulting color scheme to 'NoColor'"""
2021 2060 new_scheme = 'NoColor'
2022 2061 warn(msg)
2023 2062 # local shortcut
2024 2063 shell = self.shell
2025 2064
2026 2065 # Set prompt colors
2027 2066 try:
2028 2067 shell.outputcache.set_colors(new_scheme)
2029 2068 except:
2030 2069 color_switch_err('prompt')
2031 2070 else:
2032 2071 shell.rc.colors = \
2033 2072 shell.outputcache.color_table.active_scheme_name
2034 2073 # Set exception colors
2035 2074 try:
2036 2075 shell.InteractiveTB.set_colors(scheme = new_scheme)
2037 2076 shell.SyntaxTB.set_colors(scheme = new_scheme)
2038 2077 except:
2039 2078 color_switch_err('exception')
2040 2079
2041 2080 # threaded shells use a verbose traceback in sys.excepthook
2042 2081 if shell.isthreaded:
2043 2082 try:
2044 2083 shell.sys_excepthook.set_colors(scheme=new_scheme)
2045 2084 except:
2046 2085 color_switch_err('system exception handler')
2047 2086
2048 2087 # Set info (for 'object?') colors
2049 2088 if shell.rc.color_info:
2050 2089 try:
2051 2090 shell.inspector.set_active_scheme(new_scheme)
2052 2091 except:
2053 2092 color_switch_err('object inspector')
2054 2093 else:
2055 2094 shell.inspector.set_active_scheme('NoColor')
2056 2095
2057 2096 def magic_color_info(self,parameter_s = ''):
2058 2097 """Toggle color_info.
2059 2098
2060 2099 The color_info configuration parameter controls whether colors are
2061 2100 used for displaying object details (by things like %psource, %pfile or
2062 2101 the '?' system). This function toggles this value with each call.
2063 2102
2064 2103 Note that unless you have a fairly recent pager (less works better
2065 2104 than more) in your system, using colored object information displays
2066 2105 will not work properly. Test it and see."""
2067 2106
2068 2107 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2069 2108 self.magic_colors(self.shell.rc.colors)
2070 2109 print 'Object introspection functions have now coloring:',
2071 2110 print ['OFF','ON'][self.shell.rc.color_info]
2072 2111
2073 2112 def magic_Pprint(self, parameter_s=''):
2074 2113 """Toggle pretty printing on/off."""
2075 2114
2076 2115 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
2077 2116 print 'Pretty printing has been turned', \
2078 2117 ['OFF','ON'][self.shell.outputcache.Pprint]
2079 2118
2080 2119 def magic_exit(self, parameter_s=''):
2081 2120 """Exit IPython, confirming if configured to do so.
2082 2121
2083 2122 You can configure whether IPython asks for confirmation upon exit by
2084 2123 setting the confirm_exit flag in the ipythonrc file."""
2085 2124
2086 2125 self.shell.exit()
2087 2126
2088 2127 def magic_quit(self, parameter_s=''):
2089 2128 """Exit IPython, confirming if configured to do so (like %exit)"""
2090 2129
2091 2130 self.shell.exit()
2092 2131
2093 2132 def magic_Exit(self, parameter_s=''):
2094 2133 """Exit IPython without confirmation."""
2095 2134
2096 2135 self.shell.exit_now = True
2097 2136
2098 2137 def magic_Quit(self, parameter_s=''):
2099 2138 """Exit IPython without confirmation (like %Exit)."""
2100 2139
2101 2140 self.shell.exit_now = True
2102 2141
2103 2142 #......................................................................
2104 2143 # Functions to implement unix shell-type things
2105 2144
2106 2145 def magic_alias(self, parameter_s = ''):
2107 2146 """Define an alias for a system command.
2108 2147
2109 2148 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2110 2149
2111 2150 Then, typing 'alias_name params' will execute the system command 'cmd
2112 2151 params' (from your underlying operating system).
2113 2152
2114 2153 Aliases have lower precedence than magic functions and Python normal
2115 2154 variables, so if 'foo' is both a Python variable and an alias, the
2116 2155 alias can not be executed until 'del foo' removes the Python variable.
2117 2156
2118 2157 You can use the %l specifier in an alias definition to represent the
2119 2158 whole line when the alias is called. For example:
2120 2159
2121 2160 In [2]: alias all echo "Input in brackets: <%l>"\\
2122 2161 In [3]: all hello world\\
2123 2162 Input in brackets: <hello world>
2124 2163
2125 2164 You can also define aliases with parameters using %s specifiers (one
2126 2165 per parameter):
2127 2166
2128 2167 In [1]: alias parts echo first %s second %s\\
2129 2168 In [2]: %parts A B\\
2130 2169 first A second B\\
2131 2170 In [3]: %parts A\\
2132 2171 Incorrect number of arguments: 2 expected.\\
2133 2172 parts is an alias to: 'echo first %s second %s'
2134 2173
2135 2174 Note that %l and %s are mutually exclusive. You can only use one or
2136 2175 the other in your aliases.
2137 2176
2138 2177 Aliases expand Python variables just like system calls using ! or !!
2139 2178 do: all expressions prefixed with '$' get expanded. For details of
2140 2179 the semantic rules, see PEP-215:
2141 2180 http://www.python.org/peps/pep-0215.html. This is the library used by
2142 2181 IPython for variable expansion. If you want to access a true shell
2143 2182 variable, an extra $ is necessary to prevent its expansion by IPython:
2144 2183
2145 2184 In [6]: alias show echo\\
2146 2185 In [7]: PATH='A Python string'\\
2147 2186 In [8]: show $PATH\\
2148 2187 A Python string\\
2149 2188 In [9]: show $$PATH\\
2150 2189 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2151 2190
2152 2191 You can use the alias facility to acess all of $PATH. See the %rehash
2153 2192 and %rehashx functions, which automatically create aliases for the
2154 2193 contents of your $PATH.
2155 2194
2156 2195 If called with no parameters, %alias prints the current alias table."""
2157 2196
2158 2197 par = parameter_s.strip()
2159 2198 if not par:
2160 2199 if self.shell.rc.automagic:
2161 2200 prechar = ''
2162 2201 else:
2163 2202 prechar = self.shell.ESC_MAGIC
2164 2203 #print 'Alias\t\tSystem Command\n'+'-'*30
2165 2204 atab = self.shell.alias_table
2166 2205 aliases = atab.keys()
2167 2206 aliases.sort()
2168 2207 res = []
2169 2208 for alias in aliases:
2170 2209 res.append((alias, atab[alias][1]))
2171 2210 print "Total number of aliases:",len(aliases)
2172 2211 return res
2173 2212 try:
2174 2213 alias,cmd = par.split(None,1)
2175 2214 except:
2176 2215 print OInspect.getdoc(self.magic_alias)
2177 2216 else:
2178 2217 nargs = cmd.count('%s')
2179 2218 if nargs>0 and cmd.find('%l')>=0:
2180 2219 error('The %s and %l specifiers are mutually exclusive '
2181 2220 'in alias definitions.')
2182 2221 else: # all looks OK
2183 2222 self.shell.alias_table[alias] = (nargs,cmd)
2184 2223 self.shell.alias_table_validate(verbose=1)
2185 2224 # end magic_alias
2186 2225
2187 2226 def magic_unalias(self, parameter_s = ''):
2188 2227 """Remove an alias"""
2189 2228
2190 2229 aname = parameter_s.strip()
2191 2230 if aname in self.shell.alias_table:
2192 2231 del self.shell.alias_table[aname]
2193 2232
2194 2233 def magic_rehash(self, parameter_s = ''):
2195 2234 """Update the alias table with all entries in $PATH.
2196 2235
2197 2236 This version does no checks on execute permissions or whether the
2198 2237 contents of $PATH are truly files (instead of directories or something
2199 2238 else). For such a safer (but slower) version, use %rehashx."""
2200 2239
2201 2240 # This function (and rehashx) manipulate the alias_table directly
2202 2241 # rather than calling magic_alias, for speed reasons. A rehash on a
2203 2242 # typical Linux box involves several thousand entries, so efficiency
2204 2243 # here is a top concern.
2205 2244
2206 2245 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2207 2246 alias_table = self.shell.alias_table
2208 2247 for pdir in path:
2209 2248 for ff in os.listdir(pdir):
2210 2249 # each entry in the alias table must be (N,name), where
2211 2250 # N is the number of positional arguments of the alias.
2212 2251 alias_table[ff] = (0,ff)
2213 2252 # Make sure the alias table doesn't contain keywords or builtins
2214 2253 self.shell.alias_table_validate()
2215 2254 # Call again init_auto_alias() so we get 'rm -i' and other modified
2216 2255 # aliases since %rehash will probably clobber them
2217 2256 self.shell.init_auto_alias()
2218 2257
2219 2258 def magic_rehashx(self, parameter_s = ''):
2220 2259 """Update the alias table with all executable files in $PATH.
2221 2260
2222 2261 This version explicitly checks that every entry in $PATH is a file
2223 2262 with execute access (os.X_OK), so it is much slower than %rehash.
2224 2263
2225 2264 Under Windows, it checks executability as a match agains a
2226 2265 '|'-separated string of extensions, stored in the IPython config
2227 2266 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2228 2267
2229 2268 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2230 2269 alias_table = self.shell.alias_table
2231 2270
2232 2271 if os.name == 'posix':
2233 2272 isexec = lambda fname:os.path.isfile(fname) and \
2234 2273 os.access(fname,os.X_OK)
2235 2274 else:
2236 2275
2237 2276 try:
2238 2277 winext = os.environ['pathext'].replace(';','|').replace('.','')
2239 2278 except KeyError:
2240 2279 winext = 'exe|com|bat'
2241 2280
2242 2281 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2243 2282 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2244 2283 savedir = os.getcwd()
2245 2284 try:
2246 2285 # write the whole loop for posix/Windows so we don't have an if in
2247 2286 # the innermost part
2248 2287 if os.name == 'posix':
2249 2288 for pdir in path:
2250 2289 os.chdir(pdir)
2251 2290 for ff in os.listdir(pdir):
2252 2291 if isexec(ff):
2253 2292 # each entry in the alias table must be (N,name),
2254 2293 # where N is the number of positional arguments of the
2255 2294 # alias.
2256 2295 alias_table[ff] = (0,ff)
2257 2296 else:
2258 2297 for pdir in path:
2259 2298 os.chdir(pdir)
2260 2299 for ff in os.listdir(pdir):
2261 2300 if isexec(ff):
2262 2301 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2263 2302 # Make sure the alias table doesn't contain keywords or builtins
2264 2303 self.shell.alias_table_validate()
2265 2304 # Call again init_auto_alias() so we get 'rm -i' and other
2266 2305 # modified aliases since %rehashx will probably clobber them
2267 2306 self.shell.init_auto_alias()
2268 2307 finally:
2269 2308 os.chdir(savedir)
2270 2309
2271 2310 def magic_pwd(self, parameter_s = ''):
2272 2311 """Return the current working directory path."""
2273 2312 return os.getcwd()
2274 2313
2275 2314 def magic_cd(self, parameter_s=''):
2276 2315 """Change the current working directory.
2277 2316
2278 2317 This command automatically maintains an internal list of directories
2279 2318 you visit during your IPython session, in the variable _dh. The
2280 2319 command %dhist shows this history nicely formatted.
2281 2320
2282 2321 Usage:
2283 2322
2284 2323 cd 'dir': changes to directory 'dir'.
2285 2324
2286 2325 cd -: changes to the last visited directory.
2287 2326
2288 2327 cd -<n>: changes to the n-th directory in the directory history.
2289 2328
2290 2329 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2291 2330 (note: cd <bookmark_name> is enough if there is no
2292 2331 directory <bookmark_name>, but a bookmark with the name exists.)
2293 2332
2294 2333 Options:
2295 2334
2296 2335 -q: quiet. Do not print the working directory after the cd command is
2297 2336 executed. By default IPython's cd command does print this directory,
2298 2337 since the default prompts do not display path information.
2299 2338
2300 2339 Note that !cd doesn't work for this purpose because the shell where
2301 2340 !command runs is immediately discarded after executing 'command'."""
2302 2341
2303 2342 parameter_s = parameter_s.strip()
2304 2343 #bkms = self.shell.persist.get("bookmarks",{})
2305 2344
2306 2345 numcd = re.match(r'(-)(\d+)$',parameter_s)
2307 2346 # jump in directory history by number
2308 2347 if numcd:
2309 2348 nn = int(numcd.group(2))
2310 2349 try:
2311 2350 ps = self.shell.user_ns['_dh'][nn]
2312 2351 except IndexError:
2313 2352 print 'The requested directory does not exist in history.'
2314 2353 return
2315 2354 else:
2316 2355 opts = {}
2317 2356 else:
2318 2357 #turn all non-space-escaping backslashes to slashes,
2319 2358 # for c:\windows\directory\names\
2320 2359 parameter_s = re.sub(r'\\(?! )','/', parameter_s)
2321 2360 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2322 2361 # jump to previous
2323 2362 if ps == '-':
2324 2363 try:
2325 2364 ps = self.shell.user_ns['_dh'][-2]
2326 2365 except IndexError:
2327 2366 print 'No previous directory to change to.'
2328 2367 return
2329 2368 # jump to bookmark if needed
2330 2369 else:
2331 2370 if not os.path.isdir(ps) or opts.has_key('b'):
2332 2371 bkms = self.db.get('bookmarks', {})
2333 2372
2334 2373 if bkms.has_key(ps):
2335 2374 target = bkms[ps]
2336 2375 print '(bookmark:%s) -> %s' % (ps,target)
2337 2376 ps = target
2338 2377 else:
2339 2378 if opts.has_key('b'):
2340 2379 error("Bookmark '%s' not found. "
2341 2380 "Use '%%bookmark -l' to see your bookmarks." % ps)
2342 2381 return
2343 2382
2344 2383 # at this point ps should point to the target dir
2345 2384 if ps:
2346 2385 try:
2347 2386 os.chdir(os.path.expanduser(ps))
2348 2387 ttitle = ("IPy:" + (
2349 2388 os.getcwd() == '/' and '/' or os.path.basename(os.getcwd())))
2350 2389 platutils.set_term_title(ttitle)
2351 2390 except OSError:
2352 2391 print sys.exc_info()[1]
2353 2392 else:
2354 2393 self.shell.user_ns['_dh'].append(os.getcwd())
2355 2394 else:
2356 2395 os.chdir(self.shell.home_dir)
2357 2396 platutils.set_term_title("IPy:~")
2358 2397 self.shell.user_ns['_dh'].append(os.getcwd())
2359 2398 if not 'q' in opts:
2360 2399 print self.shell.user_ns['_dh'][-1]
2361 2400
2362 2401 def magic_dhist(self, parameter_s=''):
2363 2402 """Print your history of visited directories.
2364 2403
2365 2404 %dhist -> print full history\\
2366 2405 %dhist n -> print last n entries only\\
2367 2406 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2368 2407
2369 2408 This history is automatically maintained by the %cd command, and
2370 2409 always available as the global list variable _dh. You can use %cd -<n>
2371 2410 to go to directory number <n>."""
2372 2411
2373 2412 dh = self.shell.user_ns['_dh']
2374 2413 if parameter_s:
2375 2414 try:
2376 2415 args = map(int,parameter_s.split())
2377 2416 except:
2378 2417 self.arg_err(Magic.magic_dhist)
2379 2418 return
2380 2419 if len(args) == 1:
2381 2420 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2382 2421 elif len(args) == 2:
2383 2422 ini,fin = args
2384 2423 else:
2385 2424 self.arg_err(Magic.magic_dhist)
2386 2425 return
2387 2426 else:
2388 2427 ini,fin = 0,len(dh)
2389 2428 nlprint(dh,
2390 2429 header = 'Directory history (kept in _dh)',
2391 2430 start=ini,stop=fin)
2392 2431
2393 2432 def magic_env(self, parameter_s=''):
2394 2433 """List environment variables."""
2395 2434
2396 2435 return os.environ.data
2397 2436
2398 2437 def magic_pushd(self, parameter_s=''):
2399 2438 """Place the current dir on stack and change directory.
2400 2439
2401 2440 Usage:\\
2402 2441 %pushd ['dirname']
2403 2442
2404 2443 %pushd with no arguments does a %pushd to your home directory.
2405 2444 """
2406 2445 if parameter_s == '': parameter_s = '~'
2407 2446 dir_s = self.shell.dir_stack
2408 2447 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2409 2448 os.path.expanduser(self.shell.dir_stack[0]):
2410 2449 try:
2411 2450 self.magic_cd(parameter_s)
2412 2451 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2413 2452 self.magic_dirs()
2414 2453 except:
2415 2454 print 'Invalid directory'
2416 2455 else:
2417 2456 print 'You are already there!'
2418 2457
2419 2458 def magic_popd(self, parameter_s=''):
2420 2459 """Change to directory popped off the top of the stack.
2421 2460 """
2422 2461 if len (self.shell.dir_stack) > 1:
2423 2462 self.shell.dir_stack.pop(0)
2424 2463 self.magic_cd(self.shell.dir_stack[0])
2425 2464 print self.shell.dir_stack[0]
2426 2465 else:
2427 2466 print "You can't remove the starting directory from the stack:",\
2428 2467 self.shell.dir_stack
2429 2468
2430 2469 def magic_dirs(self, parameter_s=''):
2431 2470 """Return the current directory stack."""
2432 2471
2433 2472 return self.shell.dir_stack[:]
2434 2473
2435 2474 def magic_sc(self, parameter_s=''):
2436 2475 """Shell capture - execute a shell command and capture its output.
2437 2476
2438 2477 DEPRECATED. Suboptimal, retained for backwards compatibility.
2439 2478
2440 2479 You should use the form 'var = !command' instead. Example:
2441 2480
2442 2481 "%sc -l myfiles = ls ~" should now be written as
2443 2482
2444 2483 "myfiles = !ls ~"
2445 2484
2446 2485 myfiles.s, myfiles.l and myfiles.n still apply as documented
2447 2486 below.
2448 2487
2449 2488 --
2450 2489 %sc [options] varname=command
2451 2490
2452 2491 IPython will run the given command using commands.getoutput(), and
2453 2492 will then update the user's interactive namespace with a variable
2454 2493 called varname, containing the value of the call. Your command can
2455 2494 contain shell wildcards, pipes, etc.
2456 2495
2457 2496 The '=' sign in the syntax is mandatory, and the variable name you
2458 2497 supply must follow Python's standard conventions for valid names.
2459 2498
2460 2499 (A special format without variable name exists for internal use)
2461 2500
2462 2501 Options:
2463 2502
2464 2503 -l: list output. Split the output on newlines into a list before
2465 2504 assigning it to the given variable. By default the output is stored
2466 2505 as a single string.
2467 2506
2468 2507 -v: verbose. Print the contents of the variable.
2469 2508
2470 2509 In most cases you should not need to split as a list, because the
2471 2510 returned value is a special type of string which can automatically
2472 2511 provide its contents either as a list (split on newlines) or as a
2473 2512 space-separated string. These are convenient, respectively, either
2474 2513 for sequential processing or to be passed to a shell command.
2475 2514
2476 2515 For example:
2477 2516
2478 2517 # Capture into variable a
2479 2518 In [9]: sc a=ls *py
2480 2519
2481 2520 # a is a string with embedded newlines
2482 2521 In [10]: a
2483 2522 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2484 2523
2485 2524 # which can be seen as a list:
2486 2525 In [11]: a.l
2487 2526 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2488 2527
2489 2528 # or as a whitespace-separated string:
2490 2529 In [12]: a.s
2491 2530 Out[12]: 'setup.py win32_manual_post_install.py'
2492 2531
2493 2532 # a.s is useful to pass as a single command line:
2494 2533 In [13]: !wc -l $a.s
2495 2534 146 setup.py
2496 2535 130 win32_manual_post_install.py
2497 2536 276 total
2498 2537
2499 2538 # while the list form is useful to loop over:
2500 2539 In [14]: for f in a.l:
2501 2540 ....: !wc -l $f
2502 2541 ....:
2503 2542 146 setup.py
2504 2543 130 win32_manual_post_install.py
2505 2544
2506 2545 Similiarly, the lists returned by the -l option are also special, in
2507 2546 the sense that you can equally invoke the .s attribute on them to
2508 2547 automatically get a whitespace-separated string from their contents:
2509 2548
2510 2549 In [1]: sc -l b=ls *py
2511 2550
2512 2551 In [2]: b
2513 2552 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2514 2553
2515 2554 In [3]: b.s
2516 2555 Out[3]: 'setup.py win32_manual_post_install.py'
2517 2556
2518 2557 In summary, both the lists and strings used for ouptut capture have
2519 2558 the following special attributes:
2520 2559
2521 2560 .l (or .list) : value as list.
2522 2561 .n (or .nlstr): value as newline-separated string.
2523 2562 .s (or .spstr): value as space-separated string.
2524 2563 """
2525 2564
2526 2565 opts,args = self.parse_options(parameter_s,'lv')
2527 2566 # Try to get a variable name and command to run
2528 2567 try:
2529 2568 # the variable name must be obtained from the parse_options
2530 2569 # output, which uses shlex.split to strip options out.
2531 2570 var,_ = args.split('=',1)
2532 2571 var = var.strip()
2533 2572 # But the the command has to be extracted from the original input
2534 2573 # parameter_s, not on what parse_options returns, to avoid the
2535 2574 # quote stripping which shlex.split performs on it.
2536 2575 _,cmd = parameter_s.split('=',1)
2537 2576 except ValueError:
2538 2577 var,cmd = '',''
2539 2578 # If all looks ok, proceed
2540 2579 out,err = self.shell.getoutputerror(cmd)
2541 2580 if err:
2542 2581 print >> Term.cerr,err
2543 2582 if opts.has_key('l'):
2544 2583 out = SList(out.split('\n'))
2545 2584 else:
2546 2585 out = LSString(out)
2547 2586 if opts.has_key('v'):
2548 2587 print '%s ==\n%s' % (var,pformat(out))
2549 2588 if var:
2550 2589 self.shell.user_ns.update({var:out})
2551 2590 else:
2552 2591 return out
2553 2592
2554 2593 def magic_sx(self, parameter_s=''):
2555 2594 """Shell execute - run a shell command and capture its output.
2556 2595
2557 2596 %sx command
2558 2597
2559 2598 IPython will run the given command using commands.getoutput(), and
2560 2599 return the result formatted as a list (split on '\\n'). Since the
2561 2600 output is _returned_, it will be stored in ipython's regular output
2562 2601 cache Out[N] and in the '_N' automatic variables.
2563 2602
2564 2603 Notes:
2565 2604
2566 2605 1) If an input line begins with '!!', then %sx is automatically
2567 2606 invoked. That is, while:
2568 2607 !ls
2569 2608 causes ipython to simply issue system('ls'), typing
2570 2609 !!ls
2571 2610 is a shorthand equivalent to:
2572 2611 %sx ls
2573 2612
2574 2613 2) %sx differs from %sc in that %sx automatically splits into a list,
2575 2614 like '%sc -l'. The reason for this is to make it as easy as possible
2576 2615 to process line-oriented shell output via further python commands.
2577 2616 %sc is meant to provide much finer control, but requires more
2578 2617 typing.
2579 2618
2580 2619 3) Just like %sc -l, this is a list with special attributes:
2581 2620
2582 2621 .l (or .list) : value as list.
2583 2622 .n (or .nlstr): value as newline-separated string.
2584 2623 .s (or .spstr): value as whitespace-separated string.
2585 2624
2586 2625 This is very useful when trying to use such lists as arguments to
2587 2626 system commands."""
2588 2627
2589 2628 if parameter_s:
2590 2629 out,err = self.shell.getoutputerror(parameter_s)
2591 2630 if err:
2592 2631 print >> Term.cerr,err
2593 2632 return SList(out.split('\n'))
2594 2633
2595 2634 def magic_bg(self, parameter_s=''):
2596 2635 """Run a job in the background, in a separate thread.
2597 2636
2598 2637 For example,
2599 2638
2600 2639 %bg myfunc(x,y,z=1)
2601 2640
2602 2641 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2603 2642 execution starts, a message will be printed indicating the job
2604 2643 number. If your job number is 5, you can use
2605 2644
2606 2645 myvar = jobs.result(5) or myvar = jobs[5].result
2607 2646
2608 2647 to assign this result to variable 'myvar'.
2609 2648
2610 2649 IPython has a job manager, accessible via the 'jobs' object. You can
2611 2650 type jobs? to get more information about it, and use jobs.<TAB> to see
2612 2651 its attributes. All attributes not starting with an underscore are
2613 2652 meant for public use.
2614 2653
2615 2654 In particular, look at the jobs.new() method, which is used to create
2616 2655 new jobs. This magic %bg function is just a convenience wrapper
2617 2656 around jobs.new(), for expression-based jobs. If you want to create a
2618 2657 new job with an explicit function object and arguments, you must call
2619 2658 jobs.new() directly.
2620 2659
2621 2660 The jobs.new docstring also describes in detail several important
2622 2661 caveats associated with a thread-based model for background job
2623 2662 execution. Type jobs.new? for details.
2624 2663
2625 2664 You can check the status of all jobs with jobs.status().
2626 2665
2627 2666 The jobs variable is set by IPython into the Python builtin namespace.
2628 2667 If you ever declare a variable named 'jobs', you will shadow this
2629 2668 name. You can either delete your global jobs variable to regain
2630 2669 access to the job manager, or make a new name and assign it manually
2631 2670 to the manager (stored in IPython's namespace). For example, to
2632 2671 assign the job manager to the Jobs name, use:
2633 2672
2634 2673 Jobs = __builtins__.jobs"""
2635 2674
2636 2675 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2637 2676
2638 2677
2639 2678 def magic_bookmark(self, parameter_s=''):
2640 2679 """Manage IPython's bookmark system.
2641 2680
2642 2681 %bookmark <name> - set bookmark to current dir
2643 2682 %bookmark <name> <dir> - set bookmark to <dir>
2644 2683 %bookmark -l - list all bookmarks
2645 2684 %bookmark -d <name> - remove bookmark
2646 2685 %bookmark -r - remove all bookmarks
2647 2686
2648 2687 You can later on access a bookmarked folder with:
2649 2688 %cd -b <name>
2650 2689 or simply '%cd <name>' if there is no directory called <name> AND
2651 2690 there is such a bookmark defined.
2652 2691
2653 2692 Your bookmarks persist through IPython sessions, but they are
2654 2693 associated with each profile."""
2655 2694
2656 2695 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2657 2696 if len(args) > 2:
2658 2697 error('You can only give at most two arguments')
2659 2698 return
2660 2699
2661 2700 bkms = self.db.get('bookmarks',{})
2662 2701
2663 2702 if opts.has_key('d'):
2664 2703 try:
2665 2704 todel = args[0]
2666 2705 except IndexError:
2667 2706 error('You must provide a bookmark to delete')
2668 2707 else:
2669 2708 try:
2670 2709 del bkms[todel]
2671 2710 except:
2672 2711 error("Can't delete bookmark '%s'" % todel)
2673 2712 elif opts.has_key('r'):
2674 2713 bkms = {}
2675 2714 elif opts.has_key('l'):
2676 2715 bks = bkms.keys()
2677 2716 bks.sort()
2678 2717 if bks:
2679 2718 size = max(map(len,bks))
2680 2719 else:
2681 2720 size = 0
2682 2721 fmt = '%-'+str(size)+'s -> %s'
2683 2722 print 'Current bookmarks:'
2684 2723 for bk in bks:
2685 2724 print fmt % (bk,bkms[bk])
2686 2725 else:
2687 2726 if not args:
2688 2727 error("You must specify the bookmark name")
2689 2728 elif len(args)==1:
2690 2729 bkms[args[0]] = os.getcwd()
2691 2730 elif len(args)==2:
2692 2731 bkms[args[0]] = args[1]
2693 2732 self.db['bookmarks'] = bkms
2694 2733
2695 2734 def magic_pycat(self, parameter_s=''):
2696 2735 """Show a syntax-highlighted file through a pager.
2697 2736
2698 2737 This magic is similar to the cat utility, but it will assume the file
2699 2738 to be Python source and will show it with syntax highlighting. """
2700 2739
2701 2740 try:
2702 2741 filename = get_py_filename(parameter_s)
2703 2742 cont = file_read(filename)
2704 2743 except IOError:
2705 2744 try:
2706 2745 cont = eval(parameter_s,self.user_ns)
2707 2746 except NameError:
2708 2747 cont = None
2709 2748 if cont is None:
2710 2749 print "Error: no such file or variable"
2711 2750 return
2712 2751
2713 2752 page(self.shell.pycolorize(cont),
2714 2753 screen_lines=self.shell.rc.screen_length)
2715 2754
2716 2755 def magic_cpaste(self, parameter_s=''):
2717 2756 """Allows you to paste & execute a pre-formatted code block from
2718 2757 clipboard.
2719 2758
2720 2759 You must terminate the block with '--' (two minus-signs) alone on the
2721 2760 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
2722 2761 is the new sentinel for this operation)
2723 2762
2724 2763 The block is dedented prior to execution to enable execution of
2725 2764 method definitions. The executed block is also assigned to variable
2726 2765 named 'pasted_block' for later editing with '%edit pasted_block'.
2727 2766
2728 2767 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
2729 2768 This assigns the pasted block to variable 'foo' as string, without
2730 2769 dedenting or executing it.
2731 2770
2732 2771 Do not be alarmed by garbled output on Windows (it's a readline bug).
2733 2772 Just press enter and type -- (and press enter again) and the block
2734 2773 will be what was just pasted.
2735 2774
2736 2775 IPython statements (magics, shell escapes) are not supported (yet).
2737 2776 """
2738 2777 opts,args = self.parse_options(parameter_s,'s:',mode='string')
2739 2778 par = args.strip()
2740 2779 sentinel = opts.get('s','--')
2741 2780
2742 2781 from IPython import iplib
2743 2782 lines = []
2744 2783 print "Pasting code; enter '%s' alone on the line to stop." % sentinel
2745 2784 while 1:
2746 2785 l = iplib.raw_input_original(':')
2747 2786 if l ==sentinel:
2748 2787 break
2749 2788 lines.append(l)
2750 2789 block = "\n".join(lines) + '\n'
2751 2790 #print "block:\n",block
2752 2791 if not par:
2753 2792 b = textwrap.dedent(block)
2754 2793 exec b in self.user_ns
2755 2794 self.user_ns['pasted_block'] = b
2756 2795 else:
2757 2796 self.user_ns[par] = block
2758 2797 print "Block assigned to '%s'" % par
2759 2798 def magic_quickref(self,arg):
2760 2799 import IPython.usage
2761 2800 page(IPython.usage.quick_reference)
2762 2801 del IPython.usage
2763 2802
2764 2803
2765 2804 # end Magic
@@ -1,311 +1,418 b''
1 1 """Module for interactive demos using IPython.
2 2
3 This module implements a single class, Demo, for running Python scripts
4 interactively in IPython for demonstrations. With very simple markup (a few
5 tags in comments), you can control points where the script stops executing and
6 returns control to IPython.
3 This module implements a few classes for running Python scripts interactively
4 in IPython for demonstrations. With very simple markup (a few tags in
5 comments), you can control points where the script stops executing and returns
6 control to IPython.
7
8 The classes are (see their docstrings for further details):
9
10 - Demo: pure python demos
11
12 - IPythonDemo: demos with input to be processed by IPython as if it had been
13 typed interactively (so magics work, as well as any other special syntax you
14 may have added via input prefilters).
15
16 - LineDemo: single-line version of the Demo class. These demos are executed
17 one line at a time, and require no markup.
18
19 - IPythonLineDemo: IPython version of the LineDemo class (the demo is
20 executed a line at a time, but processed via IPython).
21
7 22
8 23 The file is run in its own empty namespace (though you can pass it a string of
9 24 arguments as if in a command line environment, and it will see those as
10 25 sys.argv). But at each stop, the global IPython namespace is updated with the
11 26 current internal demo namespace, so you can work interactively with the data
12 27 accumulated so far.
13 28
14 29 By default, each block of code is printed (with syntax highlighting) before
15 30 executing it and you have to confirm execution. This is intended to show the
16 31 code to an audience first so you can discuss it, and only proceed with
17 32 execution once you agree. There are a few tags which allow you to modify this
18 33 behavior.
19 34
20 35 The supported tags are:
21 36
22 37 # <demo> --- stop ---
23 38
24 39 Defines block boundaries, the points where IPython stops execution of the
25 40 file and returns to the interactive prompt.
26 41
27 42 # <demo> silent
28 43
29 44 Make a block execute silently (and hence automatically). Typically used in
30 45 cases where you have some boilerplate or initialization code which you need
31 46 executed but do not want to be seen in the demo.
32 47
33 48 # <demo> auto
34 49
35 50 Make a block execute automatically, but still being printed. Useful for
36 51 simple code which does not warrant discussion, since it avoids the extra
37 52 manual confirmation.
38 53
39 54 # <demo> auto_all
40 55
41 56 This tag can _only_ be in the first block, and if given it overrides the
42 57 individual auto tags to make the whole demo fully automatic (no block asks
43 58 for confirmation). It can also be given at creation time (or the attribute
44 59 set later) to override what's in the file.
45 60
46 61 While _any_ python file can be run as a Demo instance, if there are no stop
47 62 tags the whole file will run in a single block (no different that calling
48 63 first %pycat and then %run). The minimal markup to make this useful is to
49 64 place a set of stop tags; the other tags are only there to let you fine-tune
50 65 the execution.
51 66
52 67 This is probably best explained with the simple example file below. You can
53 68 copy this into a file named ex_demo.py, and try running it via:
54 69
55 70 from IPython.demo import Demo
56 71 d = Demo('ex_demo.py')
57 d() <--- Call the d object (omit the parens if you have autocall on).
72 d() <--- Call the d object (omit the parens if you have autocall set to 2).
58 73
59 74 Each time you call the demo object, it runs the next block. The demo object
60 has a few useful methods for navigation, like again(), jump(), seek() and
61 back(). It can be reset for a new run via reset() or reloaded from disk (in
62 case you've edited the source) via reload(). See their docstrings below.
75 has a few useful methods for navigation, like again(), edit(), jump(), seek()
76 and back(). It can be reset for a new run via reset() or reloaded from disk
77 (in case you've edited the source) via reload(). See their docstrings below.
63 78
64 79 #################### EXAMPLE DEMO <ex_demo.py> ###############################
65 80 '''A simple interactive demo to illustrate the use of IPython's Demo class.'''
66 81
67 82 print 'Hello, welcome to an interactive IPython demo.'
68 83
69 84 # The mark below defines a block boundary, which is a point where IPython will
70 85 # stop execution and return to the interactive prompt.
71 86 # Note that in actual interactive execution,
72 87 # <demo> --- stop ---
73 88
74 89 x = 1
75 90 y = 2
76 91
77 92 # <demo> --- stop ---
78 93
79 94 # the mark below makes this block as silent
80 95 # <demo> silent
81 96
82 97 print 'This is a silent block, which gets executed but not printed.'
83 98
84 99 # <demo> --- stop ---
85 100 # <demo> auto
86 101 print 'This is an automatic block.'
87 102 print 'It is executed without asking for confirmation, but printed.'
88 103 z = x+y
89 104
90 105 print 'z=',x
91 106
92 107 # <demo> --- stop ---
93 108 # This is just another normal block.
94 109 print 'z is now:', z
95 110
96 111 print 'bye!'
97 112 ################### END EXAMPLE DEMO <ex_demo.py> ############################
98
99 WARNING: this module uses Python 2.3 features, so it won't work in 2.2
100 environments.
101 113 """
102 114 #*****************************************************************************
103 115 # Copyright (C) 2005-2006 Fernando Perez. <Fernando.Perez@colorado.edu>
104 116 #
105 117 # Distributed under the terms of the BSD License. The full license is in
106 118 # the file COPYING, distributed as part of this software.
107 119 #
108 120 #*****************************************************************************
109 121
110 122 import exceptions
123 import os
111 124 import re
112 125 import sys
113 126
114 127 from IPython.PyColorize import Parser
115 from IPython.genutils import marquee, shlex_split, file_read
128 from IPython.genutils import marquee, shlex_split, file_read, file_readlines
116 129
117 __all__ = ['Demo','DemoError']
130 __all__ = ['Demo','IPythonDemo','LineDemo','IPythonLineDemo','DemoError']
118 131
119 132 class DemoError(exceptions.Exception): pass
120 133
121 134 def re_mark(mark):
122 135 return re.compile(r'^\s*#\s+<demo>\s+%s\s*$' % mark,re.MULTILINE)
123 136
124 137 class Demo:
125 138
126 139 re_stop = re_mark('---\s?stop\s?---')
127 140 re_silent = re_mark('silent')
128 141 re_auto = re_mark('auto')
129 142 re_auto_all = re_mark('auto_all')
130 143
131 144 def __init__(self,fname,arg_str='',auto_all=None):
132 145 """Make a new demo object. To run the demo, simply call the object.
133 146
134 147 See the module docstring for full details and an example (you can use
135 148 IPython.Demo? in IPython to see it).
136 149
137 150 Inputs:
138 151
139 152 - fname = filename.
140 153
141 154 Optional inputs:
142 155
143 156 - arg_str(''): a string of arguments, internally converted to a list
144 157 just like sys.argv, so the demo script can see a similar
145 158 environment.
146 159
147 160 - auto_all(None): global flag to run all blocks automatically without
148 161 confirmation. This attribute overrides the block-level tags and
149 162 applies to the whole demo. It is an attribute of the object, and
150 163 can be changed at runtime simply by reassigning it to a boolean
151 164 value.
152 165 """
153
166
154 167 self.fname = fname
155 168 self.sys_argv = [fname] + shlex_split(arg_str)
156 169 self.auto_all = auto_all
157 170
158 171 # get a few things from ipython. While it's a bit ugly design-wise,
159 172 # it ensures that things like color scheme and the like are always in
160 173 # sync with the ipython mode being used. This class is only meant to
161 174 # be used inside ipython anyways, so it's OK.
162 self.ip_showtb = __IPYTHON__.showtraceback
163 175 self.ip_ns = __IPYTHON__.user_ns
164 176 self.ip_colorize = __IPYTHON__.pycolorize
177 self.ip_showtb = __IPYTHON__.showtraceback
178 self.ip_runlines = __IPYTHON__.runlines
179 self.shell = __IPYTHON__
165 180
166 181 # load user data and initialize data structures
167 182 self.reload()
168 183
169 184 def reload(self):
170 185 """Reload source from disk and initialize state."""
171 186 # read data and parse into blocks
172 187 self.src = file_read(self.fname)
173 188 src_b = [b.strip() for b in self.re_stop.split(self.src) if b]
174 189 self._silent = [bool(self.re_silent.findall(b)) for b in src_b]
175 190 self._auto = [bool(self.re_auto.findall(b)) for b in src_b]
176 191
177 192 # if auto_all is not given (def. None), we read it from the file
178 193 if self.auto_all is None:
179 194 self.auto_all = bool(self.re_auto_all.findall(src_b[0]))
180 195 else:
181 196 self.auto_all = bool(self.auto_all)
182 197
183 198 # Clean the sources from all markup so it doesn't get displayed when
184 199 # running the demo
185 200 src_blocks = []
186 201 auto_strip = lambda s: self.re_auto.sub('',s)
187 202 for i,b in enumerate(src_b):
188 203 if self._auto[i]:
189 204 src_blocks.append(auto_strip(b))
190 205 else:
191 206 src_blocks.append(b)
192 207 # remove the auto_all marker
193 208 src_blocks[0] = self.re_auto_all.sub('',src_blocks[0])
194 209
195 210 self.nblocks = len(src_blocks)
196 211 self.src_blocks = src_blocks
197 212
198 213 # also build syntax-highlighted source
199 214 self.src_blocks_colored = map(self.ip_colorize,self.src_blocks)
200 215
201 216 # ensure clean namespace and seek offset
202 217 self.reset()
203 218
204 219 def reset(self):
205 220 """Reset the namespace and seek pointer to restart the demo"""
206 221 self.user_ns = {}
207 222 self.finished = False
208 223 self.block_index = 0
209 224
210 225 def _validate_index(self,index):
211 226 if index<0 or index>=self.nblocks:
212 227 raise ValueError('invalid block index %s' % index)
213 228
229 def _get_index(self,index):
230 """Get the current block index, validating and checking status.
231
232 Returns None if the demo is finished"""
233
234 if index is None:
235 if self.finished:
236 print 'Demo finished. Use reset() if you want to rerun it.'
237 return None
238 index = self.block_index
239 else:
240 self._validate_index(index)
241 return index
242
214 243 def seek(self,index):
215 244 """Move the current seek pointer to the given block"""
216 245 self._validate_index(index)
217 246 self.block_index = index
218 247 self.finished = False
219 248
220 249 def back(self,num=1):
221 250 """Move the seek pointer back num blocks (default is 1)."""
222 251 self.seek(self.block_index-num)
223 252
224 253 def jump(self,num):
225 254 """Jump a given number of blocks relative to the current one."""
226 255 self.seek(self.block_index+num)
227 256
228 257 def again(self):
229 258 """Move the seek pointer back one block and re-execute."""
230 259 self.back(1)
231 260 self()
232 261
262 def edit(self,index=None):
263 """Edit a block.
264
265 If no number is given, use the last block executed.
266
267 This edits the in-memory copy of the demo, it does NOT modify the
268 original source file. If you want to do that, simply open the file in
269 an editor and use reload() when you make changes to the file. This
270 method is meant to let you change a block during a demonstration for
271 explanatory purposes, without damaging your original script."""
272
273 index = self._get_index(index)
274 if index is None:
275 return
276 # decrease the index by one (unless we're at the very beginning), so
277 # that the default demo.edit() call opens up the sblock we've last run
278 if index>0:
279 index -= 1
280
281 filename = self.shell.mktempfile(self.src_blocks[index])
282 self.shell.hooks.editor(filename,1)
283 new_block = file_read(filename)
284 # update the source and colored block
285 self.src_blocks[index] = new_block
286 self.src_blocks_colored[index] = self.ip_colorize(new_block)
287 self.block_index = index
288 # call to run with the newly edited index
289 self()
290
233 291 def show(self,index=None):
234 292 """Show a single block on screen"""
293
294 index = self._get_index(index)
235 295 if index is None:
236 if self.finished:
237 print 'Demo finished. Use reset() if you want to rerun it.'
238 return
239 index = self.block_index
240 else:
241 self._validate_index(index)
296 return
297
242 298 print marquee('<%s> block # %s (%s remaining)' %
243 299 (self.fname,index,self.nblocks-index-1))
244 300 print self.src_blocks_colored[index],
245 301 sys.stdout.flush()
246 302
247 303 def show_all(self):
248 304 """Show entire demo on screen, block by block"""
249 305
250 306 fname = self.fname
251 307 nblocks = self.nblocks
252 308 silent = self._silent
253 309 for index,block in enumerate(self.src_blocks_colored):
254 310 if silent[index]:
255 311 print marquee('<%s> SILENT block # %s (%s remaining)' %
256 312 (fname,index,nblocks-index-1))
257 313 else:
258 314 print marquee('<%s> block # %s (%s remaining)' %
259 315 (fname,index,nblocks-index-1))
260 316 print block,
261 317 sys.stdout.flush()
262
318
319 def runlines(self,source):
320 """Execute a string with one or more lines of code"""
321
322 exec source in self.user_ns
323
263 324 def __call__(self,index=None):
264 325 """run a block of the demo.
265 326
266 327 If index is given, it should be an integer >=1 and <= nblocks. This
267 328 means that the calling convention is one off from typical Python
268 329 lists. The reason for the inconsistency is that the demo always
269 330 prints 'Block n/N, and N is the total, so it would be very odd to use
270 331 zero-indexing here."""
271 332
272 if index is None and self.finished:
273 print 'Demo finished. Use reset() if you want to rerun it.'
274 return
333 index = self._get_index(index)
275 334 if index is None:
276 index = self.block_index
277 self._validate_index(index)
335 return
278 336 try:
279 337 next_block = self.src_blocks[index]
280 338 self.block_index += 1
281 339 if self._silent[index]:
282 340 print marquee('Executing silent block # %s (%s remaining)' %
283 341 (index,self.nblocks-index-1))
284 342 else:
285 343 self.show(index)
286 344 if self.auto_all or self._auto[index]:
287 345 print marquee('output')
288 346 else:
289 347 print marquee('Press <q> to quit, <Enter> to execute...'),
290 348 ans = raw_input().strip()
291 349 if ans:
292 350 print marquee('Block NOT executed')
293 351 return
294 352 try:
295 353 save_argv = sys.argv
296 354 sys.argv = self.sys_argv
297 exec next_block in self.user_ns
355 self.runlines(next_block)
298 356 finally:
299 357 sys.argv = save_argv
300 358
301 359 except:
302 360 self.ip_showtb(filename=self.fname)
303 361 else:
304 362 self.ip_ns.update(self.user_ns)
305 363
306 364 if self.block_index == self.nblocks:
307 365 print
308 366 print marquee(' END OF DEMO ')
309 367 print marquee('Use reset() if you want to rerun it.')
310 368 self.finished = True
311 369
370 class IPythonDemo(Demo):
371 """Class for interactive demos with IPython's input processing applied.
372
373 This subclasses Demo, but instead of executing each block by the Python
374 interpreter (via exec), it actually calls IPython on it, so that any input
375 filters which may be in place are applied to the input block.
376
377 If you have an interactive environment which exposes special input
378 processing, you can use this class instead to write demo scripts which
379 operate exactly as if you had typed them interactively. The default Demo
380 class requires the input to be valid, pure Python code.
381 """
382
383 def runlines(self,source):
384 """Execute a string with one or more lines of code"""
385
386 self.runlines(source)
387
388 class LineDemo(Demo):
389 """Demo where each line is executed as a separate block.
390
391 The input script should be valid Python code.
392
393 This class doesn't require any markup at all, and it's meant for simple
394 scripts (with no nesting or any kind of indentation) which consist of
395 multiple lines of input to be executed, one at a time, as if they had been
396 typed in the interactive prompt."""
397
398 def reload(self):
399 """Reload source from disk and initialize state."""
400 # read data and parse into blocks
401 src_b = [l for l in file_readlines(self.fname) if l.strip()]
402 nblocks = len(src_b)
403 self.src = os.linesep.join(file_readlines(self.fname))
404 self._silent = [False]*nblocks
405 self._auto = [True]*nblocks
406 self.auto_all = True
407 self.nblocks = nblocks
408 self.src_blocks = src_b
409
410 # also build syntax-highlighted source
411 self.src_blocks_colored = map(self.ip_colorize,self.src_blocks)
412
413 # ensure clean namespace and seek offset
414 self.reset()
415
416 class IPythonLineDemo(IPythonDemo,LineDemo):
417 """Variant of the LineDemo class whose input is processed by IPython."""
418 pass
@@ -1,1761 +1,1768 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 General purpose utilities.
4 4
5 5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 6 these things are also convenient when working at the command line.
7 7
8 $Id: genutils.py 1110 2006-01-30 20:43:30Z vivainio $"""
8 $Id: genutils.py 1126 2006-02-06 02:31:40Z fperez $"""
9 9
10 10 #*****************************************************************************
11 11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
12 12 #
13 13 # Distributed under the terms of the BSD License. The full license is in
14 14 # the file COPYING, distributed as part of this software.
15 15 #*****************************************************************************
16 16
17 17 from __future__ import generators # 2.2 compatibility
18 18
19 19 from IPython import Release
20 20 __author__ = '%s <%s>' % Release.authors['Fernando']
21 21 __license__ = Release.license
22 22
23 23 #****************************************************************************
24 24 # required modules from the Python standard library
25 25 import __main__
26 26 import commands
27 27 import os
28 28 import re
29 29 import shlex
30 30 import shutil
31 31 import sys
32 32 import tempfile
33 33 import time
34 34 import types
35 35
36 36 # Other IPython utilities
37 37 from IPython.Itpl import Itpl,itpl,printpl
38 38 from IPython import DPyGetOpt
39 39 from path import path
40 40 if os.name == "nt":
41 41 from IPython.winconsole import get_console_size
42 42
43 43 # Build objects which appeared in Python 2.3 for 2.2, to make ipython
44 44 # 2.2-friendly
45 45 try:
46 46 basestring
47 47 except NameError:
48 48 import types
49 49 basestring = (types.StringType, types.UnicodeType)
50 50 True = 1==1
51 51 False = 1==0
52 52
53 53 def enumerate(obj):
54 54 i = -1
55 55 for item in obj:
56 56 i += 1
57 57 yield i, item
58 58
59 59 # add these to the builtin namespace, so that all modules find them
60 60 import __builtin__
61 61 __builtin__.basestring = basestring
62 62 __builtin__.True = True
63 63 __builtin__.False = False
64 64 __builtin__.enumerate = enumerate
65 65
66 66 # Try to use shlex.split for converting an input string into a sys.argv-type
67 67 # list. This appeared in Python 2.3, so here's a quick backport for 2.2.
68 68 try:
69 69 shlex_split = shlex.split
70 70 except AttributeError:
71 71 _quotesre = re.compile(r'[\'"](.*)[\'"]')
72 72 _wordchars = ('abcdfeghijklmnopqrstuvwxyz'
73 73 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~*?'
74 74 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
75 75 'À�ÂÃÄÅÆÇÈÉÊËÌ�Î��ÑÒÓÔÕÖØÙÚÛÜ�Þ%s'
76 76 % os.sep)
77 77
78 78 def shlex_split(s):
79 79 """Simplified backport to Python 2.2 of shlex.split().
80 80
81 81 This is a quick and dirty hack, since the shlex module under 2.2 lacks
82 82 several of the features needed to really match the functionality of
83 83 shlex.split() in 2.3."""
84 84
85 85 lex = shlex.shlex(StringIO(s))
86 86 # Try to get options, extensions and path separators as characters
87 87 lex.wordchars = _wordchars
88 88 lex.commenters = ''
89 89 # Make a list out of the lexer by hand, since in 2.2 it's not an
90 90 # iterator.
91 91 lout = []
92 92 while 1:
93 93 token = lex.get_token()
94 94 if token == '':
95 95 break
96 96 # Try to handle quoted tokens correctly
97 97 quotes = _quotesre.match(token)
98 98 if quotes:
99 99 token = quotes.group(1)
100 100 lout.append(token)
101 101 return lout
102 102
103 103 #****************************************************************************
104 104 # Exceptions
105 105 class Error(Exception):
106 106 """Base class for exceptions in this module."""
107 107 pass
108 108
109 109 #----------------------------------------------------------------------------
110 110 class IOStream:
111 111 def __init__(self,stream,fallback):
112 112 if not hasattr(stream,'write') or not hasattr(stream,'flush'):
113 113 stream = fallback
114 114 self.stream = stream
115 115 self._swrite = stream.write
116 116 self.flush = stream.flush
117 117
118 118 def write(self,data):
119 119 try:
120 120 self._swrite(data)
121 121 except:
122 122 try:
123 123 # print handles some unicode issues which may trip a plain
124 124 # write() call. Attempt to emulate write() by using a
125 125 # trailing comma
126 126 print >> self.stream, data,
127 127 except:
128 128 # if we get here, something is seriously broken.
129 129 print >> sys.stderr, \
130 130 'ERROR - failed to write data to stream:', stream
131 131
132 132 class IOTerm:
133 133 """ Term holds the file or file-like objects for handling I/O operations.
134 134
135 135 These are normally just sys.stdin, sys.stdout and sys.stderr but for
136 136 Windows they can can replaced to allow editing the strings before they are
137 137 displayed."""
138 138
139 139 # In the future, having IPython channel all its I/O operations through
140 140 # this class will make it easier to embed it into other environments which
141 141 # are not a normal terminal (such as a GUI-based shell)
142 142 def __init__(self,cin=None,cout=None,cerr=None):
143 143 self.cin = IOStream(cin,sys.stdin)
144 144 self.cout = IOStream(cout,sys.stdout)
145 145 self.cerr = IOStream(cerr,sys.stderr)
146 146
147 147 # Global variable to be used for all I/O
148 148 Term = IOTerm()
149 149
150 150 import IPython.rlineimpl as readline
151 151 # Remake Term to use the readline i/o facilities
152 152 if sys.platform == 'win32' and readline.have_readline:
153 153
154 154 Term = IOTerm(cout=readline._outputfile,cerr=readline._outputfile)
155 155
156 156
157 157 #****************************************************************************
158 158 # Generic warning/error printer, used by everything else
159 159 def warn(msg,level=2,exit_val=1):
160 160 """Standard warning printer. Gives formatting consistency.
161 161
162 162 Output is sent to Term.cerr (sys.stderr by default).
163 163
164 164 Options:
165 165
166 166 -level(2): allows finer control:
167 167 0 -> Do nothing, dummy function.
168 168 1 -> Print message.
169 169 2 -> Print 'WARNING:' + message. (Default level).
170 170 3 -> Print 'ERROR:' + message.
171 171 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
172 172
173 173 -exit_val (1): exit value returned by sys.exit() for a level 4
174 174 warning. Ignored for all other levels."""
175 175
176 176 if level>0:
177 177 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
178 178 print >> Term.cerr, '%s%s' % (header[level],msg)
179 179 if level == 4:
180 180 print >> Term.cerr,'Exiting.\n'
181 181 sys.exit(exit_val)
182 182
183 183 def info(msg):
184 184 """Equivalent to warn(msg,level=1)."""
185 185
186 186 warn(msg,level=1)
187 187
188 188 def error(msg):
189 189 """Equivalent to warn(msg,level=3)."""
190 190
191 191 warn(msg,level=3)
192 192
193 193 def fatal(msg,exit_val=1):
194 194 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
195 195
196 196 warn(msg,exit_val=exit_val,level=4)
197 197
198 198 #---------------------------------------------------------------------------
199 199 # Debugging routines
200 200 #
201 201 def debugx(expr,pre_msg=''):
202 202 """Print the value of an expression from the caller's frame.
203 203
204 204 Takes an expression, evaluates it in the caller's frame and prints both
205 205 the given expression and the resulting value (as well as a debug mark
206 206 indicating the name of the calling function. The input must be of a form
207 207 suitable for eval().
208 208
209 209 An optional message can be passed, which will be prepended to the printed
210 210 expr->value pair."""
211 211
212 212 cf = sys._getframe(1)
213 213 print '[DBG:%s] %s%s -> %r' % (cf.f_code.co_name,pre_msg,expr,
214 214 eval(expr,cf.f_globals,cf.f_locals))
215 215
216 216 # deactivate it by uncommenting the following line, which makes it a no-op
217 217 #def debugx(expr,pre_msg=''): pass
218 218
219 219 #----------------------------------------------------------------------------
220 220 StringTypes = types.StringTypes
221 221
222 222 # Basic timing functionality
223 223
224 224 # If possible (Unix), use the resource module instead of time.clock()
225 225 try:
226 226 import resource
227 227 def clock():
228 228 """clock() -> floating point number
229 229
230 230 Return the CPU time in seconds (user time only, system time is
231 231 ignored) since the start of the process. This is done via a call to
232 232 resource.getrusage, so it avoids the wraparound problems in
233 233 time.clock()."""
234 234
235 235 return resource.getrusage(resource.RUSAGE_SELF)[0]
236 236
237 237 def clock2():
238 238 """clock2() -> (t_user,t_system)
239 239
240 240 Similar to clock(), but return a tuple of user/system times."""
241 241 return resource.getrusage(resource.RUSAGE_SELF)[:2]
242 242
243 243 except ImportError:
244 244 clock = time.clock
245 245 def clock2():
246 246 """Under windows, system CPU time can't be measured.
247 247
248 248 This just returns clock() and zero."""
249 249 return time.clock(),0.0
250 250
251 251 def timings_out(reps,func,*args,**kw):
252 252 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
253 253
254 254 Execute a function reps times, return a tuple with the elapsed total
255 255 CPU time in seconds, the time per call and the function's output.
256 256
257 257 Under Unix, the return value is the sum of user+system time consumed by
258 258 the process, computed via the resource module. This prevents problems
259 259 related to the wraparound effect which the time.clock() function has.
260 260
261 261 Under Windows the return value is in wall clock seconds. See the
262 262 documentation for the time module for more details."""
263 263
264 264 reps = int(reps)
265 265 assert reps >=1, 'reps must be >= 1'
266 266 if reps==1:
267 267 start = clock()
268 268 out = func(*args,**kw)
269 269 tot_time = clock()-start
270 270 else:
271 271 rng = xrange(reps-1) # the last time is executed separately to store output
272 272 start = clock()
273 273 for dummy in rng: func(*args,**kw)
274 274 out = func(*args,**kw) # one last time
275 275 tot_time = clock()-start
276 276 av_time = tot_time / reps
277 277 return tot_time,av_time,out
278 278
279 279 def timings(reps,func,*args,**kw):
280 280 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
281 281
282 282 Execute a function reps times, return a tuple with the elapsed total CPU
283 283 time in seconds and the time per call. These are just the first two values
284 284 in timings_out()."""
285 285
286 286 return timings_out(reps,func,*args,**kw)[0:2]
287 287
288 288 def timing(func,*args,**kw):
289 289 """timing(func,*args,**kw) -> t_total
290 290
291 291 Execute a function once, return the elapsed total CPU time in
292 292 seconds. This is just the first value in timings_out()."""
293 293
294 294 return timings_out(1,func,*args,**kw)[0]
295 295
296 296 #****************************************************************************
297 297 # file and system
298 298
299 299 def system(cmd,verbose=0,debug=0,header=''):
300 300 """Execute a system command, return its exit status.
301 301
302 302 Options:
303 303
304 304 - verbose (0): print the command to be executed.
305 305
306 306 - debug (0): only print, do not actually execute.
307 307
308 308 - header (''): Header to print on screen prior to the executed command (it
309 309 is only prepended to the command, no newlines are added).
310 310
311 311 Note: a stateful version of this function is available through the
312 312 SystemExec class."""
313 313
314 314 stat = 0
315 315 if verbose or debug: print header+cmd
316 316 sys.stdout.flush()
317 317 if not debug: stat = os.system(cmd)
318 318 return stat
319 319
320 320 # This function is used by ipython in a lot of places to make system calls.
321 321 # We need it to be slightly different under win32, due to the vagaries of
322 322 # 'network shares'. A win32 override is below.
323 323
324 324 def shell(cmd,verbose=0,debug=0,header=''):
325 325 """Execute a command in the system shell, always return None.
326 326
327 327 Options:
328 328
329 329 - verbose (0): print the command to be executed.
330 330
331 331 - debug (0): only print, do not actually execute.
332 332
333 333 - header (''): Header to print on screen prior to the executed command (it
334 334 is only prepended to the command, no newlines are added).
335 335
336 336 Note: this is similar to genutils.system(), but it returns None so it can
337 337 be conveniently used in interactive loops without getting the return value
338 338 (typically 0) printed many times."""
339 339
340 340 stat = 0
341 341 if verbose or debug: print header+cmd
342 342 # flush stdout so we don't mangle python's buffering
343 343 sys.stdout.flush()
344 344 if not debug:
345 345 os.system(cmd)
346 346
347 347 # override shell() for win32 to deal with network shares
348 348 if os.name in ('nt','dos'):
349 349
350 350 shell_ori = shell
351 351
352 352 def shell(cmd,verbose=0,debug=0,header=''):
353 353 if os.getcwd().startswith(r"\\"):
354 354 path = os.getcwd()
355 355 # change to c drive (cannot be on UNC-share when issuing os.system,
356 356 # as cmd.exe cannot handle UNC addresses)
357 357 os.chdir("c:")
358 358 # issue pushd to the UNC-share and then run the command
359 359 try:
360 360 shell_ori('"pushd %s&&"'%path+cmd,verbose,debug,header)
361 361 finally:
362 362 os.chdir(path)
363 363 else:
364 364 shell_ori(cmd,verbose,debug,header)
365 365
366 366 shell.__doc__ = shell_ori.__doc__
367 367
368 368 def getoutput(cmd,verbose=0,debug=0,header='',split=0):
369 369 """Dummy substitute for perl's backquotes.
370 370
371 371 Executes a command and returns the output.
372 372
373 373 Accepts the same arguments as system(), plus:
374 374
375 375 - split(0): if true, the output is returned as a list split on newlines.
376 376
377 377 Note: a stateful version of this function is available through the
378 378 SystemExec class."""
379 379
380 380 if verbose or debug: print header+cmd
381 381 if not debug:
382 382 output = commands.getoutput(cmd)
383 383 if split:
384 384 return output.split('\n')
385 385 else:
386 386 return output
387 387
388 388 def getoutputerror(cmd,verbose=0,debug=0,header='',split=0):
389 389 """Return (standard output,standard error) of executing cmd in a shell.
390 390
391 391 Accepts the same arguments as system(), plus:
392 392
393 393 - split(0): if true, each of stdout/err is returned as a list split on
394 394 newlines.
395 395
396 396 Note: a stateful version of this function is available through the
397 397 SystemExec class."""
398 398
399 399 if verbose or debug: print header+cmd
400 400 if not cmd:
401 401 if split:
402 402 return [],[]
403 403 else:
404 404 return '',''
405 405 if not debug:
406 406 pin,pout,perr = os.popen3(cmd)
407 407 tout = pout.read().rstrip()
408 408 terr = perr.read().rstrip()
409 409 pin.close()
410 410 pout.close()
411 411 perr.close()
412 412 if split:
413 413 return tout.split('\n'),terr.split('\n')
414 414 else:
415 415 return tout,terr
416 416
417 417 # for compatibility with older naming conventions
418 418 xsys = system
419 419 bq = getoutput
420 420
421 421 class SystemExec:
422 422 """Access the system and getoutput functions through a stateful interface.
423 423
424 424 Note: here we refer to the system and getoutput functions from this
425 425 library, not the ones from the standard python library.
426 426
427 427 This class offers the system and getoutput functions as methods, but the
428 428 verbose, debug and header parameters can be set for the instance (at
429 429 creation time or later) so that they don't need to be specified on each
430 430 call.
431 431
432 432 For efficiency reasons, there's no way to override the parameters on a
433 433 per-call basis other than by setting instance attributes. If you need
434 434 local overrides, it's best to directly call system() or getoutput().
435 435
436 436 The following names are provided as alternate options:
437 437 - xsys: alias to system
438 438 - bq: alias to getoutput
439 439
440 440 An instance can then be created as:
441 441 >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ')
442 442
443 443 And used as:
444 444 >>> sysexec.xsys('pwd')
445 445 >>> dirlist = sysexec.bq('ls -l')
446 446 """
447 447
448 448 def __init__(self,verbose=0,debug=0,header='',split=0):
449 449 """Specify the instance's values for verbose, debug and header."""
450 450 setattr_list(self,'verbose debug header split')
451 451
452 452 def system(self,cmd):
453 453 """Stateful interface to system(), with the same keyword parameters."""
454 454
455 455 system(cmd,self.verbose,self.debug,self.header)
456 456
457 457 def shell(self,cmd):
458 458 """Stateful interface to shell(), with the same keyword parameters."""
459 459
460 460 shell(cmd,self.verbose,self.debug,self.header)
461 461
462 462 xsys = system # alias
463 463
464 464 def getoutput(self,cmd):
465 465 """Stateful interface to getoutput()."""
466 466
467 467 return getoutput(cmd,self.verbose,self.debug,self.header,self.split)
468 468
469 469 def getoutputerror(self,cmd):
470 470 """Stateful interface to getoutputerror()."""
471 471
472 472 return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split)
473 473
474 474 bq = getoutput # alias
475 475
476 476 #-----------------------------------------------------------------------------
477 477 def mutex_opts(dict,ex_op):
478 478 """Check for presence of mutually exclusive keys in a dict.
479 479
480 480 Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]"""
481 481 for op1,op2 in ex_op:
482 482 if op1 in dict and op2 in dict:
483 483 raise ValueError,'\n*** ERROR in Arguments *** '\
484 484 'Options '+op1+' and '+op2+' are mutually exclusive.'
485 485
486 486 #-----------------------------------------------------------------------------
487 487 def get_py_filename(name):
488 488 """Return a valid python filename in the current directory.
489 489
490 490 If the given name is not a file, it adds '.py' and searches again.
491 491 Raises IOError with an informative message if the file isn't found."""
492 492
493 493 name = os.path.expanduser(name)
494 494 if not os.path.isfile(name) and not name.endswith('.py'):
495 495 name += '.py'
496 496 if os.path.isfile(name):
497 497 return name
498 498 else:
499 499 raise IOError,'File `%s` not found.' % name
500 500
501 501 #-----------------------------------------------------------------------------
502 502 def filefind(fname,alt_dirs = None):
503 503 """Return the given filename either in the current directory, if it
504 504 exists, or in a specified list of directories.
505 505
506 506 ~ expansion is done on all file and directory names.
507 507
508 508 Upon an unsuccessful search, raise an IOError exception."""
509 509
510 510 if alt_dirs is None:
511 511 try:
512 512 alt_dirs = get_home_dir()
513 513 except HomeDirError:
514 514 alt_dirs = os.getcwd()
515 515 search = [fname] + list_strings(alt_dirs)
516 516 search = map(os.path.expanduser,search)
517 517 #print 'search list for',fname,'list:',search # dbg
518 518 fname = search[0]
519 519 if os.path.isfile(fname):
520 520 return fname
521 521 for direc in search[1:]:
522 522 testname = os.path.join(direc,fname)
523 523 #print 'testname',testname # dbg
524 524 if os.path.isfile(testname):
525 525 return testname
526 526 raise IOError,'File' + `fname` + \
527 527 ' not found in current or supplied directories:' + `alt_dirs`
528 528
529 529 #----------------------------------------------------------------------------
530 530 def file_read(filename):
531 531 """Read a file and close it. Returns the file source."""
532 fobj=open(filename,'r');
532 fobj = open(filename,'r');
533 533 source = fobj.read();
534 534 fobj.close()
535 535 return source
536 536
537 def file_readlines(filename):
538 """Read a file and close it. Returns the file source using readlines()."""
539 fobj = open(filename,'r');
540 lines = fobj.readlines();
541 fobj.close()
542 return lines
543
537 544 #----------------------------------------------------------------------------
538 545 def target_outdated(target,deps):
539 546 """Determine whether a target is out of date.
540 547
541 548 target_outdated(target,deps) -> 1/0
542 549
543 550 deps: list of filenames which MUST exist.
544 551 target: single filename which may or may not exist.
545 552
546 553 If target doesn't exist or is older than any file listed in deps, return
547 554 true, otherwise return false.
548 555 """
549 556 try:
550 557 target_time = os.path.getmtime(target)
551 558 except os.error:
552 559 return 1
553 560 for dep in deps:
554 561 dep_time = os.path.getmtime(dep)
555 562 if dep_time > target_time:
556 563 #print "For target",target,"Dep failed:",dep # dbg
557 564 #print "times (dep,tar):",dep_time,target_time # dbg
558 565 return 1
559 566 return 0
560 567
561 568 #-----------------------------------------------------------------------------
562 569 def target_update(target,deps,cmd):
563 570 """Update a target with a given command given a list of dependencies.
564 571
565 572 target_update(target,deps,cmd) -> runs cmd if target is outdated.
566 573
567 574 This is just a wrapper around target_outdated() which calls the given
568 575 command if target is outdated."""
569 576
570 577 if target_outdated(target,deps):
571 578 xsys(cmd)
572 579
573 580 #----------------------------------------------------------------------------
574 581 def unquote_ends(istr):
575 582 """Remove a single pair of quotes from the endpoints of a string."""
576 583
577 584 if not istr:
578 585 return istr
579 586 if (istr[0]=="'" and istr[-1]=="'") or \
580 587 (istr[0]=='"' and istr[-1]=='"'):
581 588 return istr[1:-1]
582 589 else:
583 590 return istr
584 591
585 592 #----------------------------------------------------------------------------
586 593 def process_cmdline(argv,names=[],defaults={},usage=''):
587 594 """ Process command-line options and arguments.
588 595
589 596 Arguments:
590 597
591 598 - argv: list of arguments, typically sys.argv.
592 599
593 600 - names: list of option names. See DPyGetOpt docs for details on options
594 601 syntax.
595 602
596 603 - defaults: dict of default values.
597 604
598 605 - usage: optional usage notice to print if a wrong argument is passed.
599 606
600 607 Return a dict of options and a list of free arguments."""
601 608
602 609 getopt = DPyGetOpt.DPyGetOpt()
603 610 getopt.setIgnoreCase(0)
604 611 getopt.parseConfiguration(names)
605 612
606 613 try:
607 614 getopt.processArguments(argv)
608 615 except:
609 616 print usage
610 617 warn(`sys.exc_value`,level=4)
611 618
612 619 defaults.update(getopt.optionValues)
613 620 args = getopt.freeValues
614 621
615 622 return defaults,args
616 623
617 624 #----------------------------------------------------------------------------
618 625 def optstr2types(ostr):
619 626 """Convert a string of option names to a dict of type mappings.
620 627
621 628 optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'}
622 629
623 630 This is used to get the types of all the options in a string formatted
624 631 with the conventions of DPyGetOpt. The 'type' None is used for options
625 632 which are strings (they need no further conversion). This function's main
626 633 use is to get a typemap for use with read_dict().
627 634 """
628 635
629 636 typeconv = {None:'',int:'',float:''}
630 637 typemap = {'s':None,'i':int,'f':float}
631 638 opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)')
632 639
633 640 for w in ostr.split():
634 641 oname,alias,otype = opt_re.match(w).groups()
635 642 if otype == '' or alias == '!': # simple switches are integers too
636 643 otype = 'i'
637 644 typeconv[typemap[otype]] += oname + ' '
638 645 return typeconv
639 646
640 647 #----------------------------------------------------------------------------
641 648 def read_dict(filename,type_conv=None,**opt):
642 649
643 650 """Read a dictionary of key=value pairs from an input file, optionally
644 651 performing conversions on the resulting values.
645 652
646 653 read_dict(filename,type_conv,**opt) -> dict
647 654
648 655 Only one value per line is accepted, the format should be
649 656 # optional comments are ignored
650 657 key value\n
651 658
652 659 Args:
653 660
654 661 - type_conv: A dictionary specifying which keys need to be converted to
655 662 which types. By default all keys are read as strings. This dictionary
656 663 should have as its keys valid conversion functions for strings
657 664 (int,long,float,complex, or your own). The value for each key
658 665 (converter) should be a whitespace separated string containing the names
659 666 of all the entries in the file to be converted using that function. For
660 667 keys to be left alone, use None as the conversion function (only needed
661 668 with purge=1, see below).
662 669
663 670 - opt: dictionary with extra options as below (default in parens)
664 671
665 672 purge(0): if set to 1, all keys *not* listed in type_conv are purged out
666 673 of the dictionary to be returned. If purge is going to be used, the
667 674 set of keys to be left as strings also has to be explicitly specified
668 675 using the (non-existent) conversion function None.
669 676
670 677 fs(None): field separator. This is the key/value separator to be used
671 678 when parsing the file. The None default means any whitespace [behavior
672 679 of string.split()].
673 680
674 681 strip(0): if 1, strip string values of leading/trailinig whitespace.
675 682
676 683 warn(1): warning level if requested keys are not found in file.
677 684 - 0: silently ignore.
678 685 - 1: inform but proceed.
679 686 - 2: raise KeyError exception.
680 687
681 688 no_empty(0): if 1, remove keys with whitespace strings as a value.
682 689
683 690 unique([]): list of keys (or space separated string) which can't be
684 691 repeated. If one such key is found in the file, each new instance
685 692 overwrites the previous one. For keys not listed here, the behavior is
686 693 to make a list of all appearances.
687 694
688 695 Example:
689 696 If the input file test.ini has:
690 697 i 3
691 698 x 4.5
692 699 y 5.5
693 700 s hi ho
694 701 Then:
695 702
696 703 >>> type_conv={int:'i',float:'x',None:'s'}
697 704 >>> read_dict('test.ini')
698 705 {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'}
699 706 >>> read_dict('test.ini',type_conv)
700 707 {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'}
701 708 >>> read_dict('test.ini',type_conv,purge=1)
702 709 {'i': 3, 's': 'hi ho', 'x': 4.5}
703 710 """
704 711
705 712 # starting config
706 713 opt.setdefault('purge',0)
707 714 opt.setdefault('fs',None) # field sep defaults to any whitespace
708 715 opt.setdefault('strip',0)
709 716 opt.setdefault('warn',1)
710 717 opt.setdefault('no_empty',0)
711 718 opt.setdefault('unique','')
712 719 if type(opt['unique']) in StringTypes:
713 720 unique_keys = qw(opt['unique'])
714 721 elif type(opt['unique']) in (types.TupleType,types.ListType):
715 722 unique_keys = opt['unique']
716 723 else:
717 724 raise ValueError, 'Unique keys must be given as a string, List or Tuple'
718 725
719 726 dict = {}
720 727 # first read in table of values as strings
721 728 file = open(filename,'r')
722 729 for line in file.readlines():
723 730 line = line.strip()
724 731 if len(line) and line[0]=='#': continue
725 732 if len(line)>0:
726 733 lsplit = line.split(opt['fs'],1)
727 734 try:
728 735 key,val = lsplit
729 736 except ValueError:
730 737 key,val = lsplit[0],''
731 738 key = key.strip()
732 739 if opt['strip']: val = val.strip()
733 740 if val == "''" or val == '""': val = ''
734 741 if opt['no_empty'] and (val=='' or val.isspace()):
735 742 continue
736 743 # if a key is found more than once in the file, build a list
737 744 # unless it's in the 'unique' list. In that case, last found in file
738 745 # takes precedence. User beware.
739 746 try:
740 747 if dict[key] and key in unique_keys:
741 748 dict[key] = val
742 749 elif type(dict[key]) is types.ListType:
743 750 dict[key].append(val)
744 751 else:
745 752 dict[key] = [dict[key],val]
746 753 except KeyError:
747 754 dict[key] = val
748 755 # purge if requested
749 756 if opt['purge']:
750 757 accepted_keys = qwflat(type_conv.values())
751 758 for key in dict.keys():
752 759 if key in accepted_keys: continue
753 760 del(dict[key])
754 761 # now convert if requested
755 762 if type_conv==None: return dict
756 763 conversions = type_conv.keys()
757 764 try: conversions.remove(None)
758 765 except: pass
759 766 for convert in conversions:
760 767 for val in qw(type_conv[convert]):
761 768 try:
762 769 dict[val] = convert(dict[val])
763 770 except KeyError,e:
764 771 if opt['warn'] == 0:
765 772 pass
766 773 elif opt['warn'] == 1:
767 774 print >>sys.stderr, 'Warning: key',val,\
768 775 'not found in file',filename
769 776 elif opt['warn'] == 2:
770 777 raise KeyError,e
771 778 else:
772 779 raise ValueError,'Warning level must be 0,1 or 2'
773 780
774 781 return dict
775 782
776 783 #----------------------------------------------------------------------------
777 784 def flag_calls(func):
778 785 """Wrap a function to detect and flag when it gets called.
779 786
780 787 This is a decorator which takes a function and wraps it in a function with
781 788 a 'called' attribute. wrapper.called is initialized to False.
782 789
783 790 The wrapper.called attribute is set to False right before each call to the
784 791 wrapped function, so if the call fails it remains False. After the call
785 792 completes, wrapper.called is set to True and the output is returned.
786 793
787 794 Testing for truth in wrapper.called allows you to determine if a call to
788 795 func() was attempted and succeeded."""
789 796
790 797 def wrapper(*args,**kw):
791 798 wrapper.called = False
792 799 out = func(*args,**kw)
793 800 wrapper.called = True
794 801 return out
795 802
796 803 wrapper.called = False
797 804 wrapper.__doc__ = func.__doc__
798 805 return wrapper
799 806
800 807 #----------------------------------------------------------------------------
801 808 class HomeDirError(Error):
802 809 pass
803 810
804 811 def get_home_dir():
805 812 """Return the closest possible equivalent to a 'home' directory.
806 813
807 814 We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH.
808 815
809 816 Currently only Posix and NT are implemented, a HomeDirError exception is
810 817 raised for all other OSes. """
811 818
812 819 isdir = os.path.isdir
813 820 env = os.environ
814 821 try:
815 822 homedir = env['HOME']
816 823 if not isdir(homedir):
817 824 # in case a user stuck some string which does NOT resolve to a
818 825 # valid path, it's as good as if we hadn't foud it
819 826 raise KeyError
820 827 return homedir
821 828 except KeyError:
822 829 if os.name == 'posix':
823 830 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
824 831 elif os.name == 'nt':
825 832 # For some strange reason, win9x returns 'nt' for os.name.
826 833 try:
827 834 homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH'])
828 835 if not isdir(homedir):
829 836 homedir = os.path.join(env['USERPROFILE'])
830 837 if not isdir(homedir):
831 838 raise HomeDirError
832 839 return homedir
833 840 except:
834 841 try:
835 842 # Use the registry to get the 'My Documents' folder.
836 843 import _winreg as wreg
837 844 key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
838 845 "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
839 846 homedir = wreg.QueryValueEx(key,'Personal')[0]
840 847 key.Close()
841 848 if not isdir(homedir):
842 849 e = ('Invalid "Personal" folder registry key '
843 850 'typically "My Documents".\n'
844 851 'Value: %s\n'
845 852 'This is not a valid directory on your system.' %
846 853 homedir)
847 854 raise HomeDirError(e)
848 855 return homedir
849 856 except HomeDirError:
850 857 raise
851 858 except:
852 859 return 'C:\\'
853 860 elif os.name == 'dos':
854 861 # Desperate, may do absurd things in classic MacOS. May work under DOS.
855 862 return 'C:\\'
856 863 else:
857 864 raise HomeDirError,'support for your operating system not implemented.'
858 865
859 866 #****************************************************************************
860 867 # strings and text
861 868
862 869 class LSString(str):
863 870 """String derivative with a special access attributes.
864 871
865 872 These are normal strings, but with the special attributes:
866 873
867 874 .l (or .list) : value as list (split on newlines).
868 875 .n (or .nlstr): original value (the string itself).
869 876 .s (or .spstr): value as whitespace-separated string.
870 877
871 878 Any values which require transformations are computed only once and
872 879 cached.
873 880
874 881 Such strings are very useful to efficiently interact with the shell, which
875 882 typically only understands whitespace-separated options for commands."""
876 883
877 884 def get_list(self):
878 885 try:
879 886 return self.__list
880 887 except AttributeError:
881 888 self.__list = self.split('\n')
882 889 return self.__list
883 890
884 891 l = list = property(get_list)
885 892
886 893 def get_spstr(self):
887 894 try:
888 895 return self.__spstr
889 896 except AttributeError:
890 897 self.__spstr = self.replace('\n',' ')
891 898 return self.__spstr
892 899
893 900 s = spstr = property(get_spstr)
894 901
895 902 def get_nlstr(self):
896 903 return self
897 904
898 905 n = nlstr = property(get_nlstr)
899 906
900 907 def get_paths(self):
901 908 try:
902 909 return self.__paths
903 910 except AttributeError:
904 911 self.__paths = [path(p) for p in self.split('\n') if os.path.exists(p)]
905 912 return self.__paths
906 913
907 914 p = paths = property(get_paths)
908 915
909 916
910 917 #----------------------------------------------------------------------------
911 918 class SList(list):
912 919 """List derivative with a special access attributes.
913 920
914 921 These are normal lists, but with the special attributes:
915 922
916 923 .l (or .list) : value as list (the list itself).
917 924 .n (or .nlstr): value as a string, joined on newlines.
918 925 .s (or .spstr): value as a string, joined on spaces.
919 926
920 927 Any values which require transformations are computed only once and
921 928 cached."""
922 929
923 930 def get_list(self):
924 931 return self
925 932
926 933 l = list = property(get_list)
927 934
928 935 def get_spstr(self):
929 936 try:
930 937 return self.__spstr
931 938 except AttributeError:
932 939 self.__spstr = ' '.join(self)
933 940 return self.__spstr
934 941
935 942 s = spstr = property(get_spstr)
936 943
937 944 def get_nlstr(self):
938 945 try:
939 946 return self.__nlstr
940 947 except AttributeError:
941 948 self.__nlstr = '\n'.join(self)
942 949 return self.__nlstr
943 950
944 951 n = nlstr = property(get_nlstr)
945 952
946 953 def get_paths(self):
947 954 try:
948 955 return self.__paths
949 956 except AttributeError:
950 957 self.__paths = [path(p) for p in self if os.path.exists(p)]
951 958 return self.__paths
952 959
953 960 p = paths = property(get_paths)
954 961
955 962 #----------------------------------------------------------------------------
956 963 def esc_quotes(strng):
957 964 """Return the input string with single and double quotes escaped out"""
958 965
959 966 return strng.replace('"','\\"').replace("'","\\'")
960 967
961 968 #----------------------------------------------------------------------------
962 969 def make_quoted_expr(s):
963 970 """Return string s in appropriate quotes, using raw string if possible.
964 971
965 972 Effectively this turns string: cd \ao\ao\
966 973 to: r"cd \ao\ao\_"[:-1]
967 974
968 975 Note the use of raw string and padding at the end to allow trailing backslash.
969 976
970 977 """
971 978
972 979 tail = ''
973 980 tailpadding = ''
974 981 raw = ''
975 982 if "\\" in s:
976 983 raw = 'r'
977 984 if s.endswith('\\'):
978 985 tail = '[:-1]'
979 986 tailpadding = '_'
980 987 if '"' not in s:
981 988 quote = '"'
982 989 elif "'" not in s:
983 990 quote = "'"
984 991 elif '"""' not in s and not s.endswith('"'):
985 992 quote = '"""'
986 993 elif "'''" not in s and not s.endswith("'"):
987 994 quote = "'''"
988 995 else:
989 996 # give up, backslash-escaped string will do
990 997 return '"%s"' % esc_quotes(s)
991 998 res = itpl("$raw$quote$s$tailpadding$quote$tail")
992 999 return res
993 1000
994 1001
995 1002 #----------------------------------------------------------------------------
996 1003 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
997 1004 """Take multiple lines of input.
998 1005
999 1006 A list with each line of input as a separate element is returned when a
1000 1007 termination string is entered (defaults to a single '.'). Input can also
1001 1008 terminate via EOF (^D in Unix, ^Z-RET in Windows).
1002 1009
1003 1010 Lines of input which end in \\ are joined into single entries (and a
1004 1011 secondary continuation prompt is issued as long as the user terminates
1005 1012 lines with \\). This allows entering very long strings which are still
1006 1013 meant to be treated as single entities.
1007 1014 """
1008 1015
1009 1016 try:
1010 1017 if header:
1011 1018 header += '\n'
1012 1019 lines = [raw_input(header + ps1)]
1013 1020 except EOFError:
1014 1021 return []
1015 1022 terminate = [terminate_str]
1016 1023 try:
1017 1024 while lines[-1:] != terminate:
1018 1025 new_line = raw_input(ps1)
1019 1026 while new_line.endswith('\\'):
1020 1027 new_line = new_line[:-1] + raw_input(ps2)
1021 1028 lines.append(new_line)
1022 1029
1023 1030 return lines[:-1] # don't return the termination command
1024 1031 except EOFError:
1025 1032 print
1026 1033 return lines
1027 1034
1028 1035 #----------------------------------------------------------------------------
1029 1036 def raw_input_ext(prompt='', ps2='... '):
1030 1037 """Similar to raw_input(), but accepts extended lines if input ends with \\."""
1031 1038
1032 1039 line = raw_input(prompt)
1033 1040 while line.endswith('\\'):
1034 1041 line = line[:-1] + raw_input(ps2)
1035 1042 return line
1036 1043
1037 1044 #----------------------------------------------------------------------------
1038 1045 def ask_yes_no(prompt,default=None):
1039 1046 """Asks a question and returns an integer 1/0 (y/n) answer.
1040 1047
1041 1048 If default is given (one of 'y','n'), it is used if the user input is
1042 1049 empty. Otherwise the question is repeated until an answer is given.
1043 1050 If EOF occurs 20 times consecutively, the default answer is assumed,
1044 1051 or if there is no default, an exception is raised to prevent infinite
1045 1052 loops.
1046 1053
1047 1054 Valid answers are: y/yes/n/no (match is not case sensitive)."""
1048 1055
1049 1056 answers = {'y':True,'n':False,'yes':True,'no':False}
1050 1057 ans = None
1051 1058 eofs, max_eofs = 0, 20
1052 1059 while ans not in answers.keys():
1053 1060 try:
1054 1061 ans = raw_input(prompt+' ').lower()
1055 1062 if not ans: # response was an empty string
1056 1063 ans = default
1057 1064 eofs = 0
1058 1065 except (EOFError,KeyboardInterrupt):
1059 1066 eofs = eofs + 1
1060 1067 if eofs >= max_eofs:
1061 1068 if default in answers.keys():
1062 1069 ans = default
1063 1070 else:
1064 1071 raise
1065 1072
1066 1073 return answers[ans]
1067 1074
1068 1075 #----------------------------------------------------------------------------
1069 1076 def marquee(txt='',width=78,mark='*'):
1070 1077 """Return the input string centered in a 'marquee'."""
1071 1078 if not txt:
1072 1079 return (mark*width)[:width]
1073 1080 nmark = (width-len(txt)-2)/len(mark)/2
1074 1081 if nmark < 0: nmark =0
1075 1082 marks = mark*nmark
1076 1083 return '%s %s %s' % (marks,txt,marks)
1077 1084
1078 1085 #----------------------------------------------------------------------------
1079 1086 class EvalDict:
1080 1087 """
1081 1088 Emulate a dict which evaluates its contents in the caller's frame.
1082 1089
1083 1090 Usage:
1084 1091 >>>number = 19
1085 1092 >>>text = "python"
1086 1093 >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict()
1087 1094 """
1088 1095
1089 1096 # This version is due to sismex01@hebmex.com on c.l.py, and is basically a
1090 1097 # modified (shorter) version of:
1091 1098 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by
1092 1099 # Skip Montanaro (skip@pobox.com).
1093 1100
1094 1101 def __getitem__(self, name):
1095 1102 frame = sys._getframe(1)
1096 1103 return eval(name, frame.f_globals, frame.f_locals)
1097 1104
1098 1105 EvalString = EvalDict # for backwards compatibility
1099 1106 #----------------------------------------------------------------------------
1100 1107 def qw(words,flat=0,sep=None,maxsplit=-1):
1101 1108 """Similar to Perl's qw() operator, but with some more options.
1102 1109
1103 1110 qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit)
1104 1111
1105 1112 words can also be a list itself, and with flat=1, the output will be
1106 1113 recursively flattened. Examples:
1107 1114
1108 1115 >>> qw('1 2')
1109 1116 ['1', '2']
1110 1117 >>> qw(['a b','1 2',['m n','p q']])
1111 1118 [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]]
1112 1119 >>> qw(['a b','1 2',['m n','p q']],flat=1)
1113 1120 ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """
1114 1121
1115 1122 if type(words) in StringTypes:
1116 1123 return [word.strip() for word in words.split(sep,maxsplit)
1117 1124 if word and not word.isspace() ]
1118 1125 if flat:
1119 1126 return flatten(map(qw,words,[1]*len(words)))
1120 1127 return map(qw,words)
1121 1128
1122 1129 #----------------------------------------------------------------------------
1123 1130 def qwflat(words,sep=None,maxsplit=-1):
1124 1131 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
1125 1132 return qw(words,1,sep,maxsplit)
1126 1133
1127 1134 #----------------------------------------------------------------------------
1128 1135 def qw_lol(indata):
1129 1136 """qw_lol('a b') -> [['a','b']],
1130 1137 otherwise it's just a call to qw().
1131 1138
1132 1139 We need this to make sure the modules_some keys *always* end up as a
1133 1140 list of lists."""
1134 1141
1135 1142 if type(indata) in StringTypes:
1136 1143 return [qw(indata)]
1137 1144 else:
1138 1145 return qw(indata)
1139 1146
1140 1147 #-----------------------------------------------------------------------------
1141 1148 def list_strings(arg):
1142 1149 """Always return a list of strings, given a string or list of strings
1143 1150 as input."""
1144 1151
1145 1152 if type(arg) in StringTypes: return [arg]
1146 1153 else: return arg
1147 1154
1148 1155 #----------------------------------------------------------------------------
1149 1156 def grep(pat,list,case=1):
1150 1157 """Simple minded grep-like function.
1151 1158 grep(pat,list) returns occurrences of pat in list, None on failure.
1152 1159
1153 1160 It only does simple string matching, with no support for regexps. Use the
1154 1161 option case=0 for case-insensitive matching."""
1155 1162
1156 1163 # This is pretty crude. At least it should implement copying only references
1157 1164 # to the original data in case it's big. Now it copies the data for output.
1158 1165 out=[]
1159 1166 if case:
1160 1167 for term in list:
1161 1168 if term.find(pat)>-1: out.append(term)
1162 1169 else:
1163 1170 lpat=pat.lower()
1164 1171 for term in list:
1165 1172 if term.lower().find(lpat)>-1: out.append(term)
1166 1173
1167 1174 if len(out): return out
1168 1175 else: return None
1169 1176
1170 1177 #----------------------------------------------------------------------------
1171 1178 def dgrep(pat,*opts):
1172 1179 """Return grep() on dir()+dir(__builtins__).
1173 1180
1174 1181 A very common use of grep() when working interactively."""
1175 1182
1176 1183 return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts)
1177 1184
1178 1185 #----------------------------------------------------------------------------
1179 1186 def idgrep(pat):
1180 1187 """Case-insensitive dgrep()"""
1181 1188
1182 1189 return dgrep(pat,0)
1183 1190
1184 1191 #----------------------------------------------------------------------------
1185 1192 def igrep(pat,list):
1186 1193 """Synonym for case-insensitive grep."""
1187 1194
1188 1195 return grep(pat,list,case=0)
1189 1196
1190 1197 #----------------------------------------------------------------------------
1191 1198 def indent(str,nspaces=4,ntabs=0):
1192 1199 """Indent a string a given number of spaces or tabstops.
1193 1200
1194 1201 indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
1195 1202 """
1196 1203 if str is None:
1197 1204 return
1198 1205 ind = '\t'*ntabs+' '*nspaces
1199 1206 outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind))
1200 1207 if outstr.endswith(os.linesep+ind):
1201 1208 return outstr[:-len(ind)]
1202 1209 else:
1203 1210 return outstr
1204 1211
1205 1212 #-----------------------------------------------------------------------------
1206 1213 def native_line_ends(filename,backup=1):
1207 1214 """Convert (in-place) a file to line-ends native to the current OS.
1208 1215
1209 1216 If the optional backup argument is given as false, no backup of the
1210 1217 original file is left. """
1211 1218
1212 1219 backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'}
1213 1220
1214 1221 bak_filename = filename + backup_suffixes[os.name]
1215 1222
1216 1223 original = open(filename).read()
1217 1224 shutil.copy2(filename,bak_filename)
1218 1225 try:
1219 1226 new = open(filename,'wb')
1220 1227 new.write(os.linesep.join(original.splitlines()))
1221 1228 new.write(os.linesep) # ALWAYS put an eol at the end of the file
1222 1229 new.close()
1223 1230 except:
1224 1231 os.rename(bak_filename,filename)
1225 1232 if not backup:
1226 1233 try:
1227 1234 os.remove(bak_filename)
1228 1235 except:
1229 1236 pass
1230 1237
1231 1238 #----------------------------------------------------------------------------
1232 1239 def get_pager_cmd(pager_cmd = None):
1233 1240 """Return a pager command.
1234 1241
1235 1242 Makes some attempts at finding an OS-correct one."""
1236 1243
1237 1244 if os.name == 'posix':
1238 1245 default_pager_cmd = 'less -r' # -r for color control sequences
1239 1246 elif os.name in ['nt','dos']:
1240 1247 default_pager_cmd = 'type'
1241 1248
1242 1249 if pager_cmd is None:
1243 1250 try:
1244 1251 pager_cmd = os.environ['PAGER']
1245 1252 except:
1246 1253 pager_cmd = default_pager_cmd
1247 1254 return pager_cmd
1248 1255
1249 1256 #-----------------------------------------------------------------------------
1250 1257 def get_pager_start(pager,start):
1251 1258 """Return the string for paging files with an offset.
1252 1259
1253 1260 This is the '+N' argument which less and more (under Unix) accept.
1254 1261 """
1255 1262
1256 1263 if pager in ['less','more']:
1257 1264 if start:
1258 1265 start_string = '+' + str(start)
1259 1266 else:
1260 1267 start_string = ''
1261 1268 else:
1262 1269 start_string = ''
1263 1270 return start_string
1264 1271
1265 1272 #----------------------------------------------------------------------------
1266 1273 if os.name == "nt":
1267 1274 import msvcrt
1268 1275 def page_more():
1269 1276 """ Smart pausing between pages
1270 1277
1271 1278 @return: True if need print more lines, False if quit
1272 1279 """
1273 1280 Term.cout.write('---Return to continue, q to quit--- ')
1274 1281 ans = msvcrt.getch()
1275 1282 if ans in ("q", "Q"):
1276 1283 result = False
1277 1284 else:
1278 1285 result = True
1279 1286 Term.cout.write("\b"*37 + " "*37 + "\b"*37)
1280 1287 return result
1281 1288 else:
1282 1289 def page_more():
1283 1290 ans = raw_input('---Return to continue, q to quit--- ')
1284 1291 if ans.lower().startswith('q'):
1285 1292 return False
1286 1293 else:
1287 1294 return True
1288 1295
1289 1296 esc_re = re.compile(r"(\x1b[^m]+m)")
1290 1297
1291 1298 def page_dumb(strng,start=0,screen_lines=25):
1292 1299 """Very dumb 'pager' in Python, for when nothing else works.
1293 1300
1294 1301 Only moves forward, same interface as page(), except for pager_cmd and
1295 1302 mode."""
1296 1303
1297 1304 out_ln = strng.splitlines()[start:]
1298 1305 screens = chop(out_ln,screen_lines-1)
1299 1306 if len(screens) == 1:
1300 1307 print >>Term.cout, os.linesep.join(screens[0])
1301 1308 else:
1302 1309 last_escape = ""
1303 1310 for scr in screens[0:-1]:
1304 1311 hunk = os.linesep.join(scr)
1305 1312 print >>Term.cout, last_escape + hunk
1306 1313 if not page_more():
1307 1314 return
1308 1315 esc_list = esc_re.findall(hunk)
1309 1316 if len(esc_list) > 0:
1310 1317 last_escape = esc_list[-1]
1311 1318 print >>Term.cout, last_escape + os.linesep.join(screens[-1])
1312 1319
1313 1320 #----------------------------------------------------------------------------
1314 1321 def page(strng,start=0,screen_lines=0,pager_cmd = None):
1315 1322 """Print a string, piping through a pager after a certain length.
1316 1323
1317 1324 The screen_lines parameter specifies the number of *usable* lines of your
1318 1325 terminal screen (total lines minus lines you need to reserve to show other
1319 1326 information).
1320 1327
1321 1328 If you set screen_lines to a number <=0, page() will try to auto-determine
1322 1329 your screen size and will only use up to (screen_size+screen_lines) for
1323 1330 printing, paging after that. That is, if you want auto-detection but need
1324 1331 to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for
1325 1332 auto-detection without any lines reserved simply use screen_lines = 0.
1326 1333
1327 1334 If a string won't fit in the allowed lines, it is sent through the
1328 1335 specified pager command. If none given, look for PAGER in the environment,
1329 1336 and ultimately default to less.
1330 1337
1331 1338 If no system pager works, the string is sent through a 'dumb pager'
1332 1339 written in python, very simplistic.
1333 1340 """
1334 1341
1335 1342 # Ugly kludge, but calling curses.initscr() flat out crashes in emacs
1336 1343 TERM = os.environ.get('TERM','dumb')
1337 1344 if TERM in ['dumb','emacs'] and os.name != 'nt':
1338 1345 print strng
1339 1346 return
1340 1347 # chop off the topmost part of the string we don't want to see
1341 1348 str_lines = strng.split(os.linesep)[start:]
1342 1349 str_toprint = os.linesep.join(str_lines)
1343 1350 num_newlines = len(str_lines)
1344 1351 len_str = len(str_toprint)
1345 1352
1346 1353 # Dumb heuristics to guesstimate number of on-screen lines the string
1347 1354 # takes. Very basic, but good enough for docstrings in reasonable
1348 1355 # terminals. If someone later feels like refining it, it's not hard.
1349 1356 numlines = max(num_newlines,int(len_str/80)+1)
1350 1357
1351 1358 if os.name == "nt":
1352 1359 screen_lines_def = get_console_size(defaulty=25)[1]
1353 1360 else:
1354 1361 screen_lines_def = 25 # default value if we can't auto-determine
1355 1362
1356 1363 # auto-determine screen size
1357 1364 if screen_lines <= 0:
1358 1365 if TERM=='xterm':
1359 1366 try:
1360 1367 import curses
1361 1368 if hasattr(curses,'initscr'):
1362 1369 use_curses = 1
1363 1370 else:
1364 1371 use_curses = 0
1365 1372 except ImportError:
1366 1373 use_curses = 0
1367 1374 else:
1368 1375 # curses causes problems on many terminals other than xterm.
1369 1376 use_curses = 0
1370 1377 if use_curses:
1371 1378 scr = curses.initscr()
1372 1379 screen_lines_real,screen_cols = scr.getmaxyx()
1373 1380 curses.endwin()
1374 1381 screen_lines += screen_lines_real
1375 1382 #print '***Screen size:',screen_lines_real,'lines x',\
1376 1383 #screen_cols,'columns.' # dbg
1377 1384 else:
1378 1385 screen_lines += screen_lines_def
1379 1386
1380 1387 #print 'numlines',numlines,'screenlines',screen_lines # dbg
1381 1388 if numlines <= screen_lines :
1382 1389 #print '*** normal print' # dbg
1383 1390 print >>Term.cout, str_toprint
1384 1391 else:
1385 1392 # Try to open pager and default to internal one if that fails.
1386 1393 # All failure modes are tagged as 'retval=1', to match the return
1387 1394 # value of a failed system command. If any intermediate attempt
1388 1395 # sets retval to 1, at the end we resort to our own page_dumb() pager.
1389 1396 pager_cmd = get_pager_cmd(pager_cmd)
1390 1397 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1391 1398 if os.name == 'nt':
1392 1399 if pager_cmd.startswith('type'):
1393 1400 # The default WinXP 'type' command is failing on complex strings.
1394 1401 retval = 1
1395 1402 else:
1396 1403 tmpname = tempfile.mktemp('.txt')
1397 1404 tmpfile = file(tmpname,'wt')
1398 1405 tmpfile.write(strng)
1399 1406 tmpfile.close()
1400 1407 cmd = "%s < %s" % (pager_cmd,tmpname)
1401 1408 if os.system(cmd):
1402 1409 retval = 1
1403 1410 else:
1404 1411 retval = None
1405 1412 os.remove(tmpname)
1406 1413 else:
1407 1414 try:
1408 1415 retval = None
1409 1416 # if I use popen4, things hang. No idea why.
1410 1417 #pager,shell_out = os.popen4(pager_cmd)
1411 1418 pager = os.popen(pager_cmd,'w')
1412 1419 pager.write(strng)
1413 1420 pager.close()
1414 1421 retval = pager.close() # success returns None
1415 1422 except IOError,msg: # broken pipe when user quits
1416 1423 if msg.args == (32,'Broken pipe'):
1417 1424 retval = None
1418 1425 else:
1419 1426 retval = 1
1420 1427 except OSError:
1421 1428 # Other strange problems, sometimes seen in Win2k/cygwin
1422 1429 retval = 1
1423 1430 if retval is not None:
1424 1431 page_dumb(strng,screen_lines=screen_lines)
1425 1432
1426 1433 #----------------------------------------------------------------------------
1427 1434 def page_file(fname,start = 0, pager_cmd = None):
1428 1435 """Page a file, using an optional pager command and starting line.
1429 1436 """
1430 1437
1431 1438 pager_cmd = get_pager_cmd(pager_cmd)
1432 1439 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1433 1440
1434 1441 try:
1435 1442 if os.environ['TERM'] in ['emacs','dumb']:
1436 1443 raise EnvironmentError
1437 1444 xsys(pager_cmd + ' ' + fname)
1438 1445 except:
1439 1446 try:
1440 1447 if start > 0:
1441 1448 start -= 1
1442 1449 page(open(fname).read(),start)
1443 1450 except:
1444 1451 print 'Unable to show file',`fname`
1445 1452
1446 1453 #----------------------------------------------------------------------------
1447 1454 def snip_print(str,width = 75,print_full = 0,header = ''):
1448 1455 """Print a string snipping the midsection to fit in width.
1449 1456
1450 1457 print_full: mode control:
1451 1458 - 0: only snip long strings
1452 1459 - 1: send to page() directly.
1453 1460 - 2: snip long strings and ask for full length viewing with page()
1454 1461 Return 1 if snipping was necessary, 0 otherwise."""
1455 1462
1456 1463 if print_full == 1:
1457 1464 page(header+str)
1458 1465 return 0
1459 1466
1460 1467 print header,
1461 1468 if len(str) < width:
1462 1469 print str
1463 1470 snip = 0
1464 1471 else:
1465 1472 whalf = int((width -5)/2)
1466 1473 print str[:whalf] + ' <...> ' + str[-whalf:]
1467 1474 snip = 1
1468 1475 if snip and print_full == 2:
1469 1476 if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y':
1470 1477 page(str)
1471 1478 return snip
1472 1479
1473 1480 #****************************************************************************
1474 1481 # lists, dicts and structures
1475 1482
1476 1483 def belong(candidates,checklist):
1477 1484 """Check whether a list of items appear in a given list of options.
1478 1485
1479 1486 Returns a list of 1 and 0, one for each candidate given."""
1480 1487
1481 1488 return [x in checklist for x in candidates]
1482 1489
1483 1490 #----------------------------------------------------------------------------
1484 1491 def uniq_stable(elems):
1485 1492 """uniq_stable(elems) -> list
1486 1493
1487 1494 Return from an iterable, a list of all the unique elements in the input,
1488 1495 but maintaining the order in which they first appear.
1489 1496
1490 1497 A naive solution to this problem which just makes a dictionary with the
1491 1498 elements as keys fails to respect the stability condition, since
1492 1499 dictionaries are unsorted by nature.
1493 1500
1494 1501 Note: All elements in the input must be valid dictionary keys for this
1495 1502 routine to work, as it internally uses a dictionary for efficiency
1496 1503 reasons."""
1497 1504
1498 1505 unique = []
1499 1506 unique_dict = {}
1500 1507 for nn in elems:
1501 1508 if nn not in unique_dict:
1502 1509 unique.append(nn)
1503 1510 unique_dict[nn] = None
1504 1511 return unique
1505 1512
1506 1513 #----------------------------------------------------------------------------
1507 1514 class NLprinter:
1508 1515 """Print an arbitrarily nested list, indicating index numbers.
1509 1516
1510 1517 An instance of this class called nlprint is available and callable as a
1511 1518 function.
1512 1519
1513 1520 nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent'
1514 1521 and using 'sep' to separate the index from the value. """
1515 1522
1516 1523 def __init__(self):
1517 1524 self.depth = 0
1518 1525
1519 1526 def __call__(self,lst,pos='',**kw):
1520 1527 """Prints the nested list numbering levels."""
1521 1528 kw.setdefault('indent',' ')
1522 1529 kw.setdefault('sep',': ')
1523 1530 kw.setdefault('start',0)
1524 1531 kw.setdefault('stop',len(lst))
1525 1532 # we need to remove start and stop from kw so they don't propagate
1526 1533 # into a recursive call for a nested list.
1527 1534 start = kw['start']; del kw['start']
1528 1535 stop = kw['stop']; del kw['stop']
1529 1536 if self.depth == 0 and 'header' in kw.keys():
1530 1537 print kw['header']
1531 1538
1532 1539 for idx in range(start,stop):
1533 1540 elem = lst[idx]
1534 1541 if type(elem)==type([]):
1535 1542 self.depth += 1
1536 1543 self.__call__(elem,itpl('$pos$idx,'),**kw)
1537 1544 self.depth -= 1
1538 1545 else:
1539 1546 printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem')
1540 1547
1541 1548 nlprint = NLprinter()
1542 1549 #----------------------------------------------------------------------------
1543 1550 def all_belong(candidates,checklist):
1544 1551 """Check whether a list of items ALL appear in a given list of options.
1545 1552
1546 1553 Returns a single 1 or 0 value."""
1547 1554
1548 1555 return 1-(0 in [x in checklist for x in candidates])
1549 1556
1550 1557 #----------------------------------------------------------------------------
1551 1558 def sort_compare(lst1,lst2,inplace = 1):
1552 1559 """Sort and compare two lists.
1553 1560
1554 1561 By default it does it in place, thus modifying the lists. Use inplace = 0
1555 1562 to avoid that (at the cost of temporary copy creation)."""
1556 1563 if not inplace:
1557 1564 lst1 = lst1[:]
1558 1565 lst2 = lst2[:]
1559 1566 lst1.sort(); lst2.sort()
1560 1567 return lst1 == lst2
1561 1568
1562 1569 #----------------------------------------------------------------------------
1563 1570 def mkdict(**kwargs):
1564 1571 """Return a dict from a keyword list.
1565 1572
1566 1573 It's just syntactic sugar for making ditcionary creation more convenient:
1567 1574 # the standard way
1568 1575 >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 }
1569 1576 # a cleaner way
1570 1577 >>>data = dict(red=1, green=2, blue=3)
1571 1578
1572 1579 If you need more than this, look at the Struct() class."""
1573 1580
1574 1581 return kwargs
1575 1582
1576 1583 #----------------------------------------------------------------------------
1577 1584 def list2dict(lst):
1578 1585 """Takes a list of (key,value) pairs and turns it into a dict."""
1579 1586
1580 1587 dic = {}
1581 1588 for k,v in lst: dic[k] = v
1582 1589 return dic
1583 1590
1584 1591 #----------------------------------------------------------------------------
1585 1592 def list2dict2(lst,default=''):
1586 1593 """Takes a list and turns it into a dict.
1587 1594 Much slower than list2dict, but more versatile. This version can take
1588 1595 lists with sublists of arbitrary length (including sclars)."""
1589 1596
1590 1597 dic = {}
1591 1598 for elem in lst:
1592 1599 if type(elem) in (types.ListType,types.TupleType):
1593 1600 size = len(elem)
1594 1601 if size == 0:
1595 1602 pass
1596 1603 elif size == 1:
1597 1604 dic[elem] = default
1598 1605 else:
1599 1606 k,v = elem[0], elem[1:]
1600 1607 if len(v) == 1: v = v[0]
1601 1608 dic[k] = v
1602 1609 else:
1603 1610 dic[elem] = default
1604 1611 return dic
1605 1612
1606 1613 #----------------------------------------------------------------------------
1607 1614 def flatten(seq):
1608 1615 """Flatten a list of lists (NOT recursive, only works for 2d lists)."""
1609 1616
1610 1617 # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in).
1611 1618
1612 1619 # if the x=0 isn't made, a *global* variable x is left over after calling
1613 1620 # this function, with the value of the last element in the return
1614 1621 # list. This does seem like a bug big time to me.
1615 1622
1616 1623 # the problem is fixed with the x=0, which seems to force the creation of
1617 1624 # a local name
1618 1625
1619 1626 x = 0
1620 1627 return [x for subseq in seq for x in subseq]
1621 1628
1622 1629 #----------------------------------------------------------------------------
1623 1630 def get_slice(seq,start=0,stop=None,step=1):
1624 1631 """Get a slice of a sequence with variable step. Specify start,stop,step."""
1625 1632 if stop == None:
1626 1633 stop = len(seq)
1627 1634 item = lambda i: seq[i]
1628 1635 return map(item,xrange(start,stop,step))
1629 1636
1630 1637 #----------------------------------------------------------------------------
1631 1638 def chop(seq,size):
1632 1639 """Chop a sequence into chunks of the given size."""
1633 1640 chunk = lambda i: seq[i:i+size]
1634 1641 return map(chunk,xrange(0,len(seq),size))
1635 1642
1636 1643 #----------------------------------------------------------------------------
1637 1644 def with(object, **args):
1638 1645 """Set multiple attributes for an object, similar to Pascal's with.
1639 1646
1640 1647 Example:
1641 1648 with(jim,
1642 1649 born = 1960,
1643 1650 haircolour = 'Brown',
1644 1651 eyecolour = 'Green')
1645 1652
1646 1653 Credit: Greg Ewing, in
1647 1654 http://mail.python.org/pipermail/python-list/2001-May/040703.html"""
1648 1655
1649 1656 object.__dict__.update(args)
1650 1657
1651 1658 #----------------------------------------------------------------------------
1652 1659 def setattr_list(obj,alist,nspace = None):
1653 1660 """Set a list of attributes for an object taken from a namespace.
1654 1661
1655 1662 setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in
1656 1663 alist with their values taken from nspace, which must be a dict (something
1657 1664 like locals() will often do) If nspace isn't given, locals() of the
1658 1665 *caller* is used, so in most cases you can omit it.
1659 1666
1660 1667 Note that alist can be given as a string, which will be automatically
1661 1668 split into a list on whitespace. If given as a list, it must be a list of
1662 1669 *strings* (the variable names themselves), not of variables."""
1663 1670
1664 1671 # this grabs the local variables from the *previous* call frame -- that is
1665 1672 # the locals from the function that called setattr_list().
1666 1673 # - snipped from weave.inline()
1667 1674 if nspace is None:
1668 1675 call_frame = sys._getframe().f_back
1669 1676 nspace = call_frame.f_locals
1670 1677
1671 1678 if type(alist) in StringTypes:
1672 1679 alist = alist.split()
1673 1680 for attr in alist:
1674 1681 val = eval(attr,nspace)
1675 1682 setattr(obj,attr,val)
1676 1683
1677 1684 #----------------------------------------------------------------------------
1678 1685 def getattr_list(obj,alist,*args):
1679 1686 """getattr_list(obj,alist[, default]) -> attribute list.
1680 1687
1681 1688 Get a list of named attributes for an object. When a default argument is
1682 1689 given, it is returned when the attribute doesn't exist; without it, an
1683 1690 exception is raised in that case.
1684 1691
1685 1692 Note that alist can be given as a string, which will be automatically
1686 1693 split into a list on whitespace. If given as a list, it must be a list of
1687 1694 *strings* (the variable names themselves), not of variables."""
1688 1695
1689 1696 if type(alist) in StringTypes:
1690 1697 alist = alist.split()
1691 1698 if args:
1692 1699 if len(args)==1:
1693 1700 default = args[0]
1694 1701 return map(lambda attr: getattr(obj,attr,default),alist)
1695 1702 else:
1696 1703 raise ValueError,'getattr_list() takes only one optional argument'
1697 1704 else:
1698 1705 return map(lambda attr: getattr(obj,attr),alist)
1699 1706
1700 1707 #----------------------------------------------------------------------------
1701 1708 def map_method(method,object_list,*argseq,**kw):
1702 1709 """map_method(method,object_list,*args,**kw) -> list
1703 1710
1704 1711 Return a list of the results of applying the methods to the items of the
1705 1712 argument sequence(s). If more than one sequence is given, the method is
1706 1713 called with an argument list consisting of the corresponding item of each
1707 1714 sequence. All sequences must be of the same length.
1708 1715
1709 1716 Keyword arguments are passed verbatim to all objects called.
1710 1717
1711 1718 This is Python code, so it's not nearly as fast as the builtin map()."""
1712 1719
1713 1720 out_list = []
1714 1721 idx = 0
1715 1722 for object in object_list:
1716 1723 try:
1717 1724 handler = getattr(object, method)
1718 1725 except AttributeError:
1719 1726 out_list.append(None)
1720 1727 else:
1721 1728 if argseq:
1722 1729 args = map(lambda lst:lst[idx],argseq)
1723 1730 #print 'ob',object,'hand',handler,'ar',args # dbg
1724 1731 out_list.append(handler(args,**kw))
1725 1732 else:
1726 1733 out_list.append(handler(**kw))
1727 1734 idx += 1
1728 1735 return out_list
1729 1736
1730 1737 #----------------------------------------------------------------------------
1731 1738 def import_fail_info(mod_name,fns=None):
1732 1739 """Inform load failure for a module."""
1733 1740
1734 1741 if fns == None:
1735 1742 warn("Loading of %s failed.\n" % (mod_name,))
1736 1743 else:
1737 1744 warn("Loading of %s from %s failed.\n" % (fns,mod_name))
1738 1745
1739 1746 #----------------------------------------------------------------------------
1740 1747 # Proposed popitem() extension, written as a method
1741 1748
1742 1749 class NotGiven: pass
1743 1750
1744 1751 def popkey(dct,key,default=NotGiven):
1745 1752 """Return dct[key] and delete dct[key].
1746 1753
1747 1754 If default is given, return it if dct[key] doesn't exist, otherwise raise
1748 1755 KeyError. """
1749 1756
1750 1757 try:
1751 1758 val = dct[key]
1752 1759 except KeyError:
1753 1760 if default is NotGiven:
1754 1761 raise
1755 1762 else:
1756 1763 return default
1757 1764 else:
1758 1765 del dct[key]
1759 1766 return val
1760 1767 #*************************** end of file <genutils.py> **********************
1761 1768
@@ -1,5161 +1,5178 b''
1 2006-02-05 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/demo.py (IPythonDemo): Add new classes to the demo
4 facilities, for demos processed by the IPython input filter
5 (IPythonDemo), and for running a script one-line-at-a-time as a
6 demo, both for pure Python (LineDemo) and for IPython-processed
7 input (IPythonLineDemo). After a request by Dave Kohel, from the
8 SAGE team.
9 (Demo.edit): added and edit() method to the demo objects, to edit
10 the in-memory copy of the last executed block.
11
12 * IPython/Magic.py (magic_edit): add '-r' option for 'raw'
13 processing to %edit, %macro and %save. These commands can now be
14 invoked on the unprocessed input as it was typed by the user
15 (without any prefilters applied). After requests by the SAGE team
16 at SAGE days 2006: http://modular.ucsd.edu/sage/days1/schedule.html.
17
1 18 2006-02-01 Ville Vainio <vivainio@gmail.com>
2 19
3 20 * setup.py, eggsetup.py: easy_install ipython==dev works
4 21 correctly now (on Linux)
5 22
6 23 * ipy_user_conf,ipmaker: user config changes, removed spurious
7 24 warnings
8 25
9 26 * iplib: if rc.banner is string, use it as is.
10 27
11 28 * Magic: %pycat accepts a string argument and pages it's contents.
12 29
13 30
14 31 2006-01-30 Ville Vainio <vivainio@gmail.com>
15 32
16 33 * pickleshare,pspersistence,ipapi,Magic: persistence overhaul.
17 34 Now %store and bookmarks work through PickleShare, meaning that
18 35 concurrent access is possible and all ipython sessions see the
19 36 same database situation all the time, instead of snapshot of
20 37 the situation when the session was started. Hence, %bookmark
21 38 results are immediately accessible from othes sessions. The database
22 39 is also available for use by user extensions. See:
23 40 http://www.python.org/pypi/pickleshare
24 41
25 42 * hooks.py: Two new hooks, 'shutdown_hook' and 'late_startup_hook'.
26 43
27 44 * aliases can now be %store'd
28 45
29 46 * path.py move to Extensions so that pickleshare does not need
30 47 IPython-specific import. Extensions added to pythonpath right
31 48 at __init__.
32 49
33 50 * iplib.py: ipalias deprecated/redundant; aliases are converted and
34 51 called with _ip.system and the pre-transformed command string.
35 52
36 53 2006-01-29 Fernando Perez <Fernando.Perez@colorado.edu>
37 54
38 55 * IPython/iplib.py (interact): Fix that we were not catching
39 56 KeyboardInterrupt exceptions properly. I'm not quite sure why the
40 57 logic here had to change, but it's fixed now.
41 58
42 59 2006-01-29 Ville Vainio <vivainio@gmail.com>
43 60
44 61 * iplib.py: Try to import pyreadline on Windows.
45 62
46 63 2006-01-27 Ville Vainio <vivainio@gmail.com>
47 64
48 65 * iplib.py: Expose ipapi as _ip in builtin namespace.
49 66 Makes ipmagic (-> _ip.magic), ipsystem (-> _ip.system)
50 67 and ip_set_hook (-> _ip.set_hook) redundant. % and !
51 68 syntax now produce _ip.* variant of the commands.
52 69
53 70 * "_ip.options().autoedit_syntax = 2" automatically throws
54 71 user to editor for syntax error correction without prompting.
55 72
56 73 2006-01-27 Ville Vainio <vivainio@gmail.com>
57 74
58 75 * ipmaker.py: Give "realistic" sys.argv for scripts (without
59 76 'ipython' at argv[0]) executed through command line.
60 77 NOTE: this DEPRECATES calling ipython with multiple scripts
61 78 ("ipython a.py b.py c.py")
62 79
63 80 * iplib.py, hooks.py: Added configurable input prefilter,
64 81 named 'input_prefilter'. See ext_rescapture.py for example
65 82 usage.
66 83
67 84 * ext_rescapture.py, Magic.py: Better system command output capture
68 85 through 'var = !ls' (deprecates user-visible %sc). Same notation
69 86 applies for magics, 'var = %alias' assigns alias list to var.
70 87
71 88 * ipapi.py: added meta() for accessing extension-usable data store.
72 89
73 90 * iplib.py: added InteractiveShell.getapi(). New magics should be
74 91 written doing self.getapi() instead of using the shell directly.
75 92
76 93 * Magic.py: %store now allows doing %store foo > ~/myfoo.txt and
77 94 %store foo >> ~/myfoo.txt to store variables to files (in clean
78 95 textual form, not a restorable pickle).
79 96
80 97 * ipmaker.py: now import ipy_profile_PROFILENAME automatically
81 98
82 99 * usage.py, Magic.py: added %quickref
83 100
84 101 * iplib.py: ESC_PAREN fixes: /f 1 2 -> f(1,2), not f(1 2).
85 102
86 103 * GetoptErrors when invoking magics etc. with wrong args
87 104 are now more helpful:
88 105 GetoptError: option -l not recognized (allowed: "qb" )
89 106
90 107 2006-01-25 Fernando Perez <Fernando.Perez@colorado.edu>
91 108
92 109 * IPython/demo.py (Demo.show): Flush stdout after each block, so
93 110 computationally intensive blocks don't appear to stall the demo.
94 111
95 112 2006-01-24 Ville Vainio <vivainio@gmail.com>
96 113
97 114 * iplib.py, hooks.py: 'result_display' hook can return a non-None
98 115 value to manipulate resulting history entry.
99 116
100 117 * ipapi.py: Moved TryNext here from hooks.py. Moved functions
101 118 to instance methods of IPApi class, to make extending an embedded
102 119 IPython feasible. See ext_rehashdir.py for example usage.
103 120
104 121 * Merged 1071-1076 from banches/0.7.1
105 122
106 123
107 124 2006-01-23 Fernando Perez <Fernando.Perez@colorado.edu>
108 125
109 126 * tools/release (daystamp): Fix build tools to use the new
110 127 eggsetup.py script to build lightweight eggs.
111 128
112 129 * Applied changesets 1062 and 1064 before 0.7.1 release.
113 130
114 131 * IPython/Magic.py (magic_history): Add '-r' option to %hist, to
115 132 see the raw input history (without conversions like %ls ->
116 133 ipmagic("ls")). After a request from W. Stein, SAGE
117 134 (http://modular.ucsd.edu/sage) developer. This information is
118 135 stored in the input_hist_raw attribute of the IPython instance, so
119 136 developers can access it if needed (it's an InputList instance).
120 137
121 138 * Versionstring = 0.7.2.svn
122 139
123 140 * eggsetup.py: A separate script for constructing eggs, creates
124 141 proper launch scripts even on Windows (an .exe file in
125 142 \python24\scripts).
126 143
127 144 * ipapi.py: launch_new_instance, launch entry point needed for the
128 145 egg.
129 146
130 147 2006-01-23 Ville Vainio <vivainio@gmail.com>
131 148
132 149 * Added %cpaste magic for pasting python code
133 150
134 151 2006-01-22 Ville Vainio <vivainio@gmail.com>
135 152
136 153 * Merge from branches/0.7.1 into trunk, revs 1052-1057
137 154
138 155 * Versionstring = 0.7.2.svn
139 156
140 157 * eggsetup.py: A separate script for constructing eggs, creates
141 158 proper launch scripts even on Windows (an .exe file in
142 159 \python24\scripts).
143 160
144 161 * ipapi.py: launch_new_instance, launch entry point needed for the
145 162 egg.
146 163
147 164 2006-01-22 Fernando Perez <Fernando.Perez@colorado.edu>
148 165
149 166 * IPython/OInspect.py (Inspector.pinfo): fix bug where foo?? or
150 167 %pfile foo would print the file for foo even if it was a binary.
151 168 Now, extensions '.so' and '.dll' are skipped.
152 169
153 170 * IPython/Shell.py (MTInteractiveShell.__init__): Fix threading
154 171 bug, where macros would fail in all threaded modes. I'm not 100%
155 172 sure, so I'm going to put out an rc instead of making a release
156 173 today, and wait for feedback for at least a few days.
157 174
158 175 * IPython/iplib.py (handle_normal): fix (finally? somehow I doubt
159 176 it...) the handling of pasting external code with autoindent on.
160 177 To get out of a multiline input, the rule will appear for most
161 178 users unchanged: two blank lines or change the indent level
162 179 proposed by IPython. But there is a twist now: you can
163 180 add/subtract only *one or two spaces*. If you add/subtract three
164 181 or more (unless you completely delete the line), IPython will
165 182 accept that line, and you'll need to enter a second one of pure
166 183 whitespace. I know it sounds complicated, but I can't find a
167 184 different solution that covers all the cases, with the right
168 185 heuristics. Hopefully in actual use, nobody will really notice
169 186 all these strange rules and things will 'just work'.
170 187
171 188 2006-01-21 Fernando Perez <Fernando.Perez@colorado.edu>
172 189
173 190 * IPython/iplib.py (interact): catch exceptions which can be
174 191 triggered asynchronously by signal handlers. Thanks to an
175 192 automatic crash report, submitted by Colin Kingsley
176 193 <tercel-AT-gentoo.org>.
177 194
178 195 2006-01-20 Ville Vainio <vivainio@gmail.com>
179 196
180 197 * Ipython/Extensions/ext_rehashdir.py: Created a usable example
181 198 (%rehashdir, very useful, try it out) of how to extend ipython
182 199 with new magics. Also added Extensions dir to pythonpath to make
183 200 importing extensions easy.
184 201
185 202 * %store now complains when trying to store interactively declared
186 203 classes / instances of those classes.
187 204
188 205 * Extensions/ipy_system_conf.py, UserConfig/ipy_user_conf.py,
189 206 ipmaker.py: Config rehaul. Now ipy_..._conf.py are always imported
190 207 if they exist, and ipy_user_conf.py with some defaults is created for
191 208 the user.
192 209
193 210 * Startup rehashing done by the config file, not InterpreterExec.
194 211 This means system commands are available even without selecting the
195 212 pysh profile. It's the sensible default after all.
196 213
197 214 2006-01-20 Fernando Perez <Fernando.Perez@colorado.edu>
198 215
199 216 * IPython/iplib.py (raw_input): I _think_ I got the pasting of
200 217 multiline code with autoindent on working. But I am really not
201 218 sure, so this needs more testing. Will commit a debug-enabled
202 219 version for now, while I test it some more, so that Ville and
203 220 others may also catch any problems. Also made
204 221 self.indent_current_str() a method, to ensure that there's no
205 222 chance of the indent space count and the corresponding string
206 223 falling out of sync. All code needing the string should just call
207 224 the method.
208 225
209 226 2006-01-18 Fernando Perez <Fernando.Perez@colorado.edu>
210 227
211 228 * IPython/Magic.py (magic_edit): fix check for when users don't
212 229 save their output files, the try/except was in the wrong section.
213 230
214 231 2006-01-17 Fernando Perez <Fernando.Perez@colorado.edu>
215 232
216 233 * IPython/Magic.py (magic_run): fix __file__ global missing from
217 234 script's namespace when executed via %run. After a report by
218 235 Vivian.
219 236
220 237 * IPython/Debugger.py (Pdb.__init__): Fix breakage with '%run -d'
221 238 when using python 2.4. The parent constructor changed in 2.4, and
222 239 we need to track it directly (we can't call it, as it messes up
223 240 readline and tab-completion inside our pdb would stop working).
224 241 After a bug report by R. Bernstein <rocky-AT-panix.com>.
225 242
226 243 2006-01-16 Ville Vainio <vivainio@gmail.com>
227 244
228 245 * Ipython/magic.py:Reverted back to old %edit functionality
229 246 that returns file contents on exit.
230 247
231 248 * IPython/path.py: Added Jason Orendorff's "path" module to
232 249 IPython tree, http://www.jorendorff.com/articles/python/path/.
233 250 You can get path objects conveniently through %sc, and !!, e.g.:
234 251 sc files=ls
235 252 for p in files.paths: # or files.p
236 253 print p,p.mtime
237 254
238 255 * Ipython/iplib.py:"," and ";" autoquoting-upon-autocall
239 256 now work again without considering the exclusion regexp -
240 257 hence, things like ',foo my/path' turn to 'foo("my/path")'
241 258 instead of syntax error.
242 259
243 260
244 261 2006-01-14 Ville Vainio <vivainio@gmail.com>
245 262
246 263 * IPython/ipapi.py (ashook, asmagic, options): Added convenience
247 264 ipapi decorators for python 2.4 users, options() provides access to rc
248 265 data.
249 266
250 267 * IPython/Magic.py (magic_cd): %cd now accepts backslashes
251 268 as path separators (even on Linux ;-). Space character after
252 269 backslash (as yielded by tab completer) is still space;
253 270 "%cd long\ name" works as expected.
254 271
255 272 * IPython/ipapi.py,hooks.py,iplib.py: Hooks now implemented
256 273 as "chain of command", with priority. API stays the same,
257 274 TryNext exception raised by a hook function signals that
258 275 current hook failed and next hook should try handling it, as
259 276 suggested by Walter Dörwald <walter@livinglogic.de>. Walter also
260 277 requested configurable display hook, which is now implemented.
261 278
262 279 2006-01-13 Ville Vainio <vivainio@gmail.com>
263 280
264 281 * IPython/platutils*.py: platform specific utility functions,
265 282 so far only set_term_title is implemented (change terminal
266 283 label in windowing systems). %cd now changes the title to
267 284 current dir.
268 285
269 286 * IPython/Release.py: Added myself to "authors" list,
270 287 had to create new files.
271 288
272 289 * IPython/iplib.py (handle_shell_escape): fixed logical flaw in
273 290 shell escape; not a known bug but had potential to be one in the
274 291 future.
275 292
276 293 * IPython/ipapi.py (added),OInspect.py,iplib.py: "Public"
277 294 extension API for IPython! See the module for usage example. Fix
278 295 OInspect for docstring-less magic functions.
279 296
280 297
281 298 2006-01-13 Fernando Perez <Fernando.Perez@colorado.edu>
282 299
283 300 * IPython/iplib.py (raw_input): temporarily deactivate all
284 301 attempts at allowing pasting of code with autoindent on. It
285 302 introduced bugs (reported by Prabhu) and I can't seem to find a
286 303 robust combination which works in all cases. Will have to revisit
287 304 later.
288 305
289 306 * IPython/genutils.py: remove isspace() function. We've dropped
290 307 2.2 compatibility, so it's OK to use the string method.
291 308
292 309 2006-01-12 Fernando Perez <Fernando.Perez@colorado.edu>
293 310
294 311 * IPython/iplib.py (InteractiveShell.__init__): fix regexp
295 312 matching what NOT to autocall on, to include all python binary
296 313 operators (including things like 'and', 'or', 'is' and 'in').
297 314 Prompted by a bug report on 'foo & bar', but I realized we had
298 315 many more potential bug cases with other operators. The regexp is
299 316 self.re_exclude_auto, it's fairly commented.
300 317
301 318 2006-01-12 Ville Vainio <vivainio@gmail.com>
302 319
303 320 * IPython/iplib.py (make_quoted_expr,handle_shell_escape):
304 321 Prettified and hardened string/backslash quoting with ipsystem(),
305 322 ipalias() and ipmagic(). Now even \ characters are passed to
306 323 %magics, !shell escapes and aliases exactly as they are in the
307 324 ipython command line. Should improve backslash experience,
308 325 particularly in Windows (path delimiter for some commands that
309 326 won't understand '/'), but Unix benefits as well (regexps). %cd
310 327 magic still doesn't support backslash path delimiters, though. Also
311 328 deleted all pretense of supporting multiline command strings in
312 329 !system or %magic commands. Thanks to Jerry McRae for suggestions.
313 330
314 331 * doc/build_doc_instructions.txt added. Documentation on how to
315 332 use doc/update_manual.py, added yesterday. Both files contributed
316 333 by Jörgen Stenarson <jorgen.stenarson-AT-bostream.nu>. This slates
317 334 doc/*.sh for deprecation at a later date.
318 335
319 336 * /ipython.py Added ipython.py to root directory for
320 337 zero-installation (tar xzvf ipython.tgz; cd ipython; python
321 338 ipython.py) and development convenience (no need to kee doing
322 339 "setup.py install" between changes).
323 340
324 341 * Made ! and !! shell escapes work (again) in multiline expressions:
325 342 if 1:
326 343 !ls
327 344 !!ls
328 345
329 346 2006-01-12 Fernando Perez <Fernando.Perez@colorado.edu>
330 347
331 348 * IPython/ipstruct.py (Struct): Rename IPython.Struct to
332 349 IPython.ipstruct, to avoid local shadowing of the stdlib 'struct'
333 350 module in case-insensitive installation. Was causing crashes
334 351 under win32. Closes http://www.scipy.net/roundup/ipython/issue49.
335 352
336 353 * IPython/Magic.py (magic_pycat): Fix pycat, patch by Marien Zwart
337 354 <marienz-AT-gentoo.org>, closes
338 355 http://www.scipy.net/roundup/ipython/issue51.
339 356
340 357 2006-01-11 Fernando Perez <Fernando.Perez@colorado.edu>
341 358
342 359 * IPython/Shell.py (IPShellGTK.on_timer): Finally fix the the
343 360 problem of excessive CPU usage under *nix and keyboard lag under
344 361 win32.
345 362
346 363 2006-01-10 *** Released version 0.7.0
347 364
348 365 2006-01-10 Fernando Perez <Fernando.Perez@colorado.edu>
349 366
350 367 * IPython/Release.py (revision): tag version number to 0.7.0,
351 368 ready for release.
352 369
353 370 * IPython/Magic.py (magic_edit): Add print statement to %edit so
354 371 it informs the user of the name of the temp. file used. This can
355 372 help if you decide later to reuse that same file, so you know
356 373 where to copy the info from.
357 374
358 375 2006-01-09 Fernando Perez <Fernando.Perez@colorado.edu>
359 376
360 377 * setup_bdist_egg.py: little script to build an egg. Added
361 378 support in the release tools as well.
362 379
363 380 2006-01-08 Fernando Perez <Fernando.Perez@colorado.edu>
364 381
365 382 * IPython/Shell.py (IPShellWX.__init__): add support for WXPython
366 383 version selection (new -wxversion command line and ipythonrc
367 384 parameter). Patch contributed by Arnd Baecker
368 385 <arnd.baecker-AT-web.de>.
369 386
370 387 * IPython/iplib.py (embed_mainloop): fix tab-completion in
371 388 embedded instances, for variables defined at the interactive
372 389 prompt of the embedded ipython. Reported by Arnd.
373 390
374 391 * IPython/Magic.py (magic_autocall): Fix %autocall magic. Now
375 392 it can be used as a (stateful) toggle, or with a direct parameter.
376 393
377 394 * IPython/ultraTB.py (_fixed_getinnerframes): remove debug assert which
378 395 could be triggered in certain cases and cause the traceback
379 396 printer not to work.
380 397
381 398 2006-01-07 Fernando Perez <Fernando.Perez@colorado.edu>
382 399
383 400 * IPython/iplib.py (_should_recompile): Small fix, closes
384 401 http://www.scipy.net/roundup/ipython/issue48. Patch by Scott.
385 402
386 403 2006-01-04 Fernando Perez <Fernando.Perez@colorado.edu>
387 404
388 405 * IPython/Shell.py (IPShellGTK.mainloop): fix bug in the GTK
389 406 backend for matplotlib (100% cpu utiliziation). Thanks to Charlie
390 407 Moad for help with tracking it down.
391 408
392 409 * IPython/iplib.py (handle_auto): fix autocall handling for
393 410 objects which support BOTH __getitem__ and __call__ (so that f [x]
394 411 is left alone, instead of becoming f([x]) automatically).
395 412
396 413 * IPython/Magic.py (magic_cd): fix crash when cd -b was used.
397 414 Ville's patch.
398 415
399 416 2006-01-03 Fernando Perez <Fernando.Perez@colorado.edu>
400 417
401 418 * IPython/iplib.py (handle_auto): changed autocall semantics to
402 419 include 'smart' mode, where the autocall transformation is NOT
403 420 applied if there are no arguments on the line. This allows you to
404 421 just type 'foo' if foo is a callable to see its internal form,
405 422 instead of having it called with no arguments (typically a
406 423 mistake). The old 'full' autocall still exists: for that, you
407 424 need to set the 'autocall' parameter to 2 in your ipythonrc file.
408 425
409 426 * IPython/completer.py (Completer.attr_matches): add
410 427 tab-completion support for Enthoughts' traits. After a report by
411 428 Arnd and a patch by Prabhu.
412 429
413 430 2006-01-02 Fernando Perez <Fernando.Perez@colorado.edu>
414 431
415 432 * IPython/ultraTB.py (_fixed_getinnerframes): added Alex
416 433 Schmolck's patch to fix inspect.getinnerframes().
417 434
418 435 * IPython/iplib.py (InteractiveShell.__init__): significant fixes
419 436 for embedded instances, regarding handling of namespaces and items
420 437 added to the __builtin__ one. Multiple embedded instances and
421 438 recursive embeddings should work better now (though I'm not sure
422 439 I've got all the corner cases fixed, that code is a bit of a brain
423 440 twister).
424 441
425 442 * IPython/Magic.py (magic_edit): added support to edit in-memory
426 443 macros (automatically creates the necessary temp files). %edit
427 444 also doesn't return the file contents anymore, it's just noise.
428 445
429 446 * IPython/completer.py (Completer.attr_matches): revert change to
430 447 complete only on attributes listed in __all__. I realized it
431 448 cripples the tab-completion system as a tool for exploring the
432 449 internals of unknown libraries (it renders any non-__all__
433 450 attribute off-limits). I got bit by this when trying to see
434 451 something inside the dis module.
435 452
436 453 2005-12-31 Fernando Perez <Fernando.Perez@colorado.edu>
437 454
438 455 * IPython/iplib.py (InteractiveShell.__init__): add .meta
439 456 namespace for users and extension writers to hold data in. This
440 457 follows the discussion in
441 458 http://projects.scipy.org/ipython/ipython/wiki/RefactoringIPython.
442 459
443 460 * IPython/completer.py (IPCompleter.complete): small patch to help
444 461 tab-completion under Emacs, after a suggestion by John Barnard
445 462 <barnarj-AT-ccf.org>.
446 463
447 464 * IPython/Magic.py (Magic.extract_input_slices): added support for
448 465 the slice notation in magics to use N-M to represent numbers N...M
449 466 (closed endpoints). This is used by %macro and %save.
450 467
451 468 * IPython/completer.py (Completer.attr_matches): for modules which
452 469 define __all__, complete only on those. After a patch by Jeffrey
453 470 Collins <jcollins_boulder-AT-earthlink.net>. Also, clean up and
454 471 speed up this routine.
455 472
456 473 * IPython/Logger.py (Logger.log): fix a history handling bug. I
457 474 don't know if this is the end of it, but the behavior now is
458 475 certainly much more correct. Note that coupled with macros,
459 476 slightly surprising (at first) behavior may occur: a macro will in
460 477 general expand to multiple lines of input, so upon exiting, the
461 478 in/out counters will both be bumped by the corresponding amount
462 479 (as if the macro's contents had been typed interactively). Typing
463 480 %hist will reveal the intermediate (silently processed) lines.
464 481
465 482 * IPython/Magic.py (magic_run): fix a subtle bug which could cause
466 483 pickle to fail (%run was overwriting __main__ and not restoring
467 484 it, but pickle relies on __main__ to operate).
468 485
469 486 * IPython/iplib.py (InteractiveShell): fix pdb calling: I'm now
470 487 using properties, but forgot to make the main InteractiveShell
471 488 class a new-style class. Properties fail silently, and
472 489 misteriously, with old-style class (getters work, but
473 490 setters don't do anything).
474 491
475 492 2005-12-30 Fernando Perez <Fernando.Perez@colorado.edu>
476 493
477 494 * IPython/Magic.py (magic_history): fix history reporting bug (I
478 495 know some nasties are still there, I just can't seem to find a
479 496 reproducible test case to track them down; the input history is
480 497 falling out of sync...)
481 498
482 499 * IPython/iplib.py (handle_shell_escape): fix bug where both
483 500 aliases and system accesses where broken for indented code (such
484 501 as loops).
485 502
486 503 * IPython/genutils.py (shell): fix small but critical bug for
487 504 win32 system access.
488 505
489 506 2005-12-29 Fernando Perez <Fernando.Perez@colorado.edu>
490 507
491 508 * IPython/iplib.py (showtraceback): remove use of the
492 509 sys.last_{type/value/traceback} structures, which are non
493 510 thread-safe.
494 511 (_prefilter): change control flow to ensure that we NEVER
495 512 introspect objects when autocall is off. This will guarantee that
496 513 having an input line of the form 'x.y', where access to attribute
497 514 'y' has side effects, doesn't trigger the side effect TWICE. It
498 515 is important to note that, with autocall on, these side effects
499 516 can still happen.
500 517 (ipsystem): new builtin, to complete the ip{magic/alias/system}
501 518 trio. IPython offers these three kinds of special calls which are
502 519 not python code, and it's a good thing to have their call method
503 520 be accessible as pure python functions (not just special syntax at
504 521 the command line). It gives us a better internal implementation
505 522 structure, as well as exposing these for user scripting more
506 523 cleanly.
507 524
508 525 * IPython/macro.py (Macro.__init__): moved macros to a standalone
509 526 file. Now that they'll be more likely to be used with the
510 527 persistance system (%store), I want to make sure their module path
511 528 doesn't change in the future, so that we don't break things for
512 529 users' persisted data.
513 530
514 531 * IPython/iplib.py (autoindent_update): move indentation
515 532 management into the _text_ processing loop, not the keyboard
516 533 interactive one. This is necessary to correctly process non-typed
517 534 multiline input (such as macros).
518 535
519 536 * IPython/Magic.py (Magic.format_latex): patch by Stefan van der
520 537 Walt <stefan-AT-sun.ac.za> to fix latex formatting of docstrings,
521 538 which was producing problems in the resulting manual.
522 539 (magic_whos): improve reporting of instances (show their class,
523 540 instead of simply printing 'instance' which isn't terribly
524 541 informative).
525 542
526 543 * IPython/genutils.py (shell): commit Jorgen Stenarson's patch
527 544 (minor mods) to support network shares under win32.
528 545
529 546 * IPython/winconsole.py (get_console_size): add new winconsole
530 547 module and fixes to page_dumb() to improve its behavior under
531 548 win32. Contributed by Alexander Belchenko <bialix-AT-ukr.net>.
532 549
533 550 * IPython/Magic.py (Macro): simplified Macro class to just
534 551 subclass list. We've had only 2.2 compatibility for a very long
535 552 time, yet I was still avoiding subclassing the builtin types. No
536 553 more (I'm also starting to use properties, though I won't shift to
537 554 2.3-specific features quite yet).
538 555 (magic_store): added Ville's patch for lightweight variable
539 556 persistence, after a request on the user list by Matt Wilkie
540 557 <maphew-AT-gmail.com>. The new %store magic's docstring has full
541 558 details.
542 559
543 560 * IPython/iplib.py (InteractiveShell.post_config_initialization):
544 561 changed the default logfile name from 'ipython.log' to
545 562 'ipython_log.py'. These logs are real python files, and now that
546 563 we have much better multiline support, people are more likely to
547 564 want to use them as such. Might as well name them correctly.
548 565
549 566 * IPython/Magic.py: substantial cleanup. While we can't stop
550 567 using magics as mixins, due to the existing customizations 'out
551 568 there' which rely on the mixin naming conventions, at least I
552 569 cleaned out all cross-class name usage. So once we are OK with
553 570 breaking compatibility, the two systems can be separated.
554 571
555 572 * IPython/Logger.py: major cleanup. This one is NOT a mixin
556 573 anymore, and the class is a fair bit less hideous as well. New
557 574 features were also introduced: timestamping of input, and logging
558 575 of output results. These are user-visible with the -t and -o
559 576 options to %logstart. Closes
560 577 http://www.scipy.net/roundup/ipython/issue11 and a request by
561 578 William Stein (SAGE developer - http://modular.ucsd.edu/sage).
562 579
563 580 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
564 581
565 582 * IPython/iplib.py (handle_shell_escape): add Ville's patch to
566 583 better hadnle backslashes in paths. See the thread 'More Windows
567 584 questions part 2 - \/ characters revisited' on the iypthon user
568 585 list:
569 586 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
570 587
571 588 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
572 589
573 590 (InteractiveShell.__init__): change threaded shells to not use the
574 591 ipython crash handler. This was causing more problems than not,
575 592 as exceptions in the main thread (GUI code, typically) would
576 593 always show up as a 'crash', when they really weren't.
577 594
578 595 The colors and exception mode commands (%colors/%xmode) have been
579 596 synchronized to also take this into account, so users can get
580 597 verbose exceptions for their threaded code as well. I also added
581 598 support for activating pdb inside this exception handler as well,
582 599 so now GUI authors can use IPython's enhanced pdb at runtime.
583 600
584 601 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
585 602 true by default, and add it to the shipped ipythonrc file. Since
586 603 this asks the user before proceeding, I think it's OK to make it
587 604 true by default.
588 605
589 606 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
590 607 of the previous special-casing of input in the eval loop. I think
591 608 this is cleaner, as they really are commands and shouldn't have
592 609 a special role in the middle of the core code.
593 610
594 611 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
595 612
596 613 * IPython/iplib.py (edit_syntax_error): added support for
597 614 automatically reopening the editor if the file had a syntax error
598 615 in it. Thanks to scottt who provided the patch at:
599 616 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
600 617 version committed).
601 618
602 619 * IPython/iplib.py (handle_normal): add suport for multi-line
603 620 input with emtpy lines. This fixes
604 621 http://www.scipy.net/roundup/ipython/issue43 and a similar
605 622 discussion on the user list.
606 623
607 624 WARNING: a behavior change is necessarily introduced to support
608 625 blank lines: now a single blank line with whitespace does NOT
609 626 break the input loop, which means that when autoindent is on, by
610 627 default hitting return on the next (indented) line does NOT exit.
611 628
612 629 Instead, to exit a multiline input you can either have:
613 630
614 631 - TWO whitespace lines (just hit return again), or
615 632 - a single whitespace line of a different length than provided
616 633 by the autoindent (add or remove a space).
617 634
618 635 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
619 636 module to better organize all readline-related functionality.
620 637 I've deleted FlexCompleter and put all completion clases here.
621 638
622 639 * IPython/iplib.py (raw_input): improve indentation management.
623 640 It is now possible to paste indented code with autoindent on, and
624 641 the code is interpreted correctly (though it still looks bad on
625 642 screen, due to the line-oriented nature of ipython).
626 643 (MagicCompleter.complete): change behavior so that a TAB key on an
627 644 otherwise empty line actually inserts a tab, instead of completing
628 645 on the entire global namespace. This makes it easier to use the
629 646 TAB key for indentation. After a request by Hans Meine
630 647 <hans_meine-AT-gmx.net>
631 648 (_prefilter): add support so that typing plain 'exit' or 'quit'
632 649 does a sensible thing. Originally I tried to deviate as little as
633 650 possible from the default python behavior, but even that one may
634 651 change in this direction (thread on python-dev to that effect).
635 652 Regardless, ipython should do the right thing even if CPython's
636 653 '>>>' prompt doesn't.
637 654 (InteractiveShell): removed subclassing code.InteractiveConsole
638 655 class. By now we'd overridden just about all of its methods: I've
639 656 copied the remaining two over, and now ipython is a standalone
640 657 class. This will provide a clearer picture for the chainsaw
641 658 branch refactoring.
642 659
643 660 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
644 661
645 662 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
646 663 failures for objects which break when dir() is called on them.
647 664
648 665 * IPython/FlexCompleter.py (Completer.__init__): Added support for
649 666 distinct local and global namespaces in the completer API. This
650 667 change allows us top properly handle completion with distinct
651 668 scopes, including in embedded instances (this had never really
652 669 worked correctly).
653 670
654 671 Note: this introduces a change in the constructor for
655 672 MagicCompleter, as a new global_namespace parameter is now the
656 673 second argument (the others were bumped one position).
657 674
658 675 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
659 676
660 677 * IPython/iplib.py (embed_mainloop): fix tab-completion in
661 678 embedded instances (which can be done now thanks to Vivian's
662 679 frame-handling fixes for pdb).
663 680 (InteractiveShell.__init__): Fix namespace handling problem in
664 681 embedded instances. We were overwriting __main__ unconditionally,
665 682 and this should only be done for 'full' (non-embedded) IPython;
666 683 embedded instances must respect the caller's __main__. Thanks to
667 684 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
668 685
669 686 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
670 687
671 688 * setup.py: added download_url to setup(). This registers the
672 689 download address at PyPI, which is not only useful to humans
673 690 browsing the site, but is also picked up by setuptools (the Eggs
674 691 machinery). Thanks to Ville and R. Kern for the info/discussion
675 692 on this.
676 693
677 694 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
678 695
679 696 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
680 697 This brings a lot of nice functionality to the pdb mode, which now
681 698 has tab-completion, syntax highlighting, and better stack handling
682 699 than before. Many thanks to Vivian De Smedt
683 700 <vivian-AT-vdesmedt.com> for the original patches.
684 701
685 702 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
686 703
687 704 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
688 705 sequence to consistently accept the banner argument. The
689 706 inconsistency was tripping SAGE, thanks to Gary Zablackis
690 707 <gzabl-AT-yahoo.com> for the report.
691 708
692 709 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
693 710
694 711 * IPython/iplib.py (InteractiveShell.post_config_initialization):
695 712 Fix bug where a naked 'alias' call in the ipythonrc file would
696 713 cause a crash. Bug reported by Jorgen Stenarson.
697 714
698 715 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
699 716
700 717 * IPython/ipmaker.py (make_IPython): cleanups which should improve
701 718 startup time.
702 719
703 720 * IPython/iplib.py (runcode): my globals 'fix' for embedded
704 721 instances had introduced a bug with globals in normal code. Now
705 722 it's working in all cases.
706 723
707 724 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
708 725 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
709 726 has been introduced to set the default case sensitivity of the
710 727 searches. Users can still select either mode at runtime on a
711 728 per-search basis.
712 729
713 730 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
714 731
715 732 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
716 733 attributes in wildcard searches for subclasses. Modified version
717 734 of a patch by Jorgen.
718 735
719 736 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
720 737
721 738 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
722 739 embedded instances. I added a user_global_ns attribute to the
723 740 InteractiveShell class to handle this.
724 741
725 742 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
726 743
727 744 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
728 745 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
729 746 (reported under win32, but may happen also in other platforms).
730 747 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
731 748
732 749 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
733 750
734 751 * IPython/Magic.py (magic_psearch): new support for wildcard
735 752 patterns. Now, typing ?a*b will list all names which begin with a
736 753 and end in b, for example. The %psearch magic has full
737 754 docstrings. Many thanks to Jörgen Stenarson
738 755 <jorgen.stenarson-AT-bostream.nu>, author of the patches
739 756 implementing this functionality.
740 757
741 758 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
742 759
743 760 * Manual: fixed long-standing annoyance of double-dashes (as in
744 761 --prefix=~, for example) being stripped in the HTML version. This
745 762 is a latex2html bug, but a workaround was provided. Many thanks
746 763 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
747 764 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
748 765 rolling. This seemingly small issue had tripped a number of users
749 766 when first installing, so I'm glad to see it gone.
750 767
751 768 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
752 769
753 770 * IPython/Extensions/numeric_formats.py: fix missing import,
754 771 reported by Stephen Walton.
755 772
756 773 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
757 774
758 775 * IPython/demo.py: finish demo module, fully documented now.
759 776
760 777 * IPython/genutils.py (file_read): simple little utility to read a
761 778 file and ensure it's closed afterwards.
762 779
763 780 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
764 781
765 782 * IPython/demo.py (Demo.__init__): added support for individually
766 783 tagging blocks for automatic execution.
767 784
768 785 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
769 786 syntax-highlighted python sources, requested by John.
770 787
771 788 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
772 789
773 790 * IPython/demo.py (Demo.again): fix bug where again() blocks after
774 791 finishing.
775 792
776 793 * IPython/genutils.py (shlex_split): moved from Magic to here,
777 794 where all 2.2 compatibility stuff lives. I needed it for demo.py.
778 795
779 796 * IPython/demo.py (Demo.__init__): added support for silent
780 797 blocks, improved marks as regexps, docstrings written.
781 798 (Demo.__init__): better docstring, added support for sys.argv.
782 799
783 800 * IPython/genutils.py (marquee): little utility used by the demo
784 801 code, handy in general.
785 802
786 803 * IPython/demo.py (Demo.__init__): new class for interactive
787 804 demos. Not documented yet, I just wrote it in a hurry for
788 805 scipy'05. Will docstring later.
789 806
790 807 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
791 808
792 809 * IPython/Shell.py (sigint_handler): Drastic simplification which
793 810 also seems to make Ctrl-C work correctly across threads! This is
794 811 so simple, that I can't beleive I'd missed it before. Needs more
795 812 testing, though.
796 813 (KBINT): Never mind, revert changes. I'm sure I'd tried something
797 814 like this before...
798 815
799 816 * IPython/genutils.py (get_home_dir): add protection against
800 817 non-dirs in win32 registry.
801 818
802 819 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
803 820 bug where dict was mutated while iterating (pysh crash).
804 821
805 822 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
806 823
807 824 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
808 825 spurious newlines added by this routine. After a report by
809 826 F. Mantegazza.
810 827
811 828 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
812 829
813 830 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
814 831 calls. These were a leftover from the GTK 1.x days, and can cause
815 832 problems in certain cases (after a report by John Hunter).
816 833
817 834 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
818 835 os.getcwd() fails at init time. Thanks to patch from David Remahl
819 836 <chmod007-AT-mac.com>.
820 837 (InteractiveShell.__init__): prevent certain special magics from
821 838 being shadowed by aliases. Closes
822 839 http://www.scipy.net/roundup/ipython/issue41.
823 840
824 841 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
825 842
826 843 * IPython/iplib.py (InteractiveShell.complete): Added new
827 844 top-level completion method to expose the completion mechanism
828 845 beyond readline-based environments.
829 846
830 847 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
831 848
832 849 * tools/ipsvnc (svnversion): fix svnversion capture.
833 850
834 851 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
835 852 attribute to self, which was missing. Before, it was set by a
836 853 routine which in certain cases wasn't being called, so the
837 854 instance could end up missing the attribute. This caused a crash.
838 855 Closes http://www.scipy.net/roundup/ipython/issue40.
839 856
840 857 2005-08-16 Fernando Perez <fperez@colorado.edu>
841 858
842 859 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
843 860 contains non-string attribute. Closes
844 861 http://www.scipy.net/roundup/ipython/issue38.
845 862
846 863 2005-08-14 Fernando Perez <fperez@colorado.edu>
847 864
848 865 * tools/ipsvnc: Minor improvements, to add changeset info.
849 866
850 867 2005-08-12 Fernando Perez <fperez@colorado.edu>
851 868
852 869 * IPython/iplib.py (runsource): remove self.code_to_run_src
853 870 attribute. I realized this is nothing more than
854 871 '\n'.join(self.buffer), and having the same data in two different
855 872 places is just asking for synchronization bugs. This may impact
856 873 people who have custom exception handlers, so I need to warn
857 874 ipython-dev about it (F. Mantegazza may use them).
858 875
859 876 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
860 877
861 878 * IPython/genutils.py: fix 2.2 compatibility (generators)
862 879
863 880 2005-07-18 Fernando Perez <fperez@colorado.edu>
864 881
865 882 * IPython/genutils.py (get_home_dir): fix to help users with
866 883 invalid $HOME under win32.
867 884
868 885 2005-07-17 Fernando Perez <fperez@colorado.edu>
869 886
870 887 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
871 888 some old hacks and clean up a bit other routines; code should be
872 889 simpler and a bit faster.
873 890
874 891 * IPython/iplib.py (interact): removed some last-resort attempts
875 892 to survive broken stdout/stderr. That code was only making it
876 893 harder to abstract out the i/o (necessary for gui integration),
877 894 and the crashes it could prevent were extremely rare in practice
878 895 (besides being fully user-induced in a pretty violent manner).
879 896
880 897 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
881 898 Nothing major yet, but the code is simpler to read; this should
882 899 make it easier to do more serious modifications in the future.
883 900
884 901 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
885 902 which broke in .15 (thanks to a report by Ville).
886 903
887 904 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
888 905 be quite correct, I know next to nothing about unicode). This
889 906 will allow unicode strings to be used in prompts, amongst other
890 907 cases. It also will prevent ipython from crashing when unicode
891 908 shows up unexpectedly in many places. If ascii encoding fails, we
892 909 assume utf_8. Currently the encoding is not a user-visible
893 910 setting, though it could be made so if there is demand for it.
894 911
895 912 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
896 913
897 914 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
898 915
899 916 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
900 917
901 918 * IPython/genutils.py: Add 2.2 compatibility here, so all other
902 919 code can work transparently for 2.2/2.3.
903 920
904 921 2005-07-16 Fernando Perez <fperez@colorado.edu>
905 922
906 923 * IPython/ultraTB.py (ExceptionColors): Make a global variable
907 924 out of the color scheme table used for coloring exception
908 925 tracebacks. This allows user code to add new schemes at runtime.
909 926 This is a minimally modified version of the patch at
910 927 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
911 928 for the contribution.
912 929
913 930 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
914 931 slightly modified version of the patch in
915 932 http://www.scipy.net/roundup/ipython/issue34, which also allows me
916 933 to remove the previous try/except solution (which was costlier).
917 934 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
918 935
919 936 2005-06-08 Fernando Perez <fperez@colorado.edu>
920 937
921 938 * IPython/iplib.py (write/write_err): Add methods to abstract all
922 939 I/O a bit more.
923 940
924 941 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
925 942 warning, reported by Aric Hagberg, fix by JD Hunter.
926 943
927 944 2005-06-02 *** Released version 0.6.15
928 945
929 946 2005-06-01 Fernando Perez <fperez@colorado.edu>
930 947
931 948 * IPython/iplib.py (MagicCompleter.file_matches): Fix
932 949 tab-completion of filenames within open-quoted strings. Note that
933 950 this requires that in ~/.ipython/ipythonrc, users change the
934 951 readline delimiters configuration to read:
935 952
936 953 readline_remove_delims -/~
937 954
938 955
939 956 2005-05-31 *** Released version 0.6.14
940 957
941 958 2005-05-29 Fernando Perez <fperez@colorado.edu>
942 959
943 960 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
944 961 with files not on the filesystem. Reported by Eliyahu Sandler
945 962 <eli@gondolin.net>
946 963
947 964 2005-05-22 Fernando Perez <fperez@colorado.edu>
948 965
949 966 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
950 967 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
951 968
952 969 2005-05-19 Fernando Perez <fperez@colorado.edu>
953 970
954 971 * IPython/iplib.py (safe_execfile): close a file which could be
955 972 left open (causing problems in win32, which locks open files).
956 973 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
957 974
958 975 2005-05-18 Fernando Perez <fperez@colorado.edu>
959 976
960 977 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
961 978 keyword arguments correctly to safe_execfile().
962 979
963 980 2005-05-13 Fernando Perez <fperez@colorado.edu>
964 981
965 982 * ipython.1: Added info about Qt to manpage, and threads warning
966 983 to usage page (invoked with --help).
967 984
968 985 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
969 986 new matcher (it goes at the end of the priority list) to do
970 987 tab-completion on named function arguments. Submitted by George
971 988 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
972 989 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
973 990 for more details.
974 991
975 992 * IPython/Magic.py (magic_run): Added new -e flag to ignore
976 993 SystemExit exceptions in the script being run. Thanks to a report
977 994 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
978 995 producing very annoying behavior when running unit tests.
979 996
980 997 2005-05-12 Fernando Perez <fperez@colorado.edu>
981 998
982 999 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
983 1000 which I'd broken (again) due to a changed regexp. In the process,
984 1001 added ';' as an escape to auto-quote the whole line without
985 1002 splitting its arguments. Thanks to a report by Jerry McRae
986 1003 <qrs0xyc02-AT-sneakemail.com>.
987 1004
988 1005 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
989 1006 possible crashes caused by a TokenError. Reported by Ed Schofield
990 1007 <schofield-AT-ftw.at>.
991 1008
992 1009 2005-05-06 Fernando Perez <fperez@colorado.edu>
993 1010
994 1011 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
995 1012
996 1013 2005-04-29 Fernando Perez <fperez@colorado.edu>
997 1014
998 1015 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
999 1016 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
1000 1017 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
1001 1018 which provides support for Qt interactive usage (similar to the
1002 1019 existing one for WX and GTK). This had been often requested.
1003 1020
1004 1021 2005-04-14 *** Released version 0.6.13
1005 1022
1006 1023 2005-04-08 Fernando Perez <fperez@colorado.edu>
1007 1024
1008 1025 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
1009 1026 from _ofind, which gets called on almost every input line. Now,
1010 1027 we only try to get docstrings if they are actually going to be
1011 1028 used (the overhead of fetching unnecessary docstrings can be
1012 1029 noticeable for certain objects, such as Pyro proxies).
1013 1030
1014 1031 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
1015 1032 for completers. For some reason I had been passing them the state
1016 1033 variable, which completers never actually need, and was in
1017 1034 conflict with the rlcompleter API. Custom completers ONLY need to
1018 1035 take the text parameter.
1019 1036
1020 1037 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
1021 1038 work correctly in pysh. I've also moved all the logic which used
1022 1039 to be in pysh.py here, which will prevent problems with future
1023 1040 upgrades. However, this time I must warn users to update their
1024 1041 pysh profile to include the line
1025 1042
1026 1043 import_all IPython.Extensions.InterpreterExec
1027 1044
1028 1045 because otherwise things won't work for them. They MUST also
1029 1046 delete pysh.py and the line
1030 1047
1031 1048 execfile pysh.py
1032 1049
1033 1050 from their ipythonrc-pysh.
1034 1051
1035 1052 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
1036 1053 robust in the face of objects whose dir() returns non-strings
1037 1054 (which it shouldn't, but some broken libs like ITK do). Thanks to
1038 1055 a patch by John Hunter (implemented differently, though). Also
1039 1056 minor improvements by using .extend instead of + on lists.
1040 1057
1041 1058 * pysh.py:
1042 1059
1043 1060 2005-04-06 Fernando Perez <fperez@colorado.edu>
1044 1061
1045 1062 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
1046 1063 by default, so that all users benefit from it. Those who don't
1047 1064 want it can still turn it off.
1048 1065
1049 1066 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
1050 1067 config file, I'd forgotten about this, so users were getting it
1051 1068 off by default.
1052 1069
1053 1070 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
1054 1071 consistency. Now magics can be called in multiline statements,
1055 1072 and python variables can be expanded in magic calls via $var.
1056 1073 This makes the magic system behave just like aliases or !system
1057 1074 calls.
1058 1075
1059 1076 2005-03-28 Fernando Perez <fperez@colorado.edu>
1060 1077
1061 1078 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
1062 1079 expensive string additions for building command. Add support for
1063 1080 trailing ';' when autocall is used.
1064 1081
1065 1082 2005-03-26 Fernando Perez <fperez@colorado.edu>
1066 1083
1067 1084 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
1068 1085 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
1069 1086 ipython.el robust against prompts with any number of spaces
1070 1087 (including 0) after the ':' character.
1071 1088
1072 1089 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
1073 1090 continuation prompt, which misled users to think the line was
1074 1091 already indented. Closes debian Bug#300847, reported to me by
1075 1092 Norbert Tretkowski <tretkowski-AT-inittab.de>.
1076 1093
1077 1094 2005-03-23 Fernando Perez <fperez@colorado.edu>
1078 1095
1079 1096 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
1080 1097 properly aligned if they have embedded newlines.
1081 1098
1082 1099 * IPython/iplib.py (runlines): Add a public method to expose
1083 1100 IPython's code execution machinery, so that users can run strings
1084 1101 as if they had been typed at the prompt interactively.
1085 1102 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
1086 1103 methods which can call the system shell, but with python variable
1087 1104 expansion. The three such methods are: __IPYTHON__.system,
1088 1105 .getoutput and .getoutputerror. These need to be documented in a
1089 1106 'public API' section (to be written) of the manual.
1090 1107
1091 1108 2005-03-20 Fernando Perez <fperez@colorado.edu>
1092 1109
1093 1110 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
1094 1111 for custom exception handling. This is quite powerful, and it
1095 1112 allows for user-installable exception handlers which can trap
1096 1113 custom exceptions at runtime and treat them separately from
1097 1114 IPython's default mechanisms. At the request of Frédéric
1098 1115 Mantegazza <mantegazza-AT-ill.fr>.
1099 1116 (InteractiveShell.set_custom_completer): public API function to
1100 1117 add new completers at runtime.
1101 1118
1102 1119 2005-03-19 Fernando Perez <fperez@colorado.edu>
1103 1120
1104 1121 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
1105 1122 allow objects which provide their docstrings via non-standard
1106 1123 mechanisms (like Pyro proxies) to still be inspected by ipython's
1107 1124 ? system.
1108 1125
1109 1126 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
1110 1127 automatic capture system. I tried quite hard to make it work
1111 1128 reliably, and simply failed. I tried many combinations with the
1112 1129 subprocess module, but eventually nothing worked in all needed
1113 1130 cases (not blocking stdin for the child, duplicating stdout
1114 1131 without blocking, etc). The new %sc/%sx still do capture to these
1115 1132 magical list/string objects which make shell use much more
1116 1133 conveninent, so not all is lost.
1117 1134
1118 1135 XXX - FIX MANUAL for the change above!
1119 1136
1120 1137 (runsource): I copied code.py's runsource() into ipython to modify
1121 1138 it a bit. Now the code object and source to be executed are
1122 1139 stored in ipython. This makes this info accessible to third-party
1123 1140 tools, like custom exception handlers. After a request by Frédéric
1124 1141 Mantegazza <mantegazza-AT-ill.fr>.
1125 1142
1126 1143 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
1127 1144 history-search via readline (like C-p/C-n). I'd wanted this for a
1128 1145 long time, but only recently found out how to do it. For users
1129 1146 who already have their ipythonrc files made and want this, just
1130 1147 add:
1131 1148
1132 1149 readline_parse_and_bind "\e[A": history-search-backward
1133 1150 readline_parse_and_bind "\e[B": history-search-forward
1134 1151
1135 1152 2005-03-18 Fernando Perez <fperez@colorado.edu>
1136 1153
1137 1154 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
1138 1155 LSString and SList classes which allow transparent conversions
1139 1156 between list mode and whitespace-separated string.
1140 1157 (magic_r): Fix recursion problem in %r.
1141 1158
1142 1159 * IPython/genutils.py (LSString): New class to be used for
1143 1160 automatic storage of the results of all alias/system calls in _o
1144 1161 and _e (stdout/err). These provide a .l/.list attribute which
1145 1162 does automatic splitting on newlines. This means that for most
1146 1163 uses, you'll never need to do capturing of output with %sc/%sx
1147 1164 anymore, since ipython keeps this always done for you. Note that
1148 1165 only the LAST results are stored, the _o/e variables are
1149 1166 overwritten on each call. If you need to save their contents
1150 1167 further, simply bind them to any other name.
1151 1168
1152 1169 2005-03-17 Fernando Perez <fperez@colorado.edu>
1153 1170
1154 1171 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
1155 1172 prompt namespace handling.
1156 1173
1157 1174 2005-03-16 Fernando Perez <fperez@colorado.edu>
1158 1175
1159 1176 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
1160 1177 classic prompts to be '>>> ' (final space was missing, and it
1161 1178 trips the emacs python mode).
1162 1179 (BasePrompt.__str__): Added safe support for dynamic prompt
1163 1180 strings. Now you can set your prompt string to be '$x', and the
1164 1181 value of x will be printed from your interactive namespace. The
1165 1182 interpolation syntax includes the full Itpl support, so
1166 1183 ${foo()+x+bar()} is a valid prompt string now, and the function
1167 1184 calls will be made at runtime.
1168 1185
1169 1186 2005-03-15 Fernando Perez <fperez@colorado.edu>
1170 1187
1171 1188 * IPython/Magic.py (magic_history): renamed %hist to %history, to
1172 1189 avoid name clashes in pylab. %hist still works, it just forwards
1173 1190 the call to %history.
1174 1191
1175 1192 2005-03-02 *** Released version 0.6.12
1176 1193
1177 1194 2005-03-02 Fernando Perez <fperez@colorado.edu>
1178 1195
1179 1196 * IPython/iplib.py (handle_magic): log magic calls properly as
1180 1197 ipmagic() function calls.
1181 1198
1182 1199 * IPython/Magic.py (magic_time): Improved %time to support
1183 1200 statements and provide wall-clock as well as CPU time.
1184 1201
1185 1202 2005-02-27 Fernando Perez <fperez@colorado.edu>
1186 1203
1187 1204 * IPython/hooks.py: New hooks module, to expose user-modifiable
1188 1205 IPython functionality in a clean manner. For now only the editor
1189 1206 hook is actually written, and other thigns which I intend to turn
1190 1207 into proper hooks aren't yet there. The display and prefilter
1191 1208 stuff, for example, should be hooks. But at least now the
1192 1209 framework is in place, and the rest can be moved here with more
1193 1210 time later. IPython had had a .hooks variable for a long time for
1194 1211 this purpose, but I'd never actually used it for anything.
1195 1212
1196 1213 2005-02-26 Fernando Perez <fperez@colorado.edu>
1197 1214
1198 1215 * IPython/ipmaker.py (make_IPython): make the default ipython
1199 1216 directory be called _ipython under win32, to follow more the
1200 1217 naming peculiarities of that platform (where buggy software like
1201 1218 Visual Sourcesafe breaks with .named directories). Reported by
1202 1219 Ville Vainio.
1203 1220
1204 1221 2005-02-23 Fernando Perez <fperez@colorado.edu>
1205 1222
1206 1223 * IPython/iplib.py (InteractiveShell.__init__): removed a few
1207 1224 auto_aliases for win32 which were causing problems. Users can
1208 1225 define the ones they personally like.
1209 1226
1210 1227 2005-02-21 Fernando Perez <fperez@colorado.edu>
1211 1228
1212 1229 * IPython/Magic.py (magic_time): new magic to time execution of
1213 1230 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
1214 1231
1215 1232 2005-02-19 Fernando Perez <fperez@colorado.edu>
1216 1233
1217 1234 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
1218 1235 into keys (for prompts, for example).
1219 1236
1220 1237 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
1221 1238 prompts in case users want them. This introduces a small behavior
1222 1239 change: ipython does not automatically add a space to all prompts
1223 1240 anymore. To get the old prompts with a space, users should add it
1224 1241 manually to their ipythonrc file, so for example prompt_in1 should
1225 1242 now read 'In [\#]: ' instead of 'In [\#]:'.
1226 1243 (BasePrompt.__init__): New option prompts_pad_left (only in rc
1227 1244 file) to control left-padding of secondary prompts.
1228 1245
1229 1246 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
1230 1247 the profiler can't be imported. Fix for Debian, which removed
1231 1248 profile.py because of License issues. I applied a slightly
1232 1249 modified version of the original Debian patch at
1233 1250 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
1234 1251
1235 1252 2005-02-17 Fernando Perez <fperez@colorado.edu>
1236 1253
1237 1254 * IPython/genutils.py (native_line_ends): Fix bug which would
1238 1255 cause improper line-ends under win32 b/c I was not opening files
1239 1256 in binary mode. Bug report and fix thanks to Ville.
1240 1257
1241 1258 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
1242 1259 trying to catch spurious foo[1] autocalls. My fix actually broke
1243 1260 ',/' autoquote/call with explicit escape (bad regexp).
1244 1261
1245 1262 2005-02-15 *** Released version 0.6.11
1246 1263
1247 1264 2005-02-14 Fernando Perez <fperez@colorado.edu>
1248 1265
1249 1266 * IPython/background_jobs.py: New background job management
1250 1267 subsystem. This is implemented via a new set of classes, and
1251 1268 IPython now provides a builtin 'jobs' object for background job
1252 1269 execution. A convenience %bg magic serves as a lightweight
1253 1270 frontend for starting the more common type of calls. This was
1254 1271 inspired by discussions with B. Granger and the BackgroundCommand
1255 1272 class described in the book Python Scripting for Computational
1256 1273 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
1257 1274 (although ultimately no code from this text was used, as IPython's
1258 1275 system is a separate implementation).
1259 1276
1260 1277 * IPython/iplib.py (MagicCompleter.python_matches): add new option
1261 1278 to control the completion of single/double underscore names
1262 1279 separately. As documented in the example ipytonrc file, the
1263 1280 readline_omit__names variable can now be set to 2, to omit even
1264 1281 single underscore names. Thanks to a patch by Brian Wong
1265 1282 <BrianWong-AT-AirgoNetworks.Com>.
1266 1283 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
1267 1284 be autocalled as foo([1]) if foo were callable. A problem for
1268 1285 things which are both callable and implement __getitem__.
1269 1286 (init_readline): Fix autoindentation for win32. Thanks to a patch
1270 1287 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
1271 1288
1272 1289 2005-02-12 Fernando Perez <fperez@colorado.edu>
1273 1290
1274 1291 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
1275 1292 which I had written long ago to sort out user error messages which
1276 1293 may occur during startup. This seemed like a good idea initially,
1277 1294 but it has proven a disaster in retrospect. I don't want to
1278 1295 change much code for now, so my fix is to set the internal 'debug'
1279 1296 flag to true everywhere, whose only job was precisely to control
1280 1297 this subsystem. This closes issue 28 (as well as avoiding all
1281 1298 sorts of strange hangups which occur from time to time).
1282 1299
1283 1300 2005-02-07 Fernando Perez <fperez@colorado.edu>
1284 1301
1285 1302 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
1286 1303 previous call produced a syntax error.
1287 1304
1288 1305 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
1289 1306 classes without constructor.
1290 1307
1291 1308 2005-02-06 Fernando Perez <fperez@colorado.edu>
1292 1309
1293 1310 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
1294 1311 completions with the results of each matcher, so we return results
1295 1312 to the user from all namespaces. This breaks with ipython
1296 1313 tradition, but I think it's a nicer behavior. Now you get all
1297 1314 possible completions listed, from all possible namespaces (python,
1298 1315 filesystem, magics...) After a request by John Hunter
1299 1316 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1300 1317
1301 1318 2005-02-05 Fernando Perez <fperez@colorado.edu>
1302 1319
1303 1320 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
1304 1321 the call had quote characters in it (the quotes were stripped).
1305 1322
1306 1323 2005-01-31 Fernando Perez <fperez@colorado.edu>
1307 1324
1308 1325 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
1309 1326 Itpl.itpl() to make the code more robust against psyco
1310 1327 optimizations.
1311 1328
1312 1329 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
1313 1330 of causing an exception. Quicker, cleaner.
1314 1331
1315 1332 2005-01-28 Fernando Perez <fperez@colorado.edu>
1316 1333
1317 1334 * scripts/ipython_win_post_install.py (install): hardcode
1318 1335 sys.prefix+'python.exe' as the executable path. It turns out that
1319 1336 during the post-installation run, sys.executable resolves to the
1320 1337 name of the binary installer! I should report this as a distutils
1321 1338 bug, I think. I updated the .10 release with this tiny fix, to
1322 1339 avoid annoying the lists further.
1323 1340
1324 1341 2005-01-27 *** Released version 0.6.10
1325 1342
1326 1343 2005-01-27 Fernando Perez <fperez@colorado.edu>
1327 1344
1328 1345 * IPython/numutils.py (norm): Added 'inf' as optional name for
1329 1346 L-infinity norm, included references to mathworld.com for vector
1330 1347 norm definitions.
1331 1348 (amin/amax): added amin/amax for array min/max. Similar to what
1332 1349 pylab ships with after the recent reorganization of names.
1333 1350 (spike/spike_odd): removed deprecated spike/spike_odd functions.
1334 1351
1335 1352 * ipython.el: committed Alex's recent fixes and improvements.
1336 1353 Tested with python-mode from CVS, and it looks excellent. Since
1337 1354 python-mode hasn't released anything in a while, I'm temporarily
1338 1355 putting a copy of today's CVS (v 4.70) of python-mode in:
1339 1356 http://ipython.scipy.org/tmp/python-mode.el
1340 1357
1341 1358 * scripts/ipython_win_post_install.py (install): Win32 fix to use
1342 1359 sys.executable for the executable name, instead of assuming it's
1343 1360 called 'python.exe' (the post-installer would have produced broken
1344 1361 setups on systems with a differently named python binary).
1345 1362
1346 1363 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
1347 1364 references to os.linesep, to make the code more
1348 1365 platform-independent. This is also part of the win32 coloring
1349 1366 fixes.
1350 1367
1351 1368 * IPython/genutils.py (page_dumb): Remove attempts to chop long
1352 1369 lines, which actually cause coloring bugs because the length of
1353 1370 the line is very difficult to correctly compute with embedded
1354 1371 escapes. This was the source of all the coloring problems under
1355 1372 Win32. I think that _finally_, Win32 users have a properly
1356 1373 working ipython in all respects. This would never have happened
1357 1374 if not for Gary Bishop and Viktor Ransmayr's great help and work.
1358 1375
1359 1376 2005-01-26 *** Released version 0.6.9
1360 1377
1361 1378 2005-01-25 Fernando Perez <fperez@colorado.edu>
1362 1379
1363 1380 * setup.py: finally, we have a true Windows installer, thanks to
1364 1381 the excellent work of Viktor Ransmayr
1365 1382 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
1366 1383 Windows users. The setup routine is quite a bit cleaner thanks to
1367 1384 this, and the post-install script uses the proper functions to
1368 1385 allow a clean de-installation using the standard Windows Control
1369 1386 Panel.
1370 1387
1371 1388 * IPython/genutils.py (get_home_dir): changed to use the $HOME
1372 1389 environment variable under all OSes (including win32) if
1373 1390 available. This will give consistency to win32 users who have set
1374 1391 this variable for any reason. If os.environ['HOME'] fails, the
1375 1392 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
1376 1393
1377 1394 2005-01-24 Fernando Perez <fperez@colorado.edu>
1378 1395
1379 1396 * IPython/numutils.py (empty_like): add empty_like(), similar to
1380 1397 zeros_like() but taking advantage of the new empty() Numeric routine.
1381 1398
1382 1399 2005-01-23 *** Released version 0.6.8
1383 1400
1384 1401 2005-01-22 Fernando Perez <fperez@colorado.edu>
1385 1402
1386 1403 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
1387 1404 automatic show() calls. After discussing things with JDH, it
1388 1405 turns out there are too many corner cases where this can go wrong.
1389 1406 It's best not to try to be 'too smart', and simply have ipython
1390 1407 reproduce as much as possible the default behavior of a normal
1391 1408 python shell.
1392 1409
1393 1410 * IPython/iplib.py (InteractiveShell.__init__): Modified the
1394 1411 line-splitting regexp and _prefilter() to avoid calling getattr()
1395 1412 on assignments. This closes
1396 1413 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
1397 1414 readline uses getattr(), so a simple <TAB> keypress is still
1398 1415 enough to trigger getattr() calls on an object.
1399 1416
1400 1417 2005-01-21 Fernando Perez <fperez@colorado.edu>
1401 1418
1402 1419 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
1403 1420 docstring under pylab so it doesn't mask the original.
1404 1421
1405 1422 2005-01-21 *** Released version 0.6.7
1406 1423
1407 1424 2005-01-21 Fernando Perez <fperez@colorado.edu>
1408 1425
1409 1426 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
1410 1427 signal handling for win32 users in multithreaded mode.
1411 1428
1412 1429 2005-01-17 Fernando Perez <fperez@colorado.edu>
1413 1430
1414 1431 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
1415 1432 instances with no __init__. After a crash report by Norbert Nemec
1416 1433 <Norbert-AT-nemec-online.de>.
1417 1434
1418 1435 2005-01-14 Fernando Perez <fperez@colorado.edu>
1419 1436
1420 1437 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
1421 1438 names for verbose exceptions, when multiple dotted names and the
1422 1439 'parent' object were present on the same line.
1423 1440
1424 1441 2005-01-11 Fernando Perez <fperez@colorado.edu>
1425 1442
1426 1443 * IPython/genutils.py (flag_calls): new utility to trap and flag
1427 1444 calls in functions. I need it to clean up matplotlib support.
1428 1445 Also removed some deprecated code in genutils.
1429 1446
1430 1447 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
1431 1448 that matplotlib scripts called with %run, which don't call show()
1432 1449 themselves, still have their plotting windows open.
1433 1450
1434 1451 2005-01-05 Fernando Perez <fperez@colorado.edu>
1435 1452
1436 1453 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
1437 1454 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
1438 1455
1439 1456 2004-12-19 Fernando Perez <fperez@colorado.edu>
1440 1457
1441 1458 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
1442 1459 parent_runcode, which was an eyesore. The same result can be
1443 1460 obtained with Python's regular superclass mechanisms.
1444 1461
1445 1462 2004-12-17 Fernando Perez <fperez@colorado.edu>
1446 1463
1447 1464 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
1448 1465 reported by Prabhu.
1449 1466 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
1450 1467 sys.stderr) instead of explicitly calling sys.stderr. This helps
1451 1468 maintain our I/O abstractions clean, for future GUI embeddings.
1452 1469
1453 1470 * IPython/genutils.py (info): added new utility for sys.stderr
1454 1471 unified info message handling (thin wrapper around warn()).
1455 1472
1456 1473 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
1457 1474 composite (dotted) names on verbose exceptions.
1458 1475 (VerboseTB.nullrepr): harden against another kind of errors which
1459 1476 Python's inspect module can trigger, and which were crashing
1460 1477 IPython. Thanks to a report by Marco Lombardi
1461 1478 <mlombard-AT-ma010192.hq.eso.org>.
1462 1479
1463 1480 2004-12-13 *** Released version 0.6.6
1464 1481
1465 1482 2004-12-12 Fernando Perez <fperez@colorado.edu>
1466 1483
1467 1484 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
1468 1485 generated by pygtk upon initialization if it was built without
1469 1486 threads (for matplotlib users). After a crash reported by
1470 1487 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
1471 1488
1472 1489 * IPython/ipmaker.py (make_IPython): fix small bug in the
1473 1490 import_some parameter for multiple imports.
1474 1491
1475 1492 * IPython/iplib.py (ipmagic): simplified the interface of
1476 1493 ipmagic() to take a single string argument, just as it would be
1477 1494 typed at the IPython cmd line.
1478 1495 (ipalias): Added new ipalias() with an interface identical to
1479 1496 ipmagic(). This completes exposing a pure python interface to the
1480 1497 alias and magic system, which can be used in loops or more complex
1481 1498 code where IPython's automatic line mangling is not active.
1482 1499
1483 1500 * IPython/genutils.py (timing): changed interface of timing to
1484 1501 simply run code once, which is the most common case. timings()
1485 1502 remains unchanged, for the cases where you want multiple runs.
1486 1503
1487 1504 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
1488 1505 bug where Python2.2 crashes with exec'ing code which does not end
1489 1506 in a single newline. Python 2.3 is OK, so I hadn't noticed this
1490 1507 before.
1491 1508
1492 1509 2004-12-10 Fernando Perez <fperez@colorado.edu>
1493 1510
1494 1511 * IPython/Magic.py (Magic.magic_prun): changed name of option from
1495 1512 -t to -T, to accomodate the new -t flag in %run (the %run and
1496 1513 %prun options are kind of intermixed, and it's not easy to change
1497 1514 this with the limitations of python's getopt).
1498 1515
1499 1516 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
1500 1517 the execution of scripts. It's not as fine-tuned as timeit.py,
1501 1518 but it works from inside ipython (and under 2.2, which lacks
1502 1519 timeit.py). Optionally a number of runs > 1 can be given for
1503 1520 timing very short-running code.
1504 1521
1505 1522 * IPython/genutils.py (uniq_stable): new routine which returns a
1506 1523 list of unique elements in any iterable, but in stable order of
1507 1524 appearance. I needed this for the ultraTB fixes, and it's a handy
1508 1525 utility.
1509 1526
1510 1527 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
1511 1528 dotted names in Verbose exceptions. This had been broken since
1512 1529 the very start, now x.y will properly be printed in a Verbose
1513 1530 traceback, instead of x being shown and y appearing always as an
1514 1531 'undefined global'. Getting this to work was a bit tricky,
1515 1532 because by default python tokenizers are stateless. Saved by
1516 1533 python's ability to easily add a bit of state to an arbitrary
1517 1534 function (without needing to build a full-blown callable object).
1518 1535
1519 1536 Also big cleanup of this code, which had horrendous runtime
1520 1537 lookups of zillions of attributes for colorization. Moved all
1521 1538 this code into a few templates, which make it cleaner and quicker.
1522 1539
1523 1540 Printout quality was also improved for Verbose exceptions: one
1524 1541 variable per line, and memory addresses are printed (this can be
1525 1542 quite handy in nasty debugging situations, which is what Verbose
1526 1543 is for).
1527 1544
1528 1545 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
1529 1546 the command line as scripts to be loaded by embedded instances.
1530 1547 Doing so has the potential for an infinite recursion if there are
1531 1548 exceptions thrown in the process. This fixes a strange crash
1532 1549 reported by Philippe MULLER <muller-AT-irit.fr>.
1533 1550
1534 1551 2004-12-09 Fernando Perez <fperez@colorado.edu>
1535 1552
1536 1553 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
1537 1554 to reflect new names in matplotlib, which now expose the
1538 1555 matlab-compatible interface via a pylab module instead of the
1539 1556 'matlab' name. The new code is backwards compatible, so users of
1540 1557 all matplotlib versions are OK. Patch by J. Hunter.
1541 1558
1542 1559 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
1543 1560 of __init__ docstrings for instances (class docstrings are already
1544 1561 automatically printed). Instances with customized docstrings
1545 1562 (indep. of the class) are also recognized and all 3 separate
1546 1563 docstrings are printed (instance, class, constructor). After some
1547 1564 comments/suggestions by J. Hunter.
1548 1565
1549 1566 2004-12-05 Fernando Perez <fperez@colorado.edu>
1550 1567
1551 1568 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
1552 1569 warnings when tab-completion fails and triggers an exception.
1553 1570
1554 1571 2004-12-03 Fernando Perez <fperez@colorado.edu>
1555 1572
1556 1573 * IPython/Magic.py (magic_prun): Fix bug where an exception would
1557 1574 be triggered when using 'run -p'. An incorrect option flag was
1558 1575 being set ('d' instead of 'D').
1559 1576 (manpage): fix missing escaped \- sign.
1560 1577
1561 1578 2004-11-30 *** Released version 0.6.5
1562 1579
1563 1580 2004-11-30 Fernando Perez <fperez@colorado.edu>
1564 1581
1565 1582 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
1566 1583 setting with -d option.
1567 1584
1568 1585 * setup.py (docfiles): Fix problem where the doc glob I was using
1569 1586 was COMPLETELY BROKEN. It was giving the right files by pure
1570 1587 accident, but failed once I tried to include ipython.el. Note:
1571 1588 glob() does NOT allow you to do exclusion on multiple endings!
1572 1589
1573 1590 2004-11-29 Fernando Perez <fperez@colorado.edu>
1574 1591
1575 1592 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
1576 1593 the manpage as the source. Better formatting & consistency.
1577 1594
1578 1595 * IPython/Magic.py (magic_run): Added new -d option, to run
1579 1596 scripts under the control of the python pdb debugger. Note that
1580 1597 this required changing the %prun option -d to -D, to avoid a clash
1581 1598 (since %run must pass options to %prun, and getopt is too dumb to
1582 1599 handle options with string values with embedded spaces). Thanks
1583 1600 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
1584 1601 (magic_who_ls): added type matching to %who and %whos, so that one
1585 1602 can filter their output to only include variables of certain
1586 1603 types. Another suggestion by Matthew.
1587 1604 (magic_whos): Added memory summaries in kb and Mb for arrays.
1588 1605 (magic_who): Improve formatting (break lines every 9 vars).
1589 1606
1590 1607 2004-11-28 Fernando Perez <fperez@colorado.edu>
1591 1608
1592 1609 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
1593 1610 cache when empty lines were present.
1594 1611
1595 1612 2004-11-24 Fernando Perez <fperez@colorado.edu>
1596 1613
1597 1614 * IPython/usage.py (__doc__): document the re-activated threading
1598 1615 options for WX and GTK.
1599 1616
1600 1617 2004-11-23 Fernando Perez <fperez@colorado.edu>
1601 1618
1602 1619 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
1603 1620 the -wthread and -gthread options, along with a new -tk one to try
1604 1621 and coordinate Tk threading with wx/gtk. The tk support is very
1605 1622 platform dependent, since it seems to require Tcl and Tk to be
1606 1623 built with threads (Fedora1/2 appears NOT to have it, but in
1607 1624 Prabhu's Debian boxes it works OK). But even with some Tk
1608 1625 limitations, this is a great improvement.
1609 1626
1610 1627 * IPython/Prompts.py (prompt_specials_color): Added \t for time
1611 1628 info in user prompts. Patch by Prabhu.
1612 1629
1613 1630 2004-11-18 Fernando Perez <fperez@colorado.edu>
1614 1631
1615 1632 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
1616 1633 EOFErrors and bail, to avoid infinite loops if a non-terminating
1617 1634 file is fed into ipython. Patch submitted in issue 19 by user,
1618 1635 many thanks.
1619 1636
1620 1637 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
1621 1638 autoquote/parens in continuation prompts, which can cause lots of
1622 1639 problems. Closes roundup issue 20.
1623 1640
1624 1641 2004-11-17 Fernando Perez <fperez@colorado.edu>
1625 1642
1626 1643 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
1627 1644 reported as debian bug #280505. I'm not sure my local changelog
1628 1645 entry has the proper debian format (Jack?).
1629 1646
1630 1647 2004-11-08 *** Released version 0.6.4
1631 1648
1632 1649 2004-11-08 Fernando Perez <fperez@colorado.edu>
1633 1650
1634 1651 * IPython/iplib.py (init_readline): Fix exit message for Windows
1635 1652 when readline is active. Thanks to a report by Eric Jones
1636 1653 <eric-AT-enthought.com>.
1637 1654
1638 1655 2004-11-07 Fernando Perez <fperez@colorado.edu>
1639 1656
1640 1657 * IPython/genutils.py (page): Add a trap for OSError exceptions,
1641 1658 sometimes seen by win2k/cygwin users.
1642 1659
1643 1660 2004-11-06 Fernando Perez <fperez@colorado.edu>
1644 1661
1645 1662 * IPython/iplib.py (interact): Change the handling of %Exit from
1646 1663 trying to propagate a SystemExit to an internal ipython flag.
1647 1664 This is less elegant than using Python's exception mechanism, but
1648 1665 I can't get that to work reliably with threads, so under -pylab
1649 1666 %Exit was hanging IPython. Cross-thread exception handling is
1650 1667 really a bitch. Thaks to a bug report by Stephen Walton
1651 1668 <stephen.walton-AT-csun.edu>.
1652 1669
1653 1670 2004-11-04 Fernando Perez <fperez@colorado.edu>
1654 1671
1655 1672 * IPython/iplib.py (raw_input_original): store a pointer to the
1656 1673 true raw_input to harden against code which can modify it
1657 1674 (wx.py.PyShell does this and would otherwise crash ipython).
1658 1675 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
1659 1676
1660 1677 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
1661 1678 Ctrl-C problem, which does not mess up the input line.
1662 1679
1663 1680 2004-11-03 Fernando Perez <fperez@colorado.edu>
1664 1681
1665 1682 * IPython/Release.py: Changed licensing to BSD, in all files.
1666 1683 (name): lowercase name for tarball/RPM release.
1667 1684
1668 1685 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
1669 1686 use throughout ipython.
1670 1687
1671 1688 * IPython/Magic.py (Magic._ofind): Switch to using the new
1672 1689 OInspect.getdoc() function.
1673 1690
1674 1691 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
1675 1692 of the line currently being canceled via Ctrl-C. It's extremely
1676 1693 ugly, but I don't know how to do it better (the problem is one of
1677 1694 handling cross-thread exceptions).
1678 1695
1679 1696 2004-10-28 Fernando Perez <fperez@colorado.edu>
1680 1697
1681 1698 * IPython/Shell.py (signal_handler): add signal handlers to trap
1682 1699 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
1683 1700 report by Francesc Alted.
1684 1701
1685 1702 2004-10-21 Fernando Perez <fperez@colorado.edu>
1686 1703
1687 1704 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
1688 1705 to % for pysh syntax extensions.
1689 1706
1690 1707 2004-10-09 Fernando Perez <fperez@colorado.edu>
1691 1708
1692 1709 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
1693 1710 arrays to print a more useful summary, without calling str(arr).
1694 1711 This avoids the problem of extremely lengthy computations which
1695 1712 occur if arr is large, and appear to the user as a system lockup
1696 1713 with 100% cpu activity. After a suggestion by Kristian Sandberg
1697 1714 <Kristian.Sandberg@colorado.edu>.
1698 1715 (Magic.__init__): fix bug in global magic escapes not being
1699 1716 correctly set.
1700 1717
1701 1718 2004-10-08 Fernando Perez <fperez@colorado.edu>
1702 1719
1703 1720 * IPython/Magic.py (__license__): change to absolute imports of
1704 1721 ipython's own internal packages, to start adapting to the absolute
1705 1722 import requirement of PEP-328.
1706 1723
1707 1724 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
1708 1725 files, and standardize author/license marks through the Release
1709 1726 module instead of having per/file stuff (except for files with
1710 1727 particular licenses, like the MIT/PSF-licensed codes).
1711 1728
1712 1729 * IPython/Debugger.py: remove dead code for python 2.1
1713 1730
1714 1731 2004-10-04 Fernando Perez <fperez@colorado.edu>
1715 1732
1716 1733 * IPython/iplib.py (ipmagic): New function for accessing magics
1717 1734 via a normal python function call.
1718 1735
1719 1736 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
1720 1737 from '@' to '%', to accomodate the new @decorator syntax of python
1721 1738 2.4.
1722 1739
1723 1740 2004-09-29 Fernando Perez <fperez@colorado.edu>
1724 1741
1725 1742 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
1726 1743 matplotlib.use to prevent running scripts which try to switch
1727 1744 interactive backends from within ipython. This will just crash
1728 1745 the python interpreter, so we can't allow it (but a detailed error
1729 1746 is given to the user).
1730 1747
1731 1748 2004-09-28 Fernando Perez <fperez@colorado.edu>
1732 1749
1733 1750 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
1734 1751 matplotlib-related fixes so that using @run with non-matplotlib
1735 1752 scripts doesn't pop up spurious plot windows. This requires
1736 1753 matplotlib >= 0.63, where I had to make some changes as well.
1737 1754
1738 1755 * IPython/ipmaker.py (make_IPython): update version requirement to
1739 1756 python 2.2.
1740 1757
1741 1758 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
1742 1759 banner arg for embedded customization.
1743 1760
1744 1761 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
1745 1762 explicit uses of __IP as the IPython's instance name. Now things
1746 1763 are properly handled via the shell.name value. The actual code
1747 1764 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
1748 1765 is much better than before. I'll clean things completely when the
1749 1766 magic stuff gets a real overhaul.
1750 1767
1751 1768 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
1752 1769 minor changes to debian dir.
1753 1770
1754 1771 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
1755 1772 pointer to the shell itself in the interactive namespace even when
1756 1773 a user-supplied dict is provided. This is needed for embedding
1757 1774 purposes (found by tests with Michel Sanner).
1758 1775
1759 1776 2004-09-27 Fernando Perez <fperez@colorado.edu>
1760 1777
1761 1778 * IPython/UserConfig/ipythonrc: remove []{} from
1762 1779 readline_remove_delims, so that things like [modname.<TAB> do
1763 1780 proper completion. This disables [].TAB, but that's a less common
1764 1781 case than module names in list comprehensions, for example.
1765 1782 Thanks to a report by Andrea Riciputi.
1766 1783
1767 1784 2004-09-09 Fernando Perez <fperez@colorado.edu>
1768 1785
1769 1786 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1770 1787 blocking problems in win32 and osx. Fix by John.
1771 1788
1772 1789 2004-09-08 Fernando Perez <fperez@colorado.edu>
1773 1790
1774 1791 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1775 1792 for Win32 and OSX. Fix by John Hunter.
1776 1793
1777 1794 2004-08-30 *** Released version 0.6.3
1778 1795
1779 1796 2004-08-30 Fernando Perez <fperez@colorado.edu>
1780 1797
1781 1798 * setup.py (isfile): Add manpages to list of dependent files to be
1782 1799 updated.
1783 1800
1784 1801 2004-08-27 Fernando Perez <fperez@colorado.edu>
1785 1802
1786 1803 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1787 1804 for now. They don't really work with standalone WX/GTK code
1788 1805 (though matplotlib IS working fine with both of those backends).
1789 1806 This will neeed much more testing. I disabled most things with
1790 1807 comments, so turning it back on later should be pretty easy.
1791 1808
1792 1809 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1793 1810 autocalling of expressions like r'foo', by modifying the line
1794 1811 split regexp. Closes
1795 1812 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1796 1813 Riley <ipythonbugs-AT-sabi.net>.
1797 1814 (InteractiveShell.mainloop): honor --nobanner with banner
1798 1815 extensions.
1799 1816
1800 1817 * IPython/Shell.py: Significant refactoring of all classes, so
1801 1818 that we can really support ALL matplotlib backends and threading
1802 1819 models (John spotted a bug with Tk which required this). Now we
1803 1820 should support single-threaded, WX-threads and GTK-threads, both
1804 1821 for generic code and for matplotlib.
1805 1822
1806 1823 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1807 1824 -pylab, to simplify things for users. Will also remove the pylab
1808 1825 profile, since now all of matplotlib configuration is directly
1809 1826 handled here. This also reduces startup time.
1810 1827
1811 1828 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1812 1829 shell wasn't being correctly called. Also in IPShellWX.
1813 1830
1814 1831 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1815 1832 fine-tune banner.
1816 1833
1817 1834 * IPython/numutils.py (spike): Deprecate these spike functions,
1818 1835 delete (long deprecated) gnuplot_exec handler.
1819 1836
1820 1837 2004-08-26 Fernando Perez <fperez@colorado.edu>
1821 1838
1822 1839 * ipython.1: Update for threading options, plus some others which
1823 1840 were missing.
1824 1841
1825 1842 * IPython/ipmaker.py (__call__): Added -wthread option for
1826 1843 wxpython thread handling. Make sure threading options are only
1827 1844 valid at the command line.
1828 1845
1829 1846 * scripts/ipython: moved shell selection into a factory function
1830 1847 in Shell.py, to keep the starter script to a minimum.
1831 1848
1832 1849 2004-08-25 Fernando Perez <fperez@colorado.edu>
1833 1850
1834 1851 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1835 1852 John. Along with some recent changes he made to matplotlib, the
1836 1853 next versions of both systems should work very well together.
1837 1854
1838 1855 2004-08-24 Fernando Perez <fperez@colorado.edu>
1839 1856
1840 1857 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1841 1858 tried to switch the profiling to using hotshot, but I'm getting
1842 1859 strange errors from prof.runctx() there. I may be misreading the
1843 1860 docs, but it looks weird. For now the profiling code will
1844 1861 continue to use the standard profiler.
1845 1862
1846 1863 2004-08-23 Fernando Perez <fperez@colorado.edu>
1847 1864
1848 1865 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1849 1866 threaded shell, by John Hunter. It's not quite ready yet, but
1850 1867 close.
1851 1868
1852 1869 2004-08-22 Fernando Perez <fperez@colorado.edu>
1853 1870
1854 1871 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1855 1872 in Magic and ultraTB.
1856 1873
1857 1874 * ipython.1: document threading options in manpage.
1858 1875
1859 1876 * scripts/ipython: Changed name of -thread option to -gthread,
1860 1877 since this is GTK specific. I want to leave the door open for a
1861 1878 -wthread option for WX, which will most likely be necessary. This
1862 1879 change affects usage and ipmaker as well.
1863 1880
1864 1881 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1865 1882 handle the matplotlib shell issues. Code by John Hunter
1866 1883 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1867 1884 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1868 1885 broken (and disabled for end users) for now, but it puts the
1869 1886 infrastructure in place.
1870 1887
1871 1888 2004-08-21 Fernando Perez <fperez@colorado.edu>
1872 1889
1873 1890 * ipythonrc-pylab: Add matplotlib support.
1874 1891
1875 1892 * matplotlib_config.py: new files for matplotlib support, part of
1876 1893 the pylab profile.
1877 1894
1878 1895 * IPython/usage.py (__doc__): documented the threading options.
1879 1896
1880 1897 2004-08-20 Fernando Perez <fperez@colorado.edu>
1881 1898
1882 1899 * ipython: Modified the main calling routine to handle the -thread
1883 1900 and -mpthread options. This needs to be done as a top-level hack,
1884 1901 because it determines which class to instantiate for IPython
1885 1902 itself.
1886 1903
1887 1904 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1888 1905 classes to support multithreaded GTK operation without blocking,
1889 1906 and matplotlib with all backends. This is a lot of still very
1890 1907 experimental code, and threads are tricky. So it may still have a
1891 1908 few rough edges... This code owes a lot to
1892 1909 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1893 1910 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1894 1911 to John Hunter for all the matplotlib work.
1895 1912
1896 1913 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1897 1914 options for gtk thread and matplotlib support.
1898 1915
1899 1916 2004-08-16 Fernando Perez <fperez@colorado.edu>
1900 1917
1901 1918 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1902 1919 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1903 1920 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1904 1921
1905 1922 2004-08-11 Fernando Perez <fperez@colorado.edu>
1906 1923
1907 1924 * setup.py (isfile): Fix build so documentation gets updated for
1908 1925 rpms (it was only done for .tgz builds).
1909 1926
1910 1927 2004-08-10 Fernando Perez <fperez@colorado.edu>
1911 1928
1912 1929 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1913 1930
1914 1931 * iplib.py : Silence syntax error exceptions in tab-completion.
1915 1932
1916 1933 2004-08-05 Fernando Perez <fperez@colorado.edu>
1917 1934
1918 1935 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1919 1936 'color off' mark for continuation prompts. This was causing long
1920 1937 continuation lines to mis-wrap.
1921 1938
1922 1939 2004-08-01 Fernando Perez <fperez@colorado.edu>
1923 1940
1924 1941 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1925 1942 for building ipython to be a parameter. All this is necessary
1926 1943 right now to have a multithreaded version, but this insane
1927 1944 non-design will be cleaned up soon. For now, it's a hack that
1928 1945 works.
1929 1946
1930 1947 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1931 1948 args in various places. No bugs so far, but it's a dangerous
1932 1949 practice.
1933 1950
1934 1951 2004-07-31 Fernando Perez <fperez@colorado.edu>
1935 1952
1936 1953 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1937 1954 fix completion of files with dots in their names under most
1938 1955 profiles (pysh was OK because the completion order is different).
1939 1956
1940 1957 2004-07-27 Fernando Perez <fperez@colorado.edu>
1941 1958
1942 1959 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1943 1960 keywords manually, b/c the one in keyword.py was removed in python
1944 1961 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1945 1962 This is NOT a bug under python 2.3 and earlier.
1946 1963
1947 1964 2004-07-26 Fernando Perez <fperez@colorado.edu>
1948 1965
1949 1966 * IPython/ultraTB.py (VerboseTB.text): Add another
1950 1967 linecache.checkcache() call to try to prevent inspect.py from
1951 1968 crashing under python 2.3. I think this fixes
1952 1969 http://www.scipy.net/roundup/ipython/issue17.
1953 1970
1954 1971 2004-07-26 *** Released version 0.6.2
1955 1972
1956 1973 2004-07-26 Fernando Perez <fperez@colorado.edu>
1957 1974
1958 1975 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1959 1976 fail for any number.
1960 1977 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1961 1978 empty bookmarks.
1962 1979
1963 1980 2004-07-26 *** Released version 0.6.1
1964 1981
1965 1982 2004-07-26 Fernando Perez <fperez@colorado.edu>
1966 1983
1967 1984 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1968 1985
1969 1986 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1970 1987 escaping '()[]{}' in filenames.
1971 1988
1972 1989 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1973 1990 Python 2.2 users who lack a proper shlex.split.
1974 1991
1975 1992 2004-07-19 Fernando Perez <fperez@colorado.edu>
1976 1993
1977 1994 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1978 1995 for reading readline's init file. I follow the normal chain:
1979 1996 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1980 1997 report by Mike Heeter. This closes
1981 1998 http://www.scipy.net/roundup/ipython/issue16.
1982 1999
1983 2000 2004-07-18 Fernando Perez <fperez@colorado.edu>
1984 2001
1985 2002 * IPython/iplib.py (__init__): Add better handling of '\' under
1986 2003 Win32 for filenames. After a patch by Ville.
1987 2004
1988 2005 2004-07-17 Fernando Perez <fperez@colorado.edu>
1989 2006
1990 2007 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1991 2008 autocalling would be triggered for 'foo is bar' if foo is
1992 2009 callable. I also cleaned up the autocall detection code to use a
1993 2010 regexp, which is faster. Bug reported by Alexander Schmolck.
1994 2011
1995 2012 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1996 2013 '?' in them would confuse the help system. Reported by Alex
1997 2014 Schmolck.
1998 2015
1999 2016 2004-07-16 Fernando Perez <fperez@colorado.edu>
2000 2017
2001 2018 * IPython/GnuplotInteractive.py (__all__): added plot2.
2002 2019
2003 2020 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
2004 2021 plotting dictionaries, lists or tuples of 1d arrays.
2005 2022
2006 2023 * IPython/Magic.py (Magic.magic_hist): small clenaups and
2007 2024 optimizations.
2008 2025
2009 2026 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
2010 2027 the information which was there from Janko's original IPP code:
2011 2028
2012 2029 03.05.99 20:53 porto.ifm.uni-kiel.de
2013 2030 --Started changelog.
2014 2031 --make clear do what it say it does
2015 2032 --added pretty output of lines from inputcache
2016 2033 --Made Logger a mixin class, simplifies handling of switches
2017 2034 --Added own completer class. .string<TAB> expands to last history
2018 2035 line which starts with string. The new expansion is also present
2019 2036 with Ctrl-r from the readline library. But this shows, who this
2020 2037 can be done for other cases.
2021 2038 --Added convention that all shell functions should accept a
2022 2039 parameter_string This opens the door for different behaviour for
2023 2040 each function. @cd is a good example of this.
2024 2041
2025 2042 04.05.99 12:12 porto.ifm.uni-kiel.de
2026 2043 --added logfile rotation
2027 2044 --added new mainloop method which freezes first the namespace
2028 2045
2029 2046 07.05.99 21:24 porto.ifm.uni-kiel.de
2030 2047 --added the docreader classes. Now there is a help system.
2031 2048 -This is only a first try. Currently it's not easy to put new
2032 2049 stuff in the indices. But this is the way to go. Info would be
2033 2050 better, but HTML is every where and not everybody has an info
2034 2051 system installed and it's not so easy to change html-docs to info.
2035 2052 --added global logfile option
2036 2053 --there is now a hook for object inspection method pinfo needs to
2037 2054 be provided for this. Can be reached by two '??'.
2038 2055
2039 2056 08.05.99 20:51 porto.ifm.uni-kiel.de
2040 2057 --added a README
2041 2058 --bug in rc file. Something has changed so functions in the rc
2042 2059 file need to reference the shell and not self. Not clear if it's a
2043 2060 bug or feature.
2044 2061 --changed rc file for new behavior
2045 2062
2046 2063 2004-07-15 Fernando Perez <fperez@colorado.edu>
2047 2064
2048 2065 * IPython/Logger.py (Logger.log): fixed recent bug where the input
2049 2066 cache was falling out of sync in bizarre manners when multi-line
2050 2067 input was present. Minor optimizations and cleanup.
2051 2068
2052 2069 (Logger): Remove old Changelog info for cleanup. This is the
2053 2070 information which was there from Janko's original code:
2054 2071
2055 2072 Changes to Logger: - made the default log filename a parameter
2056 2073
2057 2074 - put a check for lines beginning with !@? in log(). Needed
2058 2075 (even if the handlers properly log their lines) for mid-session
2059 2076 logging activation to work properly. Without this, lines logged
2060 2077 in mid session, which get read from the cache, would end up
2061 2078 'bare' (with !@? in the open) in the log. Now they are caught
2062 2079 and prepended with a #.
2063 2080
2064 2081 * IPython/iplib.py (InteractiveShell.init_readline): added check
2065 2082 in case MagicCompleter fails to be defined, so we don't crash.
2066 2083
2067 2084 2004-07-13 Fernando Perez <fperez@colorado.edu>
2068 2085
2069 2086 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
2070 2087 of EPS if the requested filename ends in '.eps'.
2071 2088
2072 2089 2004-07-04 Fernando Perez <fperez@colorado.edu>
2073 2090
2074 2091 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
2075 2092 escaping of quotes when calling the shell.
2076 2093
2077 2094 2004-07-02 Fernando Perez <fperez@colorado.edu>
2078 2095
2079 2096 * IPython/Prompts.py (CachedOutput.update): Fix problem with
2080 2097 gettext not working because we were clobbering '_'. Fixes
2081 2098 http://www.scipy.net/roundup/ipython/issue6.
2082 2099
2083 2100 2004-07-01 Fernando Perez <fperez@colorado.edu>
2084 2101
2085 2102 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
2086 2103 into @cd. Patch by Ville.
2087 2104
2088 2105 * IPython/iplib.py (InteractiveShell.post_config_initialization):
2089 2106 new function to store things after ipmaker runs. Patch by Ville.
2090 2107 Eventually this will go away once ipmaker is removed and the class
2091 2108 gets cleaned up, but for now it's ok. Key functionality here is
2092 2109 the addition of the persistent storage mechanism, a dict for
2093 2110 keeping data across sessions (for now just bookmarks, but more can
2094 2111 be implemented later).
2095 2112
2096 2113 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
2097 2114 persistent across sections. Patch by Ville, I modified it
2098 2115 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
2099 2116 added a '-l' option to list all bookmarks.
2100 2117
2101 2118 * IPython/iplib.py (InteractiveShell.atexit_operations): new
2102 2119 center for cleanup. Registered with atexit.register(). I moved
2103 2120 here the old exit_cleanup(). After a patch by Ville.
2104 2121
2105 2122 * IPython/Magic.py (get_py_filename): added '~' to the accepted
2106 2123 characters in the hacked shlex_split for python 2.2.
2107 2124
2108 2125 * IPython/iplib.py (file_matches): more fixes to filenames with
2109 2126 whitespace in them. It's not perfect, but limitations in python's
2110 2127 readline make it impossible to go further.
2111 2128
2112 2129 2004-06-29 Fernando Perez <fperez@colorado.edu>
2113 2130
2114 2131 * IPython/iplib.py (file_matches): escape whitespace correctly in
2115 2132 filename completions. Bug reported by Ville.
2116 2133
2117 2134 2004-06-28 Fernando Perez <fperez@colorado.edu>
2118 2135
2119 2136 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
2120 2137 the history file will be called 'history-PROFNAME' (or just
2121 2138 'history' if no profile is loaded). I was getting annoyed at
2122 2139 getting my Numerical work history clobbered by pysh sessions.
2123 2140
2124 2141 * IPython/iplib.py (InteractiveShell.__init__): Internal
2125 2142 getoutputerror() function so that we can honor the system_verbose
2126 2143 flag for _all_ system calls. I also added escaping of #
2127 2144 characters here to avoid confusing Itpl.
2128 2145
2129 2146 * IPython/Magic.py (shlex_split): removed call to shell in
2130 2147 parse_options and replaced it with shlex.split(). The annoying
2131 2148 part was that in Python 2.2, shlex.split() doesn't exist, so I had
2132 2149 to backport it from 2.3, with several frail hacks (the shlex
2133 2150 module is rather limited in 2.2). Thanks to a suggestion by Ville
2134 2151 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
2135 2152 problem.
2136 2153
2137 2154 (Magic.magic_system_verbose): new toggle to print the actual
2138 2155 system calls made by ipython. Mainly for debugging purposes.
2139 2156
2140 2157 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
2141 2158 doesn't support persistence. Reported (and fix suggested) by
2142 2159 Travis Caldwell <travis_caldwell2000@yahoo.com>.
2143 2160
2144 2161 2004-06-26 Fernando Perez <fperez@colorado.edu>
2145 2162
2146 2163 * IPython/Logger.py (Logger.log): fix to handle correctly empty
2147 2164 continue prompts.
2148 2165
2149 2166 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
2150 2167 function (basically a big docstring) and a few more things here to
2151 2168 speedup startup. pysh.py is now very lightweight. We want because
2152 2169 it gets execfile'd, while InterpreterExec gets imported, so
2153 2170 byte-compilation saves time.
2154 2171
2155 2172 2004-06-25 Fernando Perez <fperez@colorado.edu>
2156 2173
2157 2174 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
2158 2175 -NUM', which was recently broken.
2159 2176
2160 2177 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
2161 2178 in multi-line input (but not !!, which doesn't make sense there).
2162 2179
2163 2180 * IPython/UserConfig/ipythonrc: made autoindent on by default.
2164 2181 It's just too useful, and people can turn it off in the less
2165 2182 common cases where it's a problem.
2166 2183
2167 2184 2004-06-24 Fernando Perez <fperez@colorado.edu>
2168 2185
2169 2186 * IPython/iplib.py (InteractiveShell._prefilter): big change -
2170 2187 special syntaxes (like alias calling) is now allied in multi-line
2171 2188 input. This is still _very_ experimental, but it's necessary for
2172 2189 efficient shell usage combining python looping syntax with system
2173 2190 calls. For now it's restricted to aliases, I don't think it
2174 2191 really even makes sense to have this for magics.
2175 2192
2176 2193 2004-06-23 Fernando Perez <fperez@colorado.edu>
2177 2194
2178 2195 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
2179 2196 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
2180 2197
2181 2198 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
2182 2199 extensions under Windows (after code sent by Gary Bishop). The
2183 2200 extensions considered 'executable' are stored in IPython's rc
2184 2201 structure as win_exec_ext.
2185 2202
2186 2203 * IPython/genutils.py (shell): new function, like system() but
2187 2204 without return value. Very useful for interactive shell work.
2188 2205
2189 2206 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
2190 2207 delete aliases.
2191 2208
2192 2209 * IPython/iplib.py (InteractiveShell.alias_table_update): make
2193 2210 sure that the alias table doesn't contain python keywords.
2194 2211
2195 2212 2004-06-21 Fernando Perez <fperez@colorado.edu>
2196 2213
2197 2214 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
2198 2215 non-existent items are found in $PATH. Reported by Thorsten.
2199 2216
2200 2217 2004-06-20 Fernando Perez <fperez@colorado.edu>
2201 2218
2202 2219 * IPython/iplib.py (complete): modified the completer so that the
2203 2220 order of priorities can be easily changed at runtime.
2204 2221
2205 2222 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
2206 2223 Modified to auto-execute all lines beginning with '~', '/' or '.'.
2207 2224
2208 2225 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
2209 2226 expand Python variables prepended with $ in all system calls. The
2210 2227 same was done to InteractiveShell.handle_shell_escape. Now all
2211 2228 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
2212 2229 expansion of python variables and expressions according to the
2213 2230 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
2214 2231
2215 2232 Though PEP-215 has been rejected, a similar (but simpler) one
2216 2233 seems like it will go into Python 2.4, PEP-292 -
2217 2234 http://www.python.org/peps/pep-0292.html.
2218 2235
2219 2236 I'll keep the full syntax of PEP-215, since IPython has since the
2220 2237 start used Ka-Ping Yee's reference implementation discussed there
2221 2238 (Itpl), and I actually like the powerful semantics it offers.
2222 2239
2223 2240 In order to access normal shell variables, the $ has to be escaped
2224 2241 via an extra $. For example:
2225 2242
2226 2243 In [7]: PATH='a python variable'
2227 2244
2228 2245 In [8]: !echo $PATH
2229 2246 a python variable
2230 2247
2231 2248 In [9]: !echo $$PATH
2232 2249 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2233 2250
2234 2251 (Magic.parse_options): escape $ so the shell doesn't evaluate
2235 2252 things prematurely.
2236 2253
2237 2254 * IPython/iplib.py (InteractiveShell.call_alias): added the
2238 2255 ability for aliases to expand python variables via $.
2239 2256
2240 2257 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
2241 2258 system, now there's a @rehash/@rehashx pair of magics. These work
2242 2259 like the csh rehash command, and can be invoked at any time. They
2243 2260 build a table of aliases to everything in the user's $PATH
2244 2261 (@rehash uses everything, @rehashx is slower but only adds
2245 2262 executable files). With this, the pysh.py-based shell profile can
2246 2263 now simply call rehash upon startup, and full access to all
2247 2264 programs in the user's path is obtained.
2248 2265
2249 2266 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
2250 2267 functionality is now fully in place. I removed the old dynamic
2251 2268 code generation based approach, in favor of a much lighter one
2252 2269 based on a simple dict. The advantage is that this allows me to
2253 2270 now have thousands of aliases with negligible cost (unthinkable
2254 2271 with the old system).
2255 2272
2256 2273 2004-06-19 Fernando Perez <fperez@colorado.edu>
2257 2274
2258 2275 * IPython/iplib.py (__init__): extended MagicCompleter class to
2259 2276 also complete (last in priority) on user aliases.
2260 2277
2261 2278 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
2262 2279 call to eval.
2263 2280 (ItplNS.__init__): Added a new class which functions like Itpl,
2264 2281 but allows configuring the namespace for the evaluation to occur
2265 2282 in.
2266 2283
2267 2284 2004-06-18 Fernando Perez <fperez@colorado.edu>
2268 2285
2269 2286 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
2270 2287 better message when 'exit' or 'quit' are typed (a common newbie
2271 2288 confusion).
2272 2289
2273 2290 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
2274 2291 check for Windows users.
2275 2292
2276 2293 * IPython/iplib.py (InteractiveShell.user_setup): removed
2277 2294 disabling of colors for Windows. I'll test at runtime and issue a
2278 2295 warning if Gary's readline isn't found, as to nudge users to
2279 2296 download it.
2280 2297
2281 2298 2004-06-16 Fernando Perez <fperez@colorado.edu>
2282 2299
2283 2300 * IPython/genutils.py (Stream.__init__): changed to print errors
2284 2301 to sys.stderr. I had a circular dependency here. Now it's
2285 2302 possible to run ipython as IDLE's shell (consider this pre-alpha,
2286 2303 since true stdout things end up in the starting terminal instead
2287 2304 of IDLE's out).
2288 2305
2289 2306 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
2290 2307 users who haven't # updated their prompt_in2 definitions. Remove
2291 2308 eventually.
2292 2309 (multiple_replace): added credit to original ASPN recipe.
2293 2310
2294 2311 2004-06-15 Fernando Perez <fperez@colorado.edu>
2295 2312
2296 2313 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
2297 2314 list of auto-defined aliases.
2298 2315
2299 2316 2004-06-13 Fernando Perez <fperez@colorado.edu>
2300 2317
2301 2318 * setup.py (scriptfiles): Don't trigger win_post_install unless an
2302 2319 install was really requested (so setup.py can be used for other
2303 2320 things under Windows).
2304 2321
2305 2322 2004-06-10 Fernando Perez <fperez@colorado.edu>
2306 2323
2307 2324 * IPython/Logger.py (Logger.create_log): Manually remove any old
2308 2325 backup, since os.remove may fail under Windows. Fixes bug
2309 2326 reported by Thorsten.
2310 2327
2311 2328 2004-06-09 Fernando Perez <fperez@colorado.edu>
2312 2329
2313 2330 * examples/example-embed.py: fixed all references to %n (replaced
2314 2331 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
2315 2332 for all examples and the manual as well.
2316 2333
2317 2334 2004-06-08 Fernando Perez <fperez@colorado.edu>
2318 2335
2319 2336 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
2320 2337 alignment and color management. All 3 prompt subsystems now
2321 2338 inherit from BasePrompt.
2322 2339
2323 2340 * tools/release: updates for windows installer build and tag rpms
2324 2341 with python version (since paths are fixed).
2325 2342
2326 2343 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
2327 2344 which will become eventually obsolete. Also fixed the default
2328 2345 prompt_in2 to use \D, so at least new users start with the correct
2329 2346 defaults.
2330 2347 WARNING: Users with existing ipythonrc files will need to apply
2331 2348 this fix manually!
2332 2349
2333 2350 * setup.py: make windows installer (.exe). This is finally the
2334 2351 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
2335 2352 which I hadn't included because it required Python 2.3 (or recent
2336 2353 distutils).
2337 2354
2338 2355 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
2339 2356 usage of new '\D' escape.
2340 2357
2341 2358 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
2342 2359 lacks os.getuid())
2343 2360 (CachedOutput.set_colors): Added the ability to turn coloring
2344 2361 on/off with @colors even for manually defined prompt colors. It
2345 2362 uses a nasty global, but it works safely and via the generic color
2346 2363 handling mechanism.
2347 2364 (Prompt2.__init__): Introduced new escape '\D' for continuation
2348 2365 prompts. It represents the counter ('\#') as dots.
2349 2366 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
2350 2367 need to update their ipythonrc files and replace '%n' with '\D' in
2351 2368 their prompt_in2 settings everywhere. Sorry, but there's
2352 2369 otherwise no clean way to get all prompts to properly align. The
2353 2370 ipythonrc shipped with IPython has been updated.
2354 2371
2355 2372 2004-06-07 Fernando Perez <fperez@colorado.edu>
2356 2373
2357 2374 * setup.py (isfile): Pass local_icons option to latex2html, so the
2358 2375 resulting HTML file is self-contained. Thanks to
2359 2376 dryice-AT-liu.com.cn for the tip.
2360 2377
2361 2378 * pysh.py: I created a new profile 'shell', which implements a
2362 2379 _rudimentary_ IPython-based shell. This is in NO WAY a realy
2363 2380 system shell, nor will it become one anytime soon. It's mainly
2364 2381 meant to illustrate the use of the new flexible bash-like prompts.
2365 2382 I guess it could be used by hardy souls for true shell management,
2366 2383 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
2367 2384 profile. This uses the InterpreterExec extension provided by
2368 2385 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
2369 2386
2370 2387 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
2371 2388 auto-align itself with the length of the previous input prompt
2372 2389 (taking into account the invisible color escapes).
2373 2390 (CachedOutput.__init__): Large restructuring of this class. Now
2374 2391 all three prompts (primary1, primary2, output) are proper objects,
2375 2392 managed by the 'parent' CachedOutput class. The code is still a
2376 2393 bit hackish (all prompts share state via a pointer to the cache),
2377 2394 but it's overall far cleaner than before.
2378 2395
2379 2396 * IPython/genutils.py (getoutputerror): modified to add verbose,
2380 2397 debug and header options. This makes the interface of all getout*
2381 2398 functions uniform.
2382 2399 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
2383 2400
2384 2401 * IPython/Magic.py (Magic.default_option): added a function to
2385 2402 allow registering default options for any magic command. This
2386 2403 makes it easy to have profiles which customize the magics globally
2387 2404 for a certain use. The values set through this function are
2388 2405 picked up by the parse_options() method, which all magics should
2389 2406 use to parse their options.
2390 2407
2391 2408 * IPython/genutils.py (warn): modified the warnings framework to
2392 2409 use the Term I/O class. I'm trying to slowly unify all of
2393 2410 IPython's I/O operations to pass through Term.
2394 2411
2395 2412 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
2396 2413 the secondary prompt to correctly match the length of the primary
2397 2414 one for any prompt. Now multi-line code will properly line up
2398 2415 even for path dependent prompts, such as the new ones available
2399 2416 via the prompt_specials.
2400 2417
2401 2418 2004-06-06 Fernando Perez <fperez@colorado.edu>
2402 2419
2403 2420 * IPython/Prompts.py (prompt_specials): Added the ability to have
2404 2421 bash-like special sequences in the prompts, which get
2405 2422 automatically expanded. Things like hostname, current working
2406 2423 directory and username are implemented already, but it's easy to
2407 2424 add more in the future. Thanks to a patch by W.J. van der Laan
2408 2425 <gnufnork-AT-hetdigitalegat.nl>
2409 2426 (prompt_specials): Added color support for prompt strings, so
2410 2427 users can define arbitrary color setups for their prompts.
2411 2428
2412 2429 2004-06-05 Fernando Perez <fperez@colorado.edu>
2413 2430
2414 2431 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
2415 2432 code to load Gary Bishop's readline and configure it
2416 2433 automatically. Thanks to Gary for help on this.
2417 2434
2418 2435 2004-06-01 Fernando Perez <fperez@colorado.edu>
2419 2436
2420 2437 * IPython/Logger.py (Logger.create_log): fix bug for logging
2421 2438 with no filename (previous fix was incomplete).
2422 2439
2423 2440 2004-05-25 Fernando Perez <fperez@colorado.edu>
2424 2441
2425 2442 * IPython/Magic.py (Magic.parse_options): fix bug where naked
2426 2443 parens would get passed to the shell.
2427 2444
2428 2445 2004-05-20 Fernando Perez <fperez@colorado.edu>
2429 2446
2430 2447 * IPython/Magic.py (Magic.magic_prun): changed default profile
2431 2448 sort order to 'time' (the more common profiling need).
2432 2449
2433 2450 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
2434 2451 so that source code shown is guaranteed in sync with the file on
2435 2452 disk (also changed in psource). Similar fix to the one for
2436 2453 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
2437 2454 <yann.ledu-AT-noos.fr>.
2438 2455
2439 2456 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
2440 2457 with a single option would not be correctly parsed. Closes
2441 2458 http://www.scipy.net/roundup/ipython/issue14. This bug had been
2442 2459 introduced in 0.6.0 (on 2004-05-06).
2443 2460
2444 2461 2004-05-13 *** Released version 0.6.0
2445 2462
2446 2463 2004-05-13 Fernando Perez <fperez@colorado.edu>
2447 2464
2448 2465 * debian/: Added debian/ directory to CVS, so that debian support
2449 2466 is publicly accessible. The debian package is maintained by Jack
2450 2467 Moffit <jack-AT-xiph.org>.
2451 2468
2452 2469 * Documentation: included the notes about an ipython-based system
2453 2470 shell (the hypothetical 'pysh') into the new_design.pdf document,
2454 2471 so that these ideas get distributed to users along with the
2455 2472 official documentation.
2456 2473
2457 2474 2004-05-10 Fernando Perez <fperez@colorado.edu>
2458 2475
2459 2476 * IPython/Logger.py (Logger.create_log): fix recently introduced
2460 2477 bug (misindented line) where logstart would fail when not given an
2461 2478 explicit filename.
2462 2479
2463 2480 2004-05-09 Fernando Perez <fperez@colorado.edu>
2464 2481
2465 2482 * IPython/Magic.py (Magic.parse_options): skip system call when
2466 2483 there are no options to look for. Faster, cleaner for the common
2467 2484 case.
2468 2485
2469 2486 * Documentation: many updates to the manual: describing Windows
2470 2487 support better, Gnuplot updates, credits, misc small stuff. Also
2471 2488 updated the new_design doc a bit.
2472 2489
2473 2490 2004-05-06 *** Released version 0.6.0.rc1
2474 2491
2475 2492 2004-05-06 Fernando Perez <fperez@colorado.edu>
2476 2493
2477 2494 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
2478 2495 operations to use the vastly more efficient list/''.join() method.
2479 2496 (FormattedTB.text): Fix
2480 2497 http://www.scipy.net/roundup/ipython/issue12 - exception source
2481 2498 extract not updated after reload. Thanks to Mike Salib
2482 2499 <msalib-AT-mit.edu> for pinning the source of the problem.
2483 2500 Fortunately, the solution works inside ipython and doesn't require
2484 2501 any changes to python proper.
2485 2502
2486 2503 * IPython/Magic.py (Magic.parse_options): Improved to process the
2487 2504 argument list as a true shell would (by actually using the
2488 2505 underlying system shell). This way, all @magics automatically get
2489 2506 shell expansion for variables. Thanks to a comment by Alex
2490 2507 Schmolck.
2491 2508
2492 2509 2004-04-04 Fernando Perez <fperez@colorado.edu>
2493 2510
2494 2511 * IPython/iplib.py (InteractiveShell.interact): Added a special
2495 2512 trap for a debugger quit exception, which is basically impossible
2496 2513 to handle by normal mechanisms, given what pdb does to the stack.
2497 2514 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
2498 2515
2499 2516 2004-04-03 Fernando Perez <fperez@colorado.edu>
2500 2517
2501 2518 * IPython/genutils.py (Term): Standardized the names of the Term
2502 2519 class streams to cin/cout/cerr, following C++ naming conventions
2503 2520 (I can't use in/out/err because 'in' is not a valid attribute
2504 2521 name).
2505 2522
2506 2523 * IPython/iplib.py (InteractiveShell.interact): don't increment
2507 2524 the prompt if there's no user input. By Daniel 'Dang' Griffith
2508 2525 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
2509 2526 Francois Pinard.
2510 2527
2511 2528 2004-04-02 Fernando Perez <fperez@colorado.edu>
2512 2529
2513 2530 * IPython/genutils.py (Stream.__init__): Modified to survive at
2514 2531 least importing in contexts where stdin/out/err aren't true file
2515 2532 objects, such as PyCrust (they lack fileno() and mode). However,
2516 2533 the recovery facilities which rely on these things existing will
2517 2534 not work.
2518 2535
2519 2536 2004-04-01 Fernando Perez <fperez@colorado.edu>
2520 2537
2521 2538 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
2522 2539 use the new getoutputerror() function, so it properly
2523 2540 distinguishes stdout/err.
2524 2541
2525 2542 * IPython/genutils.py (getoutputerror): added a function to
2526 2543 capture separately the standard output and error of a command.
2527 2544 After a comment from dang on the mailing lists. This code is
2528 2545 basically a modified version of commands.getstatusoutput(), from
2529 2546 the standard library.
2530 2547
2531 2548 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
2532 2549 '!!' as a special syntax (shorthand) to access @sx.
2533 2550
2534 2551 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
2535 2552 command and return its output as a list split on '\n'.
2536 2553
2537 2554 2004-03-31 Fernando Perez <fperez@colorado.edu>
2538 2555
2539 2556 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
2540 2557 method to dictionaries used as FakeModule instances if they lack
2541 2558 it. At least pydoc in python2.3 breaks for runtime-defined
2542 2559 functions without this hack. At some point I need to _really_
2543 2560 understand what FakeModule is doing, because it's a gross hack.
2544 2561 But it solves Arnd's problem for now...
2545 2562
2546 2563 2004-02-27 Fernando Perez <fperez@colorado.edu>
2547 2564
2548 2565 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
2549 2566 mode would behave erratically. Also increased the number of
2550 2567 possible logs in rotate mod to 999. Thanks to Rod Holland
2551 2568 <rhh@StructureLABS.com> for the report and fixes.
2552 2569
2553 2570 2004-02-26 Fernando Perez <fperez@colorado.edu>
2554 2571
2555 2572 * IPython/genutils.py (page): Check that the curses module really
2556 2573 has the initscr attribute before trying to use it. For some
2557 2574 reason, the Solaris curses module is missing this. I think this
2558 2575 should be considered a Solaris python bug, but I'm not sure.
2559 2576
2560 2577 2004-01-17 Fernando Perez <fperez@colorado.edu>
2561 2578
2562 2579 * IPython/genutils.py (Stream.__init__): Changes to try to make
2563 2580 ipython robust against stdin/out/err being closed by the user.
2564 2581 This is 'user error' (and blocks a normal python session, at least
2565 2582 the stdout case). However, Ipython should be able to survive such
2566 2583 instances of abuse as gracefully as possible. To simplify the
2567 2584 coding and maintain compatibility with Gary Bishop's Term
2568 2585 contributions, I've made use of classmethods for this. I think
2569 2586 this introduces a dependency on python 2.2.
2570 2587
2571 2588 2004-01-13 Fernando Perez <fperez@colorado.edu>
2572 2589
2573 2590 * IPython/numutils.py (exp_safe): simplified the code a bit and
2574 2591 removed the need for importing the kinds module altogether.
2575 2592
2576 2593 2004-01-06 Fernando Perez <fperez@colorado.edu>
2577 2594
2578 2595 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
2579 2596 a magic function instead, after some community feedback. No
2580 2597 special syntax will exist for it, but its name is deliberately
2581 2598 very short.
2582 2599
2583 2600 2003-12-20 Fernando Perez <fperez@colorado.edu>
2584 2601
2585 2602 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
2586 2603 new functionality, to automagically assign the result of a shell
2587 2604 command to a variable. I'll solicit some community feedback on
2588 2605 this before making it permanent.
2589 2606
2590 2607 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
2591 2608 requested about callables for which inspect couldn't obtain a
2592 2609 proper argspec. Thanks to a crash report sent by Etienne
2593 2610 Posthumus <etienne-AT-apple01.cs.vu.nl>.
2594 2611
2595 2612 2003-12-09 Fernando Perez <fperez@colorado.edu>
2596 2613
2597 2614 * IPython/genutils.py (page): patch for the pager to work across
2598 2615 various versions of Windows. By Gary Bishop.
2599 2616
2600 2617 2003-12-04 Fernando Perez <fperez@colorado.edu>
2601 2618
2602 2619 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
2603 2620 Gnuplot.py version 1.7, whose internal names changed quite a bit.
2604 2621 While I tested this and it looks ok, there may still be corner
2605 2622 cases I've missed.
2606 2623
2607 2624 2003-12-01 Fernando Perez <fperez@colorado.edu>
2608 2625
2609 2626 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
2610 2627 where a line like 'p,q=1,2' would fail because the automagic
2611 2628 system would be triggered for @p.
2612 2629
2613 2630 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
2614 2631 cleanups, code unmodified.
2615 2632
2616 2633 * IPython/genutils.py (Term): added a class for IPython to handle
2617 2634 output. In most cases it will just be a proxy for stdout/err, but
2618 2635 having this allows modifications to be made for some platforms,
2619 2636 such as handling color escapes under Windows. All of this code
2620 2637 was contributed by Gary Bishop, with minor modifications by me.
2621 2638 The actual changes affect many files.
2622 2639
2623 2640 2003-11-30 Fernando Perez <fperez@colorado.edu>
2624 2641
2625 2642 * IPython/iplib.py (file_matches): new completion code, courtesy
2626 2643 of Jeff Collins. This enables filename completion again under
2627 2644 python 2.3, which disabled it at the C level.
2628 2645
2629 2646 2003-11-11 Fernando Perez <fperez@colorado.edu>
2630 2647
2631 2648 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
2632 2649 for Numeric.array(map(...)), but often convenient.
2633 2650
2634 2651 2003-11-05 Fernando Perez <fperez@colorado.edu>
2635 2652
2636 2653 * IPython/numutils.py (frange): Changed a call from int() to
2637 2654 int(round()) to prevent a problem reported with arange() in the
2638 2655 numpy list.
2639 2656
2640 2657 2003-10-06 Fernando Perez <fperez@colorado.edu>
2641 2658
2642 2659 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
2643 2660 prevent crashes if sys lacks an argv attribute (it happens with
2644 2661 embedded interpreters which build a bare-bones sys module).
2645 2662 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
2646 2663
2647 2664 2003-09-24 Fernando Perez <fperez@colorado.edu>
2648 2665
2649 2666 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
2650 2667 to protect against poorly written user objects where __getattr__
2651 2668 raises exceptions other than AttributeError. Thanks to a bug
2652 2669 report by Oliver Sander <osander-AT-gmx.de>.
2653 2670
2654 2671 * IPython/FakeModule.py (FakeModule.__repr__): this method was
2655 2672 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
2656 2673
2657 2674 2003-09-09 Fernando Perez <fperez@colorado.edu>
2658 2675
2659 2676 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
2660 2677 unpacking a list whith a callable as first element would
2661 2678 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
2662 2679 Collins.
2663 2680
2664 2681 2003-08-25 *** Released version 0.5.0
2665 2682
2666 2683 2003-08-22 Fernando Perez <fperez@colorado.edu>
2667 2684
2668 2685 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
2669 2686 improperly defined user exceptions. Thanks to feedback from Mark
2670 2687 Russell <mrussell-AT-verio.net>.
2671 2688
2672 2689 2003-08-20 Fernando Perez <fperez@colorado.edu>
2673 2690
2674 2691 * IPython/OInspect.py (Inspector.pinfo): changed String Form
2675 2692 printing so that it would print multi-line string forms starting
2676 2693 with a new line. This way the formatting is better respected for
2677 2694 objects which work hard to make nice string forms.
2678 2695
2679 2696 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
2680 2697 autocall would overtake data access for objects with both
2681 2698 __getitem__ and __call__.
2682 2699
2683 2700 2003-08-19 *** Released version 0.5.0-rc1
2684 2701
2685 2702 2003-08-19 Fernando Perez <fperez@colorado.edu>
2686 2703
2687 2704 * IPython/deep_reload.py (load_tail): single tiny change here
2688 2705 seems to fix the long-standing bug of dreload() failing to work
2689 2706 for dotted names. But this module is pretty tricky, so I may have
2690 2707 missed some subtlety. Needs more testing!.
2691 2708
2692 2709 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
2693 2710 exceptions which have badly implemented __str__ methods.
2694 2711 (VerboseTB.text): harden against inspect.getinnerframes crashing,
2695 2712 which I've been getting reports about from Python 2.3 users. I
2696 2713 wish I had a simple test case to reproduce the problem, so I could
2697 2714 either write a cleaner workaround or file a bug report if
2698 2715 necessary.
2699 2716
2700 2717 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
2701 2718 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
2702 2719 a bug report by Tjabo Kloppenburg.
2703 2720
2704 2721 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
2705 2722 crashes. Wrapped the pdb call in a blanket try/except, since pdb
2706 2723 seems rather unstable. Thanks to a bug report by Tjabo
2707 2724 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
2708 2725
2709 2726 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
2710 2727 this out soon because of the critical fixes in the inner loop for
2711 2728 generators.
2712 2729
2713 2730 * IPython/Magic.py (Magic.getargspec): removed. This (and
2714 2731 _get_def) have been obsoleted by OInspect for a long time, I
2715 2732 hadn't noticed that they were dead code.
2716 2733 (Magic._ofind): restored _ofind functionality for a few literals
2717 2734 (those in ["''",'""','[]','{}','()']). But it won't work anymore
2718 2735 for things like "hello".capitalize?, since that would require a
2719 2736 potentially dangerous eval() again.
2720 2737
2721 2738 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
2722 2739 logic a bit more to clean up the escapes handling and minimize the
2723 2740 use of _ofind to only necessary cases. The interactive 'feel' of
2724 2741 IPython should have improved quite a bit with the changes in
2725 2742 _prefilter and _ofind (besides being far safer than before).
2726 2743
2727 2744 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
2728 2745 obscure, never reported). Edit would fail to find the object to
2729 2746 edit under some circumstances.
2730 2747 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
2731 2748 which were causing double-calling of generators. Those eval calls
2732 2749 were _very_ dangerous, since code with side effects could be
2733 2750 triggered. As they say, 'eval is evil'... These were the
2734 2751 nastiest evals in IPython. Besides, _ofind is now far simpler,
2735 2752 and it should also be quite a bit faster. Its use of inspect is
2736 2753 also safer, so perhaps some of the inspect-related crashes I've
2737 2754 seen lately with Python 2.3 might be taken care of. That will
2738 2755 need more testing.
2739 2756
2740 2757 2003-08-17 Fernando Perez <fperez@colorado.edu>
2741 2758
2742 2759 * IPython/iplib.py (InteractiveShell._prefilter): significant
2743 2760 simplifications to the logic for handling user escapes. Faster
2744 2761 and simpler code.
2745 2762
2746 2763 2003-08-14 Fernando Perez <fperez@colorado.edu>
2747 2764
2748 2765 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
2749 2766 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
2750 2767 but it should be quite a bit faster. And the recursive version
2751 2768 generated O(log N) intermediate storage for all rank>1 arrays,
2752 2769 even if they were contiguous.
2753 2770 (l1norm): Added this function.
2754 2771 (norm): Added this function for arbitrary norms (including
2755 2772 l-infinity). l1 and l2 are still special cases for convenience
2756 2773 and speed.
2757 2774
2758 2775 2003-08-03 Fernando Perez <fperez@colorado.edu>
2759 2776
2760 2777 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
2761 2778 exceptions, which now raise PendingDeprecationWarnings in Python
2762 2779 2.3. There were some in Magic and some in Gnuplot2.
2763 2780
2764 2781 2003-06-30 Fernando Perez <fperez@colorado.edu>
2765 2782
2766 2783 * IPython/genutils.py (page): modified to call curses only for
2767 2784 terminals where TERM=='xterm'. After problems under many other
2768 2785 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2769 2786
2770 2787 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2771 2788 would be triggered when readline was absent. This was just an old
2772 2789 debugging statement I'd forgotten to take out.
2773 2790
2774 2791 2003-06-20 Fernando Perez <fperez@colorado.edu>
2775 2792
2776 2793 * IPython/genutils.py (clock): modified to return only user time
2777 2794 (not counting system time), after a discussion on scipy. While
2778 2795 system time may be a useful quantity occasionally, it may much
2779 2796 more easily be skewed by occasional swapping or other similar
2780 2797 activity.
2781 2798
2782 2799 2003-06-05 Fernando Perez <fperez@colorado.edu>
2783 2800
2784 2801 * IPython/numutils.py (identity): new function, for building
2785 2802 arbitrary rank Kronecker deltas (mostly backwards compatible with
2786 2803 Numeric.identity)
2787 2804
2788 2805 2003-06-03 Fernando Perez <fperez@colorado.edu>
2789 2806
2790 2807 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2791 2808 arguments passed to magics with spaces, to allow trailing '\' to
2792 2809 work normally (mainly for Windows users).
2793 2810
2794 2811 2003-05-29 Fernando Perez <fperez@colorado.edu>
2795 2812
2796 2813 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2797 2814 instead of pydoc.help. This fixes a bizarre behavior where
2798 2815 printing '%s' % locals() would trigger the help system. Now
2799 2816 ipython behaves like normal python does.
2800 2817
2801 2818 Note that if one does 'from pydoc import help', the bizarre
2802 2819 behavior returns, but this will also happen in normal python, so
2803 2820 it's not an ipython bug anymore (it has to do with how pydoc.help
2804 2821 is implemented).
2805 2822
2806 2823 2003-05-22 Fernando Perez <fperez@colorado.edu>
2807 2824
2808 2825 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2809 2826 return [] instead of None when nothing matches, also match to end
2810 2827 of line. Patch by Gary Bishop.
2811 2828
2812 2829 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2813 2830 protection as before, for files passed on the command line. This
2814 2831 prevents the CrashHandler from kicking in if user files call into
2815 2832 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2816 2833 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2817 2834
2818 2835 2003-05-20 *** Released version 0.4.0
2819 2836
2820 2837 2003-05-20 Fernando Perez <fperez@colorado.edu>
2821 2838
2822 2839 * setup.py: added support for manpages. It's a bit hackish b/c of
2823 2840 a bug in the way the bdist_rpm distutils target handles gzipped
2824 2841 manpages, but it works. After a patch by Jack.
2825 2842
2826 2843 2003-05-19 Fernando Perez <fperez@colorado.edu>
2827 2844
2828 2845 * IPython/numutils.py: added a mockup of the kinds module, since
2829 2846 it was recently removed from Numeric. This way, numutils will
2830 2847 work for all users even if they are missing kinds.
2831 2848
2832 2849 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2833 2850 failure, which can occur with SWIG-wrapped extensions. After a
2834 2851 crash report from Prabhu.
2835 2852
2836 2853 2003-05-16 Fernando Perez <fperez@colorado.edu>
2837 2854
2838 2855 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2839 2856 protect ipython from user code which may call directly
2840 2857 sys.excepthook (this looks like an ipython crash to the user, even
2841 2858 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2842 2859 This is especially important to help users of WxWindows, but may
2843 2860 also be useful in other cases.
2844 2861
2845 2862 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2846 2863 an optional tb_offset to be specified, and to preserve exception
2847 2864 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2848 2865
2849 2866 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2850 2867
2851 2868 2003-05-15 Fernando Perez <fperez@colorado.edu>
2852 2869
2853 2870 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2854 2871 installing for a new user under Windows.
2855 2872
2856 2873 2003-05-12 Fernando Perez <fperez@colorado.edu>
2857 2874
2858 2875 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2859 2876 handler for Emacs comint-based lines. Currently it doesn't do
2860 2877 much (but importantly, it doesn't update the history cache). In
2861 2878 the future it may be expanded if Alex needs more functionality
2862 2879 there.
2863 2880
2864 2881 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2865 2882 info to crash reports.
2866 2883
2867 2884 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2868 2885 just like Python's -c. Also fixed crash with invalid -color
2869 2886 option value at startup. Thanks to Will French
2870 2887 <wfrench-AT-bestweb.net> for the bug report.
2871 2888
2872 2889 2003-05-09 Fernando Perez <fperez@colorado.edu>
2873 2890
2874 2891 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2875 2892 to EvalDict (it's a mapping, after all) and simplified its code
2876 2893 quite a bit, after a nice discussion on c.l.py where Gustavo
2877 2894 Córdova <gcordova-AT-sismex.com> suggested the new version.
2878 2895
2879 2896 2003-04-30 Fernando Perez <fperez@colorado.edu>
2880 2897
2881 2898 * IPython/genutils.py (timings_out): modified it to reduce its
2882 2899 overhead in the common reps==1 case.
2883 2900
2884 2901 2003-04-29 Fernando Perez <fperez@colorado.edu>
2885 2902
2886 2903 * IPython/genutils.py (timings_out): Modified to use the resource
2887 2904 module, which avoids the wraparound problems of time.clock().
2888 2905
2889 2906 2003-04-17 *** Released version 0.2.15pre4
2890 2907
2891 2908 2003-04-17 Fernando Perez <fperez@colorado.edu>
2892 2909
2893 2910 * setup.py (scriptfiles): Split windows-specific stuff over to a
2894 2911 separate file, in an attempt to have a Windows GUI installer.
2895 2912 That didn't work, but part of the groundwork is done.
2896 2913
2897 2914 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2898 2915 indent/unindent with 4 spaces. Particularly useful in combination
2899 2916 with the new auto-indent option.
2900 2917
2901 2918 2003-04-16 Fernando Perez <fperez@colorado.edu>
2902 2919
2903 2920 * IPython/Magic.py: various replacements of self.rc for
2904 2921 self.shell.rc. A lot more remains to be done to fully disentangle
2905 2922 this class from the main Shell class.
2906 2923
2907 2924 * IPython/GnuplotRuntime.py: added checks for mouse support so
2908 2925 that we don't try to enable it if the current gnuplot doesn't
2909 2926 really support it. Also added checks so that we don't try to
2910 2927 enable persist under Windows (where Gnuplot doesn't recognize the
2911 2928 option).
2912 2929
2913 2930 * IPython/iplib.py (InteractiveShell.interact): Added optional
2914 2931 auto-indenting code, after a patch by King C. Shu
2915 2932 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2916 2933 get along well with pasting indented code. If I ever figure out
2917 2934 how to make that part go well, it will become on by default.
2918 2935
2919 2936 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2920 2937 crash ipython if there was an unmatched '%' in the user's prompt
2921 2938 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2922 2939
2923 2940 * IPython/iplib.py (InteractiveShell.interact): removed the
2924 2941 ability to ask the user whether he wants to crash or not at the
2925 2942 'last line' exception handler. Calling functions at that point
2926 2943 changes the stack, and the error reports would have incorrect
2927 2944 tracebacks.
2928 2945
2929 2946 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2930 2947 pass through a peger a pretty-printed form of any object. After a
2931 2948 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2932 2949
2933 2950 2003-04-14 Fernando Perez <fperez@colorado.edu>
2934 2951
2935 2952 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2936 2953 all files in ~ would be modified at first install (instead of
2937 2954 ~/.ipython). This could be potentially disastrous, as the
2938 2955 modification (make line-endings native) could damage binary files.
2939 2956
2940 2957 2003-04-10 Fernando Perez <fperez@colorado.edu>
2941 2958
2942 2959 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2943 2960 handle only lines which are invalid python. This now means that
2944 2961 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2945 2962 for the bug report.
2946 2963
2947 2964 2003-04-01 Fernando Perez <fperez@colorado.edu>
2948 2965
2949 2966 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2950 2967 where failing to set sys.last_traceback would crash pdb.pm().
2951 2968 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2952 2969 report.
2953 2970
2954 2971 2003-03-25 Fernando Perez <fperez@colorado.edu>
2955 2972
2956 2973 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2957 2974 before printing it (it had a lot of spurious blank lines at the
2958 2975 end).
2959 2976
2960 2977 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2961 2978 output would be sent 21 times! Obviously people don't use this
2962 2979 too often, or I would have heard about it.
2963 2980
2964 2981 2003-03-24 Fernando Perez <fperez@colorado.edu>
2965 2982
2966 2983 * setup.py (scriptfiles): renamed the data_files parameter from
2967 2984 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2968 2985 for the patch.
2969 2986
2970 2987 2003-03-20 Fernando Perez <fperez@colorado.edu>
2971 2988
2972 2989 * IPython/genutils.py (error): added error() and fatal()
2973 2990 functions.
2974 2991
2975 2992 2003-03-18 *** Released version 0.2.15pre3
2976 2993
2977 2994 2003-03-18 Fernando Perez <fperez@colorado.edu>
2978 2995
2979 2996 * setupext/install_data_ext.py
2980 2997 (install_data_ext.initialize_options): Class contributed by Jack
2981 2998 Moffit for fixing the old distutils hack. He is sending this to
2982 2999 the distutils folks so in the future we may not need it as a
2983 3000 private fix.
2984 3001
2985 3002 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2986 3003 changes for Debian packaging. See his patch for full details.
2987 3004 The old distutils hack of making the ipythonrc* files carry a
2988 3005 bogus .py extension is gone, at last. Examples were moved to a
2989 3006 separate subdir under doc/, and the separate executable scripts
2990 3007 now live in their own directory. Overall a great cleanup. The
2991 3008 manual was updated to use the new files, and setup.py has been
2992 3009 fixed for this setup.
2993 3010
2994 3011 * IPython/PyColorize.py (Parser.usage): made non-executable and
2995 3012 created a pycolor wrapper around it to be included as a script.
2996 3013
2997 3014 2003-03-12 *** Released version 0.2.15pre2
2998 3015
2999 3016 2003-03-12 Fernando Perez <fperez@colorado.edu>
3000 3017
3001 3018 * IPython/ColorANSI.py (make_color_table): Finally fixed the
3002 3019 long-standing problem with garbage characters in some terminals.
3003 3020 The issue was really that the \001 and \002 escapes must _only_ be
3004 3021 passed to input prompts (which call readline), but _never_ to
3005 3022 normal text to be printed on screen. I changed ColorANSI to have
3006 3023 two classes: TermColors and InputTermColors, each with the
3007 3024 appropriate escapes for input prompts or normal text. The code in
3008 3025 Prompts.py got slightly more complicated, but this very old and
3009 3026 annoying bug is finally fixed.
3010 3027
3011 3028 All the credit for nailing down the real origin of this problem
3012 3029 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
3013 3030 *Many* thanks to him for spending quite a bit of effort on this.
3014 3031
3015 3032 2003-03-05 *** Released version 0.2.15pre1
3016 3033
3017 3034 2003-03-03 Fernando Perez <fperez@colorado.edu>
3018 3035
3019 3036 * IPython/FakeModule.py: Moved the former _FakeModule to a
3020 3037 separate file, because it's also needed by Magic (to fix a similar
3021 3038 pickle-related issue in @run).
3022 3039
3023 3040 2003-03-02 Fernando Perez <fperez@colorado.edu>
3024 3041
3025 3042 * IPython/Magic.py (Magic.magic_autocall): new magic to control
3026 3043 the autocall option at runtime.
3027 3044 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
3028 3045 across Magic.py to start separating Magic from InteractiveShell.
3029 3046 (Magic._ofind): Fixed to return proper namespace for dotted
3030 3047 names. Before, a dotted name would always return 'not currently
3031 3048 defined', because it would find the 'parent'. s.x would be found,
3032 3049 but since 'x' isn't defined by itself, it would get confused.
3033 3050 (Magic.magic_run): Fixed pickling problems reported by Ralf
3034 3051 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
3035 3052 that I'd used when Mike Heeter reported similar issues at the
3036 3053 top-level, but now for @run. It boils down to injecting the
3037 3054 namespace where code is being executed with something that looks
3038 3055 enough like a module to fool pickle.dump(). Since a pickle stores
3039 3056 a named reference to the importing module, we need this for
3040 3057 pickles to save something sensible.
3041 3058
3042 3059 * IPython/ipmaker.py (make_IPython): added an autocall option.
3043 3060
3044 3061 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
3045 3062 the auto-eval code. Now autocalling is an option, and the code is
3046 3063 also vastly safer. There is no more eval() involved at all.
3047 3064
3048 3065 2003-03-01 Fernando Perez <fperez@colorado.edu>
3049 3066
3050 3067 * IPython/Magic.py (Magic._ofind): Changed interface to return a
3051 3068 dict with named keys instead of a tuple.
3052 3069
3053 3070 * IPython: Started using CVS for IPython as of 0.2.15pre1.
3054 3071
3055 3072 * setup.py (make_shortcut): Fixed message about directories
3056 3073 created during Windows installation (the directories were ok, just
3057 3074 the printed message was misleading). Thanks to Chris Liechti
3058 3075 <cliechti-AT-gmx.net> for the heads up.
3059 3076
3060 3077 2003-02-21 Fernando Perez <fperez@colorado.edu>
3061 3078
3062 3079 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
3063 3080 of ValueError exception when checking for auto-execution. This
3064 3081 one is raised by things like Numeric arrays arr.flat when the
3065 3082 array is non-contiguous.
3066 3083
3067 3084 2003-01-31 Fernando Perez <fperez@colorado.edu>
3068 3085
3069 3086 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
3070 3087 not return any value at all (even though the command would get
3071 3088 executed).
3072 3089 (xsys): Flush stdout right after printing the command to ensure
3073 3090 proper ordering of commands and command output in the total
3074 3091 output.
3075 3092 (SystemExec/xsys/bq): Switched the names of xsys/bq and
3076 3093 system/getoutput as defaults. The old ones are kept for
3077 3094 compatibility reasons, so no code which uses this library needs
3078 3095 changing.
3079 3096
3080 3097 2003-01-27 *** Released version 0.2.14
3081 3098
3082 3099 2003-01-25 Fernando Perez <fperez@colorado.edu>
3083 3100
3084 3101 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
3085 3102 functions defined in previous edit sessions could not be re-edited
3086 3103 (because the temp files were immediately removed). Now temp files
3087 3104 are removed only at IPython's exit.
3088 3105 (Magic.magic_run): Improved @run to perform shell-like expansions
3089 3106 on its arguments (~users and $VARS). With this, @run becomes more
3090 3107 like a normal command-line.
3091 3108
3092 3109 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
3093 3110 bugs related to embedding and cleaned up that code. A fairly
3094 3111 important one was the impossibility to access the global namespace
3095 3112 through the embedded IPython (only local variables were visible).
3096 3113
3097 3114 2003-01-14 Fernando Perez <fperez@colorado.edu>
3098 3115
3099 3116 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
3100 3117 auto-calling to be a bit more conservative. Now it doesn't get
3101 3118 triggered if any of '!=()<>' are in the rest of the input line, to
3102 3119 allow comparing callables. Thanks to Alex for the heads up.
3103 3120
3104 3121 2003-01-07 Fernando Perez <fperez@colorado.edu>
3105 3122
3106 3123 * IPython/genutils.py (page): fixed estimation of the number of
3107 3124 lines in a string to be paged to simply count newlines. This
3108 3125 prevents over-guessing due to embedded escape sequences. A better
3109 3126 long-term solution would involve stripping out the control chars
3110 3127 for the count, but it's potentially so expensive I just don't
3111 3128 think it's worth doing.
3112 3129
3113 3130 2002-12-19 *** Released version 0.2.14pre50
3114 3131
3115 3132 2002-12-19 Fernando Perez <fperez@colorado.edu>
3116 3133
3117 3134 * tools/release (version): Changed release scripts to inform
3118 3135 Andrea and build a NEWS file with a list of recent changes.
3119 3136
3120 3137 * IPython/ColorANSI.py (__all__): changed terminal detection
3121 3138 code. Seems to work better for xterms without breaking
3122 3139 konsole. Will need more testing to determine if WinXP and Mac OSX
3123 3140 also work ok.
3124 3141
3125 3142 2002-12-18 *** Released version 0.2.14pre49
3126 3143
3127 3144 2002-12-18 Fernando Perez <fperez@colorado.edu>
3128 3145
3129 3146 * Docs: added new info about Mac OSX, from Andrea.
3130 3147
3131 3148 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
3132 3149 allow direct plotting of python strings whose format is the same
3133 3150 of gnuplot data files.
3134 3151
3135 3152 2002-12-16 Fernando Perez <fperez@colorado.edu>
3136 3153
3137 3154 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
3138 3155 value of exit question to be acknowledged.
3139 3156
3140 3157 2002-12-03 Fernando Perez <fperez@colorado.edu>
3141 3158
3142 3159 * IPython/ipmaker.py: removed generators, which had been added
3143 3160 by mistake in an earlier debugging run. This was causing trouble
3144 3161 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
3145 3162 for pointing this out.
3146 3163
3147 3164 2002-11-17 Fernando Perez <fperez@colorado.edu>
3148 3165
3149 3166 * Manual: updated the Gnuplot section.
3150 3167
3151 3168 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
3152 3169 a much better split of what goes in Runtime and what goes in
3153 3170 Interactive.
3154 3171
3155 3172 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
3156 3173 being imported from iplib.
3157 3174
3158 3175 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
3159 3176 for command-passing. Now the global Gnuplot instance is called
3160 3177 'gp' instead of 'g', which was really a far too fragile and
3161 3178 common name.
3162 3179
3163 3180 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
3164 3181 bounding boxes generated by Gnuplot for square plots.
3165 3182
3166 3183 * IPython/genutils.py (popkey): new function added. I should
3167 3184 suggest this on c.l.py as a dict method, it seems useful.
3168 3185
3169 3186 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
3170 3187 to transparently handle PostScript generation. MUCH better than
3171 3188 the previous plot_eps/replot_eps (which I removed now). The code
3172 3189 is also fairly clean and well documented now (including
3173 3190 docstrings).
3174 3191
3175 3192 2002-11-13 Fernando Perez <fperez@colorado.edu>
3176 3193
3177 3194 * IPython/Magic.py (Magic.magic_edit): fixed docstring
3178 3195 (inconsistent with options).
3179 3196
3180 3197 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
3181 3198 manually disabled, I don't know why. Fixed it.
3182 3199 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
3183 3200 eps output.
3184 3201
3185 3202 2002-11-12 Fernando Perez <fperez@colorado.edu>
3186 3203
3187 3204 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
3188 3205 don't propagate up to caller. Fixes crash reported by François
3189 3206 Pinard.
3190 3207
3191 3208 2002-11-09 Fernando Perez <fperez@colorado.edu>
3192 3209
3193 3210 * IPython/ipmaker.py (make_IPython): fixed problem with writing
3194 3211 history file for new users.
3195 3212 (make_IPython): fixed bug where initial install would leave the
3196 3213 user running in the .ipython dir.
3197 3214 (make_IPython): fixed bug where config dir .ipython would be
3198 3215 created regardless of the given -ipythondir option. Thanks to Cory
3199 3216 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
3200 3217
3201 3218 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
3202 3219 type confirmations. Will need to use it in all of IPython's code
3203 3220 consistently.
3204 3221
3205 3222 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
3206 3223 context to print 31 lines instead of the default 5. This will make
3207 3224 the crash reports extremely detailed in case the problem is in
3208 3225 libraries I don't have access to.
3209 3226
3210 3227 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
3211 3228 line of defense' code to still crash, but giving users fair
3212 3229 warning. I don't want internal errors to go unreported: if there's
3213 3230 an internal problem, IPython should crash and generate a full
3214 3231 report.
3215 3232
3216 3233 2002-11-08 Fernando Perez <fperez@colorado.edu>
3217 3234
3218 3235 * IPython/iplib.py (InteractiveShell.interact): added code to trap
3219 3236 otherwise uncaught exceptions which can appear if people set
3220 3237 sys.stdout to something badly broken. Thanks to a crash report
3221 3238 from henni-AT-mail.brainbot.com.
3222 3239
3223 3240 2002-11-04 Fernando Perez <fperez@colorado.edu>
3224 3241
3225 3242 * IPython/iplib.py (InteractiveShell.interact): added
3226 3243 __IPYTHON__active to the builtins. It's a flag which goes on when
3227 3244 the interaction starts and goes off again when it stops. This
3228 3245 allows embedding code to detect being inside IPython. Before this
3229 3246 was done via __IPYTHON__, but that only shows that an IPython
3230 3247 instance has been created.
3231 3248
3232 3249 * IPython/Magic.py (Magic.magic_env): I realized that in a
3233 3250 UserDict, instance.data holds the data as a normal dict. So I
3234 3251 modified @env to return os.environ.data instead of rebuilding a
3235 3252 dict by hand.
3236 3253
3237 3254 2002-11-02 Fernando Perez <fperez@colorado.edu>
3238 3255
3239 3256 * IPython/genutils.py (warn): changed so that level 1 prints no
3240 3257 header. Level 2 is now the default (with 'WARNING' header, as
3241 3258 before). I think I tracked all places where changes were needed in
3242 3259 IPython, but outside code using the old level numbering may have
3243 3260 broken.
3244 3261
3245 3262 * IPython/iplib.py (InteractiveShell.runcode): added this to
3246 3263 handle the tracebacks in SystemExit traps correctly. The previous
3247 3264 code (through interact) was printing more of the stack than
3248 3265 necessary, showing IPython internal code to the user.
3249 3266
3250 3267 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
3251 3268 default. Now that the default at the confirmation prompt is yes,
3252 3269 it's not so intrusive. François' argument that ipython sessions
3253 3270 tend to be complex enough not to lose them from an accidental C-d,
3254 3271 is a valid one.
3255 3272
3256 3273 * IPython/iplib.py (InteractiveShell.interact): added a
3257 3274 showtraceback() call to the SystemExit trap, and modified the exit
3258 3275 confirmation to have yes as the default.
3259 3276
3260 3277 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
3261 3278 this file. It's been gone from the code for a long time, this was
3262 3279 simply leftover junk.
3263 3280
3264 3281 2002-11-01 Fernando Perez <fperez@colorado.edu>
3265 3282
3266 3283 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
3267 3284 added. If set, IPython now traps EOF and asks for
3268 3285 confirmation. After a request by François Pinard.
3269 3286
3270 3287 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
3271 3288 of @abort, and with a new (better) mechanism for handling the
3272 3289 exceptions.
3273 3290
3274 3291 2002-10-27 Fernando Perez <fperez@colorado.edu>
3275 3292
3276 3293 * IPython/usage.py (__doc__): updated the --help information and
3277 3294 the ipythonrc file to indicate that -log generates
3278 3295 ./ipython.log. Also fixed the corresponding info in @logstart.
3279 3296 This and several other fixes in the manuals thanks to reports by
3280 3297 François Pinard <pinard-AT-iro.umontreal.ca>.
3281 3298
3282 3299 * IPython/Logger.py (Logger.switch_log): Fixed error message to
3283 3300 refer to @logstart (instead of @log, which doesn't exist).
3284 3301
3285 3302 * IPython/iplib.py (InteractiveShell._prefilter): fixed
3286 3303 AttributeError crash. Thanks to Christopher Armstrong
3287 3304 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
3288 3305 introduced recently (in 0.2.14pre37) with the fix to the eval
3289 3306 problem mentioned below.
3290 3307
3291 3308 2002-10-17 Fernando Perez <fperez@colorado.edu>
3292 3309
3293 3310 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
3294 3311 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
3295 3312
3296 3313 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
3297 3314 this function to fix a problem reported by Alex Schmolck. He saw
3298 3315 it with list comprehensions and generators, which were getting
3299 3316 called twice. The real problem was an 'eval' call in testing for
3300 3317 automagic which was evaluating the input line silently.
3301 3318
3302 3319 This is a potentially very nasty bug, if the input has side
3303 3320 effects which must not be repeated. The code is much cleaner now,
3304 3321 without any blanket 'except' left and with a regexp test for
3305 3322 actual function names.
3306 3323
3307 3324 But an eval remains, which I'm not fully comfortable with. I just
3308 3325 don't know how to find out if an expression could be a callable in
3309 3326 the user's namespace without doing an eval on the string. However
3310 3327 that string is now much more strictly checked so that no code
3311 3328 slips by, so the eval should only happen for things that can
3312 3329 really be only function/method names.
3313 3330
3314 3331 2002-10-15 Fernando Perez <fperez@colorado.edu>
3315 3332
3316 3333 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
3317 3334 OSX information to main manual, removed README_Mac_OSX file from
3318 3335 distribution. Also updated credits for recent additions.
3319 3336
3320 3337 2002-10-10 Fernando Perez <fperez@colorado.edu>
3321 3338
3322 3339 * README_Mac_OSX: Added a README for Mac OSX users for fixing
3323 3340 terminal-related issues. Many thanks to Andrea Riciputi
3324 3341 <andrea.riciputi-AT-libero.it> for writing it.
3325 3342
3326 3343 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
3327 3344 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
3328 3345
3329 3346 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
3330 3347 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
3331 3348 <syver-en-AT-online.no> who both submitted patches for this problem.
3332 3349
3333 3350 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
3334 3351 global embedding to make sure that things don't overwrite user
3335 3352 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
3336 3353
3337 3354 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
3338 3355 compatibility. Thanks to Hayden Callow
3339 3356 <h.callow-AT-elec.canterbury.ac.nz>
3340 3357
3341 3358 2002-10-04 Fernando Perez <fperez@colorado.edu>
3342 3359
3343 3360 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
3344 3361 Gnuplot.File objects.
3345 3362
3346 3363 2002-07-23 Fernando Perez <fperez@colorado.edu>
3347 3364
3348 3365 * IPython/genutils.py (timing): Added timings() and timing() for
3349 3366 quick access to the most commonly needed data, the execution
3350 3367 times. Old timing() renamed to timings_out().
3351 3368
3352 3369 2002-07-18 Fernando Perez <fperez@colorado.edu>
3353 3370
3354 3371 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
3355 3372 bug with nested instances disrupting the parent's tab completion.
3356 3373
3357 3374 * IPython/iplib.py (all_completions): Added Alex Schmolck's
3358 3375 all_completions code to begin the emacs integration.
3359 3376
3360 3377 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
3361 3378 argument to allow titling individual arrays when plotting.
3362 3379
3363 3380 2002-07-15 Fernando Perez <fperez@colorado.edu>
3364 3381
3365 3382 * setup.py (make_shortcut): changed to retrieve the value of
3366 3383 'Program Files' directory from the registry (this value changes in
3367 3384 non-english versions of Windows). Thanks to Thomas Fanslau
3368 3385 <tfanslau-AT-gmx.de> for the report.
3369 3386
3370 3387 2002-07-10 Fernando Perez <fperez@colorado.edu>
3371 3388
3372 3389 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
3373 3390 a bug in pdb, which crashes if a line with only whitespace is
3374 3391 entered. Bug report submitted to sourceforge.
3375 3392
3376 3393 2002-07-09 Fernando Perez <fperez@colorado.edu>
3377 3394
3378 3395 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
3379 3396 reporting exceptions (it's a bug in inspect.py, I just set a
3380 3397 workaround).
3381 3398
3382 3399 2002-07-08 Fernando Perez <fperez@colorado.edu>
3383 3400
3384 3401 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
3385 3402 __IPYTHON__ in __builtins__ to show up in user_ns.
3386 3403
3387 3404 2002-07-03 Fernando Perez <fperez@colorado.edu>
3388 3405
3389 3406 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
3390 3407 name from @gp_set_instance to @gp_set_default.
3391 3408
3392 3409 * IPython/ipmaker.py (make_IPython): default editor value set to
3393 3410 '0' (a string), to match the rc file. Otherwise will crash when
3394 3411 .strip() is called on it.
3395 3412
3396 3413
3397 3414 2002-06-28 Fernando Perez <fperez@colorado.edu>
3398 3415
3399 3416 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
3400 3417 of files in current directory when a file is executed via
3401 3418 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
3402 3419
3403 3420 * setup.py (manfiles): fix for rpm builds, submitted by RA
3404 3421 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
3405 3422
3406 3423 * IPython/ipmaker.py (make_IPython): fixed lookup of default
3407 3424 editor when set to '0'. Problem was, '0' evaluates to True (it's a
3408 3425 string!). A. Schmolck caught this one.
3409 3426
3410 3427 2002-06-27 Fernando Perez <fperez@colorado.edu>
3411 3428
3412 3429 * IPython/ipmaker.py (make_IPython): fixed bug when running user
3413 3430 defined files at the cmd line. __name__ wasn't being set to
3414 3431 __main__.
3415 3432
3416 3433 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
3417 3434 regular lists and tuples besides Numeric arrays.
3418 3435
3419 3436 * IPython/Prompts.py (CachedOutput.__call__): Added output
3420 3437 supression for input ending with ';'. Similar to Mathematica and
3421 3438 Matlab. The _* vars and Out[] list are still updated, just like
3422 3439 Mathematica behaves.
3423 3440
3424 3441 2002-06-25 Fernando Perez <fperez@colorado.edu>
3425 3442
3426 3443 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
3427 3444 .ini extensions for profiels under Windows.
3428 3445
3429 3446 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
3430 3447 string form. Fix contributed by Alexander Schmolck
3431 3448 <a.schmolck-AT-gmx.net>
3432 3449
3433 3450 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
3434 3451 pre-configured Gnuplot instance.
3435 3452
3436 3453 2002-06-21 Fernando Perez <fperez@colorado.edu>
3437 3454
3438 3455 * IPython/numutils.py (exp_safe): new function, works around the
3439 3456 underflow problems in Numeric.
3440 3457 (log2): New fn. Safe log in base 2: returns exact integer answer
3441 3458 for exact integer powers of 2.
3442 3459
3443 3460 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
3444 3461 properly.
3445 3462
3446 3463 2002-06-20 Fernando Perez <fperez@colorado.edu>
3447 3464
3448 3465 * IPython/genutils.py (timing): new function like
3449 3466 Mathematica's. Similar to time_test, but returns more info.
3450 3467
3451 3468 2002-06-18 Fernando Perez <fperez@colorado.edu>
3452 3469
3453 3470 * IPython/Magic.py (Magic.magic_save): modified @save and @r
3454 3471 according to Mike Heeter's suggestions.
3455 3472
3456 3473 2002-06-16 Fernando Perez <fperez@colorado.edu>
3457 3474
3458 3475 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
3459 3476 system. GnuplotMagic is gone as a user-directory option. New files
3460 3477 make it easier to use all the gnuplot stuff both from external
3461 3478 programs as well as from IPython. Had to rewrite part of
3462 3479 hardcopy() b/c of a strange bug: often the ps files simply don't
3463 3480 get created, and require a repeat of the command (often several
3464 3481 times).
3465 3482
3466 3483 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
3467 3484 resolve output channel at call time, so that if sys.stderr has
3468 3485 been redirected by user this gets honored.
3469 3486
3470 3487 2002-06-13 Fernando Perez <fperez@colorado.edu>
3471 3488
3472 3489 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
3473 3490 IPShell. Kept a copy with the old names to avoid breaking people's
3474 3491 embedded code.
3475 3492
3476 3493 * IPython/ipython: simplified it to the bare minimum after
3477 3494 Holger's suggestions. Added info about how to use it in
3478 3495 PYTHONSTARTUP.
3479 3496
3480 3497 * IPython/Shell.py (IPythonShell): changed the options passing
3481 3498 from a string with funky %s replacements to a straight list. Maybe
3482 3499 a bit more typing, but it follows sys.argv conventions, so there's
3483 3500 less special-casing to remember.
3484 3501
3485 3502 2002-06-12 Fernando Perez <fperez@colorado.edu>
3486 3503
3487 3504 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
3488 3505 command. Thanks to a suggestion by Mike Heeter.
3489 3506 (Magic.magic_pfile): added behavior to look at filenames if given
3490 3507 arg is not a defined object.
3491 3508 (Magic.magic_save): New @save function to save code snippets. Also
3492 3509 a Mike Heeter idea.
3493 3510
3494 3511 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
3495 3512 plot() and replot(). Much more convenient now, especially for
3496 3513 interactive use.
3497 3514
3498 3515 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
3499 3516 filenames.
3500 3517
3501 3518 2002-06-02 Fernando Perez <fperez@colorado.edu>
3502 3519
3503 3520 * IPython/Struct.py (Struct.__init__): modified to admit
3504 3521 initialization via another struct.
3505 3522
3506 3523 * IPython/genutils.py (SystemExec.__init__): New stateful
3507 3524 interface to xsys and bq. Useful for writing system scripts.
3508 3525
3509 3526 2002-05-30 Fernando Perez <fperez@colorado.edu>
3510 3527
3511 3528 * MANIFEST.in: Changed docfile selection to exclude all the lyx
3512 3529 documents. This will make the user download smaller (it's getting
3513 3530 too big).
3514 3531
3515 3532 2002-05-29 Fernando Perez <fperez@colorado.edu>
3516 3533
3517 3534 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
3518 3535 fix problems with shelve and pickle. Seems to work, but I don't
3519 3536 know if corner cases break it. Thanks to Mike Heeter
3520 3537 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
3521 3538
3522 3539 2002-05-24 Fernando Perez <fperez@colorado.edu>
3523 3540
3524 3541 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
3525 3542 macros having broken.
3526 3543
3527 3544 2002-05-21 Fernando Perez <fperez@colorado.edu>
3528 3545
3529 3546 * IPython/Magic.py (Magic.magic_logstart): fixed recently
3530 3547 introduced logging bug: all history before logging started was
3531 3548 being written one character per line! This came from the redesign
3532 3549 of the input history as a special list which slices to strings,
3533 3550 not to lists.
3534 3551
3535 3552 2002-05-20 Fernando Perez <fperez@colorado.edu>
3536 3553
3537 3554 * IPython/Prompts.py (CachedOutput.__init__): made the color table
3538 3555 be an attribute of all classes in this module. The design of these
3539 3556 classes needs some serious overhauling.
3540 3557
3541 3558 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
3542 3559 which was ignoring '_' in option names.
3543 3560
3544 3561 * IPython/ultraTB.py (FormattedTB.__init__): Changed
3545 3562 'Verbose_novars' to 'Context' and made it the new default. It's a
3546 3563 bit more readable and also safer than verbose.
3547 3564
3548 3565 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
3549 3566 triple-quoted strings.
3550 3567
3551 3568 * IPython/OInspect.py (__all__): new module exposing the object
3552 3569 introspection facilities. Now the corresponding magics are dummy
3553 3570 wrappers around this. Having this module will make it much easier
3554 3571 to put these functions into our modified pdb.
3555 3572 This new object inspector system uses the new colorizing module,
3556 3573 so source code and other things are nicely syntax highlighted.
3557 3574
3558 3575 2002-05-18 Fernando Perez <fperez@colorado.edu>
3559 3576
3560 3577 * IPython/ColorANSI.py: Split the coloring tools into a separate
3561 3578 module so I can use them in other code easier (they were part of
3562 3579 ultraTB).
3563 3580
3564 3581 2002-05-17 Fernando Perez <fperez@colorado.edu>
3565 3582
3566 3583 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3567 3584 fixed it to set the global 'g' also to the called instance, as
3568 3585 long as 'g' was still a gnuplot instance (so it doesn't overwrite
3569 3586 user's 'g' variables).
3570 3587
3571 3588 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
3572 3589 global variables (aliases to _ih,_oh) so that users which expect
3573 3590 In[5] or Out[7] to work aren't unpleasantly surprised.
3574 3591 (InputList.__getslice__): new class to allow executing slices of
3575 3592 input history directly. Very simple class, complements the use of
3576 3593 macros.
3577 3594
3578 3595 2002-05-16 Fernando Perez <fperez@colorado.edu>
3579 3596
3580 3597 * setup.py (docdirbase): make doc directory be just doc/IPython
3581 3598 without version numbers, it will reduce clutter for users.
3582 3599
3583 3600 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
3584 3601 execfile call to prevent possible memory leak. See for details:
3585 3602 http://mail.python.org/pipermail/python-list/2002-February/088476.html
3586 3603
3587 3604 2002-05-15 Fernando Perez <fperez@colorado.edu>
3588 3605
3589 3606 * IPython/Magic.py (Magic.magic_psource): made the object
3590 3607 introspection names be more standard: pdoc, pdef, pfile and
3591 3608 psource. They all print/page their output, and it makes
3592 3609 remembering them easier. Kept old names for compatibility as
3593 3610 aliases.
3594 3611
3595 3612 2002-05-14 Fernando Perez <fperez@colorado.edu>
3596 3613
3597 3614 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
3598 3615 what the mouse problem was. The trick is to use gnuplot with temp
3599 3616 files and NOT with pipes (for data communication), because having
3600 3617 both pipes and the mouse on is bad news.
3601 3618
3602 3619 2002-05-13 Fernando Perez <fperez@colorado.edu>
3603 3620
3604 3621 * IPython/Magic.py (Magic._ofind): fixed namespace order search
3605 3622 bug. Information would be reported about builtins even when
3606 3623 user-defined functions overrode them.
3607 3624
3608 3625 2002-05-11 Fernando Perez <fperez@colorado.edu>
3609 3626
3610 3627 * IPython/__init__.py (__all__): removed FlexCompleter from
3611 3628 __all__ so that things don't fail in platforms without readline.
3612 3629
3613 3630 2002-05-10 Fernando Perez <fperez@colorado.edu>
3614 3631
3615 3632 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
3616 3633 it requires Numeric, effectively making Numeric a dependency for
3617 3634 IPython.
3618 3635
3619 3636 * Released 0.2.13
3620 3637
3621 3638 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
3622 3639 profiler interface. Now all the major options from the profiler
3623 3640 module are directly supported in IPython, both for single
3624 3641 expressions (@prun) and for full programs (@run -p).
3625 3642
3626 3643 2002-05-09 Fernando Perez <fperez@colorado.edu>
3627 3644
3628 3645 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
3629 3646 magic properly formatted for screen.
3630 3647
3631 3648 * setup.py (make_shortcut): Changed things to put pdf version in
3632 3649 doc/ instead of doc/manual (had to change lyxport a bit).
3633 3650
3634 3651 * IPython/Magic.py (Profile.string_stats): made profile runs go
3635 3652 through pager (they are long and a pager allows searching, saving,
3636 3653 etc.)
3637 3654
3638 3655 2002-05-08 Fernando Perez <fperez@colorado.edu>
3639 3656
3640 3657 * Released 0.2.12
3641 3658
3642 3659 2002-05-06 Fernando Perez <fperez@colorado.edu>
3643 3660
3644 3661 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
3645 3662 introduced); 'hist n1 n2' was broken.
3646 3663 (Magic.magic_pdb): added optional on/off arguments to @pdb
3647 3664 (Magic.magic_run): added option -i to @run, which executes code in
3648 3665 the IPython namespace instead of a clean one. Also added @irun as
3649 3666 an alias to @run -i.
3650 3667
3651 3668 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3652 3669 fixed (it didn't really do anything, the namespaces were wrong).
3653 3670
3654 3671 * IPython/Debugger.py (__init__): Added workaround for python 2.1
3655 3672
3656 3673 * IPython/__init__.py (__all__): Fixed package namespace, now
3657 3674 'import IPython' does give access to IPython.<all> as
3658 3675 expected. Also renamed __release__ to Release.
3659 3676
3660 3677 * IPython/Debugger.py (__license__): created new Pdb class which
3661 3678 functions like a drop-in for the normal pdb.Pdb but does NOT
3662 3679 import readline by default. This way it doesn't muck up IPython's
3663 3680 readline handling, and now tab-completion finally works in the
3664 3681 debugger -- sort of. It completes things globally visible, but the
3665 3682 completer doesn't track the stack as pdb walks it. That's a bit
3666 3683 tricky, and I'll have to implement it later.
3667 3684
3668 3685 2002-05-05 Fernando Perez <fperez@colorado.edu>
3669 3686
3670 3687 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
3671 3688 magic docstrings when printed via ? (explicit \'s were being
3672 3689 printed).
3673 3690
3674 3691 * IPython/ipmaker.py (make_IPython): fixed namespace
3675 3692 identification bug. Now variables loaded via logs or command-line
3676 3693 files are recognized in the interactive namespace by @who.
3677 3694
3678 3695 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
3679 3696 log replay system stemming from the string form of Structs.
3680 3697
3681 3698 * IPython/Magic.py (Macro.__init__): improved macros to properly
3682 3699 handle magic commands in them.
3683 3700 (Magic.magic_logstart): usernames are now expanded so 'logstart
3684 3701 ~/mylog' now works.
3685 3702
3686 3703 * IPython/iplib.py (complete): fixed bug where paths starting with
3687 3704 '/' would be completed as magic names.
3688 3705
3689 3706 2002-05-04 Fernando Perez <fperez@colorado.edu>
3690 3707
3691 3708 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
3692 3709 allow running full programs under the profiler's control.
3693 3710
3694 3711 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
3695 3712 mode to report exceptions verbosely but without formatting
3696 3713 variables. This addresses the issue of ipython 'freezing' (it's
3697 3714 not frozen, but caught in an expensive formatting loop) when huge
3698 3715 variables are in the context of an exception.
3699 3716 (VerboseTB.text): Added '--->' markers at line where exception was
3700 3717 triggered. Much clearer to read, especially in NoColor modes.
3701 3718
3702 3719 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
3703 3720 implemented in reverse when changing to the new parse_options().
3704 3721
3705 3722 2002-05-03 Fernando Perez <fperez@colorado.edu>
3706 3723
3707 3724 * IPython/Magic.py (Magic.parse_options): new function so that
3708 3725 magics can parse options easier.
3709 3726 (Magic.magic_prun): new function similar to profile.run(),
3710 3727 suggested by Chris Hart.
3711 3728 (Magic.magic_cd): fixed behavior so that it only changes if
3712 3729 directory actually is in history.
3713 3730
3714 3731 * IPython/usage.py (__doc__): added information about potential
3715 3732 slowness of Verbose exception mode when there are huge data
3716 3733 structures to be formatted (thanks to Archie Paulson).
3717 3734
3718 3735 * IPython/ipmaker.py (make_IPython): Changed default logging
3719 3736 (when simply called with -log) to use curr_dir/ipython.log in
3720 3737 rotate mode. Fixed crash which was occuring with -log before
3721 3738 (thanks to Jim Boyle).
3722 3739
3723 3740 2002-05-01 Fernando Perez <fperez@colorado.edu>
3724 3741
3725 3742 * Released 0.2.11 for these fixes (mainly the ultraTB one which
3726 3743 was nasty -- though somewhat of a corner case).
3727 3744
3728 3745 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
3729 3746 text (was a bug).
3730 3747
3731 3748 2002-04-30 Fernando Perez <fperez@colorado.edu>
3732 3749
3733 3750 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
3734 3751 a print after ^D or ^C from the user so that the In[] prompt
3735 3752 doesn't over-run the gnuplot one.
3736 3753
3737 3754 2002-04-29 Fernando Perez <fperez@colorado.edu>
3738 3755
3739 3756 * Released 0.2.10
3740 3757
3741 3758 * IPython/__release__.py (version): get date dynamically.
3742 3759
3743 3760 * Misc. documentation updates thanks to Arnd's comments. Also ran
3744 3761 a full spellcheck on the manual (hadn't been done in a while).
3745 3762
3746 3763 2002-04-27 Fernando Perez <fperez@colorado.edu>
3747 3764
3748 3765 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
3749 3766 starting a log in mid-session would reset the input history list.
3750 3767
3751 3768 2002-04-26 Fernando Perez <fperez@colorado.edu>
3752 3769
3753 3770 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
3754 3771 all files were being included in an update. Now anything in
3755 3772 UserConfig that matches [A-Za-z]*.py will go (this excludes
3756 3773 __init__.py)
3757 3774
3758 3775 2002-04-25 Fernando Perez <fperez@colorado.edu>
3759 3776
3760 3777 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
3761 3778 to __builtins__ so that any form of embedded or imported code can
3762 3779 test for being inside IPython.
3763 3780
3764 3781 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3765 3782 changed to GnuplotMagic because it's now an importable module,
3766 3783 this makes the name follow that of the standard Gnuplot module.
3767 3784 GnuplotMagic can now be loaded at any time in mid-session.
3768 3785
3769 3786 2002-04-24 Fernando Perez <fperez@colorado.edu>
3770 3787
3771 3788 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3772 3789 the globals (IPython has its own namespace) and the
3773 3790 PhysicalQuantity stuff is much better anyway.
3774 3791
3775 3792 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3776 3793 embedding example to standard user directory for
3777 3794 distribution. Also put it in the manual.
3778 3795
3779 3796 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3780 3797 instance as first argument (so it doesn't rely on some obscure
3781 3798 hidden global).
3782 3799
3783 3800 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3784 3801 delimiters. While it prevents ().TAB from working, it allows
3785 3802 completions in open (... expressions. This is by far a more common
3786 3803 case.
3787 3804
3788 3805 2002-04-23 Fernando Perez <fperez@colorado.edu>
3789 3806
3790 3807 * IPython/Extensions/InterpreterPasteInput.py: new
3791 3808 syntax-processing module for pasting lines with >>> or ... at the
3792 3809 start.
3793 3810
3794 3811 * IPython/Extensions/PhysicalQ_Interactive.py
3795 3812 (PhysicalQuantityInteractive.__int__): fixed to work with either
3796 3813 Numeric or math.
3797 3814
3798 3815 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3799 3816 provided profiles. Now we have:
3800 3817 -math -> math module as * and cmath with its own namespace.
3801 3818 -numeric -> Numeric as *, plus gnuplot & grace
3802 3819 -physics -> same as before
3803 3820
3804 3821 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3805 3822 user-defined magics wouldn't be found by @magic if they were
3806 3823 defined as class methods. Also cleaned up the namespace search
3807 3824 logic and the string building (to use %s instead of many repeated
3808 3825 string adds).
3809 3826
3810 3827 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3811 3828 of user-defined magics to operate with class methods (cleaner, in
3812 3829 line with the gnuplot code).
3813 3830
3814 3831 2002-04-22 Fernando Perez <fperez@colorado.edu>
3815 3832
3816 3833 * setup.py: updated dependency list so that manual is updated when
3817 3834 all included files change.
3818 3835
3819 3836 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3820 3837 the delimiter removal option (the fix is ugly right now).
3821 3838
3822 3839 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3823 3840 all of the math profile (quicker loading, no conflict between
3824 3841 g-9.8 and g-gnuplot).
3825 3842
3826 3843 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3827 3844 name of post-mortem files to IPython_crash_report.txt.
3828 3845
3829 3846 * Cleanup/update of the docs. Added all the new readline info and
3830 3847 formatted all lists as 'real lists'.
3831 3848
3832 3849 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3833 3850 tab-completion options, since the full readline parse_and_bind is
3834 3851 now accessible.
3835 3852
3836 3853 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3837 3854 handling of readline options. Now users can specify any string to
3838 3855 be passed to parse_and_bind(), as well as the delimiters to be
3839 3856 removed.
3840 3857 (InteractiveShell.__init__): Added __name__ to the global
3841 3858 namespace so that things like Itpl which rely on its existence
3842 3859 don't crash.
3843 3860 (InteractiveShell._prefilter): Defined the default with a _ so
3844 3861 that prefilter() is easier to override, while the default one
3845 3862 remains available.
3846 3863
3847 3864 2002-04-18 Fernando Perez <fperez@colorado.edu>
3848 3865
3849 3866 * Added information about pdb in the docs.
3850 3867
3851 3868 2002-04-17 Fernando Perez <fperez@colorado.edu>
3852 3869
3853 3870 * IPython/ipmaker.py (make_IPython): added rc_override option to
3854 3871 allow passing config options at creation time which may override
3855 3872 anything set in the config files or command line. This is
3856 3873 particularly useful for configuring embedded instances.
3857 3874
3858 3875 2002-04-15 Fernando Perez <fperez@colorado.edu>
3859 3876
3860 3877 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3861 3878 crash embedded instances because of the input cache falling out of
3862 3879 sync with the output counter.
3863 3880
3864 3881 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3865 3882 mode which calls pdb after an uncaught exception in IPython itself.
3866 3883
3867 3884 2002-04-14 Fernando Perez <fperez@colorado.edu>
3868 3885
3869 3886 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3870 3887 readline, fix it back after each call.
3871 3888
3872 3889 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3873 3890 method to force all access via __call__(), which guarantees that
3874 3891 traceback references are properly deleted.
3875 3892
3876 3893 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3877 3894 improve printing when pprint is in use.
3878 3895
3879 3896 2002-04-13 Fernando Perez <fperez@colorado.edu>
3880 3897
3881 3898 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3882 3899 exceptions aren't caught anymore. If the user triggers one, he
3883 3900 should know why he's doing it and it should go all the way up,
3884 3901 just like any other exception. So now @abort will fully kill the
3885 3902 embedded interpreter and the embedding code (unless that happens
3886 3903 to catch SystemExit).
3887 3904
3888 3905 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3889 3906 and a debugger() method to invoke the interactive pdb debugger
3890 3907 after printing exception information. Also added the corresponding
3891 3908 -pdb option and @pdb magic to control this feature, and updated
3892 3909 the docs. After a suggestion from Christopher Hart
3893 3910 (hart-AT-caltech.edu).
3894 3911
3895 3912 2002-04-12 Fernando Perez <fperez@colorado.edu>
3896 3913
3897 3914 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3898 3915 the exception handlers defined by the user (not the CrashHandler)
3899 3916 so that user exceptions don't trigger an ipython bug report.
3900 3917
3901 3918 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3902 3919 configurable (it should have always been so).
3903 3920
3904 3921 2002-03-26 Fernando Perez <fperez@colorado.edu>
3905 3922
3906 3923 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3907 3924 and there to fix embedding namespace issues. This should all be
3908 3925 done in a more elegant way.
3909 3926
3910 3927 2002-03-25 Fernando Perez <fperez@colorado.edu>
3911 3928
3912 3929 * IPython/genutils.py (get_home_dir): Try to make it work under
3913 3930 win9x also.
3914 3931
3915 3932 2002-03-20 Fernando Perez <fperez@colorado.edu>
3916 3933
3917 3934 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3918 3935 sys.displayhook untouched upon __init__.
3919 3936
3920 3937 2002-03-19 Fernando Perez <fperez@colorado.edu>
3921 3938
3922 3939 * Released 0.2.9 (for embedding bug, basically).
3923 3940
3924 3941 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3925 3942 exceptions so that enclosing shell's state can be restored.
3926 3943
3927 3944 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3928 3945 naming conventions in the .ipython/ dir.
3929 3946
3930 3947 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3931 3948 from delimiters list so filenames with - in them get expanded.
3932 3949
3933 3950 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3934 3951 sys.displayhook not being properly restored after an embedded call.
3935 3952
3936 3953 2002-03-18 Fernando Perez <fperez@colorado.edu>
3937 3954
3938 3955 * Released 0.2.8
3939 3956
3940 3957 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3941 3958 some files weren't being included in a -upgrade.
3942 3959 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3943 3960 on' so that the first tab completes.
3944 3961 (InteractiveShell.handle_magic): fixed bug with spaces around
3945 3962 quotes breaking many magic commands.
3946 3963
3947 3964 * setup.py: added note about ignoring the syntax error messages at
3948 3965 installation.
3949 3966
3950 3967 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3951 3968 streamlining the gnuplot interface, now there's only one magic @gp.
3952 3969
3953 3970 2002-03-17 Fernando Perez <fperez@colorado.edu>
3954 3971
3955 3972 * IPython/UserConfig/magic_gnuplot.py: new name for the
3956 3973 example-magic_pm.py file. Much enhanced system, now with a shell
3957 3974 for communicating directly with gnuplot, one command at a time.
3958 3975
3959 3976 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3960 3977 setting __name__=='__main__'.
3961 3978
3962 3979 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3963 3980 mini-shell for accessing gnuplot from inside ipython. Should
3964 3981 extend it later for grace access too. Inspired by Arnd's
3965 3982 suggestion.
3966 3983
3967 3984 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3968 3985 calling magic functions with () in their arguments. Thanks to Arnd
3969 3986 Baecker for pointing this to me.
3970 3987
3971 3988 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3972 3989 infinitely for integer or complex arrays (only worked with floats).
3973 3990
3974 3991 2002-03-16 Fernando Perez <fperez@colorado.edu>
3975 3992
3976 3993 * setup.py: Merged setup and setup_windows into a single script
3977 3994 which properly handles things for windows users.
3978 3995
3979 3996 2002-03-15 Fernando Perez <fperez@colorado.edu>
3980 3997
3981 3998 * Big change to the manual: now the magics are all automatically
3982 3999 documented. This information is generated from their docstrings
3983 4000 and put in a latex file included by the manual lyx file. This way
3984 4001 we get always up to date information for the magics. The manual
3985 4002 now also has proper version information, also auto-synced.
3986 4003
3987 4004 For this to work, an undocumented --magic_docstrings option was added.
3988 4005
3989 4006 2002-03-13 Fernando Perez <fperez@colorado.edu>
3990 4007
3991 4008 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3992 4009 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3993 4010
3994 4011 2002-03-12 Fernando Perez <fperez@colorado.edu>
3995 4012
3996 4013 * IPython/ultraTB.py (TermColors): changed color escapes again to
3997 4014 fix the (old, reintroduced) line-wrapping bug. Basically, if
3998 4015 \001..\002 aren't given in the color escapes, lines get wrapped
3999 4016 weirdly. But giving those screws up old xterms and emacs terms. So
4000 4017 I added some logic for emacs terms to be ok, but I can't identify old
4001 4018 xterms separately ($TERM=='xterm' for many terminals, like konsole).
4002 4019
4003 4020 2002-03-10 Fernando Perez <fperez@colorado.edu>
4004 4021
4005 4022 * IPython/usage.py (__doc__): Various documentation cleanups and
4006 4023 updates, both in usage docstrings and in the manual.
4007 4024
4008 4025 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
4009 4026 handling of caching. Set minimum acceptabe value for having a
4010 4027 cache at 20 values.
4011 4028
4012 4029 * IPython/iplib.py (InteractiveShell.user_setup): moved the
4013 4030 install_first_time function to a method, renamed it and added an
4014 4031 'upgrade' mode. Now people can update their config directory with
4015 4032 a simple command line switch (-upgrade, also new).
4016 4033
4017 4034 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
4018 4035 @file (convenient for automagic users under Python >= 2.2).
4019 4036 Removed @files (it seemed more like a plural than an abbrev. of
4020 4037 'file show').
4021 4038
4022 4039 * IPython/iplib.py (install_first_time): Fixed crash if there were
4023 4040 backup files ('~') in .ipython/ install directory.
4024 4041
4025 4042 * IPython/ipmaker.py (make_IPython): fixes for new prompt
4026 4043 system. Things look fine, but these changes are fairly
4027 4044 intrusive. Test them for a few days.
4028 4045
4029 4046 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
4030 4047 the prompts system. Now all in/out prompt strings are user
4031 4048 controllable. This is particularly useful for embedding, as one
4032 4049 can tag embedded instances with particular prompts.
4033 4050
4034 4051 Also removed global use of sys.ps1/2, which now allows nested
4035 4052 embeddings without any problems. Added command-line options for
4036 4053 the prompt strings.
4037 4054
4038 4055 2002-03-08 Fernando Perez <fperez@colorado.edu>
4039 4056
4040 4057 * IPython/UserConfig/example-embed-short.py (ipshell): added
4041 4058 example file with the bare minimum code for embedding.
4042 4059
4043 4060 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
4044 4061 functionality for the embeddable shell to be activated/deactivated
4045 4062 either globally or at each call.
4046 4063
4047 4064 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
4048 4065 rewriting the prompt with '--->' for auto-inputs with proper
4049 4066 coloring. Now the previous UGLY hack in handle_auto() is gone, and
4050 4067 this is handled by the prompts class itself, as it should.
4051 4068
4052 4069 2002-03-05 Fernando Perez <fperez@colorado.edu>
4053 4070
4054 4071 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
4055 4072 @logstart to avoid name clashes with the math log function.
4056 4073
4057 4074 * Big updates to X/Emacs section of the manual.
4058 4075
4059 4076 * Removed ipython_emacs. Milan explained to me how to pass
4060 4077 arguments to ipython through Emacs. Some day I'm going to end up
4061 4078 learning some lisp...
4062 4079
4063 4080 2002-03-04 Fernando Perez <fperez@colorado.edu>
4064 4081
4065 4082 * IPython/ipython_emacs: Created script to be used as the
4066 4083 py-python-command Emacs variable so we can pass IPython
4067 4084 parameters. I can't figure out how to tell Emacs directly to pass
4068 4085 parameters to IPython, so a dummy shell script will do it.
4069 4086
4070 4087 Other enhancements made for things to work better under Emacs'
4071 4088 various types of terminals. Many thanks to Milan Zamazal
4072 4089 <pdm-AT-zamazal.org> for all the suggestions and pointers.
4073 4090
4074 4091 2002-03-01 Fernando Perez <fperez@colorado.edu>
4075 4092
4076 4093 * IPython/ipmaker.py (make_IPython): added a --readline! option so
4077 4094 that loading of readline is now optional. This gives better
4078 4095 control to emacs users.
4079 4096
4080 4097 * IPython/ultraTB.py (__date__): Modified color escape sequences
4081 4098 and now things work fine under xterm and in Emacs' term buffers
4082 4099 (though not shell ones). Well, in emacs you get colors, but all
4083 4100 seem to be 'light' colors (no difference between dark and light
4084 4101 ones). But the garbage chars are gone, and also in xterms. It
4085 4102 seems that now I'm using 'cleaner' ansi sequences.
4086 4103
4087 4104 2002-02-21 Fernando Perez <fperez@colorado.edu>
4088 4105
4089 4106 * Released 0.2.7 (mainly to publish the scoping fix).
4090 4107
4091 4108 * IPython/Logger.py (Logger.logstate): added. A corresponding
4092 4109 @logstate magic was created.
4093 4110
4094 4111 * IPython/Magic.py: fixed nested scoping problem under Python
4095 4112 2.1.x (automagic wasn't working).
4096 4113
4097 4114 2002-02-20 Fernando Perez <fperez@colorado.edu>
4098 4115
4099 4116 * Released 0.2.6.
4100 4117
4101 4118 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
4102 4119 option so that logs can come out without any headers at all.
4103 4120
4104 4121 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
4105 4122 SciPy.
4106 4123
4107 4124 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
4108 4125 that embedded IPython calls don't require vars() to be explicitly
4109 4126 passed. Now they are extracted from the caller's frame (code
4110 4127 snatched from Eric Jones' weave). Added better documentation to
4111 4128 the section on embedding and the example file.
4112 4129
4113 4130 * IPython/genutils.py (page): Changed so that under emacs, it just
4114 4131 prints the string. You can then page up and down in the emacs
4115 4132 buffer itself. This is how the builtin help() works.
4116 4133
4117 4134 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
4118 4135 macro scoping: macros need to be executed in the user's namespace
4119 4136 to work as if they had been typed by the user.
4120 4137
4121 4138 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
4122 4139 execute automatically (no need to type 'exec...'). They then
4123 4140 behave like 'true macros'. The printing system was also modified
4124 4141 for this to work.
4125 4142
4126 4143 2002-02-19 Fernando Perez <fperez@colorado.edu>
4127 4144
4128 4145 * IPython/genutils.py (page_file): new function for paging files
4129 4146 in an OS-independent way. Also necessary for file viewing to work
4130 4147 well inside Emacs buffers.
4131 4148 (page): Added checks for being in an emacs buffer.
4132 4149 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
4133 4150 same bug in iplib.
4134 4151
4135 4152 2002-02-18 Fernando Perez <fperez@colorado.edu>
4136 4153
4137 4154 * IPython/iplib.py (InteractiveShell.init_readline): modified use
4138 4155 of readline so that IPython can work inside an Emacs buffer.
4139 4156
4140 4157 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
4141 4158 method signatures (they weren't really bugs, but it looks cleaner
4142 4159 and keeps PyChecker happy).
4143 4160
4144 4161 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
4145 4162 for implementing various user-defined hooks. Currently only
4146 4163 display is done.
4147 4164
4148 4165 * IPython/Prompts.py (CachedOutput._display): changed display
4149 4166 functions so that they can be dynamically changed by users easily.
4150 4167
4151 4168 * IPython/Extensions/numeric_formats.py (num_display): added an
4152 4169 extension for printing NumPy arrays in flexible manners. It
4153 4170 doesn't do anything yet, but all the structure is in
4154 4171 place. Ultimately the plan is to implement output format control
4155 4172 like in Octave.
4156 4173
4157 4174 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
4158 4175 methods are found at run-time by all the automatic machinery.
4159 4176
4160 4177 2002-02-17 Fernando Perez <fperez@colorado.edu>
4161 4178
4162 4179 * setup_Windows.py (make_shortcut): documented. Cleaned up the
4163 4180 whole file a little.
4164 4181
4165 4182 * ToDo: closed this document. Now there's a new_design.lyx
4166 4183 document for all new ideas. Added making a pdf of it for the
4167 4184 end-user distro.
4168 4185
4169 4186 * IPython/Logger.py (Logger.switch_log): Created this to replace
4170 4187 logon() and logoff(). It also fixes a nasty crash reported by
4171 4188 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
4172 4189
4173 4190 * IPython/iplib.py (complete): got auto-completion to work with
4174 4191 automagic (I had wanted this for a long time).
4175 4192
4176 4193 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
4177 4194 to @file, since file() is now a builtin and clashes with automagic
4178 4195 for @file.
4179 4196
4180 4197 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
4181 4198 of this was previously in iplib, which had grown to more than 2000
4182 4199 lines, way too long. No new functionality, but it makes managing
4183 4200 the code a bit easier.
4184 4201
4185 4202 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
4186 4203 information to crash reports.
4187 4204
4188 4205 2002-02-12 Fernando Perez <fperez@colorado.edu>
4189 4206
4190 4207 * Released 0.2.5.
4191 4208
4192 4209 2002-02-11 Fernando Perez <fperez@colorado.edu>
4193 4210
4194 4211 * Wrote a relatively complete Windows installer. It puts
4195 4212 everything in place, creates Start Menu entries and fixes the
4196 4213 color issues. Nothing fancy, but it works.
4197 4214
4198 4215 2002-02-10 Fernando Perez <fperez@colorado.edu>
4199 4216
4200 4217 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
4201 4218 os.path.expanduser() call so that we can type @run ~/myfile.py and
4202 4219 have thigs work as expected.
4203 4220
4204 4221 * IPython/genutils.py (page): fixed exception handling so things
4205 4222 work both in Unix and Windows correctly. Quitting a pager triggers
4206 4223 an IOError/broken pipe in Unix, and in windows not finding a pager
4207 4224 is also an IOError, so I had to actually look at the return value
4208 4225 of the exception, not just the exception itself. Should be ok now.
4209 4226
4210 4227 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
4211 4228 modified to allow case-insensitive color scheme changes.
4212 4229
4213 4230 2002-02-09 Fernando Perez <fperez@colorado.edu>
4214 4231
4215 4232 * IPython/genutils.py (native_line_ends): new function to leave
4216 4233 user config files with os-native line-endings.
4217 4234
4218 4235 * README and manual updates.
4219 4236
4220 4237 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
4221 4238 instead of StringType to catch Unicode strings.
4222 4239
4223 4240 * IPython/genutils.py (filefind): fixed bug for paths with
4224 4241 embedded spaces (very common in Windows).
4225 4242
4226 4243 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
4227 4244 files under Windows, so that they get automatically associated
4228 4245 with a text editor. Windows makes it a pain to handle
4229 4246 extension-less files.
4230 4247
4231 4248 * IPython/iplib.py (InteractiveShell.init_readline): Made the
4232 4249 warning about readline only occur for Posix. In Windows there's no
4233 4250 way to get readline, so why bother with the warning.
4234 4251
4235 4252 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
4236 4253 for __str__ instead of dir(self), since dir() changed in 2.2.
4237 4254
4238 4255 * Ported to Windows! Tested on XP, I suspect it should work fine
4239 4256 on NT/2000, but I don't think it will work on 98 et al. That
4240 4257 series of Windows is such a piece of junk anyway that I won't try
4241 4258 porting it there. The XP port was straightforward, showed a few
4242 4259 bugs here and there (fixed all), in particular some string
4243 4260 handling stuff which required considering Unicode strings (which
4244 4261 Windows uses). This is good, but hasn't been too tested :) No
4245 4262 fancy installer yet, I'll put a note in the manual so people at
4246 4263 least make manually a shortcut.
4247 4264
4248 4265 * IPython/iplib.py (Magic.magic_colors): Unified the color options
4249 4266 into a single one, "colors". This now controls both prompt and
4250 4267 exception color schemes, and can be changed both at startup
4251 4268 (either via command-line switches or via ipythonrc files) and at
4252 4269 runtime, with @colors.
4253 4270 (Magic.magic_run): renamed @prun to @run and removed the old
4254 4271 @run. The two were too similar to warrant keeping both.
4255 4272
4256 4273 2002-02-03 Fernando Perez <fperez@colorado.edu>
4257 4274
4258 4275 * IPython/iplib.py (install_first_time): Added comment on how to
4259 4276 configure the color options for first-time users. Put a <return>
4260 4277 request at the end so that small-terminal users get a chance to
4261 4278 read the startup info.
4262 4279
4263 4280 2002-01-23 Fernando Perez <fperez@colorado.edu>
4264 4281
4265 4282 * IPython/iplib.py (CachedOutput.update): Changed output memory
4266 4283 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
4267 4284 input history we still use _i. Did this b/c these variable are
4268 4285 very commonly used in interactive work, so the less we need to
4269 4286 type the better off we are.
4270 4287 (Magic.magic_prun): updated @prun to better handle the namespaces
4271 4288 the file will run in, including a fix for __name__ not being set
4272 4289 before.
4273 4290
4274 4291 2002-01-20 Fernando Perez <fperez@colorado.edu>
4275 4292
4276 4293 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
4277 4294 extra garbage for Python 2.2. Need to look more carefully into
4278 4295 this later.
4279 4296
4280 4297 2002-01-19 Fernando Perez <fperez@colorado.edu>
4281 4298
4282 4299 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
4283 4300 display SyntaxError exceptions properly formatted when they occur
4284 4301 (they can be triggered by imported code).
4285 4302
4286 4303 2002-01-18 Fernando Perez <fperez@colorado.edu>
4287 4304
4288 4305 * IPython/iplib.py (InteractiveShell.safe_execfile): now
4289 4306 SyntaxError exceptions are reported nicely formatted, instead of
4290 4307 spitting out only offset information as before.
4291 4308 (Magic.magic_prun): Added the @prun function for executing
4292 4309 programs with command line args inside IPython.
4293 4310
4294 4311 2002-01-16 Fernando Perez <fperez@colorado.edu>
4295 4312
4296 4313 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
4297 4314 to *not* include the last item given in a range. This brings their
4298 4315 behavior in line with Python's slicing:
4299 4316 a[n1:n2] -> a[n1]...a[n2-1]
4300 4317 It may be a bit less convenient, but I prefer to stick to Python's
4301 4318 conventions *everywhere*, so users never have to wonder.
4302 4319 (Magic.magic_macro): Added @macro function to ease the creation of
4303 4320 macros.
4304 4321
4305 4322 2002-01-05 Fernando Perez <fperez@colorado.edu>
4306 4323
4307 4324 * Released 0.2.4.
4308 4325
4309 4326 * IPython/iplib.py (Magic.magic_pdef):
4310 4327 (InteractiveShell.safe_execfile): report magic lines and error
4311 4328 lines without line numbers so one can easily copy/paste them for
4312 4329 re-execution.
4313 4330
4314 4331 * Updated manual with recent changes.
4315 4332
4316 4333 * IPython/iplib.py (Magic.magic_oinfo): added constructor
4317 4334 docstring printing when class? is called. Very handy for knowing
4318 4335 how to create class instances (as long as __init__ is well
4319 4336 documented, of course :)
4320 4337 (Magic.magic_doc): print both class and constructor docstrings.
4321 4338 (Magic.magic_pdef): give constructor info if passed a class and
4322 4339 __call__ info for callable object instances.
4323 4340
4324 4341 2002-01-04 Fernando Perez <fperez@colorado.edu>
4325 4342
4326 4343 * Made deep_reload() off by default. It doesn't always work
4327 4344 exactly as intended, so it's probably safer to have it off. It's
4328 4345 still available as dreload() anyway, so nothing is lost.
4329 4346
4330 4347 2002-01-02 Fernando Perez <fperez@colorado.edu>
4331 4348
4332 4349 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
4333 4350 so I wanted an updated release).
4334 4351
4335 4352 2001-12-27 Fernando Perez <fperez@colorado.edu>
4336 4353
4337 4354 * IPython/iplib.py (InteractiveShell.interact): Added the original
4338 4355 code from 'code.py' for this module in order to change the
4339 4356 handling of a KeyboardInterrupt. This was necessary b/c otherwise
4340 4357 the history cache would break when the user hit Ctrl-C, and
4341 4358 interact() offers no way to add any hooks to it.
4342 4359
4343 4360 2001-12-23 Fernando Perez <fperez@colorado.edu>
4344 4361
4345 4362 * setup.py: added check for 'MANIFEST' before trying to remove
4346 4363 it. Thanks to Sean Reifschneider.
4347 4364
4348 4365 2001-12-22 Fernando Perez <fperez@colorado.edu>
4349 4366
4350 4367 * Released 0.2.2.
4351 4368
4352 4369 * Finished (reasonably) writing the manual. Later will add the
4353 4370 python-standard navigation stylesheets, but for the time being
4354 4371 it's fairly complete. Distribution will include html and pdf
4355 4372 versions.
4356 4373
4357 4374 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
4358 4375 (MayaVi author).
4359 4376
4360 4377 2001-12-21 Fernando Perez <fperez@colorado.edu>
4361 4378
4362 4379 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
4363 4380 good public release, I think (with the manual and the distutils
4364 4381 installer). The manual can use some work, but that can go
4365 4382 slowly. Otherwise I think it's quite nice for end users. Next
4366 4383 summer, rewrite the guts of it...
4367 4384
4368 4385 * Changed format of ipythonrc files to use whitespace as the
4369 4386 separator instead of an explicit '='. Cleaner.
4370 4387
4371 4388 2001-12-20 Fernando Perez <fperez@colorado.edu>
4372 4389
4373 4390 * Started a manual in LyX. For now it's just a quick merge of the
4374 4391 various internal docstrings and READMEs. Later it may grow into a
4375 4392 nice, full-blown manual.
4376 4393
4377 4394 * Set up a distutils based installer. Installation should now be
4378 4395 trivially simple for end-users.
4379 4396
4380 4397 2001-12-11 Fernando Perez <fperez@colorado.edu>
4381 4398
4382 4399 * Released 0.2.0. First public release, announced it at
4383 4400 comp.lang.python. From now on, just bugfixes...
4384 4401
4385 4402 * Went through all the files, set copyright/license notices and
4386 4403 cleaned up things. Ready for release.
4387 4404
4388 4405 2001-12-10 Fernando Perez <fperez@colorado.edu>
4389 4406
4390 4407 * Changed the first-time installer not to use tarfiles. It's more
4391 4408 robust now and less unix-dependent. Also makes it easier for
4392 4409 people to later upgrade versions.
4393 4410
4394 4411 * Changed @exit to @abort to reflect the fact that it's pretty
4395 4412 brutal (a sys.exit()). The difference between @abort and Ctrl-D
4396 4413 becomes significant only when IPyhton is embedded: in that case,
4397 4414 C-D closes IPython only, but @abort kills the enclosing program
4398 4415 too (unless it had called IPython inside a try catching
4399 4416 SystemExit).
4400 4417
4401 4418 * Created Shell module which exposes the actuall IPython Shell
4402 4419 classes, currently the normal and the embeddable one. This at
4403 4420 least offers a stable interface we won't need to change when
4404 4421 (later) the internals are rewritten. That rewrite will be confined
4405 4422 to iplib and ipmaker, but the Shell interface should remain as is.
4406 4423
4407 4424 * Added embed module which offers an embeddable IPShell object,
4408 4425 useful to fire up IPython *inside* a running program. Great for
4409 4426 debugging or dynamical data analysis.
4410 4427
4411 4428 2001-12-08 Fernando Perez <fperez@colorado.edu>
4412 4429
4413 4430 * Fixed small bug preventing seeing info from methods of defined
4414 4431 objects (incorrect namespace in _ofind()).
4415 4432
4416 4433 * Documentation cleanup. Moved the main usage docstrings to a
4417 4434 separate file, usage.py (cleaner to maintain, and hopefully in the
4418 4435 future some perlpod-like way of producing interactive, man and
4419 4436 html docs out of it will be found).
4420 4437
4421 4438 * Added @profile to see your profile at any time.
4422 4439
4423 4440 * Added @p as an alias for 'print'. It's especially convenient if
4424 4441 using automagic ('p x' prints x).
4425 4442
4426 4443 * Small cleanups and fixes after a pychecker run.
4427 4444
4428 4445 * Changed the @cd command to handle @cd - and @cd -<n> for
4429 4446 visiting any directory in _dh.
4430 4447
4431 4448 * Introduced _dh, a history of visited directories. @dhist prints
4432 4449 it out with numbers.
4433 4450
4434 4451 2001-12-07 Fernando Perez <fperez@colorado.edu>
4435 4452
4436 4453 * Released 0.1.22
4437 4454
4438 4455 * Made initialization a bit more robust against invalid color
4439 4456 options in user input (exit, not traceback-crash).
4440 4457
4441 4458 * Changed the bug crash reporter to write the report only in the
4442 4459 user's .ipython directory. That way IPython won't litter people's
4443 4460 hard disks with crash files all over the place. Also print on
4444 4461 screen the necessary mail command.
4445 4462
4446 4463 * With the new ultraTB, implemented LightBG color scheme for light
4447 4464 background terminals. A lot of people like white backgrounds, so I
4448 4465 guess we should at least give them something readable.
4449 4466
4450 4467 2001-12-06 Fernando Perez <fperez@colorado.edu>
4451 4468
4452 4469 * Modified the structure of ultraTB. Now there's a proper class
4453 4470 for tables of color schemes which allow adding schemes easily and
4454 4471 switching the active scheme without creating a new instance every
4455 4472 time (which was ridiculous). The syntax for creating new schemes
4456 4473 is also cleaner. I think ultraTB is finally done, with a clean
4457 4474 class structure. Names are also much cleaner (now there's proper
4458 4475 color tables, no need for every variable to also have 'color' in
4459 4476 its name).
4460 4477
4461 4478 * Broke down genutils into separate files. Now genutils only
4462 4479 contains utility functions, and classes have been moved to their
4463 4480 own files (they had enough independent functionality to warrant
4464 4481 it): ConfigLoader, OutputTrap, Struct.
4465 4482
4466 4483 2001-12-05 Fernando Perez <fperez@colorado.edu>
4467 4484
4468 4485 * IPython turns 21! Released version 0.1.21, as a candidate for
4469 4486 public consumption. If all goes well, release in a few days.
4470 4487
4471 4488 * Fixed path bug (files in Extensions/ directory wouldn't be found
4472 4489 unless IPython/ was explicitly in sys.path).
4473 4490
4474 4491 * Extended the FlexCompleter class as MagicCompleter to allow
4475 4492 completion of @-starting lines.
4476 4493
4477 4494 * Created __release__.py file as a central repository for release
4478 4495 info that other files can read from.
4479 4496
4480 4497 * Fixed small bug in logging: when logging was turned on in
4481 4498 mid-session, old lines with special meanings (!@?) were being
4482 4499 logged without the prepended comment, which is necessary since
4483 4500 they are not truly valid python syntax. This should make session
4484 4501 restores produce less errors.
4485 4502
4486 4503 * The namespace cleanup forced me to make a FlexCompleter class
4487 4504 which is nothing but a ripoff of rlcompleter, but with selectable
4488 4505 namespace (rlcompleter only works in __main__.__dict__). I'll try
4489 4506 to submit a note to the authors to see if this change can be
4490 4507 incorporated in future rlcompleter releases (Dec.6: done)
4491 4508
4492 4509 * More fixes to namespace handling. It was a mess! Now all
4493 4510 explicit references to __main__.__dict__ are gone (except when
4494 4511 really needed) and everything is handled through the namespace
4495 4512 dicts in the IPython instance. We seem to be getting somewhere
4496 4513 with this, finally...
4497 4514
4498 4515 * Small documentation updates.
4499 4516
4500 4517 * Created the Extensions directory under IPython (with an
4501 4518 __init__.py). Put the PhysicalQ stuff there. This directory should
4502 4519 be used for all special-purpose extensions.
4503 4520
4504 4521 * File renaming:
4505 4522 ipythonlib --> ipmaker
4506 4523 ipplib --> iplib
4507 4524 This makes a bit more sense in terms of what these files actually do.
4508 4525
4509 4526 * Moved all the classes and functions in ipythonlib to ipplib, so
4510 4527 now ipythonlib only has make_IPython(). This will ease up its
4511 4528 splitting in smaller functional chunks later.
4512 4529
4513 4530 * Cleaned up (done, I think) output of @whos. Better column
4514 4531 formatting, and now shows str(var) for as much as it can, which is
4515 4532 typically what one gets with a 'print var'.
4516 4533
4517 4534 2001-12-04 Fernando Perez <fperez@colorado.edu>
4518 4535
4519 4536 * Fixed namespace problems. Now builtin/IPyhton/user names get
4520 4537 properly reported in their namespace. Internal namespace handling
4521 4538 is finally getting decent (not perfect yet, but much better than
4522 4539 the ad-hoc mess we had).
4523 4540
4524 4541 * Removed -exit option. If people just want to run a python
4525 4542 script, that's what the normal interpreter is for. Less
4526 4543 unnecessary options, less chances for bugs.
4527 4544
4528 4545 * Added a crash handler which generates a complete post-mortem if
4529 4546 IPython crashes. This will help a lot in tracking bugs down the
4530 4547 road.
4531 4548
4532 4549 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
4533 4550 which were boud to functions being reassigned would bypass the
4534 4551 logger, breaking the sync of _il with the prompt counter. This
4535 4552 would then crash IPython later when a new line was logged.
4536 4553
4537 4554 2001-12-02 Fernando Perez <fperez@colorado.edu>
4538 4555
4539 4556 * Made IPython a package. This means people don't have to clutter
4540 4557 their sys.path with yet another directory. Changed the INSTALL
4541 4558 file accordingly.
4542 4559
4543 4560 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
4544 4561 sorts its output (so @who shows it sorted) and @whos formats the
4545 4562 table according to the width of the first column. Nicer, easier to
4546 4563 read. Todo: write a generic table_format() which takes a list of
4547 4564 lists and prints it nicely formatted, with optional row/column
4548 4565 separators and proper padding and justification.
4549 4566
4550 4567 * Released 0.1.20
4551 4568
4552 4569 * Fixed bug in @log which would reverse the inputcache list (a
4553 4570 copy operation was missing).
4554 4571
4555 4572 * Code cleanup. @config was changed to use page(). Better, since
4556 4573 its output is always quite long.
4557 4574
4558 4575 * Itpl is back as a dependency. I was having too many problems
4559 4576 getting the parametric aliases to work reliably, and it's just
4560 4577 easier to code weird string operations with it than playing %()s
4561 4578 games. It's only ~6k, so I don't think it's too big a deal.
4562 4579
4563 4580 * Found (and fixed) a very nasty bug with history. !lines weren't
4564 4581 getting cached, and the out of sync caches would crash
4565 4582 IPython. Fixed it by reorganizing the prefilter/handlers/logger
4566 4583 division of labor a bit better. Bug fixed, cleaner structure.
4567 4584
4568 4585 2001-12-01 Fernando Perez <fperez@colorado.edu>
4569 4586
4570 4587 * Released 0.1.19
4571 4588
4572 4589 * Added option -n to @hist to prevent line number printing. Much
4573 4590 easier to copy/paste code this way.
4574 4591
4575 4592 * Created global _il to hold the input list. Allows easy
4576 4593 re-execution of blocks of code by slicing it (inspired by Janko's
4577 4594 comment on 'macros').
4578 4595
4579 4596 * Small fixes and doc updates.
4580 4597
4581 4598 * Rewrote @history function (was @h). Renamed it to @hist, @h is
4582 4599 much too fragile with automagic. Handles properly multi-line
4583 4600 statements and takes parameters.
4584 4601
4585 4602 2001-11-30 Fernando Perez <fperez@colorado.edu>
4586 4603
4587 4604 * Version 0.1.18 released.
4588 4605
4589 4606 * Fixed nasty namespace bug in initial module imports.
4590 4607
4591 4608 * Added copyright/license notes to all code files (except
4592 4609 DPyGetOpt). For the time being, LGPL. That could change.
4593 4610
4594 4611 * Rewrote a much nicer README, updated INSTALL, cleaned up
4595 4612 ipythonrc-* samples.
4596 4613
4597 4614 * Overall code/documentation cleanup. Basically ready for
4598 4615 release. Only remaining thing: licence decision (LGPL?).
4599 4616
4600 4617 * Converted load_config to a class, ConfigLoader. Now recursion
4601 4618 control is better organized. Doesn't include the same file twice.
4602 4619
4603 4620 2001-11-29 Fernando Perez <fperez@colorado.edu>
4604 4621
4605 4622 * Got input history working. Changed output history variables from
4606 4623 _p to _o so that _i is for input and _o for output. Just cleaner
4607 4624 convention.
4608 4625
4609 4626 * Implemented parametric aliases. This pretty much allows the
4610 4627 alias system to offer full-blown shell convenience, I think.
4611 4628
4612 4629 * Version 0.1.17 released, 0.1.18 opened.
4613 4630
4614 4631 * dot_ipython/ipythonrc (alias): added documentation.
4615 4632 (xcolor): Fixed small bug (xcolors -> xcolor)
4616 4633
4617 4634 * Changed the alias system. Now alias is a magic command to define
4618 4635 aliases just like the shell. Rationale: the builtin magics should
4619 4636 be there for things deeply connected to IPython's
4620 4637 architecture. And this is a much lighter system for what I think
4621 4638 is the really important feature: allowing users to define quickly
4622 4639 magics that will do shell things for them, so they can customize
4623 4640 IPython easily to match their work habits. If someone is really
4624 4641 desperate to have another name for a builtin alias, they can
4625 4642 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
4626 4643 works.
4627 4644
4628 4645 2001-11-28 Fernando Perez <fperez@colorado.edu>
4629 4646
4630 4647 * Changed @file so that it opens the source file at the proper
4631 4648 line. Since it uses less, if your EDITOR environment is
4632 4649 configured, typing v will immediately open your editor of choice
4633 4650 right at the line where the object is defined. Not as quick as
4634 4651 having a direct @edit command, but for all intents and purposes it
4635 4652 works. And I don't have to worry about writing @edit to deal with
4636 4653 all the editors, less does that.
4637 4654
4638 4655 * Version 0.1.16 released, 0.1.17 opened.
4639 4656
4640 4657 * Fixed some nasty bugs in the page/page_dumb combo that could
4641 4658 crash IPython.
4642 4659
4643 4660 2001-11-27 Fernando Perez <fperez@colorado.edu>
4644 4661
4645 4662 * Version 0.1.15 released, 0.1.16 opened.
4646 4663
4647 4664 * Finally got ? and ?? to work for undefined things: now it's
4648 4665 possible to type {}.get? and get information about the get method
4649 4666 of dicts, or os.path? even if only os is defined (so technically
4650 4667 os.path isn't). Works at any level. For example, after import os,
4651 4668 os?, os.path?, os.path.abspath? all work. This is great, took some
4652 4669 work in _ofind.
4653 4670
4654 4671 * Fixed more bugs with logging. The sanest way to do it was to add
4655 4672 to @log a 'mode' parameter. Killed two in one shot (this mode
4656 4673 option was a request of Janko's). I think it's finally clean
4657 4674 (famous last words).
4658 4675
4659 4676 * Added a page_dumb() pager which does a decent job of paging on
4660 4677 screen, if better things (like less) aren't available. One less
4661 4678 unix dependency (someday maybe somebody will port this to
4662 4679 windows).
4663 4680
4664 4681 * Fixed problem in magic_log: would lock of logging out if log
4665 4682 creation failed (because it would still think it had succeeded).
4666 4683
4667 4684 * Improved the page() function using curses to auto-detect screen
4668 4685 size. Now it can make a much better decision on whether to print
4669 4686 or page a string. Option screen_length was modified: a value 0
4670 4687 means auto-detect, and that's the default now.
4671 4688
4672 4689 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
4673 4690 go out. I'll test it for a few days, then talk to Janko about
4674 4691 licences and announce it.
4675 4692
4676 4693 * Fixed the length of the auto-generated ---> prompt which appears
4677 4694 for auto-parens and auto-quotes. Getting this right isn't trivial,
4678 4695 with all the color escapes, different prompt types and optional
4679 4696 separators. But it seems to be working in all the combinations.
4680 4697
4681 4698 2001-11-26 Fernando Perez <fperez@colorado.edu>
4682 4699
4683 4700 * Wrote a regexp filter to get option types from the option names
4684 4701 string. This eliminates the need to manually keep two duplicate
4685 4702 lists.
4686 4703
4687 4704 * Removed the unneeded check_option_names. Now options are handled
4688 4705 in a much saner manner and it's easy to visually check that things
4689 4706 are ok.
4690 4707
4691 4708 * Updated version numbers on all files I modified to carry a
4692 4709 notice so Janko and Nathan have clear version markers.
4693 4710
4694 4711 * Updated docstring for ultraTB with my changes. I should send
4695 4712 this to Nathan.
4696 4713
4697 4714 * Lots of small fixes. Ran everything through pychecker again.
4698 4715
4699 4716 * Made loading of deep_reload an cmd line option. If it's not too
4700 4717 kosher, now people can just disable it. With -nodeep_reload it's
4701 4718 still available as dreload(), it just won't overwrite reload().
4702 4719
4703 4720 * Moved many options to the no| form (-opt and -noopt
4704 4721 accepted). Cleaner.
4705 4722
4706 4723 * Changed magic_log so that if called with no parameters, it uses
4707 4724 'rotate' mode. That way auto-generated logs aren't automatically
4708 4725 over-written. For normal logs, now a backup is made if it exists
4709 4726 (only 1 level of backups). A new 'backup' mode was added to the
4710 4727 Logger class to support this. This was a request by Janko.
4711 4728
4712 4729 * Added @logoff/@logon to stop/restart an active log.
4713 4730
4714 4731 * Fixed a lot of bugs in log saving/replay. It was pretty
4715 4732 broken. Now special lines (!@,/) appear properly in the command
4716 4733 history after a log replay.
4717 4734
4718 4735 * Tried and failed to implement full session saving via pickle. My
4719 4736 idea was to pickle __main__.__dict__, but modules can't be
4720 4737 pickled. This would be a better alternative to replaying logs, but
4721 4738 seems quite tricky to get to work. Changed -session to be called
4722 4739 -logplay, which more accurately reflects what it does. And if we
4723 4740 ever get real session saving working, -session is now available.
4724 4741
4725 4742 * Implemented color schemes for prompts also. As for tracebacks,
4726 4743 currently only NoColor and Linux are supported. But now the
4727 4744 infrastructure is in place, based on a generic ColorScheme
4728 4745 class. So writing and activating new schemes both for the prompts
4729 4746 and the tracebacks should be straightforward.
4730 4747
4731 4748 * Version 0.1.13 released, 0.1.14 opened.
4732 4749
4733 4750 * Changed handling of options for output cache. Now counter is
4734 4751 hardwired starting at 1 and one specifies the maximum number of
4735 4752 entries *in the outcache* (not the max prompt counter). This is
4736 4753 much better, since many statements won't increase the cache
4737 4754 count. It also eliminated some confusing options, now there's only
4738 4755 one: cache_size.
4739 4756
4740 4757 * Added 'alias' magic function and magic_alias option in the
4741 4758 ipythonrc file. Now the user can easily define whatever names he
4742 4759 wants for the magic functions without having to play weird
4743 4760 namespace games. This gives IPython a real shell-like feel.
4744 4761
4745 4762 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
4746 4763 @ or not).
4747 4764
4748 4765 This was one of the last remaining 'visible' bugs (that I know
4749 4766 of). I think if I can clean up the session loading so it works
4750 4767 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
4751 4768 about licensing).
4752 4769
4753 4770 2001-11-25 Fernando Perez <fperez@colorado.edu>
4754 4771
4755 4772 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
4756 4773 there's a cleaner distinction between what ? and ?? show.
4757 4774
4758 4775 * Added screen_length option. Now the user can define his own
4759 4776 screen size for page() operations.
4760 4777
4761 4778 * Implemented magic shell-like functions with automatic code
4762 4779 generation. Now adding another function is just a matter of adding
4763 4780 an entry to a dict, and the function is dynamically generated at
4764 4781 run-time. Python has some really cool features!
4765 4782
4766 4783 * Renamed many options to cleanup conventions a little. Now all
4767 4784 are lowercase, and only underscores where needed. Also in the code
4768 4785 option name tables are clearer.
4769 4786
4770 4787 * Changed prompts a little. Now input is 'In [n]:' instead of
4771 4788 'In[n]:='. This allows it the numbers to be aligned with the
4772 4789 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4773 4790 Python (it was a Mathematica thing). The '...' continuation prompt
4774 4791 was also changed a little to align better.
4775 4792
4776 4793 * Fixed bug when flushing output cache. Not all _p<n> variables
4777 4794 exist, so their deletion needs to be wrapped in a try:
4778 4795
4779 4796 * Figured out how to properly use inspect.formatargspec() (it
4780 4797 requires the args preceded by *). So I removed all the code from
4781 4798 _get_pdef in Magic, which was just replicating that.
4782 4799
4783 4800 * Added test to prefilter to allow redefining magic function names
4784 4801 as variables. This is ok, since the @ form is always available,
4785 4802 but whe should allow the user to define a variable called 'ls' if
4786 4803 he needs it.
4787 4804
4788 4805 * Moved the ToDo information from README into a separate ToDo.
4789 4806
4790 4807 * General code cleanup and small bugfixes. I think it's close to a
4791 4808 state where it can be released, obviously with a big 'beta'
4792 4809 warning on it.
4793 4810
4794 4811 * Got the magic function split to work. Now all magics are defined
4795 4812 in a separate class. It just organizes things a bit, and now
4796 4813 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4797 4814 was too long).
4798 4815
4799 4816 * Changed @clear to @reset to avoid potential confusions with
4800 4817 the shell command clear. Also renamed @cl to @clear, which does
4801 4818 exactly what people expect it to from their shell experience.
4802 4819
4803 4820 Added a check to the @reset command (since it's so
4804 4821 destructive, it's probably a good idea to ask for confirmation).
4805 4822 But now reset only works for full namespace resetting. Since the
4806 4823 del keyword is already there for deleting a few specific
4807 4824 variables, I don't see the point of having a redundant magic
4808 4825 function for the same task.
4809 4826
4810 4827 2001-11-24 Fernando Perez <fperez@colorado.edu>
4811 4828
4812 4829 * Updated the builtin docs (esp. the ? ones).
4813 4830
4814 4831 * Ran all the code through pychecker. Not terribly impressed with
4815 4832 it: lots of spurious warnings and didn't really find anything of
4816 4833 substance (just a few modules being imported and not used).
4817 4834
4818 4835 * Implemented the new ultraTB functionality into IPython. New
4819 4836 option: xcolors. This chooses color scheme. xmode now only selects
4820 4837 between Plain and Verbose. Better orthogonality.
4821 4838
4822 4839 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4823 4840 mode and color scheme for the exception handlers. Now it's
4824 4841 possible to have the verbose traceback with no coloring.
4825 4842
4826 4843 2001-11-23 Fernando Perez <fperez@colorado.edu>
4827 4844
4828 4845 * Version 0.1.12 released, 0.1.13 opened.
4829 4846
4830 4847 * Removed option to set auto-quote and auto-paren escapes by
4831 4848 user. The chances of breaking valid syntax are just too high. If
4832 4849 someone *really* wants, they can always dig into the code.
4833 4850
4834 4851 * Made prompt separators configurable.
4835 4852
4836 4853 2001-11-22 Fernando Perez <fperez@colorado.edu>
4837 4854
4838 4855 * Small bugfixes in many places.
4839 4856
4840 4857 * Removed the MyCompleter class from ipplib. It seemed redundant
4841 4858 with the C-p,C-n history search functionality. Less code to
4842 4859 maintain.
4843 4860
4844 4861 * Moved all the original ipython.py code into ipythonlib.py. Right
4845 4862 now it's just one big dump into a function called make_IPython, so
4846 4863 no real modularity has been gained. But at least it makes the
4847 4864 wrapper script tiny, and since ipythonlib is a module, it gets
4848 4865 compiled and startup is much faster.
4849 4866
4850 4867 This is a reasobably 'deep' change, so we should test it for a
4851 4868 while without messing too much more with the code.
4852 4869
4853 4870 2001-11-21 Fernando Perez <fperez@colorado.edu>
4854 4871
4855 4872 * Version 0.1.11 released, 0.1.12 opened for further work.
4856 4873
4857 4874 * Removed dependency on Itpl. It was only needed in one place. It
4858 4875 would be nice if this became part of python, though. It makes life
4859 4876 *a lot* easier in some cases.
4860 4877
4861 4878 * Simplified the prefilter code a bit. Now all handlers are
4862 4879 expected to explicitly return a value (at least a blank string).
4863 4880
4864 4881 * Heavy edits in ipplib. Removed the help system altogether. Now
4865 4882 obj?/?? is used for inspecting objects, a magic @doc prints
4866 4883 docstrings, and full-blown Python help is accessed via the 'help'
4867 4884 keyword. This cleans up a lot of code (less to maintain) and does
4868 4885 the job. Since 'help' is now a standard Python component, might as
4869 4886 well use it and remove duplicate functionality.
4870 4887
4871 4888 Also removed the option to use ipplib as a standalone program. By
4872 4889 now it's too dependent on other parts of IPython to function alone.
4873 4890
4874 4891 * Fixed bug in genutils.pager. It would crash if the pager was
4875 4892 exited immediately after opening (broken pipe).
4876 4893
4877 4894 * Trimmed down the VerboseTB reporting a little. The header is
4878 4895 much shorter now and the repeated exception arguments at the end
4879 4896 have been removed. For interactive use the old header seemed a bit
4880 4897 excessive.
4881 4898
4882 4899 * Fixed small bug in output of @whos for variables with multi-word
4883 4900 types (only first word was displayed).
4884 4901
4885 4902 2001-11-17 Fernando Perez <fperez@colorado.edu>
4886 4903
4887 4904 * Version 0.1.10 released, 0.1.11 opened for further work.
4888 4905
4889 4906 * Modified dirs and friends. dirs now *returns* the stack (not
4890 4907 prints), so one can manipulate it as a variable. Convenient to
4891 4908 travel along many directories.
4892 4909
4893 4910 * Fixed bug in magic_pdef: would only work with functions with
4894 4911 arguments with default values.
4895 4912
4896 4913 2001-11-14 Fernando Perez <fperez@colorado.edu>
4897 4914
4898 4915 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4899 4916 example with IPython. Various other minor fixes and cleanups.
4900 4917
4901 4918 * Version 0.1.9 released, 0.1.10 opened for further work.
4902 4919
4903 4920 * Added sys.path to the list of directories searched in the
4904 4921 execfile= option. It used to be the current directory and the
4905 4922 user's IPYTHONDIR only.
4906 4923
4907 4924 2001-11-13 Fernando Perez <fperez@colorado.edu>
4908 4925
4909 4926 * Reinstated the raw_input/prefilter separation that Janko had
4910 4927 initially. This gives a more convenient setup for extending the
4911 4928 pre-processor from the outside: raw_input always gets a string,
4912 4929 and prefilter has to process it. We can then redefine prefilter
4913 4930 from the outside and implement extensions for special
4914 4931 purposes.
4915 4932
4916 4933 Today I got one for inputting PhysicalQuantity objects
4917 4934 (from Scientific) without needing any function calls at
4918 4935 all. Extremely convenient, and it's all done as a user-level
4919 4936 extension (no IPython code was touched). Now instead of:
4920 4937 a = PhysicalQuantity(4.2,'m/s**2')
4921 4938 one can simply say
4922 4939 a = 4.2 m/s**2
4923 4940 or even
4924 4941 a = 4.2 m/s^2
4925 4942
4926 4943 I use this, but it's also a proof of concept: IPython really is
4927 4944 fully user-extensible, even at the level of the parsing of the
4928 4945 command line. It's not trivial, but it's perfectly doable.
4929 4946
4930 4947 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4931 4948 the problem of modules being loaded in the inverse order in which
4932 4949 they were defined in
4933 4950
4934 4951 * Version 0.1.8 released, 0.1.9 opened for further work.
4935 4952
4936 4953 * Added magics pdef, source and file. They respectively show the
4937 4954 definition line ('prototype' in C), source code and full python
4938 4955 file for any callable object. The object inspector oinfo uses
4939 4956 these to show the same information.
4940 4957
4941 4958 * Version 0.1.7 released, 0.1.8 opened for further work.
4942 4959
4943 4960 * Separated all the magic functions into a class called Magic. The
4944 4961 InteractiveShell class was becoming too big for Xemacs to handle
4945 4962 (de-indenting a line would lock it up for 10 seconds while it
4946 4963 backtracked on the whole class!)
4947 4964
4948 4965 FIXME: didn't work. It can be done, but right now namespaces are
4949 4966 all messed up. Do it later (reverted it for now, so at least
4950 4967 everything works as before).
4951 4968
4952 4969 * Got the object introspection system (magic_oinfo) working! I
4953 4970 think this is pretty much ready for release to Janko, so he can
4954 4971 test it for a while and then announce it. Pretty much 100% of what
4955 4972 I wanted for the 'phase 1' release is ready. Happy, tired.
4956 4973
4957 4974 2001-11-12 Fernando Perez <fperez@colorado.edu>
4958 4975
4959 4976 * Version 0.1.6 released, 0.1.7 opened for further work.
4960 4977
4961 4978 * Fixed bug in printing: it used to test for truth before
4962 4979 printing, so 0 wouldn't print. Now checks for None.
4963 4980
4964 4981 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4965 4982 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4966 4983 reaches by hand into the outputcache. Think of a better way to do
4967 4984 this later.
4968 4985
4969 4986 * Various small fixes thanks to Nathan's comments.
4970 4987
4971 4988 * Changed magic_pprint to magic_Pprint. This way it doesn't
4972 4989 collide with pprint() and the name is consistent with the command
4973 4990 line option.
4974 4991
4975 4992 * Changed prompt counter behavior to be fully like
4976 4993 Mathematica's. That is, even input that doesn't return a result
4977 4994 raises the prompt counter. The old behavior was kind of confusing
4978 4995 (getting the same prompt number several times if the operation
4979 4996 didn't return a result).
4980 4997
4981 4998 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4982 4999
4983 5000 * Fixed -Classic mode (wasn't working anymore).
4984 5001
4985 5002 * Added colored prompts using Nathan's new code. Colors are
4986 5003 currently hardwired, they can be user-configurable. For
4987 5004 developers, they can be chosen in file ipythonlib.py, at the
4988 5005 beginning of the CachedOutput class def.
4989 5006
4990 5007 2001-11-11 Fernando Perez <fperez@colorado.edu>
4991 5008
4992 5009 * Version 0.1.5 released, 0.1.6 opened for further work.
4993 5010
4994 5011 * Changed magic_env to *return* the environment as a dict (not to
4995 5012 print it). This way it prints, but it can also be processed.
4996 5013
4997 5014 * Added Verbose exception reporting to interactive
4998 5015 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4999 5016 traceback. Had to make some changes to the ultraTB file. This is
5000 5017 probably the last 'big' thing in my mental todo list. This ties
5001 5018 in with the next entry:
5002 5019
5003 5020 * Changed -Xi and -Xf to a single -xmode option. Now all the user
5004 5021 has to specify is Plain, Color or Verbose for all exception
5005 5022 handling.
5006 5023
5007 5024 * Removed ShellServices option. All this can really be done via
5008 5025 the magic system. It's easier to extend, cleaner and has automatic
5009 5026 namespace protection and documentation.
5010 5027
5011 5028 2001-11-09 Fernando Perez <fperez@colorado.edu>
5012 5029
5013 5030 * Fixed bug in output cache flushing (missing parameter to
5014 5031 __init__). Other small bugs fixed (found using pychecker).
5015 5032
5016 5033 * Version 0.1.4 opened for bugfixing.
5017 5034
5018 5035 2001-11-07 Fernando Perez <fperez@colorado.edu>
5019 5036
5020 5037 * Version 0.1.3 released, mainly because of the raw_input bug.
5021 5038
5022 5039 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
5023 5040 and when testing for whether things were callable, a call could
5024 5041 actually be made to certain functions. They would get called again
5025 5042 once 'really' executed, with a resulting double call. A disaster
5026 5043 in many cases (list.reverse() would never work!).
5027 5044
5028 5045 * Removed prefilter() function, moved its code to raw_input (which
5029 5046 after all was just a near-empty caller for prefilter). This saves
5030 5047 a function call on every prompt, and simplifies the class a tiny bit.
5031 5048
5032 5049 * Fix _ip to __ip name in magic example file.
5033 5050
5034 5051 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
5035 5052 work with non-gnu versions of tar.
5036 5053
5037 5054 2001-11-06 Fernando Perez <fperez@colorado.edu>
5038 5055
5039 5056 * Version 0.1.2. Just to keep track of the recent changes.
5040 5057
5041 5058 * Fixed nasty bug in output prompt routine. It used to check 'if
5042 5059 arg != None...'. Problem is, this fails if arg implements a
5043 5060 special comparison (__cmp__) which disallows comparing to
5044 5061 None. Found it when trying to use the PhysicalQuantity module from
5045 5062 ScientificPython.
5046 5063
5047 5064 2001-11-05 Fernando Perez <fperez@colorado.edu>
5048 5065
5049 5066 * Also added dirs. Now the pushd/popd/dirs family functions
5050 5067 basically like the shell, with the added convenience of going home
5051 5068 when called with no args.
5052 5069
5053 5070 * pushd/popd slightly modified to mimic shell behavior more
5054 5071 closely.
5055 5072
5056 5073 * Added env,pushd,popd from ShellServices as magic functions. I
5057 5074 think the cleanest will be to port all desired functions from
5058 5075 ShellServices as magics and remove ShellServices altogether. This
5059 5076 will provide a single, clean way of adding functionality
5060 5077 (shell-type or otherwise) to IP.
5061 5078
5062 5079 2001-11-04 Fernando Perez <fperez@colorado.edu>
5063 5080
5064 5081 * Added .ipython/ directory to sys.path. This way users can keep
5065 5082 customizations there and access them via import.
5066 5083
5067 5084 2001-11-03 Fernando Perez <fperez@colorado.edu>
5068 5085
5069 5086 * Opened version 0.1.1 for new changes.
5070 5087
5071 5088 * Changed version number to 0.1.0: first 'public' release, sent to
5072 5089 Nathan and Janko.
5073 5090
5074 5091 * Lots of small fixes and tweaks.
5075 5092
5076 5093 * Minor changes to whos format. Now strings are shown, snipped if
5077 5094 too long.
5078 5095
5079 5096 * Changed ShellServices to work on __main__ so they show up in @who
5080 5097
5081 5098 * Help also works with ? at the end of a line:
5082 5099 ?sin and sin?
5083 5100 both produce the same effect. This is nice, as often I use the
5084 5101 tab-complete to find the name of a method, but I used to then have
5085 5102 to go to the beginning of the line to put a ? if I wanted more
5086 5103 info. Now I can just add the ? and hit return. Convenient.
5087 5104
5088 5105 2001-11-02 Fernando Perez <fperez@colorado.edu>
5089 5106
5090 5107 * Python version check (>=2.1) added.
5091 5108
5092 5109 * Added LazyPython documentation. At this point the docs are quite
5093 5110 a mess. A cleanup is in order.
5094 5111
5095 5112 * Auto-installer created. For some bizarre reason, the zipfiles
5096 5113 module isn't working on my system. So I made a tar version
5097 5114 (hopefully the command line options in various systems won't kill
5098 5115 me).
5099 5116
5100 5117 * Fixes to Struct in genutils. Now all dictionary-like methods are
5101 5118 protected (reasonably).
5102 5119
5103 5120 * Added pager function to genutils and changed ? to print usage
5104 5121 note through it (it was too long).
5105 5122
5106 5123 * Added the LazyPython functionality. Works great! I changed the
5107 5124 auto-quote escape to ';', it's on home row and next to '. But
5108 5125 both auto-quote and auto-paren (still /) escapes are command-line
5109 5126 parameters.
5110 5127
5111 5128
5112 5129 2001-11-01 Fernando Perez <fperez@colorado.edu>
5113 5130
5114 5131 * Version changed to 0.0.7. Fairly large change: configuration now
5115 5132 is all stored in a directory, by default .ipython. There, all
5116 5133 config files have normal looking names (not .names)
5117 5134
5118 5135 * Version 0.0.6 Released first to Lucas and Archie as a test
5119 5136 run. Since it's the first 'semi-public' release, change version to
5120 5137 > 0.0.6 for any changes now.
5121 5138
5122 5139 * Stuff I had put in the ipplib.py changelog:
5123 5140
5124 5141 Changes to InteractiveShell:
5125 5142
5126 5143 - Made the usage message a parameter.
5127 5144
5128 5145 - Require the name of the shell variable to be given. It's a bit
5129 5146 of a hack, but allows the name 'shell' not to be hardwire in the
5130 5147 magic (@) handler, which is problematic b/c it requires
5131 5148 polluting the global namespace with 'shell'. This in turn is
5132 5149 fragile: if a user redefines a variable called shell, things
5133 5150 break.
5134 5151
5135 5152 - magic @: all functions available through @ need to be defined
5136 5153 as magic_<name>, even though they can be called simply as
5137 5154 @<name>. This allows the special command @magic to gather
5138 5155 information automatically about all existing magic functions,
5139 5156 even if they are run-time user extensions, by parsing the shell
5140 5157 instance __dict__ looking for special magic_ names.
5141 5158
5142 5159 - mainloop: added *two* local namespace parameters. This allows
5143 5160 the class to differentiate between parameters which were there
5144 5161 before and after command line initialization was processed. This
5145 5162 way, later @who can show things loaded at startup by the
5146 5163 user. This trick was necessary to make session saving/reloading
5147 5164 really work: ideally after saving/exiting/reloading a session,
5148 5165 *everythin* should look the same, including the output of @who. I
5149 5166 was only able to make this work with this double namespace
5150 5167 trick.
5151 5168
5152 5169 - added a header to the logfile which allows (almost) full
5153 5170 session restoring.
5154 5171
5155 5172 - prepend lines beginning with @ or !, with a and log
5156 5173 them. Why? !lines: may be useful to know what you did @lines:
5157 5174 they may affect session state. So when restoring a session, at
5158 5175 least inform the user of their presence. I couldn't quite get
5159 5176 them to properly re-execute, but at least the user is warned.
5160 5177
5161 5178 * Started ChangeLog.
General Comments 0
You need to be logged in to leave comments. Login now