##// END OF EJS Templates
Fixes to:...
fperez -
Show More
@@ -1,228 +1,233 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 Logger class for IPython's logging facilities.
4 4
5 $Id: Logger.py 984 2005-12-31 08:40:31Z fperez $
5 $Id: Logger.py 988 2006-01-02 21:21:47Z fperez $
6 6 """
7 7
8 8 #*****************************************************************************
9 9 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
10 10 # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu>
11 11 #
12 12 # Distributed under the terms of the BSD License. The full license is in
13 13 # the file COPYING, distributed as part of this software.
14 14 #*****************************************************************************
15 15
16 16 #****************************************************************************
17 17 # Modules and globals
18 18
19 19 from IPython import Release
20 20 __author__ = '%s <%s>\n%s <%s>' % \
21 21 ( Release.authors['Janko'] + Release.authors['Fernando'] )
22 22 __license__ = Release.license
23 23
24 24 # Python standard modules
25 25 import glob
26 26 import os
27 27 import time
28 28
29 29 #****************************************************************************
30 30 # FIXME: This class isn't a mixin anymore, but it still needs attributes from
31 31 # ipython and does input cache management. Finish cleanup later...
32 32
33 33 class Logger(object):
34 34 """A Logfile class with different policies for file creation"""
35 35
36 36 def __init__(self,shell,logfname='Logger.log',loghead='',logmode='over'):
37 37
38 38 self._i00,self._i,self._ii,self._iii = '','','',''
39 39
40 40 # this is the full ipython instance, we need some attributes from it
41 41 # which won't exist until later. What a mess, clean up later...
42 42 self.shell = shell
43 43
44 44 self.logfname = logfname
45 45 self.loghead = loghead
46 46 self.logmode = logmode
47 47 self.logfile = None
48 48
49 49 # whether to also log output
50 50 self.log_output = False
51 51
52 52 # whether to put timestamps before each log entry
53 53 self.timestamp = False
54 54
55 55 # activity control flags
56 56 self.log_active = False
57 57
58 58 # logmode is a validated property
59 59 def _set_mode(self,mode):
60 60 if mode not in ['append','backup','global','over','rotate']:
61 61 raise ValueError,'invalid log mode %s given' % mode
62 62 self._logmode = mode
63 63
64 64 def _get_mode(self):
65 65 return self._logmode
66 66
67 67 logmode = property(_get_mode,_set_mode)
68 68
69 69 def logstart(self,logfname=None,loghead=None,logmode=None,
70 70 log_output=False,timestamp=False):
71 71 """Generate a new log-file with a default header.
72 72
73 73 Raises RuntimeError if the log has already been started"""
74 74
75 75 if self.logfile is not None:
76 76 raise RuntimeError('Log file is already active: %s' %
77 77 self.logfname)
78 78
79 79 self.log_active = True
80 80
81 81 # The three parameters can override constructor defaults
82 82 if logfname: self.logfname = logfname
83 83 if loghead: self.loghead = loghead
84 84 if logmode: self.logmode = logmode
85 85 self.timestamp = timestamp
86 86 self.log_output = log_output
87 87
88 88 # init depending on the log mode requested
89 89 isfile = os.path.isfile
90 90 logmode = self.logmode
91 91
92 92 if logmode == 'append':
93 93 self.logfile = open(self.logfname,'a')
94 94
95 95 elif logmode == 'backup':
96 96 if isfile(self.logfname):
97 97 backup_logname = self.logfname+'~'
98 98 # Manually remove any old backup, since os.rename may fail
99 99 # under Windows.
100 100 if isfile(backup_logname):
101 101 os.remove(backup_logname)
102 102 os.rename(self.logfname,backup_logname)
103 103 self.logfile = open(self.logfname,'w')
104 104
105 105 elif logmode == 'global':
106 106 self.logfname = os.path.join(self.shell.home_dir,self.logfname)
107 107 self.logfile = open(self.logfname, 'a')
108 108
109 109 elif logmode == 'over':
110 110 if isfile(self.logfname):
111 111 os.remove(self.logfname)
112 112 self.logfile = open(self.logfname,'w')
113 113
114 114 elif logmode == 'rotate':
115 115 if isfile(self.logfname):
116 116 if isfile(self.logfname+'.001~'):
117 117 old = glob.glob(self.logfname+'.*~')
118 118 old.sort()
119 119 old.reverse()
120 120 for f in old:
121 121 root, ext = os.path.splitext(f)
122 122 num = int(ext[1:-1])+1
123 123 os.rename(f, root+'.'+`num`.zfill(3)+'~')
124 124 os.rename(self.logfname, self.logfname+'.001~')
125 125 self.logfile = open(self.logfname,'w')
126 126
127 127 if logmode != 'append':
128 128 self.logfile.write(self.loghead)
129 129
130 130 self.logfile.flush()
131 131
132 132 def switch_log(self,val):
133 133 """Switch logging on/off. val should be ONLY a boolean."""
134 134
135 135 if val not in [False,True,0,1]:
136 136 raise ValueError, \
137 137 'Call switch_log ONLY with a boolean argument, not with:',val
138 138
139 139 label = {0:'OFF',1:'ON',False:'OFF',True:'ON'}
140 140
141 141 if self.logfile is None:
142 142 print """
143 143 Logging hasn't been started yet (use logstart for that).
144 144
145 145 %logon/%logoff are for temporarily starting and stopping logging for a logfile
146 146 which already exists. But you must first start the logging process with
147 147 %logstart (optionally giving a logfile name)."""
148 148
149 149 else:
150 150 if self.log_active == val:
151 151 print 'Logging is already',label[val]
152 152 else:
153 153 print 'Switching logging',label[val]
154 154 self.log_active = not self.log_active
155 155 self.log_active_out = self.log_active
156 156
157 157 def logstate(self):
158 158 """Print a status message about the logger."""
159 159 if self.logfile is None:
160 160 print 'Logging has not been activated.'
161 161 else:
162 162 state = self.log_active and 'active' or 'temporarily suspended'
163 163 print 'Filename :',self.logfname
164 164 print 'Mode :',self.logmode
165 165 print 'Output logging :',self.log_output
166 166 print 'Timestamping :',self.timestamp
167 167 print 'State :',state
168 168
169 169 def log(self, line,continuation=None):
170 170 """Write the line to a log and create input cache variables _i*."""
171 171
172 172 # update the auto _i tables
173 173 #print '***logging line',line # dbg
174 174 #print '***cache_count', self.shell.outputcache.prompt_count # dbg
175 input_hist = self.shell.user_ns['_ih']
175 try:
176 input_hist = self.shell.user_ns['_ih']
177 except:
178 print 'userns:',self.shell.user_ns.keys()
179 return
180
176 181 if not continuation and line:
177 182 self._iii = self._ii
178 183 self._ii = self._i
179 184 self._i = self._i00
180 185 # put back the final \n of every input line
181 186 self._i00 = line+'\n'
182 187 #print 'Logging input:<%s>' % line # dbg
183 188 input_hist.append(self._i00)
184 189 #print '---[%s]' % (len(input_hist)-1,) # dbg
185 190
186 191 # hackish access to top-level namespace to create _i1,_i2... dynamically
187 192 to_main = {'_i':self._i,'_ii':self._ii,'_iii':self._iii}
188 193 if self.shell.outputcache.do_full_cache:
189 194 in_num = self.shell.outputcache.prompt_count
190 195 # add blank lines if the input cache fell out of sync. This can
191 196 # happen for embedded instances which get killed via C-D and then
192 197 # get resumed.
193 198 while in_num >= len(input_hist):
194 199 input_hist.append('\n')
195 200 # but if the opposite is true (a macro can produce multiple inputs
196 201 # with no output display called), then bring the output counter in
197 202 # sync:
198 203 last_num = len(input_hist)-1
199 204 if in_num != last_num:
200 205 in_num = self.shell.outputcache.prompt_count = last_num
201 206 new_i = '_i%s' % in_num
202 207 if continuation:
203 208 self._i00 = '%s%s\n' % (self.shell.user_ns[new_i],line)
204 209 input_hist[in_num] = self._i00
205 210 to_main[new_i] = self._i00
206 211 self.shell.user_ns.update(to_main)
207 212 self.log_write(line)
208 213
209 214 def log_write(self,data,kind='input'):
210 215 """Write data to the log file, if active"""
211 216
212 217 if self.log_active and data:
213 218 write = self.logfile.write
214 219 if kind=='input':
215 220 if self.timestamp:
216 221 write(time.strftime('# %a, %d %b %Y %H:%M:%S\n',
217 222 time.localtime()))
218 223 write('%s\n' % data)
219 224 elif kind=='output' and self.log_output:
220 225 odata = '\n'.join(['#[Out]# %s' % s
221 226 for s in data.split('\n')])
222 227 write('%s\n' % odata)
223 228 self.logfile.flush()
224 229
225 230 def close_log(self):
226 231 self.logfile.close()
227 232 self.logfile = None
228 233 self.logfname = ''
@@ -1,2690 +1,2706 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 986 2005-12-31 23:07:31Z fperez $"""
4 $Id: Magic.py 988 2006-01-02 21:21:47Z 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 24 import bdb
25 25 import inspect
26 26 import os
27 27 import pdb
28 28 import pydoc
29 29 import sys
30 30 import re
31 31 import tempfile
32 32 import time
33 33 import cPickle as pickle
34 34 from cStringIO import StringIO
35 35 from getopt import getopt
36 36 from pprint import pprint, pformat
37 37
38 38 # profile isn't bundled by default in Debian for license reasons
39 39 try:
40 40 import profile,pstats
41 41 except ImportError:
42 42 profile = pstats = None
43 43
44 44 # Homebrewed
45 45 from IPython import Debugger, OInspect, wildcard
46 46 from IPython.FakeModule import FakeModule
47 47 from IPython.Itpl import Itpl, itpl, printpl,itplns
48 48 from IPython.PyColorize import Parser
49 49 from IPython.Struct import Struct
50 50 from IPython.macro import Macro
51 51 from IPython.genutils import *
52 52
53 53 #***************************************************************************
54 54 # Utility functions
55 55 def on_off(tag):
56 56 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
57 57 return ['OFF','ON'][tag]
58 58
59 59
60 60 #***************************************************************************
61 61 # Main class implementing Magic functionality
62 62 class Magic:
63 63 """Magic functions for InteractiveShell.
64 64
65 65 Shell functions which can be reached as %function_name. All magic
66 66 functions should accept a string, which they can parse for their own
67 67 needs. This can make some functions easier to type, eg `%cd ../`
68 68 vs. `%cd("../")`
69 69
70 70 ALL definitions MUST begin with the prefix magic_. The user won't need it
71 71 at the command line, but it is is needed in the definition. """
72 72
73 73 # class globals
74 74 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
75 75 'Automagic is ON, % prefix NOT needed for magic functions.']
76 76
77 77 #......................................................................
78 78 # some utility functions
79 79
80 80 def __init__(self,shell):
81 81
82 82 self.options_table = {}
83 83 if profile is None:
84 84 self.magic_prun = self.profile_missing_notice
85 85 self.shell = shell
86 86
87 87 def profile_missing_notice(self, *args, **kwargs):
88 88 error("""\
89 89 The profile module could not be found. If you are a Debian user,
90 90 it has been removed from the standard Debian package because of its non-free
91 91 license. To use profiling, please install"python2.3-profiler" from non-free.""")
92 92
93 93 def default_option(self,fn,optstr):
94 94 """Make an entry in the options_table for fn, with value optstr"""
95 95
96 96 if fn not in self.lsmagic():
97 97 error("%s is not a magic function" % fn)
98 98 self.options_table[fn] = optstr
99 99
100 100 def lsmagic(self):
101 101 """Return a list of currently available magic functions.
102 102
103 103 Gives a list of the bare names after mangling (['ls','cd', ...], not
104 104 ['magic_ls','magic_cd',...]"""
105 105
106 106 # FIXME. This needs a cleanup, in the way the magics list is built.
107 107
108 108 # magics in class definition
109 109 class_magic = lambda fn: fn.startswith('magic_') and \
110 110 callable(Magic.__dict__[fn])
111 111 # in instance namespace (run-time user additions)
112 112 inst_magic = lambda fn: fn.startswith('magic_') and \
113 113 callable(self.__dict__[fn])
114 114 # and bound magics by user (so they can access self):
115 115 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
116 116 callable(self.__class__.__dict__[fn])
117 117 magics = filter(class_magic,Magic.__dict__.keys()) + \
118 118 filter(inst_magic,self.__dict__.keys()) + \
119 119 filter(inst_bound_magic,self.__class__.__dict__.keys())
120 120 out = []
121 121 for fn in magics:
122 122 out.append(fn.replace('magic_','',1))
123 123 out.sort()
124 124 return out
125 125
126 126 def extract_input_slices(self,slices):
127 127 """Return as a string a set of input history slices.
128 128
129 129 The set of slices is given as a list of strings (like ['1','4:8','9'],
130 130 since this function is for use by magic functions which get their
131 131 arguments as strings.
132 132
133 133 Note that slices can be called with two notations:
134 134
135 135 N:M -> standard python form, means including items N...(M-1).
136 136
137 137 N-M -> include items N..M (closed endpoint)."""
138 138
139 139 cmds = []
140 140 for chunk in slices:
141 141 if ':' in chunk:
142 142 ini,fin = map(int,chunk.split(':'))
143 143 elif '-' in chunk:
144 144 ini,fin = map(int,chunk.split('-'))
145 145 fin += 1
146 146 else:
147 147 ini = int(chunk)
148 148 fin = ini+1
149 149 cmds.append(self.shell.input_hist[ini:fin])
150 150 return cmds
151 151
152 152 def _ofind(self,oname):
153 153 """Find an object in the available namespaces.
154 154
155 155 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
156 156
157 157 Has special code to detect magic functions.
158 158 """
159 159
160 160 oname = oname.strip()
161 161
162 162 # Namespaces to search in:
163 163 user_ns = self.shell.user_ns
164 164 internal_ns = self.shell.internal_ns
165 165 builtin_ns = __builtin__.__dict__
166 166 alias_ns = self.shell.alias_table
167 167
168 168 # Put them in a list. The order is important so that we find things in
169 169 # the same order that Python finds them.
170 170 namespaces = [ ('Interactive',user_ns),
171 171 ('IPython internal',internal_ns),
172 172 ('Python builtin',builtin_ns),
173 173 ('Alias',alias_ns),
174 174 ]
175 175
176 176 # initialize results to 'null'
177 177 found = 0; obj = None; ospace = None; ds = None;
178 178 ismagic = 0; isalias = 0
179 179
180 180 # Look for the given name by splitting it in parts. If the head is
181 181 # found, then we look for all the remaining parts as members, and only
182 182 # declare success if we can find them all.
183 183 oname_parts = oname.split('.')
184 184 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
185 185 for nsname,ns in namespaces:
186 186 try:
187 187 obj = ns[oname_head]
188 188 except KeyError:
189 189 continue
190 190 else:
191 191 for part in oname_rest:
192 192 try:
193 193 obj = getattr(obj,part)
194 194 except:
195 195 # Blanket except b/c some badly implemented objects
196 196 # allow __getattr__ to raise exceptions other than
197 197 # AttributeError, which then crashes IPython.
198 198 break
199 199 else:
200 200 # If we finish the for loop (no break), we got all members
201 201 found = 1
202 202 ospace = nsname
203 203 if ns == alias_ns:
204 204 isalias = 1
205 205 break # namespace loop
206 206
207 207 # Try to see if it's magic
208 208 if not found:
209 209 if oname.startswith(self.shell.ESC_MAGIC):
210 210 oname = oname[1:]
211 211 obj = getattr(self,'magic_'+oname,None)
212 212 if obj is not None:
213 213 found = 1
214 214 ospace = 'IPython internal'
215 215 ismagic = 1
216 216
217 217 # Last try: special-case some literals like '', [], {}, etc:
218 218 if not found and oname_head in ["''",'""','[]','{}','()']:
219 219 obj = eval(oname_head)
220 220 found = 1
221 221 ospace = 'Interactive'
222 222
223 223 return {'found':found, 'obj':obj, 'namespace':ospace,
224 224 'ismagic':ismagic, 'isalias':isalias}
225 225
226 226 def arg_err(self,func):
227 227 """Print docstring if incorrect arguments were passed"""
228 228 print 'Error in arguments:'
229 229 print OInspect.getdoc(func)
230 230
231 231 def format_latex(self,strng):
232 232 """Format a string for latex inclusion."""
233 233
234 234 # Characters that need to be escaped for latex:
235 235 escape_re = re.compile(r'(%|_|\$|#)',re.MULTILINE)
236 236 # Magic command names as headers:
237 237 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
238 238 re.MULTILINE)
239 239 # Magic commands
240 240 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
241 241 re.MULTILINE)
242 242 # Paragraph continue
243 243 par_re = re.compile(r'\\$',re.MULTILINE)
244 244
245 245 # The "\n" symbol
246 246 newline_re = re.compile(r'\\n')
247 247
248 248 # Now build the string for output:
249 249 strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
250 250 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
251 251 strng = par_re.sub(r'\\\\',strng)
252 252 strng = escape_re.sub(r'\\\1',strng)
253 253 strng = newline_re.sub(r'\\textbackslash{}n',strng)
254 254 return strng
255 255
256 256 def format_screen(self,strng):
257 257 """Format a string for screen printing.
258 258
259 259 This removes some latex-type format codes."""
260 260 # Paragraph continue
261 261 par_re = re.compile(r'\\$',re.MULTILINE)
262 262 strng = par_re.sub('',strng)
263 263 return strng
264 264
265 265 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
266 266 """Parse options passed to an argument string.
267 267
268 268 The interface is similar to that of getopt(), but it returns back a
269 269 Struct with the options as keys and the stripped argument string still
270 270 as a string.
271 271
272 272 arg_str is quoted as a true sys.argv vector by using shlex.split.
273 273 This allows us to easily expand variables, glob files, quote
274 274 arguments, etc.
275 275
276 276 Options:
277 277 -mode: default 'string'. If given as 'list', the argument string is
278 278 returned as a list (split on whitespace) instead of a string.
279 279
280 280 -list_all: put all option values in lists. Normally only options
281 281 appearing more than once are put in a list."""
282 282
283 283 # inject default options at the beginning of the input line
284 284 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
285 285 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
286 286
287 287 mode = kw.get('mode','string')
288 288 if mode not in ['string','list']:
289 289 raise ValueError,'incorrect mode given: %s' % mode
290 290 # Get options
291 291 list_all = kw.get('list_all',0)
292 292
293 293 # Check if we have more than one argument to warrant extra processing:
294 294 odict = {} # Dictionary with options
295 295 args = arg_str.split()
296 296 if len(args) >= 1:
297 297 # If the list of inputs only has 0 or 1 thing in it, there's no
298 298 # need to look for options
299 299 argv = shlex_split(arg_str)
300 300 # Do regular option processing
301 301 opts,args = getopt(argv,opt_str,*long_opts)
302 302 for o,a in opts:
303 303 if o.startswith('--'):
304 304 o = o[2:]
305 305 else:
306 306 o = o[1:]
307 307 try:
308 308 odict[o].append(a)
309 309 except AttributeError:
310 310 odict[o] = [odict[o],a]
311 311 except KeyError:
312 312 if list_all:
313 313 odict[o] = [a]
314 314 else:
315 315 odict[o] = a
316 316
317 317 # Prepare opts,args for return
318 318 opts = Struct(odict)
319 319 if mode == 'string':
320 320 args = ' '.join(args)
321 321
322 322 return opts,args
323 323
324 324 #......................................................................
325 325 # And now the actual magic functions
326 326
327 327 # Functions for IPython shell work (vars,funcs, config, etc)
328 328 def magic_lsmagic(self, parameter_s = ''):
329 329 """List currently available magic functions."""
330 330 mesc = self.shell.ESC_MAGIC
331 331 print 'Available magic functions:\n'+mesc+\
332 332 (' '+mesc).join(self.lsmagic())
333 333 print '\n' + Magic.auto_status[self.shell.rc.automagic]
334 334 return None
335 335
336 336 def magic_magic(self, parameter_s = ''):
337 337 """Print information about the magic function system."""
338 338
339 339 mode = ''
340 340 try:
341 341 if parameter_s.split()[0] == '-latex':
342 342 mode = 'latex'
343 343 except:
344 344 pass
345 345
346 346 magic_docs = []
347 347 for fname in self.lsmagic():
348 348 mname = 'magic_' + fname
349 349 for space in (Magic,self,self.__class__):
350 350 try:
351 351 fn = space.__dict__[mname]
352 352 except KeyError:
353 353 pass
354 354 else:
355 355 break
356 356 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
357 357 fname,fn.__doc__))
358 358 magic_docs = ''.join(magic_docs)
359 359
360 360 if mode == 'latex':
361 361 print self.format_latex(magic_docs)
362 362 return
363 363 else:
364 364 magic_docs = self.format_screen(magic_docs)
365 365
366 366 outmsg = """
367 367 IPython's 'magic' functions
368 368 ===========================
369 369
370 370 The magic function system provides a series of functions which allow you to
371 371 control the behavior of IPython itself, plus a lot of system-type
372 372 features. All these functions are prefixed with a % character, but parameters
373 373 are given without parentheses or quotes.
374 374
375 375 NOTE: If you have 'automagic' enabled (via the command line option or with the
376 376 %automagic function), you don't need to type in the % explicitly. By default,
377 377 IPython ships with automagic on, so you should only rarely need the % escape.
378 378
379 379 Example: typing '%cd mydir' (without the quotes) changes you working directory
380 380 to 'mydir', if it exists.
381 381
382 382 You can define your own magic functions to extend the system. See the supplied
383 383 ipythonrc and example-magic.py files for details (in your ipython
384 384 configuration directory, typically $HOME/.ipython/).
385 385
386 386 You can also define your own aliased names for magic functions. In your
387 387 ipythonrc file, placing a line like:
388 388
389 389 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
390 390
391 391 will define %pf as a new name for %profile.
392 392
393 393 You can also call magics in code using the ipmagic() function, which IPython
394 394 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
395 395
396 396 For a list of the available magic functions, use %lsmagic. For a description
397 397 of any of them, type %magic_name?, e.g. '%cd?'.
398 398
399 399 Currently the magic system has the following functions:\n"""
400 400
401 401 mesc = self.shell.ESC_MAGIC
402 402 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
403 403 "\n\n%s%s\n\n%s" % (outmsg,
404 404 magic_docs,mesc,mesc,
405 405 (' '+mesc).join(self.lsmagic()),
406 406 Magic.auto_status[self.shell.rc.automagic] ) )
407 407
408 408 page(outmsg,screen_lines=self.shell.rc.screen_length)
409 409
410 410 def magic_automagic(self, parameter_s = ''):
411 411 """Make magic functions callable without having to type the initial %.
412 412
413 413 Toggles on/off (when off, you must call it as %automagic, of
414 414 course). Note that magic functions have lowest priority, so if there's
415 415 a variable whose name collides with that of a magic fn, automagic
416 416 won't work for that function (you get the variable instead). However,
417 417 if you delete the variable (del var), the previously shadowed magic
418 418 function becomes visible to automagic again."""
419 419
420 420 rc = self.shell.rc
421 421 rc.automagic = not rc.automagic
422 422 print '\n' + Magic.auto_status[rc.automagic]
423 423
424 424 def magic_autocall(self, parameter_s = ''):
425 425 """Make functions callable without having to type parentheses.
426 426
427 427 This toggles the autocall command line option on and off."""
428 428
429 429 rc = self.shell.rc
430 430 rc.autocall = not rc.autocall
431 431 print "Automatic calling is:",['OFF','ON'][rc.autocall]
432 432
433 433 def magic_autoindent(self, parameter_s = ''):
434 434 """Toggle autoindent on/off (if available)."""
435 435
436 436 self.shell.set_autoindent()
437 437 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
438 438
439 439 def magic_system_verbose(self, parameter_s = ''):
440 440 """Toggle verbose printing of system calls on/off."""
441 441
442 442 self.shell.rc_set_toggle('system_verbose')
443 443 print "System verbose printing is:",\
444 444 ['OFF','ON'][self.shell.rc.system_verbose]
445 445
446 446 def magic_history(self, parameter_s = ''):
447 447 """Print input history (_i<n> variables), with most recent last.
448 448
449 449 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
450 450 %history [-n] n -> print at most n inputs\\
451 451 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
452 452
453 453 Each input's number <n> is shown, and is accessible as the
454 454 automatically generated variable _i<n>. Multi-line statements are
455 455 printed starting at a new line for easy copy/paste.
456 456
457 457 If option -n is used, input numbers are not printed. This is useful if
458 458 you want to get a printout of many lines which can be directly pasted
459 459 into a text editor.
460 460
461 461 This feature is only available if numbered prompts are in use."""
462 462
463 463 shell = self.shell
464 464 if not shell.outputcache.do_full_cache:
465 465 print 'This feature is only available if numbered prompts are in use.'
466 466 return
467 467 opts,args = self.parse_options(parameter_s,'n',mode='list')
468 468
469 469 input_hist = shell.input_hist
470 470 default_length = 40
471 471 if len(args) == 0:
472 472 final = len(input_hist)
473 473 init = max(1,final-default_length)
474 474 elif len(args) == 1:
475 475 final = len(input_hist)
476 476 init = max(1,final-int(args[0]))
477 477 elif len(args) == 2:
478 478 init,final = map(int,args)
479 479 else:
480 480 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
481 481 print self.magic_hist.__doc__
482 482 return
483 483 width = len(str(final))
484 484 line_sep = ['','\n']
485 485 print_nums = not opts.has_key('n')
486 486 for in_num in range(init,final):
487 487 inline = input_hist[in_num]
488 488 multiline = int(inline.count('\n') > 1)
489 489 if print_nums:
490 490 print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
491 491 print inline,
492 492
493 493 def magic_hist(self, parameter_s=''):
494 494 """Alternate name for %history."""
495 495 return self.magic_history(parameter_s)
496 496
497 497 def magic_p(self, parameter_s=''):
498 498 """Just a short alias for Python's 'print'."""
499 499 exec 'print ' + parameter_s in self.shell.user_ns
500 500
501 501 def magic_r(self, parameter_s=''):
502 502 """Repeat previous input.
503 503
504 504 If given an argument, repeats the previous command which starts with
505 505 the same string, otherwise it just repeats the previous input.
506 506
507 507 Shell escaped commands (with ! as first character) are not recognized
508 508 by this system, only pure python code and magic commands.
509 509 """
510 510
511 511 start = parameter_s.strip()
512 512 esc_magic = self.shell.ESC_MAGIC
513 513 # Identify magic commands even if automagic is on (which means
514 514 # the in-memory version is different from that typed by the user).
515 515 if self.shell.rc.automagic:
516 516 start_magic = esc_magic+start
517 517 else:
518 518 start_magic = start
519 519 # Look through the input history in reverse
520 520 for n in range(len(self.shell.input_hist)-2,0,-1):
521 521 input = self.shell.input_hist[n]
522 522 # skip plain 'r' lines so we don't recurse to infinity
523 523 if input != 'ipmagic("r")\n' and \
524 524 (input.startswith(start) or input.startswith(start_magic)):
525 525 #print 'match',`input` # dbg
526 526 print 'Executing:',input,
527 527 self.shell.runlines(input)
528 528 return
529 529 print 'No previous input matching `%s` found.' % start
530 530
531 531 def magic_page(self, parameter_s=''):
532 532 """Pretty print the object and display it through a pager.
533 533
534 534 If no parameter is given, use _ (last output)."""
535 535 # After a function contributed by Olivier Aubert, slightly modified.
536 536
537 537 oname = parameter_s and parameter_s or '_'
538 538 info = self._ofind(oname)
539 539 if info['found']:
540 540 page(pformat(info['obj']))
541 541 else:
542 542 print 'Object `%s` not found' % oname
543 543
544 544 def magic_profile(self, parameter_s=''):
545 545 """Print your currently active IPyhton profile."""
546 546 if self.shell.rc.profile:
547 547 printpl('Current IPython profile: $self.shell.rc.profile.')
548 548 else:
549 549 print 'No profile active.'
550 550
551 551 def _inspect(self,meth,oname,**kw):
552 552 """Generic interface to the inspector system.
553 553
554 554 This function is meant to be called by pdef, pdoc & friends."""
555 555
556 556 oname = oname.strip()
557 557 info = Struct(self._ofind(oname))
558 558 if info.found:
559 559 pmethod = getattr(self.shell.inspector,meth)
560 560 formatter = info.ismagic and self.format_screen or None
561 561 if meth == 'pdoc':
562 562 pmethod(info.obj,oname,formatter)
563 563 elif meth == 'pinfo':
564 564 pmethod(info.obj,oname,formatter,info,**kw)
565 565 else:
566 566 pmethod(info.obj,oname)
567 567 else:
568 568 print 'Object `%s` not found.' % oname
569 569 return 'not found' # so callers can take other action
570 570
571 571 def magic_pdef(self, parameter_s=''):
572 572 """Print the definition header for any callable object.
573 573
574 574 If the object is a class, print the constructor information."""
575 575 self._inspect('pdef',parameter_s)
576 576
577 577 def magic_pdoc(self, parameter_s=''):
578 578 """Print the docstring for an object.
579 579
580 580 If the given object is a class, it will print both the class and the
581 581 constructor docstrings."""
582 582 self._inspect('pdoc',parameter_s)
583 583
584 584 def magic_psource(self, parameter_s=''):
585 585 """Print (or run through pager) the source code for an object."""
586 586 self._inspect('psource',parameter_s)
587 587
588 588 def magic_pfile(self, parameter_s=''):
589 589 """Print (or run through pager) the file where an object is defined.
590 590
591 591 The file opens at the line where the object definition begins. IPython
592 592 will honor the environment variable PAGER if set, and otherwise will
593 593 do its best to print the file in a convenient form.
594 594
595 595 If the given argument is not an object currently defined, IPython will
596 596 try to interpret it as a filename (automatically adding a .py extension
597 597 if needed). You can thus use %pfile as a syntax highlighting code
598 598 viewer."""
599 599
600 600 # first interpret argument as an object name
601 601 out = self._inspect('pfile',parameter_s)
602 602 # if not, try the input as a filename
603 603 if out == 'not found':
604 604 try:
605 605 filename = get_py_filename(parameter_s)
606 606 except IOError,msg:
607 607 print msg
608 608 return
609 609 page(self.shell.inspector.format(file(filename).read()))
610 610
611 611 def magic_pinfo(self, parameter_s=''):
612 612 """Provide detailed information about an object.
613 613
614 614 '%pinfo object' is just a synonym for object? or ?object."""
615 615
616 616 #print 'pinfo par: <%s>' % parameter_s # dbg
617 617
618 618 # detail_level: 0 -> obj? , 1 -> obj??
619 619 detail_level = 0
620 620 # We need to detect if we got called as 'pinfo pinfo foo', which can
621 621 # happen if the user types 'pinfo foo?' at the cmd line.
622 622 pinfo,qmark1,oname,qmark2 = \
623 623 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
624 624 if pinfo or qmark1 or qmark2:
625 625 detail_level = 1
626 626 if "*" in oname:
627 627 self.magic_psearch(oname)
628 628 else:
629 629 self._inspect('pinfo',oname,detail_level=detail_level)
630 630
631 631 def magic_psearch(self, parameter_s=''):
632 632 """Search for object in namespaces by wildcard.
633 633
634 634 %psearch [options] PATTERN [OBJECT TYPE]
635 635
636 636 Note: ? can be used as a synonym for %psearch, at the beginning or at
637 637 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
638 638 rest of the command line must be unchanged (options come first), so
639 639 for example the following forms are equivalent
640 640
641 641 %psearch -i a* function
642 642 -i a* function?
643 643 ?-i a* function
644 644
645 645 Arguments:
646 646
647 647 PATTERN
648 648
649 649 where PATTERN is a string containing * as a wildcard similar to its
650 650 use in a shell. The pattern is matched in all namespaces on the
651 651 search path. By default objects starting with a single _ are not
652 652 matched, many IPython generated objects have a single
653 653 underscore. The default is case insensitive matching. Matching is
654 654 also done on the attributes of objects and not only on the objects
655 655 in a module.
656 656
657 657 [OBJECT TYPE]
658 658
659 659 Is the name of a python type from the types module. The name is
660 660 given in lowercase without the ending type, ex. StringType is
661 661 written string. By adding a type here only objects matching the
662 662 given type are matched. Using all here makes the pattern match all
663 663 types (this is the default).
664 664
665 665 Options:
666 666
667 667 -a: makes the pattern match even objects whose names start with a
668 668 single underscore. These names are normally ommitted from the
669 669 search.
670 670
671 671 -i/-c: make the pattern case insensitive/sensitive. If neither of
672 672 these options is given, the default is read from your ipythonrc
673 673 file. The option name which sets this value is
674 674 'wildcards_case_sensitive'. If this option is not specified in your
675 675 ipythonrc file, IPython's internal default is to do a case sensitive
676 676 search.
677 677
678 678 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
679 679 specifiy can be searched in any of the following namespaces:
680 680 'builtin', 'user', 'user_global','internal', 'alias', where
681 681 'builtin' and 'user' are the search defaults. Note that you should
682 682 not use quotes when specifying namespaces.
683 683
684 684 'Builtin' contains the python module builtin, 'user' contains all
685 685 user data, 'alias' only contain the shell aliases and no python
686 686 objects, 'internal' contains objects used by IPython. The
687 687 'user_global' namespace is only used by embedded IPython instances,
688 688 and it contains module-level globals. You can add namespaces to the
689 689 search with -s or exclude them with -e (these options can be given
690 690 more than once).
691 691
692 692 Examples:
693 693
694 694 %psearch a* -> objects beginning with an a
695 695 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
696 696 %psearch a* function -> all functions beginning with an a
697 697 %psearch re.e* -> objects beginning with an e in module re
698 698 %psearch r*.e* -> objects that start with e in modules starting in r
699 699 %psearch r*.* string -> all strings in modules beginning with r
700 700
701 701 Case sensitve search:
702 702
703 703 %psearch -c a* list all object beginning with lower case a
704 704
705 705 Show objects beginning with a single _:
706 706
707 707 %psearch -a _* list objects beginning with a single underscore"""
708 708
709 709 # default namespaces to be searched
710 710 def_search = ['user','builtin']
711 711
712 712 # Process options/args
713 713 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
714 714 opt = opts.get
715 715 shell = self.shell
716 716 psearch = shell.inspector.psearch
717 717
718 718 # select case options
719 719 if opts.has_key('i'):
720 720 ignore_case = True
721 721 elif opts.has_key('c'):
722 722 ignore_case = False
723 723 else:
724 724 ignore_case = not shell.rc.wildcards_case_sensitive
725 725
726 726 # Build list of namespaces to search from user options
727 727 def_search.extend(opt('s',[]))
728 728 ns_exclude = ns_exclude=opt('e',[])
729 729 ns_search = [nm for nm in def_search if nm not in ns_exclude]
730 730
731 731 # Call the actual search
732 732 try:
733 733 psearch(args,shell.ns_table,ns_search,
734 734 show_all=opt('a'),ignore_case=ignore_case)
735 735 except:
736 736 shell.showtraceback()
737 737
738 738 def magic_who_ls(self, parameter_s=''):
739 739 """Return a sorted list of all interactive variables.
740 740
741 741 If arguments are given, only variables of types matching these
742 742 arguments are returned."""
743 743
744 744 user_ns = self.shell.user_ns
745 internal_ns = self.shell.internal_ns
746 user_config_ns = self.shell.user_config_ns
745 747 out = []
746 748 typelist = parameter_s.split()
747 for i in self.shell.user_ns.keys():
749
750 for i in user_ns:
748 751 if not (i.startswith('_') or i.startswith('_i')) \
749 and not (self.shell.internal_ns.has_key(i) or
750 self.shell.user_config_ns.has_key(i)):
752 and not (i in internal_ns or i in user_config_ns):
751 753 if typelist:
752 754 if type(user_ns[i]).__name__ in typelist:
753 755 out.append(i)
754 756 else:
755 757 out.append(i)
756 758 out.sort()
757 759 return out
758 760
759 761 def magic_who(self, parameter_s=''):
760 762 """Print all interactive variables, with some minimal formatting.
761 763
762 764 If any arguments are given, only variables whose type matches one of
763 765 these are printed. For example:
764 766
765 767 %who function str
766 768
767 769 will only list functions and strings, excluding all other types of
768 770 variables. To find the proper type names, simply use type(var) at a
769 771 command line to see how python prints type names. For example:
770 772
771 773 In [1]: type('hello')\\
772 774 Out[1]: <type 'str'>
773 775
774 776 indicates that the type name for strings is 'str'.
775 777
776 778 %who always excludes executed names loaded through your configuration
777 779 file and things which are internal to IPython.
778 780
779 781 This is deliberate, as typically you may load many modules and the
780 782 purpose of %who is to show you only what you've manually defined."""
781 783
782 784 varlist = self.magic_who_ls(parameter_s)
783 785 if not varlist:
784 786 print 'Interactive namespace is empty.'
785 787 return
786 788
787 789 # if we have variables, move on...
788 790
789 791 # stupid flushing problem: when prompts have no separators, stdout is
790 792 # getting lost. I'm starting to think this is a python bug. I'm having
791 793 # to force a flush with a print because even a sys.stdout.flush
792 794 # doesn't seem to do anything!
793 795
794 796 count = 0
795 797 for i in varlist:
796 798 print i+'\t',
797 799 count += 1
798 800 if count > 8:
799 801 count = 0
800 802 print
801 803 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
802 804
803 805 print # well, this does force a flush at the expense of an extra \n
804 806
805 807 def magic_whos(self, parameter_s=''):
806 808 """Like %who, but gives some extra information about each variable.
807 809
808 810 The same type filtering of %who can be applied here.
809 811
810 812 For all variables, the type is printed. Additionally it prints:
811 813
812 814 - For {},[],(): their length.
813 815
814 816 - For Numeric arrays, a summary with shape, number of elements,
815 817 typecode and size in memory.
816 818
817 819 - Everything else: a string representation, snipping their middle if
818 820 too long."""
819 821
820 822 varnames = self.magic_who_ls(parameter_s)
821 823 if not varnames:
822 824 print 'Interactive namespace is empty.'
823 825 return
824 826
825 827 # if we have variables, move on...
826 828
827 829 # for these types, show len() instead of data:
828 830 seq_types = [types.DictType,types.ListType,types.TupleType]
829 831
830 832 # for Numeric arrays, display summary info
831 833 try:
832 834 import Numeric
833 835 except ImportError:
834 836 array_type = None
835 837 else:
836 838 array_type = Numeric.ArrayType.__name__
837 839
838 840 # Find all variable names and types so we can figure out column sizes
839 841 get_vars = lambda i: self.shell.user_ns[i]
840 842 type_name = lambda v: type(v).__name__
841 843 varlist = map(get_vars,varnames)
842 844
843 845 typelist = []
844 846 for vv in varlist:
845 847 tt = type_name(vv)
846 848 if tt=='instance':
847 849 typelist.append(str(vv.__class__))
848 850 else:
849 851 typelist.append(tt)
850 852
851 853 # column labels and # of spaces as separator
852 854 varlabel = 'Variable'
853 855 typelabel = 'Type'
854 856 datalabel = 'Data/Info'
855 857 colsep = 3
856 858 # variable format strings
857 859 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
858 860 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
859 861 aformat = "%s: %s elems, type `%s`, %s bytes"
860 862 # find the size of the columns to format the output nicely
861 863 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
862 864 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
863 865 # table header
864 866 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
865 867 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
866 868 # and the table itself
867 869 kb = 1024
868 870 Mb = 1048576 # kb**2
869 871 for vname,var,vtype in zip(varnames,varlist,typelist):
870 872 print itpl(vformat),
871 873 if vtype in seq_types:
872 874 print len(var)
873 875 elif vtype==array_type:
874 876 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
875 877 vsize = Numeric.size(var)
876 878 vbytes = vsize*var.itemsize()
877 879 if vbytes < 100000:
878 880 print aformat % (vshape,vsize,var.typecode(),vbytes)
879 881 else:
880 882 print aformat % (vshape,vsize,var.typecode(),vbytes),
881 883 if vbytes < Mb:
882 884 print '(%s kb)' % (vbytes/kb,)
883 885 else:
884 886 print '(%s Mb)' % (vbytes/Mb,)
885 887 else:
886 888 vstr = str(var).replace('\n','\\n')
887 889 if len(vstr) < 50:
888 890 print vstr
889 891 else:
890 892 printpl(vfmt_short)
891 893
892 894 def magic_reset(self, parameter_s=''):
893 895 """Resets the namespace by removing all names defined by the user.
894 896
895 897 Input/Output history are left around in case you need them."""
896 898
897 899 ans = raw_input(
898 900 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
899 901 if not ans.lower() == 'y':
900 902 print 'Nothing done.'
901 903 return
902 904 user_ns = self.shell.user_ns
903 905 for i in self.magic_who_ls():
904 906 del(user_ns[i])
905 907
906 908 def magic_config(self,parameter_s=''):
907 909 """Show IPython's internal configuration."""
908 910
909 911 page('Current configuration structure:\n'+
910 912 pformat(self.shell.rc.dict()))
911 913
912 914 def magic_logstart(self,parameter_s=''):
913 915 """Start logging anywhere in a session.
914 916
915 917 %logstart [-o|-t] [log_name [log_mode]]
916 918
917 919 If no name is given, it defaults to a file named 'ipython_log.py' in your
918 920 current directory, in 'rotate' mode (see below).
919 921
920 922 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
921 923 history up to that point and then continues logging.
922 924
923 925 %logstart takes a second optional parameter: logging mode. This can be one
924 926 of (note that the modes are given unquoted):\\
925 927 append: well, that says it.\\
926 928 backup: rename (if exists) to name~ and start name.\\
927 929 global: single logfile in your home dir, appended to.\\
928 930 over : overwrite existing log.\\
929 931 rotate: create rotating logs name.1~, name.2~, etc.
930 932
931 933 Options:
932 934
933 935 -o: log also IPython's output. In this mode, all commands which
934 936 generate an Out[NN] prompt are recorded to the logfile, right after
935 937 their corresponding input line. The output lines are always
936 938 prepended with a '#[Out]# ' marker, so that the log remains valid
937 939 Python code.
938 940
939 941 Since this marker is always the same, filtering only the output from
940 942 a log is very easy, using for example a simple awk call:
941 943
942 944 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
943 945
944 946 -t: put timestamps before each input line logged (these are put in
945 947 comments)."""
946 948
947 949 opts,par = self.parse_options(parameter_s,'ot')
948 950 log_output = 'o' in opts
949 951 timestamp = 't' in opts
950 952
951 953 rc = self.shell.rc
952 954 logger = self.shell.logger
953 955
954 956 # if no args are given, the defaults set in the logger constructor by
955 957 # ipytohn remain valid
956 958 if par:
957 959 try:
958 960 logfname,logmode = par.split()
959 961 except:
960 962 logfname = par
961 963 logmode = 'backup'
962 964 else:
963 965 logfname = logger.logfname
964 966 logmode = logger.logmode
965 967 # put logfname into rc struct as if it had been called on the command
966 968 # line, so it ends up saved in the log header Save it in case we need
967 969 # to restore it...
968 970 old_logfile = rc.opts.get('logfile','')
969 971 if logfname:
970 972 logfname = os.path.expanduser(logfname)
971 973 rc.opts.logfile = logfname
972 974 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
973 975 try:
974 976 started = logger.logstart(logfname,loghead,logmode,
975 977 log_output,timestamp)
976 978 except:
977 979 rc.opts.logfile = old_logfile
978 980 warn("Couldn't start log: %s" % sys.exc_info()[1])
979 981 else:
980 982 # log input history up to this point, optionally interleaving
981 983 # output if requested
982 984
983 985 if timestamp:
984 986 # disable timestamping for the previous history, since we've
985 987 # lost those already (no time machine here).
986 988 logger.timestamp = False
987 989 if log_output:
988 990 log_write = logger.log_write
989 991 input_hist = self.shell.input_hist
990 992 output_hist = self.shell.output_hist
991 993 for n in range(1,len(input_hist)-1):
992 994 log_write(input_hist[n].rstrip())
993 995 if n in output_hist:
994 996 log_write(repr(output_hist[n]),'output')
995 997 else:
996 998 logger.log_write(self.shell.input_hist[1:])
997 999 if timestamp:
998 1000 # re-enable timestamping
999 1001 logger.timestamp = True
1000 1002
1001 1003 print ('Activating auto-logging. '
1002 1004 'Current session state plus future input saved.')
1003 1005 logger.logstate()
1004 1006
1005 1007 def magic_logoff(self,parameter_s=''):
1006 1008 """Temporarily stop logging.
1007 1009
1008 1010 You must have previously started logging."""
1009 1011 self.shell.logger.switch_log(0)
1010 1012
1011 1013 def magic_logon(self,parameter_s=''):
1012 1014 """Restart logging.
1013 1015
1014 1016 This function is for restarting logging which you've temporarily
1015 1017 stopped with %logoff. For starting logging for the first time, you
1016 1018 must use the %logstart function, which allows you to specify an
1017 1019 optional log filename."""
1018 1020
1019 1021 self.shell.logger.switch_log(1)
1020 1022
1021 1023 def magic_logstate(self,parameter_s=''):
1022 1024 """Print the status of the logging system."""
1023 1025
1024 1026 self.shell.logger.logstate()
1025 1027
1026 1028 def magic_pdb(self, parameter_s=''):
1027 1029 """Control the calling of the pdb interactive debugger.
1028 1030
1029 1031 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1030 1032 argument it works as a toggle.
1031 1033
1032 1034 When an exception is triggered, IPython can optionally call the
1033 1035 interactive pdb debugger after the traceback printout. %pdb toggles
1034 1036 this feature on and off."""
1035 1037
1036 1038 par = parameter_s.strip().lower()
1037 1039
1038 1040 if par:
1039 1041 try:
1040 1042 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1041 1043 except KeyError:
1042 1044 print ('Incorrect argument. Use on/1, off/0, '
1043 1045 'or nothing for a toggle.')
1044 1046 return
1045 1047 else:
1046 1048 # toggle
1047 1049 new_pdb = not self.shell.InteractiveTB.call_pdb
1048 1050
1049 1051 # set on the shell
1050 1052 self.shell.call_pdb = new_pdb
1051 1053 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1052 1054
1053 1055 def magic_prun(self, parameter_s ='',user_mode=1,
1054 1056 opts=None,arg_lst=None,prog_ns=None):
1055 1057
1056 1058 """Run a statement through the python code profiler.
1057 1059
1058 1060 Usage:\\
1059 1061 %prun [options] statement
1060 1062
1061 1063 The given statement (which doesn't require quote marks) is run via the
1062 1064 python profiler in a manner similar to the profile.run() function.
1063 1065 Namespaces are internally managed to work correctly; profile.run
1064 1066 cannot be used in IPython because it makes certain assumptions about
1065 1067 namespaces which do not hold under IPython.
1066 1068
1067 1069 Options:
1068 1070
1069 1071 -l <limit>: you can place restrictions on what or how much of the
1070 1072 profile gets printed. The limit value can be:
1071 1073
1072 1074 * A string: only information for function names containing this string
1073 1075 is printed.
1074 1076
1075 1077 * An integer: only these many lines are printed.
1076 1078
1077 1079 * A float (between 0 and 1): this fraction of the report is printed
1078 1080 (for example, use a limit of 0.4 to see the topmost 40% only).
1079 1081
1080 1082 You can combine several limits with repeated use of the option. For
1081 1083 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1082 1084 information about class constructors.
1083 1085
1084 1086 -r: return the pstats.Stats object generated by the profiling. This
1085 1087 object has all the information about the profile in it, and you can
1086 1088 later use it for further analysis or in other functions.
1087 1089
1088 1090 Since magic functions have a particular form of calling which prevents
1089 1091 you from writing something like:\\
1090 1092 In [1]: p = %prun -r print 4 # invalid!\\
1091 1093 you must instead use IPython's automatic variables to assign this:\\
1092 1094 In [1]: %prun -r print 4 \\
1093 1095 Out[1]: <pstats.Stats instance at 0x8222cec>\\
1094 1096 In [2]: stats = _
1095 1097
1096 1098 If you really need to assign this value via an explicit function call,
1097 1099 you can always tap directly into the true name of the magic function
1098 1100 by using the ipmagic function (which IPython automatically adds to the
1099 1101 builtins):\\
1100 1102 In [3]: stats = ipmagic('prun','-r print 4')
1101 1103
1102 1104 You can type ipmagic? for more details on ipmagic.
1103 1105
1104 1106 -s <key>: sort profile by given key. You can provide more than one key
1105 1107 by using the option several times: '-s key1 -s key2 -s key3...'. The
1106 1108 default sorting key is 'time'.
1107 1109
1108 1110 The following is copied verbatim from the profile documentation
1109 1111 referenced below:
1110 1112
1111 1113 When more than one key is provided, additional keys are used as
1112 1114 secondary criteria when the there is equality in all keys selected
1113 1115 before them.
1114 1116
1115 1117 Abbreviations can be used for any key names, as long as the
1116 1118 abbreviation is unambiguous. The following are the keys currently
1117 1119 defined:
1118 1120
1119 1121 Valid Arg Meaning\\
1120 1122 "calls" call count\\
1121 1123 "cumulative" cumulative time\\
1122 1124 "file" file name\\
1123 1125 "module" file name\\
1124 1126 "pcalls" primitive call count\\
1125 1127 "line" line number\\
1126 1128 "name" function name\\
1127 1129 "nfl" name/file/line\\
1128 1130 "stdname" standard name\\
1129 1131 "time" internal time
1130 1132
1131 1133 Note that all sorts on statistics are in descending order (placing
1132 1134 most time consuming items first), where as name, file, and line number
1133 1135 searches are in ascending order (i.e., alphabetical). The subtle
1134 1136 distinction between "nfl" and "stdname" is that the standard name is a
1135 1137 sort of the name as printed, which means that the embedded line
1136 1138 numbers get compared in an odd way. For example, lines 3, 20, and 40
1137 1139 would (if the file names were the same) appear in the string order
1138 1140 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1139 1141 line numbers. In fact, sort_stats("nfl") is the same as
1140 1142 sort_stats("name", "file", "line").
1141 1143
1142 1144 -T <filename>: save profile results as shown on screen to a text
1143 1145 file. The profile is still shown on screen.
1144 1146
1145 1147 -D <filename>: save (via dump_stats) profile statistics to given
1146 1148 filename. This data is in a format understod by the pstats module, and
1147 1149 is generated by a call to the dump_stats() method of profile
1148 1150 objects. The profile is still shown on screen.
1149 1151
1150 1152 If you want to run complete programs under the profiler's control, use
1151 1153 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1152 1154 contains profiler specific options as described here.
1153 1155
1154 1156 You can read the complete documentation for the profile module with:\\
1155 1157 In [1]: import profile; profile.help() """
1156 1158
1157 1159 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1158 1160 # protect user quote marks
1159 1161 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1160 1162
1161 1163 if user_mode: # regular user call
1162 1164 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1163 1165 list_all=1)
1164 1166 namespace = self.shell.user_ns
1165 1167 else: # called to run a program by %run -p
1166 1168 try:
1167 1169 filename = get_py_filename(arg_lst[0])
1168 1170 except IOError,msg:
1169 1171 error(msg)
1170 1172 return
1171 1173
1172 1174 arg_str = 'execfile(filename,prog_ns)'
1173 1175 namespace = locals()
1174 1176
1175 1177 opts.merge(opts_def)
1176 1178
1177 1179 prof = profile.Profile()
1178 1180 try:
1179 1181 prof = prof.runctx(arg_str,namespace,namespace)
1180 1182 sys_exit = ''
1181 1183 except SystemExit:
1182 1184 sys_exit = """*** SystemExit exception caught in code being profiled."""
1183 1185
1184 1186 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1185 1187
1186 1188 lims = opts.l
1187 1189 if lims:
1188 1190 lims = [] # rebuild lims with ints/floats/strings
1189 1191 for lim in opts.l:
1190 1192 try:
1191 1193 lims.append(int(lim))
1192 1194 except ValueError:
1193 1195 try:
1194 1196 lims.append(float(lim))
1195 1197 except ValueError:
1196 1198 lims.append(lim)
1197 1199
1198 1200 # trap output
1199 1201 sys_stdout = sys.stdout
1200 1202 stdout_trap = StringIO()
1201 1203 try:
1202 1204 sys.stdout = stdout_trap
1203 1205 stats.print_stats(*lims)
1204 1206 finally:
1205 1207 sys.stdout = sys_stdout
1206 1208 output = stdout_trap.getvalue()
1207 1209 output = output.rstrip()
1208 1210
1209 1211 page(output,screen_lines=self.shell.rc.screen_length)
1210 1212 print sys_exit,
1211 1213
1212 1214 dump_file = opts.D[0]
1213 1215 text_file = opts.T[0]
1214 1216 if dump_file:
1215 1217 prof.dump_stats(dump_file)
1216 1218 print '\n*** Profile stats marshalled to file',\
1217 1219 `dump_file`+'.',sys_exit
1218 1220 if text_file:
1219 1221 file(text_file,'w').write(output)
1220 1222 print '\n*** Profile printout saved to text file',\
1221 1223 `text_file`+'.',sys_exit
1222 1224
1223 1225 if opts.has_key('r'):
1224 1226 return stats
1225 1227 else:
1226 1228 return None
1227 1229
1228 1230 def magic_run(self, parameter_s ='',runner=None):
1229 1231 """Run the named file inside IPython as a program.
1230 1232
1231 1233 Usage:\\
1232 1234 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1233 1235
1234 1236 Parameters after the filename are passed as command-line arguments to
1235 1237 the program (put in sys.argv). Then, control returns to IPython's
1236 1238 prompt.
1237 1239
1238 1240 This is similar to running at a system prompt:\\
1239 1241 $ python file args\\
1240 1242 but with the advantage of giving you IPython's tracebacks, and of
1241 1243 loading all variables into your interactive namespace for further use
1242 1244 (unless -p is used, see below).
1243 1245
1244 1246 The file is executed in a namespace initially consisting only of
1245 1247 __name__=='__main__' and sys.argv constructed as indicated. It thus
1246 1248 sees its environment as if it were being run as a stand-alone
1247 1249 program. But after execution, the IPython interactive namespace gets
1248 1250 updated with all variables defined in the program (except for __name__
1249 1251 and sys.argv). This allows for very convenient loading of code for
1250 1252 interactive work, while giving each program a 'clean sheet' to run in.
1251 1253
1252 1254 Options:
1253 1255
1254 1256 -n: __name__ is NOT set to '__main__', but to the running file's name
1255 1257 without extension (as python does under import). This allows running
1256 1258 scripts and reloading the definitions in them without calling code
1257 1259 protected by an ' if __name__ == "__main__" ' clause.
1258 1260
1259 1261 -i: run the file in IPython's namespace instead of an empty one. This
1260 1262 is useful if you are experimenting with code written in a text editor
1261 1263 which depends on variables defined interactively.
1262 1264
1263 1265 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1264 1266 being run. This is particularly useful if IPython is being used to
1265 1267 run unittests, which always exit with a sys.exit() call. In such
1266 1268 cases you are interested in the output of the test results, not in
1267 1269 seeing a traceback of the unittest module.
1268 1270
1269 1271 -t: print timing information at the end of the run. IPython will give
1270 1272 you an estimated CPU time consumption for your script, which under
1271 1273 Unix uses the resource module to avoid the wraparound problems of
1272 1274 time.clock(). Under Unix, an estimate of time spent on system tasks
1273 1275 is also given (for Windows platforms this is reported as 0.0).
1274 1276
1275 1277 If -t is given, an additional -N<N> option can be given, where <N>
1276 1278 must be an integer indicating how many times you want the script to
1277 1279 run. The final timing report will include total and per run results.
1278 1280
1279 1281 For example (testing the script uniq_stable.py):
1280 1282
1281 1283 In [1]: run -t uniq_stable
1282 1284
1283 1285 IPython CPU timings (estimated):\\
1284 1286 User : 0.19597 s.\\
1285 1287 System: 0.0 s.\\
1286 1288
1287 1289 In [2]: run -t -N5 uniq_stable
1288 1290
1289 1291 IPython CPU timings (estimated):\\
1290 1292 Total runs performed: 5\\
1291 1293 Times : Total Per run\\
1292 1294 User : 0.910862 s, 0.1821724 s.\\
1293 1295 System: 0.0 s, 0.0 s.
1294 1296
1295 1297 -d: run your program under the control of pdb, the Python debugger.
1296 1298 This allows you to execute your program step by step, watch variables,
1297 1299 etc. Internally, what IPython does is similar to calling:
1298 1300
1299 1301 pdb.run('execfile("YOURFILENAME")')
1300 1302
1301 1303 with a breakpoint set on line 1 of your file. You can change the line
1302 1304 number for this automatic breakpoint to be <N> by using the -bN option
1303 1305 (where N must be an integer). For example:
1304 1306
1305 1307 %run -d -b40 myscript
1306 1308
1307 1309 will set the first breakpoint at line 40 in myscript.py. Note that
1308 1310 the first breakpoint must be set on a line which actually does
1309 1311 something (not a comment or docstring) for it to stop execution.
1310 1312
1311 1313 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1312 1314 first enter 'c' (without qoutes) to start execution up to the first
1313 1315 breakpoint.
1314 1316
1315 1317 Entering 'help' gives information about the use of the debugger. You
1316 1318 can easily see pdb's full documentation with "import pdb;pdb.help()"
1317 1319 at a prompt.
1318 1320
1319 1321 -p: run program under the control of the Python profiler module (which
1320 1322 prints a detailed report of execution times, function calls, etc).
1321 1323
1322 1324 You can pass other options after -p which affect the behavior of the
1323 1325 profiler itself. See the docs for %prun for details.
1324 1326
1325 1327 In this mode, the program's variables do NOT propagate back to the
1326 1328 IPython interactive namespace (because they remain in the namespace
1327 1329 where the profiler executes them).
1328 1330
1329 1331 Internally this triggers a call to %prun, see its documentation for
1330 1332 details on the options available specifically for profiling."""
1331 1333
1332 1334 # get arguments and set sys.argv for program to be run.
1333 1335 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1334 1336 mode='list',list_all=1)
1335 1337
1336 1338 try:
1337 1339 filename = get_py_filename(arg_lst[0])
1338 1340 except IndexError:
1339 1341 warn('you must provide at least a filename.')
1340 1342 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1341 1343 return
1342 1344 except IOError,msg:
1343 1345 error(msg)
1344 1346 return
1345 1347
1346 1348 # Control the response to exit() calls made by the script being run
1347 1349 exit_ignore = opts.has_key('e')
1348 1350
1349 1351 # Make sure that the running script gets a proper sys.argv as if it
1350 1352 # were run from a system shell.
1351 1353 save_argv = sys.argv # save it for later restoring
1352 1354 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1353 1355
1354 1356 if opts.has_key('i'):
1355 1357 prog_ns = self.shell.user_ns
1356 1358 __name__save = self.shell.user_ns['__name__']
1357 1359 prog_ns['__name__'] = '__main__'
1358 1360 else:
1359 1361 if opts.has_key('n'):
1360 1362 name = os.path.splitext(os.path.basename(filename))[0]
1361 1363 else:
1362 1364 name = '__main__'
1363 1365 prog_ns = {'__name__':name}
1364 1366
1365 1367 # pickle fix. See iplib for an explanation. But we need to make sure
1366 1368 # that, if we overwrite __main__, we replace it at the end
1367 1369 if prog_ns['__name__'] == '__main__':
1368 1370 restore_main = sys.modules['__main__']
1369 1371 else:
1370 1372 restore_main = False
1371 1373
1372 1374 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1373 1375
1374 1376 stats = None
1375 1377 try:
1376 1378 if opts.has_key('p'):
1377 1379 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1378 1380 else:
1379 1381 if opts.has_key('d'):
1380 1382 deb = Debugger.Pdb(self.shell.rc.colors)
1381 1383 # reset Breakpoint state, which is moronically kept
1382 1384 # in a class
1383 1385 bdb.Breakpoint.next = 1
1384 1386 bdb.Breakpoint.bplist = {}
1385 1387 bdb.Breakpoint.bpbynumber = [None]
1386 1388 # Set an initial breakpoint to stop execution
1387 1389 maxtries = 10
1388 1390 bp = int(opts.get('b',[1])[0])
1389 1391 checkline = deb.checkline(filename,bp)
1390 1392 if not checkline:
1391 1393 for bp in range(bp+1,bp+maxtries+1):
1392 1394 if deb.checkline(filename,bp):
1393 1395 break
1394 1396 else:
1395 1397 msg = ("\nI failed to find a valid line to set "
1396 1398 "a breakpoint\n"
1397 1399 "after trying up to line: %s.\n"
1398 1400 "Please set a valid breakpoint manually "
1399 1401 "with the -b option." % bp)
1400 1402 error(msg)
1401 1403 return
1402 1404 # if we find a good linenumber, set the breakpoint
1403 1405 deb.do_break('%s:%s' % (filename,bp))
1404 1406 # Start file run
1405 1407 print "NOTE: Enter 'c' at the",
1406 1408 print "ipdb> prompt to start your script."
1407 1409 try:
1408 1410 deb.run('execfile("%s")' % filename,prog_ns)
1409 1411 except:
1410 1412 etype, value, tb = sys.exc_info()
1411 1413 # Skip three frames in the traceback: the %run one,
1412 1414 # one inside bdb.py, and the command-line typed by the
1413 1415 # user (run by exec in pdb itself).
1414 1416 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1415 1417 else:
1416 1418 if runner is None:
1417 1419 runner = self.shell.safe_execfile
1418 1420 if opts.has_key('t'):
1419 1421 try:
1420 1422 nruns = int(opts['N'][0])
1421 1423 if nruns < 1:
1422 1424 error('Number of runs must be >=1')
1423 1425 return
1424 1426 except (KeyError):
1425 1427 nruns = 1
1426 1428 if nruns == 1:
1427 1429 t0 = clock2()
1428 1430 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1429 1431 t1 = clock2()
1430 1432 t_usr = t1[0]-t0[0]
1431 1433 t_sys = t1[1]-t1[1]
1432 1434 print "\nIPython CPU timings (estimated):"
1433 1435 print " User : %10s s." % t_usr
1434 1436 print " System: %10s s." % t_sys
1435 1437 else:
1436 1438 runs = range(nruns)
1437 1439 t0 = clock2()
1438 1440 for nr in runs:
1439 1441 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1440 1442 t1 = clock2()
1441 1443 t_usr = t1[0]-t0[0]
1442 1444 t_sys = t1[1]-t1[1]
1443 1445 print "\nIPython CPU timings (estimated):"
1444 1446 print "Total runs performed:",nruns
1445 1447 print " Times : %10s %10s" % ('Total','Per run')
1446 1448 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1447 1449 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1448 1450
1449 1451 else:
1450 1452 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1451 1453 if opts.has_key('i'):
1452 1454 self.shell.user_ns['__name__'] = __name__save
1453 1455 else:
1454 1456 # update IPython interactive namespace
1455 1457 del prog_ns['__name__']
1456 1458 self.shell.user_ns.update(prog_ns)
1457 1459 finally:
1458 1460 sys.argv = save_argv
1459 1461 if restore_main:
1460 1462 sys.modules['__main__'] = restore_main
1461 1463 return stats
1462 1464
1463 1465 def magic_runlog(self, parameter_s =''):
1464 1466 """Run files as logs.
1465 1467
1466 1468 Usage:\\
1467 1469 %runlog file1 file2 ...
1468 1470
1469 1471 Run the named files (treating them as log files) in sequence inside
1470 1472 the interpreter, and return to the prompt. This is much slower than
1471 1473 %run because each line is executed in a try/except block, but it
1472 1474 allows running files with syntax errors in them.
1473 1475
1474 1476 Normally IPython will guess when a file is one of its own logfiles, so
1475 1477 you can typically use %run even for logs. This shorthand allows you to
1476 1478 force any file to be treated as a log file."""
1477 1479
1478 1480 for f in parameter_s.split():
1479 1481 self.shell.safe_execfile(f,self.shell.user_ns,
1480 1482 self.shell.user_ns,islog=1)
1481 1483
1482 1484 def magic_time(self,parameter_s = ''):
1483 1485 """Time execution of a Python statement or expression.
1484 1486
1485 1487 The CPU and wall clock times are printed, and the value of the
1486 1488 expression (if any) is returned. Note that under Win32, system time
1487 1489 is always reported as 0, since it can not be measured.
1488 1490
1489 1491 This function provides very basic timing functionality. In Python
1490 1492 2.3, the timeit module offers more control and sophistication, but for
1491 1493 now IPython supports Python 2.2, so we can not rely on timeit being
1492 1494 present.
1493 1495
1494 1496 Some examples:
1495 1497
1496 1498 In [1]: time 2**128
1497 1499 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1498 1500 Wall time: 0.00
1499 1501 Out[1]: 340282366920938463463374607431768211456L
1500 1502
1501 1503 In [2]: n = 1000000
1502 1504
1503 1505 In [3]: time sum(range(n))
1504 1506 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1505 1507 Wall time: 1.37
1506 1508 Out[3]: 499999500000L
1507 1509
1508 1510 In [4]: time print 'hello world'
1509 1511 hello world
1510 1512 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1511 1513 Wall time: 0.00
1512 1514 """
1513 1515
1514 1516 # fail immediately if the given expression can't be compiled
1515 1517 try:
1516 1518 mode = 'eval'
1517 1519 code = compile(parameter_s,'<timed eval>',mode)
1518 1520 except SyntaxError:
1519 1521 mode = 'exec'
1520 1522 code = compile(parameter_s,'<timed exec>',mode)
1521 1523 # skew measurement as little as possible
1522 1524 glob = self.shell.user_ns
1523 1525 clk = clock2
1524 1526 wtime = time.time
1525 1527 # time execution
1526 1528 wall_st = wtime()
1527 1529 if mode=='eval':
1528 1530 st = clk()
1529 1531 out = eval(code,glob)
1530 1532 end = clk()
1531 1533 else:
1532 1534 st = clk()
1533 1535 exec code in glob
1534 1536 end = clk()
1535 1537 out = None
1536 1538 wall_end = wtime()
1537 1539 # Compute actual times and report
1538 1540 wall_time = wall_end-wall_st
1539 1541 cpu_user = end[0]-st[0]
1540 1542 cpu_sys = end[1]-st[1]
1541 1543 cpu_tot = cpu_user+cpu_sys
1542 1544 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1543 1545 (cpu_user,cpu_sys,cpu_tot)
1544 1546 print "Wall time: %.2f" % wall_time
1545 1547 return out
1546 1548
1547 1549 def magic_macro(self,parameter_s = ''):
1548 1550 """Define a set of input lines as a macro for future re-execution.
1549 1551
1550 1552 Usage:\\
1551 1553 %macro name n1-n2 n3-n4 ... n5 .. n6 ...
1552 1554
1553 1555 This will define a global variable called `name` which is a string
1554 1556 made of joining the slices and lines you specify (n1,n2,... numbers
1555 1557 above) from your input history into a single string. This variable
1556 1558 acts like an automatic function which re-executes those lines as if
1557 1559 you had typed them. You just type 'name' at the prompt and the code
1558 1560 executes.
1559 1561
1560 1562 The notation for indicating number ranges is: n1-n2 means 'use line
1561 1563 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1562 1564 using the lines numbered 5,6 and 7.
1563 1565
1564 1566 Note: as a 'hidden' feature, you can also use traditional python slice
1565 1567 notation, where N:M means numbers N through M-1.
1566 1568
1567 1569 For example, if your history contains (%hist prints it):
1568 1570
1569 1571 44: x=1\\
1570 1572 45: y=3\\
1571 1573 46: z=x+y\\
1572 1574 47: print x\\
1573 1575 48: a=5\\
1574 1576 49: print 'x',x,'y',y\\
1575 1577
1576 1578 you can create a macro with lines 44 through 47 (included) and line 49
1577 1579 called my_macro with:
1578 1580
1579 1581 In [51]: %macro my_macro 44-47 49
1580 1582
1581 1583 Now, typing `my_macro` (without quotes) will re-execute all this code
1582 1584 in one pass.
1583 1585
1584 1586 You don't need to give the line-numbers in order, and any given line
1585 1587 number can appear multiple times. You can assemble macros with any
1586 1588 lines from your input history in any order.
1587 1589
1588 1590 The macro is a simple object which holds its value in an attribute,
1589 1591 but IPython's display system checks for macros and executes them as
1590 1592 code instead of printing them when you type their name.
1591 1593
1592 1594 You can view a macro's contents by explicitly printing it with:
1593 1595
1594 1596 'print macro_name'.
1595 1597
1596 1598 For one-off cases which DON'T contain magic function calls in them you
1597 1599 can obtain similar results by explicitly executing slices from your
1598 1600 input history with:
1599 1601
1600 1602 In [60]: exec In[44:48]+In[49]"""
1601 1603
1602 1604 args = parameter_s.split()
1603 1605 name,ranges = args[0], args[1:]
1604 1606 #print 'rng',ranges # dbg
1605 1607 lines = self.extract_input_slices(ranges)
1606 1608 macro = Macro(lines)
1607 1609 self.shell.user_ns.update({name:macro})
1608 1610 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1609 1611 print 'Macro contents:'
1610 1612 print macro,
1611 1613
1612 1614 def magic_save(self,parameter_s = ''):
1613 1615 """Save a set of lines to a given filename.
1614 1616
1615 1617 Usage:\\
1616 1618 %save filename n1-n2 n3-n4 ... n5 .. n6 ...
1617 1619
1618 1620 This function uses the same syntax as %macro for line extraction, but
1619 1621 instead of creating a macro it saves the resulting string to the
1620 1622 filename you specify.
1621 1623
1622 1624 It adds a '.py' extension to the file if you don't do so yourself, and
1623 1625 it asks for confirmation before overwriting existing files."""
1624 1626
1625 1627 args = parameter_s.split()
1626 1628 fname,ranges = args[0], args[1:]
1627 1629 if not fname.endswith('.py'):
1628 1630 fname += '.py'
1629 1631 if os.path.isfile(fname):
1630 1632 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1631 1633 if ans.lower() not in ['y','yes']:
1632 1634 print 'Operation cancelled.'
1633 1635 return
1634 1636 cmds = ''.join(self.extract_input_slices(ranges))
1635 1637 f = file(fname,'w')
1636 1638 f.write(cmds)
1637 1639 f.close()
1638 1640 print 'The following commands were written to file `%s`:' % fname
1639 1641 print cmds
1640 1642
1641 def magic_ed(self,parameter_s = ''):
1643 def _edit_macro(self,mname,macro):
1644 """open an editor with the macro data in a file"""
1645 filename = self.shell.mktempfile(macro.value)
1646 self.shell.hooks.editor(filename)
1647
1648 # and make a new macro object, to replace the old one
1649 mfile = open(filename)
1650 mvalue = mfile.read()
1651 mfile.close()
1652 self.shell.user_ns[mname] = Macro(mvalue)
1653
1654 def magic_ed(self,parameter_s=''):
1642 1655 """Alias to %edit."""
1643 1656 return self.magic_edit(parameter_s)
1644 1657
1645 def magic_edit(self,parameter_s = '',last_call=['','']):
1658 def magic_edit(self,parameter_s='',last_call=['','']):
1646 1659 """Bring up an editor and execute the resulting code.
1647 1660
1648 1661 Usage:
1649 1662 %edit [options] [args]
1650 1663
1651 1664 %edit runs IPython's editor hook. The default version of this hook is
1652 1665 set to call the __IPYTHON__.rc.editor command. This is read from your
1653 1666 environment variable $EDITOR. If this isn't found, it will default to
1654 1667 vi under Linux/Unix and to notepad under Windows. See the end of this
1655 1668 docstring for how to change the editor hook.
1656 1669
1657 1670 You can also set the value of this editor via the command line option
1658 1671 '-editor' or in your ipythonrc file. This is useful if you wish to use
1659 1672 specifically for IPython an editor different from your typical default
1660 1673 (and for Windows users who typically don't set environment variables).
1661 1674
1662 1675 This command allows you to conveniently edit multi-line code right in
1663 1676 your IPython session.
1664 1677
1665 1678 If called without arguments, %edit opens up an empty editor with a
1666 1679 temporary file and will execute the contents of this file when you
1667 1680 close it (don't forget to save it!).
1668 1681
1669 1682 Options:
1670 1683
1671 1684 -p: this will call the editor with the same data as the previous time
1672 1685 it was used, regardless of how long ago (in your current session) it
1673 1686 was.
1674 1687
1675 1688 -x: do not execute the edited code immediately upon exit. This is
1676 1689 mainly useful if you are editing programs which need to be called with
1677 1690 command line arguments, which you can then do using %run.
1678 1691
1679 1692 Arguments:
1680 1693
1681 1694 If arguments are given, the following possibilites exist:
1682 1695
1683 1696 - The arguments are numbers or pairs of colon-separated numbers (like
1684 1697 1 4:8 9). These are interpreted as lines of previous input to be
1685 1698 loaded into the editor. The syntax is the same of the %macro command.
1686 1699
1687 1700 - If the argument doesn't start with a number, it is evaluated as a
1688 1701 variable and its contents loaded into the editor. You can thus edit
1689 1702 any string which contains python code (including the result of
1690 1703 previous edits).
1691 1704
1692 1705 - If the argument is the name of an object (other than a string),
1693 1706 IPython will try to locate the file where it was defined and open the
1694 1707 editor at the point where it is defined. You can use `%edit function`
1695 1708 to load an editor exactly at the point where 'function' is defined,
1696 1709 edit it and have the file be executed automatically.
1697 1710
1711 If the object is a macro (see %macro for details), this opens up your
1712 specified editor with a temporary file containing the macro's data.
1713 Upon exit, the macro is reloaded with the contents of the file.
1714
1698 1715 Note: opening at an exact line is only supported under Unix, and some
1699 1716 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1700 1717 '+NUMBER' parameter necessary for this feature. Good editors like
1701 1718 (X)Emacs, vi, jed, pico and joe all do.
1702 1719
1703 1720 - If the argument is not found as a variable, IPython will look for a
1704 1721 file with that name (adding .py if necessary) and load it into the
1705 1722 editor. It will execute its contents with execfile() when you exit,
1706 1723 loading any code in the file into your interactive namespace.
1707 1724
1708 1725 After executing your code, %edit will return as output the code you
1709 1726 typed in the editor (except when it was an existing file). This way
1710 1727 you can reload the code in further invocations of %edit as a variable,
1711 1728 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1712 1729 the output.
1713 1730
1714 1731 Note that %edit is also available through the alias %ed.
1715 1732
1716 1733 This is an example of creating a simple function inside the editor and
1717 1734 then modifying it. First, start up the editor:
1718 1735
1719 1736 In [1]: ed\\
1720 1737 Editing... done. Executing edited code...\\
1721 1738 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1722 1739
1723 1740 We can then call the function foo():
1724 1741
1725 1742 In [2]: foo()\\
1726 1743 foo() was defined in an editing session
1727 1744
1728 1745 Now we edit foo. IPython automatically loads the editor with the
1729 1746 (temporary) file where foo() was previously defined:
1730 1747
1731 1748 In [3]: ed foo\\
1732 1749 Editing... done. Executing edited code...
1733 1750
1734 1751 And if we call foo() again we get the modified version:
1735 1752
1736 1753 In [4]: foo()\\
1737 1754 foo() has now been changed!
1738 1755
1739 1756 Here is an example of how to edit a code snippet successive
1740 1757 times. First we call the editor:
1741 1758
1742 1759 In [8]: ed\\
1743 1760 Editing... done. Executing edited code...\\
1744 1761 hello\\
1745 1762 Out[8]: "print 'hello'\\n"
1746 1763
1747 1764 Now we call it again with the previous output (stored in _):
1748 1765
1749 1766 In [9]: ed _\\
1750 1767 Editing... done. Executing edited code...\\
1751 1768 hello world\\
1752 1769 Out[9]: "print 'hello world'\\n"
1753 1770
1754 1771 Now we call it with the output #8 (stored in _8, also as Out[8]):
1755 1772
1756 1773 In [10]: ed _8\\
1757 1774 Editing... done. Executing edited code...\\
1758 1775 hello again\\
1759 1776 Out[10]: "print 'hello again'\\n"
1760 1777
1761 1778
1762 1779 Changing the default editor hook:
1763 1780
1764 1781 If you wish to write your own editor hook, you can put it in a
1765 1782 configuration file which you load at startup time. The default hook
1766 1783 is defined in the IPython.hooks module, and you can use that as a
1767 1784 starting example for further modifications. That file also has
1768 1785 general instructions on how to set a new hook for use once you've
1769 1786 defined it."""
1770 1787
1771 1788 # FIXME: This function has become a convoluted mess. It needs a
1772 1789 # ground-up rewrite with clean, simple logic.
1773 1790
1774 1791 def make_filename(arg):
1775 1792 "Make a filename from the given args"
1776 1793 try:
1777 1794 filename = get_py_filename(arg)
1778 1795 except IOError:
1779 1796 if args.endswith('.py'):
1780 1797 filename = arg
1781 1798 else:
1782 1799 filename = None
1783 1800 return filename
1784 1801
1785 1802 # custom exceptions
1786 1803 class DataIsObject(Exception): pass
1787 1804
1788 1805 opts,args = self.parse_options(parameter_s,'px')
1789 1806
1790 1807 # Default line number value
1791 1808 lineno = None
1792 1809 if opts.has_key('p'):
1793 1810 args = '_%s' % last_call[0]
1794 1811 if not self.shell.user_ns.has_key(args):
1795 1812 args = last_call[1]
1796 1813
1797 1814 # use last_call to remember the state of the previous call, but don't
1798 1815 # let it be clobbered by successive '-p' calls.
1799 1816 try:
1800 1817 last_call[0] = self.shell.outputcache.prompt_count
1801 1818 if not opts.has_key('p'):
1802 1819 last_call[1] = parameter_s
1803 1820 except:
1804 1821 pass
1805 1822
1806 1823 # by default this is done with temp files, except when the given
1807 1824 # arg is a filename
1808 1825 use_temp = 1
1809 1826
1810 1827 if re.match(r'\d',args):
1811 1828 # Mode where user specifies ranges of lines, like in %macro.
1812 1829 # This means that you can't edit files whose names begin with
1813 1830 # numbers this way. Tough.
1814 1831 ranges = args.split()
1815 1832 data = ''.join(self.extract_input_slices(ranges))
1816 1833 elif args.endswith('.py'):
1817 1834 filename = make_filename(args)
1818 1835 data = ''
1819 1836 use_temp = 0
1820 1837 elif args:
1821 1838 try:
1822 1839 # Load the parameter given as a variable. If not a string,
1823 1840 # process it as an object instead (below)
1824 1841
1825 1842 #print '*** args',args,'type',type(args) # dbg
1826 1843 data = eval(args,self.shell.user_ns)
1827 1844 if not type(data) in StringTypes:
1828 1845 raise DataIsObject
1846
1829 1847 except (NameError,SyntaxError):
1830 1848 # given argument is not a variable, try as a filename
1831 1849 filename = make_filename(args)
1832 1850 if filename is None:
1833 1851 warn("Argument given (%s) can't be found as a variable "
1834 1852 "or as a filename." % args)
1835 1853 return
1854
1836 1855 data = ''
1837 1856 use_temp = 0
1838 1857 except DataIsObject:
1858
1859 # macros have a special edit function
1860 if isinstance(data,Macro):
1861 self._edit_macro(args,data)
1862 return
1863
1839 1864 # For objects, try to edit the file where they are defined
1840 1865 try:
1841 1866 filename = inspect.getabsfile(data)
1842 1867 datafile = 1
1843 1868 except TypeError:
1844 1869 filename = make_filename(args)
1845 1870 datafile = 1
1846 1871 warn('Could not find file where `%s` is defined.\n'
1847 1872 'Opening a file named `%s`' % (args,filename))
1848 1873 # Now, make sure we can actually read the source (if it was in
1849 1874 # a temp file it's gone by now).
1850 1875 if datafile:
1851 1876 try:
1852 1877 lineno = inspect.getsourcelines(data)[1]
1853 1878 except IOError:
1854 1879 filename = make_filename(args)
1855 1880 if filename is None:
1856 1881 warn('The file `%s` where `%s` was defined cannot '
1857 1882 'be read.' % (filename,data))
1858 1883 return
1859 1884 use_temp = 0
1860 1885 else:
1861 1886 data = ''
1862 1887
1863 1888 if use_temp:
1864 filename = tempfile.mktemp('.py')
1865 self.shell.tempfiles.append(filename)
1866
1867 if data and use_temp:
1868 tmp_file = open(filename,'w')
1869 tmp_file.write(data)
1870 tmp_file.close()
1889 filename = self.shell.mktempfile(data)
1871 1890
1872 1891 # do actual editing here
1873 1892 print 'Editing...',
1874 1893 sys.stdout.flush()
1875 1894 self.shell.hooks.editor(filename,lineno)
1876 1895 if opts.has_key('x'): # -x prevents actual execution
1877 1896 print
1878 1897 else:
1879 1898 print 'done. Executing edited code...'
1880 1899 try:
1881 1900 self.shell.safe_execfile(filename,self.shell.user_ns)
1882 1901 except IOError,msg:
1883 1902 if msg.filename == filename:
1884 1903 warn('File not found. Did you forget to save?')
1885 1904 return
1886 1905 else:
1887 1906 self.shell.showtraceback()
1888 1907 except:
1889 1908 self.shell.showtraceback()
1890 if use_temp:
1891 contents = open(filename).read()
1892 return contents
1893 1909
1894 1910 def magic_xmode(self,parameter_s = ''):
1895 1911 """Switch modes for the exception handlers.
1896 1912
1897 1913 Valid modes: Plain, Context and Verbose.
1898 1914
1899 1915 If called without arguments, acts as a toggle."""
1900 1916
1901 1917 def xmode_switch_err(name):
1902 1918 warn('Error changing %s exception modes.\n%s' %
1903 1919 (name,sys.exc_info()[1]))
1904 1920
1905 1921 shell = self.shell
1906 1922 new_mode = parameter_s.strip().capitalize()
1907 1923 try:
1908 1924 shell.InteractiveTB.set_mode(mode=new_mode)
1909 1925 print 'Exception reporting mode:',shell.InteractiveTB.mode
1910 1926 except:
1911 1927 xmode_switch_err('user')
1912 1928
1913 1929 # threaded shells use a special handler in sys.excepthook
1914 1930 if shell.isthreaded:
1915 1931 try:
1916 1932 shell.sys_excepthook.set_mode(mode=new_mode)
1917 1933 except:
1918 1934 xmode_switch_err('threaded')
1919 1935
1920 1936 def magic_colors(self,parameter_s = ''):
1921 1937 """Switch color scheme for prompts, info system and exception handlers.
1922 1938
1923 1939 Currently implemented schemes: NoColor, Linux, LightBG.
1924 1940
1925 1941 Color scheme names are not case-sensitive."""
1926 1942
1927 1943 def color_switch_err(name):
1928 1944 warn('Error changing %s color schemes.\n%s' %
1929 1945 (name,sys.exc_info()[1]))
1930 1946
1931 1947
1932 1948 new_scheme = parameter_s.strip()
1933 1949 if not new_scheme:
1934 1950 print 'You must specify a color scheme.'
1935 1951 return
1936 1952 # Under Windows, check for Gary Bishop's readline, which is necessary
1937 1953 # for ANSI coloring
1938 1954 if os.name in ['nt','dos']:
1939 1955 try:
1940 1956 import readline
1941 1957 except ImportError:
1942 1958 has_readline = 0
1943 1959 else:
1944 1960 try:
1945 1961 readline.GetOutputFile()
1946 1962 except AttributeError:
1947 1963 has_readline = 0
1948 1964 else:
1949 1965 has_readline = 1
1950 1966 if not has_readline:
1951 1967 msg = """\
1952 1968 Proper color support under MS Windows requires Gary Bishop's readline library.
1953 1969 You can find it at:
1954 1970 http://sourceforge.net/projects/uncpythontools
1955 1971 Gary's readline needs the ctypes module, from:
1956 1972 http://starship.python.net/crew/theller/ctypes
1957 1973
1958 1974 Defaulting color scheme to 'NoColor'"""
1959 1975 new_scheme = 'NoColor'
1960 1976 warn(msg)
1961 1977 # local shortcut
1962 1978 shell = self.shell
1963 1979
1964 1980 # Set prompt colors
1965 1981 try:
1966 1982 shell.outputcache.set_colors(new_scheme)
1967 1983 except:
1968 1984 color_switch_err('prompt')
1969 1985 else:
1970 1986 shell.rc.colors = \
1971 1987 shell.outputcache.color_table.active_scheme_name
1972 1988 # Set exception colors
1973 1989 try:
1974 1990 shell.InteractiveTB.set_colors(scheme = new_scheme)
1975 1991 shell.SyntaxTB.set_colors(scheme = new_scheme)
1976 1992 except:
1977 1993 color_switch_err('exception')
1978 1994
1979 1995 # threaded shells use a verbose traceback in sys.excepthook
1980 1996 if shell.isthreaded:
1981 1997 try:
1982 1998 shell.sys_excepthook.set_colors(scheme=new_scheme)
1983 1999 except:
1984 2000 color_switch_err('system exception handler')
1985 2001
1986 2002 # Set info (for 'object?') colors
1987 2003 if shell.rc.color_info:
1988 2004 try:
1989 2005 shell.inspector.set_active_scheme(new_scheme)
1990 2006 except:
1991 2007 color_switch_err('object inspector')
1992 2008 else:
1993 2009 shell.inspector.set_active_scheme('NoColor')
1994 2010
1995 2011 def magic_color_info(self,parameter_s = ''):
1996 2012 """Toggle color_info.
1997 2013
1998 2014 The color_info configuration parameter controls whether colors are
1999 2015 used for displaying object details (by things like %psource, %pfile or
2000 2016 the '?' system). This function toggles this value with each call.
2001 2017
2002 2018 Note that unless you have a fairly recent pager (less works better
2003 2019 than more) in your system, using colored object information displays
2004 2020 will not work properly. Test it and see."""
2005 2021
2006 2022 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2007 2023 self.magic_colors(self.shell.rc.colors)
2008 2024 print 'Object introspection functions have now coloring:',
2009 2025 print ['OFF','ON'][self.shell.rc.color_info]
2010 2026
2011 2027 def magic_Pprint(self, parameter_s=''):
2012 2028 """Toggle pretty printing on/off."""
2013 2029
2014 2030 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
2015 2031 print 'Pretty printing has been turned', \
2016 2032 ['OFF','ON'][self.shell.outputcache.Pprint]
2017 2033
2018 2034 def magic_exit(self, parameter_s=''):
2019 2035 """Exit IPython, confirming if configured to do so.
2020 2036
2021 2037 You can configure whether IPython asks for confirmation upon exit by
2022 2038 setting the confirm_exit flag in the ipythonrc file."""
2023 2039
2024 2040 self.shell.exit()
2025 2041
2026 2042 def magic_quit(self, parameter_s=''):
2027 2043 """Exit IPython, confirming if configured to do so (like %exit)"""
2028 2044
2029 2045 self.shell.exit()
2030 2046
2031 2047 def magic_Exit(self, parameter_s=''):
2032 2048 """Exit IPython without confirmation."""
2033 2049
2034 2050 self.shell.exit_now = True
2035 2051
2036 2052 def magic_Quit(self, parameter_s=''):
2037 2053 """Exit IPython without confirmation (like %Exit)."""
2038 2054
2039 2055 self.shell.exit_now = True
2040 2056
2041 2057 #......................................................................
2042 2058 # Functions to implement unix shell-type things
2043 2059
2044 2060 def magic_alias(self, parameter_s = ''):
2045 2061 """Define an alias for a system command.
2046 2062
2047 2063 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2048 2064
2049 2065 Then, typing 'alias_name params' will execute the system command 'cmd
2050 2066 params' (from your underlying operating system).
2051 2067
2052 2068 Aliases have lower precedence than magic functions and Python normal
2053 2069 variables, so if 'foo' is both a Python variable and an alias, the
2054 2070 alias can not be executed until 'del foo' removes the Python variable.
2055 2071
2056 2072 You can use the %l specifier in an alias definition to represent the
2057 2073 whole line when the alias is called. For example:
2058 2074
2059 2075 In [2]: alias all echo "Input in brackets: <%l>"\\
2060 2076 In [3]: all hello world\\
2061 2077 Input in brackets: <hello world>
2062 2078
2063 2079 You can also define aliases with parameters using %s specifiers (one
2064 2080 per parameter):
2065 2081
2066 2082 In [1]: alias parts echo first %s second %s\\
2067 2083 In [2]: %parts A B\\
2068 2084 first A second B\\
2069 2085 In [3]: %parts A\\
2070 2086 Incorrect number of arguments: 2 expected.\\
2071 2087 parts is an alias to: 'echo first %s second %s'
2072 2088
2073 2089 Note that %l and %s are mutually exclusive. You can only use one or
2074 2090 the other in your aliases.
2075 2091
2076 2092 Aliases expand Python variables just like system calls using ! or !!
2077 2093 do: all expressions prefixed with '$' get expanded. For details of
2078 2094 the semantic rules, see PEP-215:
2079 2095 http://www.python.org/peps/pep-0215.html. This is the library used by
2080 2096 IPython for variable expansion. If you want to access a true shell
2081 2097 variable, an extra $ is necessary to prevent its expansion by IPython:
2082 2098
2083 2099 In [6]: alias show echo\\
2084 2100 In [7]: PATH='A Python string'\\
2085 2101 In [8]: show $PATH\\
2086 2102 A Python string\\
2087 2103 In [9]: show $$PATH\\
2088 2104 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2089 2105
2090 2106 You can use the alias facility to acess all of $PATH. See the %rehash
2091 2107 and %rehashx functions, which automatically create aliases for the
2092 2108 contents of your $PATH.
2093 2109
2094 2110 If called with no parameters, %alias prints the current alias table."""
2095 2111
2096 2112 par = parameter_s.strip()
2097 2113 if not par:
2098 2114 if self.shell.rc.automagic:
2099 2115 prechar = ''
2100 2116 else:
2101 2117 prechar = self.shell.ESC_MAGIC
2102 2118 print 'Alias\t\tSystem Command\n'+'-'*30
2103 2119 atab = self.shell.alias_table
2104 2120 aliases = atab.keys()
2105 2121 aliases.sort()
2106 2122 for alias in aliases:
2107 2123 print prechar+alias+'\t\t'+atab[alias][1]
2108 2124 print '-'*30+'\nTotal number of aliases:',len(aliases)
2109 2125 return
2110 2126 try:
2111 2127 alias,cmd = par.split(None,1)
2112 2128 except:
2113 2129 print OInspect.getdoc(self.magic_alias)
2114 2130 else:
2115 2131 nargs = cmd.count('%s')
2116 2132 if nargs>0 and cmd.find('%l')>=0:
2117 2133 error('The %s and %l specifiers are mutually exclusive '
2118 2134 'in alias definitions.')
2119 2135 else: # all looks OK
2120 2136 self.shell.alias_table[alias] = (nargs,cmd)
2121 2137 self.shell.alias_table_validate(verbose=1)
2122 2138 # end magic_alias
2123 2139
2124 2140 def magic_unalias(self, parameter_s = ''):
2125 2141 """Remove an alias"""
2126 2142
2127 2143 aname = parameter_s.strip()
2128 2144 if aname in self.shell.alias_table:
2129 2145 del self.shell.alias_table[aname]
2130 2146
2131 2147 def magic_rehash(self, parameter_s = ''):
2132 2148 """Update the alias table with all entries in $PATH.
2133 2149
2134 2150 This version does no checks on execute permissions or whether the
2135 2151 contents of $PATH are truly files (instead of directories or something
2136 2152 else). For such a safer (but slower) version, use %rehashx."""
2137 2153
2138 2154 # This function (and rehashx) manipulate the alias_table directly
2139 2155 # rather than calling magic_alias, for speed reasons. A rehash on a
2140 2156 # typical Linux box involves several thousand entries, so efficiency
2141 2157 # here is a top concern.
2142 2158
2143 2159 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2144 2160 alias_table = self.shell.alias_table
2145 2161 for pdir in path:
2146 2162 for ff in os.listdir(pdir):
2147 2163 # each entry in the alias table must be (N,name), where
2148 2164 # N is the number of positional arguments of the alias.
2149 2165 alias_table[ff] = (0,ff)
2150 2166 # Make sure the alias table doesn't contain keywords or builtins
2151 2167 self.shell.alias_table_validate()
2152 2168 # Call again init_auto_alias() so we get 'rm -i' and other modified
2153 2169 # aliases since %rehash will probably clobber them
2154 2170 self.shell.init_auto_alias()
2155 2171
2156 2172 def magic_rehashx(self, parameter_s = ''):
2157 2173 """Update the alias table with all executable files in $PATH.
2158 2174
2159 2175 This version explicitly checks that every entry in $PATH is a file
2160 2176 with execute access (os.X_OK), so it is much slower than %rehash.
2161 2177
2162 2178 Under Windows, it checks executability as a match agains a
2163 2179 '|'-separated string of extensions, stored in the IPython config
2164 2180 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2165 2181
2166 2182 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2167 2183 alias_table = self.shell.alias_table
2168 2184
2169 2185 if os.name == 'posix':
2170 2186 isexec = lambda fname:os.path.isfile(fname) and \
2171 2187 os.access(fname,os.X_OK)
2172 2188 else:
2173 2189
2174 2190 try:
2175 2191 winext = os.environ['pathext'].replace(';','|').replace('.','')
2176 2192 except KeyError:
2177 2193 winext = 'exe|com|bat'
2178 2194
2179 2195 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2180 2196 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2181 2197 savedir = os.getcwd()
2182 2198 try:
2183 2199 # write the whole loop for posix/Windows so we don't have an if in
2184 2200 # the innermost part
2185 2201 if os.name == 'posix':
2186 2202 for pdir in path:
2187 2203 os.chdir(pdir)
2188 2204 for ff in os.listdir(pdir):
2189 2205 if isexec(ff):
2190 2206 # each entry in the alias table must be (N,name),
2191 2207 # where N is the number of positional arguments of the
2192 2208 # alias.
2193 2209 alias_table[ff] = (0,ff)
2194 2210 else:
2195 2211 for pdir in path:
2196 2212 os.chdir(pdir)
2197 2213 for ff in os.listdir(pdir):
2198 2214 if isexec(ff):
2199 2215 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2200 2216 # Make sure the alias table doesn't contain keywords or builtins
2201 2217 self.shell.alias_table_validate()
2202 2218 # Call again init_auto_alias() so we get 'rm -i' and other
2203 2219 # modified aliases since %rehashx will probably clobber them
2204 2220 self.shell.init_auto_alias()
2205 2221 finally:
2206 2222 os.chdir(savedir)
2207 2223
2208 2224 def magic_pwd(self, parameter_s = ''):
2209 2225 """Return the current working directory path."""
2210 2226 return os.getcwd()
2211 2227
2212 2228 def magic_cd(self, parameter_s=''):
2213 2229 """Change the current working directory.
2214 2230
2215 2231 This command automatically maintains an internal list of directories
2216 2232 you visit during your IPython session, in the variable _dh. The
2217 2233 command %dhist shows this history nicely formatted.
2218 2234
2219 2235 Usage:
2220 2236
2221 2237 cd 'dir': changes to directory 'dir'.
2222 2238
2223 2239 cd -: changes to the last visited directory.
2224 2240
2225 2241 cd -<n>: changes to the n-th directory in the directory history.
2226 2242
2227 2243 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2228 2244 (note: cd <bookmark_name> is enough if there is no
2229 2245 directory <bookmark_name>, but a bookmark with the name exists.)
2230 2246
2231 2247 Options:
2232 2248
2233 2249 -q: quiet. Do not print the working directory after the cd command is
2234 2250 executed. By default IPython's cd command does print this directory,
2235 2251 since the default prompts do not display path information.
2236 2252
2237 2253 Note that !cd doesn't work for this purpose because the shell where
2238 2254 !command runs is immediately discarded after executing 'command'."""
2239 2255
2240 2256 parameter_s = parameter_s.strip()
2241 2257 bkms = self.shell.persist.get("bookmarks",{})
2242 2258
2243 2259 numcd = re.match(r'(-)(\d+)$',parameter_s)
2244 2260 # jump in directory history by number
2245 2261 if numcd:
2246 2262 nn = int(numcd.group(2))
2247 2263 try:
2248 2264 ps = self.shell.user_ns['_dh'][nn]
2249 2265 except IndexError:
2250 2266 print 'The requested directory does not exist in history.'
2251 2267 return
2252 2268 else:
2253 2269 opts = {}
2254 2270 else:
2255 2271 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2256 2272 # jump to previous
2257 2273 if ps == '-':
2258 2274 try:
2259 2275 ps = self.shell.user_ns['_dh'][-2]
2260 2276 except IndexError:
2261 2277 print 'No previous directory to change to.'
2262 2278 return
2263 2279 # jump to bookmark
2264 2280 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2265 2281 if bkms.has_key(ps):
2266 2282 target = bkms[ps]
2267 2283 print '(bookmark:%s) -> %s' % (ps,target)
2268 2284 ps = target
2269 2285 else:
2270 2286 if bkms:
2271 2287 error("Bookmark '%s' not found. "
2272 2288 "Use '%bookmark -l' to see your bookmarks." % ps)
2273 2289 else:
2274 2290 print "Bookmarks not set - use %bookmark <bookmarkname>"
2275 2291 return
2276 2292
2277 2293 # at this point ps should point to the target dir
2278 2294 if ps:
2279 2295 try:
2280 2296 os.chdir(os.path.expanduser(ps))
2281 2297 except OSError:
2282 2298 print sys.exc_info()[1]
2283 2299 else:
2284 2300 self.shell.user_ns['_dh'].append(os.getcwd())
2285 2301 else:
2286 2302 os.chdir(self.shell.home_dir)
2287 2303 self.shell.user_ns['_dh'].append(os.getcwd())
2288 2304 if not 'q' in opts:
2289 2305 print self.shell.user_ns['_dh'][-1]
2290 2306
2291 2307 def magic_dhist(self, parameter_s=''):
2292 2308 """Print your history of visited directories.
2293 2309
2294 2310 %dhist -> print full history\\
2295 2311 %dhist n -> print last n entries only\\
2296 2312 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2297 2313
2298 2314 This history is automatically maintained by the %cd command, and
2299 2315 always available as the global list variable _dh. You can use %cd -<n>
2300 2316 to go to directory number <n>."""
2301 2317
2302 2318 dh = self.shell.user_ns['_dh']
2303 2319 if parameter_s:
2304 2320 try:
2305 2321 args = map(int,parameter_s.split())
2306 2322 except:
2307 2323 self.arg_err(Magic.magic_dhist)
2308 2324 return
2309 2325 if len(args) == 1:
2310 2326 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2311 2327 elif len(args) == 2:
2312 2328 ini,fin = args
2313 2329 else:
2314 2330 self.arg_err(Magic.magic_dhist)
2315 2331 return
2316 2332 else:
2317 2333 ini,fin = 0,len(dh)
2318 2334 nlprint(dh,
2319 2335 header = 'Directory history (kept in _dh)',
2320 2336 start=ini,stop=fin)
2321 2337
2322 2338 def magic_env(self, parameter_s=''):
2323 2339 """List environment variables."""
2324 2340
2325 2341 return os.environ.data
2326 2342
2327 2343 def magic_pushd(self, parameter_s=''):
2328 2344 """Place the current dir on stack and change directory.
2329 2345
2330 2346 Usage:\\
2331 2347 %pushd ['dirname']
2332 2348
2333 2349 %pushd with no arguments does a %pushd to your home directory.
2334 2350 """
2335 2351 if parameter_s == '': parameter_s = '~'
2336 2352 dir_s = self.shell.dir_stack
2337 2353 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2338 2354 os.path.expanduser(self.shell.dir_stack[0]):
2339 2355 try:
2340 2356 self.magic_cd(parameter_s)
2341 2357 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2342 2358 self.magic_dirs()
2343 2359 except:
2344 2360 print 'Invalid directory'
2345 2361 else:
2346 2362 print 'You are already there!'
2347 2363
2348 2364 def magic_popd(self, parameter_s=''):
2349 2365 """Change to directory popped off the top of the stack.
2350 2366 """
2351 2367 if len (self.shell.dir_stack) > 1:
2352 2368 self.shell.dir_stack.pop(0)
2353 2369 self.magic_cd(self.shell.dir_stack[0])
2354 2370 print self.shell.dir_stack[0]
2355 2371 else:
2356 2372 print "You can't remove the starting directory from the stack:",\
2357 2373 self.shell.dir_stack
2358 2374
2359 2375 def magic_dirs(self, parameter_s=''):
2360 2376 """Return the current directory stack."""
2361 2377
2362 2378 return self.shell.dir_stack[:]
2363 2379
2364 2380 def magic_sc(self, parameter_s=''):
2365 2381 """Shell capture - execute a shell command and capture its output.
2366 2382
2367 2383 %sc [options] varname=command
2368 2384
2369 2385 IPython will run the given command using commands.getoutput(), and
2370 2386 will then update the user's interactive namespace with a variable
2371 2387 called varname, containing the value of the call. Your command can
2372 2388 contain shell wildcards, pipes, etc.
2373 2389
2374 2390 The '=' sign in the syntax is mandatory, and the variable name you
2375 2391 supply must follow Python's standard conventions for valid names.
2376 2392
2377 2393 Options:
2378 2394
2379 2395 -l: list output. Split the output on newlines into a list before
2380 2396 assigning it to the given variable. By default the output is stored
2381 2397 as a single string.
2382 2398
2383 2399 -v: verbose. Print the contents of the variable.
2384 2400
2385 2401 In most cases you should not need to split as a list, because the
2386 2402 returned value is a special type of string which can automatically
2387 2403 provide its contents either as a list (split on newlines) or as a
2388 2404 space-separated string. These are convenient, respectively, either
2389 2405 for sequential processing or to be passed to a shell command.
2390 2406
2391 2407 For example:
2392 2408
2393 2409 # Capture into variable a
2394 2410 In [9]: sc a=ls *py
2395 2411
2396 2412 # a is a string with embedded newlines
2397 2413 In [10]: a
2398 2414 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2399 2415
2400 2416 # which can be seen as a list:
2401 2417 In [11]: a.l
2402 2418 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2403 2419
2404 2420 # or as a whitespace-separated string:
2405 2421 In [12]: a.s
2406 2422 Out[12]: 'setup.py win32_manual_post_install.py'
2407 2423
2408 2424 # a.s is useful to pass as a single command line:
2409 2425 In [13]: !wc -l $a.s
2410 2426 146 setup.py
2411 2427 130 win32_manual_post_install.py
2412 2428 276 total
2413 2429
2414 2430 # while the list form is useful to loop over:
2415 2431 In [14]: for f in a.l:
2416 2432 ....: !wc -l $f
2417 2433 ....:
2418 2434 146 setup.py
2419 2435 130 win32_manual_post_install.py
2420 2436
2421 2437 Similiarly, the lists returned by the -l option are also special, in
2422 2438 the sense that you can equally invoke the .s attribute on them to
2423 2439 automatically get a whitespace-separated string from their contents:
2424 2440
2425 2441 In [1]: sc -l b=ls *py
2426 2442
2427 2443 In [2]: b
2428 2444 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2429 2445
2430 2446 In [3]: b.s
2431 2447 Out[3]: 'setup.py win32_manual_post_install.py'
2432 2448
2433 2449 In summary, both the lists and strings used for ouptut capture have
2434 2450 the following special attributes:
2435 2451
2436 2452 .l (or .list) : value as list.
2437 2453 .n (or .nlstr): value as newline-separated string.
2438 2454 .s (or .spstr): value as space-separated string.
2439 2455 """
2440 2456
2441 2457 opts,args = self.parse_options(parameter_s,'lv')
2442 2458 # Try to get a variable name and command to run
2443 2459 try:
2444 2460 # the variable name must be obtained from the parse_options
2445 2461 # output, which uses shlex.split to strip options out.
2446 2462 var,_ = args.split('=',1)
2447 2463 var = var.strip()
2448 2464 # But the the command has to be extracted from the original input
2449 2465 # parameter_s, not on what parse_options returns, to avoid the
2450 2466 # quote stripping which shlex.split performs on it.
2451 2467 _,cmd = parameter_s.split('=',1)
2452 2468 except ValueError:
2453 2469 var,cmd = '',''
2454 2470 if not var:
2455 2471 error('you must specify a variable to assign the command to.')
2456 2472 return
2457 2473 # If all looks ok, proceed
2458 2474 out,err = self.shell.getoutputerror(cmd)
2459 2475 if err:
2460 2476 print >> Term.cerr,err
2461 2477 if opts.has_key('l'):
2462 2478 out = SList(out.split('\n'))
2463 2479 else:
2464 2480 out = LSString(out)
2465 2481 if opts.has_key('v'):
2466 2482 print '%s ==\n%s' % (var,pformat(out))
2467 2483 self.shell.user_ns.update({var:out})
2468 2484
2469 2485 def magic_sx(self, parameter_s=''):
2470 2486 """Shell execute - run a shell command and capture its output.
2471 2487
2472 2488 %sx command
2473 2489
2474 2490 IPython will run the given command using commands.getoutput(), and
2475 2491 return the result formatted as a list (split on '\\n'). Since the
2476 2492 output is _returned_, it will be stored in ipython's regular output
2477 2493 cache Out[N] and in the '_N' automatic variables.
2478 2494
2479 2495 Notes:
2480 2496
2481 2497 1) If an input line begins with '!!', then %sx is automatically
2482 2498 invoked. That is, while:
2483 2499 !ls
2484 2500 causes ipython to simply issue system('ls'), typing
2485 2501 !!ls
2486 2502 is a shorthand equivalent to:
2487 2503 %sx ls
2488 2504
2489 2505 2) %sx differs from %sc in that %sx automatically splits into a list,
2490 2506 like '%sc -l'. The reason for this is to make it as easy as possible
2491 2507 to process line-oriented shell output via further python commands.
2492 2508 %sc is meant to provide much finer control, but requires more
2493 2509 typing.
2494 2510
2495 2511 3) Just like %sc -l, this is a list with special attributes:
2496 2512
2497 2513 .l (or .list) : value as list.
2498 2514 .n (or .nlstr): value as newline-separated string.
2499 2515 .s (or .spstr): value as whitespace-separated string.
2500 2516
2501 2517 This is very useful when trying to use such lists as arguments to
2502 2518 system commands."""
2503 2519
2504 2520 if parameter_s:
2505 2521 out,err = self.shell.getoutputerror(parameter_s)
2506 2522 if err:
2507 2523 print >> Term.cerr,err
2508 2524 return SList(out.split('\n'))
2509 2525
2510 2526 def magic_bg(self, parameter_s=''):
2511 2527 """Run a job in the background, in a separate thread.
2512 2528
2513 2529 For example,
2514 2530
2515 2531 %bg myfunc(x,y,z=1)
2516 2532
2517 2533 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2518 2534 execution starts, a message will be printed indicating the job
2519 2535 number. If your job number is 5, you can use
2520 2536
2521 2537 myvar = jobs.result(5) or myvar = jobs[5].result
2522 2538
2523 2539 to assign this result to variable 'myvar'.
2524 2540
2525 2541 IPython has a job manager, accessible via the 'jobs' object. You can
2526 2542 type jobs? to get more information about it, and use jobs.<TAB> to see
2527 2543 its attributes. All attributes not starting with an underscore are
2528 2544 meant for public use.
2529 2545
2530 2546 In particular, look at the jobs.new() method, which is used to create
2531 2547 new jobs. This magic %bg function is just a convenience wrapper
2532 2548 around jobs.new(), for expression-based jobs. If you want to create a
2533 2549 new job with an explicit function object and arguments, you must call
2534 2550 jobs.new() directly.
2535 2551
2536 2552 The jobs.new docstring also describes in detail several important
2537 2553 caveats associated with a thread-based model for background job
2538 2554 execution. Type jobs.new? for details.
2539 2555
2540 2556 You can check the status of all jobs with jobs.status().
2541 2557
2542 2558 The jobs variable is set by IPython into the Python builtin namespace.
2543 2559 If you ever declare a variable named 'jobs', you will shadow this
2544 2560 name. You can either delete your global jobs variable to regain
2545 2561 access to the job manager, or make a new name and assign it manually
2546 2562 to the manager (stored in IPython's namespace). For example, to
2547 2563 assign the job manager to the Jobs name, use:
2548 2564
2549 2565 Jobs = __builtins__.jobs"""
2550 2566
2551 2567 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2552 2568
2553 2569 def magic_store(self, parameter_s=''):
2554 2570 """Lightweight persistence for python variables.
2555 2571
2556 2572 Example:
2557 2573
2558 2574 ville@badger[~]|1> A = ['hello',10,'world']\\
2559 2575 ville@badger[~]|2> %store A\\
2560 2576 ville@badger[~]|3> Exit
2561 2577
2562 2578 (IPython session is closed and started again...)
2563 2579
2564 2580 ville@badger:~$ ipython -p pysh\\
2565 2581 ville@badger[~]|1> print A
2566 2582
2567 2583 ['hello', 10, 'world']
2568 2584
2569 2585 Usage:
2570 2586
2571 %store - Show list of all variables and their current values\\
2572 %store <var> - Store the *current* value of the variable to disk\\
2573 %store -d - Remove the variable and its value from storage\\
2574 %store -r - Remove all variables from storage
2587 %store - Show list of all variables and their current values\\
2588 %store <var> - Store the *current* value of the variable to disk\\
2589 %store -d <var> - Remove the variable and its value from storage\\
2590 %store -r - Remove all variables from storage
2575 2591
2576 2592 It should be noted that if you change the value of a variable, you
2577 2593 need to %store it again if you want to persist the new value.
2578 2594
2579 2595 Note also that the variables will need to be pickleable; most basic
2580 2596 python types can be safely %stored.
2581 2597 """
2582 2598
2583 2599 opts,args = self.parse_options(parameter_s,'dr',mode='list')
2584 2600 # delete
2585 2601 if opts.has_key('d'):
2586 2602 try:
2587 2603 todel = args[0]
2588 2604 except IndexError:
2589 2605 error('You must provide the variable to forget')
2590 2606 else:
2591 2607 try:
2592 2608 del self.shell.persist['S:' + todel]
2593 2609 except:
2594 2610 error("Can't delete variable '%s'" % todel)
2595 2611 # reset
2596 2612 elif opts.has_key('r'):
2597 2613 for k in self.shell.persist.keys():
2598 2614 if k.startswith('S:'):
2599 2615 del self.shell.persist[k]
2600 2616
2601 2617 # run without arguments -> list variables & values
2602 2618 elif not args:
2603 2619 vars = [v[2:] for v in self.shell.persist.keys()
2604 2620 if v.startswith('S:')]
2605 2621 vars.sort()
2606 2622 if vars:
2607 2623 size = max(map(len,vars))
2608 2624 else:
2609 2625 size = 0
2610 2626
2611 2627 print 'Stored variables and their in-memory values:'
2612 2628 fmt = '%-'+str(size)+'s -> %s'
2613 2629 get = self.shell.user_ns.get
2614 2630 for var in vars:
2615 2631 # print 30 first characters from every var
2616 2632 print fmt % (var,repr(get(var,'<unavailable>'))[:50])
2617 2633
2618 2634 # default action - store the variable
2619 2635 else:
2620 2636 pickled = pickle.dumps(self.shell.user_ns[args[0] ])
2621 2637 self.shell.persist[ 'S:' + args[0] ] = pickled
2622 2638 print "Stored '%s' (%d bytes)" % (args[0], len(pickled))
2623 2639
2624 2640 def magic_bookmark(self, parameter_s=''):
2625 2641 """Manage IPython's bookmark system.
2626 2642
2627 2643 %bookmark <name> - set bookmark to current dir
2628 2644 %bookmark <name> <dir> - set bookmark to <dir>
2629 2645 %bookmark -l - list all bookmarks
2630 2646 %bookmark -d <name> - remove bookmark
2631 2647 %bookmark -r - remove all bookmarks
2632 2648
2633 2649 You can later on access a bookmarked folder with:
2634 2650 %cd -b <name>
2635 2651 or simply '%cd <name>' if there is no directory called <name> AND
2636 2652 there is such a bookmark defined.
2637 2653
2638 2654 Your bookmarks persist through IPython sessions, but they are
2639 2655 associated with each profile."""
2640 2656
2641 2657 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2642 2658 if len(args) > 2:
2643 2659 error('You can only give at most two arguments')
2644 2660 return
2645 2661
2646 2662 bkms = self.shell.persist.get('bookmarks',{})
2647 2663
2648 2664 if opts.has_key('d'):
2649 2665 try:
2650 2666 todel = args[0]
2651 2667 except IndexError:
2652 2668 error('You must provide a bookmark to delete')
2653 2669 else:
2654 2670 try:
2655 2671 del bkms[todel]
2656 2672 except:
2657 2673 error("Can't delete bookmark '%s'" % todel)
2658 2674 elif opts.has_key('r'):
2659 2675 bkms = {}
2660 2676 elif opts.has_key('l'):
2661 2677 bks = bkms.keys()
2662 2678 bks.sort()
2663 2679 if bks:
2664 2680 size = max(map(len,bks))
2665 2681 else:
2666 2682 size = 0
2667 2683 fmt = '%-'+str(size)+'s -> %s'
2668 2684 print 'Current bookmarks:'
2669 2685 for bk in bks:
2670 2686 print fmt % (bk,bkms[bk])
2671 2687 else:
2672 2688 if not args:
2673 2689 error("You must specify the bookmark name")
2674 2690 elif len(args)==1:
2675 2691 bkms[args[0]] = os.getcwd()
2676 2692 elif len(args)==2:
2677 2693 bkms[args[0]] = args[1]
2678 2694 self.shell.persist['bookmarks'] = bkms
2679 2695
2680 2696 def magic_pycat(self, parameter_s=''):
2681 2697 """Show a syntax-highlighted file through a pager.
2682 2698
2683 2699 This magic is similar to the cat utility, but it will assume the file
2684 2700 to be Python source and will show it with syntax highlighting. """
2685 2701
2686 2702 filename = get_py_filename(parameter_s)
2687 2703 page(self.shell.colorize(file_read(filename)),
2688 2704 screen_lines=self.shell.rc.screen_length)
2689 2705
2690 2706 # end Magic
@@ -1,76 +1,76 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Release data for the IPython project.
3 3
4 $Id: Release.py 987 2005-12-31 23:50:31Z fperez $"""
4 $Id: Release.py 988 2006-01-02 21:21:47Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu>
8 8 #
9 9 # Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and Nathaniel Gray
10 10 # <n8gray@caltech.edu>
11 11 #
12 12 # Distributed under the terms of the BSD License. The full license is in
13 13 # the file COPYING, distributed as part of this software.
14 14 #*****************************************************************************
15 15
16 16 # Name of the package for release purposes. This is the name which labels
17 17 # the tarballs and RPMs made by distutils, so it's best to lowercase it.
18 18 name = 'ipython'
19 19
20 20 # For versions with substrings (like 0.6.16.svn), use an extra . to separate
21 21 # the new substring. We have to avoid using either dashes or underscores,
22 22 # because bdist_rpm does not accept dashes (an RPM) convention, and
23 23 # bdist_deb does not accept underscores (a Debian convention).
24 24
25 version = '0.7.0.rc6'
25 version = '0.7.0.rc7'
26 26
27 revision = '$Revision: 987 $'
27 revision = '$Revision: 988 $'
28 28
29 29 description = "An enhanced interactive Python shell."
30 30
31 31 long_description = \
32 32 """
33 33 IPython provides a replacement for the interactive Python interpreter with
34 34 extra functionality.
35 35
36 36 Main features:
37 37
38 38 * Comprehensive object introspection.
39 39
40 40 * Input history, persistent across sessions.
41 41
42 42 * Caching of output results during a session with automatically generated
43 43 references.
44 44
45 45 * Readline based name completion.
46 46
47 47 * Extensible system of 'magic' commands for controlling the environment and
48 48 performing many tasks related either to IPython or the operating system.
49 49
50 50 * Configuration system with easy switching between different setups (simpler
51 51 than changing $PYTHONSTARTUP environment variables every time).
52 52
53 53 * Session logging and reloading.
54 54
55 55 * Extensible syntax processing for special purpose situations.
56 56
57 57 * Access to the system shell with user-extensible alias system.
58 58
59 59 * Easily embeddable in other Python programs.
60 60
61 61 * Integrated access to the pdb debugger and the Python profiler. """
62 62
63 63 license = 'BSD'
64 64
65 65 authors = {'Fernando' : ('Fernando Perez','fperez@colorado.edu'),
66 66 'Janko' : ('Janko Hauser','jhauser@zscout.de'),
67 67 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu')
68 68 }
69 69
70 70 url = 'http://ipython.scipy.org'
71 71
72 72 download_url = 'http://ipython.scipy.org/dist'
73 73
74 74 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
75 75
76 76 keywords = ['Interactive','Interpreter','Shell']
@@ -1,543 +1,539 b''
1 1 """Word completion for IPython.
2 2
3 3 This module is a fork of the rlcompleter module in the Python standard
4 4 library. The original enhancements made to rlcompleter have been sent
5 5 upstream and were accepted as of Python 2.3, but we need a lot more
6 6 functionality specific to IPython, so this module will continue to live as an
7 7 IPython-specific utility.
8 8
9 9 ---------------------------------------------------------------------------
10 10 Original rlcompleter documentation:
11 11
12 12 This requires the latest extension to the readline module (the
13 13 completes keywords, built-ins and globals in __main__; when completing
14 14 NAME.NAME..., it evaluates (!) the expression up to the last dot and
15 15 completes its attributes.
16 16
17 17 It's very cool to do "import string" type "string.", hit the
18 18 completion key (twice), and see the list of names defined by the
19 19 string module!
20 20
21 21 Tip: to use the tab key as the completion key, call
22 22
23 23 readline.parse_and_bind("tab: complete")
24 24
25 25 Notes:
26 26
27 27 - Exceptions raised by the completer function are *ignored* (and
28 28 generally cause the completion to fail). This is a feature -- since
29 29 readline sets the tty device in raw (or cbreak) mode, printing a
30 30 traceback wouldn't work well without some complicated hoopla to save,
31 31 reset and restore the tty state.
32 32
33 33 - The evaluation of the NAME.NAME... form may cause arbitrary
34 34 application defined code to be executed if an object with a
35 35 __getattr__ hook is found. Since it is the responsibility of the
36 36 application (or the user) to enable this feature, I consider this an
37 37 acceptable risk. More complicated expressions (e.g. function calls or
38 38 indexing operations) are *not* evaluated.
39 39
40 40 - GNU readline is also used by the built-in functions input() and
41 41 raw_input(), and thus these also benefit/suffer from the completer
42 42 features. Clearly an interactive application can benefit by
43 43 specifying its own completer function and using raw_input() for all
44 44 its input.
45 45
46 46 - When the original stdin is not a tty device, GNU readline is never
47 47 used, and this module (and the readline module) are silently inactive.
48 48
49 49 """
50 50
51 51 #*****************************************************************************
52 52 #
53 53 # Since this file is essentially a minimally modified copy of the rlcompleter
54 54 # module which is part of the standard Python distribution, I assume that the
55 55 # proper procedure is to maintain its copyright as belonging to the Python
56 56 # Software Foundation (in addition to my own, for all new code).
57 57 #
58 58 # Copyright (C) 2001 Python Software Foundation, www.python.org
59 59 # Copyright (C) 2001-2005 Fernando Perez. <fperez@colorado.edu>
60 60 #
61 61 # Distributed under the terms of the BSD License. The full license is in
62 62 # the file COPYING, distributed as part of this software.
63 63 #
64 64 #*****************************************************************************
65 65
66 66 import __builtin__
67 67 import __main__
68 68 import glob
69 69 import keyword
70 70 import os
71 71 import re
72 72 import readline
73 73 import sys
74 74 import types
75 75
76 76 from IPython.genutils import shlex_split
77 77
78 78 __all__ = ['Completer','IPCompleter']
79 79
80 80 def get_class_members(cls):
81 81 ret = dir(cls)
82 82 if hasattr(cls,'__bases__'):
83 83 for base in cls.__bases__:
84 84 ret.extend(get_class_members(base))
85 85 return ret
86 86
87 87 class Completer:
88 88 def __init__(self,namespace=None,global_namespace=None):
89 89 """Create a new completer for the command line.
90 90
91 91 Completer([namespace,global_namespace]) -> completer instance.
92 92
93 93 If unspecified, the default namespace where completions are performed
94 94 is __main__ (technically, __main__.__dict__). Namespaces should be
95 95 given as dictionaries.
96 96
97 97 An optional second namespace can be given. This allows the completer
98 98 to handle cases where both the local and global scopes need to be
99 99 distinguished.
100 100
101 101 Completer instances should be used as the completion mechanism of
102 102 readline via the set_completer() call:
103 103
104 104 readline.set_completer(Completer(my_namespace).complete)
105 105 """
106 106
107 107 # some minimal strict typechecks. For some core data structures, I
108 108 # want actual basic python types, not just anything that looks like
109 109 # one. This is especially true for namespaces.
110 110 for ns in (namespace,global_namespace):
111 111 if ns is not None and type(ns) != types.DictType:
112 112 raise TypeError,'namespace must be a dictionary'
113 113
114 114 # Don't bind to namespace quite yet, but flag whether the user wants a
115 115 # specific namespace or to use __main__.__dict__. This will allow us
116 116 # to bind to __main__.__dict__ at completion time, not now.
117 117 if namespace is None:
118 118 self.use_main_ns = 1
119 119 else:
120 120 self.use_main_ns = 0
121 121 self.namespace = namespace
122 122
123 123 # The global namespace, if given, can be bound directly
124 124 if global_namespace is None:
125 125 self.global_namespace = {}
126 126 else:
127 127 self.global_namespace = global_namespace
128 128
129 129 def complete(self, text, state):
130 130 """Return the next possible completion for 'text'.
131 131
132 132 This is called successively with state == 0, 1, 2, ... until it
133 133 returns None. The completion should begin with 'text'.
134 134
135 135 """
136 136 if self.use_main_ns:
137 137 self.namespace = __main__.__dict__
138 138
139 139 if state == 0:
140 140 if "." in text:
141 141 self.matches = self.attr_matches(text)
142 142 else:
143 143 self.matches = self.global_matches(text)
144 144 try:
145 145 return self.matches[state]
146 146 except IndexError:
147 147 return None
148 148
149 149 def global_matches(self, text):
150 150 """Compute matches when text is a simple name.
151 151
152 152 Return a list of all keywords, built-in functions and names currently
153 153 defined in self.namespace or self.global_namespace that match.
154 154
155 155 """
156 156 matches = []
157 157 match_append = matches.append
158 158 n = len(text)
159 159 for lst in [keyword.kwlist,
160 160 __builtin__.__dict__.keys(),
161 161 self.namespace.keys(),
162 162 self.global_namespace.keys()]:
163 163 for word in lst:
164 164 if word[:n] == text and word != "__builtins__":
165 165 match_append(word)
166 166 return matches
167 167
168 168 def attr_matches(self, text):
169 169 """Compute matches when text contains a dot.
170 170
171 171 Assuming the text is of the form NAME.NAME....[NAME], and is
172 172 evaluatable in self.namespace or self.global_namespace, it will be
173 173 evaluated and its attributes (as revealed by dir()) are used as
174 174 possible completions. (For class instances, class members are are
175 175 also considered.)
176 176
177 177 WARNING: this can still invoke arbitrary C code, if an object
178 178 with a __getattr__ hook is evaluated.
179 179
180 180 """
181 181 import re
182 182
183 183 # Another option, seems to work great. Catches things like ''.<tab>
184 184 m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
185 185
186 186 if not m:
187 187 return []
188 188
189 189 expr, attr = m.group(1, 3)
190 190 try:
191 191 object = eval(expr, self.namespace)
192 192 except:
193 193 object = eval(expr, self.global_namespace)
194 194
195 # for modules which define __all__, complete only on those.
196 if type(object) == types.ModuleType and hasattr(object, '__all__'):
197 words = getattr(object, '__all__')
198 else:
199 words = dir(object)
200 if hasattr(object,'__class__'):
201 words.append('__class__')
202 words.extend(get_class_members(object.__class__))
195 words = dir(object)
196 if hasattr(object,'__class__'):
197 words.append('__class__')
198 words.extend(get_class_members(object.__class__))
203 199
204 200 # filter out non-string attributes which may be stuffed by dir() calls
205 201 # and poor coding in third-party modules
206 202 words = [w for w in words
207 203 if isinstance(w, basestring) and w != "__builtins__"]
208 204 # Build match list to return
209 205 n = len(attr)
210 206 return ["%s.%s" % (expr, w) for w in words if w[:n] == attr ]
211 207
212 208 class IPCompleter(Completer):
213 209 """Extension of the completer class with IPython-specific features"""
214 210
215 211 def __init__(self,shell,namespace=None,global_namespace=None,
216 212 omit__names=0,alias_table=None):
217 213 """IPCompleter() -> completer
218 214
219 215 Return a completer object suitable for use by the readline library
220 216 via readline.set_completer().
221 217
222 218 Inputs:
223 219
224 220 - shell: a pointer to the ipython shell itself. This is needed
225 221 because this completer knows about magic functions, and those can
226 222 only be accessed via the ipython instance.
227 223
228 224 - namespace: an optional dict where completions are performed.
229 225
230 226 - global_namespace: secondary optional dict for completions, to
231 227 handle cases (such as IPython embedded inside functions) where
232 228 both Python scopes are visible.
233 229
234 230 - The optional omit__names parameter sets the completer to omit the
235 231 'magic' names (__magicname__) for python objects unless the text
236 232 to be completed explicitly starts with one or more underscores.
237 233
238 234 - If alias_table is supplied, it should be a dictionary of aliases
239 235 to complete. """
240 236
241 237 Completer.__init__(self,namespace,global_namespace)
242 238 self.magic_prefix = shell.name+'.magic_'
243 239 self.magic_escape = shell.ESC_MAGIC
244 240 self.readline = readline
245 241 delims = self.readline.get_completer_delims()
246 242 delims = delims.replace(self.magic_escape,'')
247 243 self.readline.set_completer_delims(delims)
248 244 self.get_line_buffer = self.readline.get_line_buffer
249 245 self.omit__names = omit__names
250 246 self.merge_completions = shell.rc.readline_merge_completions
251 247
252 248 if alias_table is None:
253 249 alias_table = {}
254 250 self.alias_table = alias_table
255 251 # Regexp to split filenames with spaces in them
256 252 self.space_name_re = re.compile(r'([^\\] )')
257 253 # Hold a local ref. to glob.glob for speed
258 254 self.glob = glob.glob
259 255
260 256 # Determine if we are running on 'dumb' terminals, like (X)Emacs
261 257 # buffers, to avoid completion problems.
262 258 term = os.environ.get('TERM','xterm')
263 259 self.dumb_terminal = term in ['dumb','emacs']
264 260
265 261 # Special handling of backslashes needed in win32 platforms
266 262 if sys.platform == "win32":
267 263 self.clean_glob = self._clean_glob_win32
268 264 else:
269 265 self.clean_glob = self._clean_glob
270 266 self.matchers = [self.python_matches,
271 267 self.file_matches,
272 268 self.alias_matches,
273 269 self.python_func_kw_matches]
274 270
275 271 # Code contributed by Alex Schmolck, for ipython/emacs integration
276 272 def all_completions(self, text):
277 273 """Return all possible completions for the benefit of emacs."""
278 274
279 275 completions = []
280 276 comp_append = completions.append
281 277 try:
282 278 for i in xrange(sys.maxint):
283 279 res = self.complete(text, i)
284 280
285 281 if not res: break
286 282
287 283 comp_append(res)
288 284 #XXX workaround for ``notDefined.<tab>``
289 285 except NameError:
290 286 pass
291 287 return completions
292 288 # /end Alex Schmolck code.
293 289
294 290 def _clean_glob(self,text):
295 291 return self.glob("%s*" % text)
296 292
297 293 def _clean_glob_win32(self,text):
298 294 return [f.replace("\\","/")
299 295 for f in self.glob("%s*" % text)]
300 296
301 297 def file_matches(self, text):
302 298 """Match filneames, expanding ~USER type strings.
303 299
304 300 Most of the seemingly convoluted logic in this completer is an
305 301 attempt to handle filenames with spaces in them. And yet it's not
306 302 quite perfect, because Python's readline doesn't expose all of the
307 303 GNU readline details needed for this to be done correctly.
308 304
309 305 For a filename with a space in it, the printed completions will be
310 306 only the parts after what's already been typed (instead of the
311 307 full completions, as is normally done). I don't think with the
312 308 current (as of Python 2.3) Python readline it's possible to do
313 309 better."""
314 310
315 311 #print 'Completer->file_matches: <%s>' % text # dbg
316 312
317 313 # chars that require escaping with backslash - i.e. chars
318 314 # that readline treats incorrectly as delimiters, but we
319 315 # don't want to treat as delimiters in filename matching
320 316 # when escaped with backslash
321 317
322 318 protectables = ' ()[]{}'
323 319
324 320 def protect_filename(s):
325 321 return "".join([(ch in protectables and '\\' + ch or ch)
326 322 for ch in s])
327 323
328 324 lbuf = self.get_line_buffer()[:self.readline.get_endidx()]
329 325 open_quotes = 0 # track strings with open quotes
330 326 try:
331 327 lsplit = shlex_split(lbuf)[-1]
332 328 except ValueError:
333 329 # typically an unmatched ", or backslash without escaped char.
334 330 if lbuf.count('"')==1:
335 331 open_quotes = 1
336 332 lsplit = lbuf.split('"')[-1]
337 333 elif lbuf.count("'")==1:
338 334 open_quotes = 1
339 335 lsplit = lbuf.split("'")[-1]
340 336 else:
341 337 return None
342 338 except IndexError:
343 339 # tab pressed on empty line
344 340 lsplit = ""
345 341
346 342 if lsplit != protect_filename(lsplit):
347 343 # if protectables are found, do matching on the whole escaped
348 344 # name
349 345 has_protectables = 1
350 346 text0,text = text,lsplit
351 347 else:
352 348 has_protectables = 0
353 349 text = os.path.expanduser(text)
354 350
355 351 if text == "":
356 352 return [protect_filename(f) for f in self.glob("*")]
357 353
358 354 m0 = self.clean_glob(text.replace('\\',''))
359 355 if has_protectables:
360 356 # If we had protectables, we need to revert our changes to the
361 357 # beginning of filename so that we don't double-write the part
362 358 # of the filename we have so far
363 359 len_lsplit = len(lsplit)
364 360 matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0]
365 361 else:
366 362 if open_quotes:
367 363 # if we have a string with an open quote, we don't need to
368 364 # protect the names at all (and we _shouldn't_, as it
369 365 # would cause bugs when the filesystem call is made).
370 366 matches = m0
371 367 else:
372 368 matches = [protect_filename(f) for f in m0]
373 369 if len(matches) == 1 and os.path.isdir(matches[0]):
374 370 # Takes care of links to directories also. Use '/'
375 371 # explicitly, even under Windows, so that name completions
376 372 # don't end up escaped.
377 373 matches[0] += '/'
378 374 return matches
379 375
380 376 def alias_matches(self, text):
381 377 """Match internal system aliases"""
382 378 #print 'Completer->alias_matches:',text # dbg
383 379 text = os.path.expanduser(text)
384 380 aliases = self.alias_table.keys()
385 381 if text == "":
386 382 return aliases
387 383 else:
388 384 return [alias for alias in aliases if alias.startswith(text)]
389 385
390 386 def python_matches(self,text):
391 387 """Match attributes or global python names"""
392 388 #print 'Completer->python_matches' # dbg
393 389 if "." in text:
394 390 try:
395 391 matches = self.attr_matches(text)
396 392 if text.endswith('.') and self.omit__names:
397 393 if self.omit__names == 1:
398 394 # true if txt is _not_ a __ name, false otherwise:
399 395 no__name = (lambda txt:
400 396 re.match(r'.*\.__.*?__',txt) is None)
401 397 else:
402 398 # true if txt is _not_ a _ name, false otherwise:
403 399 no__name = (lambda txt:
404 400 re.match(r'.*\._.*?',txt) is None)
405 401 matches = filter(no__name, matches)
406 402 except NameError:
407 403 # catches <undefined attributes>.<tab>
408 404 matches = []
409 405 else:
410 406 matches = self.global_matches(text)
411 407 # this is so completion finds magics when automagic is on:
412 408 if matches == [] and not text.startswith(os.sep):
413 409 matches = self.attr_matches(self.magic_prefix+text)
414 410 return matches
415 411
416 412 def _default_arguments(self, obj):
417 413 """Return the list of default arguments of obj if it is callable,
418 414 or empty list otherwise."""
419 415
420 416 if not (inspect.isfunction(obj) or inspect.ismethod(obj)):
421 417 # for classes, check for __init__,__new__
422 418 if inspect.isclass(obj):
423 419 obj = (getattr(obj,'__init__',None) or
424 420 getattr(obj,'__new__',None))
425 421 # for all others, check if they are __call__able
426 422 elif hasattr(obj, '__call__'):
427 423 obj = obj.__call__
428 424 # XXX: is there a way to handle the builtins ?
429 425 try:
430 426 args,_,_1,defaults = inspect.getargspec(obj)
431 427 if defaults:
432 428 return args[-len(defaults):]
433 429 except TypeError: pass
434 430 return []
435 431
436 432 def python_func_kw_matches(self,text):
437 433 """Match named parameters (kwargs) of the last open function"""
438 434
439 435 if "." in text: # a parameter cannot be dotted
440 436 return []
441 437 try: regexp = self.__funcParamsRegex
442 438 except AttributeError:
443 439 regexp = self.__funcParamsRegex = re.compile(r'''
444 440 '.*?' | # single quoted strings or
445 441 ".*?" | # double quoted strings or
446 442 \w+ | # identifier
447 443 \S # other characters
448 444 ''', re.VERBOSE | re.DOTALL)
449 445 # 1. find the nearest identifier that comes before an unclosed
450 446 # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo"
451 447 tokens = regexp.findall(self.get_line_buffer())
452 448 tokens.reverse()
453 449 iterTokens = iter(tokens); openPar = 0
454 450 for token in iterTokens:
455 451 if token == ')':
456 452 openPar -= 1
457 453 elif token == '(':
458 454 openPar += 1
459 455 if openPar > 0:
460 456 # found the last unclosed parenthesis
461 457 break
462 458 else:
463 459 return []
464 460 # 2. Concatenate dotted names ("foo.bar" for "foo.bar(x, pa" )
465 461 ids = []
466 462 isId = re.compile(r'\w+$').match
467 463 while True:
468 464 try:
469 465 ids.append(iterTokens.next())
470 466 if not isId(ids[-1]):
471 467 ids.pop(); break
472 468 if not iterTokens.next() == '.':
473 469 break
474 470 except StopIteration:
475 471 break
476 472 # lookup the candidate callable matches either using global_matches
477 473 # or attr_matches for dotted names
478 474 if len(ids) == 1:
479 475 callableMatches = self.global_matches(ids[0])
480 476 else:
481 477 callableMatches = self.attr_matches('.'.join(ids[::-1]))
482 478 argMatches = []
483 479 for callableMatch in callableMatches:
484 480 try: namedArgs = self._default_arguments(eval(callableMatch,
485 481 self.namespace))
486 482 except: continue
487 483 for namedArg in namedArgs:
488 484 if namedArg.startswith(text):
489 485 argMatches.append("%s=" %namedArg)
490 486 return argMatches
491 487
492 488 def complete(self, text, state):
493 489 """Return the next possible completion for 'text'.
494 490
495 491 This is called successively with state == 0, 1, 2, ... until it
496 492 returns None. The completion should begin with 'text'. """
497 493
498 494 #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg
499 495
500 496 # if there is only a tab on a line with only whitespace, instead
501 497 # of the mostly useless 'do you want to see all million
502 498 # completions' message, just do the right thing and give the user
503 499 # his tab! Incidentally, this enables pasting of tabbed text from
504 500 # an editor (as long as autoindent is off).
505 501
506 502 # don't apply this on 'dumb' terminals, such as emacs buffers, so we
507 503 # don't interfere with their own tab-completion mechanism.
508 504 if not (self.dumb_terminal or self.get_line_buffer().strip()):
509 505 self.readline.insert_text('\t')
510 506 return None
511 507
512 508 magic_escape = self.magic_escape
513 509 magic_prefix = self.magic_prefix
514 510
515 511 try:
516 512 if text.startswith(magic_escape):
517 513 text = text.replace(magic_escape,magic_prefix)
518 514 elif text.startswith('~'):
519 515 text = os.path.expanduser(text)
520 516 if state == 0:
521 517 # Extend the list of completions with the results of each
522 518 # matcher, so we return results to the user from all
523 519 # namespaces.
524 520 if self.merge_completions:
525 521 self.matches = []
526 522 for matcher in self.matchers:
527 523 self.matches.extend(matcher(text))
528 524 else:
529 525 for matcher in self.matchers:
530 526 self.matches = matcher(text)
531 527 if self.matches:
532 528 break
533 529
534 530 try:
535 531 return self.matches[state].replace(magic_prefix,magic_escape)
536 532 except IndexError:
537 533 return None
538 534 except:
539 535 #from IPython.ultraTB import AutoFormattedTB; # dbg
540 536 #tb=AutoFormattedTB('Verbose');tb() #dbg
541 537
542 538 # If completion fails, don't annoy the user.
543 539 return None
@@ -1,95 +1,95 b''
1 1 """hooks for IPython.
2 2
3 3 In Python, it is possible to overwrite any method of any object if you really
4 4 want to. But IPython exposes a few 'hooks', methods which are _designed_ to
5 5 be overwritten by users for customization purposes. This module defines the
6 6 default versions of all such hooks, which get used by IPython if not
7 7 overridden by the user.
8 8
9 9 hooks are simple functions, but they should be declared with 'self' as their
10 10 first argument, because when activated they are registered into IPython as
11 11 instance methods. The self argument will be the IPython running instance
12 12 itself, so hooks have full access to the entire IPython object.
13 13
14 14 If you wish to define a new hook and activate it, you need to put the
15 15 necessary code into a python file which can be either imported or execfile()'d
16 16 from within your ipythonrc configuration.
17 17
18 18 For example, suppose that you have a module called 'myiphooks' in your
19 19 PYTHONPATH, which contains the following definition:
20 20
21 21 import os
22 22 def calljed(self,filename, linenum):
23 23 "My editor hook calls the jed editor directly."
24 24 print "Calling my own editor, jed ..."
25 25 os.system('jed +%d %s' % (linenum,filename))
26 26
27 27 You can then execute the following line of code to make it the new IPython
28 28 editor hook, after having imported 'myiphooks':
29 29
30 30 ip_set_hook('editor',myiphooks.calljed)
31 31
32 32 The ip_set_hook function is put by IPython into the builtin namespace, so it
33 33 is always available from all running code.
34 34
35 $Id: hooks.py 960 2005-12-28 06:51:01Z fperez $"""
35 $Id: hooks.py 988 2006-01-02 21:21:47Z fperez $"""
36 36
37 37 #*****************************************************************************
38 38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
39 39 #
40 40 # Distributed under the terms of the BSD License. The full license is in
41 41 # the file COPYING, distributed as part of this software.
42 42 #*****************************************************************************
43 43
44 44 from IPython import Release
45 45 __author__ = '%s <%s>' % Release.authors['Fernando']
46 46 __license__ = Release.license
47 47 __version__ = Release.version
48 48
49 49 import os
50 50
51 51 # List here all the default hooks. For now it's just the editor functions
52 52 # but over time we'll move here all the public API for user-accessible things.
53 53 __all__ = ['editor', 'fix_error_editor']
54 54
55 def editor(self,filename, linenum):
55 def editor(self,filename, linenum=None):
56 56 """Open the default editor at the given filename and linenumber.
57 57
58 58 This is IPython's default editor hook, you can use it as an example to
59 59 write your own modified one. To set your own editor function as the
60 60 new editor hook, call ip_set_hook('editor',yourfunc)."""
61 61
62 62 # IPython configures a default editor at startup by reading $EDITOR from
63 63 # the environment, and falling back on vi (unix) or notepad (win32).
64 64 editor = self.rc.editor
65 65
66 66 # marker for at which line to open the file (for existing objects)
67 67 if linenum is None or editor=='notepad':
68 68 linemark = ''
69 69 else:
70 70 linemark = '+%d' % linenum
71 71 # Call the actual editor
72 72 os.system('%s %s %s' % (editor,linemark,filename))
73 73
74 74 import tempfile
75 75 def fix_error_editor(self,filename,linenum,column,msg):
76 76 """Open the editor at the given filename, linenumber, column and
77 77 show an error message. This is used for correcting syntax errors.
78 78 The current implementation only has special support for the VIM editor,
79 79 and falls back on the 'editor' hook if VIM is not used.
80 80
81 81 Call ip_set_hook('fix_error_editor',youfunc) to use your own function,
82 82 """
83 83 def vim_quickfix_file():
84 84 t = tempfile.NamedTemporaryFile()
85 85 t.write('%s:%d:%d:%s\n' % (filename,linenum,column,msg))
86 86 t.flush()
87 87 return t
88 88 if os.path.basename(self.rc.editor) != 'vim':
89 89 self.hooks.editor(filename,linenum)
90 90 return
91 91 t = vim_quickfix_file()
92 92 try:
93 93 os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name)
94 94 finally:
95 95 t.close()
@@ -1,2065 +1,2138 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 IPython -- An enhanced Interactive Python
4 4
5 5 Requires Python 2.1 or newer.
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 987 2005-12-31 23:50:31Z fperez $
9 $Id: iplib.py 988 2006-01-02 21:21:47Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
13 13 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
14 14 # Copyright (C) 2001-2005 Fernando Perez. <fperez@colorado.edu>
15 15 #
16 16 # Distributed under the terms of the BSD License. The full license is in
17 17 # the file COPYING, distributed as part of this software.
18 18 #
19 19 # Note: this code originally subclassed code.InteractiveConsole from the
20 20 # Python standard library. Over time, all of that class has been copied
21 21 # verbatim here for modifications which could not be accomplished by
22 22 # subclassing. At this point, there are no dependencies at all on the code
23 23 # module anymore (it is not even imported). The Python License (sec. 2)
24 24 # allows for this, but it's always nice to acknowledge credit where credit is
25 25 # due.
26 26 #*****************************************************************************
27 27
28 28 #****************************************************************************
29 29 # Modules and globals
30 30
31 31 from __future__ import generators # for 2.2 backwards-compatibility
32 32
33 33 from IPython import Release
34 34 __author__ = '%s <%s>\n%s <%s>' % \
35 35 ( Release.authors['Janko'] + Release.authors['Fernando'] )
36 36 __license__ = Release.license
37 37 __version__ = Release.version
38 38
39 39 # Python standard modules
40 40 import __main__
41 41 import __builtin__
42 42 import StringIO
43 43 import bdb
44 44 import cPickle as pickle
45 45 import codeop
46 46 import exceptions
47 47 import glob
48 48 import inspect
49 49 import keyword
50 50 import new
51 51 import os
52 52 import pdb
53 53 import pydoc
54 54 import re
55 55 import shutil
56 56 import string
57 57 import sys
58 import tempfile
58 59 import traceback
59 60 import types
60 61
61 62 from pprint import pprint, pformat
62 63
63 64 # IPython's own modules
64 65 import IPython
65 66 from IPython import OInspect,PyColorize,ultraTB
66 67 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
67 68 from IPython.FakeModule import FakeModule
68 69 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
69 70 from IPython.Logger import Logger
70 71 from IPython.Magic import Magic
71 72 from IPython.Prompts import CachedOutput
72 73 from IPython.Struct import Struct
73 74 from IPython.background_jobs import BackgroundJobManager
74 75 from IPython.usage import cmd_line_usage,interactive_usage
75 76 from IPython.genutils import *
76 77
77 78 # store the builtin raw_input globally, and use this always, in case user code
78 79 # overwrites it (like wx.py.PyShell does)
79 80 raw_input_original = raw_input
80 81
81 82 # compiled regexps for autoindent management
82 83 ini_spaces_re = re.compile(r'^(\s+)')
83 84 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
84 85
85 86 #****************************************************************************
86 87 # Some utility function definitions
87 88
88 89 def softspace(file, newvalue):
89 90 """Copied from code.py, to remove the dependency"""
90 91 oldvalue = 0
91 92 try:
92 93 oldvalue = file.softspace
93 94 except AttributeError:
94 95 pass
95 96 try:
96 97 file.softspace = newvalue
97 98 except (AttributeError, TypeError):
98 99 # "attribute-less object" or "read-only attributes"
99 100 pass
100 101 return oldvalue
101 102
102 103 #****************************************************************************
103 # These special functions get installed in the builtin namespace, to provide
104 # programmatic (pure python) access to magics, aliases and system calls. This
105 # is important for logging, user scripting, and more.
106
107 # We are basically exposing, via normal python functions, the three mechanisms
108 # in which ipython offers special call modes (magics for internal control,
109 # aliases for direct system access via pre-selected names, and !cmd for
110 # calling arbitrary system commands).
111
112 def ipmagic(arg_s):
113 """Call a magic function by name.
114
115 Input: a string containing the name of the magic function to call and any
116 additional arguments to be passed to the magic.
117
118 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
119 prompt:
120
121 In[1]: %name -opt foo bar
122
123 To call a magic without arguments, simply use ipmagic('name').
124
125 This provides a proper Python function to call IPython's magics in any
126 valid Python code you can type at the interpreter, including loops and
127 compound statements. It is added by IPython to the Python builtin
128 namespace upon initialization."""
129
130 args = arg_s.split(' ',1)
131 magic_name = args[0]
132 if magic_name.startswith(__IPYTHON__.ESC_MAGIC):
133 magic_name = magic_name[1:]
134 try:
135 magic_args = args[1]
136 except IndexError:
137 magic_args = ''
138 fn = getattr(__IPYTHON__,'magic_'+magic_name,None)
139 if fn is None:
140 error("Magic function `%s` not found." % magic_name)
141 else:
142 magic_args = __IPYTHON__.var_expand(magic_args)
143 return fn(magic_args)
144
145 def ipalias(arg_s):
146 """Call an alias by name.
147
148 Input: a string containing the name of the alias to call and any
149 additional arguments to be passed to the magic.
150
151 ipalias('name -opt foo bar') is equivalent to typing at the ipython
152 prompt:
153
154 In[1]: name -opt foo bar
155
156 To call an alias without arguments, simply use ipalias('name').
157
158 This provides a proper Python function to call IPython's aliases in any
159 valid Python code you can type at the interpreter, including loops and
160 compound statements. It is added by IPython to the Python builtin
161 namespace upon initialization."""
162
163 args = arg_s.split(' ',1)
164 alias_name = args[0]
165 try:
166 alias_args = args[1]
167 except IndexError:
168 alias_args = ''
169 if alias_name in __IPYTHON__.alias_table:
170 __IPYTHON__.call_alias(alias_name,alias_args)
171 else:
172 error("Alias `%s` not found." % alias_name)
173
174 def ipsystem(arg_s):
175 """Make a system call, using IPython."""
176 __IPYTHON__.system(arg_s)
177 104
178 105
179 106 #****************************************************************************
180 107 # Local use exceptions
181 108 class SpaceInInput(exceptions.Exception): pass
182 109
183 110 #****************************************************************************
184 111 # Local use classes
185 112 class Bunch: pass
186 113
114 class Undefined: pass
115
187 116 class InputList(list):
188 117 """Class to store user input.
189 118
190 119 It's basically a list, but slices return a string instead of a list, thus
191 120 allowing things like (assuming 'In' is an instance):
192 121
193 122 exec In[4:7]
194 123
195 124 or
196 125
197 126 exec In[5:9] + In[14] + In[21:25]"""
198 127
199 128 def __getslice__(self,i,j):
200 129 return ''.join(list.__getslice__(self,i,j))
201 130
202 131 class SyntaxTB(ultraTB.ListTB):
203 132 """Extension which holds some state: the last exception value"""
204 133
205 134 def __init__(self,color_scheme = 'NoColor'):
206 135 ultraTB.ListTB.__init__(self,color_scheme)
207 136 self.last_syntax_error = None
208 137
209 138 def __call__(self, etype, value, elist):
210 139 self.last_syntax_error = value
211 140 ultraTB.ListTB.__call__(self,etype,value,elist)
212 141
213 142 def clear_err_state(self):
214 143 """Return the current error state and clear it"""
215 144 e = self.last_syntax_error
216 145 self.last_syntax_error = None
217 146 return e
218 147
219 148 #****************************************************************************
220 149 # Main IPython class
221 150
222 151 # FIXME: the Magic class is a mixin for now, and will unfortunately remain so
223 152 # until a full rewrite is made. I've cleaned all cross-class uses of
224 153 # attributes and methods, but too much user code out there relies on the
225 154 # equlity %foo == __IP.magic_foo, so I can't actually remove the mixin usage.
226 155 #
227 156 # But at least now, all the pieces have been separated and we could, in
228 157 # principle, stop using the mixin. This will ease the transition to the
229 158 # chainsaw branch.
230 159
231 160 # For reference, the following is the list of 'self.foo' uses in the Magic
232 161 # class as of 2005-12-28. These are names we CAN'T use in the main ipython
233 162 # class, to prevent clashes.
234 163
235 164 # ['self.__class__', 'self.__dict__', 'self._inspect', 'self._ofind',
236 165 # 'self.arg_err', 'self.extract_input', 'self.format_', 'self.lsmagic',
237 166 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
238 167 # 'self.value']
239 168
240 169 class InteractiveShell(object,Magic):
241 170 """An enhanced console for Python."""
242 171
243 172 # class attribute to indicate whether the class supports threads or not.
244 173 # Subclasses with thread support should override this as needed.
245 174 isthreaded = False
246 175
247 176 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
248 177 user_ns = None,user_global_ns=None,banner2='',
249 178 custom_exceptions=((),None),embedded=False):
250 179
251 180 # some minimal strict typechecks. For some core data structures, I
252 181 # want actual basic python types, not just anything that looks like
253 182 # one. This is especially true for namespaces.
254 183 for ns in (user_ns,user_global_ns):
255 184 if ns is not None and type(ns) != types.DictType:
256 185 raise TypeError,'namespace must be a dictionary'
257 186
258 # Put a reference to self in builtins so that any form of embedded or
259 # imported code can test for being inside IPython.
260 __builtin__.__IPYTHON__ = self
261
262 # And load into builtins ipmagic/ipalias/ipsystem as well
263 __builtin__.ipmagic = ipmagic
264 __builtin__.ipalias = ipalias
265 __builtin__.ipsystem = ipsystem
266
267 # Add to __builtin__ other parts of IPython's public API
268 __builtin__.ip_set_hook = self.set_hook
187 # Job manager (for jobs run as background threads)
188 self.jobs = BackgroundJobManager()
269 189
270 # Keep in the builtins a flag for when IPython is active. We set it
271 # with setdefault so that multiple nested IPythons don't clobber one
272 # another. Each will increase its value by one upon being activated,
273 # which also gives us a way to determine the nesting level.
274 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
190 # track which builtins we add, so we can clean up later
191 self.builtins_added = {}
192 # This method will add the necessary builtins for operation, but
193 # tracking what it did via the builtins_added dict.
194 self.add_builtins()
275 195
276 196 # Do the intuitively correct thing for quit/exit: we remove the
277 # builtins if they exist, and our own prefilter routine will handle
278 # these special cases
197 # builtins if they exist, and our own magics will deal with this
279 198 try:
280 199 del __builtin__.exit, __builtin__.quit
281 200 except AttributeError:
282 201 pass
283 202
284 203 # Store the actual shell's name
285 204 self.name = name
286 205
287 206 # We need to know whether the instance is meant for embedding, since
288 207 # global/local namespaces need to be handled differently in that case
289 208 self.embedded = embedded
290 209
291 210 # command compiler
292 211 self.compile = codeop.CommandCompiler()
293 212
294 213 # User input buffer
295 214 self.buffer = []
296 215
297 216 # Default name given in compilation of code
298 217 self.filename = '<ipython console>'
299 218
300 219 # Make an empty namespace, which extension writers can rely on both
301 220 # existing and NEVER being used by ipython itself. This gives them a
302 221 # convenient location for storing additional information and state
303 222 # their extensions may require, without fear of collisions with other
304 223 # ipython names that may develop later.
305 224 self.meta = Bunch()
306 225
307 226 # Create the namespace where the user will operate. user_ns is
308 227 # normally the only one used, and it is passed to the exec calls as
309 228 # the locals argument. But we do carry a user_global_ns namespace
310 229 # given as the exec 'globals' argument, This is useful in embedding
311 230 # situations where the ipython shell opens in a context where the
312 231 # distinction between locals and globals is meaningful.
313 232
314 233 # FIXME. For some strange reason, __builtins__ is showing up at user
315 234 # level as a dict instead of a module. This is a manual fix, but I
316 235 # should really track down where the problem is coming from. Alex
317 236 # Schmolck reported this problem first.
318 237
319 238 # A useful post by Alex Martelli on this topic:
320 239 # Re: inconsistent value from __builtins__
321 240 # Von: Alex Martelli <aleaxit@yahoo.com>
322 241 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
323 242 # Gruppen: comp.lang.python
324 243
325 244 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
326 245 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
327 246 # > <type 'dict'>
328 247 # > >>> print type(__builtins__)
329 248 # > <type 'module'>
330 249 # > Is this difference in return value intentional?
331 250
332 251 # Well, it's documented that '__builtins__' can be either a dictionary
333 252 # or a module, and it's been that way for a long time. Whether it's
334 253 # intentional (or sensible), I don't know. In any case, the idea is
335 254 # that if you need to access the built-in namespace directly, you
336 255 # should start with "import __builtin__" (note, no 's') which will
337 256 # definitely give you a module. Yeah, it's somewhatΒ confusing:-(.
338 257
339 258 if user_ns is None:
340 259 # Set __name__ to __main__ to better match the behavior of the
341 260 # normal interpreter.
342 261 user_ns = {'__name__' :'__main__',
343 262 '__builtins__' : __builtin__,
344 263 }
345 264
346 265 if user_global_ns is None:
347 266 user_global_ns = {}
348 267
349 268 # Assign namespaces
350 269 # This is the namespace where all normal user variables live
351 270 self.user_ns = user_ns
352 271 # Embedded instances require a separate namespace for globals.
353 272 # Normally this one is unused by non-embedded instances.
354 273 self.user_global_ns = user_global_ns
355 274 # A namespace to keep track of internal data structures to prevent
356 275 # them from cluttering user-visible stuff. Will be updated later
357 276 self.internal_ns = {}
358 277
359 278 # Namespace of system aliases. Each entry in the alias
360 279 # table must be a 2-tuple of the form (N,name), where N is the number
361 280 # of positional arguments of the alias.
362 281 self.alias_table = {}
363 282
364 283 # A table holding all the namespaces IPython deals with, so that
365 284 # introspection facilities can search easily.
366 285 self.ns_table = {'user':user_ns,
367 286 'user_global':user_global_ns,
368 287 'alias':self.alias_table,
369 288 'internal':self.internal_ns,
370 289 'builtin':__builtin__.__dict__
371 290 }
372 291
373 292 # The user namespace MUST have a pointer to the shell itself.
374 293 self.user_ns[name] = self
375 294
376 295 # We need to insert into sys.modules something that looks like a
377 296 # module but which accesses the IPython namespace, for shelve and
378 297 # pickle to work interactively. Normally they rely on getting
379 298 # everything out of __main__, but for embedding purposes each IPython
380 299 # instance has its own private namespace, so we can't go shoving
381 300 # everything into __main__.
382 301
383 302 # note, however, that we should only do this for non-embedded
384 303 # ipythons, which really mimic the __main__.__dict__ with their own
385 304 # namespace. Embedded instances, on the other hand, should not do
386 305 # this because they need to manage the user local/global namespaces
387 306 # only, but they live within a 'normal' __main__ (meaning, they
388 307 # shouldn't overtake the execution environment of the script they're
389 308 # embedded in).
390 309
391 310 if not embedded:
392 311 try:
393 312 main_name = self.user_ns['__name__']
394 313 except KeyError:
395 314 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
396 315 else:
397 316 #print "pickle hack in place" # dbg
398 317 #print 'main_name:',main_name # dbg
399 318 sys.modules[main_name] = FakeModule(self.user_ns)
400 319
401 320 # List of input with multi-line handling.
402 321 # Fill its zero entry, user counter starts at 1
403 322 self.input_hist = InputList(['\n'])
404 323
405 324 # list of visited directories
406 325 try:
407 326 self.dir_hist = [os.getcwd()]
408 327 except IOError, e:
409 328 self.dir_hist = []
410 329
411 330 # dict of output history
412 331 self.output_hist = {}
413 332
414 333 # dict of things NOT to alias (keywords, builtins and some magics)
415 334 no_alias = {}
416 335 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
417 336 for key in keyword.kwlist + no_alias_magics:
418 337 no_alias[key] = 1
419 338 no_alias.update(__builtin__.__dict__)
420 339 self.no_alias = no_alias
421 340
422 341 # make global variables for user access to these
423 342 self.user_ns['_ih'] = self.input_hist
424 343 self.user_ns['_oh'] = self.output_hist
425 344 self.user_ns['_dh'] = self.dir_hist
426 345
427 346 # user aliases to input and output histories
428 347 self.user_ns['In'] = self.input_hist
429 348 self.user_ns['Out'] = self.output_hist
430 349
431 350 # Object variable to store code object waiting execution. This is
432 351 # used mainly by the multithreaded shells, but it can come in handy in
433 352 # other situations. No need to use a Queue here, since it's a single
434 353 # item which gets cleared once run.
435 354 self.code_to_run = None
436 355
437 # Job manager (for jobs run as background threads)
438 self.jobs = BackgroundJobManager()
439 # Put the job manager into builtins so it's always there.
440 __builtin__.jobs = self.jobs
441
442 356 # escapes for automatic behavior on the command line
443 357 self.ESC_SHELL = '!'
444 358 self.ESC_HELP = '?'
445 359 self.ESC_MAGIC = '%'
446 360 self.ESC_QUOTE = ','
447 361 self.ESC_QUOTE2 = ';'
448 362 self.ESC_PAREN = '/'
449 363
450 364 # And their associated handlers
451 365 self.esc_handlers = {self.ESC_PAREN : self.handle_auto,
452 366 self.ESC_QUOTE : self.handle_auto,
453 367 self.ESC_QUOTE2 : self.handle_auto,
454 368 self.ESC_MAGIC : self.handle_magic,
455 369 self.ESC_HELP : self.handle_help,
456 370 self.ESC_SHELL : self.handle_shell_escape,
457 371 }
458 372
459 373 # class initializations
460 374 Magic.__init__(self,self)
461 375
462 376 # Python source parser/formatter for syntax highlighting
463 377 pyformat = PyColorize.Parser().format
464 378 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
465 379
466 380 # hooks holds pointers used for user-side customizations
467 381 self.hooks = Struct()
468 382
469 383 # Set all default hooks, defined in the IPython.hooks module.
470 384 hooks = IPython.hooks
471 385 for hook_name in hooks.__all__:
472 386 self.set_hook(hook_name,getattr(hooks,hook_name))
473 387
474 388 # Flag to mark unconditional exit
475 389 self.exit_now = False
476 390
477 391 self.usage_min = """\
478 392 An enhanced console for Python.
479 393 Some of its features are:
480 394 - Readline support if the readline library is present.
481 395 - Tab completion in the local namespace.
482 396 - Logging of input, see command-line options.
483 397 - System shell escape via ! , eg !ls.
484 398 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
485 399 - Keeps track of locally defined variables via %who, %whos.
486 400 - Show object information with a ? eg ?x or x? (use ?? for more info).
487 401 """
488 402 if usage: self.usage = usage
489 403 else: self.usage = self.usage_min
490 404
491 405 # Storage
492 406 self.rc = rc # This will hold all configuration information
493 407 self.pager = 'less'
494 408 # temporary files used for various purposes. Deleted at exit.
495 409 self.tempfiles = []
496 410
497 411 # Keep track of readline usage (later set by init_readline)
498 412 self.has_readline = False
499 413
500 414 # template for logfile headers. It gets resolved at runtime by the
501 415 # logstart method.
502 416 self.loghead_tpl = \
503 417 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
504 418 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
505 419 #log# opts = %s
506 420 #log# args = %s
507 421 #log# It is safe to make manual edits below here.
508 422 #log#-----------------------------------------------------------------------
509 423 """
510 424 # for pushd/popd management
511 425 try:
512 426 self.home_dir = get_home_dir()
513 427 except HomeDirError,msg:
514 428 fatal(msg)
515 429
516 430 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
517 431
518 432 # Functions to call the underlying shell.
519 433
520 434 # utility to expand user variables via Itpl
521 435 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
522 436 self.user_ns))
523 437 # The first is similar to os.system, but it doesn't return a value,
524 438 # and it allows interpolation of variables in the user's namespace.
525 439 self.system = lambda cmd: shell(self.var_expand(cmd),
526 440 header='IPython system call: ',
527 441 verbose=self.rc.system_verbose)
528 442 # These are for getoutput and getoutputerror:
529 443 self.getoutput = lambda cmd: \
530 444 getoutput(self.var_expand(cmd),
531 445 header='IPython system call: ',
532 446 verbose=self.rc.system_verbose)
533 447 self.getoutputerror = lambda cmd: \
534 448 getoutputerror(str(ItplNS(cmd.replace('#','\#'),
535 449 self.user_ns)),
536 450 header='IPython system call: ',
537 451 verbose=self.rc.system_verbose)
538 452
539 453 # RegExp for splitting line contents into pre-char//first
540 454 # word-method//rest. For clarity, each group in on one line.
541 455
542 456 # WARNING: update the regexp if the above escapes are changed, as they
543 457 # are hardwired in.
544 458
545 459 # Don't get carried away with trying to make the autocalling catch too
546 460 # much: it's better to be conservative rather than to trigger hidden
547 461 # evals() somewhere and end up causing side effects.
548 462
549 463 self.line_split = re.compile(r'^([\s*,;/])'
550 464 r'([\?\w\.]+\w*\s*)'
551 465 r'(\(?.*$)')
552 466
553 467 # Original re, keep around for a while in case changes break something
554 468 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
555 469 # r'(\s*[\?\w\.]+\w*\s*)'
556 470 # r'(\(?.*$)')
557 471
558 472 # RegExp to identify potential function names
559 473 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
560 474 # RegExp to exclude strings with this start from autocalling
561 475 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
562 476
563 477 # try to catch also methods for stuff in lists/tuples/dicts: off
564 478 # (experimental). For this to work, the line_split regexp would need
565 479 # to be modified so it wouldn't break things at '['. That line is
566 480 # nasty enough that I shouldn't change it until I can test it _well_.
567 481 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
568 482
569 483 # keep track of where we started running (mainly for crash post-mortem)
570 484 self.starting_dir = os.getcwd()
571 485
572 486 # Various switches which can be set
573 487 self.CACHELENGTH = 5000 # this is cheap, it's just text
574 488 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
575 489 self.banner2 = banner2
576 490
577 491 # TraceBack handlers:
578 492
579 493 # Syntax error handler.
580 494 self.SyntaxTB = SyntaxTB(color_scheme='NoColor')
581 495
582 496 # The interactive one is initialized with an offset, meaning we always
583 497 # want to remove the topmost item in the traceback, which is our own
584 498 # internal code. Valid modes: ['Plain','Context','Verbose']
585 499 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
586 500 color_scheme='NoColor',
587 501 tb_offset = 1)
588 502
589 503 # IPython itself shouldn't crash. This will produce a detailed
590 504 # post-mortem if it does. But we only install the crash handler for
591 505 # non-threaded shells, the threaded ones use a normal verbose reporter
592 506 # and lose the crash handler. This is because exceptions in the main
593 507 # thread (such as in GUI code) propagate directly to sys.excepthook,
594 508 # and there's no point in printing crash dumps for every user exception.
595 509 if self.isthreaded:
596 510 sys.excepthook = ultraTB.FormattedTB()
597 511 else:
598 512 from IPython import CrashHandler
599 513 sys.excepthook = CrashHandler.CrashHandler(self)
600 514
601 515 # The instance will store a pointer to this, so that runtime code
602 516 # (such as magics) can access it. This is because during the
603 517 # read-eval loop, it gets temporarily overwritten (to deal with GUI
604 518 # frameworks).
605 519 self.sys_excepthook = sys.excepthook
606 520
607 521 # and add any custom exception handlers the user may have specified
608 522 self.set_custom_exc(*custom_exceptions)
609 523
610 524 # Object inspector
611 525 self.inspector = OInspect.Inspector(OInspect.InspectColors,
612 526 PyColorize.ANSICodeColors,
613 527 'NoColor')
614 528 # indentation management
615 529 self.autoindent = False
616 530 self.indent_current_nsp = 0
617 531 self.indent_current = '' # actual indent string
618 532
619 533 # Make some aliases automatically
620 534 # Prepare list of shell aliases to auto-define
621 535 if os.name == 'posix':
622 536 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
623 537 'mv mv -i','rm rm -i','cp cp -i',
624 538 'cat cat','less less','clear clear',
625 539 # a better ls
626 540 'ls ls -F',
627 541 # long ls
628 542 'll ls -lF',
629 543 # color ls
630 544 'lc ls -F -o --color',
631 545 # ls normal files only
632 546 'lf ls -F -o --color %l | grep ^-',
633 547 # ls symbolic links
634 548 'lk ls -F -o --color %l | grep ^l',
635 549 # directories or links to directories,
636 550 'ldir ls -F -o --color %l | grep /$',
637 551 # things which are executable
638 552 'lx ls -F -o --color %l | grep ^-..x',
639 553 )
640 554 elif os.name in ['nt','dos']:
641 555 auto_alias = ('dir dir /on', 'ls dir /on',
642 556 'ddir dir /ad /on', 'ldir dir /ad /on',
643 557 'mkdir mkdir','rmdir rmdir','echo echo',
644 558 'ren ren','cls cls','copy copy')
645 559 else:
646 560 auto_alias = ()
647 561 self.auto_alias = map(lambda s:s.split(None,1),auto_alias)
648 562 # Call the actual (public) initializer
649 563 self.init_auto_alias()
650 564 # end __init__
651 565
652 566 def post_config_initialization(self):
653 567 """Post configuration init method
654 568
655 569 This is called after the configuration files have been processed to
656 570 'finalize' the initialization."""
657 571
658 572 rc = self.rc
659 573
660 574 # Load readline proper
661 575 if rc.readline:
662 576 self.init_readline()
663 577
664 578 # log system
665 579 self.logger = Logger(self,logfname='ipython_log.py',logmode='rotate')
666 580 # local shortcut, this is used a LOT
667 581 self.log = self.logger.log
668 582
669 583 # Initialize cache, set in/out prompts and printing system
670 584 self.outputcache = CachedOutput(self,
671 585 rc.cache_size,
672 586 rc.pprint,
673 587 input_sep = rc.separate_in,
674 588 output_sep = rc.separate_out,
675 589 output_sep2 = rc.separate_out2,
676 590 ps1 = rc.prompt_in1,
677 591 ps2 = rc.prompt_in2,
678 592 ps_out = rc.prompt_out,
679 593 pad_left = rc.prompts_pad_left)
680 594
681 595 # user may have over-ridden the default print hook:
682 596 try:
683 597 self.outputcache.__class__.display = self.hooks.display
684 598 except AttributeError:
685 599 pass
686 600
687 601 # I don't like assigning globally to sys, because it means when embedding
688 602 # instances, each embedded instance overrides the previous choice. But
689 603 # sys.displayhook seems to be called internally by exec, so I don't see a
690 604 # way around it.
691 605 sys.displayhook = self.outputcache
692 606
693 607 # Set user colors (don't do it in the constructor above so that it
694 608 # doesn't crash if colors option is invalid)
695 609 self.magic_colors(rc.colors)
696 610
697 611 # Set calling of pdb on exceptions
698 612 self.call_pdb = rc.pdb
699 613
700 614 # Load user aliases
701 615 for alias in rc.alias:
702 616 self.magic_alias(alias)
703 617
704 618 # dynamic data that survives through sessions
705 619 # XXX make the filename a config option?
706 620 persist_base = 'persist'
707 621 if rc.profile:
708 622 persist_base += '_%s' % rc.profile
709 623 self.persist_fname = os.path.join(rc.ipythondir,persist_base)
710 624
711 625 try:
712 626 self.persist = pickle.load(file(self.persist_fname))
713 627 except:
714 628 self.persist = {}
715 629
716 630
717 631 for (key, value) in [(k[2:],v) for (k,v) in self.persist.items() if k.startswith('S:')]:
718 632 try:
719 633 obj = pickle.loads(value)
720 634 except:
721 635
722 636 print "Unable to restore variable '%s', ignoring (use %%store -d to forget!)" % key
723 637 print "The error was:",sys.exc_info()[0]
724 638 continue
725 639
726 640
727 641 self.user_ns[key] = obj
642
643 def add_builtins(self):
644 """Store ipython references into the builtin namespace.
645
646 Some parts of ipython operate via builtins injected here, which hold a
647 reference to IPython itself."""
648
649 builtins_new = dict(__IPYTHON__ = self,
650 ip_set_hook = self.set_hook,
651 jobs = self.jobs,
652 ipmagic = self.ipmagic,
653 ipalias = self.ipalias,
654 ipsystem = self.ipsystem,
655 )
656 for biname,bival in builtins_new.items():
657 try:
658 # store the orignal value so we can restore it
659 self.builtins_added[biname] = __builtin__.__dict__[biname]
660 except KeyError:
661 # or mark that it wasn't defined, and we'll just delete it at
662 # cleanup
663 self.builtins_added[biname] = Undefined
664 __builtin__.__dict__[biname] = bival
665
666 # Keep in the builtins a flag for when IPython is active. We set it
667 # with setdefault so that multiple nested IPythons don't clobber one
668 # another. Each will increase its value by one upon being activated,
669 # which also gives us a way to determine the nesting level.
670 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
671
672 def clean_builtins(self):
673 """Remove any builtins which might have been added by add_builtins, or
674 restore overwritten ones to their previous values."""
675 for biname,bival in self.builtins_added.items():
676 if bival is Undefined:
677 del __builtin__.__dict__[biname]
678 else:
679 __builtin__.__dict__[biname] = bival
680 self.builtins_added.clear()
728 681
729 682 def set_hook(self,name,hook):
730 683 """set_hook(name,hook) -> sets an internal IPython hook.
731 684
732 685 IPython exposes some of its internal API as user-modifiable hooks. By
733 686 resetting one of these hooks, you can modify IPython's behavior to
734 687 call at runtime your own routines."""
735 688
736 689 # At some point in the future, this should validate the hook before it
737 690 # accepts it. Probably at least check that the hook takes the number
738 691 # of args it's supposed to.
739 692 setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
740 693
741 694 def set_custom_exc(self,exc_tuple,handler):
742 695 """set_custom_exc(exc_tuple,handler)
743 696
744 697 Set a custom exception handler, which will be called if any of the
745 698 exceptions in exc_tuple occur in the mainloop (specifically, in the
746 699 runcode() method.
747 700
748 701 Inputs:
749 702
750 703 - exc_tuple: a *tuple* of valid exceptions to call the defined
751 704 handler for. It is very important that you use a tuple, and NOT A
752 705 LIST here, because of the way Python's except statement works. If
753 706 you only want to trap a single exception, use a singleton tuple:
754 707
755 708 exc_tuple == (MyCustomException,)
756 709
757 710 - handler: this must be defined as a function with the following
758 711 basic interface: def my_handler(self,etype,value,tb).
759 712
760 713 This will be made into an instance method (via new.instancemethod)
761 714 of IPython itself, and it will be called if any of the exceptions
762 715 listed in the exc_tuple are caught. If the handler is None, an
763 716 internal basic one is used, which just prints basic info.
764 717
765 718 WARNING: by putting in your own exception handler into IPython's main
766 719 execution loop, you run a very good chance of nasty crashes. This
767 720 facility should only be used if you really know what you are doing."""
768 721
769 722 assert type(exc_tuple)==type(()) , \
770 723 "The custom exceptions must be given AS A TUPLE."
771 724
772 725 def dummy_handler(self,etype,value,tb):
773 726 print '*** Simple custom exception handler ***'
774 727 print 'Exception type :',etype
775 728 print 'Exception value:',value
776 729 print 'Traceback :',tb
777 730 print 'Source code :','\n'.join(self.buffer)
778 731
779 732 if handler is None: handler = dummy_handler
780 733
781 734 self.CustomTB = new.instancemethod(handler,self,self.__class__)
782 735 self.custom_exceptions = exc_tuple
783 736
784 737 def set_custom_completer(self,completer,pos=0):
785 738 """set_custom_completer(completer,pos=0)
786 739
787 740 Adds a new custom completer function.
788 741
789 742 The position argument (defaults to 0) is the index in the completers
790 743 list where you want the completer to be inserted."""
791 744
792 745 newcomp = new.instancemethod(completer,self.Completer,
793 746 self.Completer.__class__)
794 747 self.Completer.matchers.insert(pos,newcomp)
795 748
796 749 def _get_call_pdb(self):
797 750 return self._call_pdb
798 751
799 752 def _set_call_pdb(self,val):
800 753
801 754 if val not in (0,1,False,True):
802 755 raise ValueError,'new call_pdb value must be boolean'
803 756
804 757 # store value in instance
805 758 self._call_pdb = val
806 759
807 760 # notify the actual exception handlers
808 761 self.InteractiveTB.call_pdb = val
809 762 if self.isthreaded:
810 763 try:
811 764 self.sys_excepthook.call_pdb = val
812 765 except:
813 766 warn('Failed to activate pdb for threaded exception handler')
814 767
815 768 call_pdb = property(_get_call_pdb,_set_call_pdb,None,
816 769 'Control auto-activation of pdb at exceptions')
817 770
771
772 # These special functions get installed in the builtin namespace, to
773 # provide programmatic (pure python) access to magics, aliases and system
774 # calls. This is important for logging, user scripting, and more.
775
776 # We are basically exposing, via normal python functions, the three
777 # mechanisms in which ipython offers special call modes (magics for
778 # internal control, aliases for direct system access via pre-selected
779 # names, and !cmd for calling arbitrary system commands).
780
781 def ipmagic(self,arg_s):
782 """Call a magic function by name.
783
784 Input: a string containing the name of the magic function to call and any
785 additional arguments to be passed to the magic.
786
787 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
788 prompt:
789
790 In[1]: %name -opt foo bar
791
792 To call a magic without arguments, simply use ipmagic('name').
793
794 This provides a proper Python function to call IPython's magics in any
795 valid Python code you can type at the interpreter, including loops and
796 compound statements. It is added by IPython to the Python builtin
797 namespace upon initialization."""
798
799 args = arg_s.split(' ',1)
800 magic_name = args[0]
801 if magic_name.startswith(self.ESC_MAGIC):
802 magic_name = magic_name[1:]
803 try:
804 magic_args = args[1]
805 except IndexError:
806 magic_args = ''
807 fn = getattr(self,'magic_'+magic_name,None)
808 if fn is None:
809 error("Magic function `%s` not found." % magic_name)
810 else:
811 magic_args = self.var_expand(magic_args)
812 return fn(magic_args)
813
814 def ipalias(self,arg_s):
815 """Call an alias by name.
816
817 Input: a string containing the name of the alias to call and any
818 additional arguments to be passed to the magic.
819
820 ipalias('name -opt foo bar') is equivalent to typing at the ipython
821 prompt:
822
823 In[1]: name -opt foo bar
824
825 To call an alias without arguments, simply use ipalias('name').
826
827 This provides a proper Python function to call IPython's aliases in any
828 valid Python code you can type at the interpreter, including loops and
829 compound statements. It is added by IPython to the Python builtin
830 namespace upon initialization."""
831
832 args = arg_s.split(' ',1)
833 alias_name = args[0]
834 try:
835 alias_args = args[1]
836 except IndexError:
837 alias_args = ''
838 if alias_name in self.alias_table:
839 self.call_alias(alias_name,alias_args)
840 else:
841 error("Alias `%s` not found." % alias_name)
842
843 def ipsystem(self,arg_s):
844 """Make a system call, using IPython."""
845 self.system(arg_s)
846
818 847 def complete(self,text):
819 848 """Return a sorted list of all possible completions on text.
820 849
821 850 Inputs:
822 851
823 852 - text: a string of text to be completed on.
824 853
825 854 This is a wrapper around the completion mechanism, similar to what
826 855 readline does at the command line when the TAB key is hit. By
827 856 exposing it as a method, it can be used by other non-readline
828 857 environments (such as GUIs) for text completion.
829 858
830 859 Simple usage example:
831 860
832 861 In [1]: x = 'hello'
833 862
834 863 In [2]: __IP.complete('x.l')
835 864 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
836 865
837 866 complete = self.Completer.complete
838 867 state = 0
839 868 # use a dict so we get unique keys, since ipyhton's multiple
840 869 # completers can return duplicates.
841 870 comps = {}
842 871 while True:
843 872 newcomp = complete(text,state)
844 873 if newcomp is None:
845 874 break
846 875 comps[newcomp] = 1
847 876 state += 1
848 877 outcomps = comps.keys()
849 878 outcomps.sort()
850 879 return outcomps
851 880
852 881 def set_completer_frame(self, frame):
853 882 if frame:
854 883 self.Completer.namespace = frame.f_locals
855 884 self.Completer.global_namespace = frame.f_globals
856 885 else:
857 886 self.Completer.namespace = self.user_ns
858 887 self.Completer.global_namespace = self.user_global_ns
859 888
860 889 def init_auto_alias(self):
861 890 """Define some aliases automatically.
862 891
863 892 These are ALL parameter-less aliases"""
864 893 for alias,cmd in self.auto_alias:
865 894 self.alias_table[alias] = (0,cmd)
866 895
867 896 def alias_table_validate(self,verbose=0):
868 897 """Update information about the alias table.
869 898
870 899 In particular, make sure no Python keywords/builtins are in it."""
871 900
872 901 no_alias = self.no_alias
873 902 for k in self.alias_table.keys():
874 903 if k in no_alias:
875 904 del self.alias_table[k]
876 905 if verbose:
877 906 print ("Deleting alias <%s>, it's a Python "
878 907 "keyword or builtin." % k)
879 908
880 909 def set_autoindent(self,value=None):
881 910 """Set the autoindent flag, checking for readline support.
882 911
883 912 If called with no arguments, it acts as a toggle."""
884 913
885 914 if not self.has_readline:
886 915 if os.name == 'posix':
887 916 warn("The auto-indent feature requires the readline library")
888 917 self.autoindent = 0
889 918 return
890 919 if value is None:
891 920 self.autoindent = not self.autoindent
892 921 else:
893 922 self.autoindent = value
894 923
895 924 def rc_set_toggle(self,rc_field,value=None):
896 925 """Set or toggle a field in IPython's rc config. structure.
897 926
898 927 If called with no arguments, it acts as a toggle.
899 928
900 929 If called with a non-existent field, the resulting AttributeError
901 930 exception will propagate out."""
902 931
903 932 rc_val = getattr(self.rc,rc_field)
904 933 if value is None:
905 934 value = not rc_val
906 935 setattr(self.rc,rc_field,value)
907 936
908 937 def user_setup(self,ipythondir,rc_suffix,mode='install'):
909 938 """Install the user configuration directory.
910 939
911 940 Can be called when running for the first time or to upgrade the user's
912 941 .ipython/ directory with the mode parameter. Valid modes are 'install'
913 942 and 'upgrade'."""
914 943
915 944 def wait():
916 945 try:
917 946 raw_input("Please press <RETURN> to start IPython.")
918 947 except EOFError:
919 948 print >> Term.cout
920 949 print '*'*70
921 950
922 951 cwd = os.getcwd() # remember where we started
923 952 glb = glob.glob
924 953 print '*'*70
925 954 if mode == 'install':
926 955 print \
927 956 """Welcome to IPython. I will try to create a personal configuration directory
928 957 where you can customize many aspects of IPython's functionality in:\n"""
929 958 else:
930 959 print 'I am going to upgrade your configuration in:'
931 960
932 961 print ipythondir
933 962
934 963 rcdirend = os.path.join('IPython','UserConfig')
935 964 cfg = lambda d: os.path.join(d,rcdirend)
936 965 try:
937 966 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
938 967 except IOError:
939 968 warning = """
940 969 Installation error. IPython's directory was not found.
941 970
942 971 Check the following:
943 972
944 973 The ipython/IPython directory should be in a directory belonging to your
945 974 PYTHONPATH environment variable (that is, it should be in a directory
946 975 belonging to sys.path). You can copy it explicitly there or just link to it.
947 976
948 977 IPython will proceed with builtin defaults.
949 978 """
950 979 warn(warning)
951 980 wait()
952 981 return
953 982
954 983 if mode == 'install':
955 984 try:
956 985 shutil.copytree(rcdir,ipythondir)
957 986 os.chdir(ipythondir)
958 987 rc_files = glb("ipythonrc*")
959 988 for rc_file in rc_files:
960 989 os.rename(rc_file,rc_file+rc_suffix)
961 990 except:
962 991 warning = """
963 992
964 993 There was a problem with the installation:
965 994 %s
966 995 Try to correct it or contact the developers if you think it's a bug.
967 996 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
968 997 warn(warning)
969 998 wait()
970 999 return
971 1000
972 1001 elif mode == 'upgrade':
973 1002 try:
974 1003 os.chdir(ipythondir)
975 1004 except:
976 1005 print """
977 1006 Can not upgrade: changing to directory %s failed. Details:
978 1007 %s
979 1008 """ % (ipythondir,sys.exc_info()[1])
980 1009 wait()
981 1010 return
982 1011 else:
983 1012 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
984 1013 for new_full_path in sources:
985 1014 new_filename = os.path.basename(new_full_path)
986 1015 if new_filename.startswith('ipythonrc'):
987 1016 new_filename = new_filename + rc_suffix
988 1017 # The config directory should only contain files, skip any
989 1018 # directories which may be there (like CVS)
990 1019 if os.path.isdir(new_full_path):
991 1020 continue
992 1021 if os.path.exists(new_filename):
993 1022 old_file = new_filename+'.old'
994 1023 if os.path.exists(old_file):
995 1024 os.remove(old_file)
996 1025 os.rename(new_filename,old_file)
997 1026 shutil.copy(new_full_path,new_filename)
998 1027 else:
999 1028 raise ValueError,'unrecognized mode for install:',`mode`
1000 1029
1001 1030 # Fix line-endings to those native to each platform in the config
1002 1031 # directory.
1003 1032 try:
1004 1033 os.chdir(ipythondir)
1005 1034 except:
1006 1035 print """
1007 1036 Problem: changing to directory %s failed.
1008 1037 Details:
1009 1038 %s
1010 1039
1011 1040 Some configuration files may have incorrect line endings. This should not
1012 1041 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
1013 1042 wait()
1014 1043 else:
1015 1044 for fname in glb('ipythonrc*'):
1016 1045 try:
1017 1046 native_line_ends(fname,backup=0)
1018 1047 except IOError:
1019 1048 pass
1020 1049
1021 1050 if mode == 'install':
1022 1051 print """
1023 1052 Successful installation!
1024 1053
1025 1054 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
1026 1055 IPython manual (there are both HTML and PDF versions supplied with the
1027 1056 distribution) to make sure that your system environment is properly configured
1028 1057 to take advantage of IPython's features."""
1029 1058 else:
1030 1059 print """
1031 1060 Successful upgrade!
1032 1061
1033 1062 All files in your directory:
1034 1063 %(ipythondir)s
1035 1064 which would have been overwritten by the upgrade were backed up with a .old
1036 1065 extension. If you had made particular customizations in those files you may
1037 1066 want to merge them back into the new files.""" % locals()
1038 1067 wait()
1039 1068 os.chdir(cwd)
1040 1069 # end user_setup()
1041 1070
1042 1071 def atexit_operations(self):
1043 1072 """This will be executed at the time of exit.
1044 1073
1045 1074 Saving of persistent data should be performed here. """
1046 1075
1047 1076 # input history
1048 1077 self.savehist()
1049 1078
1050 1079 # Cleanup all tempfiles left around
1051 1080 for tfile in self.tempfiles:
1052 1081 try:
1053 1082 os.unlink(tfile)
1054 1083 except OSError:
1055 1084 pass
1056 1085
1057 1086 # save the "persistent data" catch-all dictionary
1058 1087 try:
1059 1088 pickle.dump(self.persist, open(self.persist_fname,"w"))
1060 1089 except:
1061 1090 print "*** ERROR *** persistent data saving failed."
1062 1091
1063 1092 def savehist(self):
1064 1093 """Save input history to a file (via readline library)."""
1065 1094 try:
1066 1095 self.readline.write_history_file(self.histfile)
1067 1096 except:
1068 1097 print 'Unable to save IPython command history to file: ' + \
1069 1098 `self.histfile`
1070 1099
1071 1100 def pre_readline(self):
1072 1101 """readline hook to be used at the start of each line.
1073 1102
1074 1103 Currently it handles auto-indent only."""
1075 1104
1076 1105 self.readline.insert_text(self.indent_current)
1077 1106
1078 1107 def init_readline(self):
1079 1108 """Command history completion/saving/reloading."""
1080 1109 try:
1081 1110 import readline
1082 1111 except ImportError:
1083 1112 self.has_readline = 0
1084 1113 self.readline = None
1085 1114 # no point in bugging windows users with this every time:
1086 1115 if os.name == 'posix':
1087 1116 warn('Readline services not available on this platform.')
1088 1117 else:
1089 1118 import atexit
1090 1119 from IPython.completer import IPCompleter
1091 1120 self.Completer = IPCompleter(self,
1092 1121 self.user_ns,
1093 1122 self.user_global_ns,
1094 1123 self.rc.readline_omit__names,
1095 1124 self.alias_table)
1096 1125
1097 1126 # Platform-specific configuration
1098 1127 if os.name == 'nt':
1099 1128 self.readline_startup_hook = readline.set_pre_input_hook
1100 1129 else:
1101 1130 self.readline_startup_hook = readline.set_startup_hook
1102 1131
1103 1132 # Load user's initrc file (readline config)
1104 1133 inputrc_name = os.environ.get('INPUTRC')
1105 1134 if inputrc_name is None:
1106 1135 home_dir = get_home_dir()
1107 1136 if home_dir is not None:
1108 1137 inputrc_name = os.path.join(home_dir,'.inputrc')
1109 1138 if os.path.isfile(inputrc_name):
1110 1139 try:
1111 1140 readline.read_init_file(inputrc_name)
1112 1141 except:
1113 1142 warn('Problems reading readline initialization file <%s>'
1114 1143 % inputrc_name)
1115 1144
1116 1145 self.has_readline = 1
1117 1146 self.readline = readline
1118 1147 # save this in sys so embedded copies can restore it properly
1119 1148 sys.ipcompleter = self.Completer.complete
1120 1149 readline.set_completer(self.Completer.complete)
1121 1150
1122 1151 # Configure readline according to user's prefs
1123 1152 for rlcommand in self.rc.readline_parse_and_bind:
1124 1153 readline.parse_and_bind(rlcommand)
1125 1154
1126 1155 # remove some chars from the delimiters list
1127 1156 delims = readline.get_completer_delims()
1128 1157 delims = delims.translate(string._idmap,
1129 1158 self.rc.readline_remove_delims)
1130 1159 readline.set_completer_delims(delims)
1131 1160 # otherwise we end up with a monster history after a while:
1132 1161 readline.set_history_length(1000)
1133 1162 try:
1134 1163 #print '*** Reading readline history' # dbg
1135 1164 readline.read_history_file(self.histfile)
1136 1165 except IOError:
1137 1166 pass # It doesn't exist yet.
1138 1167
1139 1168 atexit.register(self.atexit_operations)
1140 1169 del atexit
1141 1170
1142 1171 # Configure auto-indent for all platforms
1143 1172 self.set_autoindent(self.rc.autoindent)
1144 1173
1145 1174 def _should_recompile(self,e):
1146 1175 """Utility routine for edit_syntax_error"""
1147 1176
1148 1177 if e.filename in ('<ipython console>','<input>','<string>',
1149 1178 '<console>'):
1150 1179 return False
1151 1180 try:
1152 1181 if not ask_yes_no('Return to editor to correct syntax error? '
1153 1182 '[Y/n] ','y'):
1154 1183 return False
1155 1184 except EOFError:
1156 1185 return False
1157 1186 self.hooks.fix_error_editor(e.filename,e.lineno,e.offset,e.msg)
1158 1187 return True
1159 1188
1160 1189 def edit_syntax_error(self):
1161 1190 """The bottom half of the syntax error handler called in the main loop.
1162 1191
1163 1192 Loop until syntax error is fixed or user cancels.
1164 1193 """
1165 1194
1166 1195 while self.SyntaxTB.last_syntax_error:
1167 1196 # copy and clear last_syntax_error
1168 1197 err = self.SyntaxTB.clear_err_state()
1169 1198 if not self._should_recompile(err):
1170 1199 return
1171 1200 try:
1172 1201 # may set last_syntax_error again if a SyntaxError is raised
1173 1202 self.safe_execfile(err.filename,self.shell.user_ns)
1174 1203 except:
1175 1204 self.showtraceback()
1176 1205 else:
1177 1206 f = file(err.filename)
1178 1207 try:
1179 1208 sys.displayhook(f.read())
1180 1209 finally:
1181 1210 f.close()
1182 1211
1183 1212 def showsyntaxerror(self, filename=None):
1184 1213 """Display the syntax error that just occurred.
1185 1214
1186 1215 This doesn't display a stack trace because there isn't one.
1187 1216
1188 1217 If a filename is given, it is stuffed in the exception instead
1189 1218 of what was there before (because Python's parser always uses
1190 1219 "<string>" when reading from a string).
1191 1220 """
1192 1221 etype, value, last_traceback = sys.exc_info()
1193 1222 if filename and etype is SyntaxError:
1194 1223 # Work hard to stuff the correct filename in the exception
1195 1224 try:
1196 1225 msg, (dummy_filename, lineno, offset, line) = value
1197 1226 except:
1198 1227 # Not the format we expect; leave it alone
1199 1228 pass
1200 1229 else:
1201 1230 # Stuff in the right filename
1202 1231 try:
1203 1232 # Assume SyntaxError is a class exception
1204 1233 value = SyntaxError(msg, (filename, lineno, offset, line))
1205 1234 except:
1206 1235 # If that failed, assume SyntaxError is a string
1207 1236 value = msg, (filename, lineno, offset, line)
1208 1237 self.SyntaxTB(etype,value,[])
1209 1238
1210 1239 def debugger(self):
1211 1240 """Call the pdb debugger."""
1212 1241
1213 1242 if not self.rc.pdb:
1214 1243 return
1215 1244 pdb.pm()
1216 1245
1217 1246 def showtraceback(self,exc_tuple = None,filename=None):
1218 1247 """Display the exception that just occurred."""
1219 1248
1220 1249 # Though this won't be called by syntax errors in the input line,
1221 1250 # there may be SyntaxError cases whith imported code.
1222 1251 if exc_tuple is None:
1223 1252 type, value, tb = sys.exc_info()
1224 1253 else:
1225 1254 type, value, tb = exc_tuple
1226 1255 if type is SyntaxError:
1227 1256 self.showsyntaxerror(filename)
1228 1257 else:
1229 1258 self.InteractiveTB()
1230 1259 if self.InteractiveTB.call_pdb and self.has_readline:
1231 1260 # pdb mucks up readline, fix it back
1232 1261 self.readline.set_completer(self.Completer.complete)
1233 1262
1234 1263 def mainloop(self,banner=None):
1235 1264 """Creates the local namespace and starts the mainloop.
1236 1265
1237 1266 If an optional banner argument is given, it will override the
1238 1267 internally created default banner."""
1239 1268
1240 1269 if self.rc.c: # Emulate Python's -c option
1241 1270 self.exec_init_cmd()
1242 1271 if banner is None:
1243 1272 if self.rc.banner:
1244 1273 banner = self.BANNER+self.banner2
1245 1274 else:
1246 1275 banner = ''
1247 1276 self.interact(banner)
1248 1277
1249 1278 def exec_init_cmd(self):
1250 1279 """Execute a command given at the command line.
1251 1280
1252 1281 This emulates Python's -c option."""
1253 1282
1254 1283 sys.argv = ['-c']
1255 1284 self.push(self.rc.c)
1256 1285
1257 1286 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1258 1287 """Embeds IPython into a running python program.
1259 1288
1260 1289 Input:
1261 1290
1262 1291 - header: An optional header message can be specified.
1263 1292
1264 1293 - local_ns, global_ns: working namespaces. If given as None, the
1265 1294 IPython-initialized one is updated with __main__.__dict__, so that
1266 1295 program variables become visible but user-specific configuration
1267 1296 remains possible.
1268 1297
1269 1298 - stack_depth: specifies how many levels in the stack to go to
1270 1299 looking for namespaces (when local_ns and global_ns are None). This
1271 1300 allows an intermediate caller to make sure that this function gets
1272 1301 the namespace from the intended level in the stack. By default (0)
1273 1302 it will get its locals and globals from the immediate caller.
1274 1303
1275 1304 Warning: it's possible to use this in a program which is being run by
1276 1305 IPython itself (via %run), but some funny things will happen (a few
1277 1306 globals get overwritten). In the future this will be cleaned up, as
1278 1307 there is no fundamental reason why it can't work perfectly."""
1279 1308
1280 1309 # Get locals and globals from caller
1281 1310 if local_ns is None or global_ns is None:
1282 1311 call_frame = sys._getframe(stack_depth).f_back
1283 1312
1284 1313 if local_ns is None:
1285 1314 local_ns = call_frame.f_locals
1286 1315 if global_ns is None:
1287 1316 global_ns = call_frame.f_globals
1288 1317
1289 1318 # Update namespaces and fire up interpreter
1290 self.user_ns = local_ns
1319
1320 # The global one is easy, we can just throw it in
1291 1321 self.user_global_ns = global_ns
1292 1322
1323 # but the user/local one is tricky: ipython needs it to store internal
1324 # data, but we also need the locals. We'll copy locals in the user
1325 # one, but will track what got copied so we can delete them at exit.
1326 # This is so that a later embedded call doesn't see locals from a
1327 # previous call (which most likely existed in a separate scope).
1328 local_varnames = local_ns.keys()
1329 self.user_ns.update(local_ns)
1330
1293 1331 # Patch for global embedding to make sure that things don't overwrite
1294 1332 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1295 1333 # FIXME. Test this a bit more carefully (the if.. is new)
1296 1334 if local_ns is None and global_ns is None:
1297 1335 self.user_global_ns.update(__main__.__dict__)
1298 1336
1299 1337 # make sure the tab-completer has the correct frame information, so it
1300 1338 # actually completes using the frame's locals/globals
1301 1339 self.set_completer_frame(call_frame)
1340
1341 # before activating the interactive mode, we need to make sure that
1342 # all names in the builtin namespace needed by ipython point to
1343 # ourselves, and not to other instances.
1344 self.add_builtins()
1302 1345
1303 1346 self.interact(header)
1347
1348 # now, purge out the user namespace from anything we might have added
1349 # from the caller's local namespace
1350 delvar = self.user_ns.pop
1351 for var in local_varnames:
1352 delvar(var,None)
1353 # and clean builtins we may have overridden
1354 self.clean_builtins()
1304 1355
1305 1356 def interact(self, banner=None):
1306 1357 """Closely emulate the interactive Python console.
1307 1358
1308 1359 The optional banner argument specify the banner to print
1309 1360 before the first interaction; by default it prints a banner
1310 1361 similar to the one printed by the real Python interpreter,
1311 1362 followed by the current class name in parentheses (so as not
1312 1363 to confuse this with the real interpreter -- since it's so
1313 1364 close!).
1314 1365
1315 1366 """
1316 1367 cprt = 'Type "copyright", "credits" or "license" for more information.'
1317 1368 if banner is None:
1318 1369 self.write("Python %s on %s\n%s\n(%s)\n" %
1319 1370 (sys.version, sys.platform, cprt,
1320 1371 self.__class__.__name__))
1321 1372 else:
1322 1373 self.write(banner)
1323 1374
1324 1375 more = 0
1325 1376
1326 1377 # Mark activity in the builtins
1327 1378 __builtin__.__dict__['__IPYTHON__active'] += 1
1328 1379
1329 1380 # exit_now is set by a call to %Exit or %Quit
1381 self.exit_now = False
1330 1382 while not self.exit_now:
1383
1331 1384 try:
1332 1385 if more:
1333 1386 prompt = self.outputcache.prompt2
1334 1387 if self.autoindent:
1335 1388 self.readline_startup_hook(self.pre_readline)
1336 1389 else:
1337 1390 prompt = self.outputcache.prompt1
1338 1391 try:
1339 1392 line = self.raw_input(prompt,more)
1340 1393 if self.autoindent:
1341 1394 self.readline_startup_hook(None)
1342 1395 except EOFError:
1343 1396 if self.autoindent:
1344 1397 self.readline_startup_hook(None)
1345 1398 self.write("\n")
1346 1399 self.exit()
1347 1400 else:
1348 1401 more = self.push(line)
1349 1402
1350 1403 if (self.SyntaxTB.last_syntax_error and
1351 1404 self.rc.autoedit_syntax):
1352 1405 self.edit_syntax_error()
1353 1406
1354 1407 except KeyboardInterrupt:
1355 1408 self.write("\nKeyboardInterrupt\n")
1356 1409 self.resetbuffer()
1357 1410 more = 0
1358 1411 # keep cache in sync with the prompt counter:
1359 1412 self.outputcache.prompt_count -= 1
1360 1413
1361 1414 if self.autoindent:
1362 1415 self.indent_current_nsp = 0
1363 1416 self.indent_current = ' '* self.indent_current_nsp
1364 1417
1365 1418 except bdb.BdbQuit:
1366 1419 warn("The Python debugger has exited with a BdbQuit exception.\n"
1367 1420 "Because of how pdb handles the stack, it is impossible\n"
1368 1421 "for IPython to properly format this particular exception.\n"
1369 1422 "IPython will resume normal operation.")
1370 1423
1371 1424 # We are off again...
1372 1425 __builtin__.__dict__['__IPYTHON__active'] -= 1
1373 1426
1374 1427 def excepthook(self, type, value, tb):
1375 1428 """One more defense for GUI apps that call sys.excepthook.
1376 1429
1377 1430 GUI frameworks like wxPython trap exceptions and call
1378 1431 sys.excepthook themselves. I guess this is a feature that
1379 1432 enables them to keep running after exceptions that would
1380 1433 otherwise kill their mainloop. This is a bother for IPython
1381 1434 which excepts to catch all of the program exceptions with a try:
1382 1435 except: statement.
1383 1436
1384 1437 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1385 1438 any app directly invokes sys.excepthook, it will look to the user like
1386 1439 IPython crashed. In order to work around this, we can disable the
1387 1440 CrashHandler and replace it with this excepthook instead, which prints a
1388 1441 regular traceback using our InteractiveTB. In this fashion, apps which
1389 1442 call sys.excepthook will generate a regular-looking exception from
1390 1443 IPython, and the CrashHandler will only be triggered by real IPython
1391 1444 crashes.
1392 1445
1393 1446 This hook should be used sparingly, only in places which are not likely
1394 1447 to be true IPython errors.
1395 1448 """
1396 1449
1397 1450 self.InteractiveTB(type, value, tb, tb_offset=0)
1398 1451 if self.InteractiveTB.call_pdb and self.has_readline:
1399 1452 self.readline.set_completer(self.Completer.complete)
1400 1453
1401 1454 def call_alias(self,alias,rest=''):
1402 1455 """Call an alias given its name and the rest of the line.
1403 1456
1404 1457 This function MUST be given a proper alias, because it doesn't make
1405 1458 any checks when looking up into the alias table. The caller is
1406 1459 responsible for invoking it only with a valid alias."""
1407 1460
1408 1461 #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg
1409 1462 nargs,cmd = self.alias_table[alias]
1410 1463 # Expand the %l special to be the user's input line
1411 1464 if cmd.find('%l') >= 0:
1412 1465 cmd = cmd.replace('%l',rest)
1413 1466 rest = ''
1414 1467 if nargs==0:
1415 1468 # Simple, argument-less aliases
1416 1469 cmd = '%s %s' % (cmd,rest)
1417 1470 else:
1418 1471 # Handle aliases with positional arguments
1419 1472 args = rest.split(None,nargs)
1420 1473 if len(args)< nargs:
1421 1474 error('Alias <%s> requires %s arguments, %s given.' %
1422 1475 (alias,nargs,len(args)))
1423 1476 return
1424 1477 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1425 1478 # Now call the macro, evaluating in the user's namespace
1426 1479 try:
1427 1480 self.system(cmd)
1428 1481 except:
1429 1482 self.showtraceback()
1430 1483
1431 1484 def autoindent_update(self,line):
1432 1485 """Keep track of the indent level."""
1433 1486 if self.autoindent:
1434 1487 if line:
1435 1488 ini_spaces = ini_spaces_re.match(line)
1436 1489 if ini_spaces:
1437 1490 nspaces = ini_spaces.end()
1438 1491 else:
1439 1492 nspaces = 0
1440 1493 self.indent_current_nsp = nspaces
1441 1494
1442 1495 if line[-1] == ':':
1443 1496 self.indent_current_nsp += 4
1444 1497 elif dedent_re.match(line):
1445 1498 self.indent_current_nsp -= 4
1446 1499 else:
1447 1500 self.indent_current_nsp = 0
1448 1501
1449 1502 # indent_current is the actual string to be inserted
1450 1503 # by the readline hooks for indentation
1451 1504 self.indent_current = ' '* self.indent_current_nsp
1452 1505
1453 1506 def runlines(self,lines):
1454 1507 """Run a string of one or more lines of source.
1455 1508
1456 1509 This method is capable of running a string containing multiple source
1457 1510 lines, as if they had been entered at the IPython prompt. Since it
1458 1511 exposes IPython's processing machinery, the given strings can contain
1459 1512 magic calls (%magic), special shell access (!cmd), etc."""
1460 1513
1461 1514 # We must start with a clean buffer, in case this is run from an
1462 1515 # interactive IPython session (via a magic, for example).
1463 1516 self.resetbuffer()
1464 1517 lines = lines.split('\n')
1465 1518 more = 0
1466 1519 for line in lines:
1467 1520 # skip blank lines so we don't mess up the prompt counter, but do
1468 1521 # NOT skip even a blank line if we are in a code block (more is
1469 1522 # true)
1470 1523 if line or more:
1471 1524 more = self.push(self.prefilter(line,more))
1472 1525 # IPython's runsource returns None if there was an error
1473 1526 # compiling the code. This allows us to stop processing right
1474 1527 # away, so the user gets the error message at the right place.
1475 1528 if more is None:
1476 1529 break
1477 1530 # final newline in case the input didn't have it, so that the code
1478 1531 # actually does get executed
1479 1532 if more:
1480 1533 self.push('\n')
1481 1534
1482 1535 def runsource(self, source, filename='<input>', symbol='single'):
1483 1536 """Compile and run some source in the interpreter.
1484 1537
1485 1538 Arguments are as for compile_command().
1486 1539
1487 1540 One several things can happen:
1488 1541
1489 1542 1) The input is incorrect; compile_command() raised an
1490 1543 exception (SyntaxError or OverflowError). A syntax traceback
1491 1544 will be printed by calling the showsyntaxerror() method.
1492 1545
1493 1546 2) The input is incomplete, and more input is required;
1494 1547 compile_command() returned None. Nothing happens.
1495 1548
1496 1549 3) The input is complete; compile_command() returned a code
1497 1550 object. The code is executed by calling self.runcode() (which
1498 1551 also handles run-time exceptions, except for SystemExit).
1499 1552
1500 1553 The return value is:
1501 1554
1502 1555 - True in case 2
1503 1556
1504 1557 - False in the other cases, unless an exception is raised, where
1505 1558 None is returned instead. This can be used by external callers to
1506 1559 know whether to continue feeding input or not.
1507 1560
1508 1561 The return value can be used to decide whether to use sys.ps1 or
1509 1562 sys.ps2 to prompt the next line."""
1510 1563
1511 1564 try:
1512 1565 code = self.compile(source,filename,symbol)
1513 1566 except (OverflowError, SyntaxError, ValueError):
1514 1567 # Case 1
1515 1568 self.showsyntaxerror(filename)
1516 1569 return None
1517 1570
1518 1571 if code is None:
1519 1572 # Case 2
1520 1573 return True
1521 1574
1522 1575 # Case 3
1523 1576 # We store the code object so that threaded shells and
1524 1577 # custom exception handlers can access all this info if needed.
1525 1578 # The source corresponding to this can be obtained from the
1526 1579 # buffer attribute as '\n'.join(self.buffer).
1527 1580 self.code_to_run = code
1528 1581 # now actually execute the code object
1529 1582 if self.runcode(code) == 0:
1530 1583 return False
1531 1584 else:
1532 1585 return None
1533 1586
1534 1587 def runcode(self,code_obj):
1535 1588 """Execute a code object.
1536 1589
1537 1590 When an exception occurs, self.showtraceback() is called to display a
1538 1591 traceback.
1539 1592
1540 1593 Return value: a flag indicating whether the code to be run completed
1541 1594 successfully:
1542 1595
1543 1596 - 0: successful execution.
1544 1597 - 1: an error occurred.
1545 1598 """
1546 1599
1547 1600 # Set our own excepthook in case the user code tries to call it
1548 1601 # directly, so that the IPython crash handler doesn't get triggered
1549 1602 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1550 1603
1551 1604 # we save the original sys.excepthook in the instance, in case config
1552 1605 # code (such as magics) needs access to it.
1553 1606 self.sys_excepthook = old_excepthook
1554 1607 outflag = 1 # happens in more places, so it's easier as default
1555 1608 try:
1556 1609 try:
1557 1610 # Embedded instances require separate global/local namespaces
1558 1611 # so they can see both the surrounding (local) namespace and
1559 1612 # the module-level globals when called inside another function.
1560 1613 if self.embedded:
1561 1614 exec code_obj in self.user_global_ns, self.user_ns
1562 1615 # Normal (non-embedded) instances should only have a single
1563 1616 # namespace for user code execution, otherwise functions won't
1564 1617 # see interactive top-level globals.
1565 1618 else:
1566 1619 exec code_obj in self.user_ns
1567 1620 finally:
1568 1621 # Reset our crash handler in place
1569 1622 sys.excepthook = old_excepthook
1570 1623 except SystemExit:
1571 1624 self.resetbuffer()
1572 1625 self.showtraceback()
1573 1626 warn("Type exit or quit to exit IPython "
1574 1627 "(%Exit or %Quit do so unconditionally).",level=1)
1575 1628 except self.custom_exceptions:
1576 1629 etype,value,tb = sys.exc_info()
1577 1630 self.CustomTB(etype,value,tb)
1578 1631 except:
1579 1632 self.showtraceback()
1580 1633 else:
1581 1634 outflag = 0
1582 1635 if softspace(sys.stdout, 0):
1583 1636 print
1584 1637 # Flush out code object which has been run (and source)
1585 1638 self.code_to_run = None
1586 1639 return outflag
1587 1640
1588 1641 def push(self, line):
1589 1642 """Push a line to the interpreter.
1590 1643
1591 1644 The line should not have a trailing newline; it may have
1592 1645 internal newlines. The line is appended to a buffer and the
1593 1646 interpreter's runsource() method is called with the
1594 1647 concatenated contents of the buffer as source. If this
1595 1648 indicates that the command was executed or invalid, the buffer
1596 1649 is reset; otherwise, the command is incomplete, and the buffer
1597 1650 is left as it was after the line was appended. The return
1598 1651 value is 1 if more input is required, 0 if the line was dealt
1599 1652 with in some way (this is the same as runsource()).
1600 1653 """
1601 1654
1602 1655 # autoindent management should be done here, and not in the
1603 1656 # interactive loop, since that one is only seen by keyboard input. We
1604 1657 # need this done correctly even for code run via runlines (which uses
1605 1658 # push).
1606 1659
1607 1660 #print 'push line: <%s>' % line # dbg
1608 1661 self.autoindent_update(line)
1609 1662
1610 1663 self.buffer.append(line)
1611 1664 more = self.runsource('\n'.join(self.buffer), self.filename)
1612 1665 if not more:
1613 1666 self.resetbuffer()
1614 1667 return more
1615 1668
1616 1669 def resetbuffer(self):
1617 1670 """Reset the input buffer."""
1618 1671 self.buffer[:] = []
1619 1672
1620 1673 def raw_input(self,prompt='',continue_prompt=False):
1621 1674 """Write a prompt and read a line.
1622 1675
1623 1676 The returned line does not include the trailing newline.
1624 1677 When the user enters the EOF key sequence, EOFError is raised.
1625 1678
1626 1679 Optional inputs:
1627 1680
1628 1681 - prompt(''): a string to be printed to prompt the user.
1629 1682
1630 1683 - continue_prompt(False): whether this line is the first one or a
1631 1684 continuation in a sequence of inputs.
1632 1685 """
1633 1686
1634 1687 line = raw_input_original(prompt)
1635 1688 # Try to be reasonably smart about not re-indenting pasted input more
1636 1689 # than necessary. We do this by trimming out the auto-indent initial
1637 1690 # spaces, if the user's actual input started itself with whitespace.
1638 1691 if self.autoindent:
1639 1692 line2 = line[self.indent_current_nsp:]
1640 1693 if line2[0:1] in (' ','\t'):
1641 1694 line = line2
1642 1695 return self.prefilter(line,continue_prompt)
1643 1696
1644 1697 def split_user_input(self,line):
1645 1698 """Split user input into pre-char, function part and rest."""
1646 1699
1647 1700 lsplit = self.line_split.match(line)
1648 1701 if lsplit is None: # no regexp match returns None
1649 1702 try:
1650 1703 iFun,theRest = line.split(None,1)
1651 1704 except ValueError:
1652 1705 iFun,theRest = line,''
1653 1706 pre = re.match('^(\s*)(.*)',line).groups()[0]
1654 1707 else:
1655 1708 pre,iFun,theRest = lsplit.groups()
1656 1709
1657 1710 #print 'line:<%s>' % line # dbg
1658 1711 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
1659 1712 return pre,iFun.strip(),theRest
1660 1713
1661 1714 def _prefilter(self, line, continue_prompt):
1662 1715 """Calls different preprocessors, depending on the form of line."""
1663 1716
1664 1717 # All handlers *must* return a value, even if it's blank ('').
1665 1718
1666 1719 # Lines are NOT logged here. Handlers should process the line as
1667 1720 # needed, update the cache AND log it (so that the input cache array
1668 1721 # stays synced).
1669 1722
1670 1723 # This function is _very_ delicate, and since it's also the one which
1671 1724 # determines IPython's response to user input, it must be as efficient
1672 1725 # as possible. For this reason it has _many_ returns in it, trying
1673 1726 # always to exit as quickly as it can figure out what it needs to do.
1674 1727
1675 1728 # This function is the main responsible for maintaining IPython's
1676 1729 # behavior respectful of Python's semantics. So be _very_ careful if
1677 1730 # making changes to anything here.
1678 1731
1679 1732 #.....................................................................
1680 1733 # Code begins
1681 1734
1682 1735 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
1683 1736
1684 1737 # save the line away in case we crash, so the post-mortem handler can
1685 1738 # record it
1686 1739 self._last_input_line = line
1687 1740
1688 1741 #print '***line: <%s>' % line # dbg
1689 1742
1690 1743 # the input history needs to track even empty lines
1691 1744 if not line.strip():
1692 1745 if not continue_prompt:
1693 1746 self.outputcache.prompt_count -= 1
1694 1747 return self.handle_normal(line,continue_prompt)
1695 1748 #return self.handle_normal('',continue_prompt)
1696 1749
1697 1750 # print '***cont',continue_prompt # dbg
1698 1751 # special handlers are only allowed for single line statements
1699 1752 if continue_prompt and not self.rc.multi_line_specials:
1700 1753 return self.handle_normal(line,continue_prompt)
1701 1754
1702 1755 # For the rest, we need the structure of the input
1703 1756 pre,iFun,theRest = self.split_user_input(line)
1704 1757 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1705 1758
1706 1759 # First check for explicit escapes in the last/first character
1707 1760 handler = None
1708 1761 if line[-1] == self.ESC_HELP:
1709 1762 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
1710 1763 if handler is None:
1711 1764 # look at the first character of iFun, NOT of line, so we skip
1712 1765 # leading whitespace in multiline input
1713 1766 handler = self.esc_handlers.get(iFun[0:1])
1714 1767 if handler is not None:
1715 1768 return handler(line,continue_prompt,pre,iFun,theRest)
1716 1769 # Emacs ipython-mode tags certain input lines
1717 1770 if line.endswith('# PYTHON-MODE'):
1718 1771 return self.handle_emacs(line,continue_prompt)
1719 1772
1720 1773 # Next, check if we can automatically execute this thing
1721 1774
1722 1775 # Allow ! in multi-line statements if multi_line_specials is on:
1723 1776 if continue_prompt and self.rc.multi_line_specials and \
1724 1777 iFun.startswith(self.ESC_SHELL):
1725 1778 return self.handle_shell_escape(line,continue_prompt,
1726 1779 pre=pre,iFun=iFun,
1727 1780 theRest=theRest)
1728 1781
1729 1782 # Let's try to find if the input line is a magic fn
1730 1783 oinfo = None
1731 1784 if hasattr(self,'magic_'+iFun):
1732 1785 # WARNING: _ofind uses getattr(), so it can consume generators and
1733 1786 # cause other side effects.
1734 1787 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1735 1788 if oinfo['ismagic']:
1736 1789 # Be careful not to call magics when a variable assignment is
1737 1790 # being made (ls='hi', for example)
1738 1791 if self.rc.automagic and \
1739 1792 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
1740 1793 (self.rc.multi_line_specials or not continue_prompt):
1741 1794 return self.handle_magic(line,continue_prompt,
1742 1795 pre,iFun,theRest)
1743 1796 else:
1744 1797 return self.handle_normal(line,continue_prompt)
1745 1798
1746 1799 # If the rest of the line begins with an (in)equality, assginment or
1747 1800 # function call, we should not call _ofind but simply execute it.
1748 1801 # This avoids spurious geattr() accesses on objects upon assignment.
1749 1802 #
1750 1803 # It also allows users to assign to either alias or magic names true
1751 1804 # python variables (the magic/alias systems always take second seat to
1752 1805 # true python code).
1753 1806 if theRest and theRest[0] in '!=()':
1754 1807 return self.handle_normal(line,continue_prompt)
1755 1808
1756 1809 if oinfo is None:
1757 1810 # let's try to ensure that _oinfo is ONLY called when autocall is
1758 1811 # on. Since it has inevitable potential side effects, at least
1759 1812 # having autocall off should be a guarantee to the user that no
1760 1813 # weird things will happen.
1761 1814
1762 1815 if self.rc.autocall:
1763 1816 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1764 1817 else:
1765 1818 # in this case, all that's left is either an alias or
1766 1819 # processing the line normally.
1767 1820 if iFun in self.alias_table:
1768 1821 return self.handle_alias(line,continue_prompt,
1769 1822 pre,iFun,theRest)
1770 1823 else:
1771 1824 return self.handle_normal(line,continue_prompt)
1772 1825
1773 1826 if not oinfo['found']:
1774 1827 return self.handle_normal(line,continue_prompt)
1775 1828 else:
1776 1829 #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg
1777 1830 if oinfo['isalias']:
1778 1831 return self.handle_alias(line,continue_prompt,
1779 1832 pre,iFun,theRest)
1780 1833
1781 1834 if self.rc.autocall and \
1782 1835 not self.re_exclude_auto.match(theRest) and \
1783 1836 self.re_fun_name.match(iFun) and \
1784 1837 callable(oinfo['obj']) :
1785 1838 #print 'going auto' # dbg
1786 1839 return self.handle_auto(line,continue_prompt,pre,iFun,theRest)
1787 1840 else:
1788 1841 #print 'was callable?', callable(oinfo['obj']) # dbg
1789 1842 return self.handle_normal(line,continue_prompt)
1790 1843
1791 1844 # If we get here, we have a normal Python line. Log and return.
1792 1845 return self.handle_normal(line,continue_prompt)
1793 1846
1794 1847 def _prefilter_dumb(self, line, continue_prompt):
1795 1848 """simple prefilter function, for debugging"""
1796 1849 return self.handle_normal(line,continue_prompt)
1797 1850
1798 1851 # Set the default prefilter() function (this can be user-overridden)
1799 1852 prefilter = _prefilter
1800 1853
1801 1854 def handle_normal(self,line,continue_prompt=None,
1802 1855 pre=None,iFun=None,theRest=None):
1803 1856 """Handle normal input lines. Use as a template for handlers."""
1804 1857
1805 1858 # With autoindent on, we need some way to exit the input loop, and I
1806 1859 # don't want to force the user to have to backspace all the way to
1807 1860 # clear the line. The rule will be in this case, that either two
1808 1861 # lines of pure whitespace in a row, or a line of pure whitespace but
1809 1862 # of a size different to the indent level, will exit the input loop.
1810 1863
1811 1864 if (continue_prompt and self.autoindent and isspace(line) and
1812 1865 (line != self.indent_current or isspace(self.buffer[-1]))):
1813 1866 line = ''
1814 1867
1815 1868 self.log(line,continue_prompt)
1816 1869 return line
1817 1870
1818 1871 def handle_alias(self,line,continue_prompt=None,
1819 1872 pre=None,iFun=None,theRest=None):
1820 1873 """Handle alias input lines. """
1821 1874
1822 1875 # pre is needed, because it carries the leading whitespace. Otherwise
1823 1876 # aliases won't work in indented sections.
1824 1877 line_out = '%sipalias("%s %s")' % (pre,iFun,esc_quotes(theRest))
1825 1878 self.log(line_out,continue_prompt)
1826 1879 return line_out
1827 1880
1828 1881 def handle_shell_escape(self, line, continue_prompt=None,
1829 1882 pre=None,iFun=None,theRest=None):
1830 1883 """Execute the line in a shell, empty return value"""
1831 1884
1832 1885 #print 'line in :', `line` # dbg
1833 1886 # Example of a special handler. Others follow a similar pattern.
1834 1887 if continue_prompt: # multi-line statements
1835 1888 if iFun.startswith('!!'):
1836 1889 print 'SyntaxError: !! is not allowed in multiline statements'
1837 1890 return pre
1838 1891 else:
1839 1892 cmd = ("%s %s" % (iFun[1:],theRest))
1840 1893 line_out = '%sipsystem(r"""%s"""[:-1])' % (pre,cmd + "_")
1841 1894 else: # single-line input
1842 1895 if line.startswith('!!'):
1843 1896 # rewrite iFun/theRest to properly hold the call to %sx and
1844 1897 # the actual command to be executed, so handle_magic can work
1845 1898 # correctly
1846 1899 theRest = '%s %s' % (iFun[2:],theRest)
1847 1900 iFun = 'sx'
1848 1901 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]),
1849 1902 continue_prompt,pre,iFun,theRest)
1850 1903 else:
1851 1904 cmd=line[1:]
1852 1905 line_out = '%sipsystem(r"""%s"""[:-1])' % (pre,cmd +"_")
1853 1906 # update cache/log and return
1854 1907 self.log(line_out,continue_prompt)
1855 1908 return line_out
1856 1909
1857 1910 def handle_magic(self, line, continue_prompt=None,
1858 1911 pre=None,iFun=None,theRest=None):
1859 1912 """Execute magic functions.
1860 1913
1861 1914 Also log them with a prepended # so the log is clean Python."""
1862 1915
1863 1916 cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest)))
1864 1917 self.log(cmd,continue_prompt)
1865 1918 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
1866 1919 return cmd
1867 1920
1868 1921 def handle_auto(self, line, continue_prompt=None,
1869 1922 pre=None,iFun=None,theRest=None):
1870 1923 """Hande lines which can be auto-executed, quoting if requested."""
1871 1924
1872 1925 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1873 1926
1874 1927 # This should only be active for single-line input!
1875 1928 if continue_prompt:
1876 1929 return line
1877 1930
1878 1931 if pre == self.ESC_QUOTE:
1879 1932 # Auto-quote splitting on whitespace
1880 1933 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
1881 1934 elif pre == self.ESC_QUOTE2:
1882 1935 # Auto-quote whole string
1883 1936 newcmd = '%s("%s")' % (iFun,theRest)
1884 1937 else:
1885 1938 # Auto-paren
1886 1939 if theRest[0:1] in ('=','['):
1887 1940 # Don't autocall in these cases. They can be either
1888 1941 # rebindings of an existing callable's name, or item access
1889 1942 # for an object which is BOTH callable and implements
1890 1943 # __getitem__.
1891 1944 return '%s %s' % (iFun,theRest)
1892 1945 if theRest.endswith(';'):
1893 1946 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
1894 1947 else:
1895 1948 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1896 1949
1897 1950 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
1898 1951 # log what is now valid Python, not the actual user input (without the
1899 1952 # final newline)
1900 1953 self.log(newcmd,continue_prompt)
1901 1954 return newcmd
1902 1955
1903 1956 def handle_help(self, line, continue_prompt=None,
1904 1957 pre=None,iFun=None,theRest=None):
1905 1958 """Try to get some help for the object.
1906 1959
1907 1960 obj? or ?obj -> basic information.
1908 1961 obj?? or ??obj -> more details.
1909 1962 """
1910 1963
1911 1964 # We need to make sure that we don't process lines which would be
1912 1965 # otherwise valid python, such as "x=1 # what?"
1913 1966 try:
1914 1967 codeop.compile_command(line)
1915 1968 except SyntaxError:
1916 1969 # We should only handle as help stuff which is NOT valid syntax
1917 1970 if line[0]==self.ESC_HELP:
1918 1971 line = line[1:]
1919 1972 elif line[-1]==self.ESC_HELP:
1920 1973 line = line[:-1]
1921 1974 self.log('#?'+line)
1922 1975 if line:
1923 1976 self.magic_pinfo(line)
1924 1977 else:
1925 1978 page(self.usage,screen_lines=self.rc.screen_length)
1926 1979 return '' # Empty string is needed here!
1927 1980 except:
1928 1981 # Pass any other exceptions through to the normal handler
1929 1982 return self.handle_normal(line,continue_prompt)
1930 1983 else:
1931 1984 # If the code compiles ok, we should handle it normally
1932 1985 return self.handle_normal(line,continue_prompt)
1933 1986
1934 1987 def handle_emacs(self,line,continue_prompt=None,
1935 1988 pre=None,iFun=None,theRest=None):
1936 1989 """Handle input lines marked by python-mode."""
1937 1990
1938 1991 # Currently, nothing is done. Later more functionality can be added
1939 1992 # here if needed.
1940 1993
1941 1994 # The input cache shouldn't be updated
1942 1995
1943 1996 return line
1944 1997
1998 def mktempfile(self,data=None):
1999 """Make a new tempfile and return its filename.
2000
2001 This makes a call to tempfile.mktemp, but it registers the created
2002 filename internally so ipython cleans it up at exit time.
2003
2004 Optional inputs:
2005
2006 - data(None): if data is given, it gets written out to the temp file
2007 immediately, and the file is closed again."""
2008
2009 filename = tempfile.mktemp('.py')
2010 self.tempfiles.append(filename)
2011
2012 if data:
2013 tmp_file = open(filename,'w')
2014 tmp_file.write(data)
2015 tmp_file.close()
2016 return filename
2017
1945 2018 def write(self,data):
1946 2019 """Write a string to the default output"""
1947 2020 Term.cout.write(data)
1948 2021
1949 2022 def write_err(self,data):
1950 2023 """Write a string to the default error output"""
1951 2024 Term.cerr.write(data)
1952 2025
1953 2026 def exit(self):
1954 2027 """Handle interactive exit.
1955 2028
1956 2029 This method sets the exit_now attribute."""
1957 2030
1958 2031 if self.rc.confirm_exit:
1959 2032 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
1960 2033 self.exit_now = True
1961 2034 else:
1962 2035 self.exit_now = True
1963 2036 return self.exit_now
1964 2037
1965 2038 def safe_execfile(self,fname,*where,**kw):
1966 2039 fname = os.path.expanduser(fname)
1967 2040
1968 2041 # find things also in current directory
1969 2042 dname = os.path.dirname(fname)
1970 2043 if not sys.path.count(dname):
1971 2044 sys.path.append(dname)
1972 2045
1973 2046 try:
1974 2047 xfile = open(fname)
1975 2048 except:
1976 2049 print >> Term.cerr, \
1977 2050 'Could not open file <%s> for safe execution.' % fname
1978 2051 return None
1979 2052
1980 2053 kw.setdefault('islog',0)
1981 2054 kw.setdefault('quiet',1)
1982 2055 kw.setdefault('exit_ignore',0)
1983 2056 first = xfile.readline()
1984 2057 loghead = str(self.loghead_tpl).split('\n',1)[0].strip()
1985 2058 xfile.close()
1986 2059 # line by line execution
1987 2060 if first.startswith(loghead) or kw['islog']:
1988 2061 print 'Loading log file <%s> one line at a time...' % fname
1989 2062 if kw['quiet']:
1990 2063 stdout_save = sys.stdout
1991 2064 sys.stdout = StringIO.StringIO()
1992 2065 try:
1993 2066 globs,locs = where[0:2]
1994 2067 except:
1995 2068 try:
1996 2069 globs = locs = where[0]
1997 2070 except:
1998 2071 globs = locs = globals()
1999 2072 badblocks = []
2000 2073
2001 2074 # we also need to identify indented blocks of code when replaying
2002 2075 # logs and put them together before passing them to an exec
2003 2076 # statement. This takes a bit of regexp and look-ahead work in the
2004 2077 # file. It's easiest if we swallow the whole thing in memory
2005 2078 # first, and manually walk through the lines list moving the
2006 2079 # counter ourselves.
2007 2080 indent_re = re.compile('\s+\S')
2008 2081 xfile = open(fname)
2009 2082 filelines = xfile.readlines()
2010 2083 xfile.close()
2011 2084 nlines = len(filelines)
2012 2085 lnum = 0
2013 2086 while lnum < nlines:
2014 2087 line = filelines[lnum]
2015 2088 lnum += 1
2016 2089 # don't re-insert logger status info into cache
2017 2090 if line.startswith('#log#'):
2018 2091 continue
2019 2092 else:
2020 2093 # build a block of code (maybe a single line) for execution
2021 2094 block = line
2022 2095 try:
2023 2096 next = filelines[lnum] # lnum has already incremented
2024 2097 except:
2025 2098 next = None
2026 2099 while next and indent_re.match(next):
2027 2100 block += next
2028 2101 lnum += 1
2029 2102 try:
2030 2103 next = filelines[lnum]
2031 2104 except:
2032 2105 next = None
2033 2106 # now execute the block of one or more lines
2034 2107 try:
2035 2108 exec block in globs,locs
2036 2109 except SystemExit:
2037 2110 pass
2038 2111 except:
2039 2112 badblocks.append(block.rstrip())
2040 2113 if kw['quiet']: # restore stdout
2041 2114 sys.stdout.close()
2042 2115 sys.stdout = stdout_save
2043 2116 print 'Finished replaying log file <%s>' % fname
2044 2117 if badblocks:
2045 2118 print >> sys.stderr, ('\nThe following lines/blocks in file '
2046 2119 '<%s> reported errors:' % fname)
2047 2120
2048 2121 for badline in badblocks:
2049 2122 print >> sys.stderr, badline
2050 2123 else: # regular file execution
2051 2124 try:
2052 2125 execfile(fname,*where)
2053 2126 except SyntaxError:
2054 2127 etype,evalue = sys.exc_info()[:2]
2055 2128 self.SyntaxTB(etype,evalue,[])
2056 2129 warn('Failure executing file: <%s>' % fname)
2057 2130 except SystemExit,status:
2058 2131 if not kw['exit_ignore']:
2059 2132 self.InteractiveTB()
2060 2133 warn('Failure executing file: <%s>' % fname)
2061 2134 except:
2062 2135 self.InteractiveTB()
2063 2136 warn('Failure executing file: <%s>' % fname)
2064 2137
2065 2138 #************************* end of file <iplib.py> *****************************
@@ -1,796 +1,855 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 ultraTB.py -- Spice up your tracebacks!
4 4
5 5 * ColorTB
6 6 I've always found it a bit hard to visually parse tracebacks in Python. The
7 7 ColorTB class is a solution to that problem. It colors the different parts of a
8 8 traceback in a manner similar to what you would expect from a syntax-highlighting
9 9 text editor.
10 10
11 11 Installation instructions for ColorTB:
12 12 import sys,ultraTB
13 13 sys.excepthook = ultraTB.ColorTB()
14 14
15 15 * VerboseTB
16 16 I've also included a port of Ka-Ping Yee's "cgitb.py" that produces all kinds
17 17 of useful info when a traceback occurs. Ping originally had it spit out HTML
18 18 and intended it for CGI programmers, but why should they have all the fun? I
19 19 altered it to spit out colored text to the terminal. It's a bit overwhelming,
20 20 but kind of neat, and maybe useful for long-running programs that you believe
21 21 are bug-free. If a crash *does* occur in that type of program you want details.
22 22 Give it a shot--you'll love it or you'll hate it.
23 23
24 24 Note:
25 25
26 26 The Verbose mode prints the variables currently visible where the exception
27 27 happened (shortening their strings if too long). This can potentially be
28 28 very slow, if you happen to have a huge data structure whose string
29 29 representation is complex to compute. Your computer may appear to freeze for
30 30 a while with cpu usage at 100%. If this occurs, you can cancel the traceback
31 31 with Ctrl-C (maybe hitting it more than once).
32 32
33 33 If you encounter this kind of situation often, you may want to use the
34 34 Verbose_novars mode instead of the regular Verbose, which avoids formatting
35 35 variables (but otherwise includes the information and context given by
36 36 Verbose).
37 37
38 38
39 39 Installation instructions for ColorTB:
40 40 import sys,ultraTB
41 41 sys.excepthook = ultraTB.VerboseTB()
42 42
43 43 Note: Much of the code in this module was lifted verbatim from the standard
44 44 library module 'traceback.py' and Ka-Ping Yee's 'cgitb.py'.
45 45
46 46 * Color schemes
47 47 The colors are defined in the class TBTools through the use of the
48 48 ColorSchemeTable class. Currently the following exist:
49 49
50 50 - NoColor: allows all of this module to be used in any terminal (the color
51 51 escapes are just dummy blank strings).
52 52
53 53 - Linux: is meant to look good in a terminal like the Linux console (black
54 54 or very dark background).
55 55
56 56 - LightBG: similar to Linux but swaps dark/light colors to be more readable
57 57 in light background terminals.
58 58
59 59 You can implement other color schemes easily, the syntax is fairly
60 60 self-explanatory. Please send back new schemes you develop to the author for
61 61 possible inclusion in future releases.
62 62
63 $Id: ultraTB.py 975 2005-12-29 23:50:22Z fperez $"""
63 $Id: ultraTB.py 988 2006-01-02 21:21:47Z fperez $"""
64 64
65 65 #*****************************************************************************
66 66 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
67 67 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
68 68 #
69 69 # Distributed under the terms of the BSD License. The full license is in
70 70 # the file COPYING, distributed as part of this software.
71 71 #*****************************************************************************
72 72
73 73 from IPython import Release
74 74 __author__ = '%s <%s>\n%s <%s>' % (Release.authors['Nathan']+
75 75 Release.authors['Fernando'])
76 76 __license__ = Release.license
77 77
78 78 # Required modules
79 79 import inspect
80 80 import keyword
81 81 import linecache
82 82 import os
83 83 import pydoc
84 84 import string
85 85 import sys
86 86 import time
87 87 import tokenize
88 88 import traceback
89 89 import types
90 90
91 91 # IPython's own modules
92 92 # Modified pdb which doesn't damage IPython's readline handling
93 93 from IPython import Debugger
94 94 from IPython.Struct import Struct
95 95 from IPython.excolors import ExceptionColors
96 96 from IPython.genutils import Term,uniq_stable,error,info
97 97
98 # Globals
99 # amount of space to put line numbers before verbose tracebacks
100 INDENT_SIZE = 8
101
98 102 #---------------------------------------------------------------------------
99 103 # Code begins
100 104
105 # Utility functions
101 106 def inspect_error():
102 107 """Print a message about internal inspect errors.
103 108
104 109 These are unfortunately quite common."""
105 110
106 111 error('Internal Python error in the inspect module.\n'
107 112 'Below is the traceback from this internal error.\n')
108 113
114 def _fixed_getinnerframes(etb, context=1,tb_offset=0):
115 import linecache
116 LNUM_POS, LINES_POS, INDEX_POS = 2, 4, 5
117
118 records = inspect.getinnerframes(etb, context)
119
120 # If the error is at the console, don't build any context, since it would
121 # otherwise produce 5 blank lines printed out (there is no file at the
122 # console)
123 rec_check = records[tb_offset:]
124 rname = rec_check[0][1]
125 if rname == '<ipython console>' or rname.endswith('<string>'):
126 return rec_check
127
128 aux = traceback.extract_tb(etb)
129 assert len(records) == len(aux)
130 for i, (file, lnum, _, _) in zip(range(len(records)), aux):
131 maybeStart = lnum-1 - context//2
132 start = max(maybeStart, 0)
133 end = start + context
134 lines = linecache.getlines(file)[start:end]
135 # pad with empty lines if necessary
136 if maybeStart < 0:
137 lines = (['\n'] * -maybeStart) + lines
138 if len(lines) < context:
139 lines += ['\n'] * (context - len(lines))
140 assert len(lines) == context
141 buf = list(records[i])
142 buf[LNUM_POS] = lnum
143 buf[INDEX_POS] = lnum - 1 - start
144 buf[LINES_POS] = lines
145 records[i] = tuple(buf)
146 return records[tb_offset:]
147
148 # Helper function -- largely belongs to VerboseTB, but we need the same
149 # functionality to produce a pseudo verbose TB for SyntaxErrors, so that they
150 # can be recognized properly by ipython.el's py-traceback-line-re
151 # (SyntaxErrors have to be treated specially because they have no traceback)
152 def _formatTracebackLines(lnum, index, lines, Colors, lvals=None):
153 numbers_width = INDENT_SIZE - 1
154 res = []
155 i = lnum - index
156 for line in lines:
157 if i == lnum:
158 # This is the line with the error
159 pad = numbers_width - len(str(i))
160 if pad >= 3:
161 marker = '-'*(pad-3) + '-> '
162 elif pad == 2:
163 marker = '> '
164 elif pad == 1:
165 marker = '>'
166 else:
167 marker = ''
168 num = marker + str(i)
169 line = '%s%s%s %s%s' %(Colors.linenoEm, num,
170 Colors.line, line, Colors.Normal)
171 else:
172 num = '%*s' % (numbers_width,i)
173 line = '%s%s%s %s' %(Colors.lineno, num,
174 Colors.Normal, line)
175
176 res.append(line)
177 if lvals and i == lnum:
178 res.append(lvals + '\n')
179 i = i + 1
180 return res
181
182 #---------------------------------------------------------------------------
183 # Module classes
109 184 class TBTools:
110 185 """Basic tools used by all traceback printer classes."""
111 186
112 187 def __init__(self,color_scheme = 'NoColor',call_pdb=False):
113 188 # Whether to call the interactive pdb debugger after printing
114 189 # tracebacks or not
115 190 self.call_pdb = call_pdb
116 191
117 192 # Create color table
118 193 self.color_scheme_table = ExceptionColors
119 194
120 195 self.set_colors(color_scheme)
121 196 self.old_scheme = color_scheme # save initial value for toggles
122 197
123 198 if call_pdb:
124 199 self.pdb = Debugger.Pdb(self.color_scheme_table.active_scheme_name)
125 200 else:
126 201 self.pdb = None
127 202
128 203 def set_colors(self,*args,**kw):
129 204 """Shorthand access to the color table scheme selector method."""
130 205
131 206 self.color_scheme_table.set_active_scheme(*args,**kw)
132 207 # for convenience, set Colors to the active scheme
133 208 self.Colors = self.color_scheme_table.active_colors
134 209
135 210 def color_toggle(self):
136 211 """Toggle between the currently active color scheme and NoColor."""
137 212
138 213 if self.color_scheme_table.active_scheme_name == 'NoColor':
139 214 self.color_scheme_table.set_active_scheme(self.old_scheme)
140 215 self.Colors = self.color_scheme_table.active_colors
141 216 else:
142 217 self.old_scheme = self.color_scheme_table.active_scheme_name
143 218 self.color_scheme_table.set_active_scheme('NoColor')
144 219 self.Colors = self.color_scheme_table.active_colors
145 220
146 221 #---------------------------------------------------------------------------
147 222 class ListTB(TBTools):
148 223 """Print traceback information from a traceback list, with optional color.
149 224
150 225 Calling: requires 3 arguments:
151 226 (etype, evalue, elist)
152 227 as would be obtained by:
153 228 etype, evalue, tb = sys.exc_info()
154 229 if tb:
155 230 elist = traceback.extract_tb(tb)
156 231 else:
157 232 elist = None
158 233
159 234 It can thus be used by programs which need to process the traceback before
160 235 printing (such as console replacements based on the code module from the
161 236 standard library).
162 237
163 238 Because they are meant to be called without a full traceback (only a
164 239 list), instances of this class can't call the interactive pdb debugger."""
165 240
166 241 def __init__(self,color_scheme = 'NoColor'):
167 242 TBTools.__init__(self,color_scheme = color_scheme,call_pdb=0)
168 243
169 244 def __call__(self, etype, value, elist):
170 245 print >> Term.cerr, self.text(etype,value,elist)
171 246
172 247 def text(self,etype, value, elist,context=5):
173 248 """Return a color formatted string with the traceback info."""
174 249
175 250 Colors = self.Colors
176 251 out_string = ['%s%s%s\n' % (Colors.topline,'-'*60,Colors.Normal)]
177 252 if elist:
178 253 out_string.append('Traceback %s(most recent call last)%s:' % \
179 254 (Colors.normalEm, Colors.Normal) + '\n')
180 255 out_string.extend(self._format_list(elist))
181 256 lines = self._format_exception_only(etype, value)
182 257 for line in lines[:-1]:
183 258 out_string.append(" "+line)
184 259 out_string.append(lines[-1])
185 260 return ''.join(out_string)
186 261
187 262 def _format_list(self, extracted_list):
188 263 """Format a list of traceback entry tuples for printing.
189 264
190 265 Given a list of tuples as returned by extract_tb() or
191 266 extract_stack(), return a list of strings ready for printing.
192 267 Each string in the resulting list corresponds to the item with the
193 268 same index in the argument list. Each string ends in a newline;
194 269 the strings may contain internal newlines as well, for those items
195 270 whose source text line is not None.
196 271
197 272 Lifted almost verbatim from traceback.py
198 273 """
199 274
200 275 Colors = self.Colors
201 276 list = []
202 277 for filename, lineno, name, line in extracted_list[:-1]:
203 278 item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \
204 279 (Colors.filename, filename, Colors.Normal,
205 280 Colors.lineno, lineno, Colors.Normal,
206 281 Colors.name, name, Colors.Normal)
207 282 if line:
208 283 item = item + ' %s\n' % line.strip()
209 284 list.append(item)
210 285 # Emphasize the last entry
211 286 filename, lineno, name, line = extracted_list[-1]
212 287 item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \
213 288 (Colors.normalEm,
214 289 Colors.filenameEm, filename, Colors.normalEm,
215 290 Colors.linenoEm, lineno, Colors.normalEm,
216 291 Colors.nameEm, name, Colors.normalEm,
217 292 Colors.Normal)
218 293 if line:
219 294 item = item + '%s %s%s\n' % (Colors.line, line.strip(),
220 295 Colors.Normal)
221 296 list.append(item)
222 297 return list
223 298
224 299 def _format_exception_only(self, etype, value):
225 300 """Format the exception part of a traceback.
226 301
227 302 The arguments are the exception type and value such as given by
228 303 sys.exc_info()[:2]. The return value is a list of strings, each ending
229 304 in a newline. Normally, the list contains a single string; however,
230 305 for SyntaxError exceptions, it contains several lines that (when
231 306 printed) display detailed information about where the syntax error
232 307 occurred. The message indicating which exception occurred is the
233 308 always last string in the list.
234 309
235 310 Also lifted nearly verbatim from traceback.py
236 311 """
237 312
238 313 Colors = self.Colors
239 314 list = []
240 315 if type(etype) == types.ClassType:
241 316 stype = Colors.excName + etype.__name__ + Colors.Normal
242 317 else:
243 318 stype = etype # String exceptions don't get special coloring
244 319 if value is None:
245 320 list.append( str(stype) + '\n')
246 321 else:
247 322 if etype is SyntaxError:
248 323 try:
249 324 msg, (filename, lineno, offset, line) = value
250 325 except:
251 326 pass
252 327 else:
253 328 #print 'filename is',filename # dbg
254 329 if not filename: filename = "<string>"
255 330 list.append('%s File %s"%s"%s, line %s%d%s\n' % \
256 331 (Colors.normalEm,
257 332 Colors.filenameEm, filename, Colors.normalEm,
258 333 Colors.linenoEm, lineno, Colors.Normal ))
259 334 if line is not None:
260 335 i = 0
261 336 while i < len(line) and line[i].isspace():
262 337 i = i+1
263 338 list.append('%s %s%s\n' % (Colors.line,
264 339 line.strip(),
265 340 Colors.Normal))
266 341 if offset is not None:
267 342 s = ' '
268 343 for c in line[i:offset-1]:
269 344 if c.isspace():
270 345 s = s + c
271 346 else:
272 347 s = s + ' '
273 348 list.append('%s%s^%s\n' % (Colors.caret, s,
274 349 Colors.Normal) )
275 350 value = msg
276 351 s = self._some_str(value)
277 352 if s:
278 353 list.append('%s%s:%s %s\n' % (str(stype), Colors.excName,
279 354 Colors.Normal, s))
280 355 else:
281 356 list.append('%s\n' % str(stype))
282 357 return list
283 358
284 359 def _some_str(self, value):
285 360 # Lifted from traceback.py
286 361 try:
287 362 return str(value)
288 363 except:
289 364 return '<unprintable %s object>' % type(value).__name__
290 365
291 366 #----------------------------------------------------------------------------
292 367 class VerboseTB(TBTools):
293 368 """A port of Ka-Ping Yee's cgitb.py module that outputs color text instead
294 369 of HTML. Requires inspect and pydoc. Crazy, man.
295 370
296 371 Modified version which optionally strips the topmost entries from the
297 372 traceback, to be used with alternate interpreters (because their own code
298 373 would appear in the traceback)."""
299 374
300 375 def __init__(self,color_scheme = 'Linux',tb_offset=0,long_header=0,
301 376 call_pdb = 0, include_vars=1):
302 377 """Specify traceback offset, headers and color scheme.
303 378
304 379 Define how many frames to drop from the tracebacks. Calling it with
305 380 tb_offset=1 allows use of this handler in interpreters which will have
306 381 their own code at the top of the traceback (VerboseTB will first
307 382 remove that frame before printing the traceback info)."""
308 383 TBTools.__init__(self,color_scheme=color_scheme,call_pdb=call_pdb)
309 384 self.tb_offset = tb_offset
310 385 self.long_header = long_header
311 386 self.include_vars = include_vars
312 387
313 388 def text(self, etype, evalue, etb, context=5):
314 389 """Return a nice text document describing the traceback."""
315 390
316 391 # some locals
317 392 Colors = self.Colors # just a shorthand + quicker name lookup
318 393 ColorsNormal = Colors.Normal # used a lot
319 indent_size = 8 # we need some space to put line numbers before
320 indent = ' '*indent_size
321 numbers_width = indent_size - 1 # leave space between numbers & code
394 indent = ' '*INDENT_SIZE
322 395 text_repr = pydoc.text.repr
323 396 exc = '%s%s%s' % (Colors.excName, str(etype), ColorsNormal)
324 397 em_normal = '%s\n%s%s' % (Colors.valEm, indent,ColorsNormal)
325 398 undefined = '%sundefined%s' % (Colors.em, ColorsNormal)
326 399
327 400 # some internal-use functions
328 401 def eqrepr(value, repr=text_repr): return '=%s' % repr(value)
329 402 def nullrepr(value, repr=text_repr): return ''
330 403
331 404 # meat of the code begins
332 405 if type(etype) is types.ClassType:
333 406 etype = etype.__name__
334 407
335 408 if self.long_header:
336 409 # Header with the exception type, python version, and date
337 410 pyver = 'Python ' + string.split(sys.version)[0] + ': ' + sys.executable
338 411 date = time.ctime(time.time())
339 412
340 413 head = '%s%s%s\n%s%s%s\n%s' % (Colors.topline, '-'*75, ColorsNormal,
341 414 exc, ' '*(75-len(str(etype))-len(pyver)),
342 415 pyver, string.rjust(date, 75) )
343 416 head += "\nA problem occured executing Python code. Here is the sequence of function"\
344 417 "\ncalls leading up to the error, with the most recent (innermost) call last."
345 418 else:
346 419 # Simplified header
347 420 head = '%s%s%s\n%s%s' % (Colors.topline, '-'*75, ColorsNormal,exc,
348 421 string.rjust('Traceback (most recent call last)',
349 422 75 - len(str(etype)) ) )
350 423 frames = []
351 424 # Flush cache before calling inspect. This helps alleviate some of the
352 425 # problems with python 2.3's inspect.py.
353 426 linecache.checkcache()
354 427 # Drop topmost frames if requested
355 428 try:
356 records = inspect.getinnerframes(etb, context)[self.tb_offset:]
429 # Try the default getinnerframes and Alex's: Alex's fixes some
430 # problems, but it generates empty tracebacks for console errors
431 # (5 blanks lines) where none should be returned.
432 #records = inspect.getinnerframes(etb, context)[self.tb_offset:]
433 #print 'python records:', records # dbg
434 records = _fixed_getinnerframes(etb, context,self.tb_offset)
435 #print 'alex records:', records # dbg
357 436 except:
358 437
359 438 # FIXME: I've been getting many crash reports from python 2.3
360 439 # users, traceable to inspect.py. If I can find a small test-case
361 440 # to reproduce this, I should either write a better workaround or
362 441 # file a bug report against inspect (if that's the real problem).
363 442 # So far, I haven't been able to find an isolated example to
364 443 # reproduce the problem.
365 444 inspect_error()
366 445 traceback.print_exc(file=Term.cerr)
367 446 info('\nUnfortunately, your original traceback can not be constructed.\n')
368 447 return ''
369 448
370 449 # build some color string templates outside these nested loops
371 450 tpl_link = '%s%%s%s' % (Colors.filenameEm,ColorsNormal)
372 451 tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm,
373 452 ColorsNormal)
374 453 tpl_call_fail = 'in %s%%s%s(***failed resolving arguments***)%s' % \
375 454 (Colors.vName, Colors.valEm, ColorsNormal)
376 455 tpl_local_var = '%s%%s%s' % (Colors.vName, ColorsNormal)
377 456 tpl_global_var = '%sglobal%s %s%%s%s' % (Colors.em, ColorsNormal,
378 457 Colors.vName, ColorsNormal)
379 458 tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal)
380 459 tpl_line = '%s%%s%s %%s' % (Colors.lineno, ColorsNormal)
381 460 tpl_line_em = '%s%%s%s %%s%s' % (Colors.linenoEm,Colors.line,
382 461 ColorsNormal)
383 462
384 463 # now, loop over all records printing context and info
385 464 abspath = os.path.abspath
386 465 for frame, file, lnum, func, lines, index in records:
387 466 #print '*** record:',file,lnum,func,lines,index # dbg
388 467 try:
389 468 file = file and abspath(file) or '?'
390 469 except OSError:
391 470 # if file is '<console>' or something not in the filesystem,
392 471 # the abspath call will throw an OSError. Just ignore it and
393 472 # keep the original file string.
394 473 pass
395 474 link = tpl_link % file
396 475 try:
397 476 args, varargs, varkw, locals = inspect.getargvalues(frame)
398 477 except:
399 478 # This can happen due to a bug in python2.3. We should be
400 479 # able to remove this try/except when 2.4 becomes a
401 480 # requirement. Bug details at http://python.org/sf/1005466
402 481 inspect_error()
403 482 traceback.print_exc(file=Term.cerr)
404 483 info("\nIPython's exception reporting continues...\n")
405 484
406 485 if func == '?':
407 486 call = ''
408 487 else:
409 488 # Decide whether to include variable details or not
410 489 var_repr = self.include_vars and eqrepr or nullrepr
411 490 try:
412 491 call = tpl_call % (func,inspect.formatargvalues(args,
413 492 varargs, varkw,
414 493 locals,formatvalue=var_repr))
415 494 except KeyError:
416 495 # Very odd crash from inspect.formatargvalues(). The
417 496 # scenario under which it appeared was a call to
418 497 # view(array,scale) in NumTut.view.view(), where scale had
419 498 # been defined as a scalar (it should be a tuple). Somehow
420 499 # inspect messes up resolving the argument list of view()
421 500 # and barfs out. At some point I should dig into this one
422 501 # and file a bug report about it.
423 502 inspect_error()
424 503 traceback.print_exc(file=Term.cerr)
425 504 info("\nIPython's exception reporting continues...\n")
426 505 call = tpl_call_fail % func
427 506
428 507 # Initialize a list of names on the current line, which the
429 508 # tokenizer below will populate.
430 509 names = []
431 510
432 511 def tokeneater(token_type, token, start, end, line):
433 512 """Stateful tokeneater which builds dotted names.
434 513
435 514 The list of names it appends to (from the enclosing scope) can
436 515 contain repeated composite names. This is unavoidable, since
437 516 there is no way to disambguate partial dotted structures until
438 517 the full list is known. The caller is responsible for pruning
439 518 the final list of duplicates before using it."""
440 519
441 520 # build composite names
442 521 if token == '.':
443 522 try:
444 523 names[-1] += '.'
445 524 # store state so the next token is added for x.y.z names
446 525 tokeneater.name_cont = True
447 526 return
448 527 except IndexError:
449 528 pass
450 529 if token_type == tokenize.NAME and token not in keyword.kwlist:
451 530 if tokeneater.name_cont:
452 531 # Dotted names
453 532 names[-1] += token
454 533 tokeneater.name_cont = False
455 534 else:
456 535 # Regular new names. We append everything, the caller
457 536 # will be responsible for pruning the list later. It's
458 537 # very tricky to try to prune as we go, b/c composite
459 538 # names can fool us. The pruning at the end is easy
460 539 # to do (or the caller can print a list with repeated
461 540 # names if so desired.
462 541 names.append(token)
463 542 elif token_type == tokenize.NEWLINE:
464 543 raise IndexError
465 544 # we need to store a bit of state in the tokenizer to build
466 545 # dotted names
467 546 tokeneater.name_cont = False
468 547
469 548 def linereader(file=file, lnum=[lnum], getline=linecache.getline):
470 549 line = getline(file, lnum[0])
471 550 lnum[0] += 1
472 551 return line
473 552
474 553 # Build the list of names on this line of code where the exception
475 554 # occurred.
476 555 try:
477 556 # This builds the names list in-place by capturing it from the
478 557 # enclosing scope.
479 558 tokenize.tokenize(linereader, tokeneater)
480 559 except IndexError:
481 560 # signals exit of tokenizer
482 561 pass
483 562 except tokenize.TokenError,msg:
484 563 _m = ("An unexpected error occurred while tokenizing input\n"
485 564 "The following traceback may be corrupted or invalid\n"
486 565 "The error message is: %s\n" % msg)
487 566 error(_m)
488 567
489 568 # prune names list of duplicates, but keep the right order
490 569 unique_names = uniq_stable(names)
491 570
492 571 # Start loop over vars
493 572 lvals = []
494 573 if self.include_vars:
495 574 for name_full in unique_names:
496 575 name_base = name_full.split('.',1)[0]
497 576 if name_base in frame.f_code.co_varnames:
498 577 if locals.has_key(name_base):
499 578 try:
500 579 value = repr(eval(name_full,locals))
501 580 except:
502 581 value = undefined
503 582 else:
504 583 value = undefined
505 584 name = tpl_local_var % name_full
506 585 else:
507 586 if frame.f_globals.has_key(name_base):
508 587 try:
509 588 value = repr(eval(name_full,frame.f_globals))
510 589 except:
511 590 value = undefined
512 591 else:
513 592 value = undefined
514 593 name = tpl_global_var % name_full
515 594 lvals.append(tpl_name_val % (name,value))
516 595 if lvals:
517 596 lvals = '%s%s' % (indent,em_normal.join(lvals))
518 597 else:
519 598 lvals = ''
520 599
521 600 level = '%s %s\n' % (link,call)
522 excerpt = []
523 if index is not None:
524 i = lnum - index
525 for line in lines:
526 if i == lnum:
527 # This is the line with the error
528 pad = numbers_width - len(str(i))
529 if pad >= 3:
530 marker = '-'*(pad-3) + '-> '
531 elif pad == 2:
532 marker = '> '
533 elif pad == 1:
534 marker = '>'
535 else:
536 marker = ''
537 num = '%s%s' % (marker,i)
538 line = tpl_line_em % (num,line)
539 else:
540 num = '%*s' % (numbers_width,i)
541 line = tpl_line % (num,line)
542
543 excerpt.append(line)
544 if self.include_vars and i == lnum:
545 excerpt.append('%s\n' % lvals)
546 i += 1
547 frames.append('%s%s' % (level,''.join(excerpt)) )
601
602 if index is None:
603 frames.append(level)
604 else:
605 frames.append('%s%s' % (level,''.join(
606 _formatTracebackLines(lnum,index,lines,self.Colors,lvals))))
548 607
549 608 # Get (safely) a string form of the exception info
550 609 try:
551 610 etype_str,evalue_str = map(str,(etype,evalue))
552 611 except:
553 612 # User exception is improperly defined.
554 613 etype,evalue = str,sys.exc_info()[:2]
555 614 etype_str,evalue_str = map(str,(etype,evalue))
556 615 # ... and format it
557 616 exception = ['%s%s%s: %s' % (Colors.excName, etype_str,
558 617 ColorsNormal, evalue_str)]
559 618 if type(evalue) is types.InstanceType:
560 619 try:
561 620 names = [w for w in dir(evalue) if isinstance(w, basestring)]
562 621 except:
563 622 # Every now and then, an object with funny inernals blows up
564 623 # when dir() is called on it. We do the best we can to report
565 624 # the problem and continue
566 625 _m = '%sException reporting error (object with broken dir())%s:'
567 626 exception.append(_m % (Colors.excName,ColorsNormal))
568 627 etype_str,evalue_str = map(str,sys.exc_info()[:2])
569 628 exception.append('%s%s%s: %s' % (Colors.excName,etype_str,
570 629 ColorsNormal, evalue_str))
571 630 names = []
572 631 for name in names:
573 632 value = text_repr(getattr(evalue, name))
574 633 exception.append('\n%s%s = %s' % (indent, name, value))
575 634 # return all our info assembled as a single string
576 635 return '%s\n\n%s\n%s' % (head,'\n'.join(frames),''.join(exception[0]) )
577 636
578 637 def debugger(self):
579 638 """Call up the pdb debugger if desired, always clean up the tb reference.
580 639
581 640 If the call_pdb flag is set, the pdb interactive debugger is
582 641 invoked. In all cases, the self.tb reference to the current traceback
583 642 is deleted to prevent lingering references which hamper memory
584 643 management.
585 644
586 645 Note that each call to pdb() does an 'import readline', so if your app
587 646 requires a special setup for the readline completers, you'll have to
588 647 fix that by hand after invoking the exception handler."""
589 648
590 649 if self.call_pdb:
591 650 if self.pdb is None:
592 651 self.pdb = Debugger.Pdb(
593 652 self.color_scheme_table.active_scheme_name)
594 653 # the system displayhook may have changed, restore the original
595 654 # for pdb
596 655 dhook = sys.displayhook
597 656 sys.displayhook = sys.__displayhook__
598 657 self.pdb.reset()
599 658 # Find the right frame so we don't pop up inside ipython itself
600 659 etb = self.tb
601 660 while self.tb.tb_next is not None:
602 661 self.tb = self.tb.tb_next
603 662 try:
604 663 if etb and etb.tb_next:
605 664 etb = etb.tb_next
606 665 self.pdb.botframe = etb.tb_frame
607 666 self.pdb.interaction(self.tb.tb_frame, self.tb)
608 667 except:
609 668 print '*** ERROR ***'
610 669 print 'This version of pdb has a bug and crashed.'
611 670 print 'Returning to IPython...'
612 671 sys.displayhook = dhook
613 672 del self.tb
614 673
615 674 def handler(self, info=None):
616 675 (etype, evalue, etb) = info or sys.exc_info()
617 676 self.tb = etb
618 677 print >> Term.cerr, self.text(etype, evalue, etb)
619 678
620 679 # Changed so an instance can just be called as VerboseTB_inst() and print
621 680 # out the right info on its own.
622 681 def __call__(self, etype=None, evalue=None, etb=None):
623 682 """This hook can replace sys.excepthook (for Python 2.1 or higher)."""
624 683 if etb is None:
625 684 self.handler()
626 685 else:
627 686 self.handler((etype, evalue, etb))
628 687 self.debugger()
629 688
630 689 #----------------------------------------------------------------------------
631 690 class FormattedTB(VerboseTB,ListTB):
632 691 """Subclass ListTB but allow calling with a traceback.
633 692
634 693 It can thus be used as a sys.excepthook for Python > 2.1.
635 694
636 695 Also adds 'Context' and 'Verbose' modes, not available in ListTB.
637 696
638 697 Allows a tb_offset to be specified. This is useful for situations where
639 698 one needs to remove a number of topmost frames from the traceback (such as
640 699 occurs with python programs that themselves execute other python code,
641 700 like Python shells). """
642 701
643 702 def __init__(self, mode = 'Plain', color_scheme='Linux',
644 703 tb_offset = 0,long_header=0,call_pdb=0,include_vars=0):
645 704
646 705 # NEVER change the order of this list. Put new modes at the end:
647 706 self.valid_modes = ['Plain','Context','Verbose']
648 707 self.verbose_modes = self.valid_modes[1:3]
649 708
650 709 VerboseTB.__init__(self,color_scheme,tb_offset,long_header,
651 710 call_pdb=call_pdb,include_vars=include_vars)
652 711 self.set_mode(mode)
653 712
654 713 def _extract_tb(self,tb):
655 714 if tb:
656 715 return traceback.extract_tb(tb)
657 716 else:
658 717 return None
659 718
660 719 def text(self, etype, value, tb,context=5,mode=None):
661 720 """Return formatted traceback.
662 721
663 722 If the optional mode parameter is given, it overrides the current
664 723 mode."""
665 724
666 725 if mode is None:
667 726 mode = self.mode
668 727 if mode in self.verbose_modes:
669 728 # verbose modes need a full traceback
670 729 return VerboseTB.text(self,etype, value, tb,context=5)
671 730 else:
672 731 # We must check the source cache because otherwise we can print
673 732 # out-of-date source code.
674 733 linecache.checkcache()
675 734 # Now we can extract and format the exception
676 735 elist = self._extract_tb(tb)
677 736 if len(elist) > self.tb_offset:
678 737 del elist[:self.tb_offset]
679 738 return ListTB.text(self,etype,value,elist)
680 739
681 740 def set_mode(self,mode=None):
682 741 """Switch to the desired mode.
683 742
684 743 If mode is not specified, cycles through the available modes."""
685 744
686 745 if not mode:
687 746 new_idx = ( self.valid_modes.index(self.mode) + 1 ) % \
688 747 len(self.valid_modes)
689 748 self.mode = self.valid_modes[new_idx]
690 749 elif mode not in self.valid_modes:
691 750 raise ValueError, 'Unrecognized mode in FormattedTB: <'+mode+'>\n'\
692 751 'Valid modes: '+str(self.valid_modes)
693 752 else:
694 753 self.mode = mode
695 754 # include variable details only in 'Verbose' mode
696 755 self.include_vars = (self.mode == self.valid_modes[2])
697 756
698 757 # some convenient shorcuts
699 758 def plain(self):
700 759 self.set_mode(self.valid_modes[0])
701 760
702 761 def context(self):
703 762 self.set_mode(self.valid_modes[1])
704 763
705 764 def verbose(self):
706 765 self.set_mode(self.valid_modes[2])
707 766
708 767 #----------------------------------------------------------------------------
709 768 class AutoFormattedTB(FormattedTB):
710 769 """A traceback printer which can be called on the fly.
711 770
712 771 It will find out about exceptions by itself.
713 772
714 773 A brief example:
715 774
716 775 AutoTB = AutoFormattedTB(mode = 'Verbose',color_scheme='Linux')
717 776 try:
718 777 ...
719 778 except:
720 779 AutoTB() # or AutoTB(out=logfile) where logfile is an open file object
721 780 """
722 781 def __call__(self,etype=None,evalue=None,etb=None,
723 782 out=None,tb_offset=None):
724 783 """Print out a formatted exception traceback.
725 784
726 785 Optional arguments:
727 786 - out: an open file-like object to direct output to.
728 787
729 788 - tb_offset: the number of frames to skip over in the stack, on a
730 789 per-call basis (this overrides temporarily the instance's tb_offset
731 790 given at initialization time. """
732 791
733 792 if out is None:
734 793 out = Term.cerr
735 794 if tb_offset is not None:
736 795 tb_offset, self.tb_offset = self.tb_offset, tb_offset
737 796 print >> out, self.text(etype, evalue, etb)
738 797 self.tb_offset = tb_offset
739 798 else:
740 799 print >> out, self.text(etype, evalue, etb)
741 800 self.debugger()
742 801
743 802 def text(self,etype=None,value=None,tb=None,context=5,mode=None):
744 803 if etype is None:
745 804 etype,value,tb = sys.exc_info()
746 805 self.tb = tb
747 806 return FormattedTB.text(self,etype,value,tb,context=5,mode=mode)
748 807
749 808 #---------------------------------------------------------------------------
750 809 # A simple class to preserve Nathan's original functionality.
751 810 class ColorTB(FormattedTB):
752 811 """Shorthand to initialize a FormattedTB in Linux colors mode."""
753 812 def __init__(self,color_scheme='Linux',call_pdb=0):
754 813 FormattedTB.__init__(self,color_scheme=color_scheme,
755 814 call_pdb=call_pdb)
756 815
757 816 #----------------------------------------------------------------------------
758 817 # module testing (minimal)
759 818 if __name__ == "__main__":
760 819 def spam(c, (d, e)):
761 820 x = c + d
762 821 y = c * d
763 822 foo(x, y)
764 823
765 824 def foo(a, b, bar=1):
766 825 eggs(a, b + bar)
767 826
768 827 def eggs(f, g, z=globals()):
769 828 h = f + g
770 829 i = f - g
771 830 return h / i
772 831
773 832 print ''
774 833 print '*** Before ***'
775 834 try:
776 835 print spam(1, (2, 3))
777 836 except:
778 837 traceback.print_exc()
779 838 print ''
780 839
781 840 handler = ColorTB()
782 841 print '*** ColorTB ***'
783 842 try:
784 843 print spam(1, (2, 3))
785 844 except:
786 845 apply(handler, sys.exc_info() )
787 846 print ''
788 847
789 848 handler = VerboseTB()
790 849 print '*** VerboseTB ***'
791 850 try:
792 851 print spam(1, (2, 3))
793 852 except:
794 853 apply(handler, sys.exc_info() )
795 854 print ''
796 855
@@ -1,4726 +1,4749 b''
1 2006-01-02 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/ultraTB.py (_fixed_getinnerframes): added Alex
4 Schmolck's patch to fix inspect.getinnerframes().
5
6 * IPython/iplib.py (InteractiveShell.__init__): significant fixes
7 for embedded instances, regarding handling of namespaces and items
8 added to the __builtin__ one. Multiple embedded instances and
9 recursive embeddings should work better now (though I'm not sure
10 I've got all the corner cases fixed, that code is a bit of a brain
11 twister).
12
13 * IPython/Magic.py (magic_edit): added support to edit in-memory
14 macros (automatically creates the necessary temp files). %edit
15 also doesn't return the file contents anymore, it's just noise.
16
17 * IPython/completer.py (Completer.attr_matches): revert change to
18 complete only on attributes listed in __all__. I realized it
19 cripples the tab-completion system as a tool for exploring the
20 internals of unknown libraries (it renders any non-__all__
21 attribute off-limits). I got bit by this when trying to see
22 something inside the dis module.
23
1 24 2005-12-31 Fernando Perez <Fernando.Perez@colorado.edu>
2 25
3 26 * IPython/iplib.py (InteractiveShell.__init__): add .meta
4 27 namespace for users and extension writers to hold data in. This
5 28 follows the discussion in
6 29 http://projects.scipy.org/ipython/ipython/wiki/RefactoringIPython.
7 30
8 31 * IPython/completer.py (IPCompleter.complete): small patch to help
9 32 tab-completion under Emacs, after a suggestion by John Barnard
10 33 <barnarj-AT-ccf.org>.
11 34
12 35 * IPython/Magic.py (Magic.extract_input_slices): added support for
13 36 the slice notation in magics to use N-M to represent numbers N...M
14 37 (closed endpoints). This is used by %macro and %save.
15 38
16 39 * IPython/completer.py (Completer.attr_matches): for modules which
17 40 define __all__, complete only on those. After a patch by Jeffrey
18 41 Collins <jcollins_boulder-AT-earthlink.net>. Also, clean up and
19 42 speed up this routine.
20 43
21 44 * IPython/Logger.py (Logger.log): fix a history handling bug. I
22 45 don't know if this is the end of it, but the behavior now is
23 46 certainly much more correct. Note that coupled with macros,
24 47 slightly surprising (at first) behavior may occur: a macro will in
25 48 general expand to multiple lines of input, so upon exiting, the
26 49 in/out counters will both be bumped by the corresponding amount
27 50 (as if the macro's contents had been typed interactively). Typing
28 51 %hist will reveal the intermediate (silently processed) lines.
29 52
30 53 * IPython/Magic.py (magic_run): fix a subtle bug which could cause
31 54 pickle to fail (%run was overwriting __main__ and not restoring
32 55 it, but pickle relies on __main__ to operate).
33 56
34 57 * IPython/iplib.py (InteractiveShell): fix pdb calling: I'm now
35 58 using properties, but forgot to make the main InteractiveShell
36 59 class a new-style class. Properties fail silently, and
37 60 misteriously, with old-style class (getters work, but
38 61 setters don't do anything).
39 62
40 63 2005-12-30 Fernando Perez <Fernando.Perez@colorado.edu>
41 64
42 65 * IPython/Magic.py (magic_history): fix history reporting bug (I
43 66 know some nasties are still there, I just can't seem to find a
44 67 reproducible test case to track them down; the input history is
45 68 falling out of sync...)
46 69
47 70 * IPython/iplib.py (handle_shell_escape): fix bug where both
48 71 aliases and system accesses where broken for indented code (such
49 72 as loops).
50 73
51 74 * IPython/genutils.py (shell): fix small but critical bug for
52 75 win32 system access.
53 76
54 77 2005-12-29 Fernando Perez <Fernando.Perez@colorado.edu>
55 78
56 79 * IPython/iplib.py (showtraceback): remove use of the
57 80 sys.last_{type/value/traceback} structures, which are non
58 81 thread-safe.
59 82 (_prefilter): change control flow to ensure that we NEVER
60 83 introspect objects when autocall is off. This will guarantee that
61 84 having an input line of the form 'x.y', where access to attribute
62 85 'y' has side effects, doesn't trigger the side effect TWICE. It
63 86 is important to note that, with autocall on, these side effects
64 87 can still happen.
65 88 (ipsystem): new builtin, to complete the ip{magic/alias/system}
66 89 trio. IPython offers these three kinds of special calls which are
67 90 not python code, and it's a good thing to have their call method
68 91 be accessible as pure python functions (not just special syntax at
69 92 the command line). It gives us a better internal implementation
70 93 structure, as well as exposing these for user scripting more
71 94 cleanly.
72 95
73 96 * IPython/macro.py (Macro.__init__): moved macros to a standalone
74 97 file. Now that they'll be more likely to be used with the
75 98 persistance system (%store), I want to make sure their module path
76 99 doesn't change in the future, so that we don't break things for
77 100 users' persisted data.
78 101
79 102 * IPython/iplib.py (autoindent_update): move indentation
80 103 management into the _text_ processing loop, not the keyboard
81 104 interactive one. This is necessary to correctly process non-typed
82 105 multiline input (such as macros).
83 106
84 107 * IPython/Magic.py (Magic.format_latex): patch by Stefan van der
85 108 Walt <stefan-AT-sun.ac.za> to fix latex formatting of docstrings,
86 109 which was producing problems in the resulting manual.
87 110 (magic_whos): improve reporting of instances (show their class,
88 111 instead of simply printing 'instance' which isn't terribly
89 112 informative).
90 113
91 114 * IPython/genutils.py (shell): commit Jorgen Stenarson's patch
92 115 (minor mods) to support network shares under win32.
93 116
94 117 * IPython/winconsole.py (get_console_size): add new winconsole
95 118 module and fixes to page_dumb() to improve its behavior under
96 119 win32. Contributed by Alexander Belchenko <bialix-AT-ukr.net>.
97 120
98 121 * IPython/Magic.py (Macro): simplified Macro class to just
99 122 subclass list. We've had only 2.2 compatibility for a very long
100 123 time, yet I was still avoiding subclassing the builtin types. No
101 124 more (I'm also starting to use properties, though I won't shift to
102 125 2.3-specific features quite yet).
103 126 (magic_store): added Ville's patch for lightweight variable
104 127 persistence, after a request on the user list by Matt Wilkie
105 128 <maphew-AT-gmail.com>. The new %store magic's docstring has full
106 129 details.
107 130
108 131 * IPython/iplib.py (InteractiveShell.post_config_initialization):
109 132 changed the default logfile name from 'ipython.log' to
110 133 'ipython_log.py'. These logs are real python files, and now that
111 134 we have much better multiline support, people are more likely to
112 135 want to use them as such. Might as well name them correctly.
113 136
114 137 * IPython/Magic.py: substantial cleanup. While we can't stop
115 138 using magics as mixins, due to the existing customizations 'out
116 139 there' which rely on the mixin naming conventions, at least I
117 140 cleaned out all cross-class name usage. So once we are OK with
118 141 breaking compatibility, the two systems can be separated.
119 142
120 143 * IPython/Logger.py: major cleanup. This one is NOT a mixin
121 144 anymore, and the class is a fair bit less hideous as well. New
122 145 features were also introduced: timestamping of input, and logging
123 146 of output results. These are user-visible with the -t and -o
124 147 options to %logstart. Closes
125 148 http://www.scipy.net/roundup/ipython/issue11 and a request by
126 149 William Stein (SAGE developer - http://modular.ucsd.edu/sage).
127 150
128 151 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
129 152
130 153 * IPython/iplib.py (handle_shell_escape): add Ville's patch to
131 154 better hadnle backslashes in paths. See the thread 'More Windows
132 155 questions part 2 - \/ characters revisited' on the iypthon user
133 156 list:
134 157 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
135 158
136 159 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
137 160
138 161 (InteractiveShell.__init__): change threaded shells to not use the
139 162 ipython crash handler. This was causing more problems than not,
140 163 as exceptions in the main thread (GUI code, typically) would
141 164 always show up as a 'crash', when they really weren't.
142 165
143 166 The colors and exception mode commands (%colors/%xmode) have been
144 167 synchronized to also take this into account, so users can get
145 168 verbose exceptions for their threaded code as well. I also added
146 169 support for activating pdb inside this exception handler as well,
147 170 so now GUI authors can use IPython's enhanced pdb at runtime.
148 171
149 172 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
150 173 true by default, and add it to the shipped ipythonrc file. Since
151 174 this asks the user before proceeding, I think it's OK to make it
152 175 true by default.
153 176
154 177 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
155 178 of the previous special-casing of input in the eval loop. I think
156 179 this is cleaner, as they really are commands and shouldn't have
157 180 a special role in the middle of the core code.
158 181
159 182 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
160 183
161 184 * IPython/iplib.py (edit_syntax_error): added support for
162 185 automatically reopening the editor if the file had a syntax error
163 186 in it. Thanks to scottt who provided the patch at:
164 187 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
165 188 version committed).
166 189
167 190 * IPython/iplib.py (handle_normal): add suport for multi-line
168 191 input with emtpy lines. This fixes
169 192 http://www.scipy.net/roundup/ipython/issue43 and a similar
170 193 discussion on the user list.
171 194
172 195 WARNING: a behavior change is necessarily introduced to support
173 196 blank lines: now a single blank line with whitespace does NOT
174 197 break the input loop, which means that when autoindent is on, by
175 198 default hitting return on the next (indented) line does NOT exit.
176 199
177 200 Instead, to exit a multiline input you can either have:
178 201
179 202 - TWO whitespace lines (just hit return again), or
180 203 - a single whitespace line of a different length than provided
181 204 by the autoindent (add or remove a space).
182 205
183 206 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
184 207 module to better organize all readline-related functionality.
185 208 I've deleted FlexCompleter and put all completion clases here.
186 209
187 210 * IPython/iplib.py (raw_input): improve indentation management.
188 211 It is now possible to paste indented code with autoindent on, and
189 212 the code is interpreted correctly (though it still looks bad on
190 213 screen, due to the line-oriented nature of ipython).
191 214 (MagicCompleter.complete): change behavior so that a TAB key on an
192 215 otherwise empty line actually inserts a tab, instead of completing
193 216 on the entire global namespace. This makes it easier to use the
194 217 TAB key for indentation. After a request by Hans Meine
195 218 <hans_meine-AT-gmx.net>
196 219 (_prefilter): add support so that typing plain 'exit' or 'quit'
197 220 does a sensible thing. Originally I tried to deviate as little as
198 221 possible from the default python behavior, but even that one may
199 222 change in this direction (thread on python-dev to that effect).
200 223 Regardless, ipython should do the right thing even if CPython's
201 224 '>>>' prompt doesn't.
202 225 (InteractiveShell): removed subclassing code.InteractiveConsole
203 226 class. By now we'd overridden just about all of its methods: I've
204 227 copied the remaining two over, and now ipython is a standalone
205 228 class. This will provide a clearer picture for the chainsaw
206 229 branch refactoring.
207 230
208 231 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
209 232
210 233 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
211 234 failures for objects which break when dir() is called on them.
212 235
213 236 * IPython/FlexCompleter.py (Completer.__init__): Added support for
214 237 distinct local and global namespaces in the completer API. This
215 238 change allows us top properly handle completion with distinct
216 239 scopes, including in embedded instances (this had never really
217 240 worked correctly).
218 241
219 242 Note: this introduces a change in the constructor for
220 243 MagicCompleter, as a new global_namespace parameter is now the
221 244 second argument (the others were bumped one position).
222 245
223 246 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
224 247
225 248 * IPython/iplib.py (embed_mainloop): fix tab-completion in
226 249 embedded instances (which can be done now thanks to Vivian's
227 250 frame-handling fixes for pdb).
228 251 (InteractiveShell.__init__): Fix namespace handling problem in
229 252 embedded instances. We were overwriting __main__ unconditionally,
230 253 and this should only be done for 'full' (non-embedded) IPython;
231 254 embedded instances must respect the caller's __main__. Thanks to
232 255 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
233 256
234 257 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
235 258
236 259 * setup.py: added download_url to setup(). This registers the
237 260 download address at PyPI, which is not only useful to humans
238 261 browsing the site, but is also picked up by setuptools (the Eggs
239 262 machinery). Thanks to Ville and R. Kern for the info/discussion
240 263 on this.
241 264
242 265 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
243 266
244 267 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
245 268 This brings a lot of nice functionality to the pdb mode, which now
246 269 has tab-completion, syntax highlighting, and better stack handling
247 270 than before. Many thanks to Vivian De Smedt
248 271 <vivian-AT-vdesmedt.com> for the original patches.
249 272
250 273 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
251 274
252 275 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
253 276 sequence to consistently accept the banner argument. The
254 277 inconsistency was tripping SAGE, thanks to Gary Zablackis
255 278 <gzabl-AT-yahoo.com> for the report.
256 279
257 280 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
258 281
259 282 * IPython/iplib.py (InteractiveShell.post_config_initialization):
260 283 Fix bug where a naked 'alias' call in the ipythonrc file would
261 284 cause a crash. Bug reported by Jorgen Stenarson.
262 285
263 286 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
264 287
265 288 * IPython/ipmaker.py (make_IPython): cleanups which should improve
266 289 startup time.
267 290
268 291 * IPython/iplib.py (runcode): my globals 'fix' for embedded
269 292 instances had introduced a bug with globals in normal code. Now
270 293 it's working in all cases.
271 294
272 295 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
273 296 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
274 297 has been introduced to set the default case sensitivity of the
275 298 searches. Users can still select either mode at runtime on a
276 299 per-search basis.
277 300
278 301 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
279 302
280 303 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
281 304 attributes in wildcard searches for subclasses. Modified version
282 305 of a patch by Jorgen.
283 306
284 307 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
285 308
286 309 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
287 310 embedded instances. I added a user_global_ns attribute to the
288 311 InteractiveShell class to handle this.
289 312
290 313 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
291 314
292 315 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
293 316 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
294 317 (reported under win32, but may happen also in other platforms).
295 318 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
296 319
297 320 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
298 321
299 322 * IPython/Magic.py (magic_psearch): new support for wildcard
300 323 patterns. Now, typing ?a*b will list all names which begin with a
301 324 and end in b, for example. The %psearch magic has full
302 325 docstrings. Many thanks to JΓΆrgen Stenarson
303 326 <jorgen.stenarson-AT-bostream.nu>, author of the patches
304 327 implementing this functionality.
305 328
306 329 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
307 330
308 331 * Manual: fixed long-standing annoyance of double-dashes (as in
309 332 --prefix=~, for example) being stripped in the HTML version. This
310 333 is a latex2html bug, but a workaround was provided. Many thanks
311 334 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
312 335 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
313 336 rolling. This seemingly small issue had tripped a number of users
314 337 when first installing, so I'm glad to see it gone.
315 338
316 339 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
317 340
318 341 * IPython/Extensions/numeric_formats.py: fix missing import,
319 342 reported by Stephen Walton.
320 343
321 344 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
322 345
323 346 * IPython/demo.py: finish demo module, fully documented now.
324 347
325 348 * IPython/genutils.py (file_read): simple little utility to read a
326 349 file and ensure it's closed afterwards.
327 350
328 351 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
329 352
330 353 * IPython/demo.py (Demo.__init__): added support for individually
331 354 tagging blocks for automatic execution.
332 355
333 356 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
334 357 syntax-highlighted python sources, requested by John.
335 358
336 359 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
337 360
338 361 * IPython/demo.py (Demo.again): fix bug where again() blocks after
339 362 finishing.
340 363
341 364 * IPython/genutils.py (shlex_split): moved from Magic to here,
342 365 where all 2.2 compatibility stuff lives. I needed it for demo.py.
343 366
344 367 * IPython/demo.py (Demo.__init__): added support for silent
345 368 blocks, improved marks as regexps, docstrings written.
346 369 (Demo.__init__): better docstring, added support for sys.argv.
347 370
348 371 * IPython/genutils.py (marquee): little utility used by the demo
349 372 code, handy in general.
350 373
351 374 * IPython/demo.py (Demo.__init__): new class for interactive
352 375 demos. Not documented yet, I just wrote it in a hurry for
353 376 scipy'05. Will docstring later.
354 377
355 378 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
356 379
357 380 * IPython/Shell.py (sigint_handler): Drastic simplification which
358 381 also seems to make Ctrl-C work correctly across threads! This is
359 382 so simple, that I can't beleive I'd missed it before. Needs more
360 383 testing, though.
361 384 (KBINT): Never mind, revert changes. I'm sure I'd tried something
362 385 like this before...
363 386
364 387 * IPython/genutils.py (get_home_dir): add protection against
365 388 non-dirs in win32 registry.
366 389
367 390 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
368 391 bug where dict was mutated while iterating (pysh crash).
369 392
370 393 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
371 394
372 395 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
373 396 spurious newlines added by this routine. After a report by
374 397 F. Mantegazza.
375 398
376 399 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
377 400
378 401 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
379 402 calls. These were a leftover from the GTK 1.x days, and can cause
380 403 problems in certain cases (after a report by John Hunter).
381 404
382 405 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
383 406 os.getcwd() fails at init time. Thanks to patch from David Remahl
384 407 <chmod007-AT-mac.com>.
385 408 (InteractiveShell.__init__): prevent certain special magics from
386 409 being shadowed by aliases. Closes
387 410 http://www.scipy.net/roundup/ipython/issue41.
388 411
389 412 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
390 413
391 414 * IPython/iplib.py (InteractiveShell.complete): Added new
392 415 top-level completion method to expose the completion mechanism
393 416 beyond readline-based environments.
394 417
395 418 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
396 419
397 420 * tools/ipsvnc (svnversion): fix svnversion capture.
398 421
399 422 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
400 423 attribute to self, which was missing. Before, it was set by a
401 424 routine which in certain cases wasn't being called, so the
402 425 instance could end up missing the attribute. This caused a crash.
403 426 Closes http://www.scipy.net/roundup/ipython/issue40.
404 427
405 428 2005-08-16 Fernando Perez <fperez@colorado.edu>
406 429
407 430 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
408 431 contains non-string attribute. Closes
409 432 http://www.scipy.net/roundup/ipython/issue38.
410 433
411 434 2005-08-14 Fernando Perez <fperez@colorado.edu>
412 435
413 436 * tools/ipsvnc: Minor improvements, to add changeset info.
414 437
415 438 2005-08-12 Fernando Perez <fperez@colorado.edu>
416 439
417 440 * IPython/iplib.py (runsource): remove self.code_to_run_src
418 441 attribute. I realized this is nothing more than
419 442 '\n'.join(self.buffer), and having the same data in two different
420 443 places is just asking for synchronization bugs. This may impact
421 444 people who have custom exception handlers, so I need to warn
422 445 ipython-dev about it (F. Mantegazza may use them).
423 446
424 447 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
425 448
426 449 * IPython/genutils.py: fix 2.2 compatibility (generators)
427 450
428 451 2005-07-18 Fernando Perez <fperez@colorado.edu>
429 452
430 453 * IPython/genutils.py (get_home_dir): fix to help users with
431 454 invalid $HOME under win32.
432 455
433 456 2005-07-17 Fernando Perez <fperez@colorado.edu>
434 457
435 458 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
436 459 some old hacks and clean up a bit other routines; code should be
437 460 simpler and a bit faster.
438 461
439 462 * IPython/iplib.py (interact): removed some last-resort attempts
440 463 to survive broken stdout/stderr. That code was only making it
441 464 harder to abstract out the i/o (necessary for gui integration),
442 465 and the crashes it could prevent were extremely rare in practice
443 466 (besides being fully user-induced in a pretty violent manner).
444 467
445 468 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
446 469 Nothing major yet, but the code is simpler to read; this should
447 470 make it easier to do more serious modifications in the future.
448 471
449 472 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
450 473 which broke in .15 (thanks to a report by Ville).
451 474
452 475 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
453 476 be quite correct, I know next to nothing about unicode). This
454 477 will allow unicode strings to be used in prompts, amongst other
455 478 cases. It also will prevent ipython from crashing when unicode
456 479 shows up unexpectedly in many places. If ascii encoding fails, we
457 480 assume utf_8. Currently the encoding is not a user-visible
458 481 setting, though it could be made so if there is demand for it.
459 482
460 483 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
461 484
462 485 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
463 486
464 487 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
465 488
466 489 * IPython/genutils.py: Add 2.2 compatibility here, so all other
467 490 code can work transparently for 2.2/2.3.
468 491
469 492 2005-07-16 Fernando Perez <fperez@colorado.edu>
470 493
471 494 * IPython/ultraTB.py (ExceptionColors): Make a global variable
472 495 out of the color scheme table used for coloring exception
473 496 tracebacks. This allows user code to add new schemes at runtime.
474 497 This is a minimally modified version of the patch at
475 498 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
476 499 for the contribution.
477 500
478 501 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
479 502 slightly modified version of the patch in
480 503 http://www.scipy.net/roundup/ipython/issue34, which also allows me
481 504 to remove the previous try/except solution (which was costlier).
482 505 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
483 506
484 507 2005-06-08 Fernando Perez <fperez@colorado.edu>
485 508
486 509 * IPython/iplib.py (write/write_err): Add methods to abstract all
487 510 I/O a bit more.
488 511
489 512 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
490 513 warning, reported by Aric Hagberg, fix by JD Hunter.
491 514
492 515 2005-06-02 *** Released version 0.6.15
493 516
494 517 2005-06-01 Fernando Perez <fperez@colorado.edu>
495 518
496 519 * IPython/iplib.py (MagicCompleter.file_matches): Fix
497 520 tab-completion of filenames within open-quoted strings. Note that
498 521 this requires that in ~/.ipython/ipythonrc, users change the
499 522 readline delimiters configuration to read:
500 523
501 524 readline_remove_delims -/~
502 525
503 526
504 527 2005-05-31 *** Released version 0.6.14
505 528
506 529 2005-05-29 Fernando Perez <fperez@colorado.edu>
507 530
508 531 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
509 532 with files not on the filesystem. Reported by Eliyahu Sandler
510 533 <eli@gondolin.net>
511 534
512 535 2005-05-22 Fernando Perez <fperez@colorado.edu>
513 536
514 537 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
515 538 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
516 539
517 540 2005-05-19 Fernando Perez <fperez@colorado.edu>
518 541
519 542 * IPython/iplib.py (safe_execfile): close a file which could be
520 543 left open (causing problems in win32, which locks open files).
521 544 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
522 545
523 546 2005-05-18 Fernando Perez <fperez@colorado.edu>
524 547
525 548 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
526 549 keyword arguments correctly to safe_execfile().
527 550
528 551 2005-05-13 Fernando Perez <fperez@colorado.edu>
529 552
530 553 * ipython.1: Added info about Qt to manpage, and threads warning
531 554 to usage page (invoked with --help).
532 555
533 556 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
534 557 new matcher (it goes at the end of the priority list) to do
535 558 tab-completion on named function arguments. Submitted by George
536 559 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
537 560 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
538 561 for more details.
539 562
540 563 * IPython/Magic.py (magic_run): Added new -e flag to ignore
541 564 SystemExit exceptions in the script being run. Thanks to a report
542 565 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
543 566 producing very annoying behavior when running unit tests.
544 567
545 568 2005-05-12 Fernando Perez <fperez@colorado.edu>
546 569
547 570 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
548 571 which I'd broken (again) due to a changed regexp. In the process,
549 572 added ';' as an escape to auto-quote the whole line without
550 573 splitting its arguments. Thanks to a report by Jerry McRae
551 574 <qrs0xyc02-AT-sneakemail.com>.
552 575
553 576 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
554 577 possible crashes caused by a TokenError. Reported by Ed Schofield
555 578 <schofield-AT-ftw.at>.
556 579
557 580 2005-05-06 Fernando Perez <fperez@colorado.edu>
558 581
559 582 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
560 583
561 584 2005-04-29 Fernando Perez <fperez@colorado.edu>
562 585
563 586 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
564 587 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
565 588 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
566 589 which provides support for Qt interactive usage (similar to the
567 590 existing one for WX and GTK). This had been often requested.
568 591
569 592 2005-04-14 *** Released version 0.6.13
570 593
571 594 2005-04-08 Fernando Perez <fperez@colorado.edu>
572 595
573 596 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
574 597 from _ofind, which gets called on almost every input line. Now,
575 598 we only try to get docstrings if they are actually going to be
576 599 used (the overhead of fetching unnecessary docstrings can be
577 600 noticeable for certain objects, such as Pyro proxies).
578 601
579 602 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
580 603 for completers. For some reason I had been passing them the state
581 604 variable, which completers never actually need, and was in
582 605 conflict with the rlcompleter API. Custom completers ONLY need to
583 606 take the text parameter.
584 607
585 608 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
586 609 work correctly in pysh. I've also moved all the logic which used
587 610 to be in pysh.py here, which will prevent problems with future
588 611 upgrades. However, this time I must warn users to update their
589 612 pysh profile to include the line
590 613
591 614 import_all IPython.Extensions.InterpreterExec
592 615
593 616 because otherwise things won't work for them. They MUST also
594 617 delete pysh.py and the line
595 618
596 619 execfile pysh.py
597 620
598 621 from their ipythonrc-pysh.
599 622
600 623 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
601 624 robust in the face of objects whose dir() returns non-strings
602 625 (which it shouldn't, but some broken libs like ITK do). Thanks to
603 626 a patch by John Hunter (implemented differently, though). Also
604 627 minor improvements by using .extend instead of + on lists.
605 628
606 629 * pysh.py:
607 630
608 631 2005-04-06 Fernando Perez <fperez@colorado.edu>
609 632
610 633 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
611 634 by default, so that all users benefit from it. Those who don't
612 635 want it can still turn it off.
613 636
614 637 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
615 638 config file, I'd forgotten about this, so users were getting it
616 639 off by default.
617 640
618 641 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
619 642 consistency. Now magics can be called in multiline statements,
620 643 and python variables can be expanded in magic calls via $var.
621 644 This makes the magic system behave just like aliases or !system
622 645 calls.
623 646
624 647 2005-03-28 Fernando Perez <fperez@colorado.edu>
625 648
626 649 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
627 650 expensive string additions for building command. Add support for
628 651 trailing ';' when autocall is used.
629 652
630 653 2005-03-26 Fernando Perez <fperez@colorado.edu>
631 654
632 655 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
633 656 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
634 657 ipython.el robust against prompts with any number of spaces
635 658 (including 0) after the ':' character.
636 659
637 660 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
638 661 continuation prompt, which misled users to think the line was
639 662 already indented. Closes debian Bug#300847, reported to me by
640 663 Norbert Tretkowski <tretkowski-AT-inittab.de>.
641 664
642 665 2005-03-23 Fernando Perez <fperez@colorado.edu>
643 666
644 667 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
645 668 properly aligned if they have embedded newlines.
646 669
647 670 * IPython/iplib.py (runlines): Add a public method to expose
648 671 IPython's code execution machinery, so that users can run strings
649 672 as if they had been typed at the prompt interactively.
650 673 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
651 674 methods which can call the system shell, but with python variable
652 675 expansion. The three such methods are: __IPYTHON__.system,
653 676 .getoutput and .getoutputerror. These need to be documented in a
654 677 'public API' section (to be written) of the manual.
655 678
656 679 2005-03-20 Fernando Perez <fperez@colorado.edu>
657 680
658 681 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
659 682 for custom exception handling. This is quite powerful, and it
660 683 allows for user-installable exception handlers which can trap
661 684 custom exceptions at runtime and treat them separately from
662 685 IPython's default mechanisms. At the request of FrΓ©dΓ©ric
663 686 Mantegazza <mantegazza-AT-ill.fr>.
664 687 (InteractiveShell.set_custom_completer): public API function to
665 688 add new completers at runtime.
666 689
667 690 2005-03-19 Fernando Perez <fperez@colorado.edu>
668 691
669 692 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
670 693 allow objects which provide their docstrings via non-standard
671 694 mechanisms (like Pyro proxies) to still be inspected by ipython's
672 695 ? system.
673 696
674 697 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
675 698 automatic capture system. I tried quite hard to make it work
676 699 reliably, and simply failed. I tried many combinations with the
677 700 subprocess module, but eventually nothing worked in all needed
678 701 cases (not blocking stdin for the child, duplicating stdout
679 702 without blocking, etc). The new %sc/%sx still do capture to these
680 703 magical list/string objects which make shell use much more
681 704 conveninent, so not all is lost.
682 705
683 706 XXX - FIX MANUAL for the change above!
684 707
685 708 (runsource): I copied code.py's runsource() into ipython to modify
686 709 it a bit. Now the code object and source to be executed are
687 710 stored in ipython. This makes this info accessible to third-party
688 711 tools, like custom exception handlers. After a request by FrΓ©dΓ©ric
689 712 Mantegazza <mantegazza-AT-ill.fr>.
690 713
691 714 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
692 715 history-search via readline (like C-p/C-n). I'd wanted this for a
693 716 long time, but only recently found out how to do it. For users
694 717 who already have their ipythonrc files made and want this, just
695 718 add:
696 719
697 720 readline_parse_and_bind "\e[A": history-search-backward
698 721 readline_parse_and_bind "\e[B": history-search-forward
699 722
700 723 2005-03-18 Fernando Perez <fperez@colorado.edu>
701 724
702 725 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
703 726 LSString and SList classes which allow transparent conversions
704 727 between list mode and whitespace-separated string.
705 728 (magic_r): Fix recursion problem in %r.
706 729
707 730 * IPython/genutils.py (LSString): New class to be used for
708 731 automatic storage of the results of all alias/system calls in _o
709 732 and _e (stdout/err). These provide a .l/.list attribute which
710 733 does automatic splitting on newlines. This means that for most
711 734 uses, you'll never need to do capturing of output with %sc/%sx
712 735 anymore, since ipython keeps this always done for you. Note that
713 736 only the LAST results are stored, the _o/e variables are
714 737 overwritten on each call. If you need to save their contents
715 738 further, simply bind them to any other name.
716 739
717 740 2005-03-17 Fernando Perez <fperez@colorado.edu>
718 741
719 742 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
720 743 prompt namespace handling.
721 744
722 745 2005-03-16 Fernando Perez <fperez@colorado.edu>
723 746
724 747 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
725 748 classic prompts to be '>>> ' (final space was missing, and it
726 749 trips the emacs python mode).
727 750 (BasePrompt.__str__): Added safe support for dynamic prompt
728 751 strings. Now you can set your prompt string to be '$x', and the
729 752 value of x will be printed from your interactive namespace. The
730 753 interpolation syntax includes the full Itpl support, so
731 754 ${foo()+x+bar()} is a valid prompt string now, and the function
732 755 calls will be made at runtime.
733 756
734 757 2005-03-15 Fernando Perez <fperez@colorado.edu>
735 758
736 759 * IPython/Magic.py (magic_history): renamed %hist to %history, to
737 760 avoid name clashes in pylab. %hist still works, it just forwards
738 761 the call to %history.
739 762
740 763 2005-03-02 *** Released version 0.6.12
741 764
742 765 2005-03-02 Fernando Perez <fperez@colorado.edu>
743 766
744 767 * IPython/iplib.py (handle_magic): log magic calls properly as
745 768 ipmagic() function calls.
746 769
747 770 * IPython/Magic.py (magic_time): Improved %time to support
748 771 statements and provide wall-clock as well as CPU time.
749 772
750 773 2005-02-27 Fernando Perez <fperez@colorado.edu>
751 774
752 775 * IPython/hooks.py: New hooks module, to expose user-modifiable
753 776 IPython functionality in a clean manner. For now only the editor
754 777 hook is actually written, and other thigns which I intend to turn
755 778 into proper hooks aren't yet there. The display and prefilter
756 779 stuff, for example, should be hooks. But at least now the
757 780 framework is in place, and the rest can be moved here with more
758 781 time later. IPython had had a .hooks variable for a long time for
759 782 this purpose, but I'd never actually used it for anything.
760 783
761 784 2005-02-26 Fernando Perez <fperez@colorado.edu>
762 785
763 786 * IPython/ipmaker.py (make_IPython): make the default ipython
764 787 directory be called _ipython under win32, to follow more the
765 788 naming peculiarities of that platform (where buggy software like
766 789 Visual Sourcesafe breaks with .named directories). Reported by
767 790 Ville Vainio.
768 791
769 792 2005-02-23 Fernando Perez <fperez@colorado.edu>
770 793
771 794 * IPython/iplib.py (InteractiveShell.__init__): removed a few
772 795 auto_aliases for win32 which were causing problems. Users can
773 796 define the ones they personally like.
774 797
775 798 2005-02-21 Fernando Perez <fperez@colorado.edu>
776 799
777 800 * IPython/Magic.py (magic_time): new magic to time execution of
778 801 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
779 802
780 803 2005-02-19 Fernando Perez <fperez@colorado.edu>
781 804
782 805 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
783 806 into keys (for prompts, for example).
784 807
785 808 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
786 809 prompts in case users want them. This introduces a small behavior
787 810 change: ipython does not automatically add a space to all prompts
788 811 anymore. To get the old prompts with a space, users should add it
789 812 manually to their ipythonrc file, so for example prompt_in1 should
790 813 now read 'In [\#]: ' instead of 'In [\#]:'.
791 814 (BasePrompt.__init__): New option prompts_pad_left (only in rc
792 815 file) to control left-padding of secondary prompts.
793 816
794 817 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
795 818 the profiler can't be imported. Fix for Debian, which removed
796 819 profile.py because of License issues. I applied a slightly
797 820 modified version of the original Debian patch at
798 821 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
799 822
800 823 2005-02-17 Fernando Perez <fperez@colorado.edu>
801 824
802 825 * IPython/genutils.py (native_line_ends): Fix bug which would
803 826 cause improper line-ends under win32 b/c I was not opening files
804 827 in binary mode. Bug report and fix thanks to Ville.
805 828
806 829 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
807 830 trying to catch spurious foo[1] autocalls. My fix actually broke
808 831 ',/' autoquote/call with explicit escape (bad regexp).
809 832
810 833 2005-02-15 *** Released version 0.6.11
811 834
812 835 2005-02-14 Fernando Perez <fperez@colorado.edu>
813 836
814 837 * IPython/background_jobs.py: New background job management
815 838 subsystem. This is implemented via a new set of classes, and
816 839 IPython now provides a builtin 'jobs' object for background job
817 840 execution. A convenience %bg magic serves as a lightweight
818 841 frontend for starting the more common type of calls. This was
819 842 inspired by discussions with B. Granger and the BackgroundCommand
820 843 class described in the book Python Scripting for Computational
821 844 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
822 845 (although ultimately no code from this text was used, as IPython's
823 846 system is a separate implementation).
824 847
825 848 * IPython/iplib.py (MagicCompleter.python_matches): add new option
826 849 to control the completion of single/double underscore names
827 850 separately. As documented in the example ipytonrc file, the
828 851 readline_omit__names variable can now be set to 2, to omit even
829 852 single underscore names. Thanks to a patch by Brian Wong
830 853 <BrianWong-AT-AirgoNetworks.Com>.
831 854 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
832 855 be autocalled as foo([1]) if foo were callable. A problem for
833 856 things which are both callable and implement __getitem__.
834 857 (init_readline): Fix autoindentation for win32. Thanks to a patch
835 858 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
836 859
837 860 2005-02-12 Fernando Perez <fperez@colorado.edu>
838 861
839 862 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
840 863 which I had written long ago to sort out user error messages which
841 864 may occur during startup. This seemed like a good idea initially,
842 865 but it has proven a disaster in retrospect. I don't want to
843 866 change much code for now, so my fix is to set the internal 'debug'
844 867 flag to true everywhere, whose only job was precisely to control
845 868 this subsystem. This closes issue 28 (as well as avoiding all
846 869 sorts of strange hangups which occur from time to time).
847 870
848 871 2005-02-07 Fernando Perez <fperez@colorado.edu>
849 872
850 873 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
851 874 previous call produced a syntax error.
852 875
853 876 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
854 877 classes without constructor.
855 878
856 879 2005-02-06 Fernando Perez <fperez@colorado.edu>
857 880
858 881 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
859 882 completions with the results of each matcher, so we return results
860 883 to the user from all namespaces. This breaks with ipython
861 884 tradition, but I think it's a nicer behavior. Now you get all
862 885 possible completions listed, from all possible namespaces (python,
863 886 filesystem, magics...) After a request by John Hunter
864 887 <jdhunter-AT-nitace.bsd.uchicago.edu>.
865 888
866 889 2005-02-05 Fernando Perez <fperez@colorado.edu>
867 890
868 891 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
869 892 the call had quote characters in it (the quotes were stripped).
870 893
871 894 2005-01-31 Fernando Perez <fperez@colorado.edu>
872 895
873 896 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
874 897 Itpl.itpl() to make the code more robust against psyco
875 898 optimizations.
876 899
877 900 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
878 901 of causing an exception. Quicker, cleaner.
879 902
880 903 2005-01-28 Fernando Perez <fperez@colorado.edu>
881 904
882 905 * scripts/ipython_win_post_install.py (install): hardcode
883 906 sys.prefix+'python.exe' as the executable path. It turns out that
884 907 during the post-installation run, sys.executable resolves to the
885 908 name of the binary installer! I should report this as a distutils
886 909 bug, I think. I updated the .10 release with this tiny fix, to
887 910 avoid annoying the lists further.
888 911
889 912 2005-01-27 *** Released version 0.6.10
890 913
891 914 2005-01-27 Fernando Perez <fperez@colorado.edu>
892 915
893 916 * IPython/numutils.py (norm): Added 'inf' as optional name for
894 917 L-infinity norm, included references to mathworld.com for vector
895 918 norm definitions.
896 919 (amin/amax): added amin/amax for array min/max. Similar to what
897 920 pylab ships with after the recent reorganization of names.
898 921 (spike/spike_odd): removed deprecated spike/spike_odd functions.
899 922
900 923 * ipython.el: committed Alex's recent fixes and improvements.
901 924 Tested with python-mode from CVS, and it looks excellent. Since
902 925 python-mode hasn't released anything in a while, I'm temporarily
903 926 putting a copy of today's CVS (v 4.70) of python-mode in:
904 927 http://ipython.scipy.org/tmp/python-mode.el
905 928
906 929 * scripts/ipython_win_post_install.py (install): Win32 fix to use
907 930 sys.executable for the executable name, instead of assuming it's
908 931 called 'python.exe' (the post-installer would have produced broken
909 932 setups on systems with a differently named python binary).
910 933
911 934 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
912 935 references to os.linesep, to make the code more
913 936 platform-independent. This is also part of the win32 coloring
914 937 fixes.
915 938
916 939 * IPython/genutils.py (page_dumb): Remove attempts to chop long
917 940 lines, which actually cause coloring bugs because the length of
918 941 the line is very difficult to correctly compute with embedded
919 942 escapes. This was the source of all the coloring problems under
920 943 Win32. I think that _finally_, Win32 users have a properly
921 944 working ipython in all respects. This would never have happened
922 945 if not for Gary Bishop and Viktor Ransmayr's great help and work.
923 946
924 947 2005-01-26 *** Released version 0.6.9
925 948
926 949 2005-01-25 Fernando Perez <fperez@colorado.edu>
927 950
928 951 * setup.py: finally, we have a true Windows installer, thanks to
929 952 the excellent work of Viktor Ransmayr
930 953 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
931 954 Windows users. The setup routine is quite a bit cleaner thanks to
932 955 this, and the post-install script uses the proper functions to
933 956 allow a clean de-installation using the standard Windows Control
934 957 Panel.
935 958
936 959 * IPython/genutils.py (get_home_dir): changed to use the $HOME
937 960 environment variable under all OSes (including win32) if
938 961 available. This will give consistency to win32 users who have set
939 962 this variable for any reason. If os.environ['HOME'] fails, the
940 963 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
941 964
942 965 2005-01-24 Fernando Perez <fperez@colorado.edu>
943 966
944 967 * IPython/numutils.py (empty_like): add empty_like(), similar to
945 968 zeros_like() but taking advantage of the new empty() Numeric routine.
946 969
947 970 2005-01-23 *** Released version 0.6.8
948 971
949 972 2005-01-22 Fernando Perez <fperez@colorado.edu>
950 973
951 974 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
952 975 automatic show() calls. After discussing things with JDH, it
953 976 turns out there are too many corner cases where this can go wrong.
954 977 It's best not to try to be 'too smart', and simply have ipython
955 978 reproduce as much as possible the default behavior of a normal
956 979 python shell.
957 980
958 981 * IPython/iplib.py (InteractiveShell.__init__): Modified the
959 982 line-splitting regexp and _prefilter() to avoid calling getattr()
960 983 on assignments. This closes
961 984 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
962 985 readline uses getattr(), so a simple <TAB> keypress is still
963 986 enough to trigger getattr() calls on an object.
964 987
965 988 2005-01-21 Fernando Perez <fperez@colorado.edu>
966 989
967 990 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
968 991 docstring under pylab so it doesn't mask the original.
969 992
970 993 2005-01-21 *** Released version 0.6.7
971 994
972 995 2005-01-21 Fernando Perez <fperez@colorado.edu>
973 996
974 997 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
975 998 signal handling for win32 users in multithreaded mode.
976 999
977 1000 2005-01-17 Fernando Perez <fperez@colorado.edu>
978 1001
979 1002 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
980 1003 instances with no __init__. After a crash report by Norbert Nemec
981 1004 <Norbert-AT-nemec-online.de>.
982 1005
983 1006 2005-01-14 Fernando Perez <fperez@colorado.edu>
984 1007
985 1008 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
986 1009 names for verbose exceptions, when multiple dotted names and the
987 1010 'parent' object were present on the same line.
988 1011
989 1012 2005-01-11 Fernando Perez <fperez@colorado.edu>
990 1013
991 1014 * IPython/genutils.py (flag_calls): new utility to trap and flag
992 1015 calls in functions. I need it to clean up matplotlib support.
993 1016 Also removed some deprecated code in genutils.
994 1017
995 1018 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
996 1019 that matplotlib scripts called with %run, which don't call show()
997 1020 themselves, still have their plotting windows open.
998 1021
999 1022 2005-01-05 Fernando Perez <fperez@colorado.edu>
1000 1023
1001 1024 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
1002 1025 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
1003 1026
1004 1027 2004-12-19 Fernando Perez <fperez@colorado.edu>
1005 1028
1006 1029 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
1007 1030 parent_runcode, which was an eyesore. The same result can be
1008 1031 obtained with Python's regular superclass mechanisms.
1009 1032
1010 1033 2004-12-17 Fernando Perez <fperez@colorado.edu>
1011 1034
1012 1035 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
1013 1036 reported by Prabhu.
1014 1037 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
1015 1038 sys.stderr) instead of explicitly calling sys.stderr. This helps
1016 1039 maintain our I/O abstractions clean, for future GUI embeddings.
1017 1040
1018 1041 * IPython/genutils.py (info): added new utility for sys.stderr
1019 1042 unified info message handling (thin wrapper around warn()).
1020 1043
1021 1044 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
1022 1045 composite (dotted) names on verbose exceptions.
1023 1046 (VerboseTB.nullrepr): harden against another kind of errors which
1024 1047 Python's inspect module can trigger, and which were crashing
1025 1048 IPython. Thanks to a report by Marco Lombardi
1026 1049 <mlombard-AT-ma010192.hq.eso.org>.
1027 1050
1028 1051 2004-12-13 *** Released version 0.6.6
1029 1052
1030 1053 2004-12-12 Fernando Perez <fperez@colorado.edu>
1031 1054
1032 1055 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
1033 1056 generated by pygtk upon initialization if it was built without
1034 1057 threads (for matplotlib users). After a crash reported by
1035 1058 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
1036 1059
1037 1060 * IPython/ipmaker.py (make_IPython): fix small bug in the
1038 1061 import_some parameter for multiple imports.
1039 1062
1040 1063 * IPython/iplib.py (ipmagic): simplified the interface of
1041 1064 ipmagic() to take a single string argument, just as it would be
1042 1065 typed at the IPython cmd line.
1043 1066 (ipalias): Added new ipalias() with an interface identical to
1044 1067 ipmagic(). This completes exposing a pure python interface to the
1045 1068 alias and magic system, which can be used in loops or more complex
1046 1069 code where IPython's automatic line mangling is not active.
1047 1070
1048 1071 * IPython/genutils.py (timing): changed interface of timing to
1049 1072 simply run code once, which is the most common case. timings()
1050 1073 remains unchanged, for the cases where you want multiple runs.
1051 1074
1052 1075 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
1053 1076 bug where Python2.2 crashes with exec'ing code which does not end
1054 1077 in a single newline. Python 2.3 is OK, so I hadn't noticed this
1055 1078 before.
1056 1079
1057 1080 2004-12-10 Fernando Perez <fperez@colorado.edu>
1058 1081
1059 1082 * IPython/Magic.py (Magic.magic_prun): changed name of option from
1060 1083 -t to -T, to accomodate the new -t flag in %run (the %run and
1061 1084 %prun options are kind of intermixed, and it's not easy to change
1062 1085 this with the limitations of python's getopt).
1063 1086
1064 1087 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
1065 1088 the execution of scripts. It's not as fine-tuned as timeit.py,
1066 1089 but it works from inside ipython (and under 2.2, which lacks
1067 1090 timeit.py). Optionally a number of runs > 1 can be given for
1068 1091 timing very short-running code.
1069 1092
1070 1093 * IPython/genutils.py (uniq_stable): new routine which returns a
1071 1094 list of unique elements in any iterable, but in stable order of
1072 1095 appearance. I needed this for the ultraTB fixes, and it's a handy
1073 1096 utility.
1074 1097
1075 1098 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
1076 1099 dotted names in Verbose exceptions. This had been broken since
1077 1100 the very start, now x.y will properly be printed in a Verbose
1078 1101 traceback, instead of x being shown and y appearing always as an
1079 1102 'undefined global'. Getting this to work was a bit tricky,
1080 1103 because by default python tokenizers are stateless. Saved by
1081 1104 python's ability to easily add a bit of state to an arbitrary
1082 1105 function (without needing to build a full-blown callable object).
1083 1106
1084 1107 Also big cleanup of this code, which had horrendous runtime
1085 1108 lookups of zillions of attributes for colorization. Moved all
1086 1109 this code into a few templates, which make it cleaner and quicker.
1087 1110
1088 1111 Printout quality was also improved for Verbose exceptions: one
1089 1112 variable per line, and memory addresses are printed (this can be
1090 1113 quite handy in nasty debugging situations, which is what Verbose
1091 1114 is for).
1092 1115
1093 1116 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
1094 1117 the command line as scripts to be loaded by embedded instances.
1095 1118 Doing so has the potential for an infinite recursion if there are
1096 1119 exceptions thrown in the process. This fixes a strange crash
1097 1120 reported by Philippe MULLER <muller-AT-irit.fr>.
1098 1121
1099 1122 2004-12-09 Fernando Perez <fperez@colorado.edu>
1100 1123
1101 1124 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
1102 1125 to reflect new names in matplotlib, which now expose the
1103 1126 matlab-compatible interface via a pylab module instead of the
1104 1127 'matlab' name. The new code is backwards compatible, so users of
1105 1128 all matplotlib versions are OK. Patch by J. Hunter.
1106 1129
1107 1130 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
1108 1131 of __init__ docstrings for instances (class docstrings are already
1109 1132 automatically printed). Instances with customized docstrings
1110 1133 (indep. of the class) are also recognized and all 3 separate
1111 1134 docstrings are printed (instance, class, constructor). After some
1112 1135 comments/suggestions by J. Hunter.
1113 1136
1114 1137 2004-12-05 Fernando Perez <fperez@colorado.edu>
1115 1138
1116 1139 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
1117 1140 warnings when tab-completion fails and triggers an exception.
1118 1141
1119 1142 2004-12-03 Fernando Perez <fperez@colorado.edu>
1120 1143
1121 1144 * IPython/Magic.py (magic_prun): Fix bug where an exception would
1122 1145 be triggered when using 'run -p'. An incorrect option flag was
1123 1146 being set ('d' instead of 'D').
1124 1147 (manpage): fix missing escaped \- sign.
1125 1148
1126 1149 2004-11-30 *** Released version 0.6.5
1127 1150
1128 1151 2004-11-30 Fernando Perez <fperez@colorado.edu>
1129 1152
1130 1153 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
1131 1154 setting with -d option.
1132 1155
1133 1156 * setup.py (docfiles): Fix problem where the doc glob I was using
1134 1157 was COMPLETELY BROKEN. It was giving the right files by pure
1135 1158 accident, but failed once I tried to include ipython.el. Note:
1136 1159 glob() does NOT allow you to do exclusion on multiple endings!
1137 1160
1138 1161 2004-11-29 Fernando Perez <fperez@colorado.edu>
1139 1162
1140 1163 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
1141 1164 the manpage as the source. Better formatting & consistency.
1142 1165
1143 1166 * IPython/Magic.py (magic_run): Added new -d option, to run
1144 1167 scripts under the control of the python pdb debugger. Note that
1145 1168 this required changing the %prun option -d to -D, to avoid a clash
1146 1169 (since %run must pass options to %prun, and getopt is too dumb to
1147 1170 handle options with string values with embedded spaces). Thanks
1148 1171 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
1149 1172 (magic_who_ls): added type matching to %who and %whos, so that one
1150 1173 can filter their output to only include variables of certain
1151 1174 types. Another suggestion by Matthew.
1152 1175 (magic_whos): Added memory summaries in kb and Mb for arrays.
1153 1176 (magic_who): Improve formatting (break lines every 9 vars).
1154 1177
1155 1178 2004-11-28 Fernando Perez <fperez@colorado.edu>
1156 1179
1157 1180 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
1158 1181 cache when empty lines were present.
1159 1182
1160 1183 2004-11-24 Fernando Perez <fperez@colorado.edu>
1161 1184
1162 1185 * IPython/usage.py (__doc__): document the re-activated threading
1163 1186 options for WX and GTK.
1164 1187
1165 1188 2004-11-23 Fernando Perez <fperez@colorado.edu>
1166 1189
1167 1190 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
1168 1191 the -wthread and -gthread options, along with a new -tk one to try
1169 1192 and coordinate Tk threading with wx/gtk. The tk support is very
1170 1193 platform dependent, since it seems to require Tcl and Tk to be
1171 1194 built with threads (Fedora1/2 appears NOT to have it, but in
1172 1195 Prabhu's Debian boxes it works OK). But even with some Tk
1173 1196 limitations, this is a great improvement.
1174 1197
1175 1198 * IPython/Prompts.py (prompt_specials_color): Added \t for time
1176 1199 info in user prompts. Patch by Prabhu.
1177 1200
1178 1201 2004-11-18 Fernando Perez <fperez@colorado.edu>
1179 1202
1180 1203 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
1181 1204 EOFErrors and bail, to avoid infinite loops if a non-terminating
1182 1205 file is fed into ipython. Patch submitted in issue 19 by user,
1183 1206 many thanks.
1184 1207
1185 1208 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
1186 1209 autoquote/parens in continuation prompts, which can cause lots of
1187 1210 problems. Closes roundup issue 20.
1188 1211
1189 1212 2004-11-17 Fernando Perez <fperez@colorado.edu>
1190 1213
1191 1214 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
1192 1215 reported as debian bug #280505. I'm not sure my local changelog
1193 1216 entry has the proper debian format (Jack?).
1194 1217
1195 1218 2004-11-08 *** Released version 0.6.4
1196 1219
1197 1220 2004-11-08 Fernando Perez <fperez@colorado.edu>
1198 1221
1199 1222 * IPython/iplib.py (init_readline): Fix exit message for Windows
1200 1223 when readline is active. Thanks to a report by Eric Jones
1201 1224 <eric-AT-enthought.com>.
1202 1225
1203 1226 2004-11-07 Fernando Perez <fperez@colorado.edu>
1204 1227
1205 1228 * IPython/genutils.py (page): Add a trap for OSError exceptions,
1206 1229 sometimes seen by win2k/cygwin users.
1207 1230
1208 1231 2004-11-06 Fernando Perez <fperez@colorado.edu>
1209 1232
1210 1233 * IPython/iplib.py (interact): Change the handling of %Exit from
1211 1234 trying to propagate a SystemExit to an internal ipython flag.
1212 1235 This is less elegant than using Python's exception mechanism, but
1213 1236 I can't get that to work reliably with threads, so under -pylab
1214 1237 %Exit was hanging IPython. Cross-thread exception handling is
1215 1238 really a bitch. Thaks to a bug report by Stephen Walton
1216 1239 <stephen.walton-AT-csun.edu>.
1217 1240
1218 1241 2004-11-04 Fernando Perez <fperez@colorado.edu>
1219 1242
1220 1243 * IPython/iplib.py (raw_input_original): store a pointer to the
1221 1244 true raw_input to harden against code which can modify it
1222 1245 (wx.py.PyShell does this and would otherwise crash ipython).
1223 1246 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
1224 1247
1225 1248 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
1226 1249 Ctrl-C problem, which does not mess up the input line.
1227 1250
1228 1251 2004-11-03 Fernando Perez <fperez@colorado.edu>
1229 1252
1230 1253 * IPython/Release.py: Changed licensing to BSD, in all files.
1231 1254 (name): lowercase name for tarball/RPM release.
1232 1255
1233 1256 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
1234 1257 use throughout ipython.
1235 1258
1236 1259 * IPython/Magic.py (Magic._ofind): Switch to using the new
1237 1260 OInspect.getdoc() function.
1238 1261
1239 1262 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
1240 1263 of the line currently being canceled via Ctrl-C. It's extremely
1241 1264 ugly, but I don't know how to do it better (the problem is one of
1242 1265 handling cross-thread exceptions).
1243 1266
1244 1267 2004-10-28 Fernando Perez <fperez@colorado.edu>
1245 1268
1246 1269 * IPython/Shell.py (signal_handler): add signal handlers to trap
1247 1270 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
1248 1271 report by Francesc Alted.
1249 1272
1250 1273 2004-10-21 Fernando Perez <fperez@colorado.edu>
1251 1274
1252 1275 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
1253 1276 to % for pysh syntax extensions.
1254 1277
1255 1278 2004-10-09 Fernando Perez <fperez@colorado.edu>
1256 1279
1257 1280 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
1258 1281 arrays to print a more useful summary, without calling str(arr).
1259 1282 This avoids the problem of extremely lengthy computations which
1260 1283 occur if arr is large, and appear to the user as a system lockup
1261 1284 with 100% cpu activity. After a suggestion by Kristian Sandberg
1262 1285 <Kristian.Sandberg@colorado.edu>.
1263 1286 (Magic.__init__): fix bug in global magic escapes not being
1264 1287 correctly set.
1265 1288
1266 1289 2004-10-08 Fernando Perez <fperez@colorado.edu>
1267 1290
1268 1291 * IPython/Magic.py (__license__): change to absolute imports of
1269 1292 ipython's own internal packages, to start adapting to the absolute
1270 1293 import requirement of PEP-328.
1271 1294
1272 1295 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
1273 1296 files, and standardize author/license marks through the Release
1274 1297 module instead of having per/file stuff (except for files with
1275 1298 particular licenses, like the MIT/PSF-licensed codes).
1276 1299
1277 1300 * IPython/Debugger.py: remove dead code for python 2.1
1278 1301
1279 1302 2004-10-04 Fernando Perez <fperez@colorado.edu>
1280 1303
1281 1304 * IPython/iplib.py (ipmagic): New function for accessing magics
1282 1305 via a normal python function call.
1283 1306
1284 1307 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
1285 1308 from '@' to '%', to accomodate the new @decorator syntax of python
1286 1309 2.4.
1287 1310
1288 1311 2004-09-29 Fernando Perez <fperez@colorado.edu>
1289 1312
1290 1313 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
1291 1314 matplotlib.use to prevent running scripts which try to switch
1292 1315 interactive backends from within ipython. This will just crash
1293 1316 the python interpreter, so we can't allow it (but a detailed error
1294 1317 is given to the user).
1295 1318
1296 1319 2004-09-28 Fernando Perez <fperez@colorado.edu>
1297 1320
1298 1321 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
1299 1322 matplotlib-related fixes so that using @run with non-matplotlib
1300 1323 scripts doesn't pop up spurious plot windows. This requires
1301 1324 matplotlib >= 0.63, where I had to make some changes as well.
1302 1325
1303 1326 * IPython/ipmaker.py (make_IPython): update version requirement to
1304 1327 python 2.2.
1305 1328
1306 1329 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
1307 1330 banner arg for embedded customization.
1308 1331
1309 1332 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
1310 1333 explicit uses of __IP as the IPython's instance name. Now things
1311 1334 are properly handled via the shell.name value. The actual code
1312 1335 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
1313 1336 is much better than before. I'll clean things completely when the
1314 1337 magic stuff gets a real overhaul.
1315 1338
1316 1339 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
1317 1340 minor changes to debian dir.
1318 1341
1319 1342 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
1320 1343 pointer to the shell itself in the interactive namespace even when
1321 1344 a user-supplied dict is provided. This is needed for embedding
1322 1345 purposes (found by tests with Michel Sanner).
1323 1346
1324 1347 2004-09-27 Fernando Perez <fperez@colorado.edu>
1325 1348
1326 1349 * IPython/UserConfig/ipythonrc: remove []{} from
1327 1350 readline_remove_delims, so that things like [modname.<TAB> do
1328 1351 proper completion. This disables [].TAB, but that's a less common
1329 1352 case than module names in list comprehensions, for example.
1330 1353 Thanks to a report by Andrea Riciputi.
1331 1354
1332 1355 2004-09-09 Fernando Perez <fperez@colorado.edu>
1333 1356
1334 1357 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1335 1358 blocking problems in win32 and osx. Fix by John.
1336 1359
1337 1360 2004-09-08 Fernando Perez <fperez@colorado.edu>
1338 1361
1339 1362 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1340 1363 for Win32 and OSX. Fix by John Hunter.
1341 1364
1342 1365 2004-08-30 *** Released version 0.6.3
1343 1366
1344 1367 2004-08-30 Fernando Perez <fperez@colorado.edu>
1345 1368
1346 1369 * setup.py (isfile): Add manpages to list of dependent files to be
1347 1370 updated.
1348 1371
1349 1372 2004-08-27 Fernando Perez <fperez@colorado.edu>
1350 1373
1351 1374 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1352 1375 for now. They don't really work with standalone WX/GTK code
1353 1376 (though matplotlib IS working fine with both of those backends).
1354 1377 This will neeed much more testing. I disabled most things with
1355 1378 comments, so turning it back on later should be pretty easy.
1356 1379
1357 1380 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1358 1381 autocalling of expressions like r'foo', by modifying the line
1359 1382 split regexp. Closes
1360 1383 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1361 1384 Riley <ipythonbugs-AT-sabi.net>.
1362 1385 (InteractiveShell.mainloop): honor --nobanner with banner
1363 1386 extensions.
1364 1387
1365 1388 * IPython/Shell.py: Significant refactoring of all classes, so
1366 1389 that we can really support ALL matplotlib backends and threading
1367 1390 models (John spotted a bug with Tk which required this). Now we
1368 1391 should support single-threaded, WX-threads and GTK-threads, both
1369 1392 for generic code and for matplotlib.
1370 1393
1371 1394 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1372 1395 -pylab, to simplify things for users. Will also remove the pylab
1373 1396 profile, since now all of matplotlib configuration is directly
1374 1397 handled here. This also reduces startup time.
1375 1398
1376 1399 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1377 1400 shell wasn't being correctly called. Also in IPShellWX.
1378 1401
1379 1402 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1380 1403 fine-tune banner.
1381 1404
1382 1405 * IPython/numutils.py (spike): Deprecate these spike functions,
1383 1406 delete (long deprecated) gnuplot_exec handler.
1384 1407
1385 1408 2004-08-26 Fernando Perez <fperez@colorado.edu>
1386 1409
1387 1410 * ipython.1: Update for threading options, plus some others which
1388 1411 were missing.
1389 1412
1390 1413 * IPython/ipmaker.py (__call__): Added -wthread option for
1391 1414 wxpython thread handling. Make sure threading options are only
1392 1415 valid at the command line.
1393 1416
1394 1417 * scripts/ipython: moved shell selection into a factory function
1395 1418 in Shell.py, to keep the starter script to a minimum.
1396 1419
1397 1420 2004-08-25 Fernando Perez <fperez@colorado.edu>
1398 1421
1399 1422 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1400 1423 John. Along with some recent changes he made to matplotlib, the
1401 1424 next versions of both systems should work very well together.
1402 1425
1403 1426 2004-08-24 Fernando Perez <fperez@colorado.edu>
1404 1427
1405 1428 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1406 1429 tried to switch the profiling to using hotshot, but I'm getting
1407 1430 strange errors from prof.runctx() there. I may be misreading the
1408 1431 docs, but it looks weird. For now the profiling code will
1409 1432 continue to use the standard profiler.
1410 1433
1411 1434 2004-08-23 Fernando Perez <fperez@colorado.edu>
1412 1435
1413 1436 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1414 1437 threaded shell, by John Hunter. It's not quite ready yet, but
1415 1438 close.
1416 1439
1417 1440 2004-08-22 Fernando Perez <fperez@colorado.edu>
1418 1441
1419 1442 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1420 1443 in Magic and ultraTB.
1421 1444
1422 1445 * ipython.1: document threading options in manpage.
1423 1446
1424 1447 * scripts/ipython: Changed name of -thread option to -gthread,
1425 1448 since this is GTK specific. I want to leave the door open for a
1426 1449 -wthread option for WX, which will most likely be necessary. This
1427 1450 change affects usage and ipmaker as well.
1428 1451
1429 1452 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1430 1453 handle the matplotlib shell issues. Code by John Hunter
1431 1454 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1432 1455 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1433 1456 broken (and disabled for end users) for now, but it puts the
1434 1457 infrastructure in place.
1435 1458
1436 1459 2004-08-21 Fernando Perez <fperez@colorado.edu>
1437 1460
1438 1461 * ipythonrc-pylab: Add matplotlib support.
1439 1462
1440 1463 * matplotlib_config.py: new files for matplotlib support, part of
1441 1464 the pylab profile.
1442 1465
1443 1466 * IPython/usage.py (__doc__): documented the threading options.
1444 1467
1445 1468 2004-08-20 Fernando Perez <fperez@colorado.edu>
1446 1469
1447 1470 * ipython: Modified the main calling routine to handle the -thread
1448 1471 and -mpthread options. This needs to be done as a top-level hack,
1449 1472 because it determines which class to instantiate for IPython
1450 1473 itself.
1451 1474
1452 1475 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1453 1476 classes to support multithreaded GTK operation without blocking,
1454 1477 and matplotlib with all backends. This is a lot of still very
1455 1478 experimental code, and threads are tricky. So it may still have a
1456 1479 few rough edges... This code owes a lot to
1457 1480 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1458 1481 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1459 1482 to John Hunter for all the matplotlib work.
1460 1483
1461 1484 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1462 1485 options for gtk thread and matplotlib support.
1463 1486
1464 1487 2004-08-16 Fernando Perez <fperez@colorado.edu>
1465 1488
1466 1489 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1467 1490 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1468 1491 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1469 1492
1470 1493 2004-08-11 Fernando Perez <fperez@colorado.edu>
1471 1494
1472 1495 * setup.py (isfile): Fix build so documentation gets updated for
1473 1496 rpms (it was only done for .tgz builds).
1474 1497
1475 1498 2004-08-10 Fernando Perez <fperez@colorado.edu>
1476 1499
1477 1500 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1478 1501
1479 1502 * iplib.py : Silence syntax error exceptions in tab-completion.
1480 1503
1481 1504 2004-08-05 Fernando Perez <fperez@colorado.edu>
1482 1505
1483 1506 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1484 1507 'color off' mark for continuation prompts. This was causing long
1485 1508 continuation lines to mis-wrap.
1486 1509
1487 1510 2004-08-01 Fernando Perez <fperez@colorado.edu>
1488 1511
1489 1512 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1490 1513 for building ipython to be a parameter. All this is necessary
1491 1514 right now to have a multithreaded version, but this insane
1492 1515 non-design will be cleaned up soon. For now, it's a hack that
1493 1516 works.
1494 1517
1495 1518 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1496 1519 args in various places. No bugs so far, but it's a dangerous
1497 1520 practice.
1498 1521
1499 1522 2004-07-31 Fernando Perez <fperez@colorado.edu>
1500 1523
1501 1524 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1502 1525 fix completion of files with dots in their names under most
1503 1526 profiles (pysh was OK because the completion order is different).
1504 1527
1505 1528 2004-07-27 Fernando Perez <fperez@colorado.edu>
1506 1529
1507 1530 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1508 1531 keywords manually, b/c the one in keyword.py was removed in python
1509 1532 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1510 1533 This is NOT a bug under python 2.3 and earlier.
1511 1534
1512 1535 2004-07-26 Fernando Perez <fperez@colorado.edu>
1513 1536
1514 1537 * IPython/ultraTB.py (VerboseTB.text): Add another
1515 1538 linecache.checkcache() call to try to prevent inspect.py from
1516 1539 crashing under python 2.3. I think this fixes
1517 1540 http://www.scipy.net/roundup/ipython/issue17.
1518 1541
1519 1542 2004-07-26 *** Released version 0.6.2
1520 1543
1521 1544 2004-07-26 Fernando Perez <fperez@colorado.edu>
1522 1545
1523 1546 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1524 1547 fail for any number.
1525 1548 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1526 1549 empty bookmarks.
1527 1550
1528 1551 2004-07-26 *** Released version 0.6.1
1529 1552
1530 1553 2004-07-26 Fernando Perez <fperez@colorado.edu>
1531 1554
1532 1555 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1533 1556
1534 1557 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1535 1558 escaping '()[]{}' in filenames.
1536 1559
1537 1560 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1538 1561 Python 2.2 users who lack a proper shlex.split.
1539 1562
1540 1563 2004-07-19 Fernando Perez <fperez@colorado.edu>
1541 1564
1542 1565 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1543 1566 for reading readline's init file. I follow the normal chain:
1544 1567 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1545 1568 report by Mike Heeter. This closes
1546 1569 http://www.scipy.net/roundup/ipython/issue16.
1547 1570
1548 1571 2004-07-18 Fernando Perez <fperez@colorado.edu>
1549 1572
1550 1573 * IPython/iplib.py (__init__): Add better handling of '\' under
1551 1574 Win32 for filenames. After a patch by Ville.
1552 1575
1553 1576 2004-07-17 Fernando Perez <fperez@colorado.edu>
1554 1577
1555 1578 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1556 1579 autocalling would be triggered for 'foo is bar' if foo is
1557 1580 callable. I also cleaned up the autocall detection code to use a
1558 1581 regexp, which is faster. Bug reported by Alexander Schmolck.
1559 1582
1560 1583 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1561 1584 '?' in them would confuse the help system. Reported by Alex
1562 1585 Schmolck.
1563 1586
1564 1587 2004-07-16 Fernando Perez <fperez@colorado.edu>
1565 1588
1566 1589 * IPython/GnuplotInteractive.py (__all__): added plot2.
1567 1590
1568 1591 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1569 1592 plotting dictionaries, lists or tuples of 1d arrays.
1570 1593
1571 1594 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1572 1595 optimizations.
1573 1596
1574 1597 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1575 1598 the information which was there from Janko's original IPP code:
1576 1599
1577 1600 03.05.99 20:53 porto.ifm.uni-kiel.de
1578 1601 --Started changelog.
1579 1602 --make clear do what it say it does
1580 1603 --added pretty output of lines from inputcache
1581 1604 --Made Logger a mixin class, simplifies handling of switches
1582 1605 --Added own completer class. .string<TAB> expands to last history
1583 1606 line which starts with string. The new expansion is also present
1584 1607 with Ctrl-r from the readline library. But this shows, who this
1585 1608 can be done for other cases.
1586 1609 --Added convention that all shell functions should accept a
1587 1610 parameter_string This opens the door for different behaviour for
1588 1611 each function. @cd is a good example of this.
1589 1612
1590 1613 04.05.99 12:12 porto.ifm.uni-kiel.de
1591 1614 --added logfile rotation
1592 1615 --added new mainloop method which freezes first the namespace
1593 1616
1594 1617 07.05.99 21:24 porto.ifm.uni-kiel.de
1595 1618 --added the docreader classes. Now there is a help system.
1596 1619 -This is only a first try. Currently it's not easy to put new
1597 1620 stuff in the indices. But this is the way to go. Info would be
1598 1621 better, but HTML is every where and not everybody has an info
1599 1622 system installed and it's not so easy to change html-docs to info.
1600 1623 --added global logfile option
1601 1624 --there is now a hook for object inspection method pinfo needs to
1602 1625 be provided for this. Can be reached by two '??'.
1603 1626
1604 1627 08.05.99 20:51 porto.ifm.uni-kiel.de
1605 1628 --added a README
1606 1629 --bug in rc file. Something has changed so functions in the rc
1607 1630 file need to reference the shell and not self. Not clear if it's a
1608 1631 bug or feature.
1609 1632 --changed rc file for new behavior
1610 1633
1611 1634 2004-07-15 Fernando Perez <fperez@colorado.edu>
1612 1635
1613 1636 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1614 1637 cache was falling out of sync in bizarre manners when multi-line
1615 1638 input was present. Minor optimizations and cleanup.
1616 1639
1617 1640 (Logger): Remove old Changelog info for cleanup. This is the
1618 1641 information which was there from Janko's original code:
1619 1642
1620 1643 Changes to Logger: - made the default log filename a parameter
1621 1644
1622 1645 - put a check for lines beginning with !@? in log(). Needed
1623 1646 (even if the handlers properly log their lines) for mid-session
1624 1647 logging activation to work properly. Without this, lines logged
1625 1648 in mid session, which get read from the cache, would end up
1626 1649 'bare' (with !@? in the open) in the log. Now they are caught
1627 1650 and prepended with a #.
1628 1651
1629 1652 * IPython/iplib.py (InteractiveShell.init_readline): added check
1630 1653 in case MagicCompleter fails to be defined, so we don't crash.
1631 1654
1632 1655 2004-07-13 Fernando Perez <fperez@colorado.edu>
1633 1656
1634 1657 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1635 1658 of EPS if the requested filename ends in '.eps'.
1636 1659
1637 1660 2004-07-04 Fernando Perez <fperez@colorado.edu>
1638 1661
1639 1662 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1640 1663 escaping of quotes when calling the shell.
1641 1664
1642 1665 2004-07-02 Fernando Perez <fperez@colorado.edu>
1643 1666
1644 1667 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1645 1668 gettext not working because we were clobbering '_'. Fixes
1646 1669 http://www.scipy.net/roundup/ipython/issue6.
1647 1670
1648 1671 2004-07-01 Fernando Perez <fperez@colorado.edu>
1649 1672
1650 1673 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1651 1674 into @cd. Patch by Ville.
1652 1675
1653 1676 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1654 1677 new function to store things after ipmaker runs. Patch by Ville.
1655 1678 Eventually this will go away once ipmaker is removed and the class
1656 1679 gets cleaned up, but for now it's ok. Key functionality here is
1657 1680 the addition of the persistent storage mechanism, a dict for
1658 1681 keeping data across sessions (for now just bookmarks, but more can
1659 1682 be implemented later).
1660 1683
1661 1684 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1662 1685 persistent across sections. Patch by Ville, I modified it
1663 1686 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1664 1687 added a '-l' option to list all bookmarks.
1665 1688
1666 1689 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1667 1690 center for cleanup. Registered with atexit.register(). I moved
1668 1691 here the old exit_cleanup(). After a patch by Ville.
1669 1692
1670 1693 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1671 1694 characters in the hacked shlex_split for python 2.2.
1672 1695
1673 1696 * IPython/iplib.py (file_matches): more fixes to filenames with
1674 1697 whitespace in them. It's not perfect, but limitations in python's
1675 1698 readline make it impossible to go further.
1676 1699
1677 1700 2004-06-29 Fernando Perez <fperez@colorado.edu>
1678 1701
1679 1702 * IPython/iplib.py (file_matches): escape whitespace correctly in
1680 1703 filename completions. Bug reported by Ville.
1681 1704
1682 1705 2004-06-28 Fernando Perez <fperez@colorado.edu>
1683 1706
1684 1707 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1685 1708 the history file will be called 'history-PROFNAME' (or just
1686 1709 'history' if no profile is loaded). I was getting annoyed at
1687 1710 getting my Numerical work history clobbered by pysh sessions.
1688 1711
1689 1712 * IPython/iplib.py (InteractiveShell.__init__): Internal
1690 1713 getoutputerror() function so that we can honor the system_verbose
1691 1714 flag for _all_ system calls. I also added escaping of #
1692 1715 characters here to avoid confusing Itpl.
1693 1716
1694 1717 * IPython/Magic.py (shlex_split): removed call to shell in
1695 1718 parse_options and replaced it with shlex.split(). The annoying
1696 1719 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1697 1720 to backport it from 2.3, with several frail hacks (the shlex
1698 1721 module is rather limited in 2.2). Thanks to a suggestion by Ville
1699 1722 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1700 1723 problem.
1701 1724
1702 1725 (Magic.magic_system_verbose): new toggle to print the actual
1703 1726 system calls made by ipython. Mainly for debugging purposes.
1704 1727
1705 1728 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1706 1729 doesn't support persistence. Reported (and fix suggested) by
1707 1730 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1708 1731
1709 1732 2004-06-26 Fernando Perez <fperez@colorado.edu>
1710 1733
1711 1734 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1712 1735 continue prompts.
1713 1736
1714 1737 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1715 1738 function (basically a big docstring) and a few more things here to
1716 1739 speedup startup. pysh.py is now very lightweight. We want because
1717 1740 it gets execfile'd, while InterpreterExec gets imported, so
1718 1741 byte-compilation saves time.
1719 1742
1720 1743 2004-06-25 Fernando Perez <fperez@colorado.edu>
1721 1744
1722 1745 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1723 1746 -NUM', which was recently broken.
1724 1747
1725 1748 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1726 1749 in multi-line input (but not !!, which doesn't make sense there).
1727 1750
1728 1751 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1729 1752 It's just too useful, and people can turn it off in the less
1730 1753 common cases where it's a problem.
1731 1754
1732 1755 2004-06-24 Fernando Perez <fperez@colorado.edu>
1733 1756
1734 1757 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1735 1758 special syntaxes (like alias calling) is now allied in multi-line
1736 1759 input. This is still _very_ experimental, but it's necessary for
1737 1760 efficient shell usage combining python looping syntax with system
1738 1761 calls. For now it's restricted to aliases, I don't think it
1739 1762 really even makes sense to have this for magics.
1740 1763
1741 1764 2004-06-23 Fernando Perez <fperez@colorado.edu>
1742 1765
1743 1766 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1744 1767 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1745 1768
1746 1769 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1747 1770 extensions under Windows (after code sent by Gary Bishop). The
1748 1771 extensions considered 'executable' are stored in IPython's rc
1749 1772 structure as win_exec_ext.
1750 1773
1751 1774 * IPython/genutils.py (shell): new function, like system() but
1752 1775 without return value. Very useful for interactive shell work.
1753 1776
1754 1777 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1755 1778 delete aliases.
1756 1779
1757 1780 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1758 1781 sure that the alias table doesn't contain python keywords.
1759 1782
1760 1783 2004-06-21 Fernando Perez <fperez@colorado.edu>
1761 1784
1762 1785 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1763 1786 non-existent items are found in $PATH. Reported by Thorsten.
1764 1787
1765 1788 2004-06-20 Fernando Perez <fperez@colorado.edu>
1766 1789
1767 1790 * IPython/iplib.py (complete): modified the completer so that the
1768 1791 order of priorities can be easily changed at runtime.
1769 1792
1770 1793 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1771 1794 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1772 1795
1773 1796 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1774 1797 expand Python variables prepended with $ in all system calls. The
1775 1798 same was done to InteractiveShell.handle_shell_escape. Now all
1776 1799 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1777 1800 expansion of python variables and expressions according to the
1778 1801 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1779 1802
1780 1803 Though PEP-215 has been rejected, a similar (but simpler) one
1781 1804 seems like it will go into Python 2.4, PEP-292 -
1782 1805 http://www.python.org/peps/pep-0292.html.
1783 1806
1784 1807 I'll keep the full syntax of PEP-215, since IPython has since the
1785 1808 start used Ka-Ping Yee's reference implementation discussed there
1786 1809 (Itpl), and I actually like the powerful semantics it offers.
1787 1810
1788 1811 In order to access normal shell variables, the $ has to be escaped
1789 1812 via an extra $. For example:
1790 1813
1791 1814 In [7]: PATH='a python variable'
1792 1815
1793 1816 In [8]: !echo $PATH
1794 1817 a python variable
1795 1818
1796 1819 In [9]: !echo $$PATH
1797 1820 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1798 1821
1799 1822 (Magic.parse_options): escape $ so the shell doesn't evaluate
1800 1823 things prematurely.
1801 1824
1802 1825 * IPython/iplib.py (InteractiveShell.call_alias): added the
1803 1826 ability for aliases to expand python variables via $.
1804 1827
1805 1828 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1806 1829 system, now there's a @rehash/@rehashx pair of magics. These work
1807 1830 like the csh rehash command, and can be invoked at any time. They
1808 1831 build a table of aliases to everything in the user's $PATH
1809 1832 (@rehash uses everything, @rehashx is slower but only adds
1810 1833 executable files). With this, the pysh.py-based shell profile can
1811 1834 now simply call rehash upon startup, and full access to all
1812 1835 programs in the user's path is obtained.
1813 1836
1814 1837 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1815 1838 functionality is now fully in place. I removed the old dynamic
1816 1839 code generation based approach, in favor of a much lighter one
1817 1840 based on a simple dict. The advantage is that this allows me to
1818 1841 now have thousands of aliases with negligible cost (unthinkable
1819 1842 with the old system).
1820 1843
1821 1844 2004-06-19 Fernando Perez <fperez@colorado.edu>
1822 1845
1823 1846 * IPython/iplib.py (__init__): extended MagicCompleter class to
1824 1847 also complete (last in priority) on user aliases.
1825 1848
1826 1849 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1827 1850 call to eval.
1828 1851 (ItplNS.__init__): Added a new class which functions like Itpl,
1829 1852 but allows configuring the namespace for the evaluation to occur
1830 1853 in.
1831 1854
1832 1855 2004-06-18 Fernando Perez <fperez@colorado.edu>
1833 1856
1834 1857 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1835 1858 better message when 'exit' or 'quit' are typed (a common newbie
1836 1859 confusion).
1837 1860
1838 1861 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1839 1862 check for Windows users.
1840 1863
1841 1864 * IPython/iplib.py (InteractiveShell.user_setup): removed
1842 1865 disabling of colors for Windows. I'll test at runtime and issue a
1843 1866 warning if Gary's readline isn't found, as to nudge users to
1844 1867 download it.
1845 1868
1846 1869 2004-06-16 Fernando Perez <fperez@colorado.edu>
1847 1870
1848 1871 * IPython/genutils.py (Stream.__init__): changed to print errors
1849 1872 to sys.stderr. I had a circular dependency here. Now it's
1850 1873 possible to run ipython as IDLE's shell (consider this pre-alpha,
1851 1874 since true stdout things end up in the starting terminal instead
1852 1875 of IDLE's out).
1853 1876
1854 1877 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1855 1878 users who haven't # updated their prompt_in2 definitions. Remove
1856 1879 eventually.
1857 1880 (multiple_replace): added credit to original ASPN recipe.
1858 1881
1859 1882 2004-06-15 Fernando Perez <fperez@colorado.edu>
1860 1883
1861 1884 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1862 1885 list of auto-defined aliases.
1863 1886
1864 1887 2004-06-13 Fernando Perez <fperez@colorado.edu>
1865 1888
1866 1889 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1867 1890 install was really requested (so setup.py can be used for other
1868 1891 things under Windows).
1869 1892
1870 1893 2004-06-10 Fernando Perez <fperez@colorado.edu>
1871 1894
1872 1895 * IPython/Logger.py (Logger.create_log): Manually remove any old
1873 1896 backup, since os.remove may fail under Windows. Fixes bug
1874 1897 reported by Thorsten.
1875 1898
1876 1899 2004-06-09 Fernando Perez <fperez@colorado.edu>
1877 1900
1878 1901 * examples/example-embed.py: fixed all references to %n (replaced
1879 1902 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1880 1903 for all examples and the manual as well.
1881 1904
1882 1905 2004-06-08 Fernando Perez <fperez@colorado.edu>
1883 1906
1884 1907 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1885 1908 alignment and color management. All 3 prompt subsystems now
1886 1909 inherit from BasePrompt.
1887 1910
1888 1911 * tools/release: updates for windows installer build and tag rpms
1889 1912 with python version (since paths are fixed).
1890 1913
1891 1914 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1892 1915 which will become eventually obsolete. Also fixed the default
1893 1916 prompt_in2 to use \D, so at least new users start with the correct
1894 1917 defaults.
1895 1918 WARNING: Users with existing ipythonrc files will need to apply
1896 1919 this fix manually!
1897 1920
1898 1921 * setup.py: make windows installer (.exe). This is finally the
1899 1922 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1900 1923 which I hadn't included because it required Python 2.3 (or recent
1901 1924 distutils).
1902 1925
1903 1926 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1904 1927 usage of new '\D' escape.
1905 1928
1906 1929 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1907 1930 lacks os.getuid())
1908 1931 (CachedOutput.set_colors): Added the ability to turn coloring
1909 1932 on/off with @colors even for manually defined prompt colors. It
1910 1933 uses a nasty global, but it works safely and via the generic color
1911 1934 handling mechanism.
1912 1935 (Prompt2.__init__): Introduced new escape '\D' for continuation
1913 1936 prompts. It represents the counter ('\#') as dots.
1914 1937 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1915 1938 need to update their ipythonrc files and replace '%n' with '\D' in
1916 1939 their prompt_in2 settings everywhere. Sorry, but there's
1917 1940 otherwise no clean way to get all prompts to properly align. The
1918 1941 ipythonrc shipped with IPython has been updated.
1919 1942
1920 1943 2004-06-07 Fernando Perez <fperez@colorado.edu>
1921 1944
1922 1945 * setup.py (isfile): Pass local_icons option to latex2html, so the
1923 1946 resulting HTML file is self-contained. Thanks to
1924 1947 dryice-AT-liu.com.cn for the tip.
1925 1948
1926 1949 * pysh.py: I created a new profile 'shell', which implements a
1927 1950 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1928 1951 system shell, nor will it become one anytime soon. It's mainly
1929 1952 meant to illustrate the use of the new flexible bash-like prompts.
1930 1953 I guess it could be used by hardy souls for true shell management,
1931 1954 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1932 1955 profile. This uses the InterpreterExec extension provided by
1933 1956 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1934 1957
1935 1958 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1936 1959 auto-align itself with the length of the previous input prompt
1937 1960 (taking into account the invisible color escapes).
1938 1961 (CachedOutput.__init__): Large restructuring of this class. Now
1939 1962 all three prompts (primary1, primary2, output) are proper objects,
1940 1963 managed by the 'parent' CachedOutput class. The code is still a
1941 1964 bit hackish (all prompts share state via a pointer to the cache),
1942 1965 but it's overall far cleaner than before.
1943 1966
1944 1967 * IPython/genutils.py (getoutputerror): modified to add verbose,
1945 1968 debug and header options. This makes the interface of all getout*
1946 1969 functions uniform.
1947 1970 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1948 1971
1949 1972 * IPython/Magic.py (Magic.default_option): added a function to
1950 1973 allow registering default options for any magic command. This
1951 1974 makes it easy to have profiles which customize the magics globally
1952 1975 for a certain use. The values set through this function are
1953 1976 picked up by the parse_options() method, which all magics should
1954 1977 use to parse their options.
1955 1978
1956 1979 * IPython/genutils.py (warn): modified the warnings framework to
1957 1980 use the Term I/O class. I'm trying to slowly unify all of
1958 1981 IPython's I/O operations to pass through Term.
1959 1982
1960 1983 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1961 1984 the secondary prompt to correctly match the length of the primary
1962 1985 one for any prompt. Now multi-line code will properly line up
1963 1986 even for path dependent prompts, such as the new ones available
1964 1987 via the prompt_specials.
1965 1988
1966 1989 2004-06-06 Fernando Perez <fperez@colorado.edu>
1967 1990
1968 1991 * IPython/Prompts.py (prompt_specials): Added the ability to have
1969 1992 bash-like special sequences in the prompts, which get
1970 1993 automatically expanded. Things like hostname, current working
1971 1994 directory and username are implemented already, but it's easy to
1972 1995 add more in the future. Thanks to a patch by W.J. van der Laan
1973 1996 <gnufnork-AT-hetdigitalegat.nl>
1974 1997 (prompt_specials): Added color support for prompt strings, so
1975 1998 users can define arbitrary color setups for their prompts.
1976 1999
1977 2000 2004-06-05 Fernando Perez <fperez@colorado.edu>
1978 2001
1979 2002 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1980 2003 code to load Gary Bishop's readline and configure it
1981 2004 automatically. Thanks to Gary for help on this.
1982 2005
1983 2006 2004-06-01 Fernando Perez <fperez@colorado.edu>
1984 2007
1985 2008 * IPython/Logger.py (Logger.create_log): fix bug for logging
1986 2009 with no filename (previous fix was incomplete).
1987 2010
1988 2011 2004-05-25 Fernando Perez <fperez@colorado.edu>
1989 2012
1990 2013 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1991 2014 parens would get passed to the shell.
1992 2015
1993 2016 2004-05-20 Fernando Perez <fperez@colorado.edu>
1994 2017
1995 2018 * IPython/Magic.py (Magic.magic_prun): changed default profile
1996 2019 sort order to 'time' (the more common profiling need).
1997 2020
1998 2021 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1999 2022 so that source code shown is guaranteed in sync with the file on
2000 2023 disk (also changed in psource). Similar fix to the one for
2001 2024 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
2002 2025 <yann.ledu-AT-noos.fr>.
2003 2026
2004 2027 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
2005 2028 with a single option would not be correctly parsed. Closes
2006 2029 http://www.scipy.net/roundup/ipython/issue14. This bug had been
2007 2030 introduced in 0.6.0 (on 2004-05-06).
2008 2031
2009 2032 2004-05-13 *** Released version 0.6.0
2010 2033
2011 2034 2004-05-13 Fernando Perez <fperez@colorado.edu>
2012 2035
2013 2036 * debian/: Added debian/ directory to CVS, so that debian support
2014 2037 is publicly accessible. The debian package is maintained by Jack
2015 2038 Moffit <jack-AT-xiph.org>.
2016 2039
2017 2040 * Documentation: included the notes about an ipython-based system
2018 2041 shell (the hypothetical 'pysh') into the new_design.pdf document,
2019 2042 so that these ideas get distributed to users along with the
2020 2043 official documentation.
2021 2044
2022 2045 2004-05-10 Fernando Perez <fperez@colorado.edu>
2023 2046
2024 2047 * IPython/Logger.py (Logger.create_log): fix recently introduced
2025 2048 bug (misindented line) where logstart would fail when not given an
2026 2049 explicit filename.
2027 2050
2028 2051 2004-05-09 Fernando Perez <fperez@colorado.edu>
2029 2052
2030 2053 * IPython/Magic.py (Magic.parse_options): skip system call when
2031 2054 there are no options to look for. Faster, cleaner for the common
2032 2055 case.
2033 2056
2034 2057 * Documentation: many updates to the manual: describing Windows
2035 2058 support better, Gnuplot updates, credits, misc small stuff. Also
2036 2059 updated the new_design doc a bit.
2037 2060
2038 2061 2004-05-06 *** Released version 0.6.0.rc1
2039 2062
2040 2063 2004-05-06 Fernando Perez <fperez@colorado.edu>
2041 2064
2042 2065 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
2043 2066 operations to use the vastly more efficient list/''.join() method.
2044 2067 (FormattedTB.text): Fix
2045 2068 http://www.scipy.net/roundup/ipython/issue12 - exception source
2046 2069 extract not updated after reload. Thanks to Mike Salib
2047 2070 <msalib-AT-mit.edu> for pinning the source of the problem.
2048 2071 Fortunately, the solution works inside ipython and doesn't require
2049 2072 any changes to python proper.
2050 2073
2051 2074 * IPython/Magic.py (Magic.parse_options): Improved to process the
2052 2075 argument list as a true shell would (by actually using the
2053 2076 underlying system shell). This way, all @magics automatically get
2054 2077 shell expansion for variables. Thanks to a comment by Alex
2055 2078 Schmolck.
2056 2079
2057 2080 2004-04-04 Fernando Perez <fperez@colorado.edu>
2058 2081
2059 2082 * IPython/iplib.py (InteractiveShell.interact): Added a special
2060 2083 trap for a debugger quit exception, which is basically impossible
2061 2084 to handle by normal mechanisms, given what pdb does to the stack.
2062 2085 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
2063 2086
2064 2087 2004-04-03 Fernando Perez <fperez@colorado.edu>
2065 2088
2066 2089 * IPython/genutils.py (Term): Standardized the names of the Term
2067 2090 class streams to cin/cout/cerr, following C++ naming conventions
2068 2091 (I can't use in/out/err because 'in' is not a valid attribute
2069 2092 name).
2070 2093
2071 2094 * IPython/iplib.py (InteractiveShell.interact): don't increment
2072 2095 the prompt if there's no user input. By Daniel 'Dang' Griffith
2073 2096 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
2074 2097 Francois Pinard.
2075 2098
2076 2099 2004-04-02 Fernando Perez <fperez@colorado.edu>
2077 2100
2078 2101 * IPython/genutils.py (Stream.__init__): Modified to survive at
2079 2102 least importing in contexts where stdin/out/err aren't true file
2080 2103 objects, such as PyCrust (they lack fileno() and mode). However,
2081 2104 the recovery facilities which rely on these things existing will
2082 2105 not work.
2083 2106
2084 2107 2004-04-01 Fernando Perez <fperez@colorado.edu>
2085 2108
2086 2109 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
2087 2110 use the new getoutputerror() function, so it properly
2088 2111 distinguishes stdout/err.
2089 2112
2090 2113 * IPython/genutils.py (getoutputerror): added a function to
2091 2114 capture separately the standard output and error of a command.
2092 2115 After a comment from dang on the mailing lists. This code is
2093 2116 basically a modified version of commands.getstatusoutput(), from
2094 2117 the standard library.
2095 2118
2096 2119 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
2097 2120 '!!' as a special syntax (shorthand) to access @sx.
2098 2121
2099 2122 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
2100 2123 command and return its output as a list split on '\n'.
2101 2124
2102 2125 2004-03-31 Fernando Perez <fperez@colorado.edu>
2103 2126
2104 2127 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
2105 2128 method to dictionaries used as FakeModule instances if they lack
2106 2129 it. At least pydoc in python2.3 breaks for runtime-defined
2107 2130 functions without this hack. At some point I need to _really_
2108 2131 understand what FakeModule is doing, because it's a gross hack.
2109 2132 But it solves Arnd's problem for now...
2110 2133
2111 2134 2004-02-27 Fernando Perez <fperez@colorado.edu>
2112 2135
2113 2136 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
2114 2137 mode would behave erratically. Also increased the number of
2115 2138 possible logs in rotate mod to 999. Thanks to Rod Holland
2116 2139 <rhh@StructureLABS.com> for the report and fixes.
2117 2140
2118 2141 2004-02-26 Fernando Perez <fperez@colorado.edu>
2119 2142
2120 2143 * IPython/genutils.py (page): Check that the curses module really
2121 2144 has the initscr attribute before trying to use it. For some
2122 2145 reason, the Solaris curses module is missing this. I think this
2123 2146 should be considered a Solaris python bug, but I'm not sure.
2124 2147
2125 2148 2004-01-17 Fernando Perez <fperez@colorado.edu>
2126 2149
2127 2150 * IPython/genutils.py (Stream.__init__): Changes to try to make
2128 2151 ipython robust against stdin/out/err being closed by the user.
2129 2152 This is 'user error' (and blocks a normal python session, at least
2130 2153 the stdout case). However, Ipython should be able to survive such
2131 2154 instances of abuse as gracefully as possible. To simplify the
2132 2155 coding and maintain compatibility with Gary Bishop's Term
2133 2156 contributions, I've made use of classmethods for this. I think
2134 2157 this introduces a dependency on python 2.2.
2135 2158
2136 2159 2004-01-13 Fernando Perez <fperez@colorado.edu>
2137 2160
2138 2161 * IPython/numutils.py (exp_safe): simplified the code a bit and
2139 2162 removed the need for importing the kinds module altogether.
2140 2163
2141 2164 2004-01-06 Fernando Perez <fperez@colorado.edu>
2142 2165
2143 2166 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
2144 2167 a magic function instead, after some community feedback. No
2145 2168 special syntax will exist for it, but its name is deliberately
2146 2169 very short.
2147 2170
2148 2171 2003-12-20 Fernando Perez <fperez@colorado.edu>
2149 2172
2150 2173 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
2151 2174 new functionality, to automagically assign the result of a shell
2152 2175 command to a variable. I'll solicit some community feedback on
2153 2176 this before making it permanent.
2154 2177
2155 2178 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
2156 2179 requested about callables for which inspect couldn't obtain a
2157 2180 proper argspec. Thanks to a crash report sent by Etienne
2158 2181 Posthumus <etienne-AT-apple01.cs.vu.nl>.
2159 2182
2160 2183 2003-12-09 Fernando Perez <fperez@colorado.edu>
2161 2184
2162 2185 * IPython/genutils.py (page): patch for the pager to work across
2163 2186 various versions of Windows. By Gary Bishop.
2164 2187
2165 2188 2003-12-04 Fernando Perez <fperez@colorado.edu>
2166 2189
2167 2190 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
2168 2191 Gnuplot.py version 1.7, whose internal names changed quite a bit.
2169 2192 While I tested this and it looks ok, there may still be corner
2170 2193 cases I've missed.
2171 2194
2172 2195 2003-12-01 Fernando Perez <fperez@colorado.edu>
2173 2196
2174 2197 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
2175 2198 where a line like 'p,q=1,2' would fail because the automagic
2176 2199 system would be triggered for @p.
2177 2200
2178 2201 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
2179 2202 cleanups, code unmodified.
2180 2203
2181 2204 * IPython/genutils.py (Term): added a class for IPython to handle
2182 2205 output. In most cases it will just be a proxy for stdout/err, but
2183 2206 having this allows modifications to be made for some platforms,
2184 2207 such as handling color escapes under Windows. All of this code
2185 2208 was contributed by Gary Bishop, with minor modifications by me.
2186 2209 The actual changes affect many files.
2187 2210
2188 2211 2003-11-30 Fernando Perez <fperez@colorado.edu>
2189 2212
2190 2213 * IPython/iplib.py (file_matches): new completion code, courtesy
2191 2214 of Jeff Collins. This enables filename completion again under
2192 2215 python 2.3, which disabled it at the C level.
2193 2216
2194 2217 2003-11-11 Fernando Perez <fperez@colorado.edu>
2195 2218
2196 2219 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
2197 2220 for Numeric.array(map(...)), but often convenient.
2198 2221
2199 2222 2003-11-05 Fernando Perez <fperez@colorado.edu>
2200 2223
2201 2224 * IPython/numutils.py (frange): Changed a call from int() to
2202 2225 int(round()) to prevent a problem reported with arange() in the
2203 2226 numpy list.
2204 2227
2205 2228 2003-10-06 Fernando Perez <fperez@colorado.edu>
2206 2229
2207 2230 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
2208 2231 prevent crashes if sys lacks an argv attribute (it happens with
2209 2232 embedded interpreters which build a bare-bones sys module).
2210 2233 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
2211 2234
2212 2235 2003-09-24 Fernando Perez <fperez@colorado.edu>
2213 2236
2214 2237 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
2215 2238 to protect against poorly written user objects where __getattr__
2216 2239 raises exceptions other than AttributeError. Thanks to a bug
2217 2240 report by Oliver Sander <osander-AT-gmx.de>.
2218 2241
2219 2242 * IPython/FakeModule.py (FakeModule.__repr__): this method was
2220 2243 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
2221 2244
2222 2245 2003-09-09 Fernando Perez <fperez@colorado.edu>
2223 2246
2224 2247 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
2225 2248 unpacking a list whith a callable as first element would
2226 2249 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
2227 2250 Collins.
2228 2251
2229 2252 2003-08-25 *** Released version 0.5.0
2230 2253
2231 2254 2003-08-22 Fernando Perez <fperez@colorado.edu>
2232 2255
2233 2256 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
2234 2257 improperly defined user exceptions. Thanks to feedback from Mark
2235 2258 Russell <mrussell-AT-verio.net>.
2236 2259
2237 2260 2003-08-20 Fernando Perez <fperez@colorado.edu>
2238 2261
2239 2262 * IPython/OInspect.py (Inspector.pinfo): changed String Form
2240 2263 printing so that it would print multi-line string forms starting
2241 2264 with a new line. This way the formatting is better respected for
2242 2265 objects which work hard to make nice string forms.
2243 2266
2244 2267 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
2245 2268 autocall would overtake data access for objects with both
2246 2269 __getitem__ and __call__.
2247 2270
2248 2271 2003-08-19 *** Released version 0.5.0-rc1
2249 2272
2250 2273 2003-08-19 Fernando Perez <fperez@colorado.edu>
2251 2274
2252 2275 * IPython/deep_reload.py (load_tail): single tiny change here
2253 2276 seems to fix the long-standing bug of dreload() failing to work
2254 2277 for dotted names. But this module is pretty tricky, so I may have
2255 2278 missed some subtlety. Needs more testing!.
2256 2279
2257 2280 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
2258 2281 exceptions which have badly implemented __str__ methods.
2259 2282 (VerboseTB.text): harden against inspect.getinnerframes crashing,
2260 2283 which I've been getting reports about from Python 2.3 users. I
2261 2284 wish I had a simple test case to reproduce the problem, so I could
2262 2285 either write a cleaner workaround or file a bug report if
2263 2286 necessary.
2264 2287
2265 2288 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
2266 2289 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
2267 2290 a bug report by Tjabo Kloppenburg.
2268 2291
2269 2292 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
2270 2293 crashes. Wrapped the pdb call in a blanket try/except, since pdb
2271 2294 seems rather unstable. Thanks to a bug report by Tjabo
2272 2295 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
2273 2296
2274 2297 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
2275 2298 this out soon because of the critical fixes in the inner loop for
2276 2299 generators.
2277 2300
2278 2301 * IPython/Magic.py (Magic.getargspec): removed. This (and
2279 2302 _get_def) have been obsoleted by OInspect for a long time, I
2280 2303 hadn't noticed that they were dead code.
2281 2304 (Magic._ofind): restored _ofind functionality for a few literals
2282 2305 (those in ["''",'""','[]','{}','()']). But it won't work anymore
2283 2306 for things like "hello".capitalize?, since that would require a
2284 2307 potentially dangerous eval() again.
2285 2308
2286 2309 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
2287 2310 logic a bit more to clean up the escapes handling and minimize the
2288 2311 use of _ofind to only necessary cases. The interactive 'feel' of
2289 2312 IPython should have improved quite a bit with the changes in
2290 2313 _prefilter and _ofind (besides being far safer than before).
2291 2314
2292 2315 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
2293 2316 obscure, never reported). Edit would fail to find the object to
2294 2317 edit under some circumstances.
2295 2318 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
2296 2319 which were causing double-calling of generators. Those eval calls
2297 2320 were _very_ dangerous, since code with side effects could be
2298 2321 triggered. As they say, 'eval is evil'... These were the
2299 2322 nastiest evals in IPython. Besides, _ofind is now far simpler,
2300 2323 and it should also be quite a bit faster. Its use of inspect is
2301 2324 also safer, so perhaps some of the inspect-related crashes I've
2302 2325 seen lately with Python 2.3 might be taken care of. That will
2303 2326 need more testing.
2304 2327
2305 2328 2003-08-17 Fernando Perez <fperez@colorado.edu>
2306 2329
2307 2330 * IPython/iplib.py (InteractiveShell._prefilter): significant
2308 2331 simplifications to the logic for handling user escapes. Faster
2309 2332 and simpler code.
2310 2333
2311 2334 2003-08-14 Fernando Perez <fperez@colorado.edu>
2312 2335
2313 2336 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
2314 2337 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
2315 2338 but it should be quite a bit faster. And the recursive version
2316 2339 generated O(log N) intermediate storage for all rank>1 arrays,
2317 2340 even if they were contiguous.
2318 2341 (l1norm): Added this function.
2319 2342 (norm): Added this function for arbitrary norms (including
2320 2343 l-infinity). l1 and l2 are still special cases for convenience
2321 2344 and speed.
2322 2345
2323 2346 2003-08-03 Fernando Perez <fperez@colorado.edu>
2324 2347
2325 2348 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
2326 2349 exceptions, which now raise PendingDeprecationWarnings in Python
2327 2350 2.3. There were some in Magic and some in Gnuplot2.
2328 2351
2329 2352 2003-06-30 Fernando Perez <fperez@colorado.edu>
2330 2353
2331 2354 * IPython/genutils.py (page): modified to call curses only for
2332 2355 terminals where TERM=='xterm'. After problems under many other
2333 2356 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2334 2357
2335 2358 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2336 2359 would be triggered when readline was absent. This was just an old
2337 2360 debugging statement I'd forgotten to take out.
2338 2361
2339 2362 2003-06-20 Fernando Perez <fperez@colorado.edu>
2340 2363
2341 2364 * IPython/genutils.py (clock): modified to return only user time
2342 2365 (not counting system time), after a discussion on scipy. While
2343 2366 system time may be a useful quantity occasionally, it may much
2344 2367 more easily be skewed by occasional swapping or other similar
2345 2368 activity.
2346 2369
2347 2370 2003-06-05 Fernando Perez <fperez@colorado.edu>
2348 2371
2349 2372 * IPython/numutils.py (identity): new function, for building
2350 2373 arbitrary rank Kronecker deltas (mostly backwards compatible with
2351 2374 Numeric.identity)
2352 2375
2353 2376 2003-06-03 Fernando Perez <fperez@colorado.edu>
2354 2377
2355 2378 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2356 2379 arguments passed to magics with spaces, to allow trailing '\' to
2357 2380 work normally (mainly for Windows users).
2358 2381
2359 2382 2003-05-29 Fernando Perez <fperez@colorado.edu>
2360 2383
2361 2384 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2362 2385 instead of pydoc.help. This fixes a bizarre behavior where
2363 2386 printing '%s' % locals() would trigger the help system. Now
2364 2387 ipython behaves like normal python does.
2365 2388
2366 2389 Note that if one does 'from pydoc import help', the bizarre
2367 2390 behavior returns, but this will also happen in normal python, so
2368 2391 it's not an ipython bug anymore (it has to do with how pydoc.help
2369 2392 is implemented).
2370 2393
2371 2394 2003-05-22 Fernando Perez <fperez@colorado.edu>
2372 2395
2373 2396 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2374 2397 return [] instead of None when nothing matches, also match to end
2375 2398 of line. Patch by Gary Bishop.
2376 2399
2377 2400 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2378 2401 protection as before, for files passed on the command line. This
2379 2402 prevents the CrashHandler from kicking in if user files call into
2380 2403 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2381 2404 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2382 2405
2383 2406 2003-05-20 *** Released version 0.4.0
2384 2407
2385 2408 2003-05-20 Fernando Perez <fperez@colorado.edu>
2386 2409
2387 2410 * setup.py: added support for manpages. It's a bit hackish b/c of
2388 2411 a bug in the way the bdist_rpm distutils target handles gzipped
2389 2412 manpages, but it works. After a patch by Jack.
2390 2413
2391 2414 2003-05-19 Fernando Perez <fperez@colorado.edu>
2392 2415
2393 2416 * IPython/numutils.py: added a mockup of the kinds module, since
2394 2417 it was recently removed from Numeric. This way, numutils will
2395 2418 work for all users even if they are missing kinds.
2396 2419
2397 2420 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2398 2421 failure, which can occur with SWIG-wrapped extensions. After a
2399 2422 crash report from Prabhu.
2400 2423
2401 2424 2003-05-16 Fernando Perez <fperez@colorado.edu>
2402 2425
2403 2426 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2404 2427 protect ipython from user code which may call directly
2405 2428 sys.excepthook (this looks like an ipython crash to the user, even
2406 2429 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2407 2430 This is especially important to help users of WxWindows, but may
2408 2431 also be useful in other cases.
2409 2432
2410 2433 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2411 2434 an optional tb_offset to be specified, and to preserve exception
2412 2435 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2413 2436
2414 2437 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2415 2438
2416 2439 2003-05-15 Fernando Perez <fperez@colorado.edu>
2417 2440
2418 2441 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2419 2442 installing for a new user under Windows.
2420 2443
2421 2444 2003-05-12 Fernando Perez <fperez@colorado.edu>
2422 2445
2423 2446 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2424 2447 handler for Emacs comint-based lines. Currently it doesn't do
2425 2448 much (but importantly, it doesn't update the history cache). In
2426 2449 the future it may be expanded if Alex needs more functionality
2427 2450 there.
2428 2451
2429 2452 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2430 2453 info to crash reports.
2431 2454
2432 2455 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2433 2456 just like Python's -c. Also fixed crash with invalid -color
2434 2457 option value at startup. Thanks to Will French
2435 2458 <wfrench-AT-bestweb.net> for the bug report.
2436 2459
2437 2460 2003-05-09 Fernando Perez <fperez@colorado.edu>
2438 2461
2439 2462 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2440 2463 to EvalDict (it's a mapping, after all) and simplified its code
2441 2464 quite a bit, after a nice discussion on c.l.py where Gustavo
2442 2465 CΓ³rdova <gcordova-AT-sismex.com> suggested the new version.
2443 2466
2444 2467 2003-04-30 Fernando Perez <fperez@colorado.edu>
2445 2468
2446 2469 * IPython/genutils.py (timings_out): modified it to reduce its
2447 2470 overhead in the common reps==1 case.
2448 2471
2449 2472 2003-04-29 Fernando Perez <fperez@colorado.edu>
2450 2473
2451 2474 * IPython/genutils.py (timings_out): Modified to use the resource
2452 2475 module, which avoids the wraparound problems of time.clock().
2453 2476
2454 2477 2003-04-17 *** Released version 0.2.15pre4
2455 2478
2456 2479 2003-04-17 Fernando Perez <fperez@colorado.edu>
2457 2480
2458 2481 * setup.py (scriptfiles): Split windows-specific stuff over to a
2459 2482 separate file, in an attempt to have a Windows GUI installer.
2460 2483 That didn't work, but part of the groundwork is done.
2461 2484
2462 2485 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2463 2486 indent/unindent with 4 spaces. Particularly useful in combination
2464 2487 with the new auto-indent option.
2465 2488
2466 2489 2003-04-16 Fernando Perez <fperez@colorado.edu>
2467 2490
2468 2491 * IPython/Magic.py: various replacements of self.rc for
2469 2492 self.shell.rc. A lot more remains to be done to fully disentangle
2470 2493 this class from the main Shell class.
2471 2494
2472 2495 * IPython/GnuplotRuntime.py: added checks for mouse support so
2473 2496 that we don't try to enable it if the current gnuplot doesn't
2474 2497 really support it. Also added checks so that we don't try to
2475 2498 enable persist under Windows (where Gnuplot doesn't recognize the
2476 2499 option).
2477 2500
2478 2501 * IPython/iplib.py (InteractiveShell.interact): Added optional
2479 2502 auto-indenting code, after a patch by King C. Shu
2480 2503 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2481 2504 get along well with pasting indented code. If I ever figure out
2482 2505 how to make that part go well, it will become on by default.
2483 2506
2484 2507 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2485 2508 crash ipython if there was an unmatched '%' in the user's prompt
2486 2509 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2487 2510
2488 2511 * IPython/iplib.py (InteractiveShell.interact): removed the
2489 2512 ability to ask the user whether he wants to crash or not at the
2490 2513 'last line' exception handler. Calling functions at that point
2491 2514 changes the stack, and the error reports would have incorrect
2492 2515 tracebacks.
2493 2516
2494 2517 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2495 2518 pass through a peger a pretty-printed form of any object. After a
2496 2519 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2497 2520
2498 2521 2003-04-14 Fernando Perez <fperez@colorado.edu>
2499 2522
2500 2523 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2501 2524 all files in ~ would be modified at first install (instead of
2502 2525 ~/.ipython). This could be potentially disastrous, as the
2503 2526 modification (make line-endings native) could damage binary files.
2504 2527
2505 2528 2003-04-10 Fernando Perez <fperez@colorado.edu>
2506 2529
2507 2530 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2508 2531 handle only lines which are invalid python. This now means that
2509 2532 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2510 2533 for the bug report.
2511 2534
2512 2535 2003-04-01 Fernando Perez <fperez@colorado.edu>
2513 2536
2514 2537 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2515 2538 where failing to set sys.last_traceback would crash pdb.pm().
2516 2539 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2517 2540 report.
2518 2541
2519 2542 2003-03-25 Fernando Perez <fperez@colorado.edu>
2520 2543
2521 2544 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2522 2545 before printing it (it had a lot of spurious blank lines at the
2523 2546 end).
2524 2547
2525 2548 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2526 2549 output would be sent 21 times! Obviously people don't use this
2527 2550 too often, or I would have heard about it.
2528 2551
2529 2552 2003-03-24 Fernando Perez <fperez@colorado.edu>
2530 2553
2531 2554 * setup.py (scriptfiles): renamed the data_files parameter from
2532 2555 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2533 2556 for the patch.
2534 2557
2535 2558 2003-03-20 Fernando Perez <fperez@colorado.edu>
2536 2559
2537 2560 * IPython/genutils.py (error): added error() and fatal()
2538 2561 functions.
2539 2562
2540 2563 2003-03-18 *** Released version 0.2.15pre3
2541 2564
2542 2565 2003-03-18 Fernando Perez <fperez@colorado.edu>
2543 2566
2544 2567 * setupext/install_data_ext.py
2545 2568 (install_data_ext.initialize_options): Class contributed by Jack
2546 2569 Moffit for fixing the old distutils hack. He is sending this to
2547 2570 the distutils folks so in the future we may not need it as a
2548 2571 private fix.
2549 2572
2550 2573 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2551 2574 changes for Debian packaging. See his patch for full details.
2552 2575 The old distutils hack of making the ipythonrc* files carry a
2553 2576 bogus .py extension is gone, at last. Examples were moved to a
2554 2577 separate subdir under doc/, and the separate executable scripts
2555 2578 now live in their own directory. Overall a great cleanup. The
2556 2579 manual was updated to use the new files, and setup.py has been
2557 2580 fixed for this setup.
2558 2581
2559 2582 * IPython/PyColorize.py (Parser.usage): made non-executable and
2560 2583 created a pycolor wrapper around it to be included as a script.
2561 2584
2562 2585 2003-03-12 *** Released version 0.2.15pre2
2563 2586
2564 2587 2003-03-12 Fernando Perez <fperez@colorado.edu>
2565 2588
2566 2589 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2567 2590 long-standing problem with garbage characters in some terminals.
2568 2591 The issue was really that the \001 and \002 escapes must _only_ be
2569 2592 passed to input prompts (which call readline), but _never_ to
2570 2593 normal text to be printed on screen. I changed ColorANSI to have
2571 2594 two classes: TermColors and InputTermColors, each with the
2572 2595 appropriate escapes for input prompts or normal text. The code in
2573 2596 Prompts.py got slightly more complicated, but this very old and
2574 2597 annoying bug is finally fixed.
2575 2598
2576 2599 All the credit for nailing down the real origin of this problem
2577 2600 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2578 2601 *Many* thanks to him for spending quite a bit of effort on this.
2579 2602
2580 2603 2003-03-05 *** Released version 0.2.15pre1
2581 2604
2582 2605 2003-03-03 Fernando Perez <fperez@colorado.edu>
2583 2606
2584 2607 * IPython/FakeModule.py: Moved the former _FakeModule to a
2585 2608 separate file, because it's also needed by Magic (to fix a similar
2586 2609 pickle-related issue in @run).
2587 2610
2588 2611 2003-03-02 Fernando Perez <fperez@colorado.edu>
2589 2612
2590 2613 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2591 2614 the autocall option at runtime.
2592 2615 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2593 2616 across Magic.py to start separating Magic from InteractiveShell.
2594 2617 (Magic._ofind): Fixed to return proper namespace for dotted
2595 2618 names. Before, a dotted name would always return 'not currently
2596 2619 defined', because it would find the 'parent'. s.x would be found,
2597 2620 but since 'x' isn't defined by itself, it would get confused.
2598 2621 (Magic.magic_run): Fixed pickling problems reported by Ralf
2599 2622 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2600 2623 that I'd used when Mike Heeter reported similar issues at the
2601 2624 top-level, but now for @run. It boils down to injecting the
2602 2625 namespace where code is being executed with something that looks
2603 2626 enough like a module to fool pickle.dump(). Since a pickle stores
2604 2627 a named reference to the importing module, we need this for
2605 2628 pickles to save something sensible.
2606 2629
2607 2630 * IPython/ipmaker.py (make_IPython): added an autocall option.
2608 2631
2609 2632 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2610 2633 the auto-eval code. Now autocalling is an option, and the code is
2611 2634 also vastly safer. There is no more eval() involved at all.
2612 2635
2613 2636 2003-03-01 Fernando Perez <fperez@colorado.edu>
2614 2637
2615 2638 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2616 2639 dict with named keys instead of a tuple.
2617 2640
2618 2641 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2619 2642
2620 2643 * setup.py (make_shortcut): Fixed message about directories
2621 2644 created during Windows installation (the directories were ok, just
2622 2645 the printed message was misleading). Thanks to Chris Liechti
2623 2646 <cliechti-AT-gmx.net> for the heads up.
2624 2647
2625 2648 2003-02-21 Fernando Perez <fperez@colorado.edu>
2626 2649
2627 2650 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2628 2651 of ValueError exception when checking for auto-execution. This
2629 2652 one is raised by things like Numeric arrays arr.flat when the
2630 2653 array is non-contiguous.
2631 2654
2632 2655 2003-01-31 Fernando Perez <fperez@colorado.edu>
2633 2656
2634 2657 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2635 2658 not return any value at all (even though the command would get
2636 2659 executed).
2637 2660 (xsys): Flush stdout right after printing the command to ensure
2638 2661 proper ordering of commands and command output in the total
2639 2662 output.
2640 2663 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2641 2664 system/getoutput as defaults. The old ones are kept for
2642 2665 compatibility reasons, so no code which uses this library needs
2643 2666 changing.
2644 2667
2645 2668 2003-01-27 *** Released version 0.2.14
2646 2669
2647 2670 2003-01-25 Fernando Perez <fperez@colorado.edu>
2648 2671
2649 2672 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2650 2673 functions defined in previous edit sessions could not be re-edited
2651 2674 (because the temp files were immediately removed). Now temp files
2652 2675 are removed only at IPython's exit.
2653 2676 (Magic.magic_run): Improved @run to perform shell-like expansions
2654 2677 on its arguments (~users and $VARS). With this, @run becomes more
2655 2678 like a normal command-line.
2656 2679
2657 2680 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2658 2681 bugs related to embedding and cleaned up that code. A fairly
2659 2682 important one was the impossibility to access the global namespace
2660 2683 through the embedded IPython (only local variables were visible).
2661 2684
2662 2685 2003-01-14 Fernando Perez <fperez@colorado.edu>
2663 2686
2664 2687 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2665 2688 auto-calling to be a bit more conservative. Now it doesn't get
2666 2689 triggered if any of '!=()<>' are in the rest of the input line, to
2667 2690 allow comparing callables. Thanks to Alex for the heads up.
2668 2691
2669 2692 2003-01-07 Fernando Perez <fperez@colorado.edu>
2670 2693
2671 2694 * IPython/genutils.py (page): fixed estimation of the number of
2672 2695 lines in a string to be paged to simply count newlines. This
2673 2696 prevents over-guessing due to embedded escape sequences. A better
2674 2697 long-term solution would involve stripping out the control chars
2675 2698 for the count, but it's potentially so expensive I just don't
2676 2699 think it's worth doing.
2677 2700
2678 2701 2002-12-19 *** Released version 0.2.14pre50
2679 2702
2680 2703 2002-12-19 Fernando Perez <fperez@colorado.edu>
2681 2704
2682 2705 * tools/release (version): Changed release scripts to inform
2683 2706 Andrea and build a NEWS file with a list of recent changes.
2684 2707
2685 2708 * IPython/ColorANSI.py (__all__): changed terminal detection
2686 2709 code. Seems to work better for xterms without breaking
2687 2710 konsole. Will need more testing to determine if WinXP and Mac OSX
2688 2711 also work ok.
2689 2712
2690 2713 2002-12-18 *** Released version 0.2.14pre49
2691 2714
2692 2715 2002-12-18 Fernando Perez <fperez@colorado.edu>
2693 2716
2694 2717 * Docs: added new info about Mac OSX, from Andrea.
2695 2718
2696 2719 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2697 2720 allow direct plotting of python strings whose format is the same
2698 2721 of gnuplot data files.
2699 2722
2700 2723 2002-12-16 Fernando Perez <fperez@colorado.edu>
2701 2724
2702 2725 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2703 2726 value of exit question to be acknowledged.
2704 2727
2705 2728 2002-12-03 Fernando Perez <fperez@colorado.edu>
2706 2729
2707 2730 * IPython/ipmaker.py: removed generators, which had been added
2708 2731 by mistake in an earlier debugging run. This was causing trouble
2709 2732 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2710 2733 for pointing this out.
2711 2734
2712 2735 2002-11-17 Fernando Perez <fperez@colorado.edu>
2713 2736
2714 2737 * Manual: updated the Gnuplot section.
2715 2738
2716 2739 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2717 2740 a much better split of what goes in Runtime and what goes in
2718 2741 Interactive.
2719 2742
2720 2743 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2721 2744 being imported from iplib.
2722 2745
2723 2746 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2724 2747 for command-passing. Now the global Gnuplot instance is called
2725 2748 'gp' instead of 'g', which was really a far too fragile and
2726 2749 common name.
2727 2750
2728 2751 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2729 2752 bounding boxes generated by Gnuplot for square plots.
2730 2753
2731 2754 * IPython/genutils.py (popkey): new function added. I should
2732 2755 suggest this on c.l.py as a dict method, it seems useful.
2733 2756
2734 2757 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2735 2758 to transparently handle PostScript generation. MUCH better than
2736 2759 the previous plot_eps/replot_eps (which I removed now). The code
2737 2760 is also fairly clean and well documented now (including
2738 2761 docstrings).
2739 2762
2740 2763 2002-11-13 Fernando Perez <fperez@colorado.edu>
2741 2764
2742 2765 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2743 2766 (inconsistent with options).
2744 2767
2745 2768 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2746 2769 manually disabled, I don't know why. Fixed it.
2747 2770 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2748 2771 eps output.
2749 2772
2750 2773 2002-11-12 Fernando Perez <fperez@colorado.edu>
2751 2774
2752 2775 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2753 2776 don't propagate up to caller. Fixes crash reported by François
2754 2777 Pinard.
2755 2778
2756 2779 2002-11-09 Fernando Perez <fperez@colorado.edu>
2757 2780
2758 2781 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2759 2782 history file for new users.
2760 2783 (make_IPython): fixed bug where initial install would leave the
2761 2784 user running in the .ipython dir.
2762 2785 (make_IPython): fixed bug where config dir .ipython would be
2763 2786 created regardless of the given -ipythondir option. Thanks to Cory
2764 2787 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2765 2788
2766 2789 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2767 2790 type confirmations. Will need to use it in all of IPython's code
2768 2791 consistently.
2769 2792
2770 2793 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2771 2794 context to print 31 lines instead of the default 5. This will make
2772 2795 the crash reports extremely detailed in case the problem is in
2773 2796 libraries I don't have access to.
2774 2797
2775 2798 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2776 2799 line of defense' code to still crash, but giving users fair
2777 2800 warning. I don't want internal errors to go unreported: if there's
2778 2801 an internal problem, IPython should crash and generate a full
2779 2802 report.
2780 2803
2781 2804 2002-11-08 Fernando Perez <fperez@colorado.edu>
2782 2805
2783 2806 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2784 2807 otherwise uncaught exceptions which can appear if people set
2785 2808 sys.stdout to something badly broken. Thanks to a crash report
2786 2809 from henni-AT-mail.brainbot.com.
2787 2810
2788 2811 2002-11-04 Fernando Perez <fperez@colorado.edu>
2789 2812
2790 2813 * IPython/iplib.py (InteractiveShell.interact): added
2791 2814 __IPYTHON__active to the builtins. It's a flag which goes on when
2792 2815 the interaction starts and goes off again when it stops. This
2793 2816 allows embedding code to detect being inside IPython. Before this
2794 2817 was done via __IPYTHON__, but that only shows that an IPython
2795 2818 instance has been created.
2796 2819
2797 2820 * IPython/Magic.py (Magic.magic_env): I realized that in a
2798 2821 UserDict, instance.data holds the data as a normal dict. So I
2799 2822 modified @env to return os.environ.data instead of rebuilding a
2800 2823 dict by hand.
2801 2824
2802 2825 2002-11-02 Fernando Perez <fperez@colorado.edu>
2803 2826
2804 2827 * IPython/genutils.py (warn): changed so that level 1 prints no
2805 2828 header. Level 2 is now the default (with 'WARNING' header, as
2806 2829 before). I think I tracked all places where changes were needed in
2807 2830 IPython, but outside code using the old level numbering may have
2808 2831 broken.
2809 2832
2810 2833 * IPython/iplib.py (InteractiveShell.runcode): added this to
2811 2834 handle the tracebacks in SystemExit traps correctly. The previous
2812 2835 code (through interact) was printing more of the stack than
2813 2836 necessary, showing IPython internal code to the user.
2814 2837
2815 2838 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2816 2839 default. Now that the default at the confirmation prompt is yes,
2817 2840 it's not so intrusive. François' argument that ipython sessions
2818 2841 tend to be complex enough not to lose them from an accidental C-d,
2819 2842 is a valid one.
2820 2843
2821 2844 * IPython/iplib.py (InteractiveShell.interact): added a
2822 2845 showtraceback() call to the SystemExit trap, and modified the exit
2823 2846 confirmation to have yes as the default.
2824 2847
2825 2848 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2826 2849 this file. It's been gone from the code for a long time, this was
2827 2850 simply leftover junk.
2828 2851
2829 2852 2002-11-01 Fernando Perez <fperez@colorado.edu>
2830 2853
2831 2854 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2832 2855 added. If set, IPython now traps EOF and asks for
2833 2856 confirmation. After a request by François Pinard.
2834 2857
2835 2858 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2836 2859 of @abort, and with a new (better) mechanism for handling the
2837 2860 exceptions.
2838 2861
2839 2862 2002-10-27 Fernando Perez <fperez@colorado.edu>
2840 2863
2841 2864 * IPython/usage.py (__doc__): updated the --help information and
2842 2865 the ipythonrc file to indicate that -log generates
2843 2866 ./ipython.log. Also fixed the corresponding info in @logstart.
2844 2867 This and several other fixes in the manuals thanks to reports by
2845 2868 François Pinard <pinard-AT-iro.umontreal.ca>.
2846 2869
2847 2870 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2848 2871 refer to @logstart (instead of @log, which doesn't exist).
2849 2872
2850 2873 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2851 2874 AttributeError crash. Thanks to Christopher Armstrong
2852 2875 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2853 2876 introduced recently (in 0.2.14pre37) with the fix to the eval
2854 2877 problem mentioned below.
2855 2878
2856 2879 2002-10-17 Fernando Perez <fperez@colorado.edu>
2857 2880
2858 2881 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2859 2882 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2860 2883
2861 2884 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2862 2885 this function to fix a problem reported by Alex Schmolck. He saw
2863 2886 it with list comprehensions and generators, which were getting
2864 2887 called twice. The real problem was an 'eval' call in testing for
2865 2888 automagic which was evaluating the input line silently.
2866 2889
2867 2890 This is a potentially very nasty bug, if the input has side
2868 2891 effects which must not be repeated. The code is much cleaner now,
2869 2892 without any blanket 'except' left and with a regexp test for
2870 2893 actual function names.
2871 2894
2872 2895 But an eval remains, which I'm not fully comfortable with. I just
2873 2896 don't know how to find out if an expression could be a callable in
2874 2897 the user's namespace without doing an eval on the string. However
2875 2898 that string is now much more strictly checked so that no code
2876 2899 slips by, so the eval should only happen for things that can
2877 2900 really be only function/method names.
2878 2901
2879 2902 2002-10-15 Fernando Perez <fperez@colorado.edu>
2880 2903
2881 2904 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2882 2905 OSX information to main manual, removed README_Mac_OSX file from
2883 2906 distribution. Also updated credits for recent additions.
2884 2907
2885 2908 2002-10-10 Fernando Perez <fperez@colorado.edu>
2886 2909
2887 2910 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2888 2911 terminal-related issues. Many thanks to Andrea Riciputi
2889 2912 <andrea.riciputi-AT-libero.it> for writing it.
2890 2913
2891 2914 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2892 2915 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2893 2916
2894 2917 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2895 2918 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2896 2919 <syver-en-AT-online.no> who both submitted patches for this problem.
2897 2920
2898 2921 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2899 2922 global embedding to make sure that things don't overwrite user
2900 2923 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2901 2924
2902 2925 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2903 2926 compatibility. Thanks to Hayden Callow
2904 2927 <h.callow-AT-elec.canterbury.ac.nz>
2905 2928
2906 2929 2002-10-04 Fernando Perez <fperez@colorado.edu>
2907 2930
2908 2931 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2909 2932 Gnuplot.File objects.
2910 2933
2911 2934 2002-07-23 Fernando Perez <fperez@colorado.edu>
2912 2935
2913 2936 * IPython/genutils.py (timing): Added timings() and timing() for
2914 2937 quick access to the most commonly needed data, the execution
2915 2938 times. Old timing() renamed to timings_out().
2916 2939
2917 2940 2002-07-18 Fernando Perez <fperez@colorado.edu>
2918 2941
2919 2942 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2920 2943 bug with nested instances disrupting the parent's tab completion.
2921 2944
2922 2945 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2923 2946 all_completions code to begin the emacs integration.
2924 2947
2925 2948 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2926 2949 argument to allow titling individual arrays when plotting.
2927 2950
2928 2951 2002-07-15 Fernando Perez <fperez@colorado.edu>
2929 2952
2930 2953 * setup.py (make_shortcut): changed to retrieve the value of
2931 2954 'Program Files' directory from the registry (this value changes in
2932 2955 non-english versions of Windows). Thanks to Thomas Fanslau
2933 2956 <tfanslau-AT-gmx.de> for the report.
2934 2957
2935 2958 2002-07-10 Fernando Perez <fperez@colorado.edu>
2936 2959
2937 2960 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2938 2961 a bug in pdb, which crashes if a line with only whitespace is
2939 2962 entered. Bug report submitted to sourceforge.
2940 2963
2941 2964 2002-07-09 Fernando Perez <fperez@colorado.edu>
2942 2965
2943 2966 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2944 2967 reporting exceptions (it's a bug in inspect.py, I just set a
2945 2968 workaround).
2946 2969
2947 2970 2002-07-08 Fernando Perez <fperez@colorado.edu>
2948 2971
2949 2972 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2950 2973 __IPYTHON__ in __builtins__ to show up in user_ns.
2951 2974
2952 2975 2002-07-03 Fernando Perez <fperez@colorado.edu>
2953 2976
2954 2977 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2955 2978 name from @gp_set_instance to @gp_set_default.
2956 2979
2957 2980 * IPython/ipmaker.py (make_IPython): default editor value set to
2958 2981 '0' (a string), to match the rc file. Otherwise will crash when
2959 2982 .strip() is called on it.
2960 2983
2961 2984
2962 2985 2002-06-28 Fernando Perez <fperez@colorado.edu>
2963 2986
2964 2987 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2965 2988 of files in current directory when a file is executed via
2966 2989 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2967 2990
2968 2991 * setup.py (manfiles): fix for rpm builds, submitted by RA
2969 2992 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2970 2993
2971 2994 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2972 2995 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2973 2996 string!). A. Schmolck caught this one.
2974 2997
2975 2998 2002-06-27 Fernando Perez <fperez@colorado.edu>
2976 2999
2977 3000 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2978 3001 defined files at the cmd line. __name__ wasn't being set to
2979 3002 __main__.
2980 3003
2981 3004 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2982 3005 regular lists and tuples besides Numeric arrays.
2983 3006
2984 3007 * IPython/Prompts.py (CachedOutput.__call__): Added output
2985 3008 supression for input ending with ';'. Similar to Mathematica and
2986 3009 Matlab. The _* vars and Out[] list are still updated, just like
2987 3010 Mathematica behaves.
2988 3011
2989 3012 2002-06-25 Fernando Perez <fperez@colorado.edu>
2990 3013
2991 3014 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2992 3015 .ini extensions for profiels under Windows.
2993 3016
2994 3017 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2995 3018 string form. Fix contributed by Alexander Schmolck
2996 3019 <a.schmolck-AT-gmx.net>
2997 3020
2998 3021 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2999 3022 pre-configured Gnuplot instance.
3000 3023
3001 3024 2002-06-21 Fernando Perez <fperez@colorado.edu>
3002 3025
3003 3026 * IPython/numutils.py (exp_safe): new function, works around the
3004 3027 underflow problems in Numeric.
3005 3028 (log2): New fn. Safe log in base 2: returns exact integer answer
3006 3029 for exact integer powers of 2.
3007 3030
3008 3031 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
3009 3032 properly.
3010 3033
3011 3034 2002-06-20 Fernando Perez <fperez@colorado.edu>
3012 3035
3013 3036 * IPython/genutils.py (timing): new function like
3014 3037 Mathematica's. Similar to time_test, but returns more info.
3015 3038
3016 3039 2002-06-18 Fernando Perez <fperez@colorado.edu>
3017 3040
3018 3041 * IPython/Magic.py (Magic.magic_save): modified @save and @r
3019 3042 according to Mike Heeter's suggestions.
3020 3043
3021 3044 2002-06-16 Fernando Perez <fperez@colorado.edu>
3022 3045
3023 3046 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
3024 3047 system. GnuplotMagic is gone as a user-directory option. New files
3025 3048 make it easier to use all the gnuplot stuff both from external
3026 3049 programs as well as from IPython. Had to rewrite part of
3027 3050 hardcopy() b/c of a strange bug: often the ps files simply don't
3028 3051 get created, and require a repeat of the command (often several
3029 3052 times).
3030 3053
3031 3054 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
3032 3055 resolve output channel at call time, so that if sys.stderr has
3033 3056 been redirected by user this gets honored.
3034 3057
3035 3058 2002-06-13 Fernando Perez <fperez@colorado.edu>
3036 3059
3037 3060 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
3038 3061 IPShell. Kept a copy with the old names to avoid breaking people's
3039 3062 embedded code.
3040 3063
3041 3064 * IPython/ipython: simplified it to the bare minimum after
3042 3065 Holger's suggestions. Added info about how to use it in
3043 3066 PYTHONSTARTUP.
3044 3067
3045 3068 * IPython/Shell.py (IPythonShell): changed the options passing
3046 3069 from a string with funky %s replacements to a straight list. Maybe
3047 3070 a bit more typing, but it follows sys.argv conventions, so there's
3048 3071 less special-casing to remember.
3049 3072
3050 3073 2002-06-12 Fernando Perez <fperez@colorado.edu>
3051 3074
3052 3075 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
3053 3076 command. Thanks to a suggestion by Mike Heeter.
3054 3077 (Magic.magic_pfile): added behavior to look at filenames if given
3055 3078 arg is not a defined object.
3056 3079 (Magic.magic_save): New @save function to save code snippets. Also
3057 3080 a Mike Heeter idea.
3058 3081
3059 3082 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
3060 3083 plot() and replot(). Much more convenient now, especially for
3061 3084 interactive use.
3062 3085
3063 3086 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
3064 3087 filenames.
3065 3088
3066 3089 2002-06-02 Fernando Perez <fperez@colorado.edu>
3067 3090
3068 3091 * IPython/Struct.py (Struct.__init__): modified to admit
3069 3092 initialization via another struct.
3070 3093
3071 3094 * IPython/genutils.py (SystemExec.__init__): New stateful
3072 3095 interface to xsys and bq. Useful for writing system scripts.
3073 3096
3074 3097 2002-05-30 Fernando Perez <fperez@colorado.edu>
3075 3098
3076 3099 * MANIFEST.in: Changed docfile selection to exclude all the lyx
3077 3100 documents. This will make the user download smaller (it's getting
3078 3101 too big).
3079 3102
3080 3103 2002-05-29 Fernando Perez <fperez@colorado.edu>
3081 3104
3082 3105 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
3083 3106 fix problems with shelve and pickle. Seems to work, but I don't
3084 3107 know if corner cases break it. Thanks to Mike Heeter
3085 3108 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
3086 3109
3087 3110 2002-05-24 Fernando Perez <fperez@colorado.edu>
3088 3111
3089 3112 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
3090 3113 macros having broken.
3091 3114
3092 3115 2002-05-21 Fernando Perez <fperez@colorado.edu>
3093 3116
3094 3117 * IPython/Magic.py (Magic.magic_logstart): fixed recently
3095 3118 introduced logging bug: all history before logging started was
3096 3119 being written one character per line! This came from the redesign
3097 3120 of the input history as a special list which slices to strings,
3098 3121 not to lists.
3099 3122
3100 3123 2002-05-20 Fernando Perez <fperez@colorado.edu>
3101 3124
3102 3125 * IPython/Prompts.py (CachedOutput.__init__): made the color table
3103 3126 be an attribute of all classes in this module. The design of these
3104 3127 classes needs some serious overhauling.
3105 3128
3106 3129 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
3107 3130 which was ignoring '_' in option names.
3108 3131
3109 3132 * IPython/ultraTB.py (FormattedTB.__init__): Changed
3110 3133 'Verbose_novars' to 'Context' and made it the new default. It's a
3111 3134 bit more readable and also safer than verbose.
3112 3135
3113 3136 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
3114 3137 triple-quoted strings.
3115 3138
3116 3139 * IPython/OInspect.py (__all__): new module exposing the object
3117 3140 introspection facilities. Now the corresponding magics are dummy
3118 3141 wrappers around this. Having this module will make it much easier
3119 3142 to put these functions into our modified pdb.
3120 3143 This new object inspector system uses the new colorizing module,
3121 3144 so source code and other things are nicely syntax highlighted.
3122 3145
3123 3146 2002-05-18 Fernando Perez <fperez@colorado.edu>
3124 3147
3125 3148 * IPython/ColorANSI.py: Split the coloring tools into a separate
3126 3149 module so I can use them in other code easier (they were part of
3127 3150 ultraTB).
3128 3151
3129 3152 2002-05-17 Fernando Perez <fperez@colorado.edu>
3130 3153
3131 3154 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3132 3155 fixed it to set the global 'g' also to the called instance, as
3133 3156 long as 'g' was still a gnuplot instance (so it doesn't overwrite
3134 3157 user's 'g' variables).
3135 3158
3136 3159 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
3137 3160 global variables (aliases to _ih,_oh) so that users which expect
3138 3161 In[5] or Out[7] to work aren't unpleasantly surprised.
3139 3162 (InputList.__getslice__): new class to allow executing slices of
3140 3163 input history directly. Very simple class, complements the use of
3141 3164 macros.
3142 3165
3143 3166 2002-05-16 Fernando Perez <fperez@colorado.edu>
3144 3167
3145 3168 * setup.py (docdirbase): make doc directory be just doc/IPython
3146 3169 without version numbers, it will reduce clutter for users.
3147 3170
3148 3171 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
3149 3172 execfile call to prevent possible memory leak. See for details:
3150 3173 http://mail.python.org/pipermail/python-list/2002-February/088476.html
3151 3174
3152 3175 2002-05-15 Fernando Perez <fperez@colorado.edu>
3153 3176
3154 3177 * IPython/Magic.py (Magic.magic_psource): made the object
3155 3178 introspection names be more standard: pdoc, pdef, pfile and
3156 3179 psource. They all print/page their output, and it makes
3157 3180 remembering them easier. Kept old names for compatibility as
3158 3181 aliases.
3159 3182
3160 3183 2002-05-14 Fernando Perez <fperez@colorado.edu>
3161 3184
3162 3185 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
3163 3186 what the mouse problem was. The trick is to use gnuplot with temp
3164 3187 files and NOT with pipes (for data communication), because having
3165 3188 both pipes and the mouse on is bad news.
3166 3189
3167 3190 2002-05-13 Fernando Perez <fperez@colorado.edu>
3168 3191
3169 3192 * IPython/Magic.py (Magic._ofind): fixed namespace order search
3170 3193 bug. Information would be reported about builtins even when
3171 3194 user-defined functions overrode them.
3172 3195
3173 3196 2002-05-11 Fernando Perez <fperez@colorado.edu>
3174 3197
3175 3198 * IPython/__init__.py (__all__): removed FlexCompleter from
3176 3199 __all__ so that things don't fail in platforms without readline.
3177 3200
3178 3201 2002-05-10 Fernando Perez <fperez@colorado.edu>
3179 3202
3180 3203 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
3181 3204 it requires Numeric, effectively making Numeric a dependency for
3182 3205 IPython.
3183 3206
3184 3207 * Released 0.2.13
3185 3208
3186 3209 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
3187 3210 profiler interface. Now all the major options from the profiler
3188 3211 module are directly supported in IPython, both for single
3189 3212 expressions (@prun) and for full programs (@run -p).
3190 3213
3191 3214 2002-05-09 Fernando Perez <fperez@colorado.edu>
3192 3215
3193 3216 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
3194 3217 magic properly formatted for screen.
3195 3218
3196 3219 * setup.py (make_shortcut): Changed things to put pdf version in
3197 3220 doc/ instead of doc/manual (had to change lyxport a bit).
3198 3221
3199 3222 * IPython/Magic.py (Profile.string_stats): made profile runs go
3200 3223 through pager (they are long and a pager allows searching, saving,
3201 3224 etc.)
3202 3225
3203 3226 2002-05-08 Fernando Perez <fperez@colorado.edu>
3204 3227
3205 3228 * Released 0.2.12
3206 3229
3207 3230 2002-05-06 Fernando Perez <fperez@colorado.edu>
3208 3231
3209 3232 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
3210 3233 introduced); 'hist n1 n2' was broken.
3211 3234 (Magic.magic_pdb): added optional on/off arguments to @pdb
3212 3235 (Magic.magic_run): added option -i to @run, which executes code in
3213 3236 the IPython namespace instead of a clean one. Also added @irun as
3214 3237 an alias to @run -i.
3215 3238
3216 3239 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3217 3240 fixed (it didn't really do anything, the namespaces were wrong).
3218 3241
3219 3242 * IPython/Debugger.py (__init__): Added workaround for python 2.1
3220 3243
3221 3244 * IPython/__init__.py (__all__): Fixed package namespace, now
3222 3245 'import IPython' does give access to IPython.<all> as
3223 3246 expected. Also renamed __release__ to Release.
3224 3247
3225 3248 * IPython/Debugger.py (__license__): created new Pdb class which
3226 3249 functions like a drop-in for the normal pdb.Pdb but does NOT
3227 3250 import readline by default. This way it doesn't muck up IPython's
3228 3251 readline handling, and now tab-completion finally works in the
3229 3252 debugger -- sort of. It completes things globally visible, but the
3230 3253 completer doesn't track the stack as pdb walks it. That's a bit
3231 3254 tricky, and I'll have to implement it later.
3232 3255
3233 3256 2002-05-05 Fernando Perez <fperez@colorado.edu>
3234 3257
3235 3258 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
3236 3259 magic docstrings when printed via ? (explicit \'s were being
3237 3260 printed).
3238 3261
3239 3262 * IPython/ipmaker.py (make_IPython): fixed namespace
3240 3263 identification bug. Now variables loaded via logs or command-line
3241 3264 files are recognized in the interactive namespace by @who.
3242 3265
3243 3266 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
3244 3267 log replay system stemming from the string form of Structs.
3245 3268
3246 3269 * IPython/Magic.py (Macro.__init__): improved macros to properly
3247 3270 handle magic commands in them.
3248 3271 (Magic.magic_logstart): usernames are now expanded so 'logstart
3249 3272 ~/mylog' now works.
3250 3273
3251 3274 * IPython/iplib.py (complete): fixed bug where paths starting with
3252 3275 '/' would be completed as magic names.
3253 3276
3254 3277 2002-05-04 Fernando Perez <fperez@colorado.edu>
3255 3278
3256 3279 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
3257 3280 allow running full programs under the profiler's control.
3258 3281
3259 3282 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
3260 3283 mode to report exceptions verbosely but without formatting
3261 3284 variables. This addresses the issue of ipython 'freezing' (it's
3262 3285 not frozen, but caught in an expensive formatting loop) when huge
3263 3286 variables are in the context of an exception.
3264 3287 (VerboseTB.text): Added '--->' markers at line where exception was
3265 3288 triggered. Much clearer to read, especially in NoColor modes.
3266 3289
3267 3290 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
3268 3291 implemented in reverse when changing to the new parse_options().
3269 3292
3270 3293 2002-05-03 Fernando Perez <fperez@colorado.edu>
3271 3294
3272 3295 * IPython/Magic.py (Magic.parse_options): new function so that
3273 3296 magics can parse options easier.
3274 3297 (Magic.magic_prun): new function similar to profile.run(),
3275 3298 suggested by Chris Hart.
3276 3299 (Magic.magic_cd): fixed behavior so that it only changes if
3277 3300 directory actually is in history.
3278 3301
3279 3302 * IPython/usage.py (__doc__): added information about potential
3280 3303 slowness of Verbose exception mode when there are huge data
3281 3304 structures to be formatted (thanks to Archie Paulson).
3282 3305
3283 3306 * IPython/ipmaker.py (make_IPython): Changed default logging
3284 3307 (when simply called with -log) to use curr_dir/ipython.log in
3285 3308 rotate mode. Fixed crash which was occuring with -log before
3286 3309 (thanks to Jim Boyle).
3287 3310
3288 3311 2002-05-01 Fernando Perez <fperez@colorado.edu>
3289 3312
3290 3313 * Released 0.2.11 for these fixes (mainly the ultraTB one which
3291 3314 was nasty -- though somewhat of a corner case).
3292 3315
3293 3316 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
3294 3317 text (was a bug).
3295 3318
3296 3319 2002-04-30 Fernando Perez <fperez@colorado.edu>
3297 3320
3298 3321 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
3299 3322 a print after ^D or ^C from the user so that the In[] prompt
3300 3323 doesn't over-run the gnuplot one.
3301 3324
3302 3325 2002-04-29 Fernando Perez <fperez@colorado.edu>
3303 3326
3304 3327 * Released 0.2.10
3305 3328
3306 3329 * IPython/__release__.py (version): get date dynamically.
3307 3330
3308 3331 * Misc. documentation updates thanks to Arnd's comments. Also ran
3309 3332 a full spellcheck on the manual (hadn't been done in a while).
3310 3333
3311 3334 2002-04-27 Fernando Perez <fperez@colorado.edu>
3312 3335
3313 3336 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
3314 3337 starting a log in mid-session would reset the input history list.
3315 3338
3316 3339 2002-04-26 Fernando Perez <fperez@colorado.edu>
3317 3340
3318 3341 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
3319 3342 all files were being included in an update. Now anything in
3320 3343 UserConfig that matches [A-Za-z]*.py will go (this excludes
3321 3344 __init__.py)
3322 3345
3323 3346 2002-04-25 Fernando Perez <fperez@colorado.edu>
3324 3347
3325 3348 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
3326 3349 to __builtins__ so that any form of embedded or imported code can
3327 3350 test for being inside IPython.
3328 3351
3329 3352 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3330 3353 changed to GnuplotMagic because it's now an importable module,
3331 3354 this makes the name follow that of the standard Gnuplot module.
3332 3355 GnuplotMagic can now be loaded at any time in mid-session.
3333 3356
3334 3357 2002-04-24 Fernando Perez <fperez@colorado.edu>
3335 3358
3336 3359 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3337 3360 the globals (IPython has its own namespace) and the
3338 3361 PhysicalQuantity stuff is much better anyway.
3339 3362
3340 3363 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3341 3364 embedding example to standard user directory for
3342 3365 distribution. Also put it in the manual.
3343 3366
3344 3367 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3345 3368 instance as first argument (so it doesn't rely on some obscure
3346 3369 hidden global).
3347 3370
3348 3371 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3349 3372 delimiters. While it prevents ().TAB from working, it allows
3350 3373 completions in open (... expressions. This is by far a more common
3351 3374 case.
3352 3375
3353 3376 2002-04-23 Fernando Perez <fperez@colorado.edu>
3354 3377
3355 3378 * IPython/Extensions/InterpreterPasteInput.py: new
3356 3379 syntax-processing module for pasting lines with >>> or ... at the
3357 3380 start.
3358 3381
3359 3382 * IPython/Extensions/PhysicalQ_Interactive.py
3360 3383 (PhysicalQuantityInteractive.__int__): fixed to work with either
3361 3384 Numeric or math.
3362 3385
3363 3386 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3364 3387 provided profiles. Now we have:
3365 3388 -math -> math module as * and cmath with its own namespace.
3366 3389 -numeric -> Numeric as *, plus gnuplot & grace
3367 3390 -physics -> same as before
3368 3391
3369 3392 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3370 3393 user-defined magics wouldn't be found by @magic if they were
3371 3394 defined as class methods. Also cleaned up the namespace search
3372 3395 logic and the string building (to use %s instead of many repeated
3373 3396 string adds).
3374 3397
3375 3398 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3376 3399 of user-defined magics to operate with class methods (cleaner, in
3377 3400 line with the gnuplot code).
3378 3401
3379 3402 2002-04-22 Fernando Perez <fperez@colorado.edu>
3380 3403
3381 3404 * setup.py: updated dependency list so that manual is updated when
3382 3405 all included files change.
3383 3406
3384 3407 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3385 3408 the delimiter removal option (the fix is ugly right now).
3386 3409
3387 3410 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3388 3411 all of the math profile (quicker loading, no conflict between
3389 3412 g-9.8 and g-gnuplot).
3390 3413
3391 3414 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3392 3415 name of post-mortem files to IPython_crash_report.txt.
3393 3416
3394 3417 * Cleanup/update of the docs. Added all the new readline info and
3395 3418 formatted all lists as 'real lists'.
3396 3419
3397 3420 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3398 3421 tab-completion options, since the full readline parse_and_bind is
3399 3422 now accessible.
3400 3423
3401 3424 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3402 3425 handling of readline options. Now users can specify any string to
3403 3426 be passed to parse_and_bind(), as well as the delimiters to be
3404 3427 removed.
3405 3428 (InteractiveShell.__init__): Added __name__ to the global
3406 3429 namespace so that things like Itpl which rely on its existence
3407 3430 don't crash.
3408 3431 (InteractiveShell._prefilter): Defined the default with a _ so
3409 3432 that prefilter() is easier to override, while the default one
3410 3433 remains available.
3411 3434
3412 3435 2002-04-18 Fernando Perez <fperez@colorado.edu>
3413 3436
3414 3437 * Added information about pdb in the docs.
3415 3438
3416 3439 2002-04-17 Fernando Perez <fperez@colorado.edu>
3417 3440
3418 3441 * IPython/ipmaker.py (make_IPython): added rc_override option to
3419 3442 allow passing config options at creation time which may override
3420 3443 anything set in the config files or command line. This is
3421 3444 particularly useful for configuring embedded instances.
3422 3445
3423 3446 2002-04-15 Fernando Perez <fperez@colorado.edu>
3424 3447
3425 3448 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3426 3449 crash embedded instances because of the input cache falling out of
3427 3450 sync with the output counter.
3428 3451
3429 3452 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3430 3453 mode which calls pdb after an uncaught exception in IPython itself.
3431 3454
3432 3455 2002-04-14 Fernando Perez <fperez@colorado.edu>
3433 3456
3434 3457 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3435 3458 readline, fix it back after each call.
3436 3459
3437 3460 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3438 3461 method to force all access via __call__(), which guarantees that
3439 3462 traceback references are properly deleted.
3440 3463
3441 3464 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3442 3465 improve printing when pprint is in use.
3443 3466
3444 3467 2002-04-13 Fernando Perez <fperez@colorado.edu>
3445 3468
3446 3469 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3447 3470 exceptions aren't caught anymore. If the user triggers one, he
3448 3471 should know why he's doing it and it should go all the way up,
3449 3472 just like any other exception. So now @abort will fully kill the
3450 3473 embedded interpreter and the embedding code (unless that happens
3451 3474 to catch SystemExit).
3452 3475
3453 3476 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3454 3477 and a debugger() method to invoke the interactive pdb debugger
3455 3478 after printing exception information. Also added the corresponding
3456 3479 -pdb option and @pdb magic to control this feature, and updated
3457 3480 the docs. After a suggestion from Christopher Hart
3458 3481 (hart-AT-caltech.edu).
3459 3482
3460 3483 2002-04-12 Fernando Perez <fperez@colorado.edu>
3461 3484
3462 3485 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3463 3486 the exception handlers defined by the user (not the CrashHandler)
3464 3487 so that user exceptions don't trigger an ipython bug report.
3465 3488
3466 3489 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3467 3490 configurable (it should have always been so).
3468 3491
3469 3492 2002-03-26 Fernando Perez <fperez@colorado.edu>
3470 3493
3471 3494 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3472 3495 and there to fix embedding namespace issues. This should all be
3473 3496 done in a more elegant way.
3474 3497
3475 3498 2002-03-25 Fernando Perez <fperez@colorado.edu>
3476 3499
3477 3500 * IPython/genutils.py (get_home_dir): Try to make it work under
3478 3501 win9x also.
3479 3502
3480 3503 2002-03-20 Fernando Perez <fperez@colorado.edu>
3481 3504
3482 3505 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3483 3506 sys.displayhook untouched upon __init__.
3484 3507
3485 3508 2002-03-19 Fernando Perez <fperez@colorado.edu>
3486 3509
3487 3510 * Released 0.2.9 (for embedding bug, basically).
3488 3511
3489 3512 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3490 3513 exceptions so that enclosing shell's state can be restored.
3491 3514
3492 3515 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3493 3516 naming conventions in the .ipython/ dir.
3494 3517
3495 3518 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3496 3519 from delimiters list so filenames with - in them get expanded.
3497 3520
3498 3521 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3499 3522 sys.displayhook not being properly restored after an embedded call.
3500 3523
3501 3524 2002-03-18 Fernando Perez <fperez@colorado.edu>
3502 3525
3503 3526 * Released 0.2.8
3504 3527
3505 3528 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3506 3529 some files weren't being included in a -upgrade.
3507 3530 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3508 3531 on' so that the first tab completes.
3509 3532 (InteractiveShell.handle_magic): fixed bug with spaces around
3510 3533 quotes breaking many magic commands.
3511 3534
3512 3535 * setup.py: added note about ignoring the syntax error messages at
3513 3536 installation.
3514 3537
3515 3538 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3516 3539 streamlining the gnuplot interface, now there's only one magic @gp.
3517 3540
3518 3541 2002-03-17 Fernando Perez <fperez@colorado.edu>
3519 3542
3520 3543 * IPython/UserConfig/magic_gnuplot.py: new name for the
3521 3544 example-magic_pm.py file. Much enhanced system, now with a shell
3522 3545 for communicating directly with gnuplot, one command at a time.
3523 3546
3524 3547 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3525 3548 setting __name__=='__main__'.
3526 3549
3527 3550 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3528 3551 mini-shell for accessing gnuplot from inside ipython. Should
3529 3552 extend it later for grace access too. Inspired by Arnd's
3530 3553 suggestion.
3531 3554
3532 3555 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3533 3556 calling magic functions with () in their arguments. Thanks to Arnd
3534 3557 Baecker for pointing this to me.
3535 3558
3536 3559 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3537 3560 infinitely for integer or complex arrays (only worked with floats).
3538 3561
3539 3562 2002-03-16 Fernando Perez <fperez@colorado.edu>
3540 3563
3541 3564 * setup.py: Merged setup and setup_windows into a single script
3542 3565 which properly handles things for windows users.
3543 3566
3544 3567 2002-03-15 Fernando Perez <fperez@colorado.edu>
3545 3568
3546 3569 * Big change to the manual: now the magics are all automatically
3547 3570 documented. This information is generated from their docstrings
3548 3571 and put in a latex file included by the manual lyx file. This way
3549 3572 we get always up to date information for the magics. The manual
3550 3573 now also has proper version information, also auto-synced.
3551 3574
3552 3575 For this to work, an undocumented --magic_docstrings option was added.
3553 3576
3554 3577 2002-03-13 Fernando Perez <fperez@colorado.edu>
3555 3578
3556 3579 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3557 3580 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3558 3581
3559 3582 2002-03-12 Fernando Perez <fperez@colorado.edu>
3560 3583
3561 3584 * IPython/ultraTB.py (TermColors): changed color escapes again to
3562 3585 fix the (old, reintroduced) line-wrapping bug. Basically, if
3563 3586 \001..\002 aren't given in the color escapes, lines get wrapped
3564 3587 weirdly. But giving those screws up old xterms and emacs terms. So
3565 3588 I added some logic for emacs terms to be ok, but I can't identify old
3566 3589 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3567 3590
3568 3591 2002-03-10 Fernando Perez <fperez@colorado.edu>
3569 3592
3570 3593 * IPython/usage.py (__doc__): Various documentation cleanups and
3571 3594 updates, both in usage docstrings and in the manual.
3572 3595
3573 3596 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3574 3597 handling of caching. Set minimum acceptabe value for having a
3575 3598 cache at 20 values.
3576 3599
3577 3600 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3578 3601 install_first_time function to a method, renamed it and added an
3579 3602 'upgrade' mode. Now people can update their config directory with
3580 3603 a simple command line switch (-upgrade, also new).
3581 3604
3582 3605 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3583 3606 @file (convenient for automagic users under Python >= 2.2).
3584 3607 Removed @files (it seemed more like a plural than an abbrev. of
3585 3608 'file show').
3586 3609
3587 3610 * IPython/iplib.py (install_first_time): Fixed crash if there were
3588 3611 backup files ('~') in .ipython/ install directory.
3589 3612
3590 3613 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3591 3614 system. Things look fine, but these changes are fairly
3592 3615 intrusive. Test them for a few days.
3593 3616
3594 3617 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3595 3618 the prompts system. Now all in/out prompt strings are user
3596 3619 controllable. This is particularly useful for embedding, as one
3597 3620 can tag embedded instances with particular prompts.
3598 3621
3599 3622 Also removed global use of sys.ps1/2, which now allows nested
3600 3623 embeddings without any problems. Added command-line options for
3601 3624 the prompt strings.
3602 3625
3603 3626 2002-03-08 Fernando Perez <fperez@colorado.edu>
3604 3627
3605 3628 * IPython/UserConfig/example-embed-short.py (ipshell): added
3606 3629 example file with the bare minimum code for embedding.
3607 3630
3608 3631 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3609 3632 functionality for the embeddable shell to be activated/deactivated
3610 3633 either globally or at each call.
3611 3634
3612 3635 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3613 3636 rewriting the prompt with '--->' for auto-inputs with proper
3614 3637 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3615 3638 this is handled by the prompts class itself, as it should.
3616 3639
3617 3640 2002-03-05 Fernando Perez <fperez@colorado.edu>
3618 3641
3619 3642 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3620 3643 @logstart to avoid name clashes with the math log function.
3621 3644
3622 3645 * Big updates to X/Emacs section of the manual.
3623 3646
3624 3647 * Removed ipython_emacs. Milan explained to me how to pass
3625 3648 arguments to ipython through Emacs. Some day I'm going to end up
3626 3649 learning some lisp...
3627 3650
3628 3651 2002-03-04 Fernando Perez <fperez@colorado.edu>
3629 3652
3630 3653 * IPython/ipython_emacs: Created script to be used as the
3631 3654 py-python-command Emacs variable so we can pass IPython
3632 3655 parameters. I can't figure out how to tell Emacs directly to pass
3633 3656 parameters to IPython, so a dummy shell script will do it.
3634 3657
3635 3658 Other enhancements made for things to work better under Emacs'
3636 3659 various types of terminals. Many thanks to Milan Zamazal
3637 3660 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3638 3661
3639 3662 2002-03-01 Fernando Perez <fperez@colorado.edu>
3640 3663
3641 3664 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3642 3665 that loading of readline is now optional. This gives better
3643 3666 control to emacs users.
3644 3667
3645 3668 * IPython/ultraTB.py (__date__): Modified color escape sequences
3646 3669 and now things work fine under xterm and in Emacs' term buffers
3647 3670 (though not shell ones). Well, in emacs you get colors, but all
3648 3671 seem to be 'light' colors (no difference between dark and light
3649 3672 ones). But the garbage chars are gone, and also in xterms. It
3650 3673 seems that now I'm using 'cleaner' ansi sequences.
3651 3674
3652 3675 2002-02-21 Fernando Perez <fperez@colorado.edu>
3653 3676
3654 3677 * Released 0.2.7 (mainly to publish the scoping fix).
3655 3678
3656 3679 * IPython/Logger.py (Logger.logstate): added. A corresponding
3657 3680 @logstate magic was created.
3658 3681
3659 3682 * IPython/Magic.py: fixed nested scoping problem under Python
3660 3683 2.1.x (automagic wasn't working).
3661 3684
3662 3685 2002-02-20 Fernando Perez <fperez@colorado.edu>
3663 3686
3664 3687 * Released 0.2.6.
3665 3688
3666 3689 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3667 3690 option so that logs can come out without any headers at all.
3668 3691
3669 3692 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3670 3693 SciPy.
3671 3694
3672 3695 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3673 3696 that embedded IPython calls don't require vars() to be explicitly
3674 3697 passed. Now they are extracted from the caller's frame (code
3675 3698 snatched from Eric Jones' weave). Added better documentation to
3676 3699 the section on embedding and the example file.
3677 3700
3678 3701 * IPython/genutils.py (page): Changed so that under emacs, it just
3679 3702 prints the string. You can then page up and down in the emacs
3680 3703 buffer itself. This is how the builtin help() works.
3681 3704
3682 3705 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3683 3706 macro scoping: macros need to be executed in the user's namespace
3684 3707 to work as if they had been typed by the user.
3685 3708
3686 3709 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3687 3710 execute automatically (no need to type 'exec...'). They then
3688 3711 behave like 'true macros'. The printing system was also modified
3689 3712 for this to work.
3690 3713
3691 3714 2002-02-19 Fernando Perez <fperez@colorado.edu>
3692 3715
3693 3716 * IPython/genutils.py (page_file): new function for paging files
3694 3717 in an OS-independent way. Also necessary for file viewing to work
3695 3718 well inside Emacs buffers.
3696 3719 (page): Added checks for being in an emacs buffer.
3697 3720 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3698 3721 same bug in iplib.
3699 3722
3700 3723 2002-02-18 Fernando Perez <fperez@colorado.edu>
3701 3724
3702 3725 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3703 3726 of readline so that IPython can work inside an Emacs buffer.
3704 3727
3705 3728 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3706 3729 method signatures (they weren't really bugs, but it looks cleaner
3707 3730 and keeps PyChecker happy).
3708 3731
3709 3732 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3710 3733 for implementing various user-defined hooks. Currently only
3711 3734 display is done.
3712 3735
3713 3736 * IPython/Prompts.py (CachedOutput._display): changed display
3714 3737 functions so that they can be dynamically changed by users easily.
3715 3738
3716 3739 * IPython/Extensions/numeric_formats.py (num_display): added an
3717 3740 extension for printing NumPy arrays in flexible manners. It
3718 3741 doesn't do anything yet, but all the structure is in
3719 3742 place. Ultimately the plan is to implement output format control
3720 3743 like in Octave.
3721 3744
3722 3745 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3723 3746 methods are found at run-time by all the automatic machinery.
3724 3747
3725 3748 2002-02-17 Fernando Perez <fperez@colorado.edu>
3726 3749
3727 3750 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3728 3751 whole file a little.
3729 3752
3730 3753 * ToDo: closed this document. Now there's a new_design.lyx
3731 3754 document for all new ideas. Added making a pdf of it for the
3732 3755 end-user distro.
3733 3756
3734 3757 * IPython/Logger.py (Logger.switch_log): Created this to replace
3735 3758 logon() and logoff(). It also fixes a nasty crash reported by
3736 3759 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3737 3760
3738 3761 * IPython/iplib.py (complete): got auto-completion to work with
3739 3762 automagic (I had wanted this for a long time).
3740 3763
3741 3764 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3742 3765 to @file, since file() is now a builtin and clashes with automagic
3743 3766 for @file.
3744 3767
3745 3768 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3746 3769 of this was previously in iplib, which had grown to more than 2000
3747 3770 lines, way too long. No new functionality, but it makes managing
3748 3771 the code a bit easier.
3749 3772
3750 3773 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3751 3774 information to crash reports.
3752 3775
3753 3776 2002-02-12 Fernando Perez <fperez@colorado.edu>
3754 3777
3755 3778 * Released 0.2.5.
3756 3779
3757 3780 2002-02-11 Fernando Perez <fperez@colorado.edu>
3758 3781
3759 3782 * Wrote a relatively complete Windows installer. It puts
3760 3783 everything in place, creates Start Menu entries and fixes the
3761 3784 color issues. Nothing fancy, but it works.
3762 3785
3763 3786 2002-02-10 Fernando Perez <fperez@colorado.edu>
3764 3787
3765 3788 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3766 3789 os.path.expanduser() call so that we can type @run ~/myfile.py and
3767 3790 have thigs work as expected.
3768 3791
3769 3792 * IPython/genutils.py (page): fixed exception handling so things
3770 3793 work both in Unix and Windows correctly. Quitting a pager triggers
3771 3794 an IOError/broken pipe in Unix, and in windows not finding a pager
3772 3795 is also an IOError, so I had to actually look at the return value
3773 3796 of the exception, not just the exception itself. Should be ok now.
3774 3797
3775 3798 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3776 3799 modified to allow case-insensitive color scheme changes.
3777 3800
3778 3801 2002-02-09 Fernando Perez <fperez@colorado.edu>
3779 3802
3780 3803 * IPython/genutils.py (native_line_ends): new function to leave
3781 3804 user config files with os-native line-endings.
3782 3805
3783 3806 * README and manual updates.
3784 3807
3785 3808 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3786 3809 instead of StringType to catch Unicode strings.
3787 3810
3788 3811 * IPython/genutils.py (filefind): fixed bug for paths with
3789 3812 embedded spaces (very common in Windows).
3790 3813
3791 3814 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3792 3815 files under Windows, so that they get automatically associated
3793 3816 with a text editor. Windows makes it a pain to handle
3794 3817 extension-less files.
3795 3818
3796 3819 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3797 3820 warning about readline only occur for Posix. In Windows there's no
3798 3821 way to get readline, so why bother with the warning.
3799 3822
3800 3823 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3801 3824 for __str__ instead of dir(self), since dir() changed in 2.2.
3802 3825
3803 3826 * Ported to Windows! Tested on XP, I suspect it should work fine
3804 3827 on NT/2000, but I don't think it will work on 98 et al. That
3805 3828 series of Windows is such a piece of junk anyway that I won't try
3806 3829 porting it there. The XP port was straightforward, showed a few
3807 3830 bugs here and there (fixed all), in particular some string
3808 3831 handling stuff which required considering Unicode strings (which
3809 3832 Windows uses). This is good, but hasn't been too tested :) No
3810 3833 fancy installer yet, I'll put a note in the manual so people at
3811 3834 least make manually a shortcut.
3812 3835
3813 3836 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3814 3837 into a single one, "colors". This now controls both prompt and
3815 3838 exception color schemes, and can be changed both at startup
3816 3839 (either via command-line switches or via ipythonrc files) and at
3817 3840 runtime, with @colors.
3818 3841 (Magic.magic_run): renamed @prun to @run and removed the old
3819 3842 @run. The two were too similar to warrant keeping both.
3820 3843
3821 3844 2002-02-03 Fernando Perez <fperez@colorado.edu>
3822 3845
3823 3846 * IPython/iplib.py (install_first_time): Added comment on how to
3824 3847 configure the color options for first-time users. Put a <return>
3825 3848 request at the end so that small-terminal users get a chance to
3826 3849 read the startup info.
3827 3850
3828 3851 2002-01-23 Fernando Perez <fperez@colorado.edu>
3829 3852
3830 3853 * IPython/iplib.py (CachedOutput.update): Changed output memory
3831 3854 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3832 3855 input history we still use _i. Did this b/c these variable are
3833 3856 very commonly used in interactive work, so the less we need to
3834 3857 type the better off we are.
3835 3858 (Magic.magic_prun): updated @prun to better handle the namespaces
3836 3859 the file will run in, including a fix for __name__ not being set
3837 3860 before.
3838 3861
3839 3862 2002-01-20 Fernando Perez <fperez@colorado.edu>
3840 3863
3841 3864 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3842 3865 extra garbage for Python 2.2. Need to look more carefully into
3843 3866 this later.
3844 3867
3845 3868 2002-01-19 Fernando Perez <fperez@colorado.edu>
3846 3869
3847 3870 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3848 3871 display SyntaxError exceptions properly formatted when they occur
3849 3872 (they can be triggered by imported code).
3850 3873
3851 3874 2002-01-18 Fernando Perez <fperez@colorado.edu>
3852 3875
3853 3876 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3854 3877 SyntaxError exceptions are reported nicely formatted, instead of
3855 3878 spitting out only offset information as before.
3856 3879 (Magic.magic_prun): Added the @prun function for executing
3857 3880 programs with command line args inside IPython.
3858 3881
3859 3882 2002-01-16 Fernando Perez <fperez@colorado.edu>
3860 3883
3861 3884 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3862 3885 to *not* include the last item given in a range. This brings their
3863 3886 behavior in line with Python's slicing:
3864 3887 a[n1:n2] -> a[n1]...a[n2-1]
3865 3888 It may be a bit less convenient, but I prefer to stick to Python's
3866 3889 conventions *everywhere*, so users never have to wonder.
3867 3890 (Magic.magic_macro): Added @macro function to ease the creation of
3868 3891 macros.
3869 3892
3870 3893 2002-01-05 Fernando Perez <fperez@colorado.edu>
3871 3894
3872 3895 * Released 0.2.4.
3873 3896
3874 3897 * IPython/iplib.py (Magic.magic_pdef):
3875 3898 (InteractiveShell.safe_execfile): report magic lines and error
3876 3899 lines without line numbers so one can easily copy/paste them for
3877 3900 re-execution.
3878 3901
3879 3902 * Updated manual with recent changes.
3880 3903
3881 3904 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3882 3905 docstring printing when class? is called. Very handy for knowing
3883 3906 how to create class instances (as long as __init__ is well
3884 3907 documented, of course :)
3885 3908 (Magic.magic_doc): print both class and constructor docstrings.
3886 3909 (Magic.magic_pdef): give constructor info if passed a class and
3887 3910 __call__ info for callable object instances.
3888 3911
3889 3912 2002-01-04 Fernando Perez <fperez@colorado.edu>
3890 3913
3891 3914 * Made deep_reload() off by default. It doesn't always work
3892 3915 exactly as intended, so it's probably safer to have it off. It's
3893 3916 still available as dreload() anyway, so nothing is lost.
3894 3917
3895 3918 2002-01-02 Fernando Perez <fperez@colorado.edu>
3896 3919
3897 3920 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3898 3921 so I wanted an updated release).
3899 3922
3900 3923 2001-12-27 Fernando Perez <fperez@colorado.edu>
3901 3924
3902 3925 * IPython/iplib.py (InteractiveShell.interact): Added the original
3903 3926 code from 'code.py' for this module in order to change the
3904 3927 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3905 3928 the history cache would break when the user hit Ctrl-C, and
3906 3929 interact() offers no way to add any hooks to it.
3907 3930
3908 3931 2001-12-23 Fernando Perez <fperez@colorado.edu>
3909 3932
3910 3933 * setup.py: added check for 'MANIFEST' before trying to remove
3911 3934 it. Thanks to Sean Reifschneider.
3912 3935
3913 3936 2001-12-22 Fernando Perez <fperez@colorado.edu>
3914 3937
3915 3938 * Released 0.2.2.
3916 3939
3917 3940 * Finished (reasonably) writing the manual. Later will add the
3918 3941 python-standard navigation stylesheets, but for the time being
3919 3942 it's fairly complete. Distribution will include html and pdf
3920 3943 versions.
3921 3944
3922 3945 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3923 3946 (MayaVi author).
3924 3947
3925 3948 2001-12-21 Fernando Perez <fperez@colorado.edu>
3926 3949
3927 3950 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3928 3951 good public release, I think (with the manual and the distutils
3929 3952 installer). The manual can use some work, but that can go
3930 3953 slowly. Otherwise I think it's quite nice for end users. Next
3931 3954 summer, rewrite the guts of it...
3932 3955
3933 3956 * Changed format of ipythonrc files to use whitespace as the
3934 3957 separator instead of an explicit '='. Cleaner.
3935 3958
3936 3959 2001-12-20 Fernando Perez <fperez@colorado.edu>
3937 3960
3938 3961 * Started a manual in LyX. For now it's just a quick merge of the
3939 3962 various internal docstrings and READMEs. Later it may grow into a
3940 3963 nice, full-blown manual.
3941 3964
3942 3965 * Set up a distutils based installer. Installation should now be
3943 3966 trivially simple for end-users.
3944 3967
3945 3968 2001-12-11 Fernando Perez <fperez@colorado.edu>
3946 3969
3947 3970 * Released 0.2.0. First public release, announced it at
3948 3971 comp.lang.python. From now on, just bugfixes...
3949 3972
3950 3973 * Went through all the files, set copyright/license notices and
3951 3974 cleaned up things. Ready for release.
3952 3975
3953 3976 2001-12-10 Fernando Perez <fperez@colorado.edu>
3954 3977
3955 3978 * Changed the first-time installer not to use tarfiles. It's more
3956 3979 robust now and less unix-dependent. Also makes it easier for
3957 3980 people to later upgrade versions.
3958 3981
3959 3982 * Changed @exit to @abort to reflect the fact that it's pretty
3960 3983 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3961 3984 becomes significant only when IPyhton is embedded: in that case,
3962 3985 C-D closes IPython only, but @abort kills the enclosing program
3963 3986 too (unless it had called IPython inside a try catching
3964 3987 SystemExit).
3965 3988
3966 3989 * Created Shell module which exposes the actuall IPython Shell
3967 3990 classes, currently the normal and the embeddable one. This at
3968 3991 least offers a stable interface we won't need to change when
3969 3992 (later) the internals are rewritten. That rewrite will be confined
3970 3993 to iplib and ipmaker, but the Shell interface should remain as is.
3971 3994
3972 3995 * Added embed module which offers an embeddable IPShell object,
3973 3996 useful to fire up IPython *inside* a running program. Great for
3974 3997 debugging or dynamical data analysis.
3975 3998
3976 3999 2001-12-08 Fernando Perez <fperez@colorado.edu>
3977 4000
3978 4001 * Fixed small bug preventing seeing info from methods of defined
3979 4002 objects (incorrect namespace in _ofind()).
3980 4003
3981 4004 * Documentation cleanup. Moved the main usage docstrings to a
3982 4005 separate file, usage.py (cleaner to maintain, and hopefully in the
3983 4006 future some perlpod-like way of producing interactive, man and
3984 4007 html docs out of it will be found).
3985 4008
3986 4009 * Added @profile to see your profile at any time.
3987 4010
3988 4011 * Added @p as an alias for 'print'. It's especially convenient if
3989 4012 using automagic ('p x' prints x).
3990 4013
3991 4014 * Small cleanups and fixes after a pychecker run.
3992 4015
3993 4016 * Changed the @cd command to handle @cd - and @cd -<n> for
3994 4017 visiting any directory in _dh.
3995 4018
3996 4019 * Introduced _dh, a history of visited directories. @dhist prints
3997 4020 it out with numbers.
3998 4021
3999 4022 2001-12-07 Fernando Perez <fperez@colorado.edu>
4000 4023
4001 4024 * Released 0.1.22
4002 4025
4003 4026 * Made initialization a bit more robust against invalid color
4004 4027 options in user input (exit, not traceback-crash).
4005 4028
4006 4029 * Changed the bug crash reporter to write the report only in the
4007 4030 user's .ipython directory. That way IPython won't litter people's
4008 4031 hard disks with crash files all over the place. Also print on
4009 4032 screen the necessary mail command.
4010 4033
4011 4034 * With the new ultraTB, implemented LightBG color scheme for light
4012 4035 background terminals. A lot of people like white backgrounds, so I
4013 4036 guess we should at least give them something readable.
4014 4037
4015 4038 2001-12-06 Fernando Perez <fperez@colorado.edu>
4016 4039
4017 4040 * Modified the structure of ultraTB. Now there's a proper class
4018 4041 for tables of color schemes which allow adding schemes easily and
4019 4042 switching the active scheme without creating a new instance every
4020 4043 time (which was ridiculous). The syntax for creating new schemes
4021 4044 is also cleaner. I think ultraTB is finally done, with a clean
4022 4045 class structure. Names are also much cleaner (now there's proper
4023 4046 color tables, no need for every variable to also have 'color' in
4024 4047 its name).
4025 4048
4026 4049 * Broke down genutils into separate files. Now genutils only
4027 4050 contains utility functions, and classes have been moved to their
4028 4051 own files (they had enough independent functionality to warrant
4029 4052 it): ConfigLoader, OutputTrap, Struct.
4030 4053
4031 4054 2001-12-05 Fernando Perez <fperez@colorado.edu>
4032 4055
4033 4056 * IPython turns 21! Released version 0.1.21, as a candidate for
4034 4057 public consumption. If all goes well, release in a few days.
4035 4058
4036 4059 * Fixed path bug (files in Extensions/ directory wouldn't be found
4037 4060 unless IPython/ was explicitly in sys.path).
4038 4061
4039 4062 * Extended the FlexCompleter class as MagicCompleter to allow
4040 4063 completion of @-starting lines.
4041 4064
4042 4065 * Created __release__.py file as a central repository for release
4043 4066 info that other files can read from.
4044 4067
4045 4068 * Fixed small bug in logging: when logging was turned on in
4046 4069 mid-session, old lines with special meanings (!@?) were being
4047 4070 logged without the prepended comment, which is necessary since
4048 4071 they are not truly valid python syntax. This should make session
4049 4072 restores produce less errors.
4050 4073
4051 4074 * The namespace cleanup forced me to make a FlexCompleter class
4052 4075 which is nothing but a ripoff of rlcompleter, but with selectable
4053 4076 namespace (rlcompleter only works in __main__.__dict__). I'll try
4054 4077 to submit a note to the authors to see if this change can be
4055 4078 incorporated in future rlcompleter releases (Dec.6: done)
4056 4079
4057 4080 * More fixes to namespace handling. It was a mess! Now all
4058 4081 explicit references to __main__.__dict__ are gone (except when
4059 4082 really needed) and everything is handled through the namespace
4060 4083 dicts in the IPython instance. We seem to be getting somewhere
4061 4084 with this, finally...
4062 4085
4063 4086 * Small documentation updates.
4064 4087
4065 4088 * Created the Extensions directory under IPython (with an
4066 4089 __init__.py). Put the PhysicalQ stuff there. This directory should
4067 4090 be used for all special-purpose extensions.
4068 4091
4069 4092 * File renaming:
4070 4093 ipythonlib --> ipmaker
4071 4094 ipplib --> iplib
4072 4095 This makes a bit more sense in terms of what these files actually do.
4073 4096
4074 4097 * Moved all the classes and functions in ipythonlib to ipplib, so
4075 4098 now ipythonlib only has make_IPython(). This will ease up its
4076 4099 splitting in smaller functional chunks later.
4077 4100
4078 4101 * Cleaned up (done, I think) output of @whos. Better column
4079 4102 formatting, and now shows str(var) for as much as it can, which is
4080 4103 typically what one gets with a 'print var'.
4081 4104
4082 4105 2001-12-04 Fernando Perez <fperez@colorado.edu>
4083 4106
4084 4107 * Fixed namespace problems. Now builtin/IPyhton/user names get
4085 4108 properly reported in their namespace. Internal namespace handling
4086 4109 is finally getting decent (not perfect yet, but much better than
4087 4110 the ad-hoc mess we had).
4088 4111
4089 4112 * Removed -exit option. If people just want to run a python
4090 4113 script, that's what the normal interpreter is for. Less
4091 4114 unnecessary options, less chances for bugs.
4092 4115
4093 4116 * Added a crash handler which generates a complete post-mortem if
4094 4117 IPython crashes. This will help a lot in tracking bugs down the
4095 4118 road.
4096 4119
4097 4120 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
4098 4121 which were boud to functions being reassigned would bypass the
4099 4122 logger, breaking the sync of _il with the prompt counter. This
4100 4123 would then crash IPython later when a new line was logged.
4101 4124
4102 4125 2001-12-02 Fernando Perez <fperez@colorado.edu>
4103 4126
4104 4127 * Made IPython a package. This means people don't have to clutter
4105 4128 their sys.path with yet another directory. Changed the INSTALL
4106 4129 file accordingly.
4107 4130
4108 4131 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
4109 4132 sorts its output (so @who shows it sorted) and @whos formats the
4110 4133 table according to the width of the first column. Nicer, easier to
4111 4134 read. Todo: write a generic table_format() which takes a list of
4112 4135 lists and prints it nicely formatted, with optional row/column
4113 4136 separators and proper padding and justification.
4114 4137
4115 4138 * Released 0.1.20
4116 4139
4117 4140 * Fixed bug in @log which would reverse the inputcache list (a
4118 4141 copy operation was missing).
4119 4142
4120 4143 * Code cleanup. @config was changed to use page(). Better, since
4121 4144 its output is always quite long.
4122 4145
4123 4146 * Itpl is back as a dependency. I was having too many problems
4124 4147 getting the parametric aliases to work reliably, and it's just
4125 4148 easier to code weird string operations with it than playing %()s
4126 4149 games. It's only ~6k, so I don't think it's too big a deal.
4127 4150
4128 4151 * Found (and fixed) a very nasty bug with history. !lines weren't
4129 4152 getting cached, and the out of sync caches would crash
4130 4153 IPython. Fixed it by reorganizing the prefilter/handlers/logger
4131 4154 division of labor a bit better. Bug fixed, cleaner structure.
4132 4155
4133 4156 2001-12-01 Fernando Perez <fperez@colorado.edu>
4134 4157
4135 4158 * Released 0.1.19
4136 4159
4137 4160 * Added option -n to @hist to prevent line number printing. Much
4138 4161 easier to copy/paste code this way.
4139 4162
4140 4163 * Created global _il to hold the input list. Allows easy
4141 4164 re-execution of blocks of code by slicing it (inspired by Janko's
4142 4165 comment on 'macros').
4143 4166
4144 4167 * Small fixes and doc updates.
4145 4168
4146 4169 * Rewrote @history function (was @h). Renamed it to @hist, @h is
4147 4170 much too fragile with automagic. Handles properly multi-line
4148 4171 statements and takes parameters.
4149 4172
4150 4173 2001-11-30 Fernando Perez <fperez@colorado.edu>
4151 4174
4152 4175 * Version 0.1.18 released.
4153 4176
4154 4177 * Fixed nasty namespace bug in initial module imports.
4155 4178
4156 4179 * Added copyright/license notes to all code files (except
4157 4180 DPyGetOpt). For the time being, LGPL. That could change.
4158 4181
4159 4182 * Rewrote a much nicer README, updated INSTALL, cleaned up
4160 4183 ipythonrc-* samples.
4161 4184
4162 4185 * Overall code/documentation cleanup. Basically ready for
4163 4186 release. Only remaining thing: licence decision (LGPL?).
4164 4187
4165 4188 * Converted load_config to a class, ConfigLoader. Now recursion
4166 4189 control is better organized. Doesn't include the same file twice.
4167 4190
4168 4191 2001-11-29 Fernando Perez <fperez@colorado.edu>
4169 4192
4170 4193 * Got input history working. Changed output history variables from
4171 4194 _p to _o so that _i is for input and _o for output. Just cleaner
4172 4195 convention.
4173 4196
4174 4197 * Implemented parametric aliases. This pretty much allows the
4175 4198 alias system to offer full-blown shell convenience, I think.
4176 4199
4177 4200 * Version 0.1.17 released, 0.1.18 opened.
4178 4201
4179 4202 * dot_ipython/ipythonrc (alias): added documentation.
4180 4203 (xcolor): Fixed small bug (xcolors -> xcolor)
4181 4204
4182 4205 * Changed the alias system. Now alias is a magic command to define
4183 4206 aliases just like the shell. Rationale: the builtin magics should
4184 4207 be there for things deeply connected to IPython's
4185 4208 architecture. And this is a much lighter system for what I think
4186 4209 is the really important feature: allowing users to define quickly
4187 4210 magics that will do shell things for them, so they can customize
4188 4211 IPython easily to match their work habits. If someone is really
4189 4212 desperate to have another name for a builtin alias, they can
4190 4213 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
4191 4214 works.
4192 4215
4193 4216 2001-11-28 Fernando Perez <fperez@colorado.edu>
4194 4217
4195 4218 * Changed @file so that it opens the source file at the proper
4196 4219 line. Since it uses less, if your EDITOR environment is
4197 4220 configured, typing v will immediately open your editor of choice
4198 4221 right at the line where the object is defined. Not as quick as
4199 4222 having a direct @edit command, but for all intents and purposes it
4200 4223 works. And I don't have to worry about writing @edit to deal with
4201 4224 all the editors, less does that.
4202 4225
4203 4226 * Version 0.1.16 released, 0.1.17 opened.
4204 4227
4205 4228 * Fixed some nasty bugs in the page/page_dumb combo that could
4206 4229 crash IPython.
4207 4230
4208 4231 2001-11-27 Fernando Perez <fperez@colorado.edu>
4209 4232
4210 4233 * Version 0.1.15 released, 0.1.16 opened.
4211 4234
4212 4235 * Finally got ? and ?? to work for undefined things: now it's
4213 4236 possible to type {}.get? and get information about the get method
4214 4237 of dicts, or os.path? even if only os is defined (so technically
4215 4238 os.path isn't). Works at any level. For example, after import os,
4216 4239 os?, os.path?, os.path.abspath? all work. This is great, took some
4217 4240 work in _ofind.
4218 4241
4219 4242 * Fixed more bugs with logging. The sanest way to do it was to add
4220 4243 to @log a 'mode' parameter. Killed two in one shot (this mode
4221 4244 option was a request of Janko's). I think it's finally clean
4222 4245 (famous last words).
4223 4246
4224 4247 * Added a page_dumb() pager which does a decent job of paging on
4225 4248 screen, if better things (like less) aren't available. One less
4226 4249 unix dependency (someday maybe somebody will port this to
4227 4250 windows).
4228 4251
4229 4252 * Fixed problem in magic_log: would lock of logging out if log
4230 4253 creation failed (because it would still think it had succeeded).
4231 4254
4232 4255 * Improved the page() function using curses to auto-detect screen
4233 4256 size. Now it can make a much better decision on whether to print
4234 4257 or page a string. Option screen_length was modified: a value 0
4235 4258 means auto-detect, and that's the default now.
4236 4259
4237 4260 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
4238 4261 go out. I'll test it for a few days, then talk to Janko about
4239 4262 licences and announce it.
4240 4263
4241 4264 * Fixed the length of the auto-generated ---> prompt which appears
4242 4265 for auto-parens and auto-quotes. Getting this right isn't trivial,
4243 4266 with all the color escapes, different prompt types and optional
4244 4267 separators. But it seems to be working in all the combinations.
4245 4268
4246 4269 2001-11-26 Fernando Perez <fperez@colorado.edu>
4247 4270
4248 4271 * Wrote a regexp filter to get option types from the option names
4249 4272 string. This eliminates the need to manually keep two duplicate
4250 4273 lists.
4251 4274
4252 4275 * Removed the unneeded check_option_names. Now options are handled
4253 4276 in a much saner manner and it's easy to visually check that things
4254 4277 are ok.
4255 4278
4256 4279 * Updated version numbers on all files I modified to carry a
4257 4280 notice so Janko and Nathan have clear version markers.
4258 4281
4259 4282 * Updated docstring for ultraTB with my changes. I should send
4260 4283 this to Nathan.
4261 4284
4262 4285 * Lots of small fixes. Ran everything through pychecker again.
4263 4286
4264 4287 * Made loading of deep_reload an cmd line option. If it's not too
4265 4288 kosher, now people can just disable it. With -nodeep_reload it's
4266 4289 still available as dreload(), it just won't overwrite reload().
4267 4290
4268 4291 * Moved many options to the no| form (-opt and -noopt
4269 4292 accepted). Cleaner.
4270 4293
4271 4294 * Changed magic_log so that if called with no parameters, it uses
4272 4295 'rotate' mode. That way auto-generated logs aren't automatically
4273 4296 over-written. For normal logs, now a backup is made if it exists
4274 4297 (only 1 level of backups). A new 'backup' mode was added to the
4275 4298 Logger class to support this. This was a request by Janko.
4276 4299
4277 4300 * Added @logoff/@logon to stop/restart an active log.
4278 4301
4279 4302 * Fixed a lot of bugs in log saving/replay. It was pretty
4280 4303 broken. Now special lines (!@,/) appear properly in the command
4281 4304 history after a log replay.
4282 4305
4283 4306 * Tried and failed to implement full session saving via pickle. My
4284 4307 idea was to pickle __main__.__dict__, but modules can't be
4285 4308 pickled. This would be a better alternative to replaying logs, but
4286 4309 seems quite tricky to get to work. Changed -session to be called
4287 4310 -logplay, which more accurately reflects what it does. And if we
4288 4311 ever get real session saving working, -session is now available.
4289 4312
4290 4313 * Implemented color schemes for prompts also. As for tracebacks,
4291 4314 currently only NoColor and Linux are supported. But now the
4292 4315 infrastructure is in place, based on a generic ColorScheme
4293 4316 class. So writing and activating new schemes both for the prompts
4294 4317 and the tracebacks should be straightforward.
4295 4318
4296 4319 * Version 0.1.13 released, 0.1.14 opened.
4297 4320
4298 4321 * Changed handling of options for output cache. Now counter is
4299 4322 hardwired starting at 1 and one specifies the maximum number of
4300 4323 entries *in the outcache* (not the max prompt counter). This is
4301 4324 much better, since many statements won't increase the cache
4302 4325 count. It also eliminated some confusing options, now there's only
4303 4326 one: cache_size.
4304 4327
4305 4328 * Added 'alias' magic function and magic_alias option in the
4306 4329 ipythonrc file. Now the user can easily define whatever names he
4307 4330 wants for the magic functions without having to play weird
4308 4331 namespace games. This gives IPython a real shell-like feel.
4309 4332
4310 4333 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
4311 4334 @ or not).
4312 4335
4313 4336 This was one of the last remaining 'visible' bugs (that I know
4314 4337 of). I think if I can clean up the session loading so it works
4315 4338 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
4316 4339 about licensing).
4317 4340
4318 4341 2001-11-25 Fernando Perez <fperez@colorado.edu>
4319 4342
4320 4343 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
4321 4344 there's a cleaner distinction between what ? and ?? show.
4322 4345
4323 4346 * Added screen_length option. Now the user can define his own
4324 4347 screen size for page() operations.
4325 4348
4326 4349 * Implemented magic shell-like functions with automatic code
4327 4350 generation. Now adding another function is just a matter of adding
4328 4351 an entry to a dict, and the function is dynamically generated at
4329 4352 run-time. Python has some really cool features!
4330 4353
4331 4354 * Renamed many options to cleanup conventions a little. Now all
4332 4355 are lowercase, and only underscores where needed. Also in the code
4333 4356 option name tables are clearer.
4334 4357
4335 4358 * Changed prompts a little. Now input is 'In [n]:' instead of
4336 4359 'In[n]:='. This allows it the numbers to be aligned with the
4337 4360 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4338 4361 Python (it was a Mathematica thing). The '...' continuation prompt
4339 4362 was also changed a little to align better.
4340 4363
4341 4364 * Fixed bug when flushing output cache. Not all _p<n> variables
4342 4365 exist, so their deletion needs to be wrapped in a try:
4343 4366
4344 4367 * Figured out how to properly use inspect.formatargspec() (it
4345 4368 requires the args preceded by *). So I removed all the code from
4346 4369 _get_pdef in Magic, which was just replicating that.
4347 4370
4348 4371 * Added test to prefilter to allow redefining magic function names
4349 4372 as variables. This is ok, since the @ form is always available,
4350 4373 but whe should allow the user to define a variable called 'ls' if
4351 4374 he needs it.
4352 4375
4353 4376 * Moved the ToDo information from README into a separate ToDo.
4354 4377
4355 4378 * General code cleanup and small bugfixes. I think it's close to a
4356 4379 state where it can be released, obviously with a big 'beta'
4357 4380 warning on it.
4358 4381
4359 4382 * Got the magic function split to work. Now all magics are defined
4360 4383 in a separate class. It just organizes things a bit, and now
4361 4384 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4362 4385 was too long).
4363 4386
4364 4387 * Changed @clear to @reset to avoid potential confusions with
4365 4388 the shell command clear. Also renamed @cl to @clear, which does
4366 4389 exactly what people expect it to from their shell experience.
4367 4390
4368 4391 Added a check to the @reset command (since it's so
4369 4392 destructive, it's probably a good idea to ask for confirmation).
4370 4393 But now reset only works for full namespace resetting. Since the
4371 4394 del keyword is already there for deleting a few specific
4372 4395 variables, I don't see the point of having a redundant magic
4373 4396 function for the same task.
4374 4397
4375 4398 2001-11-24 Fernando Perez <fperez@colorado.edu>
4376 4399
4377 4400 * Updated the builtin docs (esp. the ? ones).
4378 4401
4379 4402 * Ran all the code through pychecker. Not terribly impressed with
4380 4403 it: lots of spurious warnings and didn't really find anything of
4381 4404 substance (just a few modules being imported and not used).
4382 4405
4383 4406 * Implemented the new ultraTB functionality into IPython. New
4384 4407 option: xcolors. This chooses color scheme. xmode now only selects
4385 4408 between Plain and Verbose. Better orthogonality.
4386 4409
4387 4410 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4388 4411 mode and color scheme for the exception handlers. Now it's
4389 4412 possible to have the verbose traceback with no coloring.
4390 4413
4391 4414 2001-11-23 Fernando Perez <fperez@colorado.edu>
4392 4415
4393 4416 * Version 0.1.12 released, 0.1.13 opened.
4394 4417
4395 4418 * Removed option to set auto-quote and auto-paren escapes by
4396 4419 user. The chances of breaking valid syntax are just too high. If
4397 4420 someone *really* wants, they can always dig into the code.
4398 4421
4399 4422 * Made prompt separators configurable.
4400 4423
4401 4424 2001-11-22 Fernando Perez <fperez@colorado.edu>
4402 4425
4403 4426 * Small bugfixes in many places.
4404 4427
4405 4428 * Removed the MyCompleter class from ipplib. It seemed redundant
4406 4429 with the C-p,C-n history search functionality. Less code to
4407 4430 maintain.
4408 4431
4409 4432 * Moved all the original ipython.py code into ipythonlib.py. Right
4410 4433 now it's just one big dump into a function called make_IPython, so
4411 4434 no real modularity has been gained. But at least it makes the
4412 4435 wrapper script tiny, and since ipythonlib is a module, it gets
4413 4436 compiled and startup is much faster.
4414 4437
4415 4438 This is a reasobably 'deep' change, so we should test it for a
4416 4439 while without messing too much more with the code.
4417 4440
4418 4441 2001-11-21 Fernando Perez <fperez@colorado.edu>
4419 4442
4420 4443 * Version 0.1.11 released, 0.1.12 opened for further work.
4421 4444
4422 4445 * Removed dependency on Itpl. It was only needed in one place. It
4423 4446 would be nice if this became part of python, though. It makes life
4424 4447 *a lot* easier in some cases.
4425 4448
4426 4449 * Simplified the prefilter code a bit. Now all handlers are
4427 4450 expected to explicitly return a value (at least a blank string).
4428 4451
4429 4452 * Heavy edits in ipplib. Removed the help system altogether. Now
4430 4453 obj?/?? is used for inspecting objects, a magic @doc prints
4431 4454 docstrings, and full-blown Python help is accessed via the 'help'
4432 4455 keyword. This cleans up a lot of code (less to maintain) and does
4433 4456 the job. Since 'help' is now a standard Python component, might as
4434 4457 well use it and remove duplicate functionality.
4435 4458
4436 4459 Also removed the option to use ipplib as a standalone program. By
4437 4460 now it's too dependent on other parts of IPython to function alone.
4438 4461
4439 4462 * Fixed bug in genutils.pager. It would crash if the pager was
4440 4463 exited immediately after opening (broken pipe).
4441 4464
4442 4465 * Trimmed down the VerboseTB reporting a little. The header is
4443 4466 much shorter now and the repeated exception arguments at the end
4444 4467 have been removed. For interactive use the old header seemed a bit
4445 4468 excessive.
4446 4469
4447 4470 * Fixed small bug in output of @whos for variables with multi-word
4448 4471 types (only first word was displayed).
4449 4472
4450 4473 2001-11-17 Fernando Perez <fperez@colorado.edu>
4451 4474
4452 4475 * Version 0.1.10 released, 0.1.11 opened for further work.
4453 4476
4454 4477 * Modified dirs and friends. dirs now *returns* the stack (not
4455 4478 prints), so one can manipulate it as a variable. Convenient to
4456 4479 travel along many directories.
4457 4480
4458 4481 * Fixed bug in magic_pdef: would only work with functions with
4459 4482 arguments with default values.
4460 4483
4461 4484 2001-11-14 Fernando Perez <fperez@colorado.edu>
4462 4485
4463 4486 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4464 4487 example with IPython. Various other minor fixes and cleanups.
4465 4488
4466 4489 * Version 0.1.9 released, 0.1.10 opened for further work.
4467 4490
4468 4491 * Added sys.path to the list of directories searched in the
4469 4492 execfile= option. It used to be the current directory and the
4470 4493 user's IPYTHONDIR only.
4471 4494
4472 4495 2001-11-13 Fernando Perez <fperez@colorado.edu>
4473 4496
4474 4497 * Reinstated the raw_input/prefilter separation that Janko had
4475 4498 initially. This gives a more convenient setup for extending the
4476 4499 pre-processor from the outside: raw_input always gets a string,
4477 4500 and prefilter has to process it. We can then redefine prefilter
4478 4501 from the outside and implement extensions for special
4479 4502 purposes.
4480 4503
4481 4504 Today I got one for inputting PhysicalQuantity objects
4482 4505 (from Scientific) without needing any function calls at
4483 4506 all. Extremely convenient, and it's all done as a user-level
4484 4507 extension (no IPython code was touched). Now instead of:
4485 4508 a = PhysicalQuantity(4.2,'m/s**2')
4486 4509 one can simply say
4487 4510 a = 4.2 m/s**2
4488 4511 or even
4489 4512 a = 4.2 m/s^2
4490 4513
4491 4514 I use this, but it's also a proof of concept: IPython really is
4492 4515 fully user-extensible, even at the level of the parsing of the
4493 4516 command line. It's not trivial, but it's perfectly doable.
4494 4517
4495 4518 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4496 4519 the problem of modules being loaded in the inverse order in which
4497 4520 they were defined in
4498 4521
4499 4522 * Version 0.1.8 released, 0.1.9 opened for further work.
4500 4523
4501 4524 * Added magics pdef, source and file. They respectively show the
4502 4525 definition line ('prototype' in C), source code and full python
4503 4526 file for any callable object. The object inspector oinfo uses
4504 4527 these to show the same information.
4505 4528
4506 4529 * Version 0.1.7 released, 0.1.8 opened for further work.
4507 4530
4508 4531 * Separated all the magic functions into a class called Magic. The
4509 4532 InteractiveShell class was becoming too big for Xemacs to handle
4510 4533 (de-indenting a line would lock it up for 10 seconds while it
4511 4534 backtracked on the whole class!)
4512 4535
4513 4536 FIXME: didn't work. It can be done, but right now namespaces are
4514 4537 all messed up. Do it later (reverted it for now, so at least
4515 4538 everything works as before).
4516 4539
4517 4540 * Got the object introspection system (magic_oinfo) working! I
4518 4541 think this is pretty much ready for release to Janko, so he can
4519 4542 test it for a while and then announce it. Pretty much 100% of what
4520 4543 I wanted for the 'phase 1' release is ready. Happy, tired.
4521 4544
4522 4545 2001-11-12 Fernando Perez <fperez@colorado.edu>
4523 4546
4524 4547 * Version 0.1.6 released, 0.1.7 opened for further work.
4525 4548
4526 4549 * Fixed bug in printing: it used to test for truth before
4527 4550 printing, so 0 wouldn't print. Now checks for None.
4528 4551
4529 4552 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4530 4553 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4531 4554 reaches by hand into the outputcache. Think of a better way to do
4532 4555 this later.
4533 4556
4534 4557 * Various small fixes thanks to Nathan's comments.
4535 4558
4536 4559 * Changed magic_pprint to magic_Pprint. This way it doesn't
4537 4560 collide with pprint() and the name is consistent with the command
4538 4561 line option.
4539 4562
4540 4563 * Changed prompt counter behavior to be fully like
4541 4564 Mathematica's. That is, even input that doesn't return a result
4542 4565 raises the prompt counter. The old behavior was kind of confusing
4543 4566 (getting the same prompt number several times if the operation
4544 4567 didn't return a result).
4545 4568
4546 4569 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4547 4570
4548 4571 * Fixed -Classic mode (wasn't working anymore).
4549 4572
4550 4573 * Added colored prompts using Nathan's new code. Colors are
4551 4574 currently hardwired, they can be user-configurable. For
4552 4575 developers, they can be chosen in file ipythonlib.py, at the
4553 4576 beginning of the CachedOutput class def.
4554 4577
4555 4578 2001-11-11 Fernando Perez <fperez@colorado.edu>
4556 4579
4557 4580 * Version 0.1.5 released, 0.1.6 opened for further work.
4558 4581
4559 4582 * Changed magic_env to *return* the environment as a dict (not to
4560 4583 print it). This way it prints, but it can also be processed.
4561 4584
4562 4585 * Added Verbose exception reporting to interactive
4563 4586 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4564 4587 traceback. Had to make some changes to the ultraTB file. This is
4565 4588 probably the last 'big' thing in my mental todo list. This ties
4566 4589 in with the next entry:
4567 4590
4568 4591 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4569 4592 has to specify is Plain, Color or Verbose for all exception
4570 4593 handling.
4571 4594
4572 4595 * Removed ShellServices option. All this can really be done via
4573 4596 the magic system. It's easier to extend, cleaner and has automatic
4574 4597 namespace protection and documentation.
4575 4598
4576 4599 2001-11-09 Fernando Perez <fperez@colorado.edu>
4577 4600
4578 4601 * Fixed bug in output cache flushing (missing parameter to
4579 4602 __init__). Other small bugs fixed (found using pychecker).
4580 4603
4581 4604 * Version 0.1.4 opened for bugfixing.
4582 4605
4583 4606 2001-11-07 Fernando Perez <fperez@colorado.edu>
4584 4607
4585 4608 * Version 0.1.3 released, mainly because of the raw_input bug.
4586 4609
4587 4610 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4588 4611 and when testing for whether things were callable, a call could
4589 4612 actually be made to certain functions. They would get called again
4590 4613 once 'really' executed, with a resulting double call. A disaster
4591 4614 in many cases (list.reverse() would never work!).
4592 4615
4593 4616 * Removed prefilter() function, moved its code to raw_input (which
4594 4617 after all was just a near-empty caller for prefilter). This saves
4595 4618 a function call on every prompt, and simplifies the class a tiny bit.
4596 4619
4597 4620 * Fix _ip to __ip name in magic example file.
4598 4621
4599 4622 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4600 4623 work with non-gnu versions of tar.
4601 4624
4602 4625 2001-11-06 Fernando Perez <fperez@colorado.edu>
4603 4626
4604 4627 * Version 0.1.2. Just to keep track of the recent changes.
4605 4628
4606 4629 * Fixed nasty bug in output prompt routine. It used to check 'if
4607 4630 arg != None...'. Problem is, this fails if arg implements a
4608 4631 special comparison (__cmp__) which disallows comparing to
4609 4632 None. Found it when trying to use the PhysicalQuantity module from
4610 4633 ScientificPython.
4611 4634
4612 4635 2001-11-05 Fernando Perez <fperez@colorado.edu>
4613 4636
4614 4637 * Also added dirs. Now the pushd/popd/dirs family functions
4615 4638 basically like the shell, with the added convenience of going home
4616 4639 when called with no args.
4617 4640
4618 4641 * pushd/popd slightly modified to mimic shell behavior more
4619 4642 closely.
4620 4643
4621 4644 * Added env,pushd,popd from ShellServices as magic functions. I
4622 4645 think the cleanest will be to port all desired functions from
4623 4646 ShellServices as magics and remove ShellServices altogether. This
4624 4647 will provide a single, clean way of adding functionality
4625 4648 (shell-type or otherwise) to IP.
4626 4649
4627 4650 2001-11-04 Fernando Perez <fperez@colorado.edu>
4628 4651
4629 4652 * Added .ipython/ directory to sys.path. This way users can keep
4630 4653 customizations there and access them via import.
4631 4654
4632 4655 2001-11-03 Fernando Perez <fperez@colorado.edu>
4633 4656
4634 4657 * Opened version 0.1.1 for new changes.
4635 4658
4636 4659 * Changed version number to 0.1.0: first 'public' release, sent to
4637 4660 Nathan and Janko.
4638 4661
4639 4662 * Lots of small fixes and tweaks.
4640 4663
4641 4664 * Minor changes to whos format. Now strings are shown, snipped if
4642 4665 too long.
4643 4666
4644 4667 * Changed ShellServices to work on __main__ so they show up in @who
4645 4668
4646 4669 * Help also works with ? at the end of a line:
4647 4670 ?sin and sin?
4648 4671 both produce the same effect. This is nice, as often I use the
4649 4672 tab-complete to find the name of a method, but I used to then have
4650 4673 to go to the beginning of the line to put a ? if I wanted more
4651 4674 info. Now I can just add the ? and hit return. Convenient.
4652 4675
4653 4676 2001-11-02 Fernando Perez <fperez@colorado.edu>
4654 4677
4655 4678 * Python version check (>=2.1) added.
4656 4679
4657 4680 * Added LazyPython documentation. At this point the docs are quite
4658 4681 a mess. A cleanup is in order.
4659 4682
4660 4683 * Auto-installer created. For some bizarre reason, the zipfiles
4661 4684 module isn't working on my system. So I made a tar version
4662 4685 (hopefully the command line options in various systems won't kill
4663 4686 me).
4664 4687
4665 4688 * Fixes to Struct in genutils. Now all dictionary-like methods are
4666 4689 protected (reasonably).
4667 4690
4668 4691 * Added pager function to genutils and changed ? to print usage
4669 4692 note through it (it was too long).
4670 4693
4671 4694 * Added the LazyPython functionality. Works great! I changed the
4672 4695 auto-quote escape to ';', it's on home row and next to '. But
4673 4696 both auto-quote and auto-paren (still /) escapes are command-line
4674 4697 parameters.
4675 4698
4676 4699
4677 4700 2001-11-01 Fernando Perez <fperez@colorado.edu>
4678 4701
4679 4702 * Version changed to 0.0.7. Fairly large change: configuration now
4680 4703 is all stored in a directory, by default .ipython. There, all
4681 4704 config files have normal looking names (not .names)
4682 4705
4683 4706 * Version 0.0.6 Released first to Lucas and Archie as a test
4684 4707 run. Since it's the first 'semi-public' release, change version to
4685 4708 > 0.0.6 for any changes now.
4686 4709
4687 4710 * Stuff I had put in the ipplib.py changelog:
4688 4711
4689 4712 Changes to InteractiveShell:
4690 4713
4691 4714 - Made the usage message a parameter.
4692 4715
4693 4716 - Require the name of the shell variable to be given. It's a bit
4694 4717 of a hack, but allows the name 'shell' not to be hardwire in the
4695 4718 magic (@) handler, which is problematic b/c it requires
4696 4719 polluting the global namespace with 'shell'. This in turn is
4697 4720 fragile: if a user redefines a variable called shell, things
4698 4721 break.
4699 4722
4700 4723 - magic @: all functions available through @ need to be defined
4701 4724 as magic_<name>, even though they can be called simply as
4702 4725 @<name>. This allows the special command @magic to gather
4703 4726 information automatically about all existing magic functions,
4704 4727 even if they are run-time user extensions, by parsing the shell
4705 4728 instance __dict__ looking for special magic_ names.
4706 4729
4707 4730 - mainloop: added *two* local namespace parameters. This allows
4708 4731 the class to differentiate between parameters which were there
4709 4732 before and after command line initialization was processed. This
4710 4733 way, later @who can show things loaded at startup by the
4711 4734 user. This trick was necessary to make session saving/reloading
4712 4735 really work: ideally after saving/exiting/reloading a session,
4713 4736 *everythin* should look the same, including the output of @who. I
4714 4737 was only able to make this work with this double namespace
4715 4738 trick.
4716 4739
4717 4740 - added a header to the logfile which allows (almost) full
4718 4741 session restoring.
4719 4742
4720 4743 - prepend lines beginning with @ or !, with a and log
4721 4744 them. Why? !lines: may be useful to know what you did @lines:
4722 4745 they may affect session state. So when restoring a session, at
4723 4746 least inform the user of their presence. I couldn't quite get
4724 4747 them to properly re-execute, but at least the user is warned.
4725 4748
4726 4749 * Started ChangeLog.
@@ -1,127 +1,129 b''
1 1 #!/usr/bin/env python
2 2
3 3 """An example of how to embed an IPython shell into a running program.
4 4
5 5 Please see the documentation in the IPython.Shell module for more details.
6 6
7 7 The accompanying file example-embed-short.py has quick code fragments for
8 8 embedding which you can cut and paste in your code once you understand how
9 9 things work.
10 10
11 11 The code in this file is deliberately extra-verbose, meant for learning."""
12 12
13 13 # The basics to get you going:
14 14
15 15 # IPython sets the __IPYTHON__ variable so you can know if you have nested
16 16 # copies running.
17 17
18 18 # Try running this code both at the command line and from inside IPython (with
19 19 # %run example-embed.py)
20 20 try:
21 21 __IPYTHON__
22 22 except NameError:
23 23 nested = 0
24 24 args = ['']
25 25 else:
26 26 print "Running nested copies of IPython."
27 27 print "The prompts for the nested copy have been modified"
28 28 nested = 1
29 29 # what the embedded instance will see as sys.argv:
30 args = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:','-nosep']
30 args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ',
31 '-po','Out<\\#>: ','-nosep']
31 32
32 33 # First import the embeddable shell class
33 34 from IPython.Shell import IPShellEmbed
34 35
35 36 # Now create an instance of the embeddable shell. The first argument is a
36 37 # string with options exactly as you would type them if you were starting
37 38 # IPython at the system command line. Any parameters you want to define for
38 39 # configuration can thus be specified here.
39 40 ipshell = IPShellEmbed(args,
40 41 banner = 'Dropping into IPython',
41 42 exit_msg = 'Leaving Interpreter, back to program.')
42 43
43 44 # Make a second instance, you can have as many as you want.
44 45 if nested:
45 46 args[1] = 'In2<\\#>'
46 47 else:
47 args = ['-pi1','In2<\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:','-nosep']
48 args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ',
49 '-po','Out<\\#>: ','-nosep']
48 50 ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.')
49 51
50 52 print '\nHello. This is printed from the main controller program.\n'
51 53
52 54 # You can then call ipshell() anywhere you need it (with an optional
53 55 # message):
54 56 ipshell('***Called from top level. '
55 57 'Hit Ctrl-D to exit interpreter and continue program.')
56 58
57 59 print '\nBack in caller program, moving along...\n'
58 60
59 61 #---------------------------------------------------------------------------
60 62 # More details:
61 63
62 64 # IPShellEmbed instances don't print the standard system banner and
63 65 # messages. The IPython banner (which actually may contain initialization
64 66 # messages) is available as <instance>.IP.BANNER in case you want it.
65 67
66 68 # IPShellEmbed instances print the following information everytime they
67 69 # start:
68 70
69 71 # - A global startup banner.
70 72
71 73 # - A call-specific header string, which you can use to indicate where in the
72 74 # execution flow the shell is starting.
73 75
74 76 # They also print an exit message every time they exit.
75 77
76 78 # Both the startup banner and the exit message default to None, and can be set
77 79 # either at the instance constructor or at any other time with the
78 80 # set_banner() and set_exit_msg() methods.
79 81
80 82 # The shell instance can be also put in 'dummy' mode globally or on a per-call
81 83 # basis. This gives you fine control for debugging without having to change
82 84 # code all over the place.
83 85
84 86 # The code below illustrates all this.
85 87
86 88
87 89 # This is how the global banner and exit_msg can be reset at any point
88 90 ipshell.set_banner('Entering interpreter - New Banner')
89 91 ipshell.set_exit_msg('Leaving interpreter - New exit_msg')
90 92
91 93 def foo(m):
92 94 s = 'spam'
93 95 ipshell('***In foo(). Try @whos, or print s or m:')
94 96 print 'foo says m = ',m
95 97
96 98 def bar(n):
97 99 s = 'eggs'
98 100 ipshell('***In bar(). Try @whos, or print s or n:')
99 101 print 'bar says n = ',n
100 102
101 103 # Some calls to the above functions which will trigger IPython:
102 104 print 'Main program calling foo("eggs")\n'
103 105 foo('eggs')
104 106
105 107 # The shell can be put in 'dummy' mode where calls to it silently return. This
106 108 # allows you, for example, to globally turn off debugging for a program with a
107 109 # single call.
108 110 ipshell.set_dummy_mode(1)
109 111 print '\nTrying to call IPython which is now "dummy":'
110 112 ipshell()
111 113 print 'Nothing happened...'
112 114 # The global 'dummy' mode can still be overridden for a single call
113 115 print '\nOverriding dummy mode manually:'
114 116 ipshell(dummy=0)
115 117
116 118 # Reactivate the IPython shell
117 119 ipshell.set_dummy_mode(0)
118 120
119 121 print 'You can even have multiple embedded instances:'
120 122 ipshell2()
121 123
122 124 print '\nMain program calling bar("spam")\n'
123 125 bar('spam')
124 126
125 127 print 'Main program finished. Bye!'
126 128
127 129 #********************** End of file <example-embed.py> ***********************
General Comments 0
You need to be logged in to leave comments. Login now