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