##// END OF EJS Templates
Add sys.argv support for demos.
fperez -
Show More
@@ -1,2490 +1,2454 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 583 2005-05-13 21:20:33Z fperez $"""
4 $Id: Magic.py 897 2005-09-22 09:32:46Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
8 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
8 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
9 #
9 #
10 # Distributed under the terms of the BSD License. The full license is in
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
11 # the file COPYING, distributed as part of this software.
12 #*****************************************************************************
12 #*****************************************************************************
13
13
14 #****************************************************************************
14 #****************************************************************************
15 # Modules and globals
15 # Modules and globals
16
16
17 from IPython import Release
17 from IPython import Release
18 __author__ = '%s <%s>\n%s <%s>' % \
18 __author__ = '%s <%s>\n%s <%s>' % \
19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
20 __license__ = Release.license
20 __license__ = Release.license
21
21
22 # Python standard modules
22 # Python standard modules
23 import __builtin__
23 import __builtin__
24 import os,sys,inspect,pydoc,re,tempfile,shlex,pdb,bdb,time
24 import os,sys,inspect,pydoc,re,tempfile,pdb,bdb,time
25 try:
25 try:
26 import profile,pstats
26 import profile,pstats
27 except ImportError:
27 except ImportError:
28 profile = pstats = None
28 profile = pstats = None
29 from getopt import getopt
29 from getopt import getopt
30 from pprint import pprint, pformat
30 from pprint import pprint, pformat
31 from cStringIO import StringIO
31 from cStringIO import StringIO
32
32
33 # Homebrewed
33 # Homebrewed
34 from IPython.Struct import Struct
34 from IPython.Struct import Struct
35 from IPython.Itpl import Itpl, itpl, printpl,itplns
35 from IPython.Itpl import Itpl, itpl, printpl,itplns
36 from IPython.FakeModule import FakeModule
36 from IPython.FakeModule import FakeModule
37 from IPython import OInspect
37 from IPython import OInspect
38 from IPython.genutils import *
38 from IPython.genutils import *
39
39
40 # Globals to be set later by Magic constructor
40 # Globals to be set later by Magic constructor
41 MAGIC_PREFIX = ''
41 MAGIC_PREFIX = ''
42 MAGIC_ESCAPE = ''
42 MAGIC_ESCAPE = ''
43
43
44 #***************************************************************************
44 #***************************************************************************
45 # Utility functions
45 # Utility functions
46 def magic2python(cmd):
46 def magic2python(cmd):
47 """Convert a command string of magic syntax to valid Python code."""
47 """Convert a command string of magic syntax to valid Python code."""
48
48
49 if cmd.startswith('#'+MAGIC_ESCAPE) or \
49 if cmd.startswith('#'+MAGIC_ESCAPE) or \
50 cmd.startswith(MAGIC_ESCAPE):
50 cmd.startswith(MAGIC_ESCAPE):
51 if cmd[0]=='#':
51 if cmd[0]=='#':
52 cmd = cmd[1:]
52 cmd = cmd[1:]
53 # we need to return the proper line end later
53 # we need to return the proper line end later
54 if cmd[-1] == '\n':
54 if cmd[-1] == '\n':
55 endl = '\n'
55 endl = '\n'
56 else:
56 else:
57 endl = ''
57 endl = ''
58 try:
58 try:
59 func,args = cmd[1:].split(' ',1)
59 func,args = cmd[1:].split(' ',1)
60 except:
60 except:
61 func,args = cmd[1:].rstrip(),''
61 func,args = cmd[1:].rstrip(),''
62 args = args.replace('"','\\"').replace("'","\\'").rstrip()
62 args = args.replace('"','\\"').replace("'","\\'").rstrip()
63 return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl)
63 return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl)
64 else:
64 else:
65 return cmd
65 return cmd
66
66
67 def on_off(tag):
67 def on_off(tag):
68 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
68 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
69 return ['OFF','ON'][tag]
69 return ['OFF','ON'][tag]
70
70
71 def get_py_filename(name):
71 def get_py_filename(name):
72 """Return a valid python filename in the current directory.
72 """Return a valid python filename in the current directory.
73
73
74 If the given name is not a file, it adds '.py' and searches again.
74 If the given name is not a file, it adds '.py' and searches again.
75 Raises IOError with an informative message if the file isn't found."""
75 Raises IOError with an informative message if the file isn't found."""
76
76
77 name = os.path.expanduser(name)
77 name = os.path.expanduser(name)
78 if not os.path.isfile(name) and not name.endswith('.py'):
78 if not os.path.isfile(name) and not name.endswith('.py'):
79 name += '.py'
79 name += '.py'
80 if os.path.isfile(name):
80 if os.path.isfile(name):
81 return name
81 return name
82 else:
82 else:
83 raise IOError,'File `%s` not found.' % name
83 raise IOError,'File `%s` not found.' % name
84
84
85 # Try to use shlex.split for converting an input string into a sys.argv-type
86 # list. This appeared in Python 2.3, so here's a quick backport for 2.2.
87 try:
88 shlex_split = shlex.split
89 except AttributeError:
90 _quotesre = re.compile(r'[\'"](.*)[\'"]')
91 _wordchars = ('abcdfeghijklmnopqrstuvwxyz'
92 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~*?'
93 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
94 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ%s'
95 % os.sep)
96
97 def shlex_split(s):
98 """Simplified backport to Python 2.2 of shlex.split().
99
100 This is a quick and dirty hack, since the shlex module under 2.2 lacks
101 several of the features needed to really match the functionality of
102 shlex.split() in 2.3."""
103
104 lex = shlex.shlex(StringIO(s))
105 # Try to get options, extensions and path separators as characters
106 lex.wordchars = _wordchars
107 lex.commenters = ''
108 # Make a list out of the lexer by hand, since in 2.2 it's not an
109 # iterator.
110 lout = []
111 while 1:
112 token = lex.get_token()
113 if token == '':
114 break
115 # Try to handle quoted tokens correctly
116 quotes = _quotesre.match(token)
117 if quotes:
118 token = quotes.group(1)
119 lout.append(token)
120 return lout
121
85
122 #****************************************************************************
86 #****************************************************************************
123 # Utility classes
87 # Utility classes
124 class Macro:
88 class Macro:
125 """Simple class to store the value of macros as strings.
89 """Simple class to store the value of macros as strings.
126
90
127 This allows us to later exec them by checking when something is an
91 This allows us to later exec them by checking when something is an
128 instance of this class."""
92 instance of this class."""
129
93
130 def __init__(self,cmds):
94 def __init__(self,cmds):
131 """Build a macro from a list of commands."""
95 """Build a macro from a list of commands."""
132
96
133 # Since the list may include multi-line entries, first make sure that
97 # Since the list may include multi-line entries, first make sure that
134 # they've been all broken up before passing it to magic2python
98 # they've been all broken up before passing it to magic2python
135 cmdlist = map(magic2python,''.join(cmds).split('\n'))
99 cmdlist = map(magic2python,''.join(cmds).split('\n'))
136 self.value = '\n'.join(cmdlist)
100 self.value = '\n'.join(cmdlist)
137
101
138 def __str__(self):
102 def __str__(self):
139 return self.value
103 return self.value
140
104
141 #***************************************************************************
105 #***************************************************************************
142 # Main class implementing Magic functionality
106 # Main class implementing Magic functionality
143 class Magic:
107 class Magic:
144 """Magic functions for InteractiveShell.
108 """Magic functions for InteractiveShell.
145
109
146 Shell functions which can be reached as %function_name. All magic
110 Shell functions which can be reached as %function_name. All magic
147 functions should accept a string, which they can parse for their own
111 functions should accept a string, which they can parse for their own
148 needs. This can make some functions easier to type, eg `%cd ../`
112 needs. This can make some functions easier to type, eg `%cd ../`
149 vs. `%cd("../")`
113 vs. `%cd("../")`
150
114
151 ALL definitions MUST begin with the prefix magic_. The user won't need it
115 ALL definitions MUST begin with the prefix magic_. The user won't need it
152 at the command line, but it is is needed in the definition. """
116 at the command line, but it is is needed in the definition. """
153
117
154 # class globals
118 # class globals
155 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
119 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
156 'Automagic is ON, % prefix NOT needed for magic functions.']
120 'Automagic is ON, % prefix NOT needed for magic functions.']
157
121
158 #......................................................................
122 #......................................................................
159 # some utility functions
123 # some utility functions
160
124
161 def __init__(self,shell):
125 def __init__(self,shell):
162 # XXX This is hackish, clean up later to avoid these messy globals
126 # XXX This is hackish, clean up later to avoid these messy globals
163 global MAGIC_PREFIX, MAGIC_ESCAPE
127 global MAGIC_PREFIX, MAGIC_ESCAPE
164
128
165 self.options_table = {}
129 self.options_table = {}
166 MAGIC_PREFIX = shell.name+'.magic_'
130 MAGIC_PREFIX = shell.name+'.magic_'
167 MAGIC_ESCAPE = shell.ESC_MAGIC
131 MAGIC_ESCAPE = shell.ESC_MAGIC
168 if profile is None:
132 if profile is None:
169 self.magic_prun = self.profile_missing_notice
133 self.magic_prun = self.profile_missing_notice
170
134
171 def profile_missing_notice(self, *args, **kwargs):
135 def profile_missing_notice(self, *args, **kwargs):
172 error("""\
136 error("""\
173 The profile module could not be found. If you are a Debian user,
137 The profile module could not be found. If you are a Debian user,
174 it has been removed from the standard Debian package because of its non-free
138 it has been removed from the standard Debian package because of its non-free
175 license. To use profiling, please install"python2.3-profiler" from non-free.""")
139 license. To use profiling, please install"python2.3-profiler" from non-free.""")
176
140
177 def default_option(self,fn,optstr):
141 def default_option(self,fn,optstr):
178 """Make an entry in the options_table for fn, with value optstr"""
142 """Make an entry in the options_table for fn, with value optstr"""
179
143
180 if fn not in self.lsmagic():
144 if fn not in self.lsmagic():
181 error("%s is not a magic function" % fn)
145 error("%s is not a magic function" % fn)
182 self.options_table[fn] = optstr
146 self.options_table[fn] = optstr
183
147
184 def lsmagic(self):
148 def lsmagic(self):
185 """Return a list of currently available magic functions.
149 """Return a list of currently available magic functions.
186
150
187 Gives a list of the bare names after mangling (['ls','cd', ...], not
151 Gives a list of the bare names after mangling (['ls','cd', ...], not
188 ['magic_ls','magic_cd',...]"""
152 ['magic_ls','magic_cd',...]"""
189
153
190 # FIXME. This needs a cleanup, in the way the magics list is built.
154 # FIXME. This needs a cleanup, in the way the magics list is built.
191
155
192 # magics in class definition
156 # magics in class definition
193 class_magic = lambda fn: fn.startswith('magic_') and \
157 class_magic = lambda fn: fn.startswith('magic_') and \
194 callable(Magic.__dict__[fn])
158 callable(Magic.__dict__[fn])
195 # in instance namespace (run-time user additions)
159 # in instance namespace (run-time user additions)
196 inst_magic = lambda fn: fn.startswith('magic_') and \
160 inst_magic = lambda fn: fn.startswith('magic_') and \
197 callable(self.__dict__[fn])
161 callable(self.__dict__[fn])
198 # and bound magics by user (so they can access self):
162 # and bound magics by user (so they can access self):
199 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
163 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
200 callable(self.__class__.__dict__[fn])
164 callable(self.__class__.__dict__[fn])
201 magics = filter(class_magic,Magic.__dict__.keys()) + \
165 magics = filter(class_magic,Magic.__dict__.keys()) + \
202 filter(inst_magic,self.__dict__.keys()) + \
166 filter(inst_magic,self.__dict__.keys()) + \
203 filter(inst_bound_magic,self.__class__.__dict__.keys())
167 filter(inst_bound_magic,self.__class__.__dict__.keys())
204 out = []
168 out = []
205 for fn in magics:
169 for fn in magics:
206 out.append(fn.replace('magic_','',1))
170 out.append(fn.replace('magic_','',1))
207 out.sort()
171 out.sort()
208 return out
172 return out
209
173
210 def set_shell(self,shell):
174 def set_shell(self,shell):
211 self.shell = shell
175 self.shell = shell
212 self.alias_table = shell.alias_table
176 self.alias_table = shell.alias_table
213
177
214 def extract_input_slices(self,slices):
178 def extract_input_slices(self,slices):
215 """Return as a string a set of input history slices.
179 """Return as a string a set of input history slices.
216
180
217 The set of slices is given as a list of strings (like ['1','4:8','9'],
181 The set of slices is given as a list of strings (like ['1','4:8','9'],
218 since this function is for use by magic functions which get their
182 since this function is for use by magic functions which get their
219 arguments as strings."""
183 arguments as strings."""
220
184
221 cmds = []
185 cmds = []
222 for chunk in slices:
186 for chunk in slices:
223 if ':' in chunk:
187 if ':' in chunk:
224 ini,fin = map(int,chunk.split(':'))
188 ini,fin = map(int,chunk.split(':'))
225 else:
189 else:
226 ini = int(chunk)
190 ini = int(chunk)
227 fin = ini+1
191 fin = ini+1
228 cmds.append(self.shell.input_hist[ini:fin])
192 cmds.append(self.shell.input_hist[ini:fin])
229 return cmds
193 return cmds
230
194
231 def _ofind(self,oname):
195 def _ofind(self,oname):
232 """Find an object in the available namespaces.
196 """Find an object in the available namespaces.
233
197
234 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
198 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
235
199
236 Has special code to detect magic functions.
200 Has special code to detect magic functions.
237 """
201 """
238
202
239 oname = oname.strip()
203 oname = oname.strip()
240
204
241 # Namespaces to search in:
205 # Namespaces to search in:
242 user_ns = self.shell.user_ns
206 user_ns = self.shell.user_ns
243 internal_ns = self.shell.internal_ns
207 internal_ns = self.shell.internal_ns
244 builtin_ns = __builtin__.__dict__
208 builtin_ns = __builtin__.__dict__
245 alias_ns = self.shell.alias_table
209 alias_ns = self.shell.alias_table
246
210
247 # Put them in a list. The order is important so that we find things in
211 # Put them in a list. The order is important so that we find things in
248 # the same order that Python finds them.
212 # the same order that Python finds them.
249 namespaces = [ ('Interactive',user_ns),
213 namespaces = [ ('Interactive',user_ns),
250 ('IPython internal',internal_ns),
214 ('IPython internal',internal_ns),
251 ('Python builtin',builtin_ns),
215 ('Python builtin',builtin_ns),
252 ('Alias',alias_ns),
216 ('Alias',alias_ns),
253 ]
217 ]
254
218
255 # initialize results to 'null'
219 # initialize results to 'null'
256 found = 0; obj = None; ospace = None; ds = None;
220 found = 0; obj = None; ospace = None; ds = None;
257 ismagic = 0; isalias = 0
221 ismagic = 0; isalias = 0
258
222
259 # Look for the given name by splitting it in parts. If the head is
223 # Look for the given name by splitting it in parts. If the head is
260 # found, then we look for all the remaining parts as members, and only
224 # found, then we look for all the remaining parts as members, and only
261 # declare success if we can find them all.
225 # declare success if we can find them all.
262 oname_parts = oname.split('.')
226 oname_parts = oname.split('.')
263 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
227 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
264 for nsname,ns in namespaces:
228 for nsname,ns in namespaces:
265 try:
229 try:
266 obj = ns[oname_head]
230 obj = ns[oname_head]
267 except KeyError:
231 except KeyError:
268 continue
232 continue
269 else:
233 else:
270 for part in oname_rest:
234 for part in oname_rest:
271 try:
235 try:
272 obj = getattr(obj,part)
236 obj = getattr(obj,part)
273 except:
237 except:
274 # Blanket except b/c some badly implemented objects
238 # Blanket except b/c some badly implemented objects
275 # allow __getattr__ to raise exceptions other than
239 # allow __getattr__ to raise exceptions other than
276 # AttributeError, which then crashes IPython.
240 # AttributeError, which then crashes IPython.
277 break
241 break
278 else:
242 else:
279 # If we finish the for loop (no break), we got all members
243 # If we finish the for loop (no break), we got all members
280 found = 1
244 found = 1
281 ospace = nsname
245 ospace = nsname
282 if ns == alias_ns:
246 if ns == alias_ns:
283 isalias = 1
247 isalias = 1
284 break # namespace loop
248 break # namespace loop
285
249
286 # Try to see if it's magic
250 # Try to see if it's magic
287 if not found:
251 if not found:
288 if oname.startswith(self.shell.ESC_MAGIC):
252 if oname.startswith(self.shell.ESC_MAGIC):
289 oname = oname[1:]
253 oname = oname[1:]
290 obj = getattr(self,'magic_'+oname,None)
254 obj = getattr(self,'magic_'+oname,None)
291 if obj is not None:
255 if obj is not None:
292 found = 1
256 found = 1
293 ospace = 'IPython internal'
257 ospace = 'IPython internal'
294 ismagic = 1
258 ismagic = 1
295
259
296 # Last try: special-case some literals like '', [], {}, etc:
260 # Last try: special-case some literals like '', [], {}, etc:
297 if not found and oname_head in ["''",'""','[]','{}','()']:
261 if not found and oname_head in ["''",'""','[]','{}','()']:
298 obj = eval(oname_head)
262 obj = eval(oname_head)
299 found = 1
263 found = 1
300 ospace = 'Interactive'
264 ospace = 'Interactive'
301
265
302 return {'found':found, 'obj':obj, 'namespace':ospace,
266 return {'found':found, 'obj':obj, 'namespace':ospace,
303 'ismagic':ismagic, 'isalias':isalias}
267 'ismagic':ismagic, 'isalias':isalias}
304
268
305 def arg_err(self,func):
269 def arg_err(self,func):
306 """Print docstring if incorrect arguments were passed"""
270 """Print docstring if incorrect arguments were passed"""
307 print 'Error in arguments:'
271 print 'Error in arguments:'
308 print OInspect.getdoc(func)
272 print OInspect.getdoc(func)
309
273
310
274
311 def format_latex(self,str):
275 def format_latex(self,str):
312 """Format a string for latex inclusion."""
276 """Format a string for latex inclusion."""
313
277
314 # Characters that need to be escaped for latex:
278 # Characters that need to be escaped for latex:
315 escape_re = re.compile(r'(%|_|\$)',re.MULTILINE)
279 escape_re = re.compile(r'(%|_|\$)',re.MULTILINE)
316 # Magic command names as headers:
280 # Magic command names as headers:
317 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
281 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
318 re.MULTILINE)
282 re.MULTILINE)
319 # Magic commands
283 # Magic commands
320 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
284 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
321 re.MULTILINE)
285 re.MULTILINE)
322 # Paragraph continue
286 # Paragraph continue
323 par_re = re.compile(r'\\$',re.MULTILINE)
287 par_re = re.compile(r'\\$',re.MULTILINE)
324
288
325 str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str)
289 str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str)
326 str = cmd_re.sub(r'\\texttt{\g<cmd>}',str)
290 str = cmd_re.sub(r'\\texttt{\g<cmd>}',str)
327 str = par_re.sub(r'\\\\',str)
291 str = par_re.sub(r'\\\\',str)
328 str = escape_re.sub(r'\\\1',str)
292 str = escape_re.sub(r'\\\1',str)
329 return str
293 return str
330
294
331 def format_screen(self,str):
295 def format_screen(self,str):
332 """Format a string for screen printing.
296 """Format a string for screen printing.
333
297
334 This removes some latex-type format codes."""
298 This removes some latex-type format codes."""
335 # Paragraph continue
299 # Paragraph continue
336 par_re = re.compile(r'\\$',re.MULTILINE)
300 par_re = re.compile(r'\\$',re.MULTILINE)
337 str = par_re.sub('',str)
301 str = par_re.sub('',str)
338 return str
302 return str
339
303
340 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
304 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
341 """Parse options passed to an argument string.
305 """Parse options passed to an argument string.
342
306
343 The interface is similar to that of getopt(), but it returns back a
307 The interface is similar to that of getopt(), but it returns back a
344 Struct with the options as keys and the stripped argument string still
308 Struct with the options as keys and the stripped argument string still
345 as a string.
309 as a string.
346
310
347 arg_str is quoted as a true sys.argv vector by calling on the fly a
311 arg_str is quoted as a true sys.argv vector by calling on the fly a
348 python process in a subshell. This allows us to easily expand
312 python process in a subshell. This allows us to easily expand
349 variables, glob files, quote arguments, etc, with all the power and
313 variables, glob files, quote arguments, etc, with all the power and
350 correctness of the underlying system shell.
314 correctness of the underlying system shell.
351
315
352 Options:
316 Options:
353 -mode: default 'string'. If given as 'list', the argument string is
317 -mode: default 'string'. If given as 'list', the argument string is
354 returned as a list (split on whitespace) instead of a string.
318 returned as a list (split on whitespace) instead of a string.
355
319
356 -list_all: put all option values in lists. Normally only options
320 -list_all: put all option values in lists. Normally only options
357 appearing more than once are put in a list."""
321 appearing more than once are put in a list."""
358
322
359 # inject default options at the beginning of the input line
323 # inject default options at the beginning of the input line
360 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
324 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
361 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
325 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
362
326
363 mode = kw.get('mode','string')
327 mode = kw.get('mode','string')
364 if mode not in ['string','list']:
328 if mode not in ['string','list']:
365 raise ValueError,'incorrect mode given: %s' % mode
329 raise ValueError,'incorrect mode given: %s' % mode
366 # Get options
330 # Get options
367 list_all = kw.get('list_all',0)
331 list_all = kw.get('list_all',0)
368
332
369 # Check if we have more than one argument to warrant extra processing:
333 # Check if we have more than one argument to warrant extra processing:
370 odict = {} # Dictionary with options
334 odict = {} # Dictionary with options
371 args = arg_str.split()
335 args = arg_str.split()
372 if len(args) >= 1:
336 if len(args) >= 1:
373 # If the list of inputs only has 0 or 1 thing in it, there's no
337 # If the list of inputs only has 0 or 1 thing in it, there's no
374 # need to look for options
338 # need to look for options
375 argv = shlex_split(arg_str)
339 argv = shlex_split(arg_str)
376 # Do regular option processing
340 # Do regular option processing
377 opts,args = getopt(argv,opt_str,*long_opts)
341 opts,args = getopt(argv,opt_str,*long_opts)
378 for o,a in opts:
342 for o,a in opts:
379 if o.startswith('--'):
343 if o.startswith('--'):
380 o = o[2:]
344 o = o[2:]
381 else:
345 else:
382 o = o[1:]
346 o = o[1:]
383 try:
347 try:
384 odict[o].append(a)
348 odict[o].append(a)
385 except AttributeError:
349 except AttributeError:
386 odict[o] = [odict[o],a]
350 odict[o] = [odict[o],a]
387 except KeyError:
351 except KeyError:
388 if list_all:
352 if list_all:
389 odict[o] = [a]
353 odict[o] = [a]
390 else:
354 else:
391 odict[o] = a
355 odict[o] = a
392
356
393 # Prepare opts,args for return
357 # Prepare opts,args for return
394 opts = Struct(odict)
358 opts = Struct(odict)
395 if mode == 'string':
359 if mode == 'string':
396 args = ' '.join(args)
360 args = ' '.join(args)
397
361
398 return opts,args
362 return opts,args
399
363
400 #......................................................................
364 #......................................................................
401 # And now the actual magic functions
365 # And now the actual magic functions
402
366
403 # Functions for IPython shell work (vars,funcs, config, etc)
367 # Functions for IPython shell work (vars,funcs, config, etc)
404 def magic_lsmagic(self, parameter_s = ''):
368 def magic_lsmagic(self, parameter_s = ''):
405 """List currently available magic functions."""
369 """List currently available magic functions."""
406 mesc = self.shell.ESC_MAGIC
370 mesc = self.shell.ESC_MAGIC
407 print 'Available magic functions:\n'+mesc+\
371 print 'Available magic functions:\n'+mesc+\
408 (' '+mesc).join(self.lsmagic())
372 (' '+mesc).join(self.lsmagic())
409 print '\n' + Magic.auto_status[self.shell.rc.automagic]
373 print '\n' + Magic.auto_status[self.shell.rc.automagic]
410 return None
374 return None
411
375
412 def magic_magic(self, parameter_s = ''):
376 def magic_magic(self, parameter_s = ''):
413 """Print information about the magic function system."""
377 """Print information about the magic function system."""
414
378
415 mode = ''
379 mode = ''
416 try:
380 try:
417 if parameter_s.split()[0] == '-latex':
381 if parameter_s.split()[0] == '-latex':
418 mode = 'latex'
382 mode = 'latex'
419 except:
383 except:
420 pass
384 pass
421
385
422 magic_docs = []
386 magic_docs = []
423 for fname in self.lsmagic():
387 for fname in self.lsmagic():
424 mname = 'magic_' + fname
388 mname = 'magic_' + fname
425 for space in (Magic,self,self.__class__):
389 for space in (Magic,self,self.__class__):
426 try:
390 try:
427 fn = space.__dict__[mname]
391 fn = space.__dict__[mname]
428 except KeyError:
392 except KeyError:
429 pass
393 pass
430 else:
394 else:
431 break
395 break
432 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
396 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
433 fname,fn.__doc__))
397 fname,fn.__doc__))
434 magic_docs = ''.join(magic_docs)
398 magic_docs = ''.join(magic_docs)
435
399
436 if mode == 'latex':
400 if mode == 'latex':
437 print self.format_latex(magic_docs)
401 print self.format_latex(magic_docs)
438 return
402 return
439 else:
403 else:
440 magic_docs = self.format_screen(magic_docs)
404 magic_docs = self.format_screen(magic_docs)
441
405
442 outmsg = """
406 outmsg = """
443 IPython's 'magic' functions
407 IPython's 'magic' functions
444 ===========================
408 ===========================
445
409
446 The magic function system provides a series of functions which allow you to
410 The magic function system provides a series of functions which allow you to
447 control the behavior of IPython itself, plus a lot of system-type
411 control the behavior of IPython itself, plus a lot of system-type
448 features. All these functions are prefixed with a % character, but parameters
412 features. All these functions are prefixed with a % character, but parameters
449 are given without parentheses or quotes.
413 are given without parentheses or quotes.
450
414
451 NOTE: If you have 'automagic' enabled (via the command line option or with the
415 NOTE: If you have 'automagic' enabled (via the command line option or with the
452 %automagic function), you don't need to type in the % explicitly. By default,
416 %automagic function), you don't need to type in the % explicitly. By default,
453 IPython ships with automagic on, so you should only rarely need the % escape.
417 IPython ships with automagic on, so you should only rarely need the % escape.
454
418
455 Example: typing '%cd mydir' (without the quotes) changes you working directory
419 Example: typing '%cd mydir' (without the quotes) changes you working directory
456 to 'mydir', if it exists.
420 to 'mydir', if it exists.
457
421
458 You can define your own magic functions to extend the system. See the supplied
422 You can define your own magic functions to extend the system. See the supplied
459 ipythonrc and example-magic.py files for details (in your ipython
423 ipythonrc and example-magic.py files for details (in your ipython
460 configuration directory, typically $HOME/.ipython/).
424 configuration directory, typically $HOME/.ipython/).
461
425
462 You can also define your own aliased names for magic functions. In your
426 You can also define your own aliased names for magic functions. In your
463 ipythonrc file, placing a line like:
427 ipythonrc file, placing a line like:
464
428
465 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
429 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
466
430
467 will define %pf as a new name for %profile.
431 will define %pf as a new name for %profile.
468
432
469 You can also call magics in code using the ipmagic() function, which IPython
433 You can also call magics in code using the ipmagic() function, which IPython
470 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
434 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
471
435
472 For a list of the available magic functions, use %lsmagic. For a description
436 For a list of the available magic functions, use %lsmagic. For a description
473 of any of them, type %magic_name?, e.g. '%cd?'.
437 of any of them, type %magic_name?, e.g. '%cd?'.
474
438
475 Currently the magic system has the following functions:\n"""
439 Currently the magic system has the following functions:\n"""
476
440
477 mesc = self.shell.ESC_MAGIC
441 mesc = self.shell.ESC_MAGIC
478 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
442 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
479 "\n\n%s%s\n\n%s" % (outmsg,
443 "\n\n%s%s\n\n%s" % (outmsg,
480 magic_docs,mesc,mesc,
444 magic_docs,mesc,mesc,
481 (' '+mesc).join(self.lsmagic()),
445 (' '+mesc).join(self.lsmagic()),
482 Magic.auto_status[self.shell.rc.automagic] ) )
446 Magic.auto_status[self.shell.rc.automagic] ) )
483
447
484 page(outmsg,screen_lines=self.shell.rc.screen_length)
448 page(outmsg,screen_lines=self.shell.rc.screen_length)
485
449
486 def magic_automagic(self, parameter_s = ''):
450 def magic_automagic(self, parameter_s = ''):
487 """Make magic functions callable without having to type the initial %.
451 """Make magic functions callable without having to type the initial %.
488
452
489 Toggles on/off (when off, you must call it as %automagic, of
453 Toggles on/off (when off, you must call it as %automagic, of
490 course). Note that magic functions have lowest priority, so if there's
454 course). Note that magic functions have lowest priority, so if there's
491 a variable whose name collides with that of a magic fn, automagic
455 a variable whose name collides with that of a magic fn, automagic
492 won't work for that function (you get the variable instead). However,
456 won't work for that function (you get the variable instead). However,
493 if you delete the variable (del var), the previously shadowed magic
457 if you delete the variable (del var), the previously shadowed magic
494 function becomes visible to automagic again."""
458 function becomes visible to automagic again."""
495
459
496 rc = self.shell.rc
460 rc = self.shell.rc
497 rc.automagic = not rc.automagic
461 rc.automagic = not rc.automagic
498 print '\n' + Magic.auto_status[rc.automagic]
462 print '\n' + Magic.auto_status[rc.automagic]
499
463
500 def magic_autocall(self, parameter_s = ''):
464 def magic_autocall(self, parameter_s = ''):
501 """Make functions callable without having to type parentheses.
465 """Make functions callable without having to type parentheses.
502
466
503 This toggles the autocall command line option on and off."""
467 This toggles the autocall command line option on and off."""
504
468
505 rc = self.shell.rc
469 rc = self.shell.rc
506 rc.autocall = not rc.autocall
470 rc.autocall = not rc.autocall
507 print "Automatic calling is:",['OFF','ON'][rc.autocall]
471 print "Automatic calling is:",['OFF','ON'][rc.autocall]
508
472
509 def magic_autoindent(self, parameter_s = ''):
473 def magic_autoindent(self, parameter_s = ''):
510 """Toggle autoindent on/off (if available)."""
474 """Toggle autoindent on/off (if available)."""
511
475
512 self.shell.set_autoindent()
476 self.shell.set_autoindent()
513 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
477 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
514
478
515 def magic_system_verbose(self, parameter_s = ''):
479 def magic_system_verbose(self, parameter_s = ''):
516 """Toggle verbose printing of system calls on/off."""
480 """Toggle verbose printing of system calls on/off."""
517
481
518 self.shell.rc_set_toggle('system_verbose')
482 self.shell.rc_set_toggle('system_verbose')
519 print "System verbose printing is:",\
483 print "System verbose printing is:",\
520 ['OFF','ON'][self.shell.rc.system_verbose]
484 ['OFF','ON'][self.shell.rc.system_verbose]
521
485
522 def magic_history(self, parameter_s = ''):
486 def magic_history(self, parameter_s = ''):
523 """Print input history (_i<n> variables), with most recent last.
487 """Print input history (_i<n> variables), with most recent last.
524
488
525 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
489 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
526 %history [-n] n -> print at most n inputs\\
490 %history [-n] n -> print at most n inputs\\
527 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
491 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
528
492
529 Each input's number <n> is shown, and is accessible as the
493 Each input's number <n> is shown, and is accessible as the
530 automatically generated variable _i<n>. Multi-line statements are
494 automatically generated variable _i<n>. Multi-line statements are
531 printed starting at a new line for easy copy/paste.
495 printed starting at a new line for easy copy/paste.
532
496
533 If option -n is used, input numbers are not printed. This is useful if
497 If option -n is used, input numbers are not printed. This is useful if
534 you want to get a printout of many lines which can be directly pasted
498 you want to get a printout of many lines which can be directly pasted
535 into a text editor.
499 into a text editor.
536
500
537 This feature is only available if numbered prompts are in use."""
501 This feature is only available if numbered prompts are in use."""
538
502
539 if not self.do_full_cache:
503 if not self.do_full_cache:
540 print 'This feature is only available if numbered prompts are in use.'
504 print 'This feature is only available if numbered prompts are in use.'
541 return
505 return
542 opts,args = self.parse_options(parameter_s,'n',mode='list')
506 opts,args = self.parse_options(parameter_s,'n',mode='list')
543
507
544 default_length = 40
508 default_length = 40
545 if len(args) == 0:
509 if len(args) == 0:
546 final = self.outputcache.prompt_count
510 final = self.outputcache.prompt_count
547 init = max(1,final-default_length)
511 init = max(1,final-default_length)
548 elif len(args) == 1:
512 elif len(args) == 1:
549 final = self.outputcache.prompt_count
513 final = self.outputcache.prompt_count
550 init = max(1,final-int(args[0]))
514 init = max(1,final-int(args[0]))
551 elif len(args) == 2:
515 elif len(args) == 2:
552 init,final = map(int,args)
516 init,final = map(int,args)
553 else:
517 else:
554 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
518 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
555 print self.magic_hist.__doc__
519 print self.magic_hist.__doc__
556 return
520 return
557 width = len(str(final))
521 width = len(str(final))
558 line_sep = ['','\n']
522 line_sep = ['','\n']
559 input_hist = self.shell.input_hist
523 input_hist = self.shell.input_hist
560 print_nums = not opts.has_key('n')
524 print_nums = not opts.has_key('n')
561 for in_num in range(init,final):
525 for in_num in range(init,final):
562 inline = input_hist[in_num]
526 inline = input_hist[in_num]
563 multiline = inline.count('\n') > 1
527 multiline = inline.count('\n') > 1
564 if print_nums:
528 if print_nums:
565 print str(in_num).ljust(width)+':'+ line_sep[multiline],
529 print str(in_num).ljust(width)+':'+ line_sep[multiline],
566 if inline.startswith('#'+self.shell.ESC_MAGIC) or \
530 if inline.startswith('#'+self.shell.ESC_MAGIC) or \
567 inline.startswith('#!'):
531 inline.startswith('#!'):
568 print inline[1:],
532 print inline[1:],
569 else:
533 else:
570 print inline,
534 print inline,
571
535
572 def magic_hist(self, parameter_s=''):
536 def magic_hist(self, parameter_s=''):
573 """Alternate name for %history."""
537 """Alternate name for %history."""
574 return self.magic_history(parameter_s)
538 return self.magic_history(parameter_s)
575
539
576 def magic_p(self, parameter_s=''):
540 def magic_p(self, parameter_s=''):
577 """Just a short alias for Python's 'print'."""
541 """Just a short alias for Python's 'print'."""
578 exec 'print ' + parameter_s in self.shell.user_ns
542 exec 'print ' + parameter_s in self.shell.user_ns
579
543
580 def magic_r(self, parameter_s=''):
544 def magic_r(self, parameter_s=''):
581 """Repeat previous input.
545 """Repeat previous input.
582
546
583 If given an argument, repeats the previous command which starts with
547 If given an argument, repeats the previous command which starts with
584 the same string, otherwise it just repeats the previous input.
548 the same string, otherwise it just repeats the previous input.
585
549
586 Shell escaped commands (with ! as first character) are not recognized
550 Shell escaped commands (with ! as first character) are not recognized
587 by this system, only pure python code and magic commands.
551 by this system, only pure python code and magic commands.
588 """
552 """
589
553
590 start = parameter_s.strip()
554 start = parameter_s.strip()
591 esc_magic = self.shell.ESC_MAGIC
555 esc_magic = self.shell.ESC_MAGIC
592 # Identify magic commands even if automagic is on (which means
556 # Identify magic commands even if automagic is on (which means
593 # the in-memory version is different from that typed by the user).
557 # the in-memory version is different from that typed by the user).
594 if self.shell.rc.automagic:
558 if self.shell.rc.automagic:
595 start_magic = esc_magic+start
559 start_magic = esc_magic+start
596 else:
560 else:
597 start_magic = start
561 start_magic = start
598 # Look through the input history in reverse
562 # Look through the input history in reverse
599 for n in range(len(self.shell.input_hist)-2,0,-1):
563 for n in range(len(self.shell.input_hist)-2,0,-1):
600 input = self.shell.input_hist[n]
564 input = self.shell.input_hist[n]
601 # skip plain 'r' lines so we don't recurse to infinity
565 # skip plain 'r' lines so we don't recurse to infinity
602 if input != 'ipmagic("r")\n' and \
566 if input != 'ipmagic("r")\n' and \
603 (input.startswith(start) or input.startswith(start_magic)):
567 (input.startswith(start) or input.startswith(start_magic)):
604 #print 'match',`input` # dbg
568 #print 'match',`input` # dbg
605 if input.startswith(esc_magic):
569 if input.startswith(esc_magic):
606 input = magic2python(input)
570 input = magic2python(input)
607 #print 'modified',`input` # dbg
571 #print 'modified',`input` # dbg
608 print 'Executing:',input,
572 print 'Executing:',input,
609 exec input in self.shell.user_ns
573 exec input in self.shell.user_ns
610 return
574 return
611 print 'No previous input matching `%s` found.' % start
575 print 'No previous input matching `%s` found.' % start
612
576
613 def magic_page(self, parameter_s=''):
577 def magic_page(self, parameter_s=''):
614 """Pretty print the object and display it through a pager.
578 """Pretty print the object and display it through a pager.
615
579
616 If no parameter is given, use _ (last output)."""
580 If no parameter is given, use _ (last output)."""
617 # After a function contributed by Olivier Aubert, slightly modified.
581 # After a function contributed by Olivier Aubert, slightly modified.
618
582
619 oname = parameter_s and parameter_s or '_'
583 oname = parameter_s and parameter_s or '_'
620 info = self._ofind(oname)
584 info = self._ofind(oname)
621 if info['found']:
585 if info['found']:
622 page(pformat(info['obj']))
586 page(pformat(info['obj']))
623 else:
587 else:
624 print 'Object `%s` not found' % oname
588 print 'Object `%s` not found' % oname
625
589
626 def magic_profile(self, parameter_s=''):
590 def magic_profile(self, parameter_s=''):
627 """Print your currently active IPyhton profile."""
591 """Print your currently active IPyhton profile."""
628 if self.shell.rc.profile:
592 if self.shell.rc.profile:
629 printpl('Current IPython profile: $self.shell.rc.profile.')
593 printpl('Current IPython profile: $self.shell.rc.profile.')
630 else:
594 else:
631 print 'No profile active.'
595 print 'No profile active.'
632
596
633 def _inspect(self,meth,oname,**kw):
597 def _inspect(self,meth,oname,**kw):
634 """Generic interface to the inspector system.
598 """Generic interface to the inspector system.
635
599
636 This function is meant to be called by pdef, pdoc & friends."""
600 This function is meant to be called by pdef, pdoc & friends."""
637
601
638 oname = oname.strip()
602 oname = oname.strip()
639 info = Struct(self._ofind(oname))
603 info = Struct(self._ofind(oname))
640 if info.found:
604 if info.found:
641 pmethod = getattr(self.shell.inspector,meth)
605 pmethod = getattr(self.shell.inspector,meth)
642 formatter = info.ismagic and self.format_screen or None
606 formatter = info.ismagic and self.format_screen or None
643 if meth == 'pdoc':
607 if meth == 'pdoc':
644 pmethod(info.obj,oname,formatter)
608 pmethod(info.obj,oname,formatter)
645 elif meth == 'pinfo':
609 elif meth == 'pinfo':
646 pmethod(info.obj,oname,formatter,info,**kw)
610 pmethod(info.obj,oname,formatter,info,**kw)
647 else:
611 else:
648 pmethod(info.obj,oname)
612 pmethod(info.obj,oname)
649 else:
613 else:
650 print 'Object `%s` not found.' % oname
614 print 'Object `%s` not found.' % oname
651 return 'not found' # so callers can take other action
615 return 'not found' # so callers can take other action
652
616
653 def magic_pdef(self, parameter_s=''):
617 def magic_pdef(self, parameter_s=''):
654 """Print the definition header for any callable object.
618 """Print the definition header for any callable object.
655
619
656 If the object is a class, print the constructor information."""
620 If the object is a class, print the constructor information."""
657 self._inspect('pdef',parameter_s)
621 self._inspect('pdef',parameter_s)
658
622
659 def magic_pdoc(self, parameter_s=''):
623 def magic_pdoc(self, parameter_s=''):
660 """Print the docstring for an object.
624 """Print the docstring for an object.
661
625
662 If the given object is a class, it will print both the class and the
626 If the given object is a class, it will print both the class and the
663 constructor docstrings."""
627 constructor docstrings."""
664 self._inspect('pdoc',parameter_s)
628 self._inspect('pdoc',parameter_s)
665
629
666 def magic_psource(self, parameter_s=''):
630 def magic_psource(self, parameter_s=''):
667 """Print (or run through pager) the source code for an object."""
631 """Print (or run through pager) the source code for an object."""
668 self._inspect('psource',parameter_s)
632 self._inspect('psource',parameter_s)
669
633
670 def magic_pfile(self, parameter_s=''):
634 def magic_pfile(self, parameter_s=''):
671 """Print (or run through pager) the file where an object is defined.
635 """Print (or run through pager) the file where an object is defined.
672
636
673 The file opens at the line where the object definition begins. IPython
637 The file opens at the line where the object definition begins. IPython
674 will honor the environment variable PAGER if set, and otherwise will
638 will honor the environment variable PAGER if set, and otherwise will
675 do its best to print the file in a convenient form.
639 do its best to print the file in a convenient form.
676
640
677 If the given argument is not an object currently defined, IPython will
641 If the given argument is not an object currently defined, IPython will
678 try to interpret it as a filename (automatically adding a .py extension
642 try to interpret it as a filename (automatically adding a .py extension
679 if needed). You can thus use %pfile as a syntax highlighting code
643 if needed). You can thus use %pfile as a syntax highlighting code
680 viewer."""
644 viewer."""
681
645
682 # first interpret argument as an object name
646 # first interpret argument as an object name
683 out = self._inspect('pfile',parameter_s)
647 out = self._inspect('pfile',parameter_s)
684 # if not, try the input as a filename
648 # if not, try the input as a filename
685 if out == 'not found':
649 if out == 'not found':
686 try:
650 try:
687 filename = get_py_filename(parameter_s)
651 filename = get_py_filename(parameter_s)
688 except IOError,msg:
652 except IOError,msg:
689 print msg
653 print msg
690 return
654 return
691 page(self.shell.inspector.format(file(filename).read()))
655 page(self.shell.inspector.format(file(filename).read()))
692
656
693 def magic_pinfo(self, parameter_s=''):
657 def magic_pinfo(self, parameter_s=''):
694 """Provide detailed information about an object.
658 """Provide detailed information about an object.
695
659
696 '%pinfo object' is just a synonym for object? or ?object."""
660 '%pinfo object' is just a synonym for object? or ?object."""
697
661
698 #print 'pinfo par: <%s>' % parameter_s # dbg
662 #print 'pinfo par: <%s>' % parameter_s # dbg
699
663
700 # detail_level: 0 -> obj? , 1 -> obj??
664 # detail_level: 0 -> obj? , 1 -> obj??
701 detail_level = 0
665 detail_level = 0
702 # We need to detect if we got called as 'pinfo pinfo foo', which can
666 # We need to detect if we got called as 'pinfo pinfo foo', which can
703 # happen if the user types 'pinfo foo?' at the cmd line.
667 # happen if the user types 'pinfo foo?' at the cmd line.
704 pinfo,qmark1,oname,qmark2 = \
668 pinfo,qmark1,oname,qmark2 = \
705 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
669 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
706 if pinfo or qmark1 or qmark2:
670 if pinfo or qmark1 or qmark2:
707 detail_level = 1
671 detail_level = 1
708 self._inspect('pinfo',oname,detail_level=detail_level)
672 self._inspect('pinfo',oname,detail_level=detail_level)
709
673
710 def magic_who_ls(self, parameter_s=''):
674 def magic_who_ls(self, parameter_s=''):
711 """Return a sorted list of all interactive variables.
675 """Return a sorted list of all interactive variables.
712
676
713 If arguments are given, only variables of types matching these
677 If arguments are given, only variables of types matching these
714 arguments are returned."""
678 arguments are returned."""
715
679
716 user_ns = self.shell.user_ns
680 user_ns = self.shell.user_ns
717 out = []
681 out = []
718 typelist = parameter_s.split()
682 typelist = parameter_s.split()
719 for i in self.shell.user_ns.keys():
683 for i in self.shell.user_ns.keys():
720 if not (i.startswith('_') or i.startswith('_i')) \
684 if not (i.startswith('_') or i.startswith('_i')) \
721 and not (self.internal_ns.has_key(i) or
685 and not (self.internal_ns.has_key(i) or
722 self.user_config_ns.has_key(i)):
686 self.user_config_ns.has_key(i)):
723 if typelist:
687 if typelist:
724 if type(user_ns[i]).__name__ in typelist:
688 if type(user_ns[i]).__name__ in typelist:
725 out.append(i)
689 out.append(i)
726 else:
690 else:
727 out.append(i)
691 out.append(i)
728 out.sort()
692 out.sort()
729 return out
693 return out
730
694
731 def magic_who(self, parameter_s=''):
695 def magic_who(self, parameter_s=''):
732 """Print all interactive variables, with some minimal formatting.
696 """Print all interactive variables, with some minimal formatting.
733
697
734 If any arguments are given, only variables whose type matches one of
698 If any arguments are given, only variables whose type matches one of
735 these are printed. For example:
699 these are printed. For example:
736
700
737 %who function str
701 %who function str
738
702
739 will only list functions and strings, excluding all other types of
703 will only list functions and strings, excluding all other types of
740 variables. To find the proper type names, simply use type(var) at a
704 variables. To find the proper type names, simply use type(var) at a
741 command line to see how python prints type names. For example:
705 command line to see how python prints type names. For example:
742
706
743 In [1]: type('hello')\\
707 In [1]: type('hello')\\
744 Out[1]: <type 'str'>
708 Out[1]: <type 'str'>
745
709
746 indicates that the type name for strings is 'str'.
710 indicates that the type name for strings is 'str'.
747
711
748 %who always excludes executed names loaded through your configuration
712 %who always excludes executed names loaded through your configuration
749 file and things which are internal to IPython.
713 file and things which are internal to IPython.
750
714
751 This is deliberate, as typically you may load many modules and the
715 This is deliberate, as typically you may load many modules and the
752 purpose of %who is to show you only what you've manually defined."""
716 purpose of %who is to show you only what you've manually defined."""
753
717
754 varlist = self.magic_who_ls(parameter_s)
718 varlist = self.magic_who_ls(parameter_s)
755 if not varlist:
719 if not varlist:
756 print 'Interactive namespace is empty.'
720 print 'Interactive namespace is empty.'
757 return
721 return
758
722
759 # if we have variables, move on...
723 # if we have variables, move on...
760
724
761 # stupid flushing problem: when prompts have no separators, stdout is
725 # stupid flushing problem: when prompts have no separators, stdout is
762 # getting lost. I'm starting to think this is a python bug. I'm having
726 # getting lost. I'm starting to think this is a python bug. I'm having
763 # to force a flush with a print because even a sys.stdout.flush
727 # to force a flush with a print because even a sys.stdout.flush
764 # doesn't seem to do anything!
728 # doesn't seem to do anything!
765
729
766 count = 0
730 count = 0
767 for i in varlist:
731 for i in varlist:
768 print i+'\t',
732 print i+'\t',
769 count += 1
733 count += 1
770 if count > 8:
734 if count > 8:
771 count = 0
735 count = 0
772 print
736 print
773 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
737 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
774
738
775 print # well, this does force a flush at the expense of an extra \n
739 print # well, this does force a flush at the expense of an extra \n
776
740
777 def magic_whos(self, parameter_s=''):
741 def magic_whos(self, parameter_s=''):
778 """Like %who, but gives some extra information about each variable.
742 """Like %who, but gives some extra information about each variable.
779
743
780 The same type filtering of %who can be applied here.
744 The same type filtering of %who can be applied here.
781
745
782 For all variables, the type is printed. Additionally it prints:
746 For all variables, the type is printed. Additionally it prints:
783
747
784 - For {},[],(): their length.
748 - For {},[],(): their length.
785
749
786 - For Numeric arrays, a summary with shape, number of elements,
750 - For Numeric arrays, a summary with shape, number of elements,
787 typecode and size in memory.
751 typecode and size in memory.
788
752
789 - Everything else: a string representation, snipping their middle if
753 - Everything else: a string representation, snipping their middle if
790 too long."""
754 too long."""
791
755
792 varnames = self.magic_who_ls(parameter_s)
756 varnames = self.magic_who_ls(parameter_s)
793 if not varnames:
757 if not varnames:
794 print 'Interactive namespace is empty.'
758 print 'Interactive namespace is empty.'
795 return
759 return
796
760
797 # if we have variables, move on...
761 # if we have variables, move on...
798
762
799 # for these types, show len() instead of data:
763 # for these types, show len() instead of data:
800 seq_types = [types.DictType,types.ListType,types.TupleType]
764 seq_types = [types.DictType,types.ListType,types.TupleType]
801
765
802 # for Numeric arrays, display summary info
766 # for Numeric arrays, display summary info
803 try:
767 try:
804 import Numeric
768 import Numeric
805 except ImportError:
769 except ImportError:
806 array_type = None
770 array_type = None
807 else:
771 else:
808 array_type = Numeric.ArrayType.__name__
772 array_type = Numeric.ArrayType.__name__
809
773
810 # Find all variable names and types so we can figure out column sizes
774 # Find all variable names and types so we can figure out column sizes
811 get_vars = lambda i: self.locals[i]
775 get_vars = lambda i: self.locals[i]
812 type_name = lambda v: type(v).__name__
776 type_name = lambda v: type(v).__name__
813 varlist = map(get_vars,varnames)
777 varlist = map(get_vars,varnames)
814 typelist = map(type_name,varlist)
778 typelist = map(type_name,varlist)
815 # column labels and # of spaces as separator
779 # column labels and # of spaces as separator
816 varlabel = 'Variable'
780 varlabel = 'Variable'
817 typelabel = 'Type'
781 typelabel = 'Type'
818 datalabel = 'Data/Info'
782 datalabel = 'Data/Info'
819 colsep = 3
783 colsep = 3
820 # variable format strings
784 # variable format strings
821 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
785 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
822 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
786 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
823 aformat = "%s: %s elems, type `%s`, %s bytes"
787 aformat = "%s: %s elems, type `%s`, %s bytes"
824 # find the size of the columns to format the output nicely
788 # find the size of the columns to format the output nicely
825 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
789 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
826 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
790 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
827 # table header
791 # table header
828 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
792 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
829 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
793 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
830 # and the table itself
794 # and the table itself
831 kb = 1024
795 kb = 1024
832 Mb = 1048576 # kb**2
796 Mb = 1048576 # kb**2
833 for vname,var,vtype in zip(varnames,varlist,typelist):
797 for vname,var,vtype in zip(varnames,varlist,typelist):
834 print itpl(vformat),
798 print itpl(vformat),
835 if vtype in seq_types:
799 if vtype in seq_types:
836 print len(var)
800 print len(var)
837 elif vtype==array_type:
801 elif vtype==array_type:
838 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
802 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
839 vsize = Numeric.size(var)
803 vsize = Numeric.size(var)
840 vbytes = vsize*var.itemsize()
804 vbytes = vsize*var.itemsize()
841 if vbytes < 100000:
805 if vbytes < 100000:
842 print aformat % (vshape,vsize,var.typecode(),vbytes)
806 print aformat % (vshape,vsize,var.typecode(),vbytes)
843 else:
807 else:
844 print aformat % (vshape,vsize,var.typecode(),vbytes),
808 print aformat % (vshape,vsize,var.typecode(),vbytes),
845 if vbytes < Mb:
809 if vbytes < Mb:
846 print '(%s kb)' % (vbytes/kb,)
810 print '(%s kb)' % (vbytes/kb,)
847 else:
811 else:
848 print '(%s Mb)' % (vbytes/Mb,)
812 print '(%s Mb)' % (vbytes/Mb,)
849 else:
813 else:
850 vstr = str(var)
814 vstr = str(var)
851 if len(vstr) < 50:
815 if len(vstr) < 50:
852 print vstr
816 print vstr
853 else:
817 else:
854 printpl(vfmt_short)
818 printpl(vfmt_short)
855
819
856 def magic_reset(self, parameter_s=''):
820 def magic_reset(self, parameter_s=''):
857 """Resets the namespace by removing all names defined by the user.
821 """Resets the namespace by removing all names defined by the user.
858
822
859 Input/Output history are left around in case you need them."""
823 Input/Output history are left around in case you need them."""
860
824
861 ans = raw_input(
825 ans = raw_input(
862 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
826 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
863 if not ans.lower() == 'y':
827 if not ans.lower() == 'y':
864 print 'Nothing done.'
828 print 'Nothing done.'
865 return
829 return
866 for i in self.magic_who_ls():
830 for i in self.magic_who_ls():
867 del(self.locals[i])
831 del(self.locals[i])
868
832
869 def magic_config(self,parameter_s=''):
833 def magic_config(self,parameter_s=''):
870 """Show IPython's internal configuration."""
834 """Show IPython's internal configuration."""
871
835
872 page('Current configuration structure:\n'+
836 page('Current configuration structure:\n'+
873 pformat(self.shell.rc.dict()))
837 pformat(self.shell.rc.dict()))
874
838
875 def magic_logstart(self,parameter_s=''):
839 def magic_logstart(self,parameter_s=''):
876 """Start logging anywhere in a session.
840 """Start logging anywhere in a session.
877
841
878 %logstart [log_name [log_mode]]
842 %logstart [log_name [log_mode]]
879
843
880 If no name is given, it defaults to a file named 'ipython.log' in your
844 If no name is given, it defaults to a file named 'ipython.log' in your
881 current directory, in 'rotate' mode (see below).
845 current directory, in 'rotate' mode (see below).
882
846
883 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
847 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
884 history up to that point and then continues logging.
848 history up to that point and then continues logging.
885
849
886 %logstart takes a second optional parameter: logging mode. This can be one
850 %logstart takes a second optional parameter: logging mode. This can be one
887 of (note that the modes are given unquoted):\\
851 of (note that the modes are given unquoted):\\
888 over: overwrite existing log.\\
852 over: overwrite existing log.\\
889 backup: rename (if exists) to name~ and start name.\\
853 backup: rename (if exists) to name~ and start name.\\
890 append: well, that says it.\\
854 append: well, that says it.\\
891 rotate: create rotating logs name.1~, name.2~, etc.
855 rotate: create rotating logs name.1~, name.2~, etc.
892 """
856 """
893
857
894 #FIXME. This function should all be moved to the Logger class.
858 #FIXME. This function should all be moved to the Logger class.
895
859
896 valid_modes = qw('over backup append rotate')
860 valid_modes = qw('over backup append rotate')
897 if self.LOG:
861 if self.LOG:
898 print 'Logging is already in place. Logfile:',self.LOG
862 print 'Logging is already in place. Logfile:',self.LOG
899 return
863 return
900
864
901 par = parameter_s.strip()
865 par = parameter_s.strip()
902 if not par:
866 if not par:
903 logname = self.LOGDEF
867 logname = self.LOGDEF
904 logmode = 'rotate' # use rotate for the auto-generated logs
868 logmode = 'rotate' # use rotate for the auto-generated logs
905 else:
869 else:
906 try:
870 try:
907 logname,logmode = par.split()
871 logname,logmode = par.split()
908 except:
872 except:
909 try:
873 try:
910 logname = par
874 logname = par
911 logmode = 'backup'
875 logmode = 'backup'
912 except:
876 except:
913 warn('Usage: %log [log_name [log_mode]]')
877 warn('Usage: %log [log_name [log_mode]]')
914 return
878 return
915 if not logmode in valid_modes:
879 if not logmode in valid_modes:
916 warn('Logging NOT activated.\n'
880 warn('Logging NOT activated.\n'
917 'Usage: %log [log_name [log_mode]]\n'
881 'Usage: %log [log_name [log_mode]]\n'
918 'Valid modes: '+str(valid_modes))
882 'Valid modes: '+str(valid_modes))
919 return
883 return
920
884
921 # If we made it this far, I think we're ok:
885 # If we made it this far, I think we're ok:
922 print 'Activating auto-logging.'
886 print 'Activating auto-logging.'
923 print 'Current session state plus future input saved to:',logname
887 print 'Current session state plus future input saved to:',logname
924 print 'Logging mode: ',logmode
888 print 'Logging mode: ',logmode
925 # put logname into rc struct as if it had been called on the command line,
889 # put logname into rc struct as if it had been called on the command line,
926 # so it ends up saved in the log header
890 # so it ends up saved in the log header
927 # Save it in case we need to restore it...
891 # Save it in case we need to restore it...
928 old_logfile = self.shell.rc.opts.get('logfile','')
892 old_logfile = self.shell.rc.opts.get('logfile','')
929 logname = os.path.expanduser(logname)
893 logname = os.path.expanduser(logname)
930 self.shell.rc.opts.logfile = logname
894 self.shell.rc.opts.logfile = logname
931 self.LOGMODE = logmode # FIXME: this should be set through a function.
895 self.LOGMODE = logmode # FIXME: this should be set through a function.
932 try:
896 try:
933 header = str(self.LOGHEAD)
897 header = str(self.LOGHEAD)
934 self.create_log(header,logname)
898 self.create_log(header,logname)
935 self.logstart(header,logname)
899 self.logstart(header,logname)
936 except:
900 except:
937 self.LOG = '' # we are NOT logging, something went wrong
901 self.LOG = '' # we are NOT logging, something went wrong
938 self.shell.rc.opts.logfile = old_logfile
902 self.shell.rc.opts.logfile = old_logfile
939 warn("Couldn't start log: "+str(sys.exc_info()[1]))
903 warn("Couldn't start log: "+str(sys.exc_info()[1]))
940 else: # log input history up to this point
904 else: # log input history up to this point
941 self.logfile.write(self.shell.user_ns['_ih'][1:])
905 self.logfile.write(self.shell.user_ns['_ih'][1:])
942 self.logfile.flush()
906 self.logfile.flush()
943
907
944 def magic_logoff(self,parameter_s=''):
908 def magic_logoff(self,parameter_s=''):
945 """Temporarily stop logging.
909 """Temporarily stop logging.
946
910
947 You must have previously started logging."""
911 You must have previously started logging."""
948 self.switch_log(0)
912 self.switch_log(0)
949
913
950 def magic_logon(self,parameter_s=''):
914 def magic_logon(self,parameter_s=''):
951 """Restart logging.
915 """Restart logging.
952
916
953 This function is for restarting logging which you've temporarily
917 This function is for restarting logging which you've temporarily
954 stopped with %logoff. For starting logging for the first time, you
918 stopped with %logoff. For starting logging for the first time, you
955 must use the %logstart function, which allows you to specify an
919 must use the %logstart function, which allows you to specify an
956 optional log filename."""
920 optional log filename."""
957
921
958 self.switch_log(1)
922 self.switch_log(1)
959
923
960 def magic_logstate(self,parameter_s=''):
924 def magic_logstate(self,parameter_s=''):
961 """Print the status of the logging system."""
925 """Print the status of the logging system."""
962
926
963 self.logstate()
927 self.logstate()
964
928
965 def magic_pdb(self, parameter_s=''):
929 def magic_pdb(self, parameter_s=''):
966 """Control the calling of the pdb interactive debugger.
930 """Control the calling of the pdb interactive debugger.
967
931
968 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
932 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
969 argument it works as a toggle.
933 argument it works as a toggle.
970
934
971 When an exception is triggered, IPython can optionally call the
935 When an exception is triggered, IPython can optionally call the
972 interactive pdb debugger after the traceback printout. %pdb toggles
936 interactive pdb debugger after the traceback printout. %pdb toggles
973 this feature on and off."""
937 this feature on and off."""
974
938
975 par = parameter_s.strip().lower()
939 par = parameter_s.strip().lower()
976
940
977 if par:
941 if par:
978 try:
942 try:
979 pdb = {'off':0,'0':0,'on':1,'1':1}[par]
943 pdb = {'off':0,'0':0,'on':1,'1':1}[par]
980 except KeyError:
944 except KeyError:
981 print 'Incorrect argument. Use on/1, off/0 or nothing for a toggle.'
945 print 'Incorrect argument. Use on/1, off/0 or nothing for a toggle.'
982 return
946 return
983 else:
947 else:
984 self.shell.InteractiveTB.call_pdb = pdb
948 self.shell.InteractiveTB.call_pdb = pdb
985 else:
949 else:
986 self.shell.InteractiveTB.call_pdb = 1 - self.shell.InteractiveTB.call_pdb
950 self.shell.InteractiveTB.call_pdb = 1 - self.shell.InteractiveTB.call_pdb
987 print 'Automatic pdb calling has been turned',\
951 print 'Automatic pdb calling has been turned',\
988 on_off(self.shell.InteractiveTB.call_pdb)
952 on_off(self.shell.InteractiveTB.call_pdb)
989
953
990
954
991 def magic_prun(self, parameter_s ='',user_mode=1,
955 def magic_prun(self, parameter_s ='',user_mode=1,
992 opts=None,arg_lst=None,prog_ns=None):
956 opts=None,arg_lst=None,prog_ns=None):
993
957
994 """Run a statement through the python code profiler.
958 """Run a statement through the python code profiler.
995
959
996 Usage:\\
960 Usage:\\
997 %prun [options] statement
961 %prun [options] statement
998
962
999 The given statement (which doesn't require quote marks) is run via the
963 The given statement (which doesn't require quote marks) is run via the
1000 python profiler in a manner similar to the profile.run() function.
964 python profiler in a manner similar to the profile.run() function.
1001 Namespaces are internally managed to work correctly; profile.run
965 Namespaces are internally managed to work correctly; profile.run
1002 cannot be used in IPython because it makes certain assumptions about
966 cannot be used in IPython because it makes certain assumptions about
1003 namespaces which do not hold under IPython.
967 namespaces which do not hold under IPython.
1004
968
1005 Options:
969 Options:
1006
970
1007 -l <limit>: you can place restrictions on what or how much of the
971 -l <limit>: you can place restrictions on what or how much of the
1008 profile gets printed. The limit value can be:
972 profile gets printed. The limit value can be:
1009
973
1010 * A string: only information for function names containing this string
974 * A string: only information for function names containing this string
1011 is printed.
975 is printed.
1012
976
1013 * An integer: only these many lines are printed.
977 * An integer: only these many lines are printed.
1014
978
1015 * A float (between 0 and 1): this fraction of the report is printed
979 * A float (between 0 and 1): this fraction of the report is printed
1016 (for example, use a limit of 0.4 to see the topmost 40% only).
980 (for example, use a limit of 0.4 to see the topmost 40% only).
1017
981
1018 You can combine several limits with repeated use of the option. For
982 You can combine several limits with repeated use of the option. For
1019 example, '-l __init__ -l 5' will print only the topmost 5 lines of
983 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1020 information about class constructors.
984 information about class constructors.
1021
985
1022 -r: return the pstats.Stats object generated by the profiling. This
986 -r: return the pstats.Stats object generated by the profiling. This
1023 object has all the information about the profile in it, and you can
987 object has all the information about the profile in it, and you can
1024 later use it for further analysis or in other functions.
988 later use it for further analysis or in other functions.
1025
989
1026 Since magic functions have a particular form of calling which prevents
990 Since magic functions have a particular form of calling which prevents
1027 you from writing something like:\\
991 you from writing something like:\\
1028 In [1]: p = %prun -r print 4 # invalid!\\
992 In [1]: p = %prun -r print 4 # invalid!\\
1029 you must instead use IPython's automatic variables to assign this:\\
993 you must instead use IPython's automatic variables to assign this:\\
1030 In [1]: %prun -r print 4 \\
994 In [1]: %prun -r print 4 \\
1031 Out[1]: <pstats.Stats instance at 0x8222cec>\\
995 Out[1]: <pstats.Stats instance at 0x8222cec>\\
1032 In [2]: stats = _
996 In [2]: stats = _
1033
997
1034 If you really need to assign this value via an explicit function call,
998 If you really need to assign this value via an explicit function call,
1035 you can always tap directly into the true name of the magic function
999 you can always tap directly into the true name of the magic function
1036 by using the ipmagic function (which IPython automatically adds to the
1000 by using the ipmagic function (which IPython automatically adds to the
1037 builtins):\\
1001 builtins):\\
1038 In [3]: stats = ipmagic('prun','-r print 4')
1002 In [3]: stats = ipmagic('prun','-r print 4')
1039
1003
1040 You can type ipmagic? for more details on ipmagic.
1004 You can type ipmagic? for more details on ipmagic.
1041
1005
1042 -s <key>: sort profile by given key. You can provide more than one key
1006 -s <key>: sort profile by given key. You can provide more than one key
1043 by using the option several times: '-s key1 -s key2 -s key3...'. The
1007 by using the option several times: '-s key1 -s key2 -s key3...'. The
1044 default sorting key is 'time'.
1008 default sorting key is 'time'.
1045
1009
1046 The following is copied verbatim from the profile documentation
1010 The following is copied verbatim from the profile documentation
1047 referenced below:
1011 referenced below:
1048
1012
1049 When more than one key is provided, additional keys are used as
1013 When more than one key is provided, additional keys are used as
1050 secondary criteria when the there is equality in all keys selected
1014 secondary criteria when the there is equality in all keys selected
1051 before them.
1015 before them.
1052
1016
1053 Abbreviations can be used for any key names, as long as the
1017 Abbreviations can be used for any key names, as long as the
1054 abbreviation is unambiguous. The following are the keys currently
1018 abbreviation is unambiguous. The following are the keys currently
1055 defined:
1019 defined:
1056
1020
1057 Valid Arg Meaning\\
1021 Valid Arg Meaning\\
1058 "calls" call count\\
1022 "calls" call count\\
1059 "cumulative" cumulative time\\
1023 "cumulative" cumulative time\\
1060 "file" file name\\
1024 "file" file name\\
1061 "module" file name\\
1025 "module" file name\\
1062 "pcalls" primitive call count\\
1026 "pcalls" primitive call count\\
1063 "line" line number\\
1027 "line" line number\\
1064 "name" function name\\
1028 "name" function name\\
1065 "nfl" name/file/line\\
1029 "nfl" name/file/line\\
1066 "stdname" standard name\\
1030 "stdname" standard name\\
1067 "time" internal time
1031 "time" internal time
1068
1032
1069 Note that all sorts on statistics are in descending order (placing
1033 Note that all sorts on statistics are in descending order (placing
1070 most time consuming items first), where as name, file, and line number
1034 most time consuming items first), where as name, file, and line number
1071 searches are in ascending order (i.e., alphabetical). The subtle
1035 searches are in ascending order (i.e., alphabetical). The subtle
1072 distinction between "nfl" and "stdname" is that the standard name is a
1036 distinction between "nfl" and "stdname" is that the standard name is a
1073 sort of the name as printed, which means that the embedded line
1037 sort of the name as printed, which means that the embedded line
1074 numbers get compared in an odd way. For example, lines 3, 20, and 40
1038 numbers get compared in an odd way. For example, lines 3, 20, and 40
1075 would (if the file names were the same) appear in the string order
1039 would (if the file names were the same) appear in the string order
1076 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1040 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1077 line numbers. In fact, sort_stats("nfl") is the same as
1041 line numbers. In fact, sort_stats("nfl") is the same as
1078 sort_stats("name", "file", "line").
1042 sort_stats("name", "file", "line").
1079
1043
1080 -T <filename>: save profile results as shown on screen to a text
1044 -T <filename>: save profile results as shown on screen to a text
1081 file. The profile is still shown on screen.
1045 file. The profile is still shown on screen.
1082
1046
1083 -D <filename>: save (via dump_stats) profile statistics to given
1047 -D <filename>: save (via dump_stats) profile statistics to given
1084 filename. This data is in a format understod by the pstats module, and
1048 filename. This data is in a format understod by the pstats module, and
1085 is generated by a call to the dump_stats() method of profile
1049 is generated by a call to the dump_stats() method of profile
1086 objects. The profile is still shown on screen.
1050 objects. The profile is still shown on screen.
1087
1051
1088 If you want to run complete programs under the profiler's control, use
1052 If you want to run complete programs under the profiler's control, use
1089 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1053 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1090 contains profiler specific options as described here.
1054 contains profiler specific options as described here.
1091
1055
1092 You can read the complete documentation for the profile module with:\\
1056 You can read the complete documentation for the profile module with:\\
1093 In [1]: import profile; profile.help() """
1057 In [1]: import profile; profile.help() """
1094
1058
1095 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1059 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1096 # protect user quote marks
1060 # protect user quote marks
1097 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1061 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1098
1062
1099 if user_mode: # regular user call
1063 if user_mode: # regular user call
1100 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1064 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1101 list_all=1)
1065 list_all=1)
1102 namespace = self.shell.user_ns
1066 namespace = self.shell.user_ns
1103 else: # called to run a program by %run -p
1067 else: # called to run a program by %run -p
1104 try:
1068 try:
1105 filename = get_py_filename(arg_lst[0])
1069 filename = get_py_filename(arg_lst[0])
1106 except IOError,msg:
1070 except IOError,msg:
1107 error(msg)
1071 error(msg)
1108 return
1072 return
1109
1073
1110 arg_str = 'execfile(filename,prog_ns)'
1074 arg_str = 'execfile(filename,prog_ns)'
1111 namespace = locals()
1075 namespace = locals()
1112
1076
1113 opts.merge(opts_def)
1077 opts.merge(opts_def)
1114
1078
1115 prof = profile.Profile()
1079 prof = profile.Profile()
1116 try:
1080 try:
1117 prof = prof.runctx(arg_str,namespace,namespace)
1081 prof = prof.runctx(arg_str,namespace,namespace)
1118 sys_exit = ''
1082 sys_exit = ''
1119 except SystemExit:
1083 except SystemExit:
1120 sys_exit = """*** SystemExit exception caught in code being profiled."""
1084 sys_exit = """*** SystemExit exception caught in code being profiled."""
1121
1085
1122 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1086 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1123
1087
1124 lims = opts.l
1088 lims = opts.l
1125 if lims:
1089 if lims:
1126 lims = [] # rebuild lims with ints/floats/strings
1090 lims = [] # rebuild lims with ints/floats/strings
1127 for lim in opts.l:
1091 for lim in opts.l:
1128 try:
1092 try:
1129 lims.append(int(lim))
1093 lims.append(int(lim))
1130 except ValueError:
1094 except ValueError:
1131 try:
1095 try:
1132 lims.append(float(lim))
1096 lims.append(float(lim))
1133 except ValueError:
1097 except ValueError:
1134 lims.append(lim)
1098 lims.append(lim)
1135
1099
1136 # trap output
1100 # trap output
1137 sys_stdout = sys.stdout
1101 sys_stdout = sys.stdout
1138 stdout_trap = StringIO()
1102 stdout_trap = StringIO()
1139 try:
1103 try:
1140 sys.stdout = stdout_trap
1104 sys.stdout = stdout_trap
1141 stats.print_stats(*lims)
1105 stats.print_stats(*lims)
1142 finally:
1106 finally:
1143 sys.stdout = sys_stdout
1107 sys.stdout = sys_stdout
1144 output = stdout_trap.getvalue()
1108 output = stdout_trap.getvalue()
1145 output = output.rstrip()
1109 output = output.rstrip()
1146
1110
1147 page(output,screen_lines=self.shell.rc.screen_length)
1111 page(output,screen_lines=self.shell.rc.screen_length)
1148 print sys_exit,
1112 print sys_exit,
1149
1113
1150 dump_file = opts.D[0]
1114 dump_file = opts.D[0]
1151 text_file = opts.T[0]
1115 text_file = opts.T[0]
1152 if dump_file:
1116 if dump_file:
1153 prof.dump_stats(dump_file)
1117 prof.dump_stats(dump_file)
1154 print '\n*** Profile stats marshalled to file',\
1118 print '\n*** Profile stats marshalled to file',\
1155 `dump_file`+'.',sys_exit
1119 `dump_file`+'.',sys_exit
1156 if text_file:
1120 if text_file:
1157 file(text_file,'w').write(output)
1121 file(text_file,'w').write(output)
1158 print '\n*** Profile printout saved to text file',\
1122 print '\n*** Profile printout saved to text file',\
1159 `text_file`+'.',sys_exit
1123 `text_file`+'.',sys_exit
1160
1124
1161 if opts.has_key('r'):
1125 if opts.has_key('r'):
1162 return stats
1126 return stats
1163 else:
1127 else:
1164 return None
1128 return None
1165
1129
1166 def magic_run(self, parameter_s ='',runner=None):
1130 def magic_run(self, parameter_s ='',runner=None):
1167 """Run the named file inside IPython as a program.
1131 """Run the named file inside IPython as a program.
1168
1132
1169 Usage:\\
1133 Usage:\\
1170 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1134 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1171
1135
1172 Parameters after the filename are passed as command-line arguments to
1136 Parameters after the filename are passed as command-line arguments to
1173 the program (put in sys.argv). Then, control returns to IPython's
1137 the program (put in sys.argv). Then, control returns to IPython's
1174 prompt.
1138 prompt.
1175
1139
1176 This is similar to running at a system prompt:\\
1140 This is similar to running at a system prompt:\\
1177 $ python file args\\
1141 $ python file args\\
1178 but with the advantage of giving you IPython's tracebacks, and of
1142 but with the advantage of giving you IPython's tracebacks, and of
1179 loading all variables into your interactive namespace for further use
1143 loading all variables into your interactive namespace for further use
1180 (unless -p is used, see below).
1144 (unless -p is used, see below).
1181
1145
1182 The file is executed in a namespace initially consisting only of
1146 The file is executed in a namespace initially consisting only of
1183 __name__=='__main__' and sys.argv constructed as indicated. It thus
1147 __name__=='__main__' and sys.argv constructed as indicated. It thus
1184 sees its environment as if it were being run as a stand-alone
1148 sees its environment as if it were being run as a stand-alone
1185 program. But after execution, the IPython interactive namespace gets
1149 program. But after execution, the IPython interactive namespace gets
1186 updated with all variables defined in the program (except for __name__
1150 updated with all variables defined in the program (except for __name__
1187 and sys.argv). This allows for very convenient loading of code for
1151 and sys.argv). This allows for very convenient loading of code for
1188 interactive work, while giving each program a 'clean sheet' to run in.
1152 interactive work, while giving each program a 'clean sheet' to run in.
1189
1153
1190 Options:
1154 Options:
1191
1155
1192 -n: __name__ is NOT set to '__main__', but to the running file's name
1156 -n: __name__ is NOT set to '__main__', but to the running file's name
1193 without extension (as python does under import). This allows running
1157 without extension (as python does under import). This allows running
1194 scripts and reloading the definitions in them without calling code
1158 scripts and reloading the definitions in them without calling code
1195 protected by an ' if __name__ == "__main__" ' clause.
1159 protected by an ' if __name__ == "__main__" ' clause.
1196
1160
1197 -i: run the file in IPython's namespace instead of an empty one. This
1161 -i: run the file in IPython's namespace instead of an empty one. This
1198 is useful if you are experimenting with code written in a text editor
1162 is useful if you are experimenting with code written in a text editor
1199 which depends on variables defined interactively.
1163 which depends on variables defined interactively.
1200
1164
1201 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1165 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1202 being run. This is particularly useful if IPython is being used to
1166 being run. This is particularly useful if IPython is being used to
1203 run unittests, which always exit with a sys.exit() call. In such
1167 run unittests, which always exit with a sys.exit() call. In such
1204 cases you are interested in the output of the test results, not in
1168 cases you are interested in the output of the test results, not in
1205 seeing a traceback of the unittest module.
1169 seeing a traceback of the unittest module.
1206
1170
1207 -t: print timing information at the end of the run. IPython will give
1171 -t: print timing information at the end of the run. IPython will give
1208 you an estimated CPU time consumption for your script, which under
1172 you an estimated CPU time consumption for your script, which under
1209 Unix uses the resource module to avoid the wraparound problems of
1173 Unix uses the resource module to avoid the wraparound problems of
1210 time.clock(). Under Unix, an estimate of time spent on system tasks
1174 time.clock(). Under Unix, an estimate of time spent on system tasks
1211 is also given (for Windows platforms this is reported as 0.0).
1175 is also given (for Windows platforms this is reported as 0.0).
1212
1176
1213 If -t is given, an additional -N<N> option can be given, where <N>
1177 If -t is given, an additional -N<N> option can be given, where <N>
1214 must be an integer indicating how many times you want the script to
1178 must be an integer indicating how many times you want the script to
1215 run. The final timing report will include total and per run results.
1179 run. The final timing report will include total and per run results.
1216
1180
1217 For example (testing the script uniq_stable.py):
1181 For example (testing the script uniq_stable.py):
1218
1182
1219 In [1]: run -t uniq_stable
1183 In [1]: run -t uniq_stable
1220
1184
1221 IPython CPU timings (estimated):\\
1185 IPython CPU timings (estimated):\\
1222 User : 0.19597 s.\\
1186 User : 0.19597 s.\\
1223 System: 0.0 s.\\
1187 System: 0.0 s.\\
1224
1188
1225 In [2]: run -t -N5 uniq_stable
1189 In [2]: run -t -N5 uniq_stable
1226
1190
1227 IPython CPU timings (estimated):\\
1191 IPython CPU timings (estimated):\\
1228 Total runs performed: 5\\
1192 Total runs performed: 5\\
1229 Times : Total Per run\\
1193 Times : Total Per run\\
1230 User : 0.910862 s, 0.1821724 s.\\
1194 User : 0.910862 s, 0.1821724 s.\\
1231 System: 0.0 s, 0.0 s.
1195 System: 0.0 s, 0.0 s.
1232
1196
1233 -d: run your program under the control of pdb, the Python debugger.
1197 -d: run your program under the control of pdb, the Python debugger.
1234 This allows you to execute your program step by step, watch variables,
1198 This allows you to execute your program step by step, watch variables,
1235 etc. Internally, what IPython does is similar to calling:
1199 etc. Internally, what IPython does is similar to calling:
1236
1200
1237 pdb.run('execfile("YOURFILENAME")')
1201 pdb.run('execfile("YOURFILENAME")')
1238
1202
1239 with a breakpoint set on line 1 of your file. You can change the line
1203 with a breakpoint set on line 1 of your file. You can change the line
1240 number for this automatic breakpoint to be <N> by using the -bN option
1204 number for this automatic breakpoint to be <N> by using the -bN option
1241 (where N must be an integer). For example:
1205 (where N must be an integer). For example:
1242
1206
1243 %run -d -b40 myscript
1207 %run -d -b40 myscript
1244
1208
1245 will set the first breakpoint at line 40 in myscript.py. Note that
1209 will set the first breakpoint at line 40 in myscript.py. Note that
1246 the first breakpoint must be set on a line which actually does
1210 the first breakpoint must be set on a line which actually does
1247 something (not a comment or docstring) for it to stop execution.
1211 something (not a comment or docstring) for it to stop execution.
1248
1212
1249 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1213 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1250 first enter 'c' (without qoutes) to start execution up to the first
1214 first enter 'c' (without qoutes) to start execution up to the first
1251 breakpoint.
1215 breakpoint.
1252
1216
1253 Entering 'help' gives information about the use of the debugger. You
1217 Entering 'help' gives information about the use of the debugger. You
1254 can easily see pdb's full documentation with "import pdb;pdb.help()"
1218 can easily see pdb's full documentation with "import pdb;pdb.help()"
1255 at a prompt.
1219 at a prompt.
1256
1220
1257 -p: run program under the control of the Python profiler module (which
1221 -p: run program under the control of the Python profiler module (which
1258 prints a detailed report of execution times, function calls, etc).
1222 prints a detailed report of execution times, function calls, etc).
1259
1223
1260 You can pass other options after -p which affect the behavior of the
1224 You can pass other options after -p which affect the behavior of the
1261 profiler itself. See the docs for %prun for details.
1225 profiler itself. See the docs for %prun for details.
1262
1226
1263 In this mode, the program's variables do NOT propagate back to the
1227 In this mode, the program's variables do NOT propagate back to the
1264 IPython interactive namespace (because they remain in the namespace
1228 IPython interactive namespace (because they remain in the namespace
1265 where the profiler executes them).
1229 where the profiler executes them).
1266
1230
1267 Internally this triggers a call to %prun, see its documentation for
1231 Internally this triggers a call to %prun, see its documentation for
1268 details on the options available specifically for profiling."""
1232 details on the options available specifically for profiling."""
1269
1233
1270 # get arguments and set sys.argv for program to be run.
1234 # get arguments and set sys.argv for program to be run.
1271 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1235 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1272 mode='list',list_all=1)
1236 mode='list',list_all=1)
1273
1237
1274 try:
1238 try:
1275 filename = get_py_filename(arg_lst[0])
1239 filename = get_py_filename(arg_lst[0])
1276 except IndexError:
1240 except IndexError:
1277 warn('you must provide at least a filename.')
1241 warn('you must provide at least a filename.')
1278 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1242 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1279 return
1243 return
1280 except IOError,msg:
1244 except IOError,msg:
1281 error(msg)
1245 error(msg)
1282 return
1246 return
1283
1247
1284 # Control the response to exit() calls made by the script being run
1248 # Control the response to exit() calls made by the script being run
1285 exit_ignore = opts.has_key('e')
1249 exit_ignore = opts.has_key('e')
1286
1250
1287 # Make sure that the running script gets a proper sys.argv as if it
1251 # Make sure that the running script gets a proper sys.argv as if it
1288 # were run from a system shell.
1252 # were run from a system shell.
1289 save_argv = sys.argv # save it for later restoring
1253 save_argv = sys.argv # save it for later restoring
1290 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1254 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1291
1255
1292 if opts.has_key('i'):
1256 if opts.has_key('i'):
1293 prog_ns = self.shell.user_ns
1257 prog_ns = self.shell.user_ns
1294 __name__save = self.shell.user_ns['__name__']
1258 __name__save = self.shell.user_ns['__name__']
1295 prog_ns['__name__'] = '__main__'
1259 prog_ns['__name__'] = '__main__'
1296 else:
1260 else:
1297 if opts.has_key('n'):
1261 if opts.has_key('n'):
1298 name = os.path.splitext(os.path.basename(filename))[0]
1262 name = os.path.splitext(os.path.basename(filename))[0]
1299 else:
1263 else:
1300 name = '__main__'
1264 name = '__main__'
1301 prog_ns = {'__name__':name}
1265 prog_ns = {'__name__':name}
1302
1266
1303 # pickle fix. See iplib for an explanation
1267 # pickle fix. See iplib for an explanation
1304 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1268 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1305
1269
1306 stats = None
1270 stats = None
1307 try:
1271 try:
1308 if opts.has_key('p'):
1272 if opts.has_key('p'):
1309 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1273 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1310 else:
1274 else:
1311 if opts.has_key('d'):
1275 if opts.has_key('d'):
1312 deb = pdb.Pdb()
1276 deb = pdb.Pdb()
1313 # reset Breakpoint state, which is moronically kept
1277 # reset Breakpoint state, which is moronically kept
1314 # in a class
1278 # in a class
1315 bdb.Breakpoint.next = 1
1279 bdb.Breakpoint.next = 1
1316 bdb.Breakpoint.bplist = {}
1280 bdb.Breakpoint.bplist = {}
1317 bdb.Breakpoint.bpbynumber = [None]
1281 bdb.Breakpoint.bpbynumber = [None]
1318 # Set an initial breakpoint to stop execution
1282 # Set an initial breakpoint to stop execution
1319 maxtries = 10
1283 maxtries = 10
1320 bp = int(opts.get('b',[1])[0])
1284 bp = int(opts.get('b',[1])[0])
1321 checkline = deb.checkline(filename,bp)
1285 checkline = deb.checkline(filename,bp)
1322 if not checkline:
1286 if not checkline:
1323 for bp in range(bp+1,bp+maxtries+1):
1287 for bp in range(bp+1,bp+maxtries+1):
1324 if deb.checkline(filename,bp):
1288 if deb.checkline(filename,bp):
1325 break
1289 break
1326 else:
1290 else:
1327 msg = ("\nI failed to find a valid line to set "
1291 msg = ("\nI failed to find a valid line to set "
1328 "a breakpoint\n"
1292 "a breakpoint\n"
1329 "after trying up to line: %s.\n"
1293 "after trying up to line: %s.\n"
1330 "Please set a valid breakpoint manually "
1294 "Please set a valid breakpoint manually "
1331 "with the -b option." % bp)
1295 "with the -b option." % bp)
1332 error(msg)
1296 error(msg)
1333 return
1297 return
1334 # if we find a good linenumber, set the breakpoint
1298 # if we find a good linenumber, set the breakpoint
1335 deb.do_break('%s:%s' % (filename,bp))
1299 deb.do_break('%s:%s' % (filename,bp))
1336 # Start file run
1300 # Start file run
1337 print "NOTE: Enter 'c' at the",
1301 print "NOTE: Enter 'c' at the",
1338 print "(Pdb) prompt to start your script."
1302 print "(Pdb) prompt to start your script."
1339 deb.run('execfile("%s")' % filename,prog_ns)
1303 deb.run('execfile("%s")' % filename,prog_ns)
1340 else:
1304 else:
1341 if runner is None:
1305 if runner is None:
1342 runner = self.shell.safe_execfile
1306 runner = self.shell.safe_execfile
1343 if opts.has_key('t'):
1307 if opts.has_key('t'):
1344 try:
1308 try:
1345 nruns = int(opts['N'][0])
1309 nruns = int(opts['N'][0])
1346 if nruns < 1:
1310 if nruns < 1:
1347 error('Number of runs must be >=1')
1311 error('Number of runs must be >=1')
1348 return
1312 return
1349 except (KeyError):
1313 except (KeyError):
1350 nruns = 1
1314 nruns = 1
1351 if nruns == 1:
1315 if nruns == 1:
1352 t0 = clock2()
1316 t0 = clock2()
1353 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1317 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1354 t1 = clock2()
1318 t1 = clock2()
1355 t_usr = t1[0]-t0[0]
1319 t_usr = t1[0]-t0[0]
1356 t_sys = t1[1]-t1[1]
1320 t_sys = t1[1]-t1[1]
1357 print "\nIPython CPU timings (estimated):"
1321 print "\nIPython CPU timings (estimated):"
1358 print " User : %10s s." % t_usr
1322 print " User : %10s s." % t_usr
1359 print " System: %10s s." % t_sys
1323 print " System: %10s s." % t_sys
1360 else:
1324 else:
1361 runs = range(nruns)
1325 runs = range(nruns)
1362 t0 = clock2()
1326 t0 = clock2()
1363 for nr in runs:
1327 for nr in runs:
1364 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1328 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1365 t1 = clock2()
1329 t1 = clock2()
1366 t_usr = t1[0]-t0[0]
1330 t_usr = t1[0]-t0[0]
1367 t_sys = t1[1]-t1[1]
1331 t_sys = t1[1]-t1[1]
1368 print "\nIPython CPU timings (estimated):"
1332 print "\nIPython CPU timings (estimated):"
1369 print "Total runs performed:",nruns
1333 print "Total runs performed:",nruns
1370 print " Times : %10s %10s" % ('Total','Per run')
1334 print " Times : %10s %10s" % ('Total','Per run')
1371 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1335 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1372 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1336 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1373
1337
1374 else:
1338 else:
1375 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1339 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1376 if opts.has_key('i'):
1340 if opts.has_key('i'):
1377 self.shell.user_ns['__name__'] = __name__save
1341 self.shell.user_ns['__name__'] = __name__save
1378 else:
1342 else:
1379 # update IPython interactive namespace
1343 # update IPython interactive namespace
1380 del prog_ns['__name__']
1344 del prog_ns['__name__']
1381 self.shell.user_ns.update(prog_ns)
1345 self.shell.user_ns.update(prog_ns)
1382 finally:
1346 finally:
1383 sys.argv = save_argv
1347 sys.argv = save_argv
1384 return stats
1348 return stats
1385
1349
1386 def magic_runlog(self, parameter_s =''):
1350 def magic_runlog(self, parameter_s =''):
1387 """Run files as logs.
1351 """Run files as logs.
1388
1352
1389 Usage:\\
1353 Usage:\\
1390 %runlog file1 file2 ...
1354 %runlog file1 file2 ...
1391
1355
1392 Run the named files (treating them as log files) in sequence inside
1356 Run the named files (treating them as log files) in sequence inside
1393 the interpreter, and return to the prompt. This is much slower than
1357 the interpreter, and return to the prompt. This is much slower than
1394 %run because each line is executed in a try/except block, but it
1358 %run because each line is executed in a try/except block, but it
1395 allows running files with syntax errors in them.
1359 allows running files with syntax errors in them.
1396
1360
1397 Normally IPython will guess when a file is one of its own logfiles, so
1361 Normally IPython will guess when a file is one of its own logfiles, so
1398 you can typically use %run even for logs. This shorthand allows you to
1362 you can typically use %run even for logs. This shorthand allows you to
1399 force any file to be treated as a log file."""
1363 force any file to be treated as a log file."""
1400
1364
1401 for f in parameter_s.split():
1365 for f in parameter_s.split():
1402 self.shell.safe_execfile(f,self.shell.user_ns,
1366 self.shell.safe_execfile(f,self.shell.user_ns,
1403 self.shell.user_ns,islog=1)
1367 self.shell.user_ns,islog=1)
1404
1368
1405 def magic_time(self,parameter_s = ''):
1369 def magic_time(self,parameter_s = ''):
1406 """Time execution of a Python statement or expression.
1370 """Time execution of a Python statement or expression.
1407
1371
1408 The CPU and wall clock times are printed, and the value of the
1372 The CPU and wall clock times are printed, and the value of the
1409 expression (if any) is returned. Note that under Win32, system time
1373 expression (if any) is returned. Note that under Win32, system time
1410 is always reported as 0, since it can not be measured.
1374 is always reported as 0, since it can not be measured.
1411
1375
1412 This function provides very basic timing functionality. In Python
1376 This function provides very basic timing functionality. In Python
1413 2.3, the timeit module offers more control and sophistication, but for
1377 2.3, the timeit module offers more control and sophistication, but for
1414 now IPython supports Python 2.2, so we can not rely on timeit being
1378 now IPython supports Python 2.2, so we can not rely on timeit being
1415 present.
1379 present.
1416
1380
1417 Some examples:
1381 Some examples:
1418
1382
1419 In [1]: time 2**128
1383 In [1]: time 2**128
1420 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1384 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1421 Wall time: 0.00
1385 Wall time: 0.00
1422 Out[1]: 340282366920938463463374607431768211456L
1386 Out[1]: 340282366920938463463374607431768211456L
1423
1387
1424 In [2]: n = 1000000
1388 In [2]: n = 1000000
1425
1389
1426 In [3]: time sum(range(n))
1390 In [3]: time sum(range(n))
1427 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1391 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1428 Wall time: 1.37
1392 Wall time: 1.37
1429 Out[3]: 499999500000L
1393 Out[3]: 499999500000L
1430
1394
1431 In [4]: time print 'hello world'
1395 In [4]: time print 'hello world'
1432 hello world
1396 hello world
1433 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1397 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1434 Wall time: 0.00
1398 Wall time: 0.00
1435 """
1399 """
1436
1400
1437 # fail immediately if the given expression can't be compiled
1401 # fail immediately if the given expression can't be compiled
1438 try:
1402 try:
1439 mode = 'eval'
1403 mode = 'eval'
1440 code = compile(parameter_s,'<timed eval>',mode)
1404 code = compile(parameter_s,'<timed eval>',mode)
1441 except SyntaxError:
1405 except SyntaxError:
1442 mode = 'exec'
1406 mode = 'exec'
1443 code = compile(parameter_s,'<timed exec>',mode)
1407 code = compile(parameter_s,'<timed exec>',mode)
1444 # skew measurement as little as possible
1408 # skew measurement as little as possible
1445 glob = self.shell.user_ns
1409 glob = self.shell.user_ns
1446 clk = clock2
1410 clk = clock2
1447 wtime = time.time
1411 wtime = time.time
1448 # time execution
1412 # time execution
1449 wall_st = wtime()
1413 wall_st = wtime()
1450 if mode=='eval':
1414 if mode=='eval':
1451 st = clk()
1415 st = clk()
1452 out = eval(code,glob)
1416 out = eval(code,glob)
1453 end = clk()
1417 end = clk()
1454 else:
1418 else:
1455 st = clk()
1419 st = clk()
1456 exec code in glob
1420 exec code in glob
1457 end = clk()
1421 end = clk()
1458 out = None
1422 out = None
1459 wall_end = wtime()
1423 wall_end = wtime()
1460 # Compute actual times and report
1424 # Compute actual times and report
1461 wall_time = wall_end-wall_st
1425 wall_time = wall_end-wall_st
1462 cpu_user = end[0]-st[0]
1426 cpu_user = end[0]-st[0]
1463 cpu_sys = end[1]-st[1]
1427 cpu_sys = end[1]-st[1]
1464 cpu_tot = cpu_user+cpu_sys
1428 cpu_tot = cpu_user+cpu_sys
1465 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1429 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1466 (cpu_user,cpu_sys,cpu_tot)
1430 (cpu_user,cpu_sys,cpu_tot)
1467 print "Wall time: %.2f" % wall_time
1431 print "Wall time: %.2f" % wall_time
1468 return out
1432 return out
1469
1433
1470 def magic_macro(self,parameter_s = ''):
1434 def magic_macro(self,parameter_s = ''):
1471 """Define a set of input lines as a macro for future re-execution.
1435 """Define a set of input lines as a macro for future re-execution.
1472
1436
1473 Usage:\\
1437 Usage:\\
1474 %macro name n1:n2 n3:n4 ... n5 .. n6 ...
1438 %macro name n1:n2 n3:n4 ... n5 .. n6 ...
1475
1439
1476 This will define a global variable called `name` which is a string
1440 This will define a global variable called `name` which is a string
1477 made of joining the slices and lines you specify (n1,n2,... numbers
1441 made of joining the slices and lines you specify (n1,n2,... numbers
1478 above) from your input history into a single string. This variable
1442 above) from your input history into a single string. This variable
1479 acts like an automatic function which re-executes those lines as if
1443 acts like an automatic function which re-executes those lines as if
1480 you had typed them. You just type 'name' at the prompt and the code
1444 you had typed them. You just type 'name' at the prompt and the code
1481 executes.
1445 executes.
1482
1446
1483 Note that the slices use the standard Python slicing notation (5:8
1447 Note that the slices use the standard Python slicing notation (5:8
1484 means include lines numbered 5,6,7).
1448 means include lines numbered 5,6,7).
1485
1449
1486 For example, if your history contains (%hist prints it):
1450 For example, if your history contains (%hist prints it):
1487
1451
1488 44: x=1\\
1452 44: x=1\\
1489 45: y=3\\
1453 45: y=3\\
1490 46: z=x+y\\
1454 46: z=x+y\\
1491 47: print x\\
1455 47: print x\\
1492 48: a=5\\
1456 48: a=5\\
1493 49: print 'x',x,'y',y\\
1457 49: print 'x',x,'y',y\\
1494
1458
1495 you can create a macro with lines 44 through 47 (included) and line 49
1459 you can create a macro with lines 44 through 47 (included) and line 49
1496 called my_macro with:
1460 called my_macro with:
1497
1461
1498 In [51]: %macro my_macro 44:48 49
1462 In [51]: %macro my_macro 44:48 49
1499
1463
1500 Now, typing `my_macro` (without quotes) will re-execute all this code
1464 Now, typing `my_macro` (without quotes) will re-execute all this code
1501 in one pass.
1465 in one pass.
1502
1466
1503 You don't need to give the line-numbers in order, and any given line
1467 You don't need to give the line-numbers in order, and any given line
1504 number can appear multiple times. You can assemble macros with any
1468 number can appear multiple times. You can assemble macros with any
1505 lines from your input history in any order.
1469 lines from your input history in any order.
1506
1470
1507 The macro is a simple object which holds its value in an attribute,
1471 The macro is a simple object which holds its value in an attribute,
1508 but IPython's display system checks for macros and executes them as
1472 but IPython's display system checks for macros and executes them as
1509 code instead of printing them when you type their name.
1473 code instead of printing them when you type their name.
1510
1474
1511 You can view a macro's contents by explicitly printing it with:
1475 You can view a macro's contents by explicitly printing it with:
1512
1476
1513 'print macro_name'.
1477 'print macro_name'.
1514
1478
1515 For one-off cases which DON'T contain magic function calls in them you
1479 For one-off cases which DON'T contain magic function calls in them you
1516 can obtain similar results by explicitly executing slices from your
1480 can obtain similar results by explicitly executing slices from your
1517 input history with:
1481 input history with:
1518
1482
1519 In [60]: exec In[44:48]+In[49]"""
1483 In [60]: exec In[44:48]+In[49]"""
1520
1484
1521 args = parameter_s.split()
1485 args = parameter_s.split()
1522 name,ranges = args[0], args[1:]
1486 name,ranges = args[0], args[1:]
1523 #print 'rng',ranges # dbg
1487 #print 'rng',ranges # dbg
1524 cmds = self.extract_input_slices(ranges)
1488 cmds = self.extract_input_slices(ranges)
1525 macro = Macro(cmds)
1489 macro = Macro(cmds)
1526 self.shell.user_ns.update({name:macro})
1490 self.shell.user_ns.update({name:macro})
1527 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1491 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1528 print 'Macro contents:'
1492 print 'Macro contents:'
1529 print str(macro).rstrip(),
1493 print str(macro).rstrip(),
1530
1494
1531 def magic_save(self,parameter_s = ''):
1495 def magic_save(self,parameter_s = ''):
1532 """Save a set of lines to a given filename.
1496 """Save a set of lines to a given filename.
1533
1497
1534 Usage:\\
1498 Usage:\\
1535 %save filename n1:n2 n3:n4 ... n5 .. n6 ...
1499 %save filename n1:n2 n3:n4 ... n5 .. n6 ...
1536
1500
1537 This function uses the same syntax as %macro for line extraction, but
1501 This function uses the same syntax as %macro for line extraction, but
1538 instead of creating a macro it saves the resulting string to the
1502 instead of creating a macro it saves the resulting string to the
1539 filename you specify.
1503 filename you specify.
1540
1504
1541 It adds a '.py' extension to the file if you don't do so yourself, and
1505 It adds a '.py' extension to the file if you don't do so yourself, and
1542 it asks for confirmation before overwriting existing files."""
1506 it asks for confirmation before overwriting existing files."""
1543
1507
1544 args = parameter_s.split()
1508 args = parameter_s.split()
1545 fname,ranges = args[0], args[1:]
1509 fname,ranges = args[0], args[1:]
1546 if not fname.endswith('.py'):
1510 if not fname.endswith('.py'):
1547 fname += '.py'
1511 fname += '.py'
1548 if os.path.isfile(fname):
1512 if os.path.isfile(fname):
1549 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1513 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1550 if ans.lower() not in ['y','yes']:
1514 if ans.lower() not in ['y','yes']:
1551 print 'Operation cancelled.'
1515 print 'Operation cancelled.'
1552 return
1516 return
1553 cmds = ''.join(self.extract_input_slices(ranges))
1517 cmds = ''.join(self.extract_input_slices(ranges))
1554 f = file(fname,'w')
1518 f = file(fname,'w')
1555 f.write(cmds)
1519 f.write(cmds)
1556 f.close()
1520 f.close()
1557 print 'The following commands were written to file `%s`:' % fname
1521 print 'The following commands were written to file `%s`:' % fname
1558 print cmds
1522 print cmds
1559
1523
1560 def magic_ed(self,parameter_s = ''):
1524 def magic_ed(self,parameter_s = ''):
1561 """Alias to %edit."""
1525 """Alias to %edit."""
1562 return self.magic_edit(parameter_s)
1526 return self.magic_edit(parameter_s)
1563
1527
1564 def magic_edit(self,parameter_s = '',last_call=['','']):
1528 def magic_edit(self,parameter_s = '',last_call=['','']):
1565 """Bring up an editor and execute the resulting code.
1529 """Bring up an editor and execute the resulting code.
1566
1530
1567 Usage:
1531 Usage:
1568 %edit [options] [args]
1532 %edit [options] [args]
1569
1533
1570 %edit runs IPython's editor hook. The default version of this hook is
1534 %edit runs IPython's editor hook. The default version of this hook is
1571 set to call the __IPYTHON__.rc.editor command. This is read from your
1535 set to call the __IPYTHON__.rc.editor command. This is read from your
1572 environment variable $EDITOR. If this isn't found, it will default to
1536 environment variable $EDITOR. If this isn't found, it will default to
1573 vi under Linux/Unix and to notepad under Windows. See the end of this
1537 vi under Linux/Unix and to notepad under Windows. See the end of this
1574 docstring for how to change the editor hook.
1538 docstring for how to change the editor hook.
1575
1539
1576 You can also set the value of this editor via the command line option
1540 You can also set the value of this editor via the command line option
1577 '-editor' or in your ipythonrc file. This is useful if you wish to use
1541 '-editor' or in your ipythonrc file. This is useful if you wish to use
1578 specifically for IPython an editor different from your typical default
1542 specifically for IPython an editor different from your typical default
1579 (and for Windows users who typically don't set environment variables).
1543 (and for Windows users who typically don't set environment variables).
1580
1544
1581 This command allows you to conveniently edit multi-line code right in
1545 This command allows you to conveniently edit multi-line code right in
1582 your IPython session.
1546 your IPython session.
1583
1547
1584 If called without arguments, %edit opens up an empty editor with a
1548 If called without arguments, %edit opens up an empty editor with a
1585 temporary file and will execute the contents of this file when you
1549 temporary file and will execute the contents of this file when you
1586 close it (don't forget to save it!).
1550 close it (don't forget to save it!).
1587
1551
1588 Options:
1552 Options:
1589
1553
1590 -p: this will call the editor with the same data as the previous time
1554 -p: this will call the editor with the same data as the previous time
1591 it was used, regardless of how long ago (in your current session) it
1555 it was used, regardless of how long ago (in your current session) it
1592 was.
1556 was.
1593
1557
1594 -x: do not execute the edited code immediately upon exit. This is
1558 -x: do not execute the edited code immediately upon exit. This is
1595 mainly useful if you are editing programs which need to be called with
1559 mainly useful if you are editing programs which need to be called with
1596 command line arguments, which you can then do using %run.
1560 command line arguments, which you can then do using %run.
1597
1561
1598 Arguments:
1562 Arguments:
1599
1563
1600 If arguments are given, the following possibilites exist:
1564 If arguments are given, the following possibilites exist:
1601
1565
1602 - The arguments are numbers or pairs of colon-separated numbers (like
1566 - The arguments are numbers or pairs of colon-separated numbers (like
1603 1 4:8 9). These are interpreted as lines of previous input to be
1567 1 4:8 9). These are interpreted as lines of previous input to be
1604 loaded into the editor. The syntax is the same of the %macro command.
1568 loaded into the editor. The syntax is the same of the %macro command.
1605
1569
1606 - If the argument doesn't start with a number, it is evaluated as a
1570 - If the argument doesn't start with a number, it is evaluated as a
1607 variable and its contents loaded into the editor. You can thus edit
1571 variable and its contents loaded into the editor. You can thus edit
1608 any string which contains python code (including the result of
1572 any string which contains python code (including the result of
1609 previous edits).
1573 previous edits).
1610
1574
1611 - If the argument is the name of an object (other than a string),
1575 - If the argument is the name of an object (other than a string),
1612 IPython will try to locate the file where it was defined and open the
1576 IPython will try to locate the file where it was defined and open the
1613 editor at the point where it is defined. You can use `%edit function`
1577 editor at the point where it is defined. You can use `%edit function`
1614 to load an editor exactly at the point where 'function' is defined,
1578 to load an editor exactly at the point where 'function' is defined,
1615 edit it and have the file be executed automatically.
1579 edit it and have the file be executed automatically.
1616
1580
1617 Note: opening at an exact line is only supported under Unix, and some
1581 Note: opening at an exact line is only supported under Unix, and some
1618 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1582 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1619 '+NUMBER' parameter necessary for this feature. Good editors like
1583 '+NUMBER' parameter necessary for this feature. Good editors like
1620 (X)Emacs, vi, jed, pico and joe all do.
1584 (X)Emacs, vi, jed, pico and joe all do.
1621
1585
1622 - If the argument is not found as a variable, IPython will look for a
1586 - If the argument is not found as a variable, IPython will look for a
1623 file with that name (adding .py if necessary) and load it into the
1587 file with that name (adding .py if necessary) and load it into the
1624 editor. It will execute its contents with execfile() when you exit,
1588 editor. It will execute its contents with execfile() when you exit,
1625 loading any code in the file into your interactive namespace.
1589 loading any code in the file into your interactive namespace.
1626
1590
1627 After executing your code, %edit will return as output the code you
1591 After executing your code, %edit will return as output the code you
1628 typed in the editor (except when it was an existing file). This way
1592 typed in the editor (except when it was an existing file). This way
1629 you can reload the code in further invocations of %edit as a variable,
1593 you can reload the code in further invocations of %edit as a variable,
1630 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1594 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1631 the output.
1595 the output.
1632
1596
1633 Note that %edit is also available through the alias %ed.
1597 Note that %edit is also available through the alias %ed.
1634
1598
1635 This is an example of creating a simple function inside the editor and
1599 This is an example of creating a simple function inside the editor and
1636 then modifying it. First, start up the editor:
1600 then modifying it. First, start up the editor:
1637
1601
1638 In [1]: ed\\
1602 In [1]: ed\\
1639 Editing... done. Executing edited code...\\
1603 Editing... done. Executing edited code...\\
1640 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1604 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1641
1605
1642 We can then call the function foo():
1606 We can then call the function foo():
1643
1607
1644 In [2]: foo()\\
1608 In [2]: foo()\\
1645 foo() was defined in an editing session
1609 foo() was defined in an editing session
1646
1610
1647 Now we edit foo. IPython automatically loads the editor with the
1611 Now we edit foo. IPython automatically loads the editor with the
1648 (temporary) file where foo() was previously defined:
1612 (temporary) file where foo() was previously defined:
1649
1613
1650 In [3]: ed foo\\
1614 In [3]: ed foo\\
1651 Editing... done. Executing edited code...
1615 Editing... done. Executing edited code...
1652
1616
1653 And if we call foo() again we get the modified version:
1617 And if we call foo() again we get the modified version:
1654
1618
1655 In [4]: foo()\\
1619 In [4]: foo()\\
1656 foo() has now been changed!
1620 foo() has now been changed!
1657
1621
1658 Here is an example of how to edit a code snippet successive
1622 Here is an example of how to edit a code snippet successive
1659 times. First we call the editor:
1623 times. First we call the editor:
1660
1624
1661 In [8]: ed\\
1625 In [8]: ed\\
1662 Editing... done. Executing edited code...\\
1626 Editing... done. Executing edited code...\\
1663 hello\\
1627 hello\\
1664 Out[8]: "print 'hello'\\n"
1628 Out[8]: "print 'hello'\\n"
1665
1629
1666 Now we call it again with the previous output (stored in _):
1630 Now we call it again with the previous output (stored in _):
1667
1631
1668 In [9]: ed _\\
1632 In [9]: ed _\\
1669 Editing... done. Executing edited code...\\
1633 Editing... done. Executing edited code...\\
1670 hello world\\
1634 hello world\\
1671 Out[9]: "print 'hello world'\\n"
1635 Out[9]: "print 'hello world'\\n"
1672
1636
1673 Now we call it with the output #8 (stored in _8, also as Out[8]):
1637 Now we call it with the output #8 (stored in _8, also as Out[8]):
1674
1638
1675 In [10]: ed _8\\
1639 In [10]: ed _8\\
1676 Editing... done. Executing edited code...\\
1640 Editing... done. Executing edited code...\\
1677 hello again\\
1641 hello again\\
1678 Out[10]: "print 'hello again'\\n"
1642 Out[10]: "print 'hello again'\\n"
1679
1643
1680
1644
1681 Changing the default editor hook:
1645 Changing the default editor hook:
1682
1646
1683 If you wish to write your own editor hook, you can put it in a
1647 If you wish to write your own editor hook, you can put it in a
1684 configuration file which you load at startup time. The default hook
1648 configuration file which you load at startup time. The default hook
1685 is defined in the IPython.hooks module, and you can use that as a
1649 is defined in the IPython.hooks module, and you can use that as a
1686 starting example for further modifications. That file also has
1650 starting example for further modifications. That file also has
1687 general instructions on how to set a new hook for use once you've
1651 general instructions on how to set a new hook for use once you've
1688 defined it."""
1652 defined it."""
1689
1653
1690 # FIXME: This function has become a convoluted mess. It needs a
1654 # FIXME: This function has become a convoluted mess. It needs a
1691 # ground-up rewrite with clean, simple logic.
1655 # ground-up rewrite with clean, simple logic.
1692
1656
1693 def make_filename(arg):
1657 def make_filename(arg):
1694 "Make a filename from the given args"
1658 "Make a filename from the given args"
1695 try:
1659 try:
1696 filename = get_py_filename(arg)
1660 filename = get_py_filename(arg)
1697 except IOError:
1661 except IOError:
1698 if args.endswith('.py'):
1662 if args.endswith('.py'):
1699 filename = arg
1663 filename = arg
1700 else:
1664 else:
1701 filename = None
1665 filename = None
1702 return filename
1666 return filename
1703
1667
1704 # custom exceptions
1668 # custom exceptions
1705 class DataIsObject(Exception): pass
1669 class DataIsObject(Exception): pass
1706
1670
1707 opts,args = self.parse_options(parameter_s,'px')
1671 opts,args = self.parse_options(parameter_s,'px')
1708
1672
1709 # Default line number value
1673 # Default line number value
1710 lineno = None
1674 lineno = None
1711 if opts.has_key('p'):
1675 if opts.has_key('p'):
1712 args = '_%s' % last_call[0]
1676 args = '_%s' % last_call[0]
1713 if not self.shell.user_ns.has_key(args):
1677 if not self.shell.user_ns.has_key(args):
1714 args = last_call[1]
1678 args = last_call[1]
1715
1679
1716 # use last_call to remember the state of the previous call, but don't
1680 # use last_call to remember the state of the previous call, but don't
1717 # let it be clobbered by successive '-p' calls.
1681 # let it be clobbered by successive '-p' calls.
1718 try:
1682 try:
1719 last_call[0] = self.shell.outputcache.prompt_count
1683 last_call[0] = self.shell.outputcache.prompt_count
1720 if not opts.has_key('p'):
1684 if not opts.has_key('p'):
1721 last_call[1] = parameter_s
1685 last_call[1] = parameter_s
1722 except:
1686 except:
1723 pass
1687 pass
1724
1688
1725 # by default this is done with temp files, except when the given
1689 # by default this is done with temp files, except when the given
1726 # arg is a filename
1690 # arg is a filename
1727 use_temp = 1
1691 use_temp = 1
1728
1692
1729 if re.match(r'\d',args):
1693 if re.match(r'\d',args):
1730 # Mode where user specifies ranges of lines, like in %macro.
1694 # Mode where user specifies ranges of lines, like in %macro.
1731 # This means that you can't edit files whose names begin with
1695 # This means that you can't edit files whose names begin with
1732 # numbers this way. Tough.
1696 # numbers this way. Tough.
1733 ranges = args.split()
1697 ranges = args.split()
1734 data = ''.join(self.extract_input_slices(ranges))
1698 data = ''.join(self.extract_input_slices(ranges))
1735 elif args.endswith('.py'):
1699 elif args.endswith('.py'):
1736 filename = make_filename(args)
1700 filename = make_filename(args)
1737 data = ''
1701 data = ''
1738 use_temp = 0
1702 use_temp = 0
1739 elif args:
1703 elif args:
1740 try:
1704 try:
1741 # Load the parameter given as a variable. If not a string,
1705 # Load the parameter given as a variable. If not a string,
1742 # process it as an object instead (below)
1706 # process it as an object instead (below)
1743
1707
1744 #print '*** args',args,'type',type(args) # dbg
1708 #print '*** args',args,'type',type(args) # dbg
1745 data = eval(args,self.shell.user_ns)
1709 data = eval(args,self.shell.user_ns)
1746 if not type(data) in StringTypes:
1710 if not type(data) in StringTypes:
1747 raise DataIsObject
1711 raise DataIsObject
1748 except (NameError,SyntaxError):
1712 except (NameError,SyntaxError):
1749 # given argument is not a variable, try as a filename
1713 # given argument is not a variable, try as a filename
1750 filename = make_filename(args)
1714 filename = make_filename(args)
1751 if filename is None:
1715 if filename is None:
1752 warn("Argument given (%s) can't be found as a variable "
1716 warn("Argument given (%s) can't be found as a variable "
1753 "or as a filename." % args)
1717 "or as a filename." % args)
1754 return
1718 return
1755 data = ''
1719 data = ''
1756 use_temp = 0
1720 use_temp = 0
1757 except DataIsObject:
1721 except DataIsObject:
1758 # For objects, try to edit the file where they are defined
1722 # For objects, try to edit the file where they are defined
1759 try:
1723 try:
1760 filename = inspect.getabsfile(data)
1724 filename = inspect.getabsfile(data)
1761 datafile = 1
1725 datafile = 1
1762 except TypeError:
1726 except TypeError:
1763 filename = make_filename(args)
1727 filename = make_filename(args)
1764 datafile = 1
1728 datafile = 1
1765 warn('Could not find file where `%s` is defined.\n'
1729 warn('Could not find file where `%s` is defined.\n'
1766 'Opening a file named `%s`' % (args,filename))
1730 'Opening a file named `%s`' % (args,filename))
1767 # Now, make sure we can actually read the source (if it was in
1731 # Now, make sure we can actually read the source (if it was in
1768 # a temp file it's gone by now).
1732 # a temp file it's gone by now).
1769 if datafile:
1733 if datafile:
1770 try:
1734 try:
1771 lineno = inspect.getsourcelines(data)[1]
1735 lineno = inspect.getsourcelines(data)[1]
1772 except IOError:
1736 except IOError:
1773 filename = make_filename(args)
1737 filename = make_filename(args)
1774 if filename is None:
1738 if filename is None:
1775 warn('The file `%s` where `%s` was defined cannot '
1739 warn('The file `%s` where `%s` was defined cannot '
1776 'be read.' % (filename,data))
1740 'be read.' % (filename,data))
1777 return
1741 return
1778 use_temp = 0
1742 use_temp = 0
1779 else:
1743 else:
1780 data = ''
1744 data = ''
1781
1745
1782 if use_temp:
1746 if use_temp:
1783 filename = tempfile.mktemp('.py')
1747 filename = tempfile.mktemp('.py')
1784 self.shell.tempfiles.append(filename)
1748 self.shell.tempfiles.append(filename)
1785
1749
1786 if data and use_temp:
1750 if data and use_temp:
1787 tmp_file = open(filename,'w')
1751 tmp_file = open(filename,'w')
1788 tmp_file.write(data)
1752 tmp_file.write(data)
1789 tmp_file.close()
1753 tmp_file.close()
1790
1754
1791 # do actual editing here
1755 # do actual editing here
1792 print 'Editing...',
1756 print 'Editing...',
1793 sys.stdout.flush()
1757 sys.stdout.flush()
1794 self.shell.hooks.editor(filename,lineno)
1758 self.shell.hooks.editor(filename,lineno)
1795 if opts.has_key('x'): # -x prevents actual execution
1759 if opts.has_key('x'): # -x prevents actual execution
1796 print
1760 print
1797 else:
1761 else:
1798 print 'done. Executing edited code...'
1762 print 'done. Executing edited code...'
1799 try:
1763 try:
1800 execfile(filename,self.shell.user_ns)
1764 execfile(filename,self.shell.user_ns)
1801 except IOError,msg:
1765 except IOError,msg:
1802 if msg.filename == filename:
1766 if msg.filename == filename:
1803 warn('File not found. Did you forget to save?')
1767 warn('File not found. Did you forget to save?')
1804 return
1768 return
1805 else:
1769 else:
1806 self.shell.showtraceback()
1770 self.shell.showtraceback()
1807 except:
1771 except:
1808 self.shell.showtraceback()
1772 self.shell.showtraceback()
1809 if use_temp:
1773 if use_temp:
1810 contents = open(filename).read()
1774 contents = open(filename).read()
1811 return contents
1775 return contents
1812
1776
1813 def magic_xmode(self,parameter_s = ''):
1777 def magic_xmode(self,parameter_s = ''):
1814 """Switch modes for the exception handlers.
1778 """Switch modes for the exception handlers.
1815
1779
1816 Valid modes: Plain, Context and Verbose.
1780 Valid modes: Plain, Context and Verbose.
1817
1781
1818 If called without arguments, acts as a toggle."""
1782 If called without arguments, acts as a toggle."""
1819
1783
1820 new_mode = parameter_s.strip().capitalize()
1784 new_mode = parameter_s.strip().capitalize()
1821 try:
1785 try:
1822 self.InteractiveTB.set_mode(mode = new_mode)
1786 self.InteractiveTB.set_mode(mode = new_mode)
1823 print 'Exception reporting mode:',self.InteractiveTB.mode
1787 print 'Exception reporting mode:',self.InteractiveTB.mode
1824 except:
1788 except:
1825 warn('Error changing exception modes.\n' + str(sys.exc_info()[1]))
1789 warn('Error changing exception modes.\n' + str(sys.exc_info()[1]))
1826
1790
1827 def magic_colors(self,parameter_s = ''):
1791 def magic_colors(self,parameter_s = ''):
1828 """Switch color scheme for prompts, info system and exception handlers.
1792 """Switch color scheme for prompts, info system and exception handlers.
1829
1793
1830 Currently implemented schemes: NoColor, Linux, LightBG.
1794 Currently implemented schemes: NoColor, Linux, LightBG.
1831
1795
1832 Color scheme names are not case-sensitive."""
1796 Color scheme names are not case-sensitive."""
1833
1797
1834 new_scheme = parameter_s.strip()
1798 new_scheme = parameter_s.strip()
1835 if not new_scheme:
1799 if not new_scheme:
1836 print 'You must specify a color scheme.'
1800 print 'You must specify a color scheme.'
1837 return
1801 return
1838 # Under Windows, check for Gary Bishop's readline, which is necessary
1802 # Under Windows, check for Gary Bishop's readline, which is necessary
1839 # for ANSI coloring
1803 # for ANSI coloring
1840 if os.name in ['nt','dos']:
1804 if os.name in ['nt','dos']:
1841 try:
1805 try:
1842 import readline
1806 import readline
1843 except ImportError:
1807 except ImportError:
1844 has_readline = 0
1808 has_readline = 0
1845 else:
1809 else:
1846 try:
1810 try:
1847 readline.GetOutputFile()
1811 readline.GetOutputFile()
1848 except AttributeError:
1812 except AttributeError:
1849 has_readline = 0
1813 has_readline = 0
1850 else:
1814 else:
1851 has_readline = 1
1815 has_readline = 1
1852 if not has_readline:
1816 if not has_readline:
1853 msg = """\
1817 msg = """\
1854 Proper color support under MS Windows requires Gary Bishop's readline library.
1818 Proper color support under MS Windows requires Gary Bishop's readline library.
1855 You can find it at:
1819 You can find it at:
1856 http://sourceforge.net/projects/uncpythontools
1820 http://sourceforge.net/projects/uncpythontools
1857 Gary's readline needs the ctypes module, from:
1821 Gary's readline needs the ctypes module, from:
1858 http://starship.python.net/crew/theller/ctypes
1822 http://starship.python.net/crew/theller/ctypes
1859
1823
1860 Defaulting color scheme to 'NoColor'"""
1824 Defaulting color scheme to 'NoColor'"""
1861 new_scheme = 'NoColor'
1825 new_scheme = 'NoColor'
1862 warn(msg)
1826 warn(msg)
1863
1827
1864 # Set prompt colors
1828 # Set prompt colors
1865 try:
1829 try:
1866 self.shell.outputcache.set_colors(new_scheme)
1830 self.shell.outputcache.set_colors(new_scheme)
1867 except:
1831 except:
1868 warn('Error changing prompt color schemes.\n'
1832 warn('Error changing prompt color schemes.\n'
1869 + str(sys.exc_info()[1]))
1833 + str(sys.exc_info()[1]))
1870 else:
1834 else:
1871 self.shell.rc.colors = \
1835 self.shell.rc.colors = \
1872 self.shell.outputcache.color_table.active_scheme_name
1836 self.shell.outputcache.color_table.active_scheme_name
1873 # Set exception colors
1837 # Set exception colors
1874 try:
1838 try:
1875 self.shell.InteractiveTB.set_colors(scheme = new_scheme)
1839 self.shell.InteractiveTB.set_colors(scheme = new_scheme)
1876 self.shell.SyntaxTB.set_colors(scheme = new_scheme)
1840 self.shell.SyntaxTB.set_colors(scheme = new_scheme)
1877 except:
1841 except:
1878 warn('Error changing exception color schemes.\n'
1842 warn('Error changing exception color schemes.\n'
1879 + str(sys.exc_info()[1]))
1843 + str(sys.exc_info()[1]))
1880 # Set info (for 'object?') colors
1844 # Set info (for 'object?') colors
1881 if self.shell.rc.color_info:
1845 if self.shell.rc.color_info:
1882 try:
1846 try:
1883 self.shell.inspector.set_active_scheme(new_scheme)
1847 self.shell.inspector.set_active_scheme(new_scheme)
1884 except:
1848 except:
1885 warn('Error changing object inspector color schemes.\n'
1849 warn('Error changing object inspector color schemes.\n'
1886 + str(sys.exc_info()[1]))
1850 + str(sys.exc_info()[1]))
1887 else:
1851 else:
1888 self.shell.inspector.set_active_scheme('NoColor')
1852 self.shell.inspector.set_active_scheme('NoColor')
1889
1853
1890 def magic_color_info(self,parameter_s = ''):
1854 def magic_color_info(self,parameter_s = ''):
1891 """Toggle color_info.
1855 """Toggle color_info.
1892
1856
1893 The color_info configuration parameter controls whether colors are
1857 The color_info configuration parameter controls whether colors are
1894 used for displaying object details (by things like %psource, %pfile or
1858 used for displaying object details (by things like %psource, %pfile or
1895 the '?' system). This function toggles this value with each call.
1859 the '?' system). This function toggles this value with each call.
1896
1860
1897 Note that unless you have a fairly recent pager (less works better
1861 Note that unless you have a fairly recent pager (less works better
1898 than more) in your system, using colored object information displays
1862 than more) in your system, using colored object information displays
1899 will not work properly. Test it and see."""
1863 will not work properly. Test it and see."""
1900
1864
1901 self.shell.rc.color_info = 1 - self.shell.rc.color_info
1865 self.shell.rc.color_info = 1 - self.shell.rc.color_info
1902 self.magic_colors(self.shell.rc.colors)
1866 self.magic_colors(self.shell.rc.colors)
1903 print 'Object introspection functions have now coloring:',
1867 print 'Object introspection functions have now coloring:',
1904 print ['OFF','ON'][self.shell.rc.color_info]
1868 print ['OFF','ON'][self.shell.rc.color_info]
1905
1869
1906 def magic_Pprint(self, parameter_s=''):
1870 def magic_Pprint(self, parameter_s=''):
1907 """Toggle pretty printing on/off."""
1871 """Toggle pretty printing on/off."""
1908
1872
1909 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
1873 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
1910 print 'Pretty printing has been turned', \
1874 print 'Pretty printing has been turned', \
1911 ['OFF','ON'][self.shell.outputcache.Pprint]
1875 ['OFF','ON'][self.shell.outputcache.Pprint]
1912
1876
1913 def magic_Exit(self, parameter_s=''):
1877 def magic_Exit(self, parameter_s=''):
1914 """Exit IPython without confirmation."""
1878 """Exit IPython without confirmation."""
1915
1879
1916 self.shell.exit_now = True
1880 self.shell.exit_now = True
1917
1881
1918 def magic_Quit(self, parameter_s=''):
1882 def magic_Quit(self, parameter_s=''):
1919 """Exit IPython without confirmation (like %Exit)."""
1883 """Exit IPython without confirmation (like %Exit)."""
1920
1884
1921 self.shell.exit_now = True
1885 self.shell.exit_now = True
1922
1886
1923 #......................................................................
1887 #......................................................................
1924 # Functions to implement unix shell-type things
1888 # Functions to implement unix shell-type things
1925
1889
1926 def magic_alias(self, parameter_s = ''):
1890 def magic_alias(self, parameter_s = ''):
1927 """Define an alias for a system command.
1891 """Define an alias for a system command.
1928
1892
1929 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1893 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
1930
1894
1931 Then, typing 'alias_name params' will execute the system command 'cmd
1895 Then, typing 'alias_name params' will execute the system command 'cmd
1932 params' (from your underlying operating system).
1896 params' (from your underlying operating system).
1933
1897
1934 Aliases have lower precedence than magic functions and Python normal
1898 Aliases have lower precedence than magic functions and Python normal
1935 variables, so if 'foo' is both a Python variable and an alias, the
1899 variables, so if 'foo' is both a Python variable and an alias, the
1936 alias can not be executed until 'del foo' removes the Python variable.
1900 alias can not be executed until 'del foo' removes the Python variable.
1937
1901
1938 You can use the %l specifier in an alias definition to represent the
1902 You can use the %l specifier in an alias definition to represent the
1939 whole line when the alias is called. For example:
1903 whole line when the alias is called. For example:
1940
1904
1941 In [2]: alias all echo "Input in brackets: <%l>"\\
1905 In [2]: alias all echo "Input in brackets: <%l>"\\
1942 In [3]: all hello world\\
1906 In [3]: all hello world\\
1943 Input in brackets: <hello world>
1907 Input in brackets: <hello world>
1944
1908
1945 You can also define aliases with parameters using %s specifiers (one
1909 You can also define aliases with parameters using %s specifiers (one
1946 per parameter):
1910 per parameter):
1947
1911
1948 In [1]: alias parts echo first %s second %s\\
1912 In [1]: alias parts echo first %s second %s\\
1949 In [2]: %parts A B\\
1913 In [2]: %parts A B\\
1950 first A second B\\
1914 first A second B\\
1951 In [3]: %parts A\\
1915 In [3]: %parts A\\
1952 Incorrect number of arguments: 2 expected.\\
1916 Incorrect number of arguments: 2 expected.\\
1953 parts is an alias to: 'echo first %s second %s'
1917 parts is an alias to: 'echo first %s second %s'
1954
1918
1955 Note that %l and %s are mutually exclusive. You can only use one or
1919 Note that %l and %s are mutually exclusive. You can only use one or
1956 the other in your aliases.
1920 the other in your aliases.
1957
1921
1958 Aliases expand Python variables just like system calls using ! or !!
1922 Aliases expand Python variables just like system calls using ! or !!
1959 do: all expressions prefixed with '$' get expanded. For details of
1923 do: all expressions prefixed with '$' get expanded. For details of
1960 the semantic rules, see PEP-215:
1924 the semantic rules, see PEP-215:
1961 http://www.python.org/peps/pep-0215.html. This is the library used by
1925 http://www.python.org/peps/pep-0215.html. This is the library used by
1962 IPython for variable expansion. If you want to access a true shell
1926 IPython for variable expansion. If you want to access a true shell
1963 variable, an extra $ is necessary to prevent its expansion by IPython:
1927 variable, an extra $ is necessary to prevent its expansion by IPython:
1964
1928
1965 In [6]: alias show echo\\
1929 In [6]: alias show echo\\
1966 In [7]: PATH='A Python string'\\
1930 In [7]: PATH='A Python string'\\
1967 In [8]: show $PATH\\
1931 In [8]: show $PATH\\
1968 A Python string\\
1932 A Python string\\
1969 In [9]: show $$PATH\\
1933 In [9]: show $$PATH\\
1970 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1934 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1971
1935
1972 You can use the alias facility to acess all of $PATH. See the %rehash
1936 You can use the alias facility to acess all of $PATH. See the %rehash
1973 and %rehashx functions, which automatically create aliases for the
1937 and %rehashx functions, which automatically create aliases for the
1974 contents of your $PATH.
1938 contents of your $PATH.
1975
1939
1976 If called with no parameters, %alias prints the current alias table."""
1940 If called with no parameters, %alias prints the current alias table."""
1977
1941
1978 par = parameter_s.strip()
1942 par = parameter_s.strip()
1979 if not par:
1943 if not par:
1980 if self.shell.rc.automagic:
1944 if self.shell.rc.automagic:
1981 prechar = ''
1945 prechar = ''
1982 else:
1946 else:
1983 prechar = self.shell.ESC_MAGIC
1947 prechar = self.shell.ESC_MAGIC
1984 print 'Alias\t\tSystem Command\n'+'-'*30
1948 print 'Alias\t\tSystem Command\n'+'-'*30
1985 atab = self.shell.alias_table
1949 atab = self.shell.alias_table
1986 aliases = atab.keys()
1950 aliases = atab.keys()
1987 aliases.sort()
1951 aliases.sort()
1988 for alias in aliases:
1952 for alias in aliases:
1989 print prechar+alias+'\t\t'+atab[alias][1]
1953 print prechar+alias+'\t\t'+atab[alias][1]
1990 print '-'*30+'\nTotal number of aliases:',len(aliases)
1954 print '-'*30+'\nTotal number of aliases:',len(aliases)
1991 return
1955 return
1992 try:
1956 try:
1993 alias,cmd = par.split(None,1)
1957 alias,cmd = par.split(None,1)
1994 except:
1958 except:
1995 print OInspect.getdoc(self.magic_alias)
1959 print OInspect.getdoc(self.magic_alias)
1996 else:
1960 else:
1997 nargs = cmd.count('%s')
1961 nargs = cmd.count('%s')
1998 if nargs>0 and cmd.find('%l')>=0:
1962 if nargs>0 and cmd.find('%l')>=0:
1999 error('The %s and %l specifiers are mutually exclusive '
1963 error('The %s and %l specifiers are mutually exclusive '
2000 'in alias definitions.')
1964 'in alias definitions.')
2001 else: # all looks OK
1965 else: # all looks OK
2002 self.shell.alias_table[alias] = (nargs,cmd)
1966 self.shell.alias_table[alias] = (nargs,cmd)
2003 self.shell.alias_table_validate(verbose=1)
1967 self.shell.alias_table_validate(verbose=1)
2004 # end magic_alias
1968 # end magic_alias
2005
1969
2006 def magic_unalias(self, parameter_s = ''):
1970 def magic_unalias(self, parameter_s = ''):
2007 """Remove an alias"""
1971 """Remove an alias"""
2008
1972
2009 aname = parameter_s.strip()
1973 aname = parameter_s.strip()
2010 if aname in self.shell.alias_table:
1974 if aname in self.shell.alias_table:
2011 del self.shell.alias_table[aname]
1975 del self.shell.alias_table[aname]
2012
1976
2013 def magic_rehash(self, parameter_s = ''):
1977 def magic_rehash(self, parameter_s = ''):
2014 """Update the alias table with all entries in $PATH.
1978 """Update the alias table with all entries in $PATH.
2015
1979
2016 This version does no checks on execute permissions or whether the
1980 This version does no checks on execute permissions or whether the
2017 contents of $PATH are truly files (instead of directories or something
1981 contents of $PATH are truly files (instead of directories or something
2018 else). For such a safer (but slower) version, use %rehashx."""
1982 else). For such a safer (but slower) version, use %rehashx."""
2019
1983
2020 # This function (and rehashx) manipulate the alias_table directly
1984 # This function (and rehashx) manipulate the alias_table directly
2021 # rather than calling magic_alias, for speed reasons. A rehash on a
1985 # rather than calling magic_alias, for speed reasons. A rehash on a
2022 # typical Linux box involves several thousand entries, so efficiency
1986 # typical Linux box involves several thousand entries, so efficiency
2023 # here is a top concern.
1987 # here is a top concern.
2024
1988
2025 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
1989 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2026 alias_table = self.shell.alias_table
1990 alias_table = self.shell.alias_table
2027 for pdir in path:
1991 for pdir in path:
2028 for ff in os.listdir(pdir):
1992 for ff in os.listdir(pdir):
2029 # each entry in the alias table must be (N,name), where
1993 # each entry in the alias table must be (N,name), where
2030 # N is the number of positional arguments of the alias.
1994 # N is the number of positional arguments of the alias.
2031 alias_table[ff] = (0,ff)
1995 alias_table[ff] = (0,ff)
2032 # Make sure the alias table doesn't contain keywords or builtins
1996 # Make sure the alias table doesn't contain keywords or builtins
2033 self.shell.alias_table_validate()
1997 self.shell.alias_table_validate()
2034 # Call again init_auto_alias() so we get 'rm -i' and other modified
1998 # Call again init_auto_alias() so we get 'rm -i' and other modified
2035 # aliases since %rehash will probably clobber them
1999 # aliases since %rehash will probably clobber them
2036 self.shell.init_auto_alias()
2000 self.shell.init_auto_alias()
2037
2001
2038 def magic_rehashx(self, parameter_s = ''):
2002 def magic_rehashx(self, parameter_s = ''):
2039 """Update the alias table with all executable files in $PATH.
2003 """Update the alias table with all executable files in $PATH.
2040
2004
2041 This version explicitly checks that every entry in $PATH is a file
2005 This version explicitly checks that every entry in $PATH is a file
2042 with execute access (os.X_OK), so it is much slower than %rehash.
2006 with execute access (os.X_OK), so it is much slower than %rehash.
2043
2007
2044 Under Windows, it checks executability as a match agains a
2008 Under Windows, it checks executability as a match agains a
2045 '|'-separated string of extensions, stored in the IPython config
2009 '|'-separated string of extensions, stored in the IPython config
2046 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2010 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2047
2011
2048 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2012 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2049 alias_table = self.shell.alias_table
2013 alias_table = self.shell.alias_table
2050
2014
2051 if os.name == 'posix':
2015 if os.name == 'posix':
2052 isexec = lambda fname:os.path.isfile(fname) and \
2016 isexec = lambda fname:os.path.isfile(fname) and \
2053 os.access(fname,os.X_OK)
2017 os.access(fname,os.X_OK)
2054 else:
2018 else:
2055
2019
2056 try:
2020 try:
2057 winext = os.environ['pathext'].replace(';','|').replace('.','')
2021 winext = os.environ['pathext'].replace(';','|').replace('.','')
2058 except KeyError:
2022 except KeyError:
2059 winext = 'exe|com|bat'
2023 winext = 'exe|com|bat'
2060
2024
2061 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2025 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2062 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2026 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2063 savedir = os.getcwd()
2027 savedir = os.getcwd()
2064 try:
2028 try:
2065 # write the whole loop for posix/Windows so we don't have an if in
2029 # write the whole loop for posix/Windows so we don't have an if in
2066 # the innermost part
2030 # the innermost part
2067 if os.name == 'posix':
2031 if os.name == 'posix':
2068 for pdir in path:
2032 for pdir in path:
2069 os.chdir(pdir)
2033 os.chdir(pdir)
2070 for ff in os.listdir(pdir):
2034 for ff in os.listdir(pdir):
2071 if isexec(ff):
2035 if isexec(ff):
2072 # each entry in the alias table must be (N,name),
2036 # each entry in the alias table must be (N,name),
2073 # where N is the number of positional arguments of the
2037 # where N is the number of positional arguments of the
2074 # alias.
2038 # alias.
2075 alias_table[ff] = (0,ff)
2039 alias_table[ff] = (0,ff)
2076 else:
2040 else:
2077 for pdir in path:
2041 for pdir in path:
2078 os.chdir(pdir)
2042 os.chdir(pdir)
2079 for ff in os.listdir(pdir):
2043 for ff in os.listdir(pdir):
2080 if isexec(ff):
2044 if isexec(ff):
2081 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2045 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2082 # Make sure the alias table doesn't contain keywords or builtins
2046 # Make sure the alias table doesn't contain keywords or builtins
2083 self.shell.alias_table_validate()
2047 self.shell.alias_table_validate()
2084 # Call again init_auto_alias() so we get 'rm -i' and other
2048 # Call again init_auto_alias() so we get 'rm -i' and other
2085 # modified aliases since %rehashx will probably clobber them
2049 # modified aliases since %rehashx will probably clobber them
2086 self.shell.init_auto_alias()
2050 self.shell.init_auto_alias()
2087 finally:
2051 finally:
2088 os.chdir(savedir)
2052 os.chdir(savedir)
2089
2053
2090 def magic_pwd(self, parameter_s = ''):
2054 def magic_pwd(self, parameter_s = ''):
2091 """Return the current working directory path."""
2055 """Return the current working directory path."""
2092 return os.getcwd()
2056 return os.getcwd()
2093
2057
2094 def magic_cd(self, parameter_s=''):
2058 def magic_cd(self, parameter_s=''):
2095 """Change the current working directory.
2059 """Change the current working directory.
2096
2060
2097 This command automatically maintains an internal list of directories
2061 This command automatically maintains an internal list of directories
2098 you visit during your IPython session, in the variable _dh. The
2062 you visit during your IPython session, in the variable _dh. The
2099 command %dhist shows this history nicely formatted.
2063 command %dhist shows this history nicely formatted.
2100
2064
2101 Usage:
2065 Usage:
2102
2066
2103 cd 'dir': changes to directory 'dir'.
2067 cd 'dir': changes to directory 'dir'.
2104
2068
2105 cd -: changes to the last visited directory.
2069 cd -: changes to the last visited directory.
2106
2070
2107 cd -<n>: changes to the n-th directory in the directory history.
2071 cd -<n>: changes to the n-th directory in the directory history.
2108
2072
2109 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2073 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2110 (note: cd <bookmark_name> is enough if there is no
2074 (note: cd <bookmark_name> is enough if there is no
2111 directory <bookmark_name>, but a bookmark with the name exists.)
2075 directory <bookmark_name>, but a bookmark with the name exists.)
2112
2076
2113 Options:
2077 Options:
2114
2078
2115 -q: quiet. Do not print the working directory after the cd command is
2079 -q: quiet. Do not print the working directory after the cd command is
2116 executed. By default IPython's cd command does print this directory,
2080 executed. By default IPython's cd command does print this directory,
2117 since the default prompts do not display path information.
2081 since the default prompts do not display path information.
2118
2082
2119 Note that !cd doesn't work for this purpose because the shell where
2083 Note that !cd doesn't work for this purpose because the shell where
2120 !command runs is immediately discarded after executing 'command'."""
2084 !command runs is immediately discarded after executing 'command'."""
2121
2085
2122 parameter_s = parameter_s.strip()
2086 parameter_s = parameter_s.strip()
2123 bkms = self.shell.persist.get("bookmarks",{})
2087 bkms = self.shell.persist.get("bookmarks",{})
2124
2088
2125 numcd = re.match(r'(-)(\d+)$',parameter_s)
2089 numcd = re.match(r'(-)(\d+)$',parameter_s)
2126 # jump in directory history by number
2090 # jump in directory history by number
2127 if numcd:
2091 if numcd:
2128 nn = int(numcd.group(2))
2092 nn = int(numcd.group(2))
2129 try:
2093 try:
2130 ps = self.shell.user_ns['_dh'][nn]
2094 ps = self.shell.user_ns['_dh'][nn]
2131 except IndexError:
2095 except IndexError:
2132 print 'The requested directory does not exist in history.'
2096 print 'The requested directory does not exist in history.'
2133 return
2097 return
2134 else:
2098 else:
2135 opts = {}
2099 opts = {}
2136 else:
2100 else:
2137 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2101 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2138 # jump to previous
2102 # jump to previous
2139 if ps == '-':
2103 if ps == '-':
2140 try:
2104 try:
2141 ps = self.shell.user_ns['_dh'][-2]
2105 ps = self.shell.user_ns['_dh'][-2]
2142 except IndexError:
2106 except IndexError:
2143 print 'No previous directory to change to.'
2107 print 'No previous directory to change to.'
2144 return
2108 return
2145 # jump to bookmark
2109 # jump to bookmark
2146 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2110 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2147 if bkms.has_key(ps):
2111 if bkms.has_key(ps):
2148 target = bkms[ps]
2112 target = bkms[ps]
2149 print '(bookmark:%s) -> %s' % (ps,target)
2113 print '(bookmark:%s) -> %s' % (ps,target)
2150 ps = target
2114 ps = target
2151 else:
2115 else:
2152 if bkms:
2116 if bkms:
2153 error("Bookmark '%s' not found. "
2117 error("Bookmark '%s' not found. "
2154 "Use '%bookmark -l' to see your bookmarks." % ps)
2118 "Use '%bookmark -l' to see your bookmarks." % ps)
2155 else:
2119 else:
2156 print "Bookmarks not set - use %bookmark <bookmarkname>"
2120 print "Bookmarks not set - use %bookmark <bookmarkname>"
2157 return
2121 return
2158
2122
2159 # at this point ps should point to the target dir
2123 # at this point ps should point to the target dir
2160 if ps:
2124 if ps:
2161 try:
2125 try:
2162 os.chdir(os.path.expanduser(ps))
2126 os.chdir(os.path.expanduser(ps))
2163 except OSError:
2127 except OSError:
2164 print sys.exc_info()[1]
2128 print sys.exc_info()[1]
2165 else:
2129 else:
2166 self.shell.user_ns['_dh'].append(os.getcwd())
2130 self.shell.user_ns['_dh'].append(os.getcwd())
2167 else:
2131 else:
2168 os.chdir(self.home_dir)
2132 os.chdir(self.home_dir)
2169 self.shell.user_ns['_dh'].append(os.getcwd())
2133 self.shell.user_ns['_dh'].append(os.getcwd())
2170 if not 'q' in opts:
2134 if not 'q' in opts:
2171 print self.shell.user_ns['_dh'][-1]
2135 print self.shell.user_ns['_dh'][-1]
2172
2136
2173 def magic_dhist(self, parameter_s=''):
2137 def magic_dhist(self, parameter_s=''):
2174 """Print your history of visited directories.
2138 """Print your history of visited directories.
2175
2139
2176 %dhist -> print full history\\
2140 %dhist -> print full history\\
2177 %dhist n -> print last n entries only\\
2141 %dhist n -> print last n entries only\\
2178 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2142 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2179
2143
2180 This history is automatically maintained by the %cd command, and
2144 This history is automatically maintained by the %cd command, and
2181 always available as the global list variable _dh. You can use %cd -<n>
2145 always available as the global list variable _dh. You can use %cd -<n>
2182 to go to directory number <n>."""
2146 to go to directory number <n>."""
2183
2147
2184 dh = self.shell.user_ns['_dh']
2148 dh = self.shell.user_ns['_dh']
2185 if parameter_s:
2149 if parameter_s:
2186 try:
2150 try:
2187 args = map(int,parameter_s.split())
2151 args = map(int,parameter_s.split())
2188 except:
2152 except:
2189 self.arg_err(Magic.magic_dhist)
2153 self.arg_err(Magic.magic_dhist)
2190 return
2154 return
2191 if len(args) == 1:
2155 if len(args) == 1:
2192 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2156 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2193 elif len(args) == 2:
2157 elif len(args) == 2:
2194 ini,fin = args
2158 ini,fin = args
2195 else:
2159 else:
2196 self.arg_err(Magic.magic_dhist)
2160 self.arg_err(Magic.magic_dhist)
2197 return
2161 return
2198 else:
2162 else:
2199 ini,fin = 0,len(dh)
2163 ini,fin = 0,len(dh)
2200 nlprint(dh,
2164 nlprint(dh,
2201 header = 'Directory history (kept in _dh)',
2165 header = 'Directory history (kept in _dh)',
2202 start=ini,stop=fin)
2166 start=ini,stop=fin)
2203
2167
2204 def magic_env(self, parameter_s=''):
2168 def magic_env(self, parameter_s=''):
2205 """List environment variables."""
2169 """List environment variables."""
2206
2170
2207 # environ is an instance of UserDict
2171 # environ is an instance of UserDict
2208 return os.environ.data
2172 return os.environ.data
2209
2173
2210 def magic_pushd(self, parameter_s=''):
2174 def magic_pushd(self, parameter_s=''):
2211 """Place the current dir on stack and change directory.
2175 """Place the current dir on stack and change directory.
2212
2176
2213 Usage:\\
2177 Usage:\\
2214 %pushd ['dirname']
2178 %pushd ['dirname']
2215
2179
2216 %pushd with no arguments does a %pushd to your home directory.
2180 %pushd with no arguments does a %pushd to your home directory.
2217 """
2181 """
2218 if parameter_s == '': parameter_s = '~'
2182 if parameter_s == '': parameter_s = '~'
2219 if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \
2183 if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \
2220 os.path.expanduser(self.dir_stack[0]):
2184 os.path.expanduser(self.dir_stack[0]):
2221 try:
2185 try:
2222 self.magic_cd(parameter_s)
2186 self.magic_cd(parameter_s)
2223 self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~'))
2187 self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~'))
2224 self.magic_dirs()
2188 self.magic_dirs()
2225 except:
2189 except:
2226 print 'Invalid directory'
2190 print 'Invalid directory'
2227 else:
2191 else:
2228 print 'You are already there!'
2192 print 'You are already there!'
2229
2193
2230 def magic_popd(self, parameter_s=''):
2194 def magic_popd(self, parameter_s=''):
2231 """Change to directory popped off the top of the stack.
2195 """Change to directory popped off the top of the stack.
2232 """
2196 """
2233 if len (self.dir_stack) > 1:
2197 if len (self.dir_stack) > 1:
2234 self.dir_stack.pop(0)
2198 self.dir_stack.pop(0)
2235 self.magic_cd(self.dir_stack[0])
2199 self.magic_cd(self.dir_stack[0])
2236 print self.dir_stack[0]
2200 print self.dir_stack[0]
2237 else:
2201 else:
2238 print "You can't remove the starting directory from the stack:",\
2202 print "You can't remove the starting directory from the stack:",\
2239 self.dir_stack
2203 self.dir_stack
2240
2204
2241 def magic_dirs(self, parameter_s=''):
2205 def magic_dirs(self, parameter_s=''):
2242 """Return the current directory stack."""
2206 """Return the current directory stack."""
2243
2207
2244 return self.dir_stack[:]
2208 return self.dir_stack[:]
2245
2209
2246 def magic_sc(self, parameter_s=''):
2210 def magic_sc(self, parameter_s=''):
2247 """Shell capture - execute a shell command and capture its output.
2211 """Shell capture - execute a shell command and capture its output.
2248
2212
2249 %sc [options] varname=command
2213 %sc [options] varname=command
2250
2214
2251 IPython will run the given command using commands.getoutput(), and
2215 IPython will run the given command using commands.getoutput(), and
2252 will then update the user's interactive namespace with a variable
2216 will then update the user's interactive namespace with a variable
2253 called varname, containing the value of the call. Your command can
2217 called varname, containing the value of the call. Your command can
2254 contain shell wildcards, pipes, etc.
2218 contain shell wildcards, pipes, etc.
2255
2219
2256 The '=' sign in the syntax is mandatory, and the variable name you
2220 The '=' sign in the syntax is mandatory, and the variable name you
2257 supply must follow Python's standard conventions for valid names.
2221 supply must follow Python's standard conventions for valid names.
2258
2222
2259 Options:
2223 Options:
2260
2224
2261 -l: list output. Split the output on newlines into a list before
2225 -l: list output. Split the output on newlines into a list before
2262 assigning it to the given variable. By default the output is stored
2226 assigning it to the given variable. By default the output is stored
2263 as a single string.
2227 as a single string.
2264
2228
2265 -v: verbose. Print the contents of the variable.
2229 -v: verbose. Print the contents of the variable.
2266
2230
2267 In most cases you should not need to split as a list, because the
2231 In most cases you should not need to split as a list, because the
2268 returned value is a special type of string which can automatically
2232 returned value is a special type of string which can automatically
2269 provide its contents either as a list (split on newlines) or as a
2233 provide its contents either as a list (split on newlines) or as a
2270 space-separated string. These are convenient, respectively, either
2234 space-separated string. These are convenient, respectively, either
2271 for sequential processing or to be passed to a shell command.
2235 for sequential processing or to be passed to a shell command.
2272
2236
2273 For example:
2237 For example:
2274
2238
2275 # Capture into variable a
2239 # Capture into variable a
2276 In [9]: sc a=ls *py
2240 In [9]: sc a=ls *py
2277
2241
2278 # a is a string with embedded newlines
2242 # a is a string with embedded newlines
2279 In [10]: a
2243 In [10]: a
2280 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2244 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2281
2245
2282 # which can be seen as a list:
2246 # which can be seen as a list:
2283 In [11]: a.l
2247 In [11]: a.l
2284 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2248 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2285
2249
2286 # or as a whitespace-separated string:
2250 # or as a whitespace-separated string:
2287 In [12]: a.s
2251 In [12]: a.s
2288 Out[12]: 'setup.py win32_manual_post_install.py'
2252 Out[12]: 'setup.py win32_manual_post_install.py'
2289
2253
2290 # a.s is useful to pass as a single command line:
2254 # a.s is useful to pass as a single command line:
2291 In [13]: !wc -l $a.s
2255 In [13]: !wc -l $a.s
2292 146 setup.py
2256 146 setup.py
2293 130 win32_manual_post_install.py
2257 130 win32_manual_post_install.py
2294 276 total
2258 276 total
2295
2259
2296 # while the list form is useful to loop over:
2260 # while the list form is useful to loop over:
2297 In [14]: for f in a.l:
2261 In [14]: for f in a.l:
2298 ....: !wc -l $f
2262 ....: !wc -l $f
2299 ....:
2263 ....:
2300 146 setup.py
2264 146 setup.py
2301 130 win32_manual_post_install.py
2265 130 win32_manual_post_install.py
2302
2266
2303 Similiarly, the lists returned by the -l option are also special, in
2267 Similiarly, the lists returned by the -l option are also special, in
2304 the sense that you can equally invoke the .s attribute on them to
2268 the sense that you can equally invoke the .s attribute on them to
2305 automatically get a whitespace-separated string from their contents:
2269 automatically get a whitespace-separated string from their contents:
2306
2270
2307 In [1]: sc -l b=ls *py
2271 In [1]: sc -l b=ls *py
2308
2272
2309 In [2]: b
2273 In [2]: b
2310 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2274 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2311
2275
2312 In [3]: b.s
2276 In [3]: b.s
2313 Out[3]: 'setup.py win32_manual_post_install.py'
2277 Out[3]: 'setup.py win32_manual_post_install.py'
2314
2278
2315 In summary, both the lists and strings used for ouptut capture have
2279 In summary, both the lists and strings used for ouptut capture have
2316 the following special attributes:
2280 the following special attributes:
2317
2281
2318 .l (or .list) : value as list.
2282 .l (or .list) : value as list.
2319 .n (or .nlstr): value as newline-separated string.
2283 .n (or .nlstr): value as newline-separated string.
2320 .s (or .spstr): value as space-separated string.
2284 .s (or .spstr): value as space-separated string.
2321 """
2285 """
2322
2286
2323 opts,args = self.parse_options(parameter_s,'lv')
2287 opts,args = self.parse_options(parameter_s,'lv')
2324 # Try to get a variable name and command to run
2288 # Try to get a variable name and command to run
2325 try:
2289 try:
2326 # the variable name must be obtained from the parse_options
2290 # the variable name must be obtained from the parse_options
2327 # output, which uses shlex.split to strip options out.
2291 # output, which uses shlex.split to strip options out.
2328 var,_ = args.split('=',1)
2292 var,_ = args.split('=',1)
2329 var = var.strip()
2293 var = var.strip()
2330 # But the the command has to be extracted from the original input
2294 # But the the command has to be extracted from the original input
2331 # parameter_s, not on what parse_options returns, to avoid the
2295 # parameter_s, not on what parse_options returns, to avoid the
2332 # quote stripping which shlex.split performs on it.
2296 # quote stripping which shlex.split performs on it.
2333 _,cmd = parameter_s.split('=',1)
2297 _,cmd = parameter_s.split('=',1)
2334 except ValueError:
2298 except ValueError:
2335 var,cmd = '',''
2299 var,cmd = '',''
2336 if not var:
2300 if not var:
2337 error('you must specify a variable to assign the command to.')
2301 error('you must specify a variable to assign the command to.')
2338 return
2302 return
2339 # If all looks ok, proceed
2303 # If all looks ok, proceed
2340 out,err = self.shell.getoutputerror(cmd)
2304 out,err = self.shell.getoutputerror(cmd)
2341 if err:
2305 if err:
2342 print >> Term.cerr,err
2306 print >> Term.cerr,err
2343 if opts.has_key('l'):
2307 if opts.has_key('l'):
2344 out = SList(out.split('\n'))
2308 out = SList(out.split('\n'))
2345 else:
2309 else:
2346 out = LSString(out)
2310 out = LSString(out)
2347 if opts.has_key('v'):
2311 if opts.has_key('v'):
2348 print '%s ==\n%s' % (var,pformat(out))
2312 print '%s ==\n%s' % (var,pformat(out))
2349 self.shell.user_ns.update({var:out})
2313 self.shell.user_ns.update({var:out})
2350
2314
2351 def magic_sx(self, parameter_s=''):
2315 def magic_sx(self, parameter_s=''):
2352 """Shell execute - run a shell command and capture its output.
2316 """Shell execute - run a shell command and capture its output.
2353
2317
2354 %sx command
2318 %sx command
2355
2319
2356 IPython will run the given command using commands.getoutput(), and
2320 IPython will run the given command using commands.getoutput(), and
2357 return the result formatted as a list (split on '\\n'). Since the
2321 return the result formatted as a list (split on '\\n'). Since the
2358 output is _returned_, it will be stored in ipython's regular output
2322 output is _returned_, it will be stored in ipython's regular output
2359 cache Out[N] and in the '_N' automatic variables.
2323 cache Out[N] and in the '_N' automatic variables.
2360
2324
2361 Notes:
2325 Notes:
2362
2326
2363 1) If an input line begins with '!!', then %sx is automatically
2327 1) If an input line begins with '!!', then %sx is automatically
2364 invoked. That is, while:
2328 invoked. That is, while:
2365 !ls
2329 !ls
2366 causes ipython to simply issue system('ls'), typing
2330 causes ipython to simply issue system('ls'), typing
2367 !!ls
2331 !!ls
2368 is a shorthand equivalent to:
2332 is a shorthand equivalent to:
2369 %sx ls
2333 %sx ls
2370
2334
2371 2) %sx differs from %sc in that %sx automatically splits into a list,
2335 2) %sx differs from %sc in that %sx automatically splits into a list,
2372 like '%sc -l'. The reason for this is to make it as easy as possible
2336 like '%sc -l'. The reason for this is to make it as easy as possible
2373 to process line-oriented shell output via further python commands.
2337 to process line-oriented shell output via further python commands.
2374 %sc is meant to provide much finer control, but requires more
2338 %sc is meant to provide much finer control, but requires more
2375 typing.
2339 typing.
2376
2340
2377 3) Just like %sc -l, this is a list with special attributes:
2341 3) Just like %sc -l, this is a list with special attributes:
2378
2342
2379 .l (or .list) : value as list.
2343 .l (or .list) : value as list.
2380 .n (or .nlstr): value as newline-separated string.
2344 .n (or .nlstr): value as newline-separated string.
2381 .s (or .spstr): value as whitespace-separated string.
2345 .s (or .spstr): value as whitespace-separated string.
2382
2346
2383 This is very useful when trying to use such lists as arguments to
2347 This is very useful when trying to use such lists as arguments to
2384 system commands."""
2348 system commands."""
2385
2349
2386 if parameter_s:
2350 if parameter_s:
2387 out,err = self.shell.getoutputerror(parameter_s)
2351 out,err = self.shell.getoutputerror(parameter_s)
2388 if err:
2352 if err:
2389 print >> Term.cerr,err
2353 print >> Term.cerr,err
2390 return SList(out.split('\n'))
2354 return SList(out.split('\n'))
2391
2355
2392 def magic_bg(self, parameter_s=''):
2356 def magic_bg(self, parameter_s=''):
2393 """Run a job in the background, in a separate thread.
2357 """Run a job in the background, in a separate thread.
2394
2358
2395 For example,
2359 For example,
2396
2360
2397 %bg myfunc(x,y,z=1)
2361 %bg myfunc(x,y,z=1)
2398
2362
2399 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2363 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2400 execution starts, a message will be printed indicating the job
2364 execution starts, a message will be printed indicating the job
2401 number. If your job number is 5, you can use
2365 number. If your job number is 5, you can use
2402
2366
2403 myvar = jobs.result(5) or myvar = jobs[5].result
2367 myvar = jobs.result(5) or myvar = jobs[5].result
2404
2368
2405 to assign this result to variable 'myvar'.
2369 to assign this result to variable 'myvar'.
2406
2370
2407 IPython has a job manager, accessible via the 'jobs' object. You can
2371 IPython has a job manager, accessible via the 'jobs' object. You can
2408 type jobs? to get more information about it, and use jobs.<TAB> to see
2372 type jobs? to get more information about it, and use jobs.<TAB> to see
2409 its attributes. All attributes not starting with an underscore are
2373 its attributes. All attributes not starting with an underscore are
2410 meant for public use.
2374 meant for public use.
2411
2375
2412 In particular, look at the jobs.new() method, which is used to create
2376 In particular, look at the jobs.new() method, which is used to create
2413 new jobs. This magic %bg function is just a convenience wrapper
2377 new jobs. This magic %bg function is just a convenience wrapper
2414 around jobs.new(), for expression-based jobs. If you want to create a
2378 around jobs.new(), for expression-based jobs. If you want to create a
2415 new job with an explicit function object and arguments, you must call
2379 new job with an explicit function object and arguments, you must call
2416 jobs.new() directly.
2380 jobs.new() directly.
2417
2381
2418 The jobs.new docstring also describes in detail several important
2382 The jobs.new docstring also describes in detail several important
2419 caveats associated with a thread-based model for background job
2383 caveats associated with a thread-based model for background job
2420 execution. Type jobs.new? for details.
2384 execution. Type jobs.new? for details.
2421
2385
2422 You can check the status of all jobs with jobs.status().
2386 You can check the status of all jobs with jobs.status().
2423
2387
2424 The jobs variable is set by IPython into the Python builtin namespace.
2388 The jobs variable is set by IPython into the Python builtin namespace.
2425 If you ever declare a variable named 'jobs', you will shadow this
2389 If you ever declare a variable named 'jobs', you will shadow this
2426 name. You can either delete your global jobs variable to regain
2390 name. You can either delete your global jobs variable to regain
2427 access to the job manager, or make a new name and assign it manually
2391 access to the job manager, or make a new name and assign it manually
2428 to the manager (stored in IPython's namespace). For example, to
2392 to the manager (stored in IPython's namespace). For example, to
2429 assign the job manager to the Jobs name, use:
2393 assign the job manager to the Jobs name, use:
2430
2394
2431 Jobs = __builtins__.jobs"""
2395 Jobs = __builtins__.jobs"""
2432
2396
2433 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2397 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2434
2398
2435 def magic_bookmark(self, parameter_s=''):
2399 def magic_bookmark(self, parameter_s=''):
2436 """Manage IPython's bookmark system.
2400 """Manage IPython's bookmark system.
2437
2401
2438 %bookmark <name> - set bookmark to current dir
2402 %bookmark <name> - set bookmark to current dir
2439 %bookmark <name> <dir> - set bookmark to <dir>
2403 %bookmark <name> <dir> - set bookmark to <dir>
2440 %bookmark -l - list all bookmarks
2404 %bookmark -l - list all bookmarks
2441 %bookmark -d <name> - remove bookmark
2405 %bookmark -d <name> - remove bookmark
2442 %bookmark -r - remove all bookmarks
2406 %bookmark -r - remove all bookmarks
2443
2407
2444 You can later on access a bookmarked folder with:
2408 You can later on access a bookmarked folder with:
2445 %cd -b <name>
2409 %cd -b <name>
2446 or simply '%cd <name>' if there is no directory called <name> AND
2410 or simply '%cd <name>' if there is no directory called <name> AND
2447 there is such a bookmark defined.
2411 there is such a bookmark defined.
2448
2412
2449 Your bookmarks persist through IPython sessions, but they are
2413 Your bookmarks persist through IPython sessions, but they are
2450 associated with each profile."""
2414 associated with each profile."""
2451
2415
2452 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2416 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2453 if len(args) > 2:
2417 if len(args) > 2:
2454 error('You can only give at most two arguments')
2418 error('You can only give at most two arguments')
2455 return
2419 return
2456
2420
2457 bkms = self.shell.persist.get('bookmarks',{})
2421 bkms = self.shell.persist.get('bookmarks',{})
2458
2422
2459 if opts.has_key('d'):
2423 if opts.has_key('d'):
2460 try:
2424 try:
2461 todel = args[0]
2425 todel = args[0]
2462 except IndexError:
2426 except IndexError:
2463 error('You must provide a bookmark to delete')
2427 error('You must provide a bookmark to delete')
2464 else:
2428 else:
2465 try:
2429 try:
2466 del bkms[todel]
2430 del bkms[todel]
2467 except:
2431 except:
2468 error("Can't delete bookmark '%s'" % todel)
2432 error("Can't delete bookmark '%s'" % todel)
2469 elif opts.has_key('r'):
2433 elif opts.has_key('r'):
2470 bkms = {}
2434 bkms = {}
2471 elif opts.has_key('l'):
2435 elif opts.has_key('l'):
2472 bks = bkms.keys()
2436 bks = bkms.keys()
2473 bks.sort()
2437 bks.sort()
2474 if bks:
2438 if bks:
2475 size = max(map(len,bks))
2439 size = max(map(len,bks))
2476 else:
2440 else:
2477 size = 0
2441 size = 0
2478 fmt = '%-'+str(size)+'s -> %s'
2442 fmt = '%-'+str(size)+'s -> %s'
2479 print 'Current bookmarks:'
2443 print 'Current bookmarks:'
2480 for bk in bks:
2444 for bk in bks:
2481 print fmt % (bk,bkms[bk])
2445 print fmt % (bk,bkms[bk])
2482 else:
2446 else:
2483 if not args:
2447 if not args:
2484 error("You must specify the bookmark name")
2448 error("You must specify the bookmark name")
2485 elif len(args)==1:
2449 elif len(args)==1:
2486 bkms[args[0]] = os.getcwd()
2450 bkms[args[0]] = os.getcwd()
2487 elif len(args)==2:
2451 elif len(args)==2:
2488 bkms[args[0]] = args[1]
2452 bkms[args[0]] = args[1]
2489 self.persist['bookmarks'] = bkms
2453 self.persist['bookmarks'] = bkms
2490 # end Magic
2454 # end Magic
@@ -1,149 +1,175 b''
1 """Module for interactive demos using IPython.
1 """Module for interactive demos using IPython.
2
2
3 Sorry, but this uses Python 2.3 features, so it won't work in 2.2 environments.
3 Sorry, but this uses Python 2.3 features, so it won't work in 2.2 environments.
4 """
4 """
5 #*****************************************************************************
5 #*****************************************************************************
6 # Copyright (C) 2005 Fernando Perez. <Fernando.Perez@colorado.edu>
6 # Copyright (C) 2005 Fernando Perez. <Fernando.Perez@colorado.edu>
7 #
7 #
8 # Distributed under the terms of the BSD License. The full license is in
8 # Distributed under the terms of the BSD License. The full license is in
9 # the file COPYING, distributed as part of this software.
9 # the file COPYING, distributed as part of this software.
10 #
10 #
11 #*****************************************************************************
11 #*****************************************************************************
12
12
13 import sys
13 import exceptions
14 import exceptions
14 import re
15 import re
15
16
16 from IPython.PyColorize import Parser
17 from IPython.PyColorize import Parser
17 from IPython.genutils import marquee
18 from IPython.genutils import marquee, shlex_split
18
19
19 class DemoError(exceptions.Exception): pass
20 class DemoError(exceptions.Exception): pass
20
21
21 class Demo:
22 class Demo:
22 def __init__(self,fname,mark_pause='# pause',mark_silent='# silent',
23 def __init__(self,fname,arg_str='',mark_pause='# pause',
23 auto=False):
24 mark_silent='# silent',auto=False):
24 """The marks are turned into regexps which match them as standalone in
25 """Make a new demo object. To run the demo, simply call the object.
25 a line, with all leading/trailing whitespace ignored."""
26
27 Inputs:
28
29 - fname = filename.
30
31 Optional inputs:
32
33 - arg_str(''): a string of arguments, internally converted to a list
34 just like sys.argv, so the demo script can see a similar
35 environment.
36
37 - mark_pause ('# pause'), mark_silent('# silent'): marks for pausing
38 (block boundaries) and to tag blocks as silent. The marks are
39 turned into regexps which match them as standalone in a line, with
40 all leading/trailing whitespace ignored.
41
42 - auto(False): flag to run each block automatically without
43 confirmation. Note that silent blocks are always automatically
44 executed. This flag is an attribute of the object, and can be
45 changed at runtime simply by reassigning it.
46 """
26
47
27 self.fname = fname
48 self.fname = fname
28 self.mark_pause = mark_pause
49 self.mark_pause = mark_pause
29 self.re_pause = re.compile(r'^\s*%s\s*$' % mark_pause,re.MULTILINE)
50 self.re_pause = re.compile(r'^\s*%s\s*$' % mark_pause,re.MULTILINE)
30 self.mark_silent = mark_silent
51 self.mark_silent = mark_silent
31 self.re_silent = re.compile(r'^\s*%s\s*$' % mark_silent,re.MULTILINE)
52 self.re_silent = re.compile(r'^\s*%s\s*$' % mark_silent,re.MULTILINE)
32 self.auto = auto
53 self.auto = auto
54 self.sys_argv = shlex_split(arg_str)
33
55
34 # get a few things from ipython. While it's a bit ugly design-wise,
56 # get a few things from ipython. While it's a bit ugly design-wise,
35 # it ensures that things like color scheme and the like are always in
57 # it ensures that things like color scheme and the like are always in
36 # sync with the ipython mode being used. This class is only meant to
58 # sync with the ipython mode being used. This class is only meant to
37 # be used inside ipython anyways, so it's OK.
59 # be used inside ipython anyways, so it's OK.
38 self.ip_showtraceback = __IPYTHON__.showtraceback
60 self.ip_showtraceback = __IPYTHON__.showtraceback
39 self.ip_ns = __IPYTHON__.user_ns
61 self.ip_ns = __IPYTHON__.user_ns
40 self.ip_colors = __IPYTHON__.rc['colors']
62 self.ip_colors = __IPYTHON__.rc['colors']
41
63
42 # read data and parse into blocks
64 # read data and parse into blocks
43 fobj = file(fname,'r')
65 fobj = file(fname,'r')
44 self.src = fobj.read()
66 self.src = fobj.read()
45 fobj.close()
67 fobj.close()
46 self.src_blocks = [b.strip() for b in self.re_pause.split(self.src) if b]
68 self.src_blocks = [b.strip() for b in self.re_pause.split(self.src) if b]
47 self.silent = [bool(self.re_silent.findall(b)) for b in self.src_blocks]
69 self.silent = [bool(self.re_silent.findall(b)) for b in self.src_blocks]
48 self.nblocks = len(self.src_blocks)
70 self.nblocks = len(self.src_blocks)
49
71
50 # try to colorize blocks
72 # try to colorize blocks
51 colorize = Parser().format
73 colorize = Parser().format
52 col_scheme = self.ip_colors
74 col_scheme = self.ip_colors
53 self.src_blocks_colored = [colorize(s_blk,'str',col_scheme)
75 self.src_blocks_colored = [colorize(s_blk,'str',col_scheme)
54 for s_blk in self.src_blocks]
76 for s_blk in self.src_blocks]
55
77
56 # finish initialization
78 # finish initialization
57 self.reset()
79 self.reset()
58
80
59 def reset(self):
81 def reset(self):
60 """Reset the namespace and seek pointer to restart the demo"""
82 """Reset the namespace and seek pointer to restart the demo"""
61 self.user_ns = {}
83 self.user_ns = {}
62 self.finished = False
84 self.finished = False
63 self.block_index = 0
85 self.block_index = 0
64
86
65 def again(self):
87 def again(self):
66 """Repeat the last block"""
88 """Repeat the last block"""
67 self.block_index -= 1
89 self.block_index -= 1
68 self()
90 self()
69
91
70 def _validate_index(self,index):
92 def _validate_index(self,index):
71 if index<0 or index>=self.nblocks:
93 if index<0 or index>=self.nblocks:
72 raise ValueError('invalid block index %s' % index)
94 raise ValueError('invalid block index %s' % index)
73
95
74 def seek(self,index):
96 def seek(self,index):
75 """Move the current seek pointer to the given block"""
97 """Move the current seek pointer to the given block"""
76 self._validate_index(index)
98 self._validate_index(index)
77 self.block_index = index-1
99 self.block_index = index-1
78 self.finished = False
100 self.finished = False
79
101
80 def show_block(self,index=None):
102 def show_block(self,index=None):
81 """Show a single block on screen"""
103 """Show a single block on screen"""
82 if index is None:
104 if index is None:
83 if self.finished:
105 if self.finished:
84 print 'Demo finished. Use reset() if you want to rerun it.'
106 print 'Demo finished. Use reset() if you want to rerun it.'
85 return
107 return
86 index = self.block_index
108 index = self.block_index
87 else:
109 else:
88 self._validate_index(index)
110 self._validate_index(index)
89 print marquee('<%s> block # %s (%s/%s)' %
111 print marquee('<%s> block # %s (%s/%s)' %
90 (self.fname,index,index+1,self.nblocks))
112 (self.fname,index,index+1,self.nblocks))
91 print self.src_blocks_colored[index],
113 print self.src_blocks_colored[index],
92
114
93 def show(self):
115 def show(self):
94 """Show entire demo on screen, block by block"""
116 """Show entire demo on screen, block by block"""
95
117
96 fname = self.fname
118 fname = self.fname
97 nblocks = self.nblocks
119 nblocks = self.nblocks
98 silent = self.silent
120 silent = self.silent
99 for index,block in enumerate(self.src_blocks_colored):
121 for index,block in enumerate(self.src_blocks_colored):
100 if silent[index]:
122 if silent[index]:
101 print marquee('<%s> SILENT block # %s (%s/%s)' %
123 print marquee('<%s> SILENT block # %s (%s/%s)' %
102 (fname,index,index+1,nblocks))
124 (fname,index,index+1,nblocks))
103 else:
125 else:
104 print marquee('<%s> block # %s (%s/%s)' %
126 print marquee('<%s> block # %s (%s/%s)' %
105 (fname,index,index+1,nblocks))
127 (fname,index,index+1,nblocks))
106 print block,
128 print block,
107
129
108 def __call__(self,index=None):
130 def __call__(self,index=None):
109 """run a block of the demo.
131 """run a block of the demo.
110
132
111 If index is given, it should be an integer >=1 and <= nblocks. This
133 If index is given, it should be an integer >=1 and <= nblocks. This
112 means that the calling convention is one off from typical Python
134 means that the calling convention is one off from typical Python
113 lists. The reason for the inconsistency is that the demo always
135 lists. The reason for the inconsistency is that the demo always
114 prints 'Block n/N, and N is the total, so it would be very odd to use
136 prints 'Block n/N, and N is the total, so it would be very odd to use
115 zero-indexing here."""
137 zero-indexing here."""
116
138
117 if index is None and self.finished:
139 if index is None and self.finished:
118 print 'Demo finished. Use reset() if you want to rerun it.'
140 print 'Demo finished. Use reset() if you want to rerun it.'
119 return
141 return
120 if index is None:
142 if index is None:
121 index = self.block_index
143 index = self.block_index
122 self._validate_index(index)
144 self._validate_index(index)
123 try:
145 try:
124 next_block = self.src_blocks[index]
146 next_block = self.src_blocks[index]
125 self.block_index += 1
147 self.block_index += 1
126 if self.silent[index]:
148 if self.silent[index]:
127 print marquee('Executing silent block # %s (%s/%s)' %
149 print marquee('Executing silent block # %s (%s/%s)' %
128 (index,index+1,self.nblocks))
150 (index,index+1,self.nblocks))
129 else:
151 else:
130 self.show_block(index)
152 self.show_block(index)
131 if not self.auto:
153 if not self.auto:
132 print marquee('Press <q> to quit, <Enter> to execute...'),
154 print marquee('Press <q> to quit, <Enter> to execute...'),
133 ans = raw_input().strip()
155 ans = raw_input().strip()
134 if ans:
156 if ans:
135 print marquee('Block NOT executed')
157 print marquee('Block NOT executed')
136 return
158 return
137
159 try:
160 save_argv = sys.argv
161 sys.argv = self.sys_argv
138 exec next_block in self.user_ns
162 exec next_block in self.user_ns
163 finally:
164 sys.argv = save_argv
139
165
140 except:
166 except:
141 self.ip_showtraceback(filename=self.fname)
167 self.ip_showtraceback(filename=self.fname)
142 else:
168 else:
143 self.ip_ns.update(self.user_ns)
169 self.ip_ns.update(self.user_ns)
144
170
145 if self.block_index == self.nblocks:
171 if self.block_index == self.nblocks:
146 print
172 print
147 print marquee(' END OF DEMO ')
173 print marquee(' END OF DEMO ')
148 print marquee('Use reset() if you want to rerun it.')
174 print marquee('Use reset() if you want to rerun it.')
149 self.finished = True
175 self.finished = True
@@ -1,1540 +1,1578 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 General purpose utilities.
3 General purpose utilities.
4
4
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 these things are also convenient when working at the command line.
6 these things are also convenient when working at the command line.
7
7
8 $Id: genutils.py 894 2005-09-22 07:16:18Z fperez $"""
8 $Id: genutils.py 897 2005-09-22 09:32:46Z fperez $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
12 #
12 #
13 # Distributed under the terms of the BSD License. The full license is in
13 # Distributed under the terms of the BSD License. The full license is in
14 # the file COPYING, distributed as part of this software.
14 # the file COPYING, distributed as part of this software.
15 #*****************************************************************************
15 #*****************************************************************************
16
16
17 from __future__ import generators # 2.2 compatibility
17 from __future__ import generators # 2.2 compatibility
18
18
19 from IPython import Release
19 from IPython import Release
20 __author__ = '%s <%s>' % Release.authors['Fernando']
20 __author__ = '%s <%s>' % Release.authors['Fernando']
21 __license__ = Release.license
21 __license__ = Release.license
22
22
23 #****************************************************************************
23 #****************************************************************************
24 # required modules
24 # required modules
25 import __main__
25 import __main__
26 import types,commands,time,sys,os,re,shutil
26 import types,commands,time,sys,os,re,shutil
27 import shlex
27 import tempfile
28 import tempfile
28 from IPython.Itpl import Itpl,itpl,printpl
29 from IPython.Itpl import Itpl,itpl,printpl
29 from IPython import DPyGetOpt
30 from IPython import DPyGetOpt
30
31
31 # Build objects which appeared in Python 2.3 for 2.2, to make ipython
32 # Build objects which appeared in Python 2.3 for 2.2, to make ipython
32 # 2.2-friendly
33 # 2.2-friendly
33 try:
34 try:
34 basestring
35 basestring
35 except NameError:
36 except NameError:
36 import types
37 import types
37 basestring = (types.StringType, types.UnicodeType)
38 basestring = (types.StringType, types.UnicodeType)
38 True = 1==1
39 True = 1==1
39 False = 1==0
40 False = 1==0
40
41
41 def enumerate(obj):
42 def enumerate(obj):
42 i = -1
43 i = -1
43 for item in obj:
44 for item in obj:
44 i += 1
45 i += 1
45 yield i, item
46 yield i, item
46
47
47 # add these to the builtin namespace, so that all modules find them
48 # add these to the builtin namespace, so that all modules find them
48 import __builtin__
49 import __builtin__
49 __builtin__.basestring = basestring
50 __builtin__.basestring = basestring
50 __builtin__.True = True
51 __builtin__.True = True
51 __builtin__.False = False
52 __builtin__.False = False
52 __builtin__.enumerate = enumerate
53 __builtin__.enumerate = enumerate
53
54
55 # Try to use shlex.split for converting an input string into a sys.argv-type
56 # list. This appeared in Python 2.3, so here's a quick backport for 2.2.
57 try:
58 shlex_split = shlex.split
59 except AttributeError:
60 _quotesre = re.compile(r'[\'"](.*)[\'"]')
61 _wordchars = ('abcdfeghijklmnopqrstuvwxyz'
62 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~*?'
63 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
64 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ%s'
65 % os.sep)
66
67 def shlex_split(s):
68 """Simplified backport to Python 2.2 of shlex.split().
69
70 This is a quick and dirty hack, since the shlex module under 2.2 lacks
71 several of the features needed to really match the functionality of
72 shlex.split() in 2.3."""
73
74 lex = shlex.shlex(StringIO(s))
75 # Try to get options, extensions and path separators as characters
76 lex.wordchars = _wordchars
77 lex.commenters = ''
78 # Make a list out of the lexer by hand, since in 2.2 it's not an
79 # iterator.
80 lout = []
81 while 1:
82 token = lex.get_token()
83 if token == '':
84 break
85 # Try to handle quoted tokens correctly
86 quotes = _quotesre.match(token)
87 if quotes:
88 token = quotes.group(1)
89 lout.append(token)
90 return lout
91
54 #****************************************************************************
92 #****************************************************************************
55 # Exceptions
93 # Exceptions
56 class Error(Exception):
94 class Error(Exception):
57 """Base class for exceptions in this module."""
95 """Base class for exceptions in this module."""
58 pass
96 pass
59
97
60 #----------------------------------------------------------------------------
98 #----------------------------------------------------------------------------
61 class IOStream:
99 class IOStream:
62 def __init__(self,stream,fallback):
100 def __init__(self,stream,fallback):
63 if not hasattr(stream,'write') or not hasattr(stream,'flush'):
101 if not hasattr(stream,'write') or not hasattr(stream,'flush'):
64 stream = fallback
102 stream = fallback
65 self.stream = stream
103 self.stream = stream
66 self._swrite = stream.write
104 self._swrite = stream.write
67 self.flush = stream.flush
105 self.flush = stream.flush
68
106
69 def write(self,data):
107 def write(self,data):
70 try:
108 try:
71 self._swrite(data)
109 self._swrite(data)
72 except:
110 except:
73 try:
111 try:
74 # print handles some unicode issues which may trip a plain
112 # print handles some unicode issues which may trip a plain
75 # write() call. Attempt to emulate write() by using a
113 # write() call. Attempt to emulate write() by using a
76 # trailing comma
114 # trailing comma
77 print >> self.stream, data,
115 print >> self.stream, data,
78 except:
116 except:
79 # if we get here, something is seriously broken.
117 # if we get here, something is seriously broken.
80 print >> sys.stderr, \
118 print >> sys.stderr, \
81 'ERROR - failed to write data to stream:', stream
119 'ERROR - failed to write data to stream:', stream
82
120
83 class IOTerm:
121 class IOTerm:
84 """ Term holds the file or file-like objects for handling I/O operations.
122 """ Term holds the file or file-like objects for handling I/O operations.
85
123
86 These are normally just sys.stdin, sys.stdout and sys.stderr but for
124 These are normally just sys.stdin, sys.stdout and sys.stderr but for
87 Windows they can can replaced to allow editing the strings before they are
125 Windows they can can replaced to allow editing the strings before they are
88 displayed."""
126 displayed."""
89
127
90 # In the future, having IPython channel all its I/O operations through
128 # In the future, having IPython channel all its I/O operations through
91 # this class will make it easier to embed it into other environments which
129 # this class will make it easier to embed it into other environments which
92 # are not a normal terminal (such as a GUI-based shell)
130 # are not a normal terminal (such as a GUI-based shell)
93 def __init__(self,cin=None,cout=None,cerr=None):
131 def __init__(self,cin=None,cout=None,cerr=None):
94 self.cin = IOStream(cin,sys.stdin)
132 self.cin = IOStream(cin,sys.stdin)
95 self.cout = IOStream(cout,sys.stdout)
133 self.cout = IOStream(cout,sys.stdout)
96 self.cerr = IOStream(cerr,sys.stderr)
134 self.cerr = IOStream(cerr,sys.stderr)
97
135
98 # Global variable to be used for all I/O
136 # Global variable to be used for all I/O
99 Term = IOTerm()
137 Term = IOTerm()
100
138
101 # Windows-specific code to load Gary Bishop's readline and configure it
139 # Windows-specific code to load Gary Bishop's readline and configure it
102 # automatically for the users
140 # automatically for the users
103 # Note: os.name on cygwin returns posix, so this should only pick up 'native'
141 # Note: os.name on cygwin returns posix, so this should only pick up 'native'
104 # windows. Cygwin returns 'cygwin' for sys.platform.
142 # windows. Cygwin returns 'cygwin' for sys.platform.
105 if os.name == 'nt':
143 if os.name == 'nt':
106 try:
144 try:
107 import readline
145 import readline
108 except ImportError:
146 except ImportError:
109 pass
147 pass
110 else:
148 else:
111 try:
149 try:
112 _out = readline.GetOutputFile()
150 _out = readline.GetOutputFile()
113 except AttributeError:
151 except AttributeError:
114 pass
152 pass
115 else:
153 else:
116 # Remake Term to use the readline i/o facilities
154 # Remake Term to use the readline i/o facilities
117 Term = IOTerm(cout=_out,cerr=_out)
155 Term = IOTerm(cout=_out,cerr=_out)
118 del _out
156 del _out
119
157
120 #****************************************************************************
158 #****************************************************************************
121 # Generic warning/error printer, used by everything else
159 # Generic warning/error printer, used by everything else
122 def warn(msg,level=2,exit_val=1):
160 def warn(msg,level=2,exit_val=1):
123 """Standard warning printer. Gives formatting consistency.
161 """Standard warning printer. Gives formatting consistency.
124
162
125 Output is sent to Term.cerr (sys.stderr by default).
163 Output is sent to Term.cerr (sys.stderr by default).
126
164
127 Options:
165 Options:
128
166
129 -level(2): allows finer control:
167 -level(2): allows finer control:
130 0 -> Do nothing, dummy function.
168 0 -> Do nothing, dummy function.
131 1 -> Print message.
169 1 -> Print message.
132 2 -> Print 'WARNING:' + message. (Default level).
170 2 -> Print 'WARNING:' + message. (Default level).
133 3 -> Print 'ERROR:' + message.
171 3 -> Print 'ERROR:' + message.
134 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
172 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
135
173
136 -exit_val (1): exit value returned by sys.exit() for a level 4
174 -exit_val (1): exit value returned by sys.exit() for a level 4
137 warning. Ignored for all other levels."""
175 warning. Ignored for all other levels."""
138
176
139 if level>0:
177 if level>0:
140 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
178 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
141 print >> Term.cerr, '%s%s' % (header[level],msg)
179 print >> Term.cerr, '%s%s' % (header[level],msg)
142 if level == 4:
180 if level == 4:
143 print >> Term.cerr,'Exiting.\n'
181 print >> Term.cerr,'Exiting.\n'
144 sys.exit(exit_val)
182 sys.exit(exit_val)
145
183
146 def info(msg):
184 def info(msg):
147 """Equivalent to warn(msg,level=1)."""
185 """Equivalent to warn(msg,level=1)."""
148
186
149 warn(msg,level=1)
187 warn(msg,level=1)
150
188
151 def error(msg):
189 def error(msg):
152 """Equivalent to warn(msg,level=3)."""
190 """Equivalent to warn(msg,level=3)."""
153
191
154 warn(msg,level=3)
192 warn(msg,level=3)
155
193
156 def fatal(msg,exit_val=1):
194 def fatal(msg,exit_val=1):
157 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
195 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
158
196
159 warn(msg,exit_val=exit_val,level=4)
197 warn(msg,exit_val=exit_val,level=4)
160
198
161 #----------------------------------------------------------------------------
199 #----------------------------------------------------------------------------
162 StringTypes = types.StringTypes
200 StringTypes = types.StringTypes
163
201
164 # Basic timing functionality
202 # Basic timing functionality
165
203
166 # If possible (Unix), use the resource module instead of time.clock()
204 # If possible (Unix), use the resource module instead of time.clock()
167 try:
205 try:
168 import resource
206 import resource
169 def clock():
207 def clock():
170 """clock() -> floating point number
208 """clock() -> floating point number
171
209
172 Return the CPU time in seconds (user time only, system time is
210 Return the CPU time in seconds (user time only, system time is
173 ignored) since the start of the process. This is done via a call to
211 ignored) since the start of the process. This is done via a call to
174 resource.getrusage, so it avoids the wraparound problems in
212 resource.getrusage, so it avoids the wraparound problems in
175 time.clock()."""
213 time.clock()."""
176
214
177 return resource.getrusage(resource.RUSAGE_SELF)[0]
215 return resource.getrusage(resource.RUSAGE_SELF)[0]
178
216
179 def clock2():
217 def clock2():
180 """clock2() -> (t_user,t_system)
218 """clock2() -> (t_user,t_system)
181
219
182 Similar to clock(), but return a tuple of user/system times."""
220 Similar to clock(), but return a tuple of user/system times."""
183 return resource.getrusage(resource.RUSAGE_SELF)[:2]
221 return resource.getrusage(resource.RUSAGE_SELF)[:2]
184
222
185 except ImportError:
223 except ImportError:
186 clock = time.clock
224 clock = time.clock
187 def clock2():
225 def clock2():
188 """Under windows, system CPU time can't be measured.
226 """Under windows, system CPU time can't be measured.
189
227
190 This just returns clock() and zero."""
228 This just returns clock() and zero."""
191 return time.clock(),0.0
229 return time.clock(),0.0
192
230
193 def timings_out(reps,func,*args,**kw):
231 def timings_out(reps,func,*args,**kw):
194 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
232 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
195
233
196 Execute a function reps times, return a tuple with the elapsed total
234 Execute a function reps times, return a tuple with the elapsed total
197 CPU time in seconds, the time per call and the function's output.
235 CPU time in seconds, the time per call and the function's output.
198
236
199 Under Unix, the return value is the sum of user+system time consumed by
237 Under Unix, the return value is the sum of user+system time consumed by
200 the process, computed via the resource module. This prevents problems
238 the process, computed via the resource module. This prevents problems
201 related to the wraparound effect which the time.clock() function has.
239 related to the wraparound effect which the time.clock() function has.
202
240
203 Under Windows the return value is in wall clock seconds. See the
241 Under Windows the return value is in wall clock seconds. See the
204 documentation for the time module for more details."""
242 documentation for the time module for more details."""
205
243
206 reps = int(reps)
244 reps = int(reps)
207 assert reps >=1, 'reps must be >= 1'
245 assert reps >=1, 'reps must be >= 1'
208 if reps==1:
246 if reps==1:
209 start = clock()
247 start = clock()
210 out = func(*args,**kw)
248 out = func(*args,**kw)
211 tot_time = clock()-start
249 tot_time = clock()-start
212 else:
250 else:
213 rng = xrange(reps-1) # the last time is executed separately to store output
251 rng = xrange(reps-1) # the last time is executed separately to store output
214 start = clock()
252 start = clock()
215 for dummy in rng: func(*args,**kw)
253 for dummy in rng: func(*args,**kw)
216 out = func(*args,**kw) # one last time
254 out = func(*args,**kw) # one last time
217 tot_time = clock()-start
255 tot_time = clock()-start
218 av_time = tot_time / reps
256 av_time = tot_time / reps
219 return tot_time,av_time,out
257 return tot_time,av_time,out
220
258
221 def timings(reps,func,*args,**kw):
259 def timings(reps,func,*args,**kw):
222 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
260 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
223
261
224 Execute a function reps times, return a tuple with the elapsed total CPU
262 Execute a function reps times, return a tuple with the elapsed total CPU
225 time in seconds and the time per call. These are just the first two values
263 time in seconds and the time per call. These are just the first two values
226 in timings_out()."""
264 in timings_out()."""
227
265
228 return timings_out(reps,func,*args,**kw)[0:2]
266 return timings_out(reps,func,*args,**kw)[0:2]
229
267
230 def timing(func,*args,**kw):
268 def timing(func,*args,**kw):
231 """timing(func,*args,**kw) -> t_total
269 """timing(func,*args,**kw) -> t_total
232
270
233 Execute a function once, return the elapsed total CPU time in
271 Execute a function once, return the elapsed total CPU time in
234 seconds. This is just the first value in timings_out()."""
272 seconds. This is just the first value in timings_out()."""
235
273
236 return timings_out(1,func,*args,**kw)[0]
274 return timings_out(1,func,*args,**kw)[0]
237
275
238 #****************************************************************************
276 #****************************************************************************
239 # file and system
277 # file and system
240
278
241 def system(cmd,verbose=0,debug=0,header=''):
279 def system(cmd,verbose=0,debug=0,header=''):
242 """Execute a system command, return its exit status.
280 """Execute a system command, return its exit status.
243
281
244 Options:
282 Options:
245
283
246 - verbose (0): print the command to be executed.
284 - verbose (0): print the command to be executed.
247
285
248 - debug (0): only print, do not actually execute.
286 - debug (0): only print, do not actually execute.
249
287
250 - header (''): Header to print on screen prior to the executed command (it
288 - header (''): Header to print on screen prior to the executed command (it
251 is only prepended to the command, no newlines are added).
289 is only prepended to the command, no newlines are added).
252
290
253 Note: a stateful version of this function is available through the
291 Note: a stateful version of this function is available through the
254 SystemExec class."""
292 SystemExec class."""
255
293
256 stat = 0
294 stat = 0
257 if verbose or debug: print header+cmd
295 if verbose or debug: print header+cmd
258 sys.stdout.flush()
296 sys.stdout.flush()
259 if not debug: stat = os.system(cmd)
297 if not debug: stat = os.system(cmd)
260 return stat
298 return stat
261
299
262 def shell(cmd,verbose=0,debug=0,header=''):
300 def shell(cmd,verbose=0,debug=0,header=''):
263 """Execute a command in the system shell, always return None.
301 """Execute a command in the system shell, always return None.
264
302
265 Options:
303 Options:
266
304
267 - verbose (0): print the command to be executed.
305 - verbose (0): print the command to be executed.
268
306
269 - debug (0): only print, do not actually execute.
307 - debug (0): only print, do not actually execute.
270
308
271 - header (''): Header to print on screen prior to the executed command (it
309 - header (''): Header to print on screen prior to the executed command (it
272 is only prepended to the command, no newlines are added).
310 is only prepended to the command, no newlines are added).
273
311
274 Note: this is similar to genutils.system(), but it returns None so it can
312 Note: this is similar to genutils.system(), but it returns None so it can
275 be conveniently used in interactive loops without getting the return value
313 be conveniently used in interactive loops without getting the return value
276 (typically 0) printed many times."""
314 (typically 0) printed many times."""
277
315
278 stat = 0
316 stat = 0
279 if verbose or debug: print header+cmd
317 if verbose or debug: print header+cmd
280 # flush stdout so we don't mangle python's buffering
318 # flush stdout so we don't mangle python's buffering
281 sys.stdout.flush()
319 sys.stdout.flush()
282 if not debug:
320 if not debug:
283 os.system(cmd)
321 os.system(cmd)
284
322
285 def getoutput(cmd,verbose=0,debug=0,header='',split=0):
323 def getoutput(cmd,verbose=0,debug=0,header='',split=0):
286 """Dummy substitute for perl's backquotes.
324 """Dummy substitute for perl's backquotes.
287
325
288 Executes a command and returns the output.
326 Executes a command and returns the output.
289
327
290 Accepts the same arguments as system(), plus:
328 Accepts the same arguments as system(), plus:
291
329
292 - split(0): if true, the output is returned as a list split on newlines.
330 - split(0): if true, the output is returned as a list split on newlines.
293
331
294 Note: a stateful version of this function is available through the
332 Note: a stateful version of this function is available through the
295 SystemExec class."""
333 SystemExec class."""
296
334
297 if verbose or debug: print header+cmd
335 if verbose or debug: print header+cmd
298 if not debug:
336 if not debug:
299 output = commands.getoutput(cmd)
337 output = commands.getoutput(cmd)
300 if split:
338 if split:
301 return output.split('\n')
339 return output.split('\n')
302 else:
340 else:
303 return output
341 return output
304
342
305 def getoutputerror(cmd,verbose=0,debug=0,header='',split=0):
343 def getoutputerror(cmd,verbose=0,debug=0,header='',split=0):
306 """Return (standard output,standard error) of executing cmd in a shell.
344 """Return (standard output,standard error) of executing cmd in a shell.
307
345
308 Accepts the same arguments as system(), plus:
346 Accepts the same arguments as system(), plus:
309
347
310 - split(0): if true, each of stdout/err is returned as a list split on
348 - split(0): if true, each of stdout/err is returned as a list split on
311 newlines.
349 newlines.
312
350
313 Note: a stateful version of this function is available through the
351 Note: a stateful version of this function is available through the
314 SystemExec class."""
352 SystemExec class."""
315
353
316 if verbose or debug: print header+cmd
354 if verbose or debug: print header+cmd
317 if not cmd:
355 if not cmd:
318 if split:
356 if split:
319 return [],[]
357 return [],[]
320 else:
358 else:
321 return '',''
359 return '',''
322 if not debug:
360 if not debug:
323 pin,pout,perr = os.popen3(cmd)
361 pin,pout,perr = os.popen3(cmd)
324 tout = pout.read().rstrip()
362 tout = pout.read().rstrip()
325 terr = perr.read().rstrip()
363 terr = perr.read().rstrip()
326 pin.close()
364 pin.close()
327 pout.close()
365 pout.close()
328 perr.close()
366 perr.close()
329 if split:
367 if split:
330 return tout.split('\n'),terr.split('\n')
368 return tout.split('\n'),terr.split('\n')
331 else:
369 else:
332 return tout,terr
370 return tout,terr
333
371
334 # for compatibility with older naming conventions
372 # for compatibility with older naming conventions
335 xsys = system
373 xsys = system
336 bq = getoutput
374 bq = getoutput
337
375
338 class SystemExec:
376 class SystemExec:
339 """Access the system and getoutput functions through a stateful interface.
377 """Access the system and getoutput functions through a stateful interface.
340
378
341 Note: here we refer to the system and getoutput functions from this
379 Note: here we refer to the system and getoutput functions from this
342 library, not the ones from the standard python library.
380 library, not the ones from the standard python library.
343
381
344 This class offers the system and getoutput functions as methods, but the
382 This class offers the system and getoutput functions as methods, but the
345 verbose, debug and header parameters can be set for the instance (at
383 verbose, debug and header parameters can be set for the instance (at
346 creation time or later) so that they don't need to be specified on each
384 creation time or later) so that they don't need to be specified on each
347 call.
385 call.
348
386
349 For efficiency reasons, there's no way to override the parameters on a
387 For efficiency reasons, there's no way to override the parameters on a
350 per-call basis other than by setting instance attributes. If you need
388 per-call basis other than by setting instance attributes. If you need
351 local overrides, it's best to directly call system() or getoutput().
389 local overrides, it's best to directly call system() or getoutput().
352
390
353 The following names are provided as alternate options:
391 The following names are provided as alternate options:
354 - xsys: alias to system
392 - xsys: alias to system
355 - bq: alias to getoutput
393 - bq: alias to getoutput
356
394
357 An instance can then be created as:
395 An instance can then be created as:
358 >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ')
396 >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ')
359
397
360 And used as:
398 And used as:
361 >>> sysexec.xsys('pwd')
399 >>> sysexec.xsys('pwd')
362 >>> dirlist = sysexec.bq('ls -l')
400 >>> dirlist = sysexec.bq('ls -l')
363 """
401 """
364
402
365 def __init__(self,verbose=0,debug=0,header='',split=0):
403 def __init__(self,verbose=0,debug=0,header='',split=0):
366 """Specify the instance's values for verbose, debug and header."""
404 """Specify the instance's values for verbose, debug and header."""
367 setattr_list(self,'verbose debug header split')
405 setattr_list(self,'verbose debug header split')
368
406
369 def system(self,cmd):
407 def system(self,cmd):
370 """Stateful interface to system(), with the same keyword parameters."""
408 """Stateful interface to system(), with the same keyword parameters."""
371
409
372 system(cmd,self.verbose,self.debug,self.header)
410 system(cmd,self.verbose,self.debug,self.header)
373
411
374 def shell(self,cmd):
412 def shell(self,cmd):
375 """Stateful interface to shell(), with the same keyword parameters."""
413 """Stateful interface to shell(), with the same keyword parameters."""
376
414
377 shell(cmd,self.verbose,self.debug,self.header)
415 shell(cmd,self.verbose,self.debug,self.header)
378
416
379 xsys = system # alias
417 xsys = system # alias
380
418
381 def getoutput(self,cmd):
419 def getoutput(self,cmd):
382 """Stateful interface to getoutput()."""
420 """Stateful interface to getoutput()."""
383
421
384 return getoutput(cmd,self.verbose,self.debug,self.header,self.split)
422 return getoutput(cmd,self.verbose,self.debug,self.header,self.split)
385
423
386 def getoutputerror(self,cmd):
424 def getoutputerror(self,cmd):
387 """Stateful interface to getoutputerror()."""
425 """Stateful interface to getoutputerror()."""
388
426
389 return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split)
427 return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split)
390
428
391 bq = getoutput # alias
429 bq = getoutput # alias
392
430
393 #-----------------------------------------------------------------------------
431 #-----------------------------------------------------------------------------
394 def mutex_opts(dict,ex_op):
432 def mutex_opts(dict,ex_op):
395 """Check for presence of mutually exclusive keys in a dict.
433 """Check for presence of mutually exclusive keys in a dict.
396
434
397 Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]"""
435 Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]"""
398 for op1,op2 in ex_op:
436 for op1,op2 in ex_op:
399 if op1 in dict and op2 in dict:
437 if op1 in dict and op2 in dict:
400 raise ValueError,'\n*** ERROR in Arguments *** '\
438 raise ValueError,'\n*** ERROR in Arguments *** '\
401 'Options '+op1+' and '+op2+' are mutually exclusive.'
439 'Options '+op1+' and '+op2+' are mutually exclusive.'
402
440
403 #-----------------------------------------------------------------------------
441 #-----------------------------------------------------------------------------
404 def filefind(fname,alt_dirs = None):
442 def filefind(fname,alt_dirs = None):
405 """Return the given filename either in the current directory, if it
443 """Return the given filename either in the current directory, if it
406 exists, or in a specified list of directories.
444 exists, or in a specified list of directories.
407
445
408 ~ expansion is done on all file and directory names.
446 ~ expansion is done on all file and directory names.
409
447
410 Upon an unsuccessful search, raise an IOError exception."""
448 Upon an unsuccessful search, raise an IOError exception."""
411
449
412 if alt_dirs is None:
450 if alt_dirs is None:
413 try:
451 try:
414 alt_dirs = get_home_dir()
452 alt_dirs = get_home_dir()
415 except HomeDirError:
453 except HomeDirError:
416 alt_dirs = os.getcwd()
454 alt_dirs = os.getcwd()
417 search = [fname] + list_strings(alt_dirs)
455 search = [fname] + list_strings(alt_dirs)
418 search = map(os.path.expanduser,search)
456 search = map(os.path.expanduser,search)
419 #print 'search list for',fname,'list:',search # dbg
457 #print 'search list for',fname,'list:',search # dbg
420 fname = search[0]
458 fname = search[0]
421 if os.path.isfile(fname):
459 if os.path.isfile(fname):
422 return fname
460 return fname
423 for direc in search[1:]:
461 for direc in search[1:]:
424 testname = os.path.join(direc,fname)
462 testname = os.path.join(direc,fname)
425 #print 'testname',testname # dbg
463 #print 'testname',testname # dbg
426 if os.path.isfile(testname):
464 if os.path.isfile(testname):
427 return testname
465 return testname
428 raise IOError,'File' + `fname` + \
466 raise IOError,'File' + `fname` + \
429 ' not found in current or supplied directories:' + `alt_dirs`
467 ' not found in current or supplied directories:' + `alt_dirs`
430
468
431 #----------------------------------------------------------------------------
469 #----------------------------------------------------------------------------
432 def target_outdated(target,deps):
470 def target_outdated(target,deps):
433 """Determine whether a target is out of date.
471 """Determine whether a target is out of date.
434
472
435 target_outdated(target,deps) -> 1/0
473 target_outdated(target,deps) -> 1/0
436
474
437 deps: list of filenames which MUST exist.
475 deps: list of filenames which MUST exist.
438 target: single filename which may or may not exist.
476 target: single filename which may or may not exist.
439
477
440 If target doesn't exist or is older than any file listed in deps, return
478 If target doesn't exist or is older than any file listed in deps, return
441 true, otherwise return false.
479 true, otherwise return false.
442 """
480 """
443 try:
481 try:
444 target_time = os.path.getmtime(target)
482 target_time = os.path.getmtime(target)
445 except os.error:
483 except os.error:
446 return 1
484 return 1
447 for dep in deps:
485 for dep in deps:
448 dep_time = os.path.getmtime(dep)
486 dep_time = os.path.getmtime(dep)
449 if dep_time > target_time:
487 if dep_time > target_time:
450 #print "For target",target,"Dep failed:",dep # dbg
488 #print "For target",target,"Dep failed:",dep # dbg
451 #print "times (dep,tar):",dep_time,target_time # dbg
489 #print "times (dep,tar):",dep_time,target_time # dbg
452 return 1
490 return 1
453 return 0
491 return 0
454
492
455 #-----------------------------------------------------------------------------
493 #-----------------------------------------------------------------------------
456 def target_update(target,deps,cmd):
494 def target_update(target,deps,cmd):
457 """Update a target with a given command given a list of dependencies.
495 """Update a target with a given command given a list of dependencies.
458
496
459 target_update(target,deps,cmd) -> runs cmd if target is outdated.
497 target_update(target,deps,cmd) -> runs cmd if target is outdated.
460
498
461 This is just a wrapper around target_outdated() which calls the given
499 This is just a wrapper around target_outdated() which calls the given
462 command if target is outdated."""
500 command if target is outdated."""
463
501
464 if target_outdated(target,deps):
502 if target_outdated(target,deps):
465 xsys(cmd)
503 xsys(cmd)
466
504
467 #----------------------------------------------------------------------------
505 #----------------------------------------------------------------------------
468 def unquote_ends(istr):
506 def unquote_ends(istr):
469 """Remove a single pair of quotes from the endpoints of a string."""
507 """Remove a single pair of quotes from the endpoints of a string."""
470
508
471 if not istr:
509 if not istr:
472 return istr
510 return istr
473 if (istr[0]=="'" and istr[-1]=="'") or \
511 if (istr[0]=="'" and istr[-1]=="'") or \
474 (istr[0]=='"' and istr[-1]=='"'):
512 (istr[0]=='"' and istr[-1]=='"'):
475 return istr[1:-1]
513 return istr[1:-1]
476 else:
514 else:
477 return istr
515 return istr
478
516
479 #----------------------------------------------------------------------------
517 #----------------------------------------------------------------------------
480 def process_cmdline(argv,names=[],defaults={},usage=''):
518 def process_cmdline(argv,names=[],defaults={},usage=''):
481 """ Process command-line options and arguments.
519 """ Process command-line options and arguments.
482
520
483 Arguments:
521 Arguments:
484
522
485 - argv: list of arguments, typically sys.argv.
523 - argv: list of arguments, typically sys.argv.
486
524
487 - names: list of option names. See DPyGetOpt docs for details on options
525 - names: list of option names. See DPyGetOpt docs for details on options
488 syntax.
526 syntax.
489
527
490 - defaults: dict of default values.
528 - defaults: dict of default values.
491
529
492 - usage: optional usage notice to print if a wrong argument is passed.
530 - usage: optional usage notice to print if a wrong argument is passed.
493
531
494 Return a dict of options and a list of free arguments."""
532 Return a dict of options and a list of free arguments."""
495
533
496 getopt = DPyGetOpt.DPyGetOpt()
534 getopt = DPyGetOpt.DPyGetOpt()
497 getopt.setIgnoreCase(0)
535 getopt.setIgnoreCase(0)
498 getopt.parseConfiguration(names)
536 getopt.parseConfiguration(names)
499
537
500 try:
538 try:
501 getopt.processArguments(argv)
539 getopt.processArguments(argv)
502 except:
540 except:
503 print usage
541 print usage
504 warn(`sys.exc_value`,level=4)
542 warn(`sys.exc_value`,level=4)
505
543
506 defaults.update(getopt.optionValues)
544 defaults.update(getopt.optionValues)
507 args = getopt.freeValues
545 args = getopt.freeValues
508
546
509 return defaults,args
547 return defaults,args
510
548
511 #----------------------------------------------------------------------------
549 #----------------------------------------------------------------------------
512 def optstr2types(ostr):
550 def optstr2types(ostr):
513 """Convert a string of option names to a dict of type mappings.
551 """Convert a string of option names to a dict of type mappings.
514
552
515 optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'}
553 optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'}
516
554
517 This is used to get the types of all the options in a string formatted
555 This is used to get the types of all the options in a string formatted
518 with the conventions of DPyGetOpt. The 'type' None is used for options
556 with the conventions of DPyGetOpt. The 'type' None is used for options
519 which are strings (they need no further conversion). This function's main
557 which are strings (they need no further conversion). This function's main
520 use is to get a typemap for use with read_dict().
558 use is to get a typemap for use with read_dict().
521 """
559 """
522
560
523 typeconv = {None:'',int:'',float:''}
561 typeconv = {None:'',int:'',float:''}
524 typemap = {'s':None,'i':int,'f':float}
562 typemap = {'s':None,'i':int,'f':float}
525 opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)')
563 opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)')
526
564
527 for w in ostr.split():
565 for w in ostr.split():
528 oname,alias,otype = opt_re.match(w).groups()
566 oname,alias,otype = opt_re.match(w).groups()
529 if otype == '' or alias == '!': # simple switches are integers too
567 if otype == '' or alias == '!': # simple switches are integers too
530 otype = 'i'
568 otype = 'i'
531 typeconv[typemap[otype]] += oname + ' '
569 typeconv[typemap[otype]] += oname + ' '
532 return typeconv
570 return typeconv
533
571
534 #----------------------------------------------------------------------------
572 #----------------------------------------------------------------------------
535 def read_dict(filename,type_conv=None,**opt):
573 def read_dict(filename,type_conv=None,**opt):
536
574
537 """Read a dictionary of key=value pairs from an input file, optionally
575 """Read a dictionary of key=value pairs from an input file, optionally
538 performing conversions on the resulting values.
576 performing conversions on the resulting values.
539
577
540 read_dict(filename,type_conv,**opt) -> dict
578 read_dict(filename,type_conv,**opt) -> dict
541
579
542 Only one value per line is accepted, the format should be
580 Only one value per line is accepted, the format should be
543 # optional comments are ignored
581 # optional comments are ignored
544 key value\n
582 key value\n
545
583
546 Args:
584 Args:
547
585
548 - type_conv: A dictionary specifying which keys need to be converted to
586 - type_conv: A dictionary specifying which keys need to be converted to
549 which types. By default all keys are read as strings. This dictionary
587 which types. By default all keys are read as strings. This dictionary
550 should have as its keys valid conversion functions for strings
588 should have as its keys valid conversion functions for strings
551 (int,long,float,complex, or your own). The value for each key
589 (int,long,float,complex, or your own). The value for each key
552 (converter) should be a whitespace separated string containing the names
590 (converter) should be a whitespace separated string containing the names
553 of all the entries in the file to be converted using that function. For
591 of all the entries in the file to be converted using that function. For
554 keys to be left alone, use None as the conversion function (only needed
592 keys to be left alone, use None as the conversion function (only needed
555 with purge=1, see below).
593 with purge=1, see below).
556
594
557 - opt: dictionary with extra options as below (default in parens)
595 - opt: dictionary with extra options as below (default in parens)
558
596
559 purge(0): if set to 1, all keys *not* listed in type_conv are purged out
597 purge(0): if set to 1, all keys *not* listed in type_conv are purged out
560 of the dictionary to be returned. If purge is going to be used, the
598 of the dictionary to be returned. If purge is going to be used, the
561 set of keys to be left as strings also has to be explicitly specified
599 set of keys to be left as strings also has to be explicitly specified
562 using the (non-existent) conversion function None.
600 using the (non-existent) conversion function None.
563
601
564 fs(None): field separator. This is the key/value separator to be used
602 fs(None): field separator. This is the key/value separator to be used
565 when parsing the file. The None default means any whitespace [behavior
603 when parsing the file. The None default means any whitespace [behavior
566 of string.split()].
604 of string.split()].
567
605
568 strip(0): if 1, strip string values of leading/trailinig whitespace.
606 strip(0): if 1, strip string values of leading/trailinig whitespace.
569
607
570 warn(1): warning level if requested keys are not found in file.
608 warn(1): warning level if requested keys are not found in file.
571 - 0: silently ignore.
609 - 0: silently ignore.
572 - 1: inform but proceed.
610 - 1: inform but proceed.
573 - 2: raise KeyError exception.
611 - 2: raise KeyError exception.
574
612
575 no_empty(0): if 1, remove keys with whitespace strings as a value.
613 no_empty(0): if 1, remove keys with whitespace strings as a value.
576
614
577 unique([]): list of keys (or space separated string) which can't be
615 unique([]): list of keys (or space separated string) which can't be
578 repeated. If one such key is found in the file, each new instance
616 repeated. If one such key is found in the file, each new instance
579 overwrites the previous one. For keys not listed here, the behavior is
617 overwrites the previous one. For keys not listed here, the behavior is
580 to make a list of all appearances.
618 to make a list of all appearances.
581
619
582 Example:
620 Example:
583 If the input file test.ini has:
621 If the input file test.ini has:
584 i 3
622 i 3
585 x 4.5
623 x 4.5
586 y 5.5
624 y 5.5
587 s hi ho
625 s hi ho
588 Then:
626 Then:
589
627
590 >>> type_conv={int:'i',float:'x',None:'s'}
628 >>> type_conv={int:'i',float:'x',None:'s'}
591 >>> read_dict('test.ini')
629 >>> read_dict('test.ini')
592 {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'}
630 {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'}
593 >>> read_dict('test.ini',type_conv)
631 >>> read_dict('test.ini',type_conv)
594 {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'}
632 {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'}
595 >>> read_dict('test.ini',type_conv,purge=1)
633 >>> read_dict('test.ini',type_conv,purge=1)
596 {'i': 3, 's': 'hi ho', 'x': 4.5}
634 {'i': 3, 's': 'hi ho', 'x': 4.5}
597 """
635 """
598
636
599 # starting config
637 # starting config
600 opt.setdefault('purge',0)
638 opt.setdefault('purge',0)
601 opt.setdefault('fs',None) # field sep defaults to any whitespace
639 opt.setdefault('fs',None) # field sep defaults to any whitespace
602 opt.setdefault('strip',0)
640 opt.setdefault('strip',0)
603 opt.setdefault('warn',1)
641 opt.setdefault('warn',1)
604 opt.setdefault('no_empty',0)
642 opt.setdefault('no_empty',0)
605 opt.setdefault('unique','')
643 opt.setdefault('unique','')
606 if type(opt['unique']) in StringTypes:
644 if type(opt['unique']) in StringTypes:
607 unique_keys = qw(opt['unique'])
645 unique_keys = qw(opt['unique'])
608 elif type(opt['unique']) in (types.TupleType,types.ListType):
646 elif type(opt['unique']) in (types.TupleType,types.ListType):
609 unique_keys = opt['unique']
647 unique_keys = opt['unique']
610 else:
648 else:
611 raise ValueError, 'Unique keys must be given as a string, List or Tuple'
649 raise ValueError, 'Unique keys must be given as a string, List or Tuple'
612
650
613 dict = {}
651 dict = {}
614 # first read in table of values as strings
652 # first read in table of values as strings
615 file = open(filename,'r')
653 file = open(filename,'r')
616 for line in file.readlines():
654 for line in file.readlines():
617 line = line.strip()
655 line = line.strip()
618 if len(line) and line[0]=='#': continue
656 if len(line) and line[0]=='#': continue
619 if len(line)>0:
657 if len(line)>0:
620 lsplit = line.split(opt['fs'],1)
658 lsplit = line.split(opt['fs'],1)
621 try:
659 try:
622 key,val = lsplit
660 key,val = lsplit
623 except ValueError:
661 except ValueError:
624 key,val = lsplit[0],''
662 key,val = lsplit[0],''
625 key = key.strip()
663 key = key.strip()
626 if opt['strip']: val = val.strip()
664 if opt['strip']: val = val.strip()
627 if val == "''" or val == '""': val = ''
665 if val == "''" or val == '""': val = ''
628 if opt['no_empty'] and (val=='' or val.isspace()):
666 if opt['no_empty'] and (val=='' or val.isspace()):
629 continue
667 continue
630 # if a key is found more than once in the file, build a list
668 # if a key is found more than once in the file, build a list
631 # unless it's in the 'unique' list. In that case, last found in file
669 # unless it's in the 'unique' list. In that case, last found in file
632 # takes precedence. User beware.
670 # takes precedence. User beware.
633 try:
671 try:
634 if dict[key] and key in unique_keys:
672 if dict[key] and key in unique_keys:
635 dict[key] = val
673 dict[key] = val
636 elif type(dict[key]) is types.ListType:
674 elif type(dict[key]) is types.ListType:
637 dict[key].append(val)
675 dict[key].append(val)
638 else:
676 else:
639 dict[key] = [dict[key],val]
677 dict[key] = [dict[key],val]
640 except KeyError:
678 except KeyError:
641 dict[key] = val
679 dict[key] = val
642 # purge if requested
680 # purge if requested
643 if opt['purge']:
681 if opt['purge']:
644 accepted_keys = qwflat(type_conv.values())
682 accepted_keys = qwflat(type_conv.values())
645 for key in dict.keys():
683 for key in dict.keys():
646 if key in accepted_keys: continue
684 if key in accepted_keys: continue
647 del(dict[key])
685 del(dict[key])
648 # now convert if requested
686 # now convert if requested
649 if type_conv==None: return dict
687 if type_conv==None: return dict
650 conversions = type_conv.keys()
688 conversions = type_conv.keys()
651 try: conversions.remove(None)
689 try: conversions.remove(None)
652 except: pass
690 except: pass
653 for convert in conversions:
691 for convert in conversions:
654 for val in qw(type_conv[convert]):
692 for val in qw(type_conv[convert]):
655 try:
693 try:
656 dict[val] = convert(dict[val])
694 dict[val] = convert(dict[val])
657 except KeyError,e:
695 except KeyError,e:
658 if opt['warn'] == 0:
696 if opt['warn'] == 0:
659 pass
697 pass
660 elif opt['warn'] == 1:
698 elif opt['warn'] == 1:
661 print >>sys.stderr, 'Warning: key',val,\
699 print >>sys.stderr, 'Warning: key',val,\
662 'not found in file',filename
700 'not found in file',filename
663 elif opt['warn'] == 2:
701 elif opt['warn'] == 2:
664 raise KeyError,e
702 raise KeyError,e
665 else:
703 else:
666 raise ValueError,'Warning level must be 0,1 or 2'
704 raise ValueError,'Warning level must be 0,1 or 2'
667
705
668 return dict
706 return dict
669
707
670 #----------------------------------------------------------------------------
708 #----------------------------------------------------------------------------
671 def flag_calls(func):
709 def flag_calls(func):
672 """Wrap a function to detect and flag when it gets called.
710 """Wrap a function to detect and flag when it gets called.
673
711
674 This is a decorator which takes a function and wraps it in a function with
712 This is a decorator which takes a function and wraps it in a function with
675 a 'called' attribute. wrapper.called is initialized to False.
713 a 'called' attribute. wrapper.called is initialized to False.
676
714
677 The wrapper.called attribute is set to False right before each call to the
715 The wrapper.called attribute is set to False right before each call to the
678 wrapped function, so if the call fails it remains False. After the call
716 wrapped function, so if the call fails it remains False. After the call
679 completes, wrapper.called is set to True and the output is returned.
717 completes, wrapper.called is set to True and the output is returned.
680
718
681 Testing for truth in wrapper.called allows you to determine if a call to
719 Testing for truth in wrapper.called allows you to determine if a call to
682 func() was attempted and succeeded."""
720 func() was attempted and succeeded."""
683
721
684 def wrapper(*args,**kw):
722 def wrapper(*args,**kw):
685 wrapper.called = False
723 wrapper.called = False
686 out = func(*args,**kw)
724 out = func(*args,**kw)
687 wrapper.called = True
725 wrapper.called = True
688 return out
726 return out
689
727
690 wrapper.called = False
728 wrapper.called = False
691 wrapper.__doc__ = func.__doc__
729 wrapper.__doc__ = func.__doc__
692 return wrapper
730 return wrapper
693
731
694 #----------------------------------------------------------------------------
732 #----------------------------------------------------------------------------
695 class HomeDirError(Error):
733 class HomeDirError(Error):
696 pass
734 pass
697
735
698 def get_home_dir():
736 def get_home_dir():
699 """Return the closest possible equivalent to a 'home' directory.
737 """Return the closest possible equivalent to a 'home' directory.
700
738
701 We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH.
739 We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH.
702
740
703 Currently only Posix and NT are implemented, a HomeDirError exception is
741 Currently only Posix and NT are implemented, a HomeDirError exception is
704 raised for all other OSes. """
742 raised for all other OSes. """
705
743
706 isdir = os.path.isdir
744 isdir = os.path.isdir
707 env = os.environ
745 env = os.environ
708 try:
746 try:
709 homedir = env['HOME']
747 homedir = env['HOME']
710 if not isdir(homedir):
748 if not isdir(homedir):
711 # in case a user stuck some string which does NOT resolve to a
749 # in case a user stuck some string which does NOT resolve to a
712 # valid path, it's as good as if we hadn't foud it
750 # valid path, it's as good as if we hadn't foud it
713 raise KeyError
751 raise KeyError
714 return homedir
752 return homedir
715 except KeyError:
753 except KeyError:
716 if os.name == 'posix':
754 if os.name == 'posix':
717 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
755 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
718 elif os.name == 'nt':
756 elif os.name == 'nt':
719 # For some strange reason, win9x returns 'nt' for os.name.
757 # For some strange reason, win9x returns 'nt' for os.name.
720 try:
758 try:
721 homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH'])
759 homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH'])
722 if not isdir(homedir):
760 if not isdir(homedir):
723 homedir = os.path.join(env['USERPROFILE'])
761 homedir = os.path.join(env['USERPROFILE'])
724 if not isdir(homedir):
762 if not isdir(homedir):
725 raise HomeDirError
763 raise HomeDirError
726 return homedir
764 return homedir
727 except:
765 except:
728 try:
766 try:
729 # Use the registry to get the 'My Documents' folder.
767 # Use the registry to get the 'My Documents' folder.
730 import _winreg as wreg
768 import _winreg as wreg
731 key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
769 key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
732 "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
770 "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
733 homedir = wreg.QueryValueEx(key,'Personal')[0]
771 homedir = wreg.QueryValueEx(key,'Personal')[0]
734 key.Close()
772 key.Close()
735 if not isdir(homedir):
773 if not isdir(homedir):
736 e = ('Invalid "Personal" folder registry key '
774 e = ('Invalid "Personal" folder registry key '
737 'typically "My Documents".\n'
775 'typically "My Documents".\n'
738 'Value: %s\n'
776 'Value: %s\n'
739 'This is not a valid directory on your system.' %
777 'This is not a valid directory on your system.' %
740 homedir)
778 homedir)
741 raise HomeDirError(e)
779 raise HomeDirError(e)
742 return homedir
780 return homedir
743 except HomeDirError:
781 except HomeDirError:
744 raise
782 raise
745 except:
783 except:
746 return 'C:\\'
784 return 'C:\\'
747 elif os.name == 'dos':
785 elif os.name == 'dos':
748 # Desperate, may do absurd things in classic MacOS. May work under DOS.
786 # Desperate, may do absurd things in classic MacOS. May work under DOS.
749 return 'C:\\'
787 return 'C:\\'
750 else:
788 else:
751 raise HomeDirError,'support for your operating system not implemented.'
789 raise HomeDirError,'support for your operating system not implemented.'
752
790
753 #****************************************************************************
791 #****************************************************************************
754 # strings and text
792 # strings and text
755
793
756 class LSString(str):
794 class LSString(str):
757 """String derivative with a special access attributes.
795 """String derivative with a special access attributes.
758
796
759 These are normal strings, but with the special attributes:
797 These are normal strings, but with the special attributes:
760
798
761 .l (or .list) : value as list (split on newlines).
799 .l (or .list) : value as list (split on newlines).
762 .n (or .nlstr): original value (the string itself).
800 .n (or .nlstr): original value (the string itself).
763 .s (or .spstr): value as whitespace-separated string.
801 .s (or .spstr): value as whitespace-separated string.
764
802
765 Any values which require transformations are computed only once and
803 Any values which require transformations are computed only once and
766 cached.
804 cached.
767
805
768 Such strings are very useful to efficiently interact with the shell, which
806 Such strings are very useful to efficiently interact with the shell, which
769 typically only understands whitespace-separated options for commands."""
807 typically only understands whitespace-separated options for commands."""
770
808
771 def get_list(self):
809 def get_list(self):
772 try:
810 try:
773 return self.__list
811 return self.__list
774 except AttributeError:
812 except AttributeError:
775 self.__list = self.split('\n')
813 self.__list = self.split('\n')
776 return self.__list
814 return self.__list
777
815
778 l = list = property(get_list)
816 l = list = property(get_list)
779
817
780 def get_spstr(self):
818 def get_spstr(self):
781 try:
819 try:
782 return self.__spstr
820 return self.__spstr
783 except AttributeError:
821 except AttributeError:
784 self.__spstr = self.replace('\n',' ')
822 self.__spstr = self.replace('\n',' ')
785 return self.__spstr
823 return self.__spstr
786
824
787 s = spstr = property(get_spstr)
825 s = spstr = property(get_spstr)
788
826
789 def get_nlstr(self):
827 def get_nlstr(self):
790 return self
828 return self
791
829
792 n = nlstr = property(get_nlstr)
830 n = nlstr = property(get_nlstr)
793
831
794 class SList(list):
832 class SList(list):
795 """List derivative with a special access attributes.
833 """List derivative with a special access attributes.
796
834
797 These are normal lists, but with the special attributes:
835 These are normal lists, but with the special attributes:
798
836
799 .l (or .list) : value as list (the list itself).
837 .l (or .list) : value as list (the list itself).
800 .n (or .nlstr): value as a string, joined on newlines.
838 .n (or .nlstr): value as a string, joined on newlines.
801 .s (or .spstr): value as a string, joined on spaces.
839 .s (or .spstr): value as a string, joined on spaces.
802
840
803 Any values which require transformations are computed only once and
841 Any values which require transformations are computed only once and
804 cached."""
842 cached."""
805
843
806 def get_list(self):
844 def get_list(self):
807 return self
845 return self
808
846
809 l = list = property(get_list)
847 l = list = property(get_list)
810
848
811 def get_spstr(self):
849 def get_spstr(self):
812 try:
850 try:
813 return self.__spstr
851 return self.__spstr
814 except AttributeError:
852 except AttributeError:
815 self.__spstr = ' '.join(self)
853 self.__spstr = ' '.join(self)
816 return self.__spstr
854 return self.__spstr
817
855
818 s = spstr = property(get_spstr)
856 s = spstr = property(get_spstr)
819
857
820 def get_nlstr(self):
858 def get_nlstr(self):
821 try:
859 try:
822 return self.__nlstr
860 return self.__nlstr
823 except AttributeError:
861 except AttributeError:
824 self.__nlstr = '\n'.join(self)
862 self.__nlstr = '\n'.join(self)
825 return self.__nlstr
863 return self.__nlstr
826
864
827 n = nlstr = property(get_nlstr)
865 n = nlstr = property(get_nlstr)
828
866
829 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
867 def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'):
830 """Take multiple lines of input.
868 """Take multiple lines of input.
831
869
832 A list with each line of input as a separate element is returned when a
870 A list with each line of input as a separate element is returned when a
833 termination string is entered (defaults to a single '.'). Input can also
871 termination string is entered (defaults to a single '.'). Input can also
834 terminate via EOF (^D in Unix, ^Z-RET in Windows).
872 terminate via EOF (^D in Unix, ^Z-RET in Windows).
835
873
836 Lines of input which end in \\ are joined into single entries (and a
874 Lines of input which end in \\ are joined into single entries (and a
837 secondary continuation prompt is issued as long as the user terminates
875 secondary continuation prompt is issued as long as the user terminates
838 lines with \\). This allows entering very long strings which are still
876 lines with \\). This allows entering very long strings which are still
839 meant to be treated as single entities.
877 meant to be treated as single entities.
840 """
878 """
841
879
842 try:
880 try:
843 if header:
881 if header:
844 header += '\n'
882 header += '\n'
845 lines = [raw_input(header + ps1)]
883 lines = [raw_input(header + ps1)]
846 except EOFError:
884 except EOFError:
847 return []
885 return []
848 terminate = [terminate_str]
886 terminate = [terminate_str]
849 try:
887 try:
850 while lines[-1:] != terminate:
888 while lines[-1:] != terminate:
851 new_line = raw_input(ps1)
889 new_line = raw_input(ps1)
852 while new_line.endswith('\\'):
890 while new_line.endswith('\\'):
853 new_line = new_line[:-1] + raw_input(ps2)
891 new_line = new_line[:-1] + raw_input(ps2)
854 lines.append(new_line)
892 lines.append(new_line)
855
893
856 return lines[:-1] # don't return the termination command
894 return lines[:-1] # don't return the termination command
857 except EOFError:
895 except EOFError:
858 print
896 print
859 return lines
897 return lines
860
898
861 #----------------------------------------------------------------------------
899 #----------------------------------------------------------------------------
862 def raw_input_ext(prompt='', ps2='... '):
900 def raw_input_ext(prompt='', ps2='... '):
863 """Similar to raw_input(), but accepts extended lines if input ends with \\."""
901 """Similar to raw_input(), but accepts extended lines if input ends with \\."""
864
902
865 line = raw_input(prompt)
903 line = raw_input(prompt)
866 while line.endswith('\\'):
904 while line.endswith('\\'):
867 line = line[:-1] + raw_input(ps2)
905 line = line[:-1] + raw_input(ps2)
868 return line
906 return line
869
907
870 #----------------------------------------------------------------------------
908 #----------------------------------------------------------------------------
871 def ask_yes_no(prompt,default=None):
909 def ask_yes_no(prompt,default=None):
872 """Asks a question and returns an integer 1/0 (y/n) answer.
910 """Asks a question and returns an integer 1/0 (y/n) answer.
873
911
874 If default is given (one of 'y','n'), it is used if the user input is
912 If default is given (one of 'y','n'), it is used if the user input is
875 empty. Otherwise the question is repeated until an answer is given.
913 empty. Otherwise the question is repeated until an answer is given.
876 If EOF occurs 20 times consecutively, the default answer is assumed,
914 If EOF occurs 20 times consecutively, the default answer is assumed,
877 or if there is no default, an exception is raised to prevent infinite
915 or if there is no default, an exception is raised to prevent infinite
878 loops.
916 loops.
879
917
880 Valid answers are: y/yes/n/no (match is not case sensitive)."""
918 Valid answers are: y/yes/n/no (match is not case sensitive)."""
881
919
882 answers = {'y':1,'n':0,'yes':1,'no':0}
920 answers = {'y':1,'n':0,'yes':1,'no':0}
883 ans = None
921 ans = None
884 eofs, max_eofs = 0, 20
922 eofs, max_eofs = 0, 20
885 while ans not in answers.keys():
923 while ans not in answers.keys():
886 try:
924 try:
887 ans = raw_input(prompt+' ').lower()
925 ans = raw_input(prompt+' ').lower()
888 if not ans: # response was an empty string
926 if not ans: # response was an empty string
889 ans = default
927 ans = default
890 eofs = 0
928 eofs = 0
891 except (EOFError,KeyboardInterrupt):
929 except (EOFError,KeyboardInterrupt):
892 eofs = eofs + 1
930 eofs = eofs + 1
893 if eofs >= max_eofs:
931 if eofs >= max_eofs:
894 if default in answers.keys():
932 if default in answers.keys():
895 ans = default
933 ans = default
896 else:
934 else:
897 raise
935 raise
898
936
899 return answers[ans]
937 return answers[ans]
900
938
901 #----------------------------------------------------------------------------
939 #----------------------------------------------------------------------------
902 def marquee(txt='',width=80,mark='*'):
940 def marquee(txt='',width=80,mark='*'):
903 """Return the input string centered in a 'marquee'."""
941 """Return the input string centered in a 'marquee'."""
904 if not txt:
942 if not txt:
905 return (mark*width)[:width]
943 return (mark*width)[:width]
906 nmark = (width-len(txt)-2)/len(mark)/2
944 nmark = (width-len(txt)-2)/len(mark)/2
907 if nmark < 0: nmark =0
945 if nmark < 0: nmark =0
908 marks = mark*nmark
946 marks = mark*nmark
909 return '%s %s %s' % (marks,txt,marks)
947 return '%s %s %s' % (marks,txt,marks)
910
948
911 #----------------------------------------------------------------------------
949 #----------------------------------------------------------------------------
912 class EvalDict:
950 class EvalDict:
913 """
951 """
914 Emulate a dict which evaluates its contents in the caller's frame.
952 Emulate a dict which evaluates its contents in the caller's frame.
915
953
916 Usage:
954 Usage:
917 >>>number = 19
955 >>>number = 19
918 >>>text = "python"
956 >>>text = "python"
919 >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict()
957 >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict()
920 """
958 """
921
959
922 # This version is due to sismex01@hebmex.com on c.l.py, and is basically a
960 # This version is due to sismex01@hebmex.com on c.l.py, and is basically a
923 # modified (shorter) version of:
961 # modified (shorter) version of:
924 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by
962 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by
925 # Skip Montanaro (skip@pobox.com).
963 # Skip Montanaro (skip@pobox.com).
926
964
927 def __getitem__(self, name):
965 def __getitem__(self, name):
928 frame = sys._getframe(1)
966 frame = sys._getframe(1)
929 return eval(name, frame.f_globals, frame.f_locals)
967 return eval(name, frame.f_globals, frame.f_locals)
930
968
931 EvalString = EvalDict # for backwards compatibility
969 EvalString = EvalDict # for backwards compatibility
932 #----------------------------------------------------------------------------
970 #----------------------------------------------------------------------------
933 def qw(words,flat=0,sep=None,maxsplit=-1):
971 def qw(words,flat=0,sep=None,maxsplit=-1):
934 """Similar to Perl's qw() operator, but with some more options.
972 """Similar to Perl's qw() operator, but with some more options.
935
973
936 qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit)
974 qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit)
937
975
938 words can also be a list itself, and with flat=1, the output will be
976 words can also be a list itself, and with flat=1, the output will be
939 recursively flattened. Examples:
977 recursively flattened. Examples:
940
978
941 >>> qw('1 2')
979 >>> qw('1 2')
942 ['1', '2']
980 ['1', '2']
943 >>> qw(['a b','1 2',['m n','p q']])
981 >>> qw(['a b','1 2',['m n','p q']])
944 [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]]
982 [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]]
945 >>> qw(['a b','1 2',['m n','p q']],flat=1)
983 >>> qw(['a b','1 2',['m n','p q']],flat=1)
946 ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """
984 ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """
947
985
948 if type(words) in StringTypes:
986 if type(words) in StringTypes:
949 return [word.strip() for word in words.split(sep,maxsplit)
987 return [word.strip() for word in words.split(sep,maxsplit)
950 if word and not word.isspace() ]
988 if word and not word.isspace() ]
951 if flat:
989 if flat:
952 return flatten(map(qw,words,[1]*len(words)))
990 return flatten(map(qw,words,[1]*len(words)))
953 return map(qw,words)
991 return map(qw,words)
954
992
955 #----------------------------------------------------------------------------
993 #----------------------------------------------------------------------------
956 def qwflat(words,sep=None,maxsplit=-1):
994 def qwflat(words,sep=None,maxsplit=-1):
957 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
995 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
958 return qw(words,1,sep,maxsplit)
996 return qw(words,1,sep,maxsplit)
959
997
960 #-----------------------------------------------------------------------------
998 #-----------------------------------------------------------------------------
961 def list_strings(arg):
999 def list_strings(arg):
962 """Always return a list of strings, given a string or list of strings
1000 """Always return a list of strings, given a string or list of strings
963 as input."""
1001 as input."""
964
1002
965 if type(arg) in StringTypes: return [arg]
1003 if type(arg) in StringTypes: return [arg]
966 else: return arg
1004 else: return arg
967
1005
968 #----------------------------------------------------------------------------
1006 #----------------------------------------------------------------------------
969 def grep(pat,list,case=1):
1007 def grep(pat,list,case=1):
970 """Simple minded grep-like function.
1008 """Simple minded grep-like function.
971 grep(pat,list) returns occurrences of pat in list, None on failure.
1009 grep(pat,list) returns occurrences of pat in list, None on failure.
972
1010
973 It only does simple string matching, with no support for regexps. Use the
1011 It only does simple string matching, with no support for regexps. Use the
974 option case=0 for case-insensitive matching."""
1012 option case=0 for case-insensitive matching."""
975
1013
976 # This is pretty crude. At least it should implement copying only references
1014 # This is pretty crude. At least it should implement copying only references
977 # to the original data in case it's big. Now it copies the data for output.
1015 # to the original data in case it's big. Now it copies the data for output.
978 out=[]
1016 out=[]
979 if case:
1017 if case:
980 for term in list:
1018 for term in list:
981 if term.find(pat)>-1: out.append(term)
1019 if term.find(pat)>-1: out.append(term)
982 else:
1020 else:
983 lpat=pat.lower()
1021 lpat=pat.lower()
984 for term in list:
1022 for term in list:
985 if term.lower().find(lpat)>-1: out.append(term)
1023 if term.lower().find(lpat)>-1: out.append(term)
986
1024
987 if len(out): return out
1025 if len(out): return out
988 else: return None
1026 else: return None
989
1027
990 #----------------------------------------------------------------------------
1028 #----------------------------------------------------------------------------
991 def dgrep(pat,*opts):
1029 def dgrep(pat,*opts):
992 """Return grep() on dir()+dir(__builtins__).
1030 """Return grep() on dir()+dir(__builtins__).
993
1031
994 A very common use of grep() when working interactively."""
1032 A very common use of grep() when working interactively."""
995
1033
996 return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts)
1034 return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts)
997
1035
998 #----------------------------------------------------------------------------
1036 #----------------------------------------------------------------------------
999 def idgrep(pat):
1037 def idgrep(pat):
1000 """Case-insensitive dgrep()"""
1038 """Case-insensitive dgrep()"""
1001
1039
1002 return dgrep(pat,0)
1040 return dgrep(pat,0)
1003
1041
1004 #----------------------------------------------------------------------------
1042 #----------------------------------------------------------------------------
1005 def igrep(pat,list):
1043 def igrep(pat,list):
1006 """Synonym for case-insensitive grep."""
1044 """Synonym for case-insensitive grep."""
1007
1045
1008 return grep(pat,list,case=0)
1046 return grep(pat,list,case=0)
1009
1047
1010 #----------------------------------------------------------------------------
1048 #----------------------------------------------------------------------------
1011 def indent(str,nspaces=4,ntabs=0):
1049 def indent(str,nspaces=4,ntabs=0):
1012 """Indent a string a given number of spaces or tabstops.
1050 """Indent a string a given number of spaces or tabstops.
1013
1051
1014 indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
1052 indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
1015 """
1053 """
1016 if str is None:
1054 if str is None:
1017 return
1055 return
1018 ind = '\t'*ntabs+' '*nspaces
1056 ind = '\t'*ntabs+' '*nspaces
1019 outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind))
1057 outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind))
1020 if outstr.endswith(os.linesep+ind):
1058 if outstr.endswith(os.linesep+ind):
1021 return outstr[:-len(ind)]
1059 return outstr[:-len(ind)]
1022 else:
1060 else:
1023 return outstr
1061 return outstr
1024
1062
1025 #-----------------------------------------------------------------------------
1063 #-----------------------------------------------------------------------------
1026 def native_line_ends(filename,backup=1):
1064 def native_line_ends(filename,backup=1):
1027 """Convert (in-place) a file to line-ends native to the current OS.
1065 """Convert (in-place) a file to line-ends native to the current OS.
1028
1066
1029 If the optional backup argument is given as false, no backup of the
1067 If the optional backup argument is given as false, no backup of the
1030 original file is left. """
1068 original file is left. """
1031
1069
1032 backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'}
1070 backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'}
1033
1071
1034 bak_filename = filename + backup_suffixes[os.name]
1072 bak_filename = filename + backup_suffixes[os.name]
1035
1073
1036 original = open(filename).read()
1074 original = open(filename).read()
1037 shutil.copy2(filename,bak_filename)
1075 shutil.copy2(filename,bak_filename)
1038 try:
1076 try:
1039 new = open(filename,'wb')
1077 new = open(filename,'wb')
1040 new.write(os.linesep.join(original.splitlines()))
1078 new.write(os.linesep.join(original.splitlines()))
1041 new.write(os.linesep) # ALWAYS put an eol at the end of the file
1079 new.write(os.linesep) # ALWAYS put an eol at the end of the file
1042 new.close()
1080 new.close()
1043 except:
1081 except:
1044 os.rename(bak_filename,filename)
1082 os.rename(bak_filename,filename)
1045 if not backup:
1083 if not backup:
1046 try:
1084 try:
1047 os.remove(bak_filename)
1085 os.remove(bak_filename)
1048 except:
1086 except:
1049 pass
1087 pass
1050
1088
1051 #----------------------------------------------------------------------------
1089 #----------------------------------------------------------------------------
1052 def get_pager_cmd(pager_cmd = None):
1090 def get_pager_cmd(pager_cmd = None):
1053 """Return a pager command.
1091 """Return a pager command.
1054
1092
1055 Makes some attempts at finding an OS-correct one."""
1093 Makes some attempts at finding an OS-correct one."""
1056
1094
1057 if os.name == 'posix':
1095 if os.name == 'posix':
1058 default_pager_cmd = 'less -r' # -r for color control sequences
1096 default_pager_cmd = 'less -r' # -r for color control sequences
1059 elif os.name in ['nt','dos']:
1097 elif os.name in ['nt','dos']:
1060 default_pager_cmd = 'type'
1098 default_pager_cmd = 'type'
1061
1099
1062 if pager_cmd is None:
1100 if pager_cmd is None:
1063 try:
1101 try:
1064 pager_cmd = os.environ['PAGER']
1102 pager_cmd = os.environ['PAGER']
1065 except:
1103 except:
1066 pager_cmd = default_pager_cmd
1104 pager_cmd = default_pager_cmd
1067 return pager_cmd
1105 return pager_cmd
1068
1106
1069 #-----------------------------------------------------------------------------
1107 #-----------------------------------------------------------------------------
1070 def get_pager_start(pager,start):
1108 def get_pager_start(pager,start):
1071 """Return the string for paging files with an offset.
1109 """Return the string for paging files with an offset.
1072
1110
1073 This is the '+N' argument which less and more (under Unix) accept.
1111 This is the '+N' argument which less and more (under Unix) accept.
1074 """
1112 """
1075
1113
1076 if pager in ['less','more']:
1114 if pager in ['less','more']:
1077 if start:
1115 if start:
1078 start_string = '+' + str(start)
1116 start_string = '+' + str(start)
1079 else:
1117 else:
1080 start_string = ''
1118 start_string = ''
1081 else:
1119 else:
1082 start_string = ''
1120 start_string = ''
1083 return start_string
1121 return start_string
1084
1122
1085 #----------------------------------------------------------------------------
1123 #----------------------------------------------------------------------------
1086 def page_dumb(strng,start=0,screen_lines=25):
1124 def page_dumb(strng,start=0,screen_lines=25):
1087 """Very dumb 'pager' in Python, for when nothing else works.
1125 """Very dumb 'pager' in Python, for when nothing else works.
1088
1126
1089 Only moves forward, same interface as page(), except for pager_cmd and
1127 Only moves forward, same interface as page(), except for pager_cmd and
1090 mode."""
1128 mode."""
1091
1129
1092 out_ln = strng.splitlines()[start:]
1130 out_ln = strng.splitlines()[start:]
1093 screens = chop(out_ln,screen_lines-1)
1131 screens = chop(out_ln,screen_lines-1)
1094 if len(screens) == 1:
1132 if len(screens) == 1:
1095 print >>Term.cout, os.linesep.join(screens[0])
1133 print >>Term.cout, os.linesep.join(screens[0])
1096 else:
1134 else:
1097 for scr in screens[0:-1]:
1135 for scr in screens[0:-1]:
1098 print >>Term.cout, os.linesep.join(scr)
1136 print >>Term.cout, os.linesep.join(scr)
1099 ans = raw_input('---Return to continue, q to quit--- ')
1137 ans = raw_input('---Return to continue, q to quit--- ')
1100 if ans.lower().startswith('q'):
1138 if ans.lower().startswith('q'):
1101 return
1139 return
1102 print >>Term.cout, os.linesep.join(screens[-1])
1140 print >>Term.cout, os.linesep.join(screens[-1])
1103
1141
1104 #----------------------------------------------------------------------------
1142 #----------------------------------------------------------------------------
1105 def page(strng,start=0,screen_lines=0,pager_cmd = None):
1143 def page(strng,start=0,screen_lines=0,pager_cmd = None):
1106 """Print a string, piping through a pager after a certain length.
1144 """Print a string, piping through a pager after a certain length.
1107
1145
1108 The screen_lines parameter specifies the number of *usable* lines of your
1146 The screen_lines parameter specifies the number of *usable* lines of your
1109 terminal screen (total lines minus lines you need to reserve to show other
1147 terminal screen (total lines minus lines you need to reserve to show other
1110 information).
1148 information).
1111
1149
1112 If you set screen_lines to a number <=0, page() will try to auto-determine
1150 If you set screen_lines to a number <=0, page() will try to auto-determine
1113 your screen size and will only use up to (screen_size+screen_lines) for
1151 your screen size and will only use up to (screen_size+screen_lines) for
1114 printing, paging after that. That is, if you want auto-detection but need
1152 printing, paging after that. That is, if you want auto-detection but need
1115 to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for
1153 to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for
1116 auto-detection without any lines reserved simply use screen_lines = 0.
1154 auto-detection without any lines reserved simply use screen_lines = 0.
1117
1155
1118 If a string won't fit in the allowed lines, it is sent through the
1156 If a string won't fit in the allowed lines, it is sent through the
1119 specified pager command. If none given, look for PAGER in the environment,
1157 specified pager command. If none given, look for PAGER in the environment,
1120 and ultimately default to less.
1158 and ultimately default to less.
1121
1159
1122 If no system pager works, the string is sent through a 'dumb pager'
1160 If no system pager works, the string is sent through a 'dumb pager'
1123 written in python, very simplistic.
1161 written in python, very simplistic.
1124 """
1162 """
1125
1163
1126 # Ugly kludge, but calling curses.initscr() flat out crashes in emacs
1164 # Ugly kludge, but calling curses.initscr() flat out crashes in emacs
1127 TERM = os.environ.get('TERM','dumb')
1165 TERM = os.environ.get('TERM','dumb')
1128 if TERM in ['dumb','emacs'] and os.name != 'nt':
1166 if TERM in ['dumb','emacs'] and os.name != 'nt':
1129 print strng
1167 print strng
1130 return
1168 return
1131 # chop off the topmost part of the string we don't want to see
1169 # chop off the topmost part of the string we don't want to see
1132 str_lines = strng.split(os.linesep)[start:]
1170 str_lines = strng.split(os.linesep)[start:]
1133 str_toprint = os.linesep.join(str_lines)
1171 str_toprint = os.linesep.join(str_lines)
1134 num_newlines = len(str_lines)
1172 num_newlines = len(str_lines)
1135 len_str = len(str_toprint)
1173 len_str = len(str_toprint)
1136
1174
1137 # Dumb heuristics to guesstimate number of on-screen lines the string
1175 # Dumb heuristics to guesstimate number of on-screen lines the string
1138 # takes. Very basic, but good enough for docstrings in reasonable
1176 # takes. Very basic, but good enough for docstrings in reasonable
1139 # terminals. If someone later feels like refining it, it's not hard.
1177 # terminals. If someone later feels like refining it, it's not hard.
1140 numlines = max(num_newlines,int(len_str/80)+1)
1178 numlines = max(num_newlines,int(len_str/80)+1)
1141
1179
1142 screen_lines_def = 25 # default value if we can't auto-determine
1180 screen_lines_def = 25 # default value if we can't auto-determine
1143
1181
1144 # auto-determine screen size
1182 # auto-determine screen size
1145 if screen_lines <= 0:
1183 if screen_lines <= 0:
1146 if TERM=='xterm':
1184 if TERM=='xterm':
1147 try:
1185 try:
1148 import curses
1186 import curses
1149 if hasattr(curses,'initscr'):
1187 if hasattr(curses,'initscr'):
1150 use_curses = 1
1188 use_curses = 1
1151 else:
1189 else:
1152 use_curses = 0
1190 use_curses = 0
1153 except ImportError:
1191 except ImportError:
1154 use_curses = 0
1192 use_curses = 0
1155 else:
1193 else:
1156 # curses causes problems on many terminals other than xterm.
1194 # curses causes problems on many terminals other than xterm.
1157 use_curses = 0
1195 use_curses = 0
1158 if use_curses:
1196 if use_curses:
1159 scr = curses.initscr()
1197 scr = curses.initscr()
1160 screen_lines_real,screen_cols = scr.getmaxyx()
1198 screen_lines_real,screen_cols = scr.getmaxyx()
1161 curses.endwin()
1199 curses.endwin()
1162 screen_lines += screen_lines_real
1200 screen_lines += screen_lines_real
1163 #print '***Screen size:',screen_lines_real,'lines x',\
1201 #print '***Screen size:',screen_lines_real,'lines x',\
1164 #screen_cols,'columns.' # dbg
1202 #screen_cols,'columns.' # dbg
1165 else:
1203 else:
1166 screen_lines += screen_lines_def
1204 screen_lines += screen_lines_def
1167
1205
1168 #print 'numlines',numlines,'screenlines',screen_lines # dbg
1206 #print 'numlines',numlines,'screenlines',screen_lines # dbg
1169 if numlines <= screen_lines :
1207 if numlines <= screen_lines :
1170 #print '*** normal print' # dbg
1208 #print '*** normal print' # dbg
1171 print >>Term.cout, str_toprint
1209 print >>Term.cout, str_toprint
1172 else:
1210 else:
1173 # Try to open pager and default to internal one if that fails.
1211 # Try to open pager and default to internal one if that fails.
1174 # All failure modes are tagged as 'retval=1', to match the return
1212 # All failure modes are tagged as 'retval=1', to match the return
1175 # value of a failed system command. If any intermediate attempt
1213 # value of a failed system command. If any intermediate attempt
1176 # sets retval to 1, at the end we resort to our own page_dumb() pager.
1214 # sets retval to 1, at the end we resort to our own page_dumb() pager.
1177 pager_cmd = get_pager_cmd(pager_cmd)
1215 pager_cmd = get_pager_cmd(pager_cmd)
1178 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1216 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1179 if os.name == 'nt':
1217 if os.name == 'nt':
1180 if pager_cmd.startswith('type'):
1218 if pager_cmd.startswith('type'):
1181 # The default WinXP 'type' command is failing on complex strings.
1219 # The default WinXP 'type' command is failing on complex strings.
1182 retval = 1
1220 retval = 1
1183 else:
1221 else:
1184 tmpname = tempfile.mktemp('.txt')
1222 tmpname = tempfile.mktemp('.txt')
1185 tmpfile = file(tmpname,'wt')
1223 tmpfile = file(tmpname,'wt')
1186 tmpfile.write(strng)
1224 tmpfile.write(strng)
1187 tmpfile.close()
1225 tmpfile.close()
1188 cmd = "%s < %s" % (pager_cmd,tmpname)
1226 cmd = "%s < %s" % (pager_cmd,tmpname)
1189 if os.system(cmd):
1227 if os.system(cmd):
1190 retval = 1
1228 retval = 1
1191 else:
1229 else:
1192 retval = None
1230 retval = None
1193 os.remove(tmpname)
1231 os.remove(tmpname)
1194 else:
1232 else:
1195 try:
1233 try:
1196 retval = None
1234 retval = None
1197 # if I use popen4, things hang. No idea why.
1235 # if I use popen4, things hang. No idea why.
1198 #pager,shell_out = os.popen4(pager_cmd)
1236 #pager,shell_out = os.popen4(pager_cmd)
1199 pager = os.popen(pager_cmd,'w')
1237 pager = os.popen(pager_cmd,'w')
1200 pager.write(strng)
1238 pager.write(strng)
1201 pager.close()
1239 pager.close()
1202 retval = pager.close() # success returns None
1240 retval = pager.close() # success returns None
1203 except IOError,msg: # broken pipe when user quits
1241 except IOError,msg: # broken pipe when user quits
1204 if msg.args == (32,'Broken pipe'):
1242 if msg.args == (32,'Broken pipe'):
1205 retval = None
1243 retval = None
1206 else:
1244 else:
1207 retval = 1
1245 retval = 1
1208 except OSError:
1246 except OSError:
1209 # Other strange problems, sometimes seen in Win2k/cygwin
1247 # Other strange problems, sometimes seen in Win2k/cygwin
1210 retval = 1
1248 retval = 1
1211 if retval is not None:
1249 if retval is not None:
1212 page_dumb(strng,screen_lines=screen_lines)
1250 page_dumb(strng,screen_lines=screen_lines)
1213
1251
1214 #----------------------------------------------------------------------------
1252 #----------------------------------------------------------------------------
1215 def page_file(fname,start = 0, pager_cmd = None):
1253 def page_file(fname,start = 0, pager_cmd = None):
1216 """Page a file, using an optional pager command and starting line.
1254 """Page a file, using an optional pager command and starting line.
1217 """
1255 """
1218
1256
1219 pager_cmd = get_pager_cmd(pager_cmd)
1257 pager_cmd = get_pager_cmd(pager_cmd)
1220 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1258 pager_cmd += ' ' + get_pager_start(pager_cmd,start)
1221
1259
1222 try:
1260 try:
1223 if os.environ['TERM'] in ['emacs','dumb']:
1261 if os.environ['TERM'] in ['emacs','dumb']:
1224 raise EnvironmentError
1262 raise EnvironmentError
1225 xsys(pager_cmd + ' ' + fname)
1263 xsys(pager_cmd + ' ' + fname)
1226 except:
1264 except:
1227 try:
1265 try:
1228 if start > 0:
1266 if start > 0:
1229 start -= 1
1267 start -= 1
1230 page(open(fname).read(),start)
1268 page(open(fname).read(),start)
1231 except:
1269 except:
1232 print 'Unable to show file',`fname`
1270 print 'Unable to show file',`fname`
1233
1271
1234 #----------------------------------------------------------------------------
1272 #----------------------------------------------------------------------------
1235 def snip_print(str,width = 75,print_full = 0,header = ''):
1273 def snip_print(str,width = 75,print_full = 0,header = ''):
1236 """Print a string snipping the midsection to fit in width.
1274 """Print a string snipping the midsection to fit in width.
1237
1275
1238 print_full: mode control:
1276 print_full: mode control:
1239 - 0: only snip long strings
1277 - 0: only snip long strings
1240 - 1: send to page() directly.
1278 - 1: send to page() directly.
1241 - 2: snip long strings and ask for full length viewing with page()
1279 - 2: snip long strings and ask for full length viewing with page()
1242 Return 1 if snipping was necessary, 0 otherwise."""
1280 Return 1 if snipping was necessary, 0 otherwise."""
1243
1281
1244 if print_full == 1:
1282 if print_full == 1:
1245 page(header+str)
1283 page(header+str)
1246 return 0
1284 return 0
1247
1285
1248 print header,
1286 print header,
1249 if len(str) < width:
1287 if len(str) < width:
1250 print str
1288 print str
1251 snip = 0
1289 snip = 0
1252 else:
1290 else:
1253 whalf = int((width -5)/2)
1291 whalf = int((width -5)/2)
1254 print str[:whalf] + ' <...> ' + str[-whalf:]
1292 print str[:whalf] + ' <...> ' + str[-whalf:]
1255 snip = 1
1293 snip = 1
1256 if snip and print_full == 2:
1294 if snip and print_full == 2:
1257 if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y':
1295 if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y':
1258 page(str)
1296 page(str)
1259 return snip
1297 return snip
1260
1298
1261 #****************************************************************************
1299 #****************************************************************************
1262 # lists, dicts and structures
1300 # lists, dicts and structures
1263
1301
1264 def belong(candidates,checklist):
1302 def belong(candidates,checklist):
1265 """Check whether a list of items appear in a given list of options.
1303 """Check whether a list of items appear in a given list of options.
1266
1304
1267 Returns a list of 1 and 0, one for each candidate given."""
1305 Returns a list of 1 and 0, one for each candidate given."""
1268
1306
1269 return [x in checklist for x in candidates]
1307 return [x in checklist for x in candidates]
1270
1308
1271 #----------------------------------------------------------------------------
1309 #----------------------------------------------------------------------------
1272 def uniq_stable(elems):
1310 def uniq_stable(elems):
1273 """uniq_stable(elems) -> list
1311 """uniq_stable(elems) -> list
1274
1312
1275 Return from an iterable, a list of all the unique elements in the input,
1313 Return from an iterable, a list of all the unique elements in the input,
1276 but maintaining the order in which they first appear.
1314 but maintaining the order in which they first appear.
1277
1315
1278 A naive solution to this problem which just makes a dictionary with the
1316 A naive solution to this problem which just makes a dictionary with the
1279 elements as keys fails to respect the stability condition, since
1317 elements as keys fails to respect the stability condition, since
1280 dictionaries are unsorted by nature.
1318 dictionaries are unsorted by nature.
1281
1319
1282 Note: All elements in the input must be valid dictionary keys for this
1320 Note: All elements in the input must be valid dictionary keys for this
1283 routine to work, as it internally uses a dictionary for efficiency
1321 routine to work, as it internally uses a dictionary for efficiency
1284 reasons."""
1322 reasons."""
1285
1323
1286 unique = []
1324 unique = []
1287 unique_dict = {}
1325 unique_dict = {}
1288 for nn in elems:
1326 for nn in elems:
1289 if nn not in unique_dict:
1327 if nn not in unique_dict:
1290 unique.append(nn)
1328 unique.append(nn)
1291 unique_dict[nn] = None
1329 unique_dict[nn] = None
1292 return unique
1330 return unique
1293
1331
1294 #----------------------------------------------------------------------------
1332 #----------------------------------------------------------------------------
1295 class NLprinter:
1333 class NLprinter:
1296 """Print an arbitrarily nested list, indicating index numbers.
1334 """Print an arbitrarily nested list, indicating index numbers.
1297
1335
1298 An instance of this class called nlprint is available and callable as a
1336 An instance of this class called nlprint is available and callable as a
1299 function.
1337 function.
1300
1338
1301 nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent'
1339 nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent'
1302 and using 'sep' to separate the index from the value. """
1340 and using 'sep' to separate the index from the value. """
1303
1341
1304 def __init__(self):
1342 def __init__(self):
1305 self.depth = 0
1343 self.depth = 0
1306
1344
1307 def __call__(self,lst,pos='',**kw):
1345 def __call__(self,lst,pos='',**kw):
1308 """Prints the nested list numbering levels."""
1346 """Prints the nested list numbering levels."""
1309 kw.setdefault('indent',' ')
1347 kw.setdefault('indent',' ')
1310 kw.setdefault('sep',': ')
1348 kw.setdefault('sep',': ')
1311 kw.setdefault('start',0)
1349 kw.setdefault('start',0)
1312 kw.setdefault('stop',len(lst))
1350 kw.setdefault('stop',len(lst))
1313 # we need to remove start and stop from kw so they don't propagate
1351 # we need to remove start and stop from kw so they don't propagate
1314 # into a recursive call for a nested list.
1352 # into a recursive call for a nested list.
1315 start = kw['start']; del kw['start']
1353 start = kw['start']; del kw['start']
1316 stop = kw['stop']; del kw['stop']
1354 stop = kw['stop']; del kw['stop']
1317 if self.depth == 0 and 'header' in kw.keys():
1355 if self.depth == 0 and 'header' in kw.keys():
1318 print kw['header']
1356 print kw['header']
1319
1357
1320 for idx in range(start,stop):
1358 for idx in range(start,stop):
1321 elem = lst[idx]
1359 elem = lst[idx]
1322 if type(elem)==type([]):
1360 if type(elem)==type([]):
1323 self.depth += 1
1361 self.depth += 1
1324 self.__call__(elem,itpl('$pos$idx,'),**kw)
1362 self.__call__(elem,itpl('$pos$idx,'),**kw)
1325 self.depth -= 1
1363 self.depth -= 1
1326 else:
1364 else:
1327 printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem')
1365 printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem')
1328
1366
1329 nlprint = NLprinter()
1367 nlprint = NLprinter()
1330 #----------------------------------------------------------------------------
1368 #----------------------------------------------------------------------------
1331 def all_belong(candidates,checklist):
1369 def all_belong(candidates,checklist):
1332 """Check whether a list of items ALL appear in a given list of options.
1370 """Check whether a list of items ALL appear in a given list of options.
1333
1371
1334 Returns a single 1 or 0 value."""
1372 Returns a single 1 or 0 value."""
1335
1373
1336 return 1-(0 in [x in checklist for x in candidates])
1374 return 1-(0 in [x in checklist for x in candidates])
1337
1375
1338 #----------------------------------------------------------------------------
1376 #----------------------------------------------------------------------------
1339 def sort_compare(lst1,lst2,inplace = 1):
1377 def sort_compare(lst1,lst2,inplace = 1):
1340 """Sort and compare two lists.
1378 """Sort and compare two lists.
1341
1379
1342 By default it does it in place, thus modifying the lists. Use inplace = 0
1380 By default it does it in place, thus modifying the lists. Use inplace = 0
1343 to avoid that (at the cost of temporary copy creation)."""
1381 to avoid that (at the cost of temporary copy creation)."""
1344 if not inplace:
1382 if not inplace:
1345 lst1 = lst1[:]
1383 lst1 = lst1[:]
1346 lst2 = lst2[:]
1384 lst2 = lst2[:]
1347 lst1.sort(); lst2.sort()
1385 lst1.sort(); lst2.sort()
1348 return lst1 == lst2
1386 return lst1 == lst2
1349
1387
1350 #----------------------------------------------------------------------------
1388 #----------------------------------------------------------------------------
1351 def mkdict(**kwargs):
1389 def mkdict(**kwargs):
1352 """Return a dict from a keyword list.
1390 """Return a dict from a keyword list.
1353
1391
1354 It's just syntactic sugar for making ditcionary creation more convenient:
1392 It's just syntactic sugar for making ditcionary creation more convenient:
1355 # the standard way
1393 # the standard way
1356 >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 }
1394 >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 }
1357 # a cleaner way
1395 # a cleaner way
1358 >>>data = dict(red=1, green=2, blue=3)
1396 >>>data = dict(red=1, green=2, blue=3)
1359
1397
1360 If you need more than this, look at the Struct() class."""
1398 If you need more than this, look at the Struct() class."""
1361
1399
1362 return kwargs
1400 return kwargs
1363
1401
1364 #----------------------------------------------------------------------------
1402 #----------------------------------------------------------------------------
1365 def list2dict(lst):
1403 def list2dict(lst):
1366 """Takes a list of (key,value) pairs and turns it into a dict."""
1404 """Takes a list of (key,value) pairs and turns it into a dict."""
1367
1405
1368 dic = {}
1406 dic = {}
1369 for k,v in lst: dic[k] = v
1407 for k,v in lst: dic[k] = v
1370 return dic
1408 return dic
1371
1409
1372 #----------------------------------------------------------------------------
1410 #----------------------------------------------------------------------------
1373 def list2dict2(lst,default=''):
1411 def list2dict2(lst,default=''):
1374 """Takes a list and turns it into a dict.
1412 """Takes a list and turns it into a dict.
1375 Much slower than list2dict, but more versatile. This version can take
1413 Much slower than list2dict, but more versatile. This version can take
1376 lists with sublists of arbitrary length (including sclars)."""
1414 lists with sublists of arbitrary length (including sclars)."""
1377
1415
1378 dic = {}
1416 dic = {}
1379 for elem in lst:
1417 for elem in lst:
1380 if type(elem) in (types.ListType,types.TupleType):
1418 if type(elem) in (types.ListType,types.TupleType):
1381 size = len(elem)
1419 size = len(elem)
1382 if size == 0:
1420 if size == 0:
1383 pass
1421 pass
1384 elif size == 1:
1422 elif size == 1:
1385 dic[elem] = default
1423 dic[elem] = default
1386 else:
1424 else:
1387 k,v = elem[0], elem[1:]
1425 k,v = elem[0], elem[1:]
1388 if len(v) == 1: v = v[0]
1426 if len(v) == 1: v = v[0]
1389 dic[k] = v
1427 dic[k] = v
1390 else:
1428 else:
1391 dic[elem] = default
1429 dic[elem] = default
1392 return dic
1430 return dic
1393
1431
1394 #----------------------------------------------------------------------------
1432 #----------------------------------------------------------------------------
1395 def flatten(seq):
1433 def flatten(seq):
1396 """Flatten a list of lists (NOT recursive, only works for 2d lists)."""
1434 """Flatten a list of lists (NOT recursive, only works for 2d lists)."""
1397
1435
1398 # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in).
1436 # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in).
1399
1437
1400 # if the x=0 isn't made, a *global* variable x is left over after calling
1438 # if the x=0 isn't made, a *global* variable x is left over after calling
1401 # this function, with the value of the last element in the return
1439 # this function, with the value of the last element in the return
1402 # list. This does seem like a bug big time to me.
1440 # list. This does seem like a bug big time to me.
1403
1441
1404 # the problem is fixed with the x=0, which seems to force the creation of
1442 # the problem is fixed with the x=0, which seems to force the creation of
1405 # a local name
1443 # a local name
1406
1444
1407 x = 0
1445 x = 0
1408 return [x for subseq in seq for x in subseq]
1446 return [x for subseq in seq for x in subseq]
1409
1447
1410 #----------------------------------------------------------------------------
1448 #----------------------------------------------------------------------------
1411 def get_slice(seq,start=0,stop=None,step=1):
1449 def get_slice(seq,start=0,stop=None,step=1):
1412 """Get a slice of a sequence with variable step. Specify start,stop,step."""
1450 """Get a slice of a sequence with variable step. Specify start,stop,step."""
1413 if stop == None:
1451 if stop == None:
1414 stop = len(seq)
1452 stop = len(seq)
1415 item = lambda i: seq[i]
1453 item = lambda i: seq[i]
1416 return map(item,xrange(start,stop,step))
1454 return map(item,xrange(start,stop,step))
1417
1455
1418 #----------------------------------------------------------------------------
1456 #----------------------------------------------------------------------------
1419 def chop(seq,size):
1457 def chop(seq,size):
1420 """Chop a sequence into chunks of the given size."""
1458 """Chop a sequence into chunks of the given size."""
1421 chunk = lambda i: seq[i:i+size]
1459 chunk = lambda i: seq[i:i+size]
1422 return map(chunk,xrange(0,len(seq),size))
1460 return map(chunk,xrange(0,len(seq),size))
1423
1461
1424 #----------------------------------------------------------------------------
1462 #----------------------------------------------------------------------------
1425 def with(object, **args):
1463 def with(object, **args):
1426 """Set multiple attributes for an object, similar to Pascal's with.
1464 """Set multiple attributes for an object, similar to Pascal's with.
1427
1465
1428 Example:
1466 Example:
1429 with(jim,
1467 with(jim,
1430 born = 1960,
1468 born = 1960,
1431 haircolour = 'Brown',
1469 haircolour = 'Brown',
1432 eyecolour = 'Green')
1470 eyecolour = 'Green')
1433
1471
1434 Credit: Greg Ewing, in
1472 Credit: Greg Ewing, in
1435 http://mail.python.org/pipermail/python-list/2001-May/040703.html"""
1473 http://mail.python.org/pipermail/python-list/2001-May/040703.html"""
1436
1474
1437 object.__dict__.update(args)
1475 object.__dict__.update(args)
1438
1476
1439 #----------------------------------------------------------------------------
1477 #----------------------------------------------------------------------------
1440 def setattr_list(obj,alist,nspace = None):
1478 def setattr_list(obj,alist,nspace = None):
1441 """Set a list of attributes for an object taken from a namespace.
1479 """Set a list of attributes for an object taken from a namespace.
1442
1480
1443 setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in
1481 setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in
1444 alist with their values taken from nspace, which must be a dict (something
1482 alist with their values taken from nspace, which must be a dict (something
1445 like locals() will often do) If nspace isn't given, locals() of the
1483 like locals() will often do) If nspace isn't given, locals() of the
1446 *caller* is used, so in most cases you can omit it.
1484 *caller* is used, so in most cases you can omit it.
1447
1485
1448 Note that alist can be given as a string, which will be automatically
1486 Note that alist can be given as a string, which will be automatically
1449 split into a list on whitespace. If given as a list, it must be a list of
1487 split into a list on whitespace. If given as a list, it must be a list of
1450 *strings* (the variable names themselves), not of variables."""
1488 *strings* (the variable names themselves), not of variables."""
1451
1489
1452 # this grabs the local variables from the *previous* call frame -- that is
1490 # this grabs the local variables from the *previous* call frame -- that is
1453 # the locals from the function that called setattr_list().
1491 # the locals from the function that called setattr_list().
1454 # - snipped from weave.inline()
1492 # - snipped from weave.inline()
1455 if nspace is None:
1493 if nspace is None:
1456 call_frame = sys._getframe().f_back
1494 call_frame = sys._getframe().f_back
1457 nspace = call_frame.f_locals
1495 nspace = call_frame.f_locals
1458
1496
1459 if type(alist) in StringTypes:
1497 if type(alist) in StringTypes:
1460 alist = alist.split()
1498 alist = alist.split()
1461 for attr in alist:
1499 for attr in alist:
1462 val = eval(attr,nspace)
1500 val = eval(attr,nspace)
1463 setattr(obj,attr,val)
1501 setattr(obj,attr,val)
1464
1502
1465 #----------------------------------------------------------------------------
1503 #----------------------------------------------------------------------------
1466 def getattr_list(obj,alist,*args):
1504 def getattr_list(obj,alist,*args):
1467 """getattr_list(obj,alist[, default]) -> attribute list.
1505 """getattr_list(obj,alist[, default]) -> attribute list.
1468
1506
1469 Get a list of named attributes for an object. When a default argument is
1507 Get a list of named attributes for an object. When a default argument is
1470 given, it is returned when the attribute doesn't exist; without it, an
1508 given, it is returned when the attribute doesn't exist; without it, an
1471 exception is raised in that case.
1509 exception is raised in that case.
1472
1510
1473 Note that alist can be given as a string, which will be automatically
1511 Note that alist can be given as a string, which will be automatically
1474 split into a list on whitespace. If given as a list, it must be a list of
1512 split into a list on whitespace. If given as a list, it must be a list of
1475 *strings* (the variable names themselves), not of variables."""
1513 *strings* (the variable names themselves), not of variables."""
1476
1514
1477 if type(alist) in StringTypes:
1515 if type(alist) in StringTypes:
1478 alist = alist.split()
1516 alist = alist.split()
1479 if args:
1517 if args:
1480 if len(args)==1:
1518 if len(args)==1:
1481 default = args[0]
1519 default = args[0]
1482 return map(lambda attr: getattr(obj,attr,default),alist)
1520 return map(lambda attr: getattr(obj,attr,default),alist)
1483 else:
1521 else:
1484 raise ValueError,'getattr_list() takes only one optional argument'
1522 raise ValueError,'getattr_list() takes only one optional argument'
1485 else:
1523 else:
1486 return map(lambda attr: getattr(obj,attr),alist)
1524 return map(lambda attr: getattr(obj,attr),alist)
1487
1525
1488 #----------------------------------------------------------------------------
1526 #----------------------------------------------------------------------------
1489 def map_method(method,object_list,*argseq,**kw):
1527 def map_method(method,object_list,*argseq,**kw):
1490 """map_method(method,object_list,*args,**kw) -> list
1528 """map_method(method,object_list,*args,**kw) -> list
1491
1529
1492 Return a list of the results of applying the methods to the items of the
1530 Return a list of the results of applying the methods to the items of the
1493 argument sequence(s). If more than one sequence is given, the method is
1531 argument sequence(s). If more than one sequence is given, the method is
1494 called with an argument list consisting of the corresponding item of each
1532 called with an argument list consisting of the corresponding item of each
1495 sequence. All sequences must be of the same length.
1533 sequence. All sequences must be of the same length.
1496
1534
1497 Keyword arguments are passed verbatim to all objects called.
1535 Keyword arguments are passed verbatim to all objects called.
1498
1536
1499 This is Python code, so it's not nearly as fast as the builtin map()."""
1537 This is Python code, so it's not nearly as fast as the builtin map()."""
1500
1538
1501 out_list = []
1539 out_list = []
1502 idx = 0
1540 idx = 0
1503 for object in object_list:
1541 for object in object_list:
1504 try:
1542 try:
1505 handler = getattr(object, method)
1543 handler = getattr(object, method)
1506 except AttributeError:
1544 except AttributeError:
1507 out_list.append(None)
1545 out_list.append(None)
1508 else:
1546 else:
1509 if argseq:
1547 if argseq:
1510 args = map(lambda lst:lst[idx],argseq)
1548 args = map(lambda lst:lst[idx],argseq)
1511 #print 'ob',object,'hand',handler,'ar',args # dbg
1549 #print 'ob',object,'hand',handler,'ar',args # dbg
1512 out_list.append(handler(args,**kw))
1550 out_list.append(handler(args,**kw))
1513 else:
1551 else:
1514 out_list.append(handler(**kw))
1552 out_list.append(handler(**kw))
1515 idx += 1
1553 idx += 1
1516 return out_list
1554 return out_list
1517
1555
1518 #----------------------------------------------------------------------------
1556 #----------------------------------------------------------------------------
1519 # Proposed popitem() extension, written as a method
1557 # Proposed popitem() extension, written as a method
1520
1558
1521 class NotGiven: pass
1559 class NotGiven: pass
1522
1560
1523 def popkey(dct,key,default=NotGiven):
1561 def popkey(dct,key,default=NotGiven):
1524 """Return dct[key] and delete dct[key].
1562 """Return dct[key] and delete dct[key].
1525
1563
1526 If default is given, return it if dct[key] doesn't exist, otherwise raise
1564 If default is given, return it if dct[key] doesn't exist, otherwise raise
1527 KeyError. """
1565 KeyError. """
1528
1566
1529 try:
1567 try:
1530 val = dct[key]
1568 val = dct[key]
1531 except KeyError:
1569 except KeyError:
1532 if default is NotGiven:
1570 if default is NotGiven:
1533 raise
1571 raise
1534 else:
1572 else:
1535 return default
1573 return default
1536 else:
1574 else:
1537 del dct[key]
1575 del dct[key]
1538 return val
1576 return val
1539 #*************************** end of file <genutils.py> **********************
1577 #*************************** end of file <genutils.py> **********************
1540
1578
@@ -1,4384 +1,4388 b''
1 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
1 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
2
2
3 * IPython/genutils.py (shlex_split): moved from Magic to here,
4 where all 2.2 compatibility stuff lives. I needed it for demo.py.
5
3 * IPython/demo.py (Demo.__init__): added support for silent
6 * IPython/demo.py (Demo.__init__): added support for silent
4 blocks, improved marks as regexps, docstrings written.
7 blocks, improved marks as regexps, docstrings written.
8 (Demo.__init__): better docstring, added support for sys.argv.
5
9
6 * IPython/genutils.py (marquee): little utility used by the demo
10 * IPython/genutils.py (marquee): little utility used by the demo
7 code, handy in general.
11 code, handy in general.
8
12
9 * IPython/demo.py (Demo.__init__): new class for interactive
13 * IPython/demo.py (Demo.__init__): new class for interactive
10 demos. Not documented yet, I just wrote it in a hurry for
14 demos. Not documented yet, I just wrote it in a hurry for
11 scipy'05. Will docstring later.
15 scipy'05. Will docstring later.
12
16
13 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
17 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
14
18
15 * IPython/Shell.py (sigint_handler): Drastic simplification which
19 * IPython/Shell.py (sigint_handler): Drastic simplification which
16 also seems to make Ctrl-C work correctly across threads! This is
20 also seems to make Ctrl-C work correctly across threads! This is
17 so simple, that I can't beleive I'd missed it before. Needs more
21 so simple, that I can't beleive I'd missed it before. Needs more
18 testing, though.
22 testing, though.
19 (KBINT): Never mind, revert changes. I'm sure I'd tried something
23 (KBINT): Never mind, revert changes. I'm sure I'd tried something
20 like this before...
24 like this before...
21
25
22 * IPython/genutils.py (get_home_dir): add protection against
26 * IPython/genutils.py (get_home_dir): add protection against
23 non-dirs in win32 registry.
27 non-dirs in win32 registry.
24
28
25 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
29 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
26 bug where dict was mutated while iterating (pysh crash).
30 bug where dict was mutated while iterating (pysh crash).
27
31
28 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
32 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
29
33
30 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
34 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
31 spurious newlines added by this routine. After a report by
35 spurious newlines added by this routine. After a report by
32 F. Mantegazza.
36 F. Mantegazza.
33
37
34 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
38 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
35
39
36 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
40 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
37 calls. These were a leftover from the GTK 1.x days, and can cause
41 calls. These were a leftover from the GTK 1.x days, and can cause
38 problems in certain cases (after a report by John Hunter).
42 problems in certain cases (after a report by John Hunter).
39
43
40 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
44 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
41 os.getcwd() fails at init time. Thanks to patch from David Remahl
45 os.getcwd() fails at init time. Thanks to patch from David Remahl
42 <chmod007 AT mac.com>.
46 <chmod007 AT mac.com>.
43 (InteractiveShell.__init__): prevent certain special magics from
47 (InteractiveShell.__init__): prevent certain special magics from
44 being shadowed by aliases. Closes
48 being shadowed by aliases. Closes
45 http://www.scipy.net/roundup/ipython/issue41.
49 http://www.scipy.net/roundup/ipython/issue41.
46
50
47 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
51 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
48
52
49 * IPython/iplib.py (InteractiveShell.complete): Added new
53 * IPython/iplib.py (InteractiveShell.complete): Added new
50 top-level completion method to expose the completion mechanism
54 top-level completion method to expose the completion mechanism
51 beyond readline-based environments.
55 beyond readline-based environments.
52
56
53 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
57 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
54
58
55 * tools/ipsvnc (svnversion): fix svnversion capture.
59 * tools/ipsvnc (svnversion): fix svnversion capture.
56
60
57 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
61 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
58 attribute to self, which was missing. Before, it was set by a
62 attribute to self, which was missing. Before, it was set by a
59 routine which in certain cases wasn't being called, so the
63 routine which in certain cases wasn't being called, so the
60 instance could end up missing the attribute. This caused a crash.
64 instance could end up missing the attribute. This caused a crash.
61 Closes http://www.scipy.net/roundup/ipython/issue40.
65 Closes http://www.scipy.net/roundup/ipython/issue40.
62
66
63 2005-08-16 Fernando Perez <fperez@colorado.edu>
67 2005-08-16 Fernando Perez <fperez@colorado.edu>
64
68
65 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
69 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
66 contains non-string attribute. Closes
70 contains non-string attribute. Closes
67 http://www.scipy.net/roundup/ipython/issue38.
71 http://www.scipy.net/roundup/ipython/issue38.
68
72
69 2005-08-14 Fernando Perez <fperez@colorado.edu>
73 2005-08-14 Fernando Perez <fperez@colorado.edu>
70
74
71 * tools/ipsvnc: Minor improvements, to add changeset info.
75 * tools/ipsvnc: Minor improvements, to add changeset info.
72
76
73 2005-08-12 Fernando Perez <fperez@colorado.edu>
77 2005-08-12 Fernando Perez <fperez@colorado.edu>
74
78
75 * IPython/iplib.py (runsource): remove self.code_to_run_src
79 * IPython/iplib.py (runsource): remove self.code_to_run_src
76 attribute. I realized this is nothing more than
80 attribute. I realized this is nothing more than
77 '\n'.join(self.buffer), and having the same data in two different
81 '\n'.join(self.buffer), and having the same data in two different
78 places is just asking for synchronization bugs. This may impact
82 places is just asking for synchronization bugs. This may impact
79 people who have custom exception handlers, so I need to warn
83 people who have custom exception handlers, so I need to warn
80 ipython-dev about it (F. Mantegazza may use them).
84 ipython-dev about it (F. Mantegazza may use them).
81
85
82 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
86 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
83
87
84 * IPython/genutils.py: fix 2.2 compatibility (generators)
88 * IPython/genutils.py: fix 2.2 compatibility (generators)
85
89
86 2005-07-18 Fernando Perez <fperez@colorado.edu>
90 2005-07-18 Fernando Perez <fperez@colorado.edu>
87
91
88 * IPython/genutils.py (get_home_dir): fix to help users with
92 * IPython/genutils.py (get_home_dir): fix to help users with
89 invalid $HOME under win32.
93 invalid $HOME under win32.
90
94
91 2005-07-17 Fernando Perez <fperez@colorado.edu>
95 2005-07-17 Fernando Perez <fperez@colorado.edu>
92
96
93 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
97 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
94 some old hacks and clean up a bit other routines; code should be
98 some old hacks and clean up a bit other routines; code should be
95 simpler and a bit faster.
99 simpler and a bit faster.
96
100
97 * IPython/iplib.py (interact): removed some last-resort attempts
101 * IPython/iplib.py (interact): removed some last-resort attempts
98 to survive broken stdout/stderr. That code was only making it
102 to survive broken stdout/stderr. That code was only making it
99 harder to abstract out the i/o (necessary for gui integration),
103 harder to abstract out the i/o (necessary for gui integration),
100 and the crashes it could prevent were extremely rare in practice
104 and the crashes it could prevent were extremely rare in practice
101 (besides being fully user-induced in a pretty violent manner).
105 (besides being fully user-induced in a pretty violent manner).
102
106
103 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
107 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
104 Nothing major yet, but the code is simpler to read; this should
108 Nothing major yet, but the code is simpler to read; this should
105 make it easier to do more serious modifications in the future.
109 make it easier to do more serious modifications in the future.
106
110
107 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
111 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
108 which broke in .15 (thanks to a report by Ville).
112 which broke in .15 (thanks to a report by Ville).
109
113
110 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
114 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
111 be quite correct, I know next to nothing about unicode). This
115 be quite correct, I know next to nothing about unicode). This
112 will allow unicode strings to be used in prompts, amongst other
116 will allow unicode strings to be used in prompts, amongst other
113 cases. It also will prevent ipython from crashing when unicode
117 cases. It also will prevent ipython from crashing when unicode
114 shows up unexpectedly in many places. If ascii encoding fails, we
118 shows up unexpectedly in many places. If ascii encoding fails, we
115 assume utf_8. Currently the encoding is not a user-visible
119 assume utf_8. Currently the encoding is not a user-visible
116 setting, though it could be made so if there is demand for it.
120 setting, though it could be made so if there is demand for it.
117
121
118 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
122 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
119
123
120 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
124 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
121
125
122 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
126 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
123
127
124 * IPython/genutils.py: Add 2.2 compatibility here, so all other
128 * IPython/genutils.py: Add 2.2 compatibility here, so all other
125 code can work transparently for 2.2/2.3.
129 code can work transparently for 2.2/2.3.
126
130
127 2005-07-16 Fernando Perez <fperez@colorado.edu>
131 2005-07-16 Fernando Perez <fperez@colorado.edu>
128
132
129 * IPython/ultraTB.py (ExceptionColors): Make a global variable
133 * IPython/ultraTB.py (ExceptionColors): Make a global variable
130 out of the color scheme table used for coloring exception
134 out of the color scheme table used for coloring exception
131 tracebacks. This allows user code to add new schemes at runtime.
135 tracebacks. This allows user code to add new schemes at runtime.
132 This is a minimally modified version of the patch at
136 This is a minimally modified version of the patch at
133 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
137 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
134 for the contribution.
138 for the contribution.
135
139
136 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
140 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
137 slightly modified version of the patch in
141 slightly modified version of the patch in
138 http://www.scipy.net/roundup/ipython/issue34, which also allows me
142 http://www.scipy.net/roundup/ipython/issue34, which also allows me
139 to remove the previous try/except solution (which was costlier).
143 to remove the previous try/except solution (which was costlier).
140 Thanks to Gaetan Lehmann <gaetan.lehmann AT jouy.inra.fr> for the fix.
144 Thanks to Gaetan Lehmann <gaetan.lehmann AT jouy.inra.fr> for the fix.
141
145
142 2005-06-08 Fernando Perez <fperez@colorado.edu>
146 2005-06-08 Fernando Perez <fperez@colorado.edu>
143
147
144 * IPython/iplib.py (write/write_err): Add methods to abstract all
148 * IPython/iplib.py (write/write_err): Add methods to abstract all
145 I/O a bit more.
149 I/O a bit more.
146
150
147 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
151 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
148 warning, reported by Aric Hagberg, fix by JD Hunter.
152 warning, reported by Aric Hagberg, fix by JD Hunter.
149
153
150 2005-06-02 *** Released version 0.6.15
154 2005-06-02 *** Released version 0.6.15
151
155
152 2005-06-01 Fernando Perez <fperez@colorado.edu>
156 2005-06-01 Fernando Perez <fperez@colorado.edu>
153
157
154 * IPython/iplib.py (MagicCompleter.file_matches): Fix
158 * IPython/iplib.py (MagicCompleter.file_matches): Fix
155 tab-completion of filenames within open-quoted strings. Note that
159 tab-completion of filenames within open-quoted strings. Note that
156 this requires that in ~/.ipython/ipythonrc, users change the
160 this requires that in ~/.ipython/ipythonrc, users change the
157 readline delimiters configuration to read:
161 readline delimiters configuration to read:
158
162
159 readline_remove_delims -/~
163 readline_remove_delims -/~
160
164
161
165
162 2005-05-31 *** Released version 0.6.14
166 2005-05-31 *** Released version 0.6.14
163
167
164 2005-05-29 Fernando Perez <fperez@colorado.edu>
168 2005-05-29 Fernando Perez <fperez@colorado.edu>
165
169
166 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
170 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
167 with files not on the filesystem. Reported by Eliyahu Sandler
171 with files not on the filesystem. Reported by Eliyahu Sandler
168 <eli@gondolin.net>
172 <eli@gondolin.net>
169
173
170 2005-05-22 Fernando Perez <fperez@colorado.edu>
174 2005-05-22 Fernando Perez <fperez@colorado.edu>
171
175
172 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
176 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
173 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
177 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
174
178
175 2005-05-19 Fernando Perez <fperez@colorado.edu>
179 2005-05-19 Fernando Perez <fperez@colorado.edu>
176
180
177 * IPython/iplib.py (safe_execfile): close a file which could be
181 * IPython/iplib.py (safe_execfile): close a file which could be
178 left open (causing problems in win32, which locks open files).
182 left open (causing problems in win32, which locks open files).
179 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
183 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
180
184
181 2005-05-18 Fernando Perez <fperez@colorado.edu>
185 2005-05-18 Fernando Perez <fperez@colorado.edu>
182
186
183 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
187 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
184 keyword arguments correctly to safe_execfile().
188 keyword arguments correctly to safe_execfile().
185
189
186 2005-05-13 Fernando Perez <fperez@colorado.edu>
190 2005-05-13 Fernando Perez <fperez@colorado.edu>
187
191
188 * ipython.1: Added info about Qt to manpage, and threads warning
192 * ipython.1: Added info about Qt to manpage, and threads warning
189 to usage page (invoked with --help).
193 to usage page (invoked with --help).
190
194
191 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
195 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
192 new matcher (it goes at the end of the priority list) to do
196 new matcher (it goes at the end of the priority list) to do
193 tab-completion on named function arguments. Submitted by George
197 tab-completion on named function arguments. Submitted by George
194 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
198 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
195 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
199 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
196 for more details.
200 for more details.
197
201
198 * IPython/Magic.py (magic_run): Added new -e flag to ignore
202 * IPython/Magic.py (magic_run): Added new -e flag to ignore
199 SystemExit exceptions in the script being run. Thanks to a report
203 SystemExit exceptions in the script being run. Thanks to a report
200 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
204 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
201 producing very annoying behavior when running unit tests.
205 producing very annoying behavior when running unit tests.
202
206
203 2005-05-12 Fernando Perez <fperez@colorado.edu>
207 2005-05-12 Fernando Perez <fperez@colorado.edu>
204
208
205 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
209 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
206 which I'd broken (again) due to a changed regexp. In the process,
210 which I'd broken (again) due to a changed regexp. In the process,
207 added ';' as an escape to auto-quote the whole line without
211 added ';' as an escape to auto-quote the whole line without
208 splitting its arguments. Thanks to a report by Jerry McRae
212 splitting its arguments. Thanks to a report by Jerry McRae
209 <qrs0xyc02-AT-sneakemail.com>.
213 <qrs0xyc02-AT-sneakemail.com>.
210
214
211 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
215 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
212 possible crashes caused by a TokenError. Reported by Ed Schofield
216 possible crashes caused by a TokenError. Reported by Ed Schofield
213 <schofield-AT-ftw.at>.
217 <schofield-AT-ftw.at>.
214
218
215 2005-05-06 Fernando Perez <fperez@colorado.edu>
219 2005-05-06 Fernando Perez <fperez@colorado.edu>
216
220
217 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
221 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
218
222
219 2005-04-29 Fernando Perez <fperez@colorado.edu>
223 2005-04-29 Fernando Perez <fperez@colorado.edu>
220
224
221 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
225 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
222 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
226 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
223 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
227 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
224 which provides support for Qt interactive usage (similar to the
228 which provides support for Qt interactive usage (similar to the
225 existing one for WX and GTK). This had been often requested.
229 existing one for WX and GTK). This had been often requested.
226
230
227 2005-04-14 *** Released version 0.6.13
231 2005-04-14 *** Released version 0.6.13
228
232
229 2005-04-08 Fernando Perez <fperez@colorado.edu>
233 2005-04-08 Fernando Perez <fperez@colorado.edu>
230
234
231 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
235 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
232 from _ofind, which gets called on almost every input line. Now,
236 from _ofind, which gets called on almost every input line. Now,
233 we only try to get docstrings if they are actually going to be
237 we only try to get docstrings if they are actually going to be
234 used (the overhead of fetching unnecessary docstrings can be
238 used (the overhead of fetching unnecessary docstrings can be
235 noticeable for certain objects, such as Pyro proxies).
239 noticeable for certain objects, such as Pyro proxies).
236
240
237 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
241 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
238 for completers. For some reason I had been passing them the state
242 for completers. For some reason I had been passing them the state
239 variable, which completers never actually need, and was in
243 variable, which completers never actually need, and was in
240 conflict with the rlcompleter API. Custom completers ONLY need to
244 conflict with the rlcompleter API. Custom completers ONLY need to
241 take the text parameter.
245 take the text parameter.
242
246
243 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
247 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
244 work correctly in pysh. I've also moved all the logic which used
248 work correctly in pysh. I've also moved all the logic which used
245 to be in pysh.py here, which will prevent problems with future
249 to be in pysh.py here, which will prevent problems with future
246 upgrades. However, this time I must warn users to update their
250 upgrades. However, this time I must warn users to update their
247 pysh profile to include the line
251 pysh profile to include the line
248
252
249 import_all IPython.Extensions.InterpreterExec
253 import_all IPython.Extensions.InterpreterExec
250
254
251 because otherwise things won't work for them. They MUST also
255 because otherwise things won't work for them. They MUST also
252 delete pysh.py and the line
256 delete pysh.py and the line
253
257
254 execfile pysh.py
258 execfile pysh.py
255
259
256 from their ipythonrc-pysh.
260 from their ipythonrc-pysh.
257
261
258 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
262 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
259 robust in the face of objects whose dir() returns non-strings
263 robust in the face of objects whose dir() returns non-strings
260 (which it shouldn't, but some broken libs like ITK do). Thanks to
264 (which it shouldn't, but some broken libs like ITK do). Thanks to
261 a patch by John Hunter (implemented differently, though). Also
265 a patch by John Hunter (implemented differently, though). Also
262 minor improvements by using .extend instead of + on lists.
266 minor improvements by using .extend instead of + on lists.
263
267
264 * pysh.py:
268 * pysh.py:
265
269
266 2005-04-06 Fernando Perez <fperez@colorado.edu>
270 2005-04-06 Fernando Perez <fperez@colorado.edu>
267
271
268 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
272 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
269 by default, so that all users benefit from it. Those who don't
273 by default, so that all users benefit from it. Those who don't
270 want it can still turn it off.
274 want it can still turn it off.
271
275
272 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
276 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
273 config file, I'd forgotten about this, so users were getting it
277 config file, I'd forgotten about this, so users were getting it
274 off by default.
278 off by default.
275
279
276 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
280 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
277 consistency. Now magics can be called in multiline statements,
281 consistency. Now magics can be called in multiline statements,
278 and python variables can be expanded in magic calls via $var.
282 and python variables can be expanded in magic calls via $var.
279 This makes the magic system behave just like aliases or !system
283 This makes the magic system behave just like aliases or !system
280 calls.
284 calls.
281
285
282 2005-03-28 Fernando Perez <fperez@colorado.edu>
286 2005-03-28 Fernando Perez <fperez@colorado.edu>
283
287
284 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
288 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
285 expensive string additions for building command. Add support for
289 expensive string additions for building command. Add support for
286 trailing ';' when autocall is used.
290 trailing ';' when autocall is used.
287
291
288 2005-03-26 Fernando Perez <fperez@colorado.edu>
292 2005-03-26 Fernando Perez <fperez@colorado.edu>
289
293
290 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
294 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
291 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
295 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
292 ipython.el robust against prompts with any number of spaces
296 ipython.el robust against prompts with any number of spaces
293 (including 0) after the ':' character.
297 (including 0) after the ':' character.
294
298
295 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
299 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
296 continuation prompt, which misled users to think the line was
300 continuation prompt, which misled users to think the line was
297 already indented. Closes debian Bug#300847, reported to me by
301 already indented. Closes debian Bug#300847, reported to me by
298 Norbert Tretkowski <tretkowski-AT-inittab.de>.
302 Norbert Tretkowski <tretkowski-AT-inittab.de>.
299
303
300 2005-03-23 Fernando Perez <fperez@colorado.edu>
304 2005-03-23 Fernando Perez <fperez@colorado.edu>
301
305
302 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
306 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
303 properly aligned if they have embedded newlines.
307 properly aligned if they have embedded newlines.
304
308
305 * IPython/iplib.py (runlines): Add a public method to expose
309 * IPython/iplib.py (runlines): Add a public method to expose
306 IPython's code execution machinery, so that users can run strings
310 IPython's code execution machinery, so that users can run strings
307 as if they had been typed at the prompt interactively.
311 as if they had been typed at the prompt interactively.
308 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
312 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
309 methods which can call the system shell, but with python variable
313 methods which can call the system shell, but with python variable
310 expansion. The three such methods are: __IPYTHON__.system,
314 expansion. The three such methods are: __IPYTHON__.system,
311 .getoutput and .getoutputerror. These need to be documented in a
315 .getoutput and .getoutputerror. These need to be documented in a
312 'public API' section (to be written) of the manual.
316 'public API' section (to be written) of the manual.
313
317
314 2005-03-20 Fernando Perez <fperez@colorado.edu>
318 2005-03-20 Fernando Perez <fperez@colorado.edu>
315
319
316 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
320 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
317 for custom exception handling. This is quite powerful, and it
321 for custom exception handling. This is quite powerful, and it
318 allows for user-installable exception handlers which can trap
322 allows for user-installable exception handlers which can trap
319 custom exceptions at runtime and treat them separately from
323 custom exceptions at runtime and treat them separately from
320 IPython's default mechanisms. At the request of Frédéric
324 IPython's default mechanisms. At the request of Frédéric
321 Mantegazza <mantegazza-AT-ill.fr>.
325 Mantegazza <mantegazza-AT-ill.fr>.
322 (InteractiveShell.set_custom_completer): public API function to
326 (InteractiveShell.set_custom_completer): public API function to
323 add new completers at runtime.
327 add new completers at runtime.
324
328
325 2005-03-19 Fernando Perez <fperez@colorado.edu>
329 2005-03-19 Fernando Perez <fperez@colorado.edu>
326
330
327 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
331 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
328 allow objects which provide their docstrings via non-standard
332 allow objects which provide their docstrings via non-standard
329 mechanisms (like Pyro proxies) to still be inspected by ipython's
333 mechanisms (like Pyro proxies) to still be inspected by ipython's
330 ? system.
334 ? system.
331
335
332 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
336 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
333 automatic capture system. I tried quite hard to make it work
337 automatic capture system. I tried quite hard to make it work
334 reliably, and simply failed. I tried many combinations with the
338 reliably, and simply failed. I tried many combinations with the
335 subprocess module, but eventually nothing worked in all needed
339 subprocess module, but eventually nothing worked in all needed
336 cases (not blocking stdin for the child, duplicating stdout
340 cases (not blocking stdin for the child, duplicating stdout
337 without blocking, etc). The new %sc/%sx still do capture to these
341 without blocking, etc). The new %sc/%sx still do capture to these
338 magical list/string objects which make shell use much more
342 magical list/string objects which make shell use much more
339 conveninent, so not all is lost.
343 conveninent, so not all is lost.
340
344
341 XXX - FIX MANUAL for the change above!
345 XXX - FIX MANUAL for the change above!
342
346
343 (runsource): I copied code.py's runsource() into ipython to modify
347 (runsource): I copied code.py's runsource() into ipython to modify
344 it a bit. Now the code object and source to be executed are
348 it a bit. Now the code object and source to be executed are
345 stored in ipython. This makes this info accessible to third-party
349 stored in ipython. This makes this info accessible to third-party
346 tools, like custom exception handlers. After a request by Frédéric
350 tools, like custom exception handlers. After a request by Frédéric
347 Mantegazza <mantegazza-AT-ill.fr>.
351 Mantegazza <mantegazza-AT-ill.fr>.
348
352
349 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
353 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
350 history-search via readline (like C-p/C-n). I'd wanted this for a
354 history-search via readline (like C-p/C-n). I'd wanted this for a
351 long time, but only recently found out how to do it. For users
355 long time, but only recently found out how to do it. For users
352 who already have their ipythonrc files made and want this, just
356 who already have their ipythonrc files made and want this, just
353 add:
357 add:
354
358
355 readline_parse_and_bind "\e[A": history-search-backward
359 readline_parse_and_bind "\e[A": history-search-backward
356 readline_parse_and_bind "\e[B": history-search-forward
360 readline_parse_and_bind "\e[B": history-search-forward
357
361
358 2005-03-18 Fernando Perez <fperez@colorado.edu>
362 2005-03-18 Fernando Perez <fperez@colorado.edu>
359
363
360 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
364 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
361 LSString and SList classes which allow transparent conversions
365 LSString and SList classes which allow transparent conversions
362 between list mode and whitespace-separated string.
366 between list mode and whitespace-separated string.
363 (magic_r): Fix recursion problem in %r.
367 (magic_r): Fix recursion problem in %r.
364
368
365 * IPython/genutils.py (LSString): New class to be used for
369 * IPython/genutils.py (LSString): New class to be used for
366 automatic storage of the results of all alias/system calls in _o
370 automatic storage of the results of all alias/system calls in _o
367 and _e (stdout/err). These provide a .l/.list attribute which
371 and _e (stdout/err). These provide a .l/.list attribute which
368 does automatic splitting on newlines. This means that for most
372 does automatic splitting on newlines. This means that for most
369 uses, you'll never need to do capturing of output with %sc/%sx
373 uses, you'll never need to do capturing of output with %sc/%sx
370 anymore, since ipython keeps this always done for you. Note that
374 anymore, since ipython keeps this always done for you. Note that
371 only the LAST results are stored, the _o/e variables are
375 only the LAST results are stored, the _o/e variables are
372 overwritten on each call. If you need to save their contents
376 overwritten on each call. If you need to save their contents
373 further, simply bind them to any other name.
377 further, simply bind them to any other name.
374
378
375 2005-03-17 Fernando Perez <fperez@colorado.edu>
379 2005-03-17 Fernando Perez <fperez@colorado.edu>
376
380
377 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
381 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
378 prompt namespace handling.
382 prompt namespace handling.
379
383
380 2005-03-16 Fernando Perez <fperez@colorado.edu>
384 2005-03-16 Fernando Perez <fperez@colorado.edu>
381
385
382 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
386 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
383 classic prompts to be '>>> ' (final space was missing, and it
387 classic prompts to be '>>> ' (final space was missing, and it
384 trips the emacs python mode).
388 trips the emacs python mode).
385 (BasePrompt.__str__): Added safe support for dynamic prompt
389 (BasePrompt.__str__): Added safe support for dynamic prompt
386 strings. Now you can set your prompt string to be '$x', and the
390 strings. Now you can set your prompt string to be '$x', and the
387 value of x will be printed from your interactive namespace. The
391 value of x will be printed from your interactive namespace. The
388 interpolation syntax includes the full Itpl support, so
392 interpolation syntax includes the full Itpl support, so
389 ${foo()+x+bar()} is a valid prompt string now, and the function
393 ${foo()+x+bar()} is a valid prompt string now, and the function
390 calls will be made at runtime.
394 calls will be made at runtime.
391
395
392 2005-03-15 Fernando Perez <fperez@colorado.edu>
396 2005-03-15 Fernando Perez <fperez@colorado.edu>
393
397
394 * IPython/Magic.py (magic_history): renamed %hist to %history, to
398 * IPython/Magic.py (magic_history): renamed %hist to %history, to
395 avoid name clashes in pylab. %hist still works, it just forwards
399 avoid name clashes in pylab. %hist still works, it just forwards
396 the call to %history.
400 the call to %history.
397
401
398 2005-03-02 *** Released version 0.6.12
402 2005-03-02 *** Released version 0.6.12
399
403
400 2005-03-02 Fernando Perez <fperez@colorado.edu>
404 2005-03-02 Fernando Perez <fperez@colorado.edu>
401
405
402 * IPython/iplib.py (handle_magic): log magic calls properly as
406 * IPython/iplib.py (handle_magic): log magic calls properly as
403 ipmagic() function calls.
407 ipmagic() function calls.
404
408
405 * IPython/Magic.py (magic_time): Improved %time to support
409 * IPython/Magic.py (magic_time): Improved %time to support
406 statements and provide wall-clock as well as CPU time.
410 statements and provide wall-clock as well as CPU time.
407
411
408 2005-02-27 Fernando Perez <fperez@colorado.edu>
412 2005-02-27 Fernando Perez <fperez@colorado.edu>
409
413
410 * IPython/hooks.py: New hooks module, to expose user-modifiable
414 * IPython/hooks.py: New hooks module, to expose user-modifiable
411 IPython functionality in a clean manner. For now only the editor
415 IPython functionality in a clean manner. For now only the editor
412 hook is actually written, and other thigns which I intend to turn
416 hook is actually written, and other thigns which I intend to turn
413 into proper hooks aren't yet there. The display and prefilter
417 into proper hooks aren't yet there. The display and prefilter
414 stuff, for example, should be hooks. But at least now the
418 stuff, for example, should be hooks. But at least now the
415 framework is in place, and the rest can be moved here with more
419 framework is in place, and the rest can be moved here with more
416 time later. IPython had had a .hooks variable for a long time for
420 time later. IPython had had a .hooks variable for a long time for
417 this purpose, but I'd never actually used it for anything.
421 this purpose, but I'd never actually used it for anything.
418
422
419 2005-02-26 Fernando Perez <fperez@colorado.edu>
423 2005-02-26 Fernando Perez <fperez@colorado.edu>
420
424
421 * IPython/ipmaker.py (make_IPython): make the default ipython
425 * IPython/ipmaker.py (make_IPython): make the default ipython
422 directory be called _ipython under win32, to follow more the
426 directory be called _ipython under win32, to follow more the
423 naming peculiarities of that platform (where buggy software like
427 naming peculiarities of that platform (where buggy software like
424 Visual Sourcesafe breaks with .named directories). Reported by
428 Visual Sourcesafe breaks with .named directories). Reported by
425 Ville Vainio.
429 Ville Vainio.
426
430
427 2005-02-23 Fernando Perez <fperez@colorado.edu>
431 2005-02-23 Fernando Perez <fperez@colorado.edu>
428
432
429 * IPython/iplib.py (InteractiveShell.__init__): removed a few
433 * IPython/iplib.py (InteractiveShell.__init__): removed a few
430 auto_aliases for win32 which were causing problems. Users can
434 auto_aliases for win32 which were causing problems. Users can
431 define the ones they personally like.
435 define the ones they personally like.
432
436
433 2005-02-21 Fernando Perez <fperez@colorado.edu>
437 2005-02-21 Fernando Perez <fperez@colorado.edu>
434
438
435 * IPython/Magic.py (magic_time): new magic to time execution of
439 * IPython/Magic.py (magic_time): new magic to time execution of
436 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
440 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
437
441
438 2005-02-19 Fernando Perez <fperez@colorado.edu>
442 2005-02-19 Fernando Perez <fperez@colorado.edu>
439
443
440 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
444 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
441 into keys (for prompts, for example).
445 into keys (for prompts, for example).
442
446
443 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
447 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
444 prompts in case users want them. This introduces a small behavior
448 prompts in case users want them. This introduces a small behavior
445 change: ipython does not automatically add a space to all prompts
449 change: ipython does not automatically add a space to all prompts
446 anymore. To get the old prompts with a space, users should add it
450 anymore. To get the old prompts with a space, users should add it
447 manually to their ipythonrc file, so for example prompt_in1 should
451 manually to their ipythonrc file, so for example prompt_in1 should
448 now read 'In [\#]: ' instead of 'In [\#]:'.
452 now read 'In [\#]: ' instead of 'In [\#]:'.
449 (BasePrompt.__init__): New option prompts_pad_left (only in rc
453 (BasePrompt.__init__): New option prompts_pad_left (only in rc
450 file) to control left-padding of secondary prompts.
454 file) to control left-padding of secondary prompts.
451
455
452 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
456 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
453 the profiler can't be imported. Fix for Debian, which removed
457 the profiler can't be imported. Fix for Debian, which removed
454 profile.py because of License issues. I applied a slightly
458 profile.py because of License issues. I applied a slightly
455 modified version of the original Debian patch at
459 modified version of the original Debian patch at
456 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
460 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
457
461
458 2005-02-17 Fernando Perez <fperez@colorado.edu>
462 2005-02-17 Fernando Perez <fperez@colorado.edu>
459
463
460 * IPython/genutils.py (native_line_ends): Fix bug which would
464 * IPython/genutils.py (native_line_ends): Fix bug which would
461 cause improper line-ends under win32 b/c I was not opening files
465 cause improper line-ends under win32 b/c I was not opening files
462 in binary mode. Bug report and fix thanks to Ville.
466 in binary mode. Bug report and fix thanks to Ville.
463
467
464 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
468 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
465 trying to catch spurious foo[1] autocalls. My fix actually broke
469 trying to catch spurious foo[1] autocalls. My fix actually broke
466 ',/' autoquote/call with explicit escape (bad regexp).
470 ',/' autoquote/call with explicit escape (bad regexp).
467
471
468 2005-02-15 *** Released version 0.6.11
472 2005-02-15 *** Released version 0.6.11
469
473
470 2005-02-14 Fernando Perez <fperez@colorado.edu>
474 2005-02-14 Fernando Perez <fperez@colorado.edu>
471
475
472 * IPython/background_jobs.py: New background job management
476 * IPython/background_jobs.py: New background job management
473 subsystem. This is implemented via a new set of classes, and
477 subsystem. This is implemented via a new set of classes, and
474 IPython now provides a builtin 'jobs' object for background job
478 IPython now provides a builtin 'jobs' object for background job
475 execution. A convenience %bg magic serves as a lightweight
479 execution. A convenience %bg magic serves as a lightweight
476 frontend for starting the more common type of calls. This was
480 frontend for starting the more common type of calls. This was
477 inspired by discussions with B. Granger and the BackgroundCommand
481 inspired by discussions with B. Granger and the BackgroundCommand
478 class described in the book Python Scripting for Computational
482 class described in the book Python Scripting for Computational
479 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
483 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
480 (although ultimately no code from this text was used, as IPython's
484 (although ultimately no code from this text was used, as IPython's
481 system is a separate implementation).
485 system is a separate implementation).
482
486
483 * IPython/iplib.py (MagicCompleter.python_matches): add new option
487 * IPython/iplib.py (MagicCompleter.python_matches): add new option
484 to control the completion of single/double underscore names
488 to control the completion of single/double underscore names
485 separately. As documented in the example ipytonrc file, the
489 separately. As documented in the example ipytonrc file, the
486 readline_omit__names variable can now be set to 2, to omit even
490 readline_omit__names variable can now be set to 2, to omit even
487 single underscore names. Thanks to a patch by Brian Wong
491 single underscore names. Thanks to a patch by Brian Wong
488 <BrianWong-AT-AirgoNetworks.Com>.
492 <BrianWong-AT-AirgoNetworks.Com>.
489 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
493 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
490 be autocalled as foo([1]) if foo were callable. A problem for
494 be autocalled as foo([1]) if foo were callable. A problem for
491 things which are both callable and implement __getitem__.
495 things which are both callable and implement __getitem__.
492 (init_readline): Fix autoindentation for win32. Thanks to a patch
496 (init_readline): Fix autoindentation for win32. Thanks to a patch
493 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
497 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
494
498
495 2005-02-12 Fernando Perez <fperez@colorado.edu>
499 2005-02-12 Fernando Perez <fperez@colorado.edu>
496
500
497 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
501 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
498 which I had written long ago to sort out user error messages which
502 which I had written long ago to sort out user error messages which
499 may occur during startup. This seemed like a good idea initially,
503 may occur during startup. This seemed like a good idea initially,
500 but it has proven a disaster in retrospect. I don't want to
504 but it has proven a disaster in retrospect. I don't want to
501 change much code for now, so my fix is to set the internal 'debug'
505 change much code for now, so my fix is to set the internal 'debug'
502 flag to true everywhere, whose only job was precisely to control
506 flag to true everywhere, whose only job was precisely to control
503 this subsystem. This closes issue 28 (as well as avoiding all
507 this subsystem. This closes issue 28 (as well as avoiding all
504 sorts of strange hangups which occur from time to time).
508 sorts of strange hangups which occur from time to time).
505
509
506 2005-02-07 Fernando Perez <fperez@colorado.edu>
510 2005-02-07 Fernando Perez <fperez@colorado.edu>
507
511
508 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
512 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
509 previous call produced a syntax error.
513 previous call produced a syntax error.
510
514
511 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
515 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
512 classes without constructor.
516 classes without constructor.
513
517
514 2005-02-06 Fernando Perez <fperez@colorado.edu>
518 2005-02-06 Fernando Perez <fperez@colorado.edu>
515
519
516 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
520 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
517 completions with the results of each matcher, so we return results
521 completions with the results of each matcher, so we return results
518 to the user from all namespaces. This breaks with ipython
522 to the user from all namespaces. This breaks with ipython
519 tradition, but I think it's a nicer behavior. Now you get all
523 tradition, but I think it's a nicer behavior. Now you get all
520 possible completions listed, from all possible namespaces (python,
524 possible completions listed, from all possible namespaces (python,
521 filesystem, magics...) After a request by John Hunter
525 filesystem, magics...) After a request by John Hunter
522 <jdhunter-AT-nitace.bsd.uchicago.edu>.
526 <jdhunter-AT-nitace.bsd.uchicago.edu>.
523
527
524 2005-02-05 Fernando Perez <fperez@colorado.edu>
528 2005-02-05 Fernando Perez <fperez@colorado.edu>
525
529
526 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
530 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
527 the call had quote characters in it (the quotes were stripped).
531 the call had quote characters in it (the quotes were stripped).
528
532
529 2005-01-31 Fernando Perez <fperez@colorado.edu>
533 2005-01-31 Fernando Perez <fperez@colorado.edu>
530
534
531 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
535 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
532 Itpl.itpl() to make the code more robust against psyco
536 Itpl.itpl() to make the code more robust against psyco
533 optimizations.
537 optimizations.
534
538
535 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
539 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
536 of causing an exception. Quicker, cleaner.
540 of causing an exception. Quicker, cleaner.
537
541
538 2005-01-28 Fernando Perez <fperez@colorado.edu>
542 2005-01-28 Fernando Perez <fperez@colorado.edu>
539
543
540 * scripts/ipython_win_post_install.py (install): hardcode
544 * scripts/ipython_win_post_install.py (install): hardcode
541 sys.prefix+'python.exe' as the executable path. It turns out that
545 sys.prefix+'python.exe' as the executable path. It turns out that
542 during the post-installation run, sys.executable resolves to the
546 during the post-installation run, sys.executable resolves to the
543 name of the binary installer! I should report this as a distutils
547 name of the binary installer! I should report this as a distutils
544 bug, I think. I updated the .10 release with this tiny fix, to
548 bug, I think. I updated the .10 release with this tiny fix, to
545 avoid annoying the lists further.
549 avoid annoying the lists further.
546
550
547 2005-01-27 *** Released version 0.6.10
551 2005-01-27 *** Released version 0.6.10
548
552
549 2005-01-27 Fernando Perez <fperez@colorado.edu>
553 2005-01-27 Fernando Perez <fperez@colorado.edu>
550
554
551 * IPython/numutils.py (norm): Added 'inf' as optional name for
555 * IPython/numutils.py (norm): Added 'inf' as optional name for
552 L-infinity norm, included references to mathworld.com for vector
556 L-infinity norm, included references to mathworld.com for vector
553 norm definitions.
557 norm definitions.
554 (amin/amax): added amin/amax for array min/max. Similar to what
558 (amin/amax): added amin/amax for array min/max. Similar to what
555 pylab ships with after the recent reorganization of names.
559 pylab ships with after the recent reorganization of names.
556 (spike/spike_odd): removed deprecated spike/spike_odd functions.
560 (spike/spike_odd): removed deprecated spike/spike_odd functions.
557
561
558 * ipython.el: committed Alex's recent fixes and improvements.
562 * ipython.el: committed Alex's recent fixes and improvements.
559 Tested with python-mode from CVS, and it looks excellent. Since
563 Tested with python-mode from CVS, and it looks excellent. Since
560 python-mode hasn't released anything in a while, I'm temporarily
564 python-mode hasn't released anything in a while, I'm temporarily
561 putting a copy of today's CVS (v 4.70) of python-mode in:
565 putting a copy of today's CVS (v 4.70) of python-mode in:
562 http://ipython.scipy.org/tmp/python-mode.el
566 http://ipython.scipy.org/tmp/python-mode.el
563
567
564 * scripts/ipython_win_post_install.py (install): Win32 fix to use
568 * scripts/ipython_win_post_install.py (install): Win32 fix to use
565 sys.executable for the executable name, instead of assuming it's
569 sys.executable for the executable name, instead of assuming it's
566 called 'python.exe' (the post-installer would have produced broken
570 called 'python.exe' (the post-installer would have produced broken
567 setups on systems with a differently named python binary).
571 setups on systems with a differently named python binary).
568
572
569 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
573 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
570 references to os.linesep, to make the code more
574 references to os.linesep, to make the code more
571 platform-independent. This is also part of the win32 coloring
575 platform-independent. This is also part of the win32 coloring
572 fixes.
576 fixes.
573
577
574 * IPython/genutils.py (page_dumb): Remove attempts to chop long
578 * IPython/genutils.py (page_dumb): Remove attempts to chop long
575 lines, which actually cause coloring bugs because the length of
579 lines, which actually cause coloring bugs because the length of
576 the line is very difficult to correctly compute with embedded
580 the line is very difficult to correctly compute with embedded
577 escapes. This was the source of all the coloring problems under
581 escapes. This was the source of all the coloring problems under
578 Win32. I think that _finally_, Win32 users have a properly
582 Win32. I think that _finally_, Win32 users have a properly
579 working ipython in all respects. This would never have happened
583 working ipython in all respects. This would never have happened
580 if not for Gary Bishop and Viktor Ransmayr's great help and work.
584 if not for Gary Bishop and Viktor Ransmayr's great help and work.
581
585
582 2005-01-26 *** Released version 0.6.9
586 2005-01-26 *** Released version 0.6.9
583
587
584 2005-01-25 Fernando Perez <fperez@colorado.edu>
588 2005-01-25 Fernando Perez <fperez@colorado.edu>
585
589
586 * setup.py: finally, we have a true Windows installer, thanks to
590 * setup.py: finally, we have a true Windows installer, thanks to
587 the excellent work of Viktor Ransmayr
591 the excellent work of Viktor Ransmayr
588 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
592 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
589 Windows users. The setup routine is quite a bit cleaner thanks to
593 Windows users. The setup routine is quite a bit cleaner thanks to
590 this, and the post-install script uses the proper functions to
594 this, and the post-install script uses the proper functions to
591 allow a clean de-installation using the standard Windows Control
595 allow a clean de-installation using the standard Windows Control
592 Panel.
596 Panel.
593
597
594 * IPython/genutils.py (get_home_dir): changed to use the $HOME
598 * IPython/genutils.py (get_home_dir): changed to use the $HOME
595 environment variable under all OSes (including win32) if
599 environment variable under all OSes (including win32) if
596 available. This will give consistency to win32 users who have set
600 available. This will give consistency to win32 users who have set
597 this variable for any reason. If os.environ['HOME'] fails, the
601 this variable for any reason. If os.environ['HOME'] fails, the
598 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
602 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
599
603
600 2005-01-24 Fernando Perez <fperez@colorado.edu>
604 2005-01-24 Fernando Perez <fperez@colorado.edu>
601
605
602 * IPython/numutils.py (empty_like): add empty_like(), similar to
606 * IPython/numutils.py (empty_like): add empty_like(), similar to
603 zeros_like() but taking advantage of the new empty() Numeric routine.
607 zeros_like() but taking advantage of the new empty() Numeric routine.
604
608
605 2005-01-23 *** Released version 0.6.8
609 2005-01-23 *** Released version 0.6.8
606
610
607 2005-01-22 Fernando Perez <fperez@colorado.edu>
611 2005-01-22 Fernando Perez <fperez@colorado.edu>
608
612
609 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
613 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
610 automatic show() calls. After discussing things with JDH, it
614 automatic show() calls. After discussing things with JDH, it
611 turns out there are too many corner cases where this can go wrong.
615 turns out there are too many corner cases where this can go wrong.
612 It's best not to try to be 'too smart', and simply have ipython
616 It's best not to try to be 'too smart', and simply have ipython
613 reproduce as much as possible the default behavior of a normal
617 reproduce as much as possible the default behavior of a normal
614 python shell.
618 python shell.
615
619
616 * IPython/iplib.py (InteractiveShell.__init__): Modified the
620 * IPython/iplib.py (InteractiveShell.__init__): Modified the
617 line-splitting regexp and _prefilter() to avoid calling getattr()
621 line-splitting regexp and _prefilter() to avoid calling getattr()
618 on assignments. This closes
622 on assignments. This closes
619 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
623 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
620 readline uses getattr(), so a simple <TAB> keypress is still
624 readline uses getattr(), so a simple <TAB> keypress is still
621 enough to trigger getattr() calls on an object.
625 enough to trigger getattr() calls on an object.
622
626
623 2005-01-21 Fernando Perez <fperez@colorado.edu>
627 2005-01-21 Fernando Perez <fperez@colorado.edu>
624
628
625 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
629 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
626 docstring under pylab so it doesn't mask the original.
630 docstring under pylab so it doesn't mask the original.
627
631
628 2005-01-21 *** Released version 0.6.7
632 2005-01-21 *** Released version 0.6.7
629
633
630 2005-01-21 Fernando Perez <fperez@colorado.edu>
634 2005-01-21 Fernando Perez <fperez@colorado.edu>
631
635
632 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
636 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
633 signal handling for win32 users in multithreaded mode.
637 signal handling for win32 users in multithreaded mode.
634
638
635 2005-01-17 Fernando Perez <fperez@colorado.edu>
639 2005-01-17 Fernando Perez <fperez@colorado.edu>
636
640
637 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
641 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
638 instances with no __init__. After a crash report by Norbert Nemec
642 instances with no __init__. After a crash report by Norbert Nemec
639 <Norbert-AT-nemec-online.de>.
643 <Norbert-AT-nemec-online.de>.
640
644
641 2005-01-14 Fernando Perez <fperez@colorado.edu>
645 2005-01-14 Fernando Perez <fperez@colorado.edu>
642
646
643 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
647 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
644 names for verbose exceptions, when multiple dotted names and the
648 names for verbose exceptions, when multiple dotted names and the
645 'parent' object were present on the same line.
649 'parent' object were present on the same line.
646
650
647 2005-01-11 Fernando Perez <fperez@colorado.edu>
651 2005-01-11 Fernando Perez <fperez@colorado.edu>
648
652
649 * IPython/genutils.py (flag_calls): new utility to trap and flag
653 * IPython/genutils.py (flag_calls): new utility to trap and flag
650 calls in functions. I need it to clean up matplotlib support.
654 calls in functions. I need it to clean up matplotlib support.
651 Also removed some deprecated code in genutils.
655 Also removed some deprecated code in genutils.
652
656
653 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
657 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
654 that matplotlib scripts called with %run, which don't call show()
658 that matplotlib scripts called with %run, which don't call show()
655 themselves, still have their plotting windows open.
659 themselves, still have their plotting windows open.
656
660
657 2005-01-05 Fernando Perez <fperez@colorado.edu>
661 2005-01-05 Fernando Perez <fperez@colorado.edu>
658
662
659 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
663 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
660 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
664 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
661
665
662 2004-12-19 Fernando Perez <fperez@colorado.edu>
666 2004-12-19 Fernando Perez <fperez@colorado.edu>
663
667
664 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
668 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
665 parent_runcode, which was an eyesore. The same result can be
669 parent_runcode, which was an eyesore. The same result can be
666 obtained with Python's regular superclass mechanisms.
670 obtained with Python's regular superclass mechanisms.
667
671
668 2004-12-17 Fernando Perez <fperez@colorado.edu>
672 2004-12-17 Fernando Perez <fperez@colorado.edu>
669
673
670 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
674 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
671 reported by Prabhu.
675 reported by Prabhu.
672 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
676 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
673 sys.stderr) instead of explicitly calling sys.stderr. This helps
677 sys.stderr) instead of explicitly calling sys.stderr. This helps
674 maintain our I/O abstractions clean, for future GUI embeddings.
678 maintain our I/O abstractions clean, for future GUI embeddings.
675
679
676 * IPython/genutils.py (info): added new utility for sys.stderr
680 * IPython/genutils.py (info): added new utility for sys.stderr
677 unified info message handling (thin wrapper around warn()).
681 unified info message handling (thin wrapper around warn()).
678
682
679 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
683 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
680 composite (dotted) names on verbose exceptions.
684 composite (dotted) names on verbose exceptions.
681 (VerboseTB.nullrepr): harden against another kind of errors which
685 (VerboseTB.nullrepr): harden against another kind of errors which
682 Python's inspect module can trigger, and which were crashing
686 Python's inspect module can trigger, and which were crashing
683 IPython. Thanks to a report by Marco Lombardi
687 IPython. Thanks to a report by Marco Lombardi
684 <mlombard-AT-ma010192.hq.eso.org>.
688 <mlombard-AT-ma010192.hq.eso.org>.
685
689
686 2004-12-13 *** Released version 0.6.6
690 2004-12-13 *** Released version 0.6.6
687
691
688 2004-12-12 Fernando Perez <fperez@colorado.edu>
692 2004-12-12 Fernando Perez <fperez@colorado.edu>
689
693
690 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
694 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
691 generated by pygtk upon initialization if it was built without
695 generated by pygtk upon initialization if it was built without
692 threads (for matplotlib users). After a crash reported by
696 threads (for matplotlib users). After a crash reported by
693 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
697 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
694
698
695 * IPython/ipmaker.py (make_IPython): fix small bug in the
699 * IPython/ipmaker.py (make_IPython): fix small bug in the
696 import_some parameter for multiple imports.
700 import_some parameter for multiple imports.
697
701
698 * IPython/iplib.py (ipmagic): simplified the interface of
702 * IPython/iplib.py (ipmagic): simplified the interface of
699 ipmagic() to take a single string argument, just as it would be
703 ipmagic() to take a single string argument, just as it would be
700 typed at the IPython cmd line.
704 typed at the IPython cmd line.
701 (ipalias): Added new ipalias() with an interface identical to
705 (ipalias): Added new ipalias() with an interface identical to
702 ipmagic(). This completes exposing a pure python interface to the
706 ipmagic(). This completes exposing a pure python interface to the
703 alias and magic system, which can be used in loops or more complex
707 alias and magic system, which can be used in loops or more complex
704 code where IPython's automatic line mangling is not active.
708 code where IPython's automatic line mangling is not active.
705
709
706 * IPython/genutils.py (timing): changed interface of timing to
710 * IPython/genutils.py (timing): changed interface of timing to
707 simply run code once, which is the most common case. timings()
711 simply run code once, which is the most common case. timings()
708 remains unchanged, for the cases where you want multiple runs.
712 remains unchanged, for the cases where you want multiple runs.
709
713
710 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
714 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
711 bug where Python2.2 crashes with exec'ing code which does not end
715 bug where Python2.2 crashes with exec'ing code which does not end
712 in a single newline. Python 2.3 is OK, so I hadn't noticed this
716 in a single newline. Python 2.3 is OK, so I hadn't noticed this
713 before.
717 before.
714
718
715 2004-12-10 Fernando Perez <fperez@colorado.edu>
719 2004-12-10 Fernando Perez <fperez@colorado.edu>
716
720
717 * IPython/Magic.py (Magic.magic_prun): changed name of option from
721 * IPython/Magic.py (Magic.magic_prun): changed name of option from
718 -t to -T, to accomodate the new -t flag in %run (the %run and
722 -t to -T, to accomodate the new -t flag in %run (the %run and
719 %prun options are kind of intermixed, and it's not easy to change
723 %prun options are kind of intermixed, and it's not easy to change
720 this with the limitations of python's getopt).
724 this with the limitations of python's getopt).
721
725
722 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
726 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
723 the execution of scripts. It's not as fine-tuned as timeit.py,
727 the execution of scripts. It's not as fine-tuned as timeit.py,
724 but it works from inside ipython (and under 2.2, which lacks
728 but it works from inside ipython (and under 2.2, which lacks
725 timeit.py). Optionally a number of runs > 1 can be given for
729 timeit.py). Optionally a number of runs > 1 can be given for
726 timing very short-running code.
730 timing very short-running code.
727
731
728 * IPython/genutils.py (uniq_stable): new routine which returns a
732 * IPython/genutils.py (uniq_stable): new routine which returns a
729 list of unique elements in any iterable, but in stable order of
733 list of unique elements in any iterable, but in stable order of
730 appearance. I needed this for the ultraTB fixes, and it's a handy
734 appearance. I needed this for the ultraTB fixes, and it's a handy
731 utility.
735 utility.
732
736
733 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
737 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
734 dotted names in Verbose exceptions. This had been broken since
738 dotted names in Verbose exceptions. This had been broken since
735 the very start, now x.y will properly be printed in a Verbose
739 the very start, now x.y will properly be printed in a Verbose
736 traceback, instead of x being shown and y appearing always as an
740 traceback, instead of x being shown and y appearing always as an
737 'undefined global'. Getting this to work was a bit tricky,
741 'undefined global'. Getting this to work was a bit tricky,
738 because by default python tokenizers are stateless. Saved by
742 because by default python tokenizers are stateless. Saved by
739 python's ability to easily add a bit of state to an arbitrary
743 python's ability to easily add a bit of state to an arbitrary
740 function (without needing to build a full-blown callable object).
744 function (without needing to build a full-blown callable object).
741
745
742 Also big cleanup of this code, which had horrendous runtime
746 Also big cleanup of this code, which had horrendous runtime
743 lookups of zillions of attributes for colorization. Moved all
747 lookups of zillions of attributes for colorization. Moved all
744 this code into a few templates, which make it cleaner and quicker.
748 this code into a few templates, which make it cleaner and quicker.
745
749
746 Printout quality was also improved for Verbose exceptions: one
750 Printout quality was also improved for Verbose exceptions: one
747 variable per line, and memory addresses are printed (this can be
751 variable per line, and memory addresses are printed (this can be
748 quite handy in nasty debugging situations, which is what Verbose
752 quite handy in nasty debugging situations, which is what Verbose
749 is for).
753 is for).
750
754
751 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
755 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
752 the command line as scripts to be loaded by embedded instances.
756 the command line as scripts to be loaded by embedded instances.
753 Doing so has the potential for an infinite recursion if there are
757 Doing so has the potential for an infinite recursion if there are
754 exceptions thrown in the process. This fixes a strange crash
758 exceptions thrown in the process. This fixes a strange crash
755 reported by Philippe MULLER <muller-AT-irit.fr>.
759 reported by Philippe MULLER <muller-AT-irit.fr>.
756
760
757 2004-12-09 Fernando Perez <fperez@colorado.edu>
761 2004-12-09 Fernando Perez <fperez@colorado.edu>
758
762
759 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
763 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
760 to reflect new names in matplotlib, which now expose the
764 to reflect new names in matplotlib, which now expose the
761 matlab-compatible interface via a pylab module instead of the
765 matlab-compatible interface via a pylab module instead of the
762 'matlab' name. The new code is backwards compatible, so users of
766 'matlab' name. The new code is backwards compatible, so users of
763 all matplotlib versions are OK. Patch by J. Hunter.
767 all matplotlib versions are OK. Patch by J. Hunter.
764
768
765 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
769 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
766 of __init__ docstrings for instances (class docstrings are already
770 of __init__ docstrings for instances (class docstrings are already
767 automatically printed). Instances with customized docstrings
771 automatically printed). Instances with customized docstrings
768 (indep. of the class) are also recognized and all 3 separate
772 (indep. of the class) are also recognized and all 3 separate
769 docstrings are printed (instance, class, constructor). After some
773 docstrings are printed (instance, class, constructor). After some
770 comments/suggestions by J. Hunter.
774 comments/suggestions by J. Hunter.
771
775
772 2004-12-05 Fernando Perez <fperez@colorado.edu>
776 2004-12-05 Fernando Perez <fperez@colorado.edu>
773
777
774 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
778 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
775 warnings when tab-completion fails and triggers an exception.
779 warnings when tab-completion fails and triggers an exception.
776
780
777 2004-12-03 Fernando Perez <fperez@colorado.edu>
781 2004-12-03 Fernando Perez <fperez@colorado.edu>
778
782
779 * IPython/Magic.py (magic_prun): Fix bug where an exception would
783 * IPython/Magic.py (magic_prun): Fix bug where an exception would
780 be triggered when using 'run -p'. An incorrect option flag was
784 be triggered when using 'run -p'. An incorrect option flag was
781 being set ('d' instead of 'D').
785 being set ('d' instead of 'D').
782 (manpage): fix missing escaped \- sign.
786 (manpage): fix missing escaped \- sign.
783
787
784 2004-11-30 *** Released version 0.6.5
788 2004-11-30 *** Released version 0.6.5
785
789
786 2004-11-30 Fernando Perez <fperez@colorado.edu>
790 2004-11-30 Fernando Perez <fperez@colorado.edu>
787
791
788 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
792 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
789 setting with -d option.
793 setting with -d option.
790
794
791 * setup.py (docfiles): Fix problem where the doc glob I was using
795 * setup.py (docfiles): Fix problem where the doc glob I was using
792 was COMPLETELY BROKEN. It was giving the right files by pure
796 was COMPLETELY BROKEN. It was giving the right files by pure
793 accident, but failed once I tried to include ipython.el. Note:
797 accident, but failed once I tried to include ipython.el. Note:
794 glob() does NOT allow you to do exclusion on multiple endings!
798 glob() does NOT allow you to do exclusion on multiple endings!
795
799
796 2004-11-29 Fernando Perez <fperez@colorado.edu>
800 2004-11-29 Fernando Perez <fperez@colorado.edu>
797
801
798 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
802 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
799 the manpage as the source. Better formatting & consistency.
803 the manpage as the source. Better formatting & consistency.
800
804
801 * IPython/Magic.py (magic_run): Added new -d option, to run
805 * IPython/Magic.py (magic_run): Added new -d option, to run
802 scripts under the control of the python pdb debugger. Note that
806 scripts under the control of the python pdb debugger. Note that
803 this required changing the %prun option -d to -D, to avoid a clash
807 this required changing the %prun option -d to -D, to avoid a clash
804 (since %run must pass options to %prun, and getopt is too dumb to
808 (since %run must pass options to %prun, and getopt is too dumb to
805 handle options with string values with embedded spaces). Thanks
809 handle options with string values with embedded spaces). Thanks
806 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
810 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
807 (magic_who_ls): added type matching to %who and %whos, so that one
811 (magic_who_ls): added type matching to %who and %whos, so that one
808 can filter their output to only include variables of certain
812 can filter their output to only include variables of certain
809 types. Another suggestion by Matthew.
813 types. Another suggestion by Matthew.
810 (magic_whos): Added memory summaries in kb and Mb for arrays.
814 (magic_whos): Added memory summaries in kb and Mb for arrays.
811 (magic_who): Improve formatting (break lines every 9 vars).
815 (magic_who): Improve formatting (break lines every 9 vars).
812
816
813 2004-11-28 Fernando Perez <fperez@colorado.edu>
817 2004-11-28 Fernando Perez <fperez@colorado.edu>
814
818
815 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
819 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
816 cache when empty lines were present.
820 cache when empty lines were present.
817
821
818 2004-11-24 Fernando Perez <fperez@colorado.edu>
822 2004-11-24 Fernando Perez <fperez@colorado.edu>
819
823
820 * IPython/usage.py (__doc__): document the re-activated threading
824 * IPython/usage.py (__doc__): document the re-activated threading
821 options for WX and GTK.
825 options for WX and GTK.
822
826
823 2004-11-23 Fernando Perez <fperez@colorado.edu>
827 2004-11-23 Fernando Perez <fperez@colorado.edu>
824
828
825 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
829 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
826 the -wthread and -gthread options, along with a new -tk one to try
830 the -wthread and -gthread options, along with a new -tk one to try
827 and coordinate Tk threading with wx/gtk. The tk support is very
831 and coordinate Tk threading with wx/gtk. The tk support is very
828 platform dependent, since it seems to require Tcl and Tk to be
832 platform dependent, since it seems to require Tcl and Tk to be
829 built with threads (Fedora1/2 appears NOT to have it, but in
833 built with threads (Fedora1/2 appears NOT to have it, but in
830 Prabhu's Debian boxes it works OK). But even with some Tk
834 Prabhu's Debian boxes it works OK). But even with some Tk
831 limitations, this is a great improvement.
835 limitations, this is a great improvement.
832
836
833 * IPython/Prompts.py (prompt_specials_color): Added \t for time
837 * IPython/Prompts.py (prompt_specials_color): Added \t for time
834 info in user prompts. Patch by Prabhu.
838 info in user prompts. Patch by Prabhu.
835
839
836 2004-11-18 Fernando Perez <fperez@colorado.edu>
840 2004-11-18 Fernando Perez <fperez@colorado.edu>
837
841
838 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
842 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
839 EOFErrors and bail, to avoid infinite loops if a non-terminating
843 EOFErrors and bail, to avoid infinite loops if a non-terminating
840 file is fed into ipython. Patch submitted in issue 19 by user,
844 file is fed into ipython. Patch submitted in issue 19 by user,
841 many thanks.
845 many thanks.
842
846
843 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
847 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
844 autoquote/parens in continuation prompts, which can cause lots of
848 autoquote/parens in continuation prompts, which can cause lots of
845 problems. Closes roundup issue 20.
849 problems. Closes roundup issue 20.
846
850
847 2004-11-17 Fernando Perez <fperez@colorado.edu>
851 2004-11-17 Fernando Perez <fperez@colorado.edu>
848
852
849 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
853 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
850 reported as debian bug #280505. I'm not sure my local changelog
854 reported as debian bug #280505. I'm not sure my local changelog
851 entry has the proper debian format (Jack?).
855 entry has the proper debian format (Jack?).
852
856
853 2004-11-08 *** Released version 0.6.4
857 2004-11-08 *** Released version 0.6.4
854
858
855 2004-11-08 Fernando Perez <fperez@colorado.edu>
859 2004-11-08 Fernando Perez <fperez@colorado.edu>
856
860
857 * IPython/iplib.py (init_readline): Fix exit message for Windows
861 * IPython/iplib.py (init_readline): Fix exit message for Windows
858 when readline is active. Thanks to a report by Eric Jones
862 when readline is active. Thanks to a report by Eric Jones
859 <eric-AT-enthought.com>.
863 <eric-AT-enthought.com>.
860
864
861 2004-11-07 Fernando Perez <fperez@colorado.edu>
865 2004-11-07 Fernando Perez <fperez@colorado.edu>
862
866
863 * IPython/genutils.py (page): Add a trap for OSError exceptions,
867 * IPython/genutils.py (page): Add a trap for OSError exceptions,
864 sometimes seen by win2k/cygwin users.
868 sometimes seen by win2k/cygwin users.
865
869
866 2004-11-06 Fernando Perez <fperez@colorado.edu>
870 2004-11-06 Fernando Perez <fperez@colorado.edu>
867
871
868 * IPython/iplib.py (interact): Change the handling of %Exit from
872 * IPython/iplib.py (interact): Change the handling of %Exit from
869 trying to propagate a SystemExit to an internal ipython flag.
873 trying to propagate a SystemExit to an internal ipython flag.
870 This is less elegant than using Python's exception mechanism, but
874 This is less elegant than using Python's exception mechanism, but
871 I can't get that to work reliably with threads, so under -pylab
875 I can't get that to work reliably with threads, so under -pylab
872 %Exit was hanging IPython. Cross-thread exception handling is
876 %Exit was hanging IPython. Cross-thread exception handling is
873 really a bitch. Thaks to a bug report by Stephen Walton
877 really a bitch. Thaks to a bug report by Stephen Walton
874 <stephen.walton-AT-csun.edu>.
878 <stephen.walton-AT-csun.edu>.
875
879
876 2004-11-04 Fernando Perez <fperez@colorado.edu>
880 2004-11-04 Fernando Perez <fperez@colorado.edu>
877
881
878 * IPython/iplib.py (raw_input_original): store a pointer to the
882 * IPython/iplib.py (raw_input_original): store a pointer to the
879 true raw_input to harden against code which can modify it
883 true raw_input to harden against code which can modify it
880 (wx.py.PyShell does this and would otherwise crash ipython).
884 (wx.py.PyShell does this and would otherwise crash ipython).
881 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
885 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
882
886
883 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
887 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
884 Ctrl-C problem, which does not mess up the input line.
888 Ctrl-C problem, which does not mess up the input line.
885
889
886 2004-11-03 Fernando Perez <fperez@colorado.edu>
890 2004-11-03 Fernando Perez <fperez@colorado.edu>
887
891
888 * IPython/Release.py: Changed licensing to BSD, in all files.
892 * IPython/Release.py: Changed licensing to BSD, in all files.
889 (name): lowercase name for tarball/RPM release.
893 (name): lowercase name for tarball/RPM release.
890
894
891 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
895 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
892 use throughout ipython.
896 use throughout ipython.
893
897
894 * IPython/Magic.py (Magic._ofind): Switch to using the new
898 * IPython/Magic.py (Magic._ofind): Switch to using the new
895 OInspect.getdoc() function.
899 OInspect.getdoc() function.
896
900
897 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
901 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
898 of the line currently being canceled via Ctrl-C. It's extremely
902 of the line currently being canceled via Ctrl-C. It's extremely
899 ugly, but I don't know how to do it better (the problem is one of
903 ugly, but I don't know how to do it better (the problem is one of
900 handling cross-thread exceptions).
904 handling cross-thread exceptions).
901
905
902 2004-10-28 Fernando Perez <fperez@colorado.edu>
906 2004-10-28 Fernando Perez <fperez@colorado.edu>
903
907
904 * IPython/Shell.py (signal_handler): add signal handlers to trap
908 * IPython/Shell.py (signal_handler): add signal handlers to trap
905 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
909 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
906 report by Francesc Alted.
910 report by Francesc Alted.
907
911
908 2004-10-21 Fernando Perez <fperez@colorado.edu>
912 2004-10-21 Fernando Perez <fperez@colorado.edu>
909
913
910 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
914 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
911 to % for pysh syntax extensions.
915 to % for pysh syntax extensions.
912
916
913 2004-10-09 Fernando Perez <fperez@colorado.edu>
917 2004-10-09 Fernando Perez <fperez@colorado.edu>
914
918
915 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
919 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
916 arrays to print a more useful summary, without calling str(arr).
920 arrays to print a more useful summary, without calling str(arr).
917 This avoids the problem of extremely lengthy computations which
921 This avoids the problem of extremely lengthy computations which
918 occur if arr is large, and appear to the user as a system lockup
922 occur if arr is large, and appear to the user as a system lockup
919 with 100% cpu activity. After a suggestion by Kristian Sandberg
923 with 100% cpu activity. After a suggestion by Kristian Sandberg
920 <Kristian.Sandberg@colorado.edu>.
924 <Kristian.Sandberg@colorado.edu>.
921 (Magic.__init__): fix bug in global magic escapes not being
925 (Magic.__init__): fix bug in global magic escapes not being
922 correctly set.
926 correctly set.
923
927
924 2004-10-08 Fernando Perez <fperez@colorado.edu>
928 2004-10-08 Fernando Perez <fperez@colorado.edu>
925
929
926 * IPython/Magic.py (__license__): change to absolute imports of
930 * IPython/Magic.py (__license__): change to absolute imports of
927 ipython's own internal packages, to start adapting to the absolute
931 ipython's own internal packages, to start adapting to the absolute
928 import requirement of PEP-328.
932 import requirement of PEP-328.
929
933
930 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
934 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
931 files, and standardize author/license marks through the Release
935 files, and standardize author/license marks through the Release
932 module instead of having per/file stuff (except for files with
936 module instead of having per/file stuff (except for files with
933 particular licenses, like the MIT/PSF-licensed codes).
937 particular licenses, like the MIT/PSF-licensed codes).
934
938
935 * IPython/Debugger.py: remove dead code for python 2.1
939 * IPython/Debugger.py: remove dead code for python 2.1
936
940
937 2004-10-04 Fernando Perez <fperez@colorado.edu>
941 2004-10-04 Fernando Perez <fperez@colorado.edu>
938
942
939 * IPython/iplib.py (ipmagic): New function for accessing magics
943 * IPython/iplib.py (ipmagic): New function for accessing magics
940 via a normal python function call.
944 via a normal python function call.
941
945
942 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
946 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
943 from '@' to '%', to accomodate the new @decorator syntax of python
947 from '@' to '%', to accomodate the new @decorator syntax of python
944 2.4.
948 2.4.
945
949
946 2004-09-29 Fernando Perez <fperez@colorado.edu>
950 2004-09-29 Fernando Perez <fperez@colorado.edu>
947
951
948 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
952 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
949 matplotlib.use to prevent running scripts which try to switch
953 matplotlib.use to prevent running scripts which try to switch
950 interactive backends from within ipython. This will just crash
954 interactive backends from within ipython. This will just crash
951 the python interpreter, so we can't allow it (but a detailed error
955 the python interpreter, so we can't allow it (but a detailed error
952 is given to the user).
956 is given to the user).
953
957
954 2004-09-28 Fernando Perez <fperez@colorado.edu>
958 2004-09-28 Fernando Perez <fperez@colorado.edu>
955
959
956 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
960 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
957 matplotlib-related fixes so that using @run with non-matplotlib
961 matplotlib-related fixes so that using @run with non-matplotlib
958 scripts doesn't pop up spurious plot windows. This requires
962 scripts doesn't pop up spurious plot windows. This requires
959 matplotlib >= 0.63, where I had to make some changes as well.
963 matplotlib >= 0.63, where I had to make some changes as well.
960
964
961 * IPython/ipmaker.py (make_IPython): update version requirement to
965 * IPython/ipmaker.py (make_IPython): update version requirement to
962 python 2.2.
966 python 2.2.
963
967
964 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
968 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
965 banner arg for embedded customization.
969 banner arg for embedded customization.
966
970
967 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
971 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
968 explicit uses of __IP as the IPython's instance name. Now things
972 explicit uses of __IP as the IPython's instance name. Now things
969 are properly handled via the shell.name value. The actual code
973 are properly handled via the shell.name value. The actual code
970 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
974 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
971 is much better than before. I'll clean things completely when the
975 is much better than before. I'll clean things completely when the
972 magic stuff gets a real overhaul.
976 magic stuff gets a real overhaul.
973
977
974 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
978 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
975 minor changes to debian dir.
979 minor changes to debian dir.
976
980
977 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
981 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
978 pointer to the shell itself in the interactive namespace even when
982 pointer to the shell itself in the interactive namespace even when
979 a user-supplied dict is provided. This is needed for embedding
983 a user-supplied dict is provided. This is needed for embedding
980 purposes (found by tests with Michel Sanner).
984 purposes (found by tests with Michel Sanner).
981
985
982 2004-09-27 Fernando Perez <fperez@colorado.edu>
986 2004-09-27 Fernando Perez <fperez@colorado.edu>
983
987
984 * IPython/UserConfig/ipythonrc: remove []{} from
988 * IPython/UserConfig/ipythonrc: remove []{} from
985 readline_remove_delims, so that things like [modname.<TAB> do
989 readline_remove_delims, so that things like [modname.<TAB> do
986 proper completion. This disables [].TAB, but that's a less common
990 proper completion. This disables [].TAB, but that's a less common
987 case than module names in list comprehensions, for example.
991 case than module names in list comprehensions, for example.
988 Thanks to a report by Andrea Riciputi.
992 Thanks to a report by Andrea Riciputi.
989
993
990 2004-09-09 Fernando Perez <fperez@colorado.edu>
994 2004-09-09 Fernando Perez <fperez@colorado.edu>
991
995
992 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
996 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
993 blocking problems in win32 and osx. Fix by John.
997 blocking problems in win32 and osx. Fix by John.
994
998
995 2004-09-08 Fernando Perez <fperez@colorado.edu>
999 2004-09-08 Fernando Perez <fperez@colorado.edu>
996
1000
997 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1001 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
998 for Win32 and OSX. Fix by John Hunter.
1002 for Win32 and OSX. Fix by John Hunter.
999
1003
1000 2004-08-30 *** Released version 0.6.3
1004 2004-08-30 *** Released version 0.6.3
1001
1005
1002 2004-08-30 Fernando Perez <fperez@colorado.edu>
1006 2004-08-30 Fernando Perez <fperez@colorado.edu>
1003
1007
1004 * setup.py (isfile): Add manpages to list of dependent files to be
1008 * setup.py (isfile): Add manpages to list of dependent files to be
1005 updated.
1009 updated.
1006
1010
1007 2004-08-27 Fernando Perez <fperez@colorado.edu>
1011 2004-08-27 Fernando Perez <fperez@colorado.edu>
1008
1012
1009 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1013 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1010 for now. They don't really work with standalone WX/GTK code
1014 for now. They don't really work with standalone WX/GTK code
1011 (though matplotlib IS working fine with both of those backends).
1015 (though matplotlib IS working fine with both of those backends).
1012 This will neeed much more testing. I disabled most things with
1016 This will neeed much more testing. I disabled most things with
1013 comments, so turning it back on later should be pretty easy.
1017 comments, so turning it back on later should be pretty easy.
1014
1018
1015 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1019 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1016 autocalling of expressions like r'foo', by modifying the line
1020 autocalling of expressions like r'foo', by modifying the line
1017 split regexp. Closes
1021 split regexp. Closes
1018 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1022 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1019 Riley <ipythonbugs-AT-sabi.net>.
1023 Riley <ipythonbugs-AT-sabi.net>.
1020 (InteractiveShell.mainloop): honor --nobanner with banner
1024 (InteractiveShell.mainloop): honor --nobanner with banner
1021 extensions.
1025 extensions.
1022
1026
1023 * IPython/Shell.py: Significant refactoring of all classes, so
1027 * IPython/Shell.py: Significant refactoring of all classes, so
1024 that we can really support ALL matplotlib backends and threading
1028 that we can really support ALL matplotlib backends and threading
1025 models (John spotted a bug with Tk which required this). Now we
1029 models (John spotted a bug with Tk which required this). Now we
1026 should support single-threaded, WX-threads and GTK-threads, both
1030 should support single-threaded, WX-threads and GTK-threads, both
1027 for generic code and for matplotlib.
1031 for generic code and for matplotlib.
1028
1032
1029 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1033 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1030 -pylab, to simplify things for users. Will also remove the pylab
1034 -pylab, to simplify things for users. Will also remove the pylab
1031 profile, since now all of matplotlib configuration is directly
1035 profile, since now all of matplotlib configuration is directly
1032 handled here. This also reduces startup time.
1036 handled here. This also reduces startup time.
1033
1037
1034 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1038 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1035 shell wasn't being correctly called. Also in IPShellWX.
1039 shell wasn't being correctly called. Also in IPShellWX.
1036
1040
1037 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1041 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1038 fine-tune banner.
1042 fine-tune banner.
1039
1043
1040 * IPython/numutils.py (spike): Deprecate these spike functions,
1044 * IPython/numutils.py (spike): Deprecate these spike functions,
1041 delete (long deprecated) gnuplot_exec handler.
1045 delete (long deprecated) gnuplot_exec handler.
1042
1046
1043 2004-08-26 Fernando Perez <fperez@colorado.edu>
1047 2004-08-26 Fernando Perez <fperez@colorado.edu>
1044
1048
1045 * ipython.1: Update for threading options, plus some others which
1049 * ipython.1: Update for threading options, plus some others which
1046 were missing.
1050 were missing.
1047
1051
1048 * IPython/ipmaker.py (__call__): Added -wthread option for
1052 * IPython/ipmaker.py (__call__): Added -wthread option for
1049 wxpython thread handling. Make sure threading options are only
1053 wxpython thread handling. Make sure threading options are only
1050 valid at the command line.
1054 valid at the command line.
1051
1055
1052 * scripts/ipython: moved shell selection into a factory function
1056 * scripts/ipython: moved shell selection into a factory function
1053 in Shell.py, to keep the starter script to a minimum.
1057 in Shell.py, to keep the starter script to a minimum.
1054
1058
1055 2004-08-25 Fernando Perez <fperez@colorado.edu>
1059 2004-08-25 Fernando Perez <fperez@colorado.edu>
1056
1060
1057 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1061 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1058 John. Along with some recent changes he made to matplotlib, the
1062 John. Along with some recent changes he made to matplotlib, the
1059 next versions of both systems should work very well together.
1063 next versions of both systems should work very well together.
1060
1064
1061 2004-08-24 Fernando Perez <fperez@colorado.edu>
1065 2004-08-24 Fernando Perez <fperez@colorado.edu>
1062
1066
1063 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1067 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1064 tried to switch the profiling to using hotshot, but I'm getting
1068 tried to switch the profiling to using hotshot, but I'm getting
1065 strange errors from prof.runctx() there. I may be misreading the
1069 strange errors from prof.runctx() there. I may be misreading the
1066 docs, but it looks weird. For now the profiling code will
1070 docs, but it looks weird. For now the profiling code will
1067 continue to use the standard profiler.
1071 continue to use the standard profiler.
1068
1072
1069 2004-08-23 Fernando Perez <fperez@colorado.edu>
1073 2004-08-23 Fernando Perez <fperez@colorado.edu>
1070
1074
1071 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1075 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1072 threaded shell, by John Hunter. It's not quite ready yet, but
1076 threaded shell, by John Hunter. It's not quite ready yet, but
1073 close.
1077 close.
1074
1078
1075 2004-08-22 Fernando Perez <fperez@colorado.edu>
1079 2004-08-22 Fernando Perez <fperez@colorado.edu>
1076
1080
1077 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1081 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1078 in Magic and ultraTB.
1082 in Magic and ultraTB.
1079
1083
1080 * ipython.1: document threading options in manpage.
1084 * ipython.1: document threading options in manpage.
1081
1085
1082 * scripts/ipython: Changed name of -thread option to -gthread,
1086 * scripts/ipython: Changed name of -thread option to -gthread,
1083 since this is GTK specific. I want to leave the door open for a
1087 since this is GTK specific. I want to leave the door open for a
1084 -wthread option for WX, which will most likely be necessary. This
1088 -wthread option for WX, which will most likely be necessary. This
1085 change affects usage and ipmaker as well.
1089 change affects usage and ipmaker as well.
1086
1090
1087 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1091 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1088 handle the matplotlib shell issues. Code by John Hunter
1092 handle the matplotlib shell issues. Code by John Hunter
1089 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1093 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1090 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1094 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1091 broken (and disabled for end users) for now, but it puts the
1095 broken (and disabled for end users) for now, but it puts the
1092 infrastructure in place.
1096 infrastructure in place.
1093
1097
1094 2004-08-21 Fernando Perez <fperez@colorado.edu>
1098 2004-08-21 Fernando Perez <fperez@colorado.edu>
1095
1099
1096 * ipythonrc-pylab: Add matplotlib support.
1100 * ipythonrc-pylab: Add matplotlib support.
1097
1101
1098 * matplotlib_config.py: new files for matplotlib support, part of
1102 * matplotlib_config.py: new files for matplotlib support, part of
1099 the pylab profile.
1103 the pylab profile.
1100
1104
1101 * IPython/usage.py (__doc__): documented the threading options.
1105 * IPython/usage.py (__doc__): documented the threading options.
1102
1106
1103 2004-08-20 Fernando Perez <fperez@colorado.edu>
1107 2004-08-20 Fernando Perez <fperez@colorado.edu>
1104
1108
1105 * ipython: Modified the main calling routine to handle the -thread
1109 * ipython: Modified the main calling routine to handle the -thread
1106 and -mpthread options. This needs to be done as a top-level hack,
1110 and -mpthread options. This needs to be done as a top-level hack,
1107 because it determines which class to instantiate for IPython
1111 because it determines which class to instantiate for IPython
1108 itself.
1112 itself.
1109
1113
1110 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1114 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1111 classes to support multithreaded GTK operation without blocking,
1115 classes to support multithreaded GTK operation without blocking,
1112 and matplotlib with all backends. This is a lot of still very
1116 and matplotlib with all backends. This is a lot of still very
1113 experimental code, and threads are tricky. So it may still have a
1117 experimental code, and threads are tricky. So it may still have a
1114 few rough edges... This code owes a lot to
1118 few rough edges... This code owes a lot to
1115 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1119 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1116 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1120 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1117 to John Hunter for all the matplotlib work.
1121 to John Hunter for all the matplotlib work.
1118
1122
1119 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1123 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1120 options for gtk thread and matplotlib support.
1124 options for gtk thread and matplotlib support.
1121
1125
1122 2004-08-16 Fernando Perez <fperez@colorado.edu>
1126 2004-08-16 Fernando Perez <fperez@colorado.edu>
1123
1127
1124 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1128 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1125 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1129 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1126 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1130 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1127
1131
1128 2004-08-11 Fernando Perez <fperez@colorado.edu>
1132 2004-08-11 Fernando Perez <fperez@colorado.edu>
1129
1133
1130 * setup.py (isfile): Fix build so documentation gets updated for
1134 * setup.py (isfile): Fix build so documentation gets updated for
1131 rpms (it was only done for .tgz builds).
1135 rpms (it was only done for .tgz builds).
1132
1136
1133 2004-08-10 Fernando Perez <fperez@colorado.edu>
1137 2004-08-10 Fernando Perez <fperez@colorado.edu>
1134
1138
1135 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1139 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1136
1140
1137 * iplib.py : Silence syntax error exceptions in tab-completion.
1141 * iplib.py : Silence syntax error exceptions in tab-completion.
1138
1142
1139 2004-08-05 Fernando Perez <fperez@colorado.edu>
1143 2004-08-05 Fernando Perez <fperez@colorado.edu>
1140
1144
1141 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1145 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1142 'color off' mark for continuation prompts. This was causing long
1146 'color off' mark for continuation prompts. This was causing long
1143 continuation lines to mis-wrap.
1147 continuation lines to mis-wrap.
1144
1148
1145 2004-08-01 Fernando Perez <fperez@colorado.edu>
1149 2004-08-01 Fernando Perez <fperez@colorado.edu>
1146
1150
1147 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1151 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1148 for building ipython to be a parameter. All this is necessary
1152 for building ipython to be a parameter. All this is necessary
1149 right now to have a multithreaded version, but this insane
1153 right now to have a multithreaded version, but this insane
1150 non-design will be cleaned up soon. For now, it's a hack that
1154 non-design will be cleaned up soon. For now, it's a hack that
1151 works.
1155 works.
1152
1156
1153 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1157 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1154 args in various places. No bugs so far, but it's a dangerous
1158 args in various places. No bugs so far, but it's a dangerous
1155 practice.
1159 practice.
1156
1160
1157 2004-07-31 Fernando Perez <fperez@colorado.edu>
1161 2004-07-31 Fernando Perez <fperez@colorado.edu>
1158
1162
1159 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1163 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1160 fix completion of files with dots in their names under most
1164 fix completion of files with dots in their names under most
1161 profiles (pysh was OK because the completion order is different).
1165 profiles (pysh was OK because the completion order is different).
1162
1166
1163 2004-07-27 Fernando Perez <fperez@colorado.edu>
1167 2004-07-27 Fernando Perez <fperez@colorado.edu>
1164
1168
1165 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1169 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1166 keywords manually, b/c the one in keyword.py was removed in python
1170 keywords manually, b/c the one in keyword.py was removed in python
1167 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1171 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1168 This is NOT a bug under python 2.3 and earlier.
1172 This is NOT a bug under python 2.3 and earlier.
1169
1173
1170 2004-07-26 Fernando Perez <fperez@colorado.edu>
1174 2004-07-26 Fernando Perez <fperez@colorado.edu>
1171
1175
1172 * IPython/ultraTB.py (VerboseTB.text): Add another
1176 * IPython/ultraTB.py (VerboseTB.text): Add another
1173 linecache.checkcache() call to try to prevent inspect.py from
1177 linecache.checkcache() call to try to prevent inspect.py from
1174 crashing under python 2.3. I think this fixes
1178 crashing under python 2.3. I think this fixes
1175 http://www.scipy.net/roundup/ipython/issue17.
1179 http://www.scipy.net/roundup/ipython/issue17.
1176
1180
1177 2004-07-26 *** Released version 0.6.2
1181 2004-07-26 *** Released version 0.6.2
1178
1182
1179 2004-07-26 Fernando Perez <fperez@colorado.edu>
1183 2004-07-26 Fernando Perez <fperez@colorado.edu>
1180
1184
1181 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1185 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1182 fail for any number.
1186 fail for any number.
1183 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1187 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1184 empty bookmarks.
1188 empty bookmarks.
1185
1189
1186 2004-07-26 *** Released version 0.6.1
1190 2004-07-26 *** Released version 0.6.1
1187
1191
1188 2004-07-26 Fernando Perez <fperez@colorado.edu>
1192 2004-07-26 Fernando Perez <fperez@colorado.edu>
1189
1193
1190 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1194 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1191
1195
1192 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1196 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1193 escaping '()[]{}' in filenames.
1197 escaping '()[]{}' in filenames.
1194
1198
1195 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1199 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1196 Python 2.2 users who lack a proper shlex.split.
1200 Python 2.2 users who lack a proper shlex.split.
1197
1201
1198 2004-07-19 Fernando Perez <fperez@colorado.edu>
1202 2004-07-19 Fernando Perez <fperez@colorado.edu>
1199
1203
1200 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1204 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1201 for reading readline's init file. I follow the normal chain:
1205 for reading readline's init file. I follow the normal chain:
1202 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1206 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1203 report by Mike Heeter. This closes
1207 report by Mike Heeter. This closes
1204 http://www.scipy.net/roundup/ipython/issue16.
1208 http://www.scipy.net/roundup/ipython/issue16.
1205
1209
1206 2004-07-18 Fernando Perez <fperez@colorado.edu>
1210 2004-07-18 Fernando Perez <fperez@colorado.edu>
1207
1211
1208 * IPython/iplib.py (__init__): Add better handling of '\' under
1212 * IPython/iplib.py (__init__): Add better handling of '\' under
1209 Win32 for filenames. After a patch by Ville.
1213 Win32 for filenames. After a patch by Ville.
1210
1214
1211 2004-07-17 Fernando Perez <fperez@colorado.edu>
1215 2004-07-17 Fernando Perez <fperez@colorado.edu>
1212
1216
1213 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1217 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1214 autocalling would be triggered for 'foo is bar' if foo is
1218 autocalling would be triggered for 'foo is bar' if foo is
1215 callable. I also cleaned up the autocall detection code to use a
1219 callable. I also cleaned up the autocall detection code to use a
1216 regexp, which is faster. Bug reported by Alexander Schmolck.
1220 regexp, which is faster. Bug reported by Alexander Schmolck.
1217
1221
1218 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1222 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1219 '?' in them would confuse the help system. Reported by Alex
1223 '?' in them would confuse the help system. Reported by Alex
1220 Schmolck.
1224 Schmolck.
1221
1225
1222 2004-07-16 Fernando Perez <fperez@colorado.edu>
1226 2004-07-16 Fernando Perez <fperez@colorado.edu>
1223
1227
1224 * IPython/GnuplotInteractive.py (__all__): added plot2.
1228 * IPython/GnuplotInteractive.py (__all__): added plot2.
1225
1229
1226 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1230 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1227 plotting dictionaries, lists or tuples of 1d arrays.
1231 plotting dictionaries, lists or tuples of 1d arrays.
1228
1232
1229 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1233 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1230 optimizations.
1234 optimizations.
1231
1235
1232 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1236 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1233 the information which was there from Janko's original IPP code:
1237 the information which was there from Janko's original IPP code:
1234
1238
1235 03.05.99 20:53 porto.ifm.uni-kiel.de
1239 03.05.99 20:53 porto.ifm.uni-kiel.de
1236 --Started changelog.
1240 --Started changelog.
1237 --make clear do what it say it does
1241 --make clear do what it say it does
1238 --added pretty output of lines from inputcache
1242 --added pretty output of lines from inputcache
1239 --Made Logger a mixin class, simplifies handling of switches
1243 --Made Logger a mixin class, simplifies handling of switches
1240 --Added own completer class. .string<TAB> expands to last history
1244 --Added own completer class. .string<TAB> expands to last history
1241 line which starts with string. The new expansion is also present
1245 line which starts with string. The new expansion is also present
1242 with Ctrl-r from the readline library. But this shows, who this
1246 with Ctrl-r from the readline library. But this shows, who this
1243 can be done for other cases.
1247 can be done for other cases.
1244 --Added convention that all shell functions should accept a
1248 --Added convention that all shell functions should accept a
1245 parameter_string This opens the door for different behaviour for
1249 parameter_string This opens the door for different behaviour for
1246 each function. @cd is a good example of this.
1250 each function. @cd is a good example of this.
1247
1251
1248 04.05.99 12:12 porto.ifm.uni-kiel.de
1252 04.05.99 12:12 porto.ifm.uni-kiel.de
1249 --added logfile rotation
1253 --added logfile rotation
1250 --added new mainloop method which freezes first the namespace
1254 --added new mainloop method which freezes first the namespace
1251
1255
1252 07.05.99 21:24 porto.ifm.uni-kiel.de
1256 07.05.99 21:24 porto.ifm.uni-kiel.de
1253 --added the docreader classes. Now there is a help system.
1257 --added the docreader classes. Now there is a help system.
1254 -This is only a first try. Currently it's not easy to put new
1258 -This is only a first try. Currently it's not easy to put new
1255 stuff in the indices. But this is the way to go. Info would be
1259 stuff in the indices. But this is the way to go. Info would be
1256 better, but HTML is every where and not everybody has an info
1260 better, but HTML is every where and not everybody has an info
1257 system installed and it's not so easy to change html-docs to info.
1261 system installed and it's not so easy to change html-docs to info.
1258 --added global logfile option
1262 --added global logfile option
1259 --there is now a hook for object inspection method pinfo needs to
1263 --there is now a hook for object inspection method pinfo needs to
1260 be provided for this. Can be reached by two '??'.
1264 be provided for this. Can be reached by two '??'.
1261
1265
1262 08.05.99 20:51 porto.ifm.uni-kiel.de
1266 08.05.99 20:51 porto.ifm.uni-kiel.de
1263 --added a README
1267 --added a README
1264 --bug in rc file. Something has changed so functions in the rc
1268 --bug in rc file. Something has changed so functions in the rc
1265 file need to reference the shell and not self. Not clear if it's a
1269 file need to reference the shell and not self. Not clear if it's a
1266 bug or feature.
1270 bug or feature.
1267 --changed rc file for new behavior
1271 --changed rc file for new behavior
1268
1272
1269 2004-07-15 Fernando Perez <fperez@colorado.edu>
1273 2004-07-15 Fernando Perez <fperez@colorado.edu>
1270
1274
1271 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1275 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1272 cache was falling out of sync in bizarre manners when multi-line
1276 cache was falling out of sync in bizarre manners when multi-line
1273 input was present. Minor optimizations and cleanup.
1277 input was present. Minor optimizations and cleanup.
1274
1278
1275 (Logger): Remove old Changelog info for cleanup. This is the
1279 (Logger): Remove old Changelog info for cleanup. This is the
1276 information which was there from Janko's original code:
1280 information which was there from Janko's original code:
1277
1281
1278 Changes to Logger: - made the default log filename a parameter
1282 Changes to Logger: - made the default log filename a parameter
1279
1283
1280 - put a check for lines beginning with !@? in log(). Needed
1284 - put a check for lines beginning with !@? in log(). Needed
1281 (even if the handlers properly log their lines) for mid-session
1285 (even if the handlers properly log their lines) for mid-session
1282 logging activation to work properly. Without this, lines logged
1286 logging activation to work properly. Without this, lines logged
1283 in mid session, which get read from the cache, would end up
1287 in mid session, which get read from the cache, would end up
1284 'bare' (with !@? in the open) in the log. Now they are caught
1288 'bare' (with !@? in the open) in the log. Now they are caught
1285 and prepended with a #.
1289 and prepended with a #.
1286
1290
1287 * IPython/iplib.py (InteractiveShell.init_readline): added check
1291 * IPython/iplib.py (InteractiveShell.init_readline): added check
1288 in case MagicCompleter fails to be defined, so we don't crash.
1292 in case MagicCompleter fails to be defined, so we don't crash.
1289
1293
1290 2004-07-13 Fernando Perez <fperez@colorado.edu>
1294 2004-07-13 Fernando Perez <fperez@colorado.edu>
1291
1295
1292 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1296 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1293 of EPS if the requested filename ends in '.eps'.
1297 of EPS if the requested filename ends in '.eps'.
1294
1298
1295 2004-07-04 Fernando Perez <fperez@colorado.edu>
1299 2004-07-04 Fernando Perez <fperez@colorado.edu>
1296
1300
1297 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1301 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1298 escaping of quotes when calling the shell.
1302 escaping of quotes when calling the shell.
1299
1303
1300 2004-07-02 Fernando Perez <fperez@colorado.edu>
1304 2004-07-02 Fernando Perez <fperez@colorado.edu>
1301
1305
1302 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1306 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1303 gettext not working because we were clobbering '_'. Fixes
1307 gettext not working because we were clobbering '_'. Fixes
1304 http://www.scipy.net/roundup/ipython/issue6.
1308 http://www.scipy.net/roundup/ipython/issue6.
1305
1309
1306 2004-07-01 Fernando Perez <fperez@colorado.edu>
1310 2004-07-01 Fernando Perez <fperez@colorado.edu>
1307
1311
1308 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1312 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1309 into @cd. Patch by Ville.
1313 into @cd. Patch by Ville.
1310
1314
1311 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1315 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1312 new function to store things after ipmaker runs. Patch by Ville.
1316 new function to store things after ipmaker runs. Patch by Ville.
1313 Eventually this will go away once ipmaker is removed and the class
1317 Eventually this will go away once ipmaker is removed and the class
1314 gets cleaned up, but for now it's ok. Key functionality here is
1318 gets cleaned up, but for now it's ok. Key functionality here is
1315 the addition of the persistent storage mechanism, a dict for
1319 the addition of the persistent storage mechanism, a dict for
1316 keeping data across sessions (for now just bookmarks, but more can
1320 keeping data across sessions (for now just bookmarks, but more can
1317 be implemented later).
1321 be implemented later).
1318
1322
1319 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1323 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1320 persistent across sections. Patch by Ville, I modified it
1324 persistent across sections. Patch by Ville, I modified it
1321 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1325 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1322 added a '-l' option to list all bookmarks.
1326 added a '-l' option to list all bookmarks.
1323
1327
1324 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1328 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1325 center for cleanup. Registered with atexit.register(). I moved
1329 center for cleanup. Registered with atexit.register(). I moved
1326 here the old exit_cleanup(). After a patch by Ville.
1330 here the old exit_cleanup(). After a patch by Ville.
1327
1331
1328 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1332 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1329 characters in the hacked shlex_split for python 2.2.
1333 characters in the hacked shlex_split for python 2.2.
1330
1334
1331 * IPython/iplib.py (file_matches): more fixes to filenames with
1335 * IPython/iplib.py (file_matches): more fixes to filenames with
1332 whitespace in them. It's not perfect, but limitations in python's
1336 whitespace in them. It's not perfect, but limitations in python's
1333 readline make it impossible to go further.
1337 readline make it impossible to go further.
1334
1338
1335 2004-06-29 Fernando Perez <fperez@colorado.edu>
1339 2004-06-29 Fernando Perez <fperez@colorado.edu>
1336
1340
1337 * IPython/iplib.py (file_matches): escape whitespace correctly in
1341 * IPython/iplib.py (file_matches): escape whitespace correctly in
1338 filename completions. Bug reported by Ville.
1342 filename completions. Bug reported by Ville.
1339
1343
1340 2004-06-28 Fernando Perez <fperez@colorado.edu>
1344 2004-06-28 Fernando Perez <fperez@colorado.edu>
1341
1345
1342 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1346 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1343 the history file will be called 'history-PROFNAME' (or just
1347 the history file will be called 'history-PROFNAME' (or just
1344 'history' if no profile is loaded). I was getting annoyed at
1348 'history' if no profile is loaded). I was getting annoyed at
1345 getting my Numerical work history clobbered by pysh sessions.
1349 getting my Numerical work history clobbered by pysh sessions.
1346
1350
1347 * IPython/iplib.py (InteractiveShell.__init__): Internal
1351 * IPython/iplib.py (InteractiveShell.__init__): Internal
1348 getoutputerror() function so that we can honor the system_verbose
1352 getoutputerror() function so that we can honor the system_verbose
1349 flag for _all_ system calls. I also added escaping of #
1353 flag for _all_ system calls. I also added escaping of #
1350 characters here to avoid confusing Itpl.
1354 characters here to avoid confusing Itpl.
1351
1355
1352 * IPython/Magic.py (shlex_split): removed call to shell in
1356 * IPython/Magic.py (shlex_split): removed call to shell in
1353 parse_options and replaced it with shlex.split(). The annoying
1357 parse_options and replaced it with shlex.split(). The annoying
1354 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1358 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1355 to backport it from 2.3, with several frail hacks (the shlex
1359 to backport it from 2.3, with several frail hacks (the shlex
1356 module is rather limited in 2.2). Thanks to a suggestion by Ville
1360 module is rather limited in 2.2). Thanks to a suggestion by Ville
1357 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1361 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1358 problem.
1362 problem.
1359
1363
1360 (Magic.magic_system_verbose): new toggle to print the actual
1364 (Magic.magic_system_verbose): new toggle to print the actual
1361 system calls made by ipython. Mainly for debugging purposes.
1365 system calls made by ipython. Mainly for debugging purposes.
1362
1366
1363 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1367 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1364 doesn't support persistence. Reported (and fix suggested) by
1368 doesn't support persistence. Reported (and fix suggested) by
1365 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1369 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1366
1370
1367 2004-06-26 Fernando Perez <fperez@colorado.edu>
1371 2004-06-26 Fernando Perez <fperez@colorado.edu>
1368
1372
1369 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1373 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1370 continue prompts.
1374 continue prompts.
1371
1375
1372 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1376 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1373 function (basically a big docstring) and a few more things here to
1377 function (basically a big docstring) and a few more things here to
1374 speedup startup. pysh.py is now very lightweight. We want because
1378 speedup startup. pysh.py is now very lightweight. We want because
1375 it gets execfile'd, while InterpreterExec gets imported, so
1379 it gets execfile'd, while InterpreterExec gets imported, so
1376 byte-compilation saves time.
1380 byte-compilation saves time.
1377
1381
1378 2004-06-25 Fernando Perez <fperez@colorado.edu>
1382 2004-06-25 Fernando Perez <fperez@colorado.edu>
1379
1383
1380 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1384 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1381 -NUM', which was recently broken.
1385 -NUM', which was recently broken.
1382
1386
1383 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1387 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1384 in multi-line input (but not !!, which doesn't make sense there).
1388 in multi-line input (but not !!, which doesn't make sense there).
1385
1389
1386 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1390 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1387 It's just too useful, and people can turn it off in the less
1391 It's just too useful, and people can turn it off in the less
1388 common cases where it's a problem.
1392 common cases where it's a problem.
1389
1393
1390 2004-06-24 Fernando Perez <fperez@colorado.edu>
1394 2004-06-24 Fernando Perez <fperez@colorado.edu>
1391
1395
1392 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1396 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1393 special syntaxes (like alias calling) is now allied in multi-line
1397 special syntaxes (like alias calling) is now allied in multi-line
1394 input. This is still _very_ experimental, but it's necessary for
1398 input. This is still _very_ experimental, but it's necessary for
1395 efficient shell usage combining python looping syntax with system
1399 efficient shell usage combining python looping syntax with system
1396 calls. For now it's restricted to aliases, I don't think it
1400 calls. For now it's restricted to aliases, I don't think it
1397 really even makes sense to have this for magics.
1401 really even makes sense to have this for magics.
1398
1402
1399 2004-06-23 Fernando Perez <fperez@colorado.edu>
1403 2004-06-23 Fernando Perez <fperez@colorado.edu>
1400
1404
1401 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1405 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1402 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1406 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1403
1407
1404 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1408 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1405 extensions under Windows (after code sent by Gary Bishop). The
1409 extensions under Windows (after code sent by Gary Bishop). The
1406 extensions considered 'executable' are stored in IPython's rc
1410 extensions considered 'executable' are stored in IPython's rc
1407 structure as win_exec_ext.
1411 structure as win_exec_ext.
1408
1412
1409 * IPython/genutils.py (shell): new function, like system() but
1413 * IPython/genutils.py (shell): new function, like system() but
1410 without return value. Very useful for interactive shell work.
1414 without return value. Very useful for interactive shell work.
1411
1415
1412 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1416 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1413 delete aliases.
1417 delete aliases.
1414
1418
1415 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1419 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1416 sure that the alias table doesn't contain python keywords.
1420 sure that the alias table doesn't contain python keywords.
1417
1421
1418 2004-06-21 Fernando Perez <fperez@colorado.edu>
1422 2004-06-21 Fernando Perez <fperez@colorado.edu>
1419
1423
1420 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1424 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1421 non-existent items are found in $PATH. Reported by Thorsten.
1425 non-existent items are found in $PATH. Reported by Thorsten.
1422
1426
1423 2004-06-20 Fernando Perez <fperez@colorado.edu>
1427 2004-06-20 Fernando Perez <fperez@colorado.edu>
1424
1428
1425 * IPython/iplib.py (complete): modified the completer so that the
1429 * IPython/iplib.py (complete): modified the completer so that the
1426 order of priorities can be easily changed at runtime.
1430 order of priorities can be easily changed at runtime.
1427
1431
1428 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1432 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1429 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1433 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1430
1434
1431 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1435 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1432 expand Python variables prepended with $ in all system calls. The
1436 expand Python variables prepended with $ in all system calls. The
1433 same was done to InteractiveShell.handle_shell_escape. Now all
1437 same was done to InteractiveShell.handle_shell_escape. Now all
1434 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1438 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1435 expansion of python variables and expressions according to the
1439 expansion of python variables and expressions according to the
1436 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1440 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1437
1441
1438 Though PEP-215 has been rejected, a similar (but simpler) one
1442 Though PEP-215 has been rejected, a similar (but simpler) one
1439 seems like it will go into Python 2.4, PEP-292 -
1443 seems like it will go into Python 2.4, PEP-292 -
1440 http://www.python.org/peps/pep-0292.html.
1444 http://www.python.org/peps/pep-0292.html.
1441
1445
1442 I'll keep the full syntax of PEP-215, since IPython has since the
1446 I'll keep the full syntax of PEP-215, since IPython has since the
1443 start used Ka-Ping Yee's reference implementation discussed there
1447 start used Ka-Ping Yee's reference implementation discussed there
1444 (Itpl), and I actually like the powerful semantics it offers.
1448 (Itpl), and I actually like the powerful semantics it offers.
1445
1449
1446 In order to access normal shell variables, the $ has to be escaped
1450 In order to access normal shell variables, the $ has to be escaped
1447 via an extra $. For example:
1451 via an extra $. For example:
1448
1452
1449 In [7]: PATH='a python variable'
1453 In [7]: PATH='a python variable'
1450
1454
1451 In [8]: !echo $PATH
1455 In [8]: !echo $PATH
1452 a python variable
1456 a python variable
1453
1457
1454 In [9]: !echo $$PATH
1458 In [9]: !echo $$PATH
1455 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1459 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1456
1460
1457 (Magic.parse_options): escape $ so the shell doesn't evaluate
1461 (Magic.parse_options): escape $ so the shell doesn't evaluate
1458 things prematurely.
1462 things prematurely.
1459
1463
1460 * IPython/iplib.py (InteractiveShell.call_alias): added the
1464 * IPython/iplib.py (InteractiveShell.call_alias): added the
1461 ability for aliases to expand python variables via $.
1465 ability for aliases to expand python variables via $.
1462
1466
1463 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1467 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1464 system, now there's a @rehash/@rehashx pair of magics. These work
1468 system, now there's a @rehash/@rehashx pair of magics. These work
1465 like the csh rehash command, and can be invoked at any time. They
1469 like the csh rehash command, and can be invoked at any time. They
1466 build a table of aliases to everything in the user's $PATH
1470 build a table of aliases to everything in the user's $PATH
1467 (@rehash uses everything, @rehashx is slower but only adds
1471 (@rehash uses everything, @rehashx is slower but only adds
1468 executable files). With this, the pysh.py-based shell profile can
1472 executable files). With this, the pysh.py-based shell profile can
1469 now simply call rehash upon startup, and full access to all
1473 now simply call rehash upon startup, and full access to all
1470 programs in the user's path is obtained.
1474 programs in the user's path is obtained.
1471
1475
1472 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1476 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1473 functionality is now fully in place. I removed the old dynamic
1477 functionality is now fully in place. I removed the old dynamic
1474 code generation based approach, in favor of a much lighter one
1478 code generation based approach, in favor of a much lighter one
1475 based on a simple dict. The advantage is that this allows me to
1479 based on a simple dict. The advantage is that this allows me to
1476 now have thousands of aliases with negligible cost (unthinkable
1480 now have thousands of aliases with negligible cost (unthinkable
1477 with the old system).
1481 with the old system).
1478
1482
1479 2004-06-19 Fernando Perez <fperez@colorado.edu>
1483 2004-06-19 Fernando Perez <fperez@colorado.edu>
1480
1484
1481 * IPython/iplib.py (__init__): extended MagicCompleter class to
1485 * IPython/iplib.py (__init__): extended MagicCompleter class to
1482 also complete (last in priority) on user aliases.
1486 also complete (last in priority) on user aliases.
1483
1487
1484 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1488 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1485 call to eval.
1489 call to eval.
1486 (ItplNS.__init__): Added a new class which functions like Itpl,
1490 (ItplNS.__init__): Added a new class which functions like Itpl,
1487 but allows configuring the namespace for the evaluation to occur
1491 but allows configuring the namespace for the evaluation to occur
1488 in.
1492 in.
1489
1493
1490 2004-06-18 Fernando Perez <fperez@colorado.edu>
1494 2004-06-18 Fernando Perez <fperez@colorado.edu>
1491
1495
1492 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1496 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1493 better message when 'exit' or 'quit' are typed (a common newbie
1497 better message when 'exit' or 'quit' are typed (a common newbie
1494 confusion).
1498 confusion).
1495
1499
1496 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1500 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1497 check for Windows users.
1501 check for Windows users.
1498
1502
1499 * IPython/iplib.py (InteractiveShell.user_setup): removed
1503 * IPython/iplib.py (InteractiveShell.user_setup): removed
1500 disabling of colors for Windows. I'll test at runtime and issue a
1504 disabling of colors for Windows. I'll test at runtime and issue a
1501 warning if Gary's readline isn't found, as to nudge users to
1505 warning if Gary's readline isn't found, as to nudge users to
1502 download it.
1506 download it.
1503
1507
1504 2004-06-16 Fernando Perez <fperez@colorado.edu>
1508 2004-06-16 Fernando Perez <fperez@colorado.edu>
1505
1509
1506 * IPython/genutils.py (Stream.__init__): changed to print errors
1510 * IPython/genutils.py (Stream.__init__): changed to print errors
1507 to sys.stderr. I had a circular dependency here. Now it's
1511 to sys.stderr. I had a circular dependency here. Now it's
1508 possible to run ipython as IDLE's shell (consider this pre-alpha,
1512 possible to run ipython as IDLE's shell (consider this pre-alpha,
1509 since true stdout things end up in the starting terminal instead
1513 since true stdout things end up in the starting terminal instead
1510 of IDLE's out).
1514 of IDLE's out).
1511
1515
1512 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1516 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1513 users who haven't # updated their prompt_in2 definitions. Remove
1517 users who haven't # updated their prompt_in2 definitions. Remove
1514 eventually.
1518 eventually.
1515 (multiple_replace): added credit to original ASPN recipe.
1519 (multiple_replace): added credit to original ASPN recipe.
1516
1520
1517 2004-06-15 Fernando Perez <fperez@colorado.edu>
1521 2004-06-15 Fernando Perez <fperez@colorado.edu>
1518
1522
1519 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1523 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1520 list of auto-defined aliases.
1524 list of auto-defined aliases.
1521
1525
1522 2004-06-13 Fernando Perez <fperez@colorado.edu>
1526 2004-06-13 Fernando Perez <fperez@colorado.edu>
1523
1527
1524 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1528 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1525 install was really requested (so setup.py can be used for other
1529 install was really requested (so setup.py can be used for other
1526 things under Windows).
1530 things under Windows).
1527
1531
1528 2004-06-10 Fernando Perez <fperez@colorado.edu>
1532 2004-06-10 Fernando Perez <fperez@colorado.edu>
1529
1533
1530 * IPython/Logger.py (Logger.create_log): Manually remove any old
1534 * IPython/Logger.py (Logger.create_log): Manually remove any old
1531 backup, since os.remove may fail under Windows. Fixes bug
1535 backup, since os.remove may fail under Windows. Fixes bug
1532 reported by Thorsten.
1536 reported by Thorsten.
1533
1537
1534 2004-06-09 Fernando Perez <fperez@colorado.edu>
1538 2004-06-09 Fernando Perez <fperez@colorado.edu>
1535
1539
1536 * examples/example-embed.py: fixed all references to %n (replaced
1540 * examples/example-embed.py: fixed all references to %n (replaced
1537 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1541 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1538 for all examples and the manual as well.
1542 for all examples and the manual as well.
1539
1543
1540 2004-06-08 Fernando Perez <fperez@colorado.edu>
1544 2004-06-08 Fernando Perez <fperez@colorado.edu>
1541
1545
1542 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1546 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1543 alignment and color management. All 3 prompt subsystems now
1547 alignment and color management. All 3 prompt subsystems now
1544 inherit from BasePrompt.
1548 inherit from BasePrompt.
1545
1549
1546 * tools/release: updates for windows installer build and tag rpms
1550 * tools/release: updates for windows installer build and tag rpms
1547 with python version (since paths are fixed).
1551 with python version (since paths are fixed).
1548
1552
1549 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1553 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1550 which will become eventually obsolete. Also fixed the default
1554 which will become eventually obsolete. Also fixed the default
1551 prompt_in2 to use \D, so at least new users start with the correct
1555 prompt_in2 to use \D, so at least new users start with the correct
1552 defaults.
1556 defaults.
1553 WARNING: Users with existing ipythonrc files will need to apply
1557 WARNING: Users with existing ipythonrc files will need to apply
1554 this fix manually!
1558 this fix manually!
1555
1559
1556 * setup.py: make windows installer (.exe). This is finally the
1560 * setup.py: make windows installer (.exe). This is finally the
1557 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1561 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1558 which I hadn't included because it required Python 2.3 (or recent
1562 which I hadn't included because it required Python 2.3 (or recent
1559 distutils).
1563 distutils).
1560
1564
1561 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1565 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1562 usage of new '\D' escape.
1566 usage of new '\D' escape.
1563
1567
1564 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1568 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1565 lacks os.getuid())
1569 lacks os.getuid())
1566 (CachedOutput.set_colors): Added the ability to turn coloring
1570 (CachedOutput.set_colors): Added the ability to turn coloring
1567 on/off with @colors even for manually defined prompt colors. It
1571 on/off with @colors even for manually defined prompt colors. It
1568 uses a nasty global, but it works safely and via the generic color
1572 uses a nasty global, but it works safely and via the generic color
1569 handling mechanism.
1573 handling mechanism.
1570 (Prompt2.__init__): Introduced new escape '\D' for continuation
1574 (Prompt2.__init__): Introduced new escape '\D' for continuation
1571 prompts. It represents the counter ('\#') as dots.
1575 prompts. It represents the counter ('\#') as dots.
1572 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1576 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1573 need to update their ipythonrc files and replace '%n' with '\D' in
1577 need to update their ipythonrc files and replace '%n' with '\D' in
1574 their prompt_in2 settings everywhere. Sorry, but there's
1578 their prompt_in2 settings everywhere. Sorry, but there's
1575 otherwise no clean way to get all prompts to properly align. The
1579 otherwise no clean way to get all prompts to properly align. The
1576 ipythonrc shipped with IPython has been updated.
1580 ipythonrc shipped with IPython has been updated.
1577
1581
1578 2004-06-07 Fernando Perez <fperez@colorado.edu>
1582 2004-06-07 Fernando Perez <fperez@colorado.edu>
1579
1583
1580 * setup.py (isfile): Pass local_icons option to latex2html, so the
1584 * setup.py (isfile): Pass local_icons option to latex2html, so the
1581 resulting HTML file is self-contained. Thanks to
1585 resulting HTML file is self-contained. Thanks to
1582 dryice-AT-liu.com.cn for the tip.
1586 dryice-AT-liu.com.cn for the tip.
1583
1587
1584 * pysh.py: I created a new profile 'shell', which implements a
1588 * pysh.py: I created a new profile 'shell', which implements a
1585 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1589 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1586 system shell, nor will it become one anytime soon. It's mainly
1590 system shell, nor will it become one anytime soon. It's mainly
1587 meant to illustrate the use of the new flexible bash-like prompts.
1591 meant to illustrate the use of the new flexible bash-like prompts.
1588 I guess it could be used by hardy souls for true shell management,
1592 I guess it could be used by hardy souls for true shell management,
1589 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1593 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1590 profile. This uses the InterpreterExec extension provided by
1594 profile. This uses the InterpreterExec extension provided by
1591 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1595 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1592
1596
1593 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1597 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1594 auto-align itself with the length of the previous input prompt
1598 auto-align itself with the length of the previous input prompt
1595 (taking into account the invisible color escapes).
1599 (taking into account the invisible color escapes).
1596 (CachedOutput.__init__): Large restructuring of this class. Now
1600 (CachedOutput.__init__): Large restructuring of this class. Now
1597 all three prompts (primary1, primary2, output) are proper objects,
1601 all three prompts (primary1, primary2, output) are proper objects,
1598 managed by the 'parent' CachedOutput class. The code is still a
1602 managed by the 'parent' CachedOutput class. The code is still a
1599 bit hackish (all prompts share state via a pointer to the cache),
1603 bit hackish (all prompts share state via a pointer to the cache),
1600 but it's overall far cleaner than before.
1604 but it's overall far cleaner than before.
1601
1605
1602 * IPython/genutils.py (getoutputerror): modified to add verbose,
1606 * IPython/genutils.py (getoutputerror): modified to add verbose,
1603 debug and header options. This makes the interface of all getout*
1607 debug and header options. This makes the interface of all getout*
1604 functions uniform.
1608 functions uniform.
1605 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1609 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1606
1610
1607 * IPython/Magic.py (Magic.default_option): added a function to
1611 * IPython/Magic.py (Magic.default_option): added a function to
1608 allow registering default options for any magic command. This
1612 allow registering default options for any magic command. This
1609 makes it easy to have profiles which customize the magics globally
1613 makes it easy to have profiles which customize the magics globally
1610 for a certain use. The values set through this function are
1614 for a certain use. The values set through this function are
1611 picked up by the parse_options() method, which all magics should
1615 picked up by the parse_options() method, which all magics should
1612 use to parse their options.
1616 use to parse their options.
1613
1617
1614 * IPython/genutils.py (warn): modified the warnings framework to
1618 * IPython/genutils.py (warn): modified the warnings framework to
1615 use the Term I/O class. I'm trying to slowly unify all of
1619 use the Term I/O class. I'm trying to slowly unify all of
1616 IPython's I/O operations to pass through Term.
1620 IPython's I/O operations to pass through Term.
1617
1621
1618 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1622 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1619 the secondary prompt to correctly match the length of the primary
1623 the secondary prompt to correctly match the length of the primary
1620 one for any prompt. Now multi-line code will properly line up
1624 one for any prompt. Now multi-line code will properly line up
1621 even for path dependent prompts, such as the new ones available
1625 even for path dependent prompts, such as the new ones available
1622 via the prompt_specials.
1626 via the prompt_specials.
1623
1627
1624 2004-06-06 Fernando Perez <fperez@colorado.edu>
1628 2004-06-06 Fernando Perez <fperez@colorado.edu>
1625
1629
1626 * IPython/Prompts.py (prompt_specials): Added the ability to have
1630 * IPython/Prompts.py (prompt_specials): Added the ability to have
1627 bash-like special sequences in the prompts, which get
1631 bash-like special sequences in the prompts, which get
1628 automatically expanded. Things like hostname, current working
1632 automatically expanded. Things like hostname, current working
1629 directory and username are implemented already, but it's easy to
1633 directory and username are implemented already, but it's easy to
1630 add more in the future. Thanks to a patch by W.J. van der Laan
1634 add more in the future. Thanks to a patch by W.J. van der Laan
1631 <gnufnork-AT-hetdigitalegat.nl>
1635 <gnufnork-AT-hetdigitalegat.nl>
1632 (prompt_specials): Added color support for prompt strings, so
1636 (prompt_specials): Added color support for prompt strings, so
1633 users can define arbitrary color setups for their prompts.
1637 users can define arbitrary color setups for their prompts.
1634
1638
1635 2004-06-05 Fernando Perez <fperez@colorado.edu>
1639 2004-06-05 Fernando Perez <fperez@colorado.edu>
1636
1640
1637 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1641 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1638 code to load Gary Bishop's readline and configure it
1642 code to load Gary Bishop's readline and configure it
1639 automatically. Thanks to Gary for help on this.
1643 automatically. Thanks to Gary for help on this.
1640
1644
1641 2004-06-01 Fernando Perez <fperez@colorado.edu>
1645 2004-06-01 Fernando Perez <fperez@colorado.edu>
1642
1646
1643 * IPython/Logger.py (Logger.create_log): fix bug for logging
1647 * IPython/Logger.py (Logger.create_log): fix bug for logging
1644 with no filename (previous fix was incomplete).
1648 with no filename (previous fix was incomplete).
1645
1649
1646 2004-05-25 Fernando Perez <fperez@colorado.edu>
1650 2004-05-25 Fernando Perez <fperez@colorado.edu>
1647
1651
1648 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1652 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1649 parens would get passed to the shell.
1653 parens would get passed to the shell.
1650
1654
1651 2004-05-20 Fernando Perez <fperez@colorado.edu>
1655 2004-05-20 Fernando Perez <fperez@colorado.edu>
1652
1656
1653 * IPython/Magic.py (Magic.magic_prun): changed default profile
1657 * IPython/Magic.py (Magic.magic_prun): changed default profile
1654 sort order to 'time' (the more common profiling need).
1658 sort order to 'time' (the more common profiling need).
1655
1659
1656 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1660 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1657 so that source code shown is guaranteed in sync with the file on
1661 so that source code shown is guaranteed in sync with the file on
1658 disk (also changed in psource). Similar fix to the one for
1662 disk (also changed in psource). Similar fix to the one for
1659 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
1663 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
1660 <yann.ledu-AT-noos.fr>.
1664 <yann.ledu-AT-noos.fr>.
1661
1665
1662 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
1666 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
1663 with a single option would not be correctly parsed. Closes
1667 with a single option would not be correctly parsed. Closes
1664 http://www.scipy.net/roundup/ipython/issue14. This bug had been
1668 http://www.scipy.net/roundup/ipython/issue14. This bug had been
1665 introduced in 0.6.0 (on 2004-05-06).
1669 introduced in 0.6.0 (on 2004-05-06).
1666
1670
1667 2004-05-13 *** Released version 0.6.0
1671 2004-05-13 *** Released version 0.6.0
1668
1672
1669 2004-05-13 Fernando Perez <fperez@colorado.edu>
1673 2004-05-13 Fernando Perez <fperez@colorado.edu>
1670
1674
1671 * debian/: Added debian/ directory to CVS, so that debian support
1675 * debian/: Added debian/ directory to CVS, so that debian support
1672 is publicly accessible. The debian package is maintained by Jack
1676 is publicly accessible. The debian package is maintained by Jack
1673 Moffit <jack-AT-xiph.org>.
1677 Moffit <jack-AT-xiph.org>.
1674
1678
1675 * Documentation: included the notes about an ipython-based system
1679 * Documentation: included the notes about an ipython-based system
1676 shell (the hypothetical 'pysh') into the new_design.pdf document,
1680 shell (the hypothetical 'pysh') into the new_design.pdf document,
1677 so that these ideas get distributed to users along with the
1681 so that these ideas get distributed to users along with the
1678 official documentation.
1682 official documentation.
1679
1683
1680 2004-05-10 Fernando Perez <fperez@colorado.edu>
1684 2004-05-10 Fernando Perez <fperez@colorado.edu>
1681
1685
1682 * IPython/Logger.py (Logger.create_log): fix recently introduced
1686 * IPython/Logger.py (Logger.create_log): fix recently introduced
1683 bug (misindented line) where logstart would fail when not given an
1687 bug (misindented line) where logstart would fail when not given an
1684 explicit filename.
1688 explicit filename.
1685
1689
1686 2004-05-09 Fernando Perez <fperez@colorado.edu>
1690 2004-05-09 Fernando Perez <fperez@colorado.edu>
1687
1691
1688 * IPython/Magic.py (Magic.parse_options): skip system call when
1692 * IPython/Magic.py (Magic.parse_options): skip system call when
1689 there are no options to look for. Faster, cleaner for the common
1693 there are no options to look for. Faster, cleaner for the common
1690 case.
1694 case.
1691
1695
1692 * Documentation: many updates to the manual: describing Windows
1696 * Documentation: many updates to the manual: describing Windows
1693 support better, Gnuplot updates, credits, misc small stuff. Also
1697 support better, Gnuplot updates, credits, misc small stuff. Also
1694 updated the new_design doc a bit.
1698 updated the new_design doc a bit.
1695
1699
1696 2004-05-06 *** Released version 0.6.0.rc1
1700 2004-05-06 *** Released version 0.6.0.rc1
1697
1701
1698 2004-05-06 Fernando Perez <fperez@colorado.edu>
1702 2004-05-06 Fernando Perez <fperez@colorado.edu>
1699
1703
1700 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
1704 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
1701 operations to use the vastly more efficient list/''.join() method.
1705 operations to use the vastly more efficient list/''.join() method.
1702 (FormattedTB.text): Fix
1706 (FormattedTB.text): Fix
1703 http://www.scipy.net/roundup/ipython/issue12 - exception source
1707 http://www.scipy.net/roundup/ipython/issue12 - exception source
1704 extract not updated after reload. Thanks to Mike Salib
1708 extract not updated after reload. Thanks to Mike Salib
1705 <msalib-AT-mit.edu> for pinning the source of the problem.
1709 <msalib-AT-mit.edu> for pinning the source of the problem.
1706 Fortunately, the solution works inside ipython and doesn't require
1710 Fortunately, the solution works inside ipython and doesn't require
1707 any changes to python proper.
1711 any changes to python proper.
1708
1712
1709 * IPython/Magic.py (Magic.parse_options): Improved to process the
1713 * IPython/Magic.py (Magic.parse_options): Improved to process the
1710 argument list as a true shell would (by actually using the
1714 argument list as a true shell would (by actually using the
1711 underlying system shell). This way, all @magics automatically get
1715 underlying system shell). This way, all @magics automatically get
1712 shell expansion for variables. Thanks to a comment by Alex
1716 shell expansion for variables. Thanks to a comment by Alex
1713 Schmolck.
1717 Schmolck.
1714
1718
1715 2004-04-04 Fernando Perez <fperez@colorado.edu>
1719 2004-04-04 Fernando Perez <fperez@colorado.edu>
1716
1720
1717 * IPython/iplib.py (InteractiveShell.interact): Added a special
1721 * IPython/iplib.py (InteractiveShell.interact): Added a special
1718 trap for a debugger quit exception, which is basically impossible
1722 trap for a debugger quit exception, which is basically impossible
1719 to handle by normal mechanisms, given what pdb does to the stack.
1723 to handle by normal mechanisms, given what pdb does to the stack.
1720 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
1724 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
1721
1725
1722 2004-04-03 Fernando Perez <fperez@colorado.edu>
1726 2004-04-03 Fernando Perez <fperez@colorado.edu>
1723
1727
1724 * IPython/genutils.py (Term): Standardized the names of the Term
1728 * IPython/genutils.py (Term): Standardized the names of the Term
1725 class streams to cin/cout/cerr, following C++ naming conventions
1729 class streams to cin/cout/cerr, following C++ naming conventions
1726 (I can't use in/out/err because 'in' is not a valid attribute
1730 (I can't use in/out/err because 'in' is not a valid attribute
1727 name).
1731 name).
1728
1732
1729 * IPython/iplib.py (InteractiveShell.interact): don't increment
1733 * IPython/iplib.py (InteractiveShell.interact): don't increment
1730 the prompt if there's no user input. By Daniel 'Dang' Griffith
1734 the prompt if there's no user input. By Daniel 'Dang' Griffith
1731 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
1735 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
1732 Francois Pinard.
1736 Francois Pinard.
1733
1737
1734 2004-04-02 Fernando Perez <fperez@colorado.edu>
1738 2004-04-02 Fernando Perez <fperez@colorado.edu>
1735
1739
1736 * IPython/genutils.py (Stream.__init__): Modified to survive at
1740 * IPython/genutils.py (Stream.__init__): Modified to survive at
1737 least importing in contexts where stdin/out/err aren't true file
1741 least importing in contexts where stdin/out/err aren't true file
1738 objects, such as PyCrust (they lack fileno() and mode). However,
1742 objects, such as PyCrust (they lack fileno() and mode). However,
1739 the recovery facilities which rely on these things existing will
1743 the recovery facilities which rely on these things existing will
1740 not work.
1744 not work.
1741
1745
1742 2004-04-01 Fernando Perez <fperez@colorado.edu>
1746 2004-04-01 Fernando Perez <fperez@colorado.edu>
1743
1747
1744 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
1748 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
1745 use the new getoutputerror() function, so it properly
1749 use the new getoutputerror() function, so it properly
1746 distinguishes stdout/err.
1750 distinguishes stdout/err.
1747
1751
1748 * IPython/genutils.py (getoutputerror): added a function to
1752 * IPython/genutils.py (getoutputerror): added a function to
1749 capture separately the standard output and error of a command.
1753 capture separately the standard output and error of a command.
1750 After a comment from dang on the mailing lists. This code is
1754 After a comment from dang on the mailing lists. This code is
1751 basically a modified version of commands.getstatusoutput(), from
1755 basically a modified version of commands.getstatusoutput(), from
1752 the standard library.
1756 the standard library.
1753
1757
1754 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
1758 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
1755 '!!' as a special syntax (shorthand) to access @sx.
1759 '!!' as a special syntax (shorthand) to access @sx.
1756
1760
1757 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
1761 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
1758 command and return its output as a list split on '\n'.
1762 command and return its output as a list split on '\n'.
1759
1763
1760 2004-03-31 Fernando Perez <fperez@colorado.edu>
1764 2004-03-31 Fernando Perez <fperez@colorado.edu>
1761
1765
1762 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
1766 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
1763 method to dictionaries used as FakeModule instances if they lack
1767 method to dictionaries used as FakeModule instances if they lack
1764 it. At least pydoc in python2.3 breaks for runtime-defined
1768 it. At least pydoc in python2.3 breaks for runtime-defined
1765 functions without this hack. At some point I need to _really_
1769 functions without this hack. At some point I need to _really_
1766 understand what FakeModule is doing, because it's a gross hack.
1770 understand what FakeModule is doing, because it's a gross hack.
1767 But it solves Arnd's problem for now...
1771 But it solves Arnd's problem for now...
1768
1772
1769 2004-02-27 Fernando Perez <fperez@colorado.edu>
1773 2004-02-27 Fernando Perez <fperez@colorado.edu>
1770
1774
1771 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
1775 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
1772 mode would behave erratically. Also increased the number of
1776 mode would behave erratically. Also increased the number of
1773 possible logs in rotate mod to 999. Thanks to Rod Holland
1777 possible logs in rotate mod to 999. Thanks to Rod Holland
1774 <rhh@StructureLABS.com> for the report and fixes.
1778 <rhh@StructureLABS.com> for the report and fixes.
1775
1779
1776 2004-02-26 Fernando Perez <fperez@colorado.edu>
1780 2004-02-26 Fernando Perez <fperez@colorado.edu>
1777
1781
1778 * IPython/genutils.py (page): Check that the curses module really
1782 * IPython/genutils.py (page): Check that the curses module really
1779 has the initscr attribute before trying to use it. For some
1783 has the initscr attribute before trying to use it. For some
1780 reason, the Solaris curses module is missing this. I think this
1784 reason, the Solaris curses module is missing this. I think this
1781 should be considered a Solaris python bug, but I'm not sure.
1785 should be considered a Solaris python bug, but I'm not sure.
1782
1786
1783 2004-01-17 Fernando Perez <fperez@colorado.edu>
1787 2004-01-17 Fernando Perez <fperez@colorado.edu>
1784
1788
1785 * IPython/genutils.py (Stream.__init__): Changes to try to make
1789 * IPython/genutils.py (Stream.__init__): Changes to try to make
1786 ipython robust against stdin/out/err being closed by the user.
1790 ipython robust against stdin/out/err being closed by the user.
1787 This is 'user error' (and blocks a normal python session, at least
1791 This is 'user error' (and blocks a normal python session, at least
1788 the stdout case). However, Ipython should be able to survive such
1792 the stdout case). However, Ipython should be able to survive such
1789 instances of abuse as gracefully as possible. To simplify the
1793 instances of abuse as gracefully as possible. To simplify the
1790 coding and maintain compatibility with Gary Bishop's Term
1794 coding and maintain compatibility with Gary Bishop's Term
1791 contributions, I've made use of classmethods for this. I think
1795 contributions, I've made use of classmethods for this. I think
1792 this introduces a dependency on python 2.2.
1796 this introduces a dependency on python 2.2.
1793
1797
1794 2004-01-13 Fernando Perez <fperez@colorado.edu>
1798 2004-01-13 Fernando Perez <fperez@colorado.edu>
1795
1799
1796 * IPython/numutils.py (exp_safe): simplified the code a bit and
1800 * IPython/numutils.py (exp_safe): simplified the code a bit and
1797 removed the need for importing the kinds module altogether.
1801 removed the need for importing the kinds module altogether.
1798
1802
1799 2004-01-06 Fernando Perez <fperez@colorado.edu>
1803 2004-01-06 Fernando Perez <fperez@colorado.edu>
1800
1804
1801 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
1805 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
1802 a magic function instead, after some community feedback. No
1806 a magic function instead, after some community feedback. No
1803 special syntax will exist for it, but its name is deliberately
1807 special syntax will exist for it, but its name is deliberately
1804 very short.
1808 very short.
1805
1809
1806 2003-12-20 Fernando Perez <fperez@colorado.edu>
1810 2003-12-20 Fernando Perez <fperez@colorado.edu>
1807
1811
1808 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
1812 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
1809 new functionality, to automagically assign the result of a shell
1813 new functionality, to automagically assign the result of a shell
1810 command to a variable. I'll solicit some community feedback on
1814 command to a variable. I'll solicit some community feedback on
1811 this before making it permanent.
1815 this before making it permanent.
1812
1816
1813 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
1817 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
1814 requested about callables for which inspect couldn't obtain a
1818 requested about callables for which inspect couldn't obtain a
1815 proper argspec. Thanks to a crash report sent by Etienne
1819 proper argspec. Thanks to a crash report sent by Etienne
1816 Posthumus <etienne-AT-apple01.cs.vu.nl>.
1820 Posthumus <etienne-AT-apple01.cs.vu.nl>.
1817
1821
1818 2003-12-09 Fernando Perez <fperez@colorado.edu>
1822 2003-12-09 Fernando Perez <fperez@colorado.edu>
1819
1823
1820 * IPython/genutils.py (page): patch for the pager to work across
1824 * IPython/genutils.py (page): patch for the pager to work across
1821 various versions of Windows. By Gary Bishop.
1825 various versions of Windows. By Gary Bishop.
1822
1826
1823 2003-12-04 Fernando Perez <fperez@colorado.edu>
1827 2003-12-04 Fernando Perez <fperez@colorado.edu>
1824
1828
1825 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
1829 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
1826 Gnuplot.py version 1.7, whose internal names changed quite a bit.
1830 Gnuplot.py version 1.7, whose internal names changed quite a bit.
1827 While I tested this and it looks ok, there may still be corner
1831 While I tested this and it looks ok, there may still be corner
1828 cases I've missed.
1832 cases I've missed.
1829
1833
1830 2003-12-01 Fernando Perez <fperez@colorado.edu>
1834 2003-12-01 Fernando Perez <fperez@colorado.edu>
1831
1835
1832 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
1836 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
1833 where a line like 'p,q=1,2' would fail because the automagic
1837 where a line like 'p,q=1,2' would fail because the automagic
1834 system would be triggered for @p.
1838 system would be triggered for @p.
1835
1839
1836 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
1840 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
1837 cleanups, code unmodified.
1841 cleanups, code unmodified.
1838
1842
1839 * IPython/genutils.py (Term): added a class for IPython to handle
1843 * IPython/genutils.py (Term): added a class for IPython to handle
1840 output. In most cases it will just be a proxy for stdout/err, but
1844 output. In most cases it will just be a proxy for stdout/err, but
1841 having this allows modifications to be made for some platforms,
1845 having this allows modifications to be made for some platforms,
1842 such as handling color escapes under Windows. All of this code
1846 such as handling color escapes under Windows. All of this code
1843 was contributed by Gary Bishop, with minor modifications by me.
1847 was contributed by Gary Bishop, with minor modifications by me.
1844 The actual changes affect many files.
1848 The actual changes affect many files.
1845
1849
1846 2003-11-30 Fernando Perez <fperez@colorado.edu>
1850 2003-11-30 Fernando Perez <fperez@colorado.edu>
1847
1851
1848 * IPython/iplib.py (file_matches): new completion code, courtesy
1852 * IPython/iplib.py (file_matches): new completion code, courtesy
1849 of Jeff Collins. This enables filename completion again under
1853 of Jeff Collins. This enables filename completion again under
1850 python 2.3, which disabled it at the C level.
1854 python 2.3, which disabled it at the C level.
1851
1855
1852 2003-11-11 Fernando Perez <fperez@colorado.edu>
1856 2003-11-11 Fernando Perez <fperez@colorado.edu>
1853
1857
1854 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
1858 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
1855 for Numeric.array(map(...)), but often convenient.
1859 for Numeric.array(map(...)), but often convenient.
1856
1860
1857 2003-11-05 Fernando Perez <fperez@colorado.edu>
1861 2003-11-05 Fernando Perez <fperez@colorado.edu>
1858
1862
1859 * IPython/numutils.py (frange): Changed a call from int() to
1863 * IPython/numutils.py (frange): Changed a call from int() to
1860 int(round()) to prevent a problem reported with arange() in the
1864 int(round()) to prevent a problem reported with arange() in the
1861 numpy list.
1865 numpy list.
1862
1866
1863 2003-10-06 Fernando Perez <fperez@colorado.edu>
1867 2003-10-06 Fernando Perez <fperez@colorado.edu>
1864
1868
1865 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
1869 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
1866 prevent crashes if sys lacks an argv attribute (it happens with
1870 prevent crashes if sys lacks an argv attribute (it happens with
1867 embedded interpreters which build a bare-bones sys module).
1871 embedded interpreters which build a bare-bones sys module).
1868 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
1872 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
1869
1873
1870 2003-09-24 Fernando Perez <fperez@colorado.edu>
1874 2003-09-24 Fernando Perez <fperez@colorado.edu>
1871
1875
1872 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
1876 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
1873 to protect against poorly written user objects where __getattr__
1877 to protect against poorly written user objects where __getattr__
1874 raises exceptions other than AttributeError. Thanks to a bug
1878 raises exceptions other than AttributeError. Thanks to a bug
1875 report by Oliver Sander <osander-AT-gmx.de>.
1879 report by Oliver Sander <osander-AT-gmx.de>.
1876
1880
1877 * IPython/FakeModule.py (FakeModule.__repr__): this method was
1881 * IPython/FakeModule.py (FakeModule.__repr__): this method was
1878 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
1882 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
1879
1883
1880 2003-09-09 Fernando Perez <fperez@colorado.edu>
1884 2003-09-09 Fernando Perez <fperez@colorado.edu>
1881
1885
1882 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1886 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1883 unpacking a list whith a callable as first element would
1887 unpacking a list whith a callable as first element would
1884 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
1888 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
1885 Collins.
1889 Collins.
1886
1890
1887 2003-08-25 *** Released version 0.5.0
1891 2003-08-25 *** Released version 0.5.0
1888
1892
1889 2003-08-22 Fernando Perez <fperez@colorado.edu>
1893 2003-08-22 Fernando Perez <fperez@colorado.edu>
1890
1894
1891 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
1895 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
1892 improperly defined user exceptions. Thanks to feedback from Mark
1896 improperly defined user exceptions. Thanks to feedback from Mark
1893 Russell <mrussell-AT-verio.net>.
1897 Russell <mrussell-AT-verio.net>.
1894
1898
1895 2003-08-20 Fernando Perez <fperez@colorado.edu>
1899 2003-08-20 Fernando Perez <fperez@colorado.edu>
1896
1900
1897 * IPython/OInspect.py (Inspector.pinfo): changed String Form
1901 * IPython/OInspect.py (Inspector.pinfo): changed String Form
1898 printing so that it would print multi-line string forms starting
1902 printing so that it would print multi-line string forms starting
1899 with a new line. This way the formatting is better respected for
1903 with a new line. This way the formatting is better respected for
1900 objects which work hard to make nice string forms.
1904 objects which work hard to make nice string forms.
1901
1905
1902 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
1906 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
1903 autocall would overtake data access for objects with both
1907 autocall would overtake data access for objects with both
1904 __getitem__ and __call__.
1908 __getitem__ and __call__.
1905
1909
1906 2003-08-19 *** Released version 0.5.0-rc1
1910 2003-08-19 *** Released version 0.5.0-rc1
1907
1911
1908 2003-08-19 Fernando Perez <fperez@colorado.edu>
1912 2003-08-19 Fernando Perez <fperez@colorado.edu>
1909
1913
1910 * IPython/deep_reload.py (load_tail): single tiny change here
1914 * IPython/deep_reload.py (load_tail): single tiny change here
1911 seems to fix the long-standing bug of dreload() failing to work
1915 seems to fix the long-standing bug of dreload() failing to work
1912 for dotted names. But this module is pretty tricky, so I may have
1916 for dotted names. But this module is pretty tricky, so I may have
1913 missed some subtlety. Needs more testing!.
1917 missed some subtlety. Needs more testing!.
1914
1918
1915 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
1919 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
1916 exceptions which have badly implemented __str__ methods.
1920 exceptions which have badly implemented __str__ methods.
1917 (VerboseTB.text): harden against inspect.getinnerframes crashing,
1921 (VerboseTB.text): harden against inspect.getinnerframes crashing,
1918 which I've been getting reports about from Python 2.3 users. I
1922 which I've been getting reports about from Python 2.3 users. I
1919 wish I had a simple test case to reproduce the problem, so I could
1923 wish I had a simple test case to reproduce the problem, so I could
1920 either write a cleaner workaround or file a bug report if
1924 either write a cleaner workaround or file a bug report if
1921 necessary.
1925 necessary.
1922
1926
1923 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
1927 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
1924 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
1928 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
1925 a bug report by Tjabo Kloppenburg.
1929 a bug report by Tjabo Kloppenburg.
1926
1930
1927 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
1931 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
1928 crashes. Wrapped the pdb call in a blanket try/except, since pdb
1932 crashes. Wrapped the pdb call in a blanket try/except, since pdb
1929 seems rather unstable. Thanks to a bug report by Tjabo
1933 seems rather unstable. Thanks to a bug report by Tjabo
1930 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
1934 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
1931
1935
1932 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
1936 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
1933 this out soon because of the critical fixes in the inner loop for
1937 this out soon because of the critical fixes in the inner loop for
1934 generators.
1938 generators.
1935
1939
1936 * IPython/Magic.py (Magic.getargspec): removed. This (and
1940 * IPython/Magic.py (Magic.getargspec): removed. This (and
1937 _get_def) have been obsoleted by OInspect for a long time, I
1941 _get_def) have been obsoleted by OInspect for a long time, I
1938 hadn't noticed that they were dead code.
1942 hadn't noticed that they were dead code.
1939 (Magic._ofind): restored _ofind functionality for a few literals
1943 (Magic._ofind): restored _ofind functionality for a few literals
1940 (those in ["''",'""','[]','{}','()']). But it won't work anymore
1944 (those in ["''",'""','[]','{}','()']). But it won't work anymore
1941 for things like "hello".capitalize?, since that would require a
1945 for things like "hello".capitalize?, since that would require a
1942 potentially dangerous eval() again.
1946 potentially dangerous eval() again.
1943
1947
1944 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
1948 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
1945 logic a bit more to clean up the escapes handling and minimize the
1949 logic a bit more to clean up the escapes handling and minimize the
1946 use of _ofind to only necessary cases. The interactive 'feel' of
1950 use of _ofind to only necessary cases. The interactive 'feel' of
1947 IPython should have improved quite a bit with the changes in
1951 IPython should have improved quite a bit with the changes in
1948 _prefilter and _ofind (besides being far safer than before).
1952 _prefilter and _ofind (besides being far safer than before).
1949
1953
1950 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
1954 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
1951 obscure, never reported). Edit would fail to find the object to
1955 obscure, never reported). Edit would fail to find the object to
1952 edit under some circumstances.
1956 edit under some circumstances.
1953 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
1957 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
1954 which were causing double-calling of generators. Those eval calls
1958 which were causing double-calling of generators. Those eval calls
1955 were _very_ dangerous, since code with side effects could be
1959 were _very_ dangerous, since code with side effects could be
1956 triggered. As they say, 'eval is evil'... These were the
1960 triggered. As they say, 'eval is evil'... These were the
1957 nastiest evals in IPython. Besides, _ofind is now far simpler,
1961 nastiest evals in IPython. Besides, _ofind is now far simpler,
1958 and it should also be quite a bit faster. Its use of inspect is
1962 and it should also be quite a bit faster. Its use of inspect is
1959 also safer, so perhaps some of the inspect-related crashes I've
1963 also safer, so perhaps some of the inspect-related crashes I've
1960 seen lately with Python 2.3 might be taken care of. That will
1964 seen lately with Python 2.3 might be taken care of. That will
1961 need more testing.
1965 need more testing.
1962
1966
1963 2003-08-17 Fernando Perez <fperez@colorado.edu>
1967 2003-08-17 Fernando Perez <fperez@colorado.edu>
1964
1968
1965 * IPython/iplib.py (InteractiveShell._prefilter): significant
1969 * IPython/iplib.py (InteractiveShell._prefilter): significant
1966 simplifications to the logic for handling user escapes. Faster
1970 simplifications to the logic for handling user escapes. Faster
1967 and simpler code.
1971 and simpler code.
1968
1972
1969 2003-08-14 Fernando Perez <fperez@colorado.edu>
1973 2003-08-14 Fernando Perez <fperez@colorado.edu>
1970
1974
1971 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
1975 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
1972 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
1976 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
1973 but it should be quite a bit faster. And the recursive version
1977 but it should be quite a bit faster. And the recursive version
1974 generated O(log N) intermediate storage for all rank>1 arrays,
1978 generated O(log N) intermediate storage for all rank>1 arrays,
1975 even if they were contiguous.
1979 even if they were contiguous.
1976 (l1norm): Added this function.
1980 (l1norm): Added this function.
1977 (norm): Added this function for arbitrary norms (including
1981 (norm): Added this function for arbitrary norms (including
1978 l-infinity). l1 and l2 are still special cases for convenience
1982 l-infinity). l1 and l2 are still special cases for convenience
1979 and speed.
1983 and speed.
1980
1984
1981 2003-08-03 Fernando Perez <fperez@colorado.edu>
1985 2003-08-03 Fernando Perez <fperez@colorado.edu>
1982
1986
1983 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
1987 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
1984 exceptions, which now raise PendingDeprecationWarnings in Python
1988 exceptions, which now raise PendingDeprecationWarnings in Python
1985 2.3. There were some in Magic and some in Gnuplot2.
1989 2.3. There were some in Magic and some in Gnuplot2.
1986
1990
1987 2003-06-30 Fernando Perez <fperez@colorado.edu>
1991 2003-06-30 Fernando Perez <fperez@colorado.edu>
1988
1992
1989 * IPython/genutils.py (page): modified to call curses only for
1993 * IPython/genutils.py (page): modified to call curses only for
1990 terminals where TERM=='xterm'. After problems under many other
1994 terminals where TERM=='xterm'. After problems under many other
1991 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
1995 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
1992
1996
1993 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
1997 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
1994 would be triggered when readline was absent. This was just an old
1998 would be triggered when readline was absent. This was just an old
1995 debugging statement I'd forgotten to take out.
1999 debugging statement I'd forgotten to take out.
1996
2000
1997 2003-06-20 Fernando Perez <fperez@colorado.edu>
2001 2003-06-20 Fernando Perez <fperez@colorado.edu>
1998
2002
1999 * IPython/genutils.py (clock): modified to return only user time
2003 * IPython/genutils.py (clock): modified to return only user time
2000 (not counting system time), after a discussion on scipy. While
2004 (not counting system time), after a discussion on scipy. While
2001 system time may be a useful quantity occasionally, it may much
2005 system time may be a useful quantity occasionally, it may much
2002 more easily be skewed by occasional swapping or other similar
2006 more easily be skewed by occasional swapping or other similar
2003 activity.
2007 activity.
2004
2008
2005 2003-06-05 Fernando Perez <fperez@colorado.edu>
2009 2003-06-05 Fernando Perez <fperez@colorado.edu>
2006
2010
2007 * IPython/numutils.py (identity): new function, for building
2011 * IPython/numutils.py (identity): new function, for building
2008 arbitrary rank Kronecker deltas (mostly backwards compatible with
2012 arbitrary rank Kronecker deltas (mostly backwards compatible with
2009 Numeric.identity)
2013 Numeric.identity)
2010
2014
2011 2003-06-03 Fernando Perez <fperez@colorado.edu>
2015 2003-06-03 Fernando Perez <fperez@colorado.edu>
2012
2016
2013 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2017 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2014 arguments passed to magics with spaces, to allow trailing '\' to
2018 arguments passed to magics with spaces, to allow trailing '\' to
2015 work normally (mainly for Windows users).
2019 work normally (mainly for Windows users).
2016
2020
2017 2003-05-29 Fernando Perez <fperez@colorado.edu>
2021 2003-05-29 Fernando Perez <fperez@colorado.edu>
2018
2022
2019 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2023 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2020 instead of pydoc.help. This fixes a bizarre behavior where
2024 instead of pydoc.help. This fixes a bizarre behavior where
2021 printing '%s' % locals() would trigger the help system. Now
2025 printing '%s' % locals() would trigger the help system. Now
2022 ipython behaves like normal python does.
2026 ipython behaves like normal python does.
2023
2027
2024 Note that if one does 'from pydoc import help', the bizarre
2028 Note that if one does 'from pydoc import help', the bizarre
2025 behavior returns, but this will also happen in normal python, so
2029 behavior returns, but this will also happen in normal python, so
2026 it's not an ipython bug anymore (it has to do with how pydoc.help
2030 it's not an ipython bug anymore (it has to do with how pydoc.help
2027 is implemented).
2031 is implemented).
2028
2032
2029 2003-05-22 Fernando Perez <fperez@colorado.edu>
2033 2003-05-22 Fernando Perez <fperez@colorado.edu>
2030
2034
2031 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2035 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2032 return [] instead of None when nothing matches, also match to end
2036 return [] instead of None when nothing matches, also match to end
2033 of line. Patch by Gary Bishop.
2037 of line. Patch by Gary Bishop.
2034
2038
2035 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2039 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2036 protection as before, for files passed on the command line. This
2040 protection as before, for files passed on the command line. This
2037 prevents the CrashHandler from kicking in if user files call into
2041 prevents the CrashHandler from kicking in if user files call into
2038 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2042 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2039 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2043 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2040
2044
2041 2003-05-20 *** Released version 0.4.0
2045 2003-05-20 *** Released version 0.4.0
2042
2046
2043 2003-05-20 Fernando Perez <fperez@colorado.edu>
2047 2003-05-20 Fernando Perez <fperez@colorado.edu>
2044
2048
2045 * setup.py: added support for manpages. It's a bit hackish b/c of
2049 * setup.py: added support for manpages. It's a bit hackish b/c of
2046 a bug in the way the bdist_rpm distutils target handles gzipped
2050 a bug in the way the bdist_rpm distutils target handles gzipped
2047 manpages, but it works. After a patch by Jack.
2051 manpages, but it works. After a patch by Jack.
2048
2052
2049 2003-05-19 Fernando Perez <fperez@colorado.edu>
2053 2003-05-19 Fernando Perez <fperez@colorado.edu>
2050
2054
2051 * IPython/numutils.py: added a mockup of the kinds module, since
2055 * IPython/numutils.py: added a mockup of the kinds module, since
2052 it was recently removed from Numeric. This way, numutils will
2056 it was recently removed from Numeric. This way, numutils will
2053 work for all users even if they are missing kinds.
2057 work for all users even if they are missing kinds.
2054
2058
2055 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2059 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2056 failure, which can occur with SWIG-wrapped extensions. After a
2060 failure, which can occur with SWIG-wrapped extensions. After a
2057 crash report from Prabhu.
2061 crash report from Prabhu.
2058
2062
2059 2003-05-16 Fernando Perez <fperez@colorado.edu>
2063 2003-05-16 Fernando Perez <fperez@colorado.edu>
2060
2064
2061 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2065 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2062 protect ipython from user code which may call directly
2066 protect ipython from user code which may call directly
2063 sys.excepthook (this looks like an ipython crash to the user, even
2067 sys.excepthook (this looks like an ipython crash to the user, even
2064 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2068 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2065 This is especially important to help users of WxWindows, but may
2069 This is especially important to help users of WxWindows, but may
2066 also be useful in other cases.
2070 also be useful in other cases.
2067
2071
2068 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2072 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2069 an optional tb_offset to be specified, and to preserve exception
2073 an optional tb_offset to be specified, and to preserve exception
2070 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2074 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2071
2075
2072 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2076 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2073
2077
2074 2003-05-15 Fernando Perez <fperez@colorado.edu>
2078 2003-05-15 Fernando Perez <fperez@colorado.edu>
2075
2079
2076 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2080 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2077 installing for a new user under Windows.
2081 installing for a new user under Windows.
2078
2082
2079 2003-05-12 Fernando Perez <fperez@colorado.edu>
2083 2003-05-12 Fernando Perez <fperez@colorado.edu>
2080
2084
2081 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2085 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2082 handler for Emacs comint-based lines. Currently it doesn't do
2086 handler for Emacs comint-based lines. Currently it doesn't do
2083 much (but importantly, it doesn't update the history cache). In
2087 much (but importantly, it doesn't update the history cache). In
2084 the future it may be expanded if Alex needs more functionality
2088 the future it may be expanded if Alex needs more functionality
2085 there.
2089 there.
2086
2090
2087 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2091 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2088 info to crash reports.
2092 info to crash reports.
2089
2093
2090 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2094 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2091 just like Python's -c. Also fixed crash with invalid -color
2095 just like Python's -c. Also fixed crash with invalid -color
2092 option value at startup. Thanks to Will French
2096 option value at startup. Thanks to Will French
2093 <wfrench-AT-bestweb.net> for the bug report.
2097 <wfrench-AT-bestweb.net> for the bug report.
2094
2098
2095 2003-05-09 Fernando Perez <fperez@colorado.edu>
2099 2003-05-09 Fernando Perez <fperez@colorado.edu>
2096
2100
2097 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2101 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2098 to EvalDict (it's a mapping, after all) and simplified its code
2102 to EvalDict (it's a mapping, after all) and simplified its code
2099 quite a bit, after a nice discussion on c.l.py where Gustavo
2103 quite a bit, after a nice discussion on c.l.py where Gustavo
2100 Córdova <gcordova-AT-sismex.com> suggested the new version.
2104 Córdova <gcordova-AT-sismex.com> suggested the new version.
2101
2105
2102 2003-04-30 Fernando Perez <fperez@colorado.edu>
2106 2003-04-30 Fernando Perez <fperez@colorado.edu>
2103
2107
2104 * IPython/genutils.py (timings_out): modified it to reduce its
2108 * IPython/genutils.py (timings_out): modified it to reduce its
2105 overhead in the common reps==1 case.
2109 overhead in the common reps==1 case.
2106
2110
2107 2003-04-29 Fernando Perez <fperez@colorado.edu>
2111 2003-04-29 Fernando Perez <fperez@colorado.edu>
2108
2112
2109 * IPython/genutils.py (timings_out): Modified to use the resource
2113 * IPython/genutils.py (timings_out): Modified to use the resource
2110 module, which avoids the wraparound problems of time.clock().
2114 module, which avoids the wraparound problems of time.clock().
2111
2115
2112 2003-04-17 *** Released version 0.2.15pre4
2116 2003-04-17 *** Released version 0.2.15pre4
2113
2117
2114 2003-04-17 Fernando Perez <fperez@colorado.edu>
2118 2003-04-17 Fernando Perez <fperez@colorado.edu>
2115
2119
2116 * setup.py (scriptfiles): Split windows-specific stuff over to a
2120 * setup.py (scriptfiles): Split windows-specific stuff over to a
2117 separate file, in an attempt to have a Windows GUI installer.
2121 separate file, in an attempt to have a Windows GUI installer.
2118 That didn't work, but part of the groundwork is done.
2122 That didn't work, but part of the groundwork is done.
2119
2123
2120 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2124 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2121 indent/unindent with 4 spaces. Particularly useful in combination
2125 indent/unindent with 4 spaces. Particularly useful in combination
2122 with the new auto-indent option.
2126 with the new auto-indent option.
2123
2127
2124 2003-04-16 Fernando Perez <fperez@colorado.edu>
2128 2003-04-16 Fernando Perez <fperez@colorado.edu>
2125
2129
2126 * IPython/Magic.py: various replacements of self.rc for
2130 * IPython/Magic.py: various replacements of self.rc for
2127 self.shell.rc. A lot more remains to be done to fully disentangle
2131 self.shell.rc. A lot more remains to be done to fully disentangle
2128 this class from the main Shell class.
2132 this class from the main Shell class.
2129
2133
2130 * IPython/GnuplotRuntime.py: added checks for mouse support so
2134 * IPython/GnuplotRuntime.py: added checks for mouse support so
2131 that we don't try to enable it if the current gnuplot doesn't
2135 that we don't try to enable it if the current gnuplot doesn't
2132 really support it. Also added checks so that we don't try to
2136 really support it. Also added checks so that we don't try to
2133 enable persist under Windows (where Gnuplot doesn't recognize the
2137 enable persist under Windows (where Gnuplot doesn't recognize the
2134 option).
2138 option).
2135
2139
2136 * IPython/iplib.py (InteractiveShell.interact): Added optional
2140 * IPython/iplib.py (InteractiveShell.interact): Added optional
2137 auto-indenting code, after a patch by King C. Shu
2141 auto-indenting code, after a patch by King C. Shu
2138 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2142 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2139 get along well with pasting indented code. If I ever figure out
2143 get along well with pasting indented code. If I ever figure out
2140 how to make that part go well, it will become on by default.
2144 how to make that part go well, it will become on by default.
2141
2145
2142 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2146 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2143 crash ipython if there was an unmatched '%' in the user's prompt
2147 crash ipython if there was an unmatched '%' in the user's prompt
2144 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2148 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2145
2149
2146 * IPython/iplib.py (InteractiveShell.interact): removed the
2150 * IPython/iplib.py (InteractiveShell.interact): removed the
2147 ability to ask the user whether he wants to crash or not at the
2151 ability to ask the user whether he wants to crash or not at the
2148 'last line' exception handler. Calling functions at that point
2152 'last line' exception handler. Calling functions at that point
2149 changes the stack, and the error reports would have incorrect
2153 changes the stack, and the error reports would have incorrect
2150 tracebacks.
2154 tracebacks.
2151
2155
2152 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2156 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2153 pass through a peger a pretty-printed form of any object. After a
2157 pass through a peger a pretty-printed form of any object. After a
2154 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2158 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2155
2159
2156 2003-04-14 Fernando Perez <fperez@colorado.edu>
2160 2003-04-14 Fernando Perez <fperez@colorado.edu>
2157
2161
2158 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2162 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2159 all files in ~ would be modified at first install (instead of
2163 all files in ~ would be modified at first install (instead of
2160 ~/.ipython). This could be potentially disastrous, as the
2164 ~/.ipython). This could be potentially disastrous, as the
2161 modification (make line-endings native) could damage binary files.
2165 modification (make line-endings native) could damage binary files.
2162
2166
2163 2003-04-10 Fernando Perez <fperez@colorado.edu>
2167 2003-04-10 Fernando Perez <fperez@colorado.edu>
2164
2168
2165 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2169 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2166 handle only lines which are invalid python. This now means that
2170 handle only lines which are invalid python. This now means that
2167 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2171 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2168 for the bug report.
2172 for the bug report.
2169
2173
2170 2003-04-01 Fernando Perez <fperez@colorado.edu>
2174 2003-04-01 Fernando Perez <fperez@colorado.edu>
2171
2175
2172 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2176 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2173 where failing to set sys.last_traceback would crash pdb.pm().
2177 where failing to set sys.last_traceback would crash pdb.pm().
2174 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2178 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2175 report.
2179 report.
2176
2180
2177 2003-03-25 Fernando Perez <fperez@colorado.edu>
2181 2003-03-25 Fernando Perez <fperez@colorado.edu>
2178
2182
2179 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2183 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2180 before printing it (it had a lot of spurious blank lines at the
2184 before printing it (it had a lot of spurious blank lines at the
2181 end).
2185 end).
2182
2186
2183 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2187 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2184 output would be sent 21 times! Obviously people don't use this
2188 output would be sent 21 times! Obviously people don't use this
2185 too often, or I would have heard about it.
2189 too often, or I would have heard about it.
2186
2190
2187 2003-03-24 Fernando Perez <fperez@colorado.edu>
2191 2003-03-24 Fernando Perez <fperez@colorado.edu>
2188
2192
2189 * setup.py (scriptfiles): renamed the data_files parameter from
2193 * setup.py (scriptfiles): renamed the data_files parameter from
2190 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2194 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2191 for the patch.
2195 for the patch.
2192
2196
2193 2003-03-20 Fernando Perez <fperez@colorado.edu>
2197 2003-03-20 Fernando Perez <fperez@colorado.edu>
2194
2198
2195 * IPython/genutils.py (error): added error() and fatal()
2199 * IPython/genutils.py (error): added error() and fatal()
2196 functions.
2200 functions.
2197
2201
2198 2003-03-18 *** Released version 0.2.15pre3
2202 2003-03-18 *** Released version 0.2.15pre3
2199
2203
2200 2003-03-18 Fernando Perez <fperez@colorado.edu>
2204 2003-03-18 Fernando Perez <fperez@colorado.edu>
2201
2205
2202 * setupext/install_data_ext.py
2206 * setupext/install_data_ext.py
2203 (install_data_ext.initialize_options): Class contributed by Jack
2207 (install_data_ext.initialize_options): Class contributed by Jack
2204 Moffit for fixing the old distutils hack. He is sending this to
2208 Moffit for fixing the old distutils hack. He is sending this to
2205 the distutils folks so in the future we may not need it as a
2209 the distutils folks so in the future we may not need it as a
2206 private fix.
2210 private fix.
2207
2211
2208 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2212 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2209 changes for Debian packaging. See his patch for full details.
2213 changes for Debian packaging. See his patch for full details.
2210 The old distutils hack of making the ipythonrc* files carry a
2214 The old distutils hack of making the ipythonrc* files carry a
2211 bogus .py extension is gone, at last. Examples were moved to a
2215 bogus .py extension is gone, at last. Examples were moved to a
2212 separate subdir under doc/, and the separate executable scripts
2216 separate subdir under doc/, and the separate executable scripts
2213 now live in their own directory. Overall a great cleanup. The
2217 now live in their own directory. Overall a great cleanup. The
2214 manual was updated to use the new files, and setup.py has been
2218 manual was updated to use the new files, and setup.py has been
2215 fixed for this setup.
2219 fixed for this setup.
2216
2220
2217 * IPython/PyColorize.py (Parser.usage): made non-executable and
2221 * IPython/PyColorize.py (Parser.usage): made non-executable and
2218 created a pycolor wrapper around it to be included as a script.
2222 created a pycolor wrapper around it to be included as a script.
2219
2223
2220 2003-03-12 *** Released version 0.2.15pre2
2224 2003-03-12 *** Released version 0.2.15pre2
2221
2225
2222 2003-03-12 Fernando Perez <fperez@colorado.edu>
2226 2003-03-12 Fernando Perez <fperez@colorado.edu>
2223
2227
2224 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2228 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2225 long-standing problem with garbage characters in some terminals.
2229 long-standing problem with garbage characters in some terminals.
2226 The issue was really that the \001 and \002 escapes must _only_ be
2230 The issue was really that the \001 and \002 escapes must _only_ be
2227 passed to input prompts (which call readline), but _never_ to
2231 passed to input prompts (which call readline), but _never_ to
2228 normal text to be printed on screen. I changed ColorANSI to have
2232 normal text to be printed on screen. I changed ColorANSI to have
2229 two classes: TermColors and InputTermColors, each with the
2233 two classes: TermColors and InputTermColors, each with the
2230 appropriate escapes for input prompts or normal text. The code in
2234 appropriate escapes for input prompts or normal text. The code in
2231 Prompts.py got slightly more complicated, but this very old and
2235 Prompts.py got slightly more complicated, but this very old and
2232 annoying bug is finally fixed.
2236 annoying bug is finally fixed.
2233
2237
2234 All the credit for nailing down the real origin of this problem
2238 All the credit for nailing down the real origin of this problem
2235 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2239 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2236 *Many* thanks to him for spending quite a bit of effort on this.
2240 *Many* thanks to him for spending quite a bit of effort on this.
2237
2241
2238 2003-03-05 *** Released version 0.2.15pre1
2242 2003-03-05 *** Released version 0.2.15pre1
2239
2243
2240 2003-03-03 Fernando Perez <fperez@colorado.edu>
2244 2003-03-03 Fernando Perez <fperez@colorado.edu>
2241
2245
2242 * IPython/FakeModule.py: Moved the former _FakeModule to a
2246 * IPython/FakeModule.py: Moved the former _FakeModule to a
2243 separate file, because it's also needed by Magic (to fix a similar
2247 separate file, because it's also needed by Magic (to fix a similar
2244 pickle-related issue in @run).
2248 pickle-related issue in @run).
2245
2249
2246 2003-03-02 Fernando Perez <fperez@colorado.edu>
2250 2003-03-02 Fernando Perez <fperez@colorado.edu>
2247
2251
2248 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2252 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2249 the autocall option at runtime.
2253 the autocall option at runtime.
2250 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2254 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2251 across Magic.py to start separating Magic from InteractiveShell.
2255 across Magic.py to start separating Magic from InteractiveShell.
2252 (Magic._ofind): Fixed to return proper namespace for dotted
2256 (Magic._ofind): Fixed to return proper namespace for dotted
2253 names. Before, a dotted name would always return 'not currently
2257 names. Before, a dotted name would always return 'not currently
2254 defined', because it would find the 'parent'. s.x would be found,
2258 defined', because it would find the 'parent'. s.x would be found,
2255 but since 'x' isn't defined by itself, it would get confused.
2259 but since 'x' isn't defined by itself, it would get confused.
2256 (Magic.magic_run): Fixed pickling problems reported by Ralf
2260 (Magic.magic_run): Fixed pickling problems reported by Ralf
2257 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2261 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2258 that I'd used when Mike Heeter reported similar issues at the
2262 that I'd used when Mike Heeter reported similar issues at the
2259 top-level, but now for @run. It boils down to injecting the
2263 top-level, but now for @run. It boils down to injecting the
2260 namespace where code is being executed with something that looks
2264 namespace where code is being executed with something that looks
2261 enough like a module to fool pickle.dump(). Since a pickle stores
2265 enough like a module to fool pickle.dump(). Since a pickle stores
2262 a named reference to the importing module, we need this for
2266 a named reference to the importing module, we need this for
2263 pickles to save something sensible.
2267 pickles to save something sensible.
2264
2268
2265 * IPython/ipmaker.py (make_IPython): added an autocall option.
2269 * IPython/ipmaker.py (make_IPython): added an autocall option.
2266
2270
2267 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2271 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2268 the auto-eval code. Now autocalling is an option, and the code is
2272 the auto-eval code. Now autocalling is an option, and the code is
2269 also vastly safer. There is no more eval() involved at all.
2273 also vastly safer. There is no more eval() involved at all.
2270
2274
2271 2003-03-01 Fernando Perez <fperez@colorado.edu>
2275 2003-03-01 Fernando Perez <fperez@colorado.edu>
2272
2276
2273 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2277 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2274 dict with named keys instead of a tuple.
2278 dict with named keys instead of a tuple.
2275
2279
2276 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2280 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2277
2281
2278 * setup.py (make_shortcut): Fixed message about directories
2282 * setup.py (make_shortcut): Fixed message about directories
2279 created during Windows installation (the directories were ok, just
2283 created during Windows installation (the directories were ok, just
2280 the printed message was misleading). Thanks to Chris Liechti
2284 the printed message was misleading). Thanks to Chris Liechti
2281 <cliechti-AT-gmx.net> for the heads up.
2285 <cliechti-AT-gmx.net> for the heads up.
2282
2286
2283 2003-02-21 Fernando Perez <fperez@colorado.edu>
2287 2003-02-21 Fernando Perez <fperez@colorado.edu>
2284
2288
2285 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2289 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2286 of ValueError exception when checking for auto-execution. This
2290 of ValueError exception when checking for auto-execution. This
2287 one is raised by things like Numeric arrays arr.flat when the
2291 one is raised by things like Numeric arrays arr.flat when the
2288 array is non-contiguous.
2292 array is non-contiguous.
2289
2293
2290 2003-01-31 Fernando Perez <fperez@colorado.edu>
2294 2003-01-31 Fernando Perez <fperez@colorado.edu>
2291
2295
2292 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2296 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2293 not return any value at all (even though the command would get
2297 not return any value at all (even though the command would get
2294 executed).
2298 executed).
2295 (xsys): Flush stdout right after printing the command to ensure
2299 (xsys): Flush stdout right after printing the command to ensure
2296 proper ordering of commands and command output in the total
2300 proper ordering of commands and command output in the total
2297 output.
2301 output.
2298 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2302 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2299 system/getoutput as defaults. The old ones are kept for
2303 system/getoutput as defaults. The old ones are kept for
2300 compatibility reasons, so no code which uses this library needs
2304 compatibility reasons, so no code which uses this library needs
2301 changing.
2305 changing.
2302
2306
2303 2003-01-27 *** Released version 0.2.14
2307 2003-01-27 *** Released version 0.2.14
2304
2308
2305 2003-01-25 Fernando Perez <fperez@colorado.edu>
2309 2003-01-25 Fernando Perez <fperez@colorado.edu>
2306
2310
2307 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2311 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2308 functions defined in previous edit sessions could not be re-edited
2312 functions defined in previous edit sessions could not be re-edited
2309 (because the temp files were immediately removed). Now temp files
2313 (because the temp files were immediately removed). Now temp files
2310 are removed only at IPython's exit.
2314 are removed only at IPython's exit.
2311 (Magic.magic_run): Improved @run to perform shell-like expansions
2315 (Magic.magic_run): Improved @run to perform shell-like expansions
2312 on its arguments (~users and $VARS). With this, @run becomes more
2316 on its arguments (~users and $VARS). With this, @run becomes more
2313 like a normal command-line.
2317 like a normal command-line.
2314
2318
2315 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2319 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2316 bugs related to embedding and cleaned up that code. A fairly
2320 bugs related to embedding and cleaned up that code. A fairly
2317 important one was the impossibility to access the global namespace
2321 important one was the impossibility to access the global namespace
2318 through the embedded IPython (only local variables were visible).
2322 through the embedded IPython (only local variables were visible).
2319
2323
2320 2003-01-14 Fernando Perez <fperez@colorado.edu>
2324 2003-01-14 Fernando Perez <fperez@colorado.edu>
2321
2325
2322 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2326 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2323 auto-calling to be a bit more conservative. Now it doesn't get
2327 auto-calling to be a bit more conservative. Now it doesn't get
2324 triggered if any of '!=()<>' are in the rest of the input line, to
2328 triggered if any of '!=()<>' are in the rest of the input line, to
2325 allow comparing callables. Thanks to Alex for the heads up.
2329 allow comparing callables. Thanks to Alex for the heads up.
2326
2330
2327 2003-01-07 Fernando Perez <fperez@colorado.edu>
2331 2003-01-07 Fernando Perez <fperez@colorado.edu>
2328
2332
2329 * IPython/genutils.py (page): fixed estimation of the number of
2333 * IPython/genutils.py (page): fixed estimation of the number of
2330 lines in a string to be paged to simply count newlines. This
2334 lines in a string to be paged to simply count newlines. This
2331 prevents over-guessing due to embedded escape sequences. A better
2335 prevents over-guessing due to embedded escape sequences. A better
2332 long-term solution would involve stripping out the control chars
2336 long-term solution would involve stripping out the control chars
2333 for the count, but it's potentially so expensive I just don't
2337 for the count, but it's potentially so expensive I just don't
2334 think it's worth doing.
2338 think it's worth doing.
2335
2339
2336 2002-12-19 *** Released version 0.2.14pre50
2340 2002-12-19 *** Released version 0.2.14pre50
2337
2341
2338 2002-12-19 Fernando Perez <fperez@colorado.edu>
2342 2002-12-19 Fernando Perez <fperez@colorado.edu>
2339
2343
2340 * tools/release (version): Changed release scripts to inform
2344 * tools/release (version): Changed release scripts to inform
2341 Andrea and build a NEWS file with a list of recent changes.
2345 Andrea and build a NEWS file with a list of recent changes.
2342
2346
2343 * IPython/ColorANSI.py (__all__): changed terminal detection
2347 * IPython/ColorANSI.py (__all__): changed terminal detection
2344 code. Seems to work better for xterms without breaking
2348 code. Seems to work better for xterms without breaking
2345 konsole. Will need more testing to determine if WinXP and Mac OSX
2349 konsole. Will need more testing to determine if WinXP and Mac OSX
2346 also work ok.
2350 also work ok.
2347
2351
2348 2002-12-18 *** Released version 0.2.14pre49
2352 2002-12-18 *** Released version 0.2.14pre49
2349
2353
2350 2002-12-18 Fernando Perez <fperez@colorado.edu>
2354 2002-12-18 Fernando Perez <fperez@colorado.edu>
2351
2355
2352 * Docs: added new info about Mac OSX, from Andrea.
2356 * Docs: added new info about Mac OSX, from Andrea.
2353
2357
2354 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2358 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2355 allow direct plotting of python strings whose format is the same
2359 allow direct plotting of python strings whose format is the same
2356 of gnuplot data files.
2360 of gnuplot data files.
2357
2361
2358 2002-12-16 Fernando Perez <fperez@colorado.edu>
2362 2002-12-16 Fernando Perez <fperez@colorado.edu>
2359
2363
2360 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2364 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2361 value of exit question to be acknowledged.
2365 value of exit question to be acknowledged.
2362
2366
2363 2002-12-03 Fernando Perez <fperez@colorado.edu>
2367 2002-12-03 Fernando Perez <fperez@colorado.edu>
2364
2368
2365 * IPython/ipmaker.py: removed generators, which had been added
2369 * IPython/ipmaker.py: removed generators, which had been added
2366 by mistake in an earlier debugging run. This was causing trouble
2370 by mistake in an earlier debugging run. This was causing trouble
2367 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2371 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2368 for pointing this out.
2372 for pointing this out.
2369
2373
2370 2002-11-17 Fernando Perez <fperez@colorado.edu>
2374 2002-11-17 Fernando Perez <fperez@colorado.edu>
2371
2375
2372 * Manual: updated the Gnuplot section.
2376 * Manual: updated the Gnuplot section.
2373
2377
2374 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2378 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2375 a much better split of what goes in Runtime and what goes in
2379 a much better split of what goes in Runtime and what goes in
2376 Interactive.
2380 Interactive.
2377
2381
2378 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2382 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2379 being imported from iplib.
2383 being imported from iplib.
2380
2384
2381 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2385 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2382 for command-passing. Now the global Gnuplot instance is called
2386 for command-passing. Now the global Gnuplot instance is called
2383 'gp' instead of 'g', which was really a far too fragile and
2387 'gp' instead of 'g', which was really a far too fragile and
2384 common name.
2388 common name.
2385
2389
2386 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2390 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2387 bounding boxes generated by Gnuplot for square plots.
2391 bounding boxes generated by Gnuplot for square plots.
2388
2392
2389 * IPython/genutils.py (popkey): new function added. I should
2393 * IPython/genutils.py (popkey): new function added. I should
2390 suggest this on c.l.py as a dict method, it seems useful.
2394 suggest this on c.l.py as a dict method, it seems useful.
2391
2395
2392 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2396 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2393 to transparently handle PostScript generation. MUCH better than
2397 to transparently handle PostScript generation. MUCH better than
2394 the previous plot_eps/replot_eps (which I removed now). The code
2398 the previous plot_eps/replot_eps (which I removed now). The code
2395 is also fairly clean and well documented now (including
2399 is also fairly clean and well documented now (including
2396 docstrings).
2400 docstrings).
2397
2401
2398 2002-11-13 Fernando Perez <fperez@colorado.edu>
2402 2002-11-13 Fernando Perez <fperez@colorado.edu>
2399
2403
2400 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2404 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2401 (inconsistent with options).
2405 (inconsistent with options).
2402
2406
2403 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2407 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2404 manually disabled, I don't know why. Fixed it.
2408 manually disabled, I don't know why. Fixed it.
2405 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2409 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2406 eps output.
2410 eps output.
2407
2411
2408 2002-11-12 Fernando Perez <fperez@colorado.edu>
2412 2002-11-12 Fernando Perez <fperez@colorado.edu>
2409
2413
2410 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2414 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2411 don't propagate up to caller. Fixes crash reported by François
2415 don't propagate up to caller. Fixes crash reported by François
2412 Pinard.
2416 Pinard.
2413
2417
2414 2002-11-09 Fernando Perez <fperez@colorado.edu>
2418 2002-11-09 Fernando Perez <fperez@colorado.edu>
2415
2419
2416 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2420 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2417 history file for new users.
2421 history file for new users.
2418 (make_IPython): fixed bug where initial install would leave the
2422 (make_IPython): fixed bug where initial install would leave the
2419 user running in the .ipython dir.
2423 user running in the .ipython dir.
2420 (make_IPython): fixed bug where config dir .ipython would be
2424 (make_IPython): fixed bug where config dir .ipython would be
2421 created regardless of the given -ipythondir option. Thanks to Cory
2425 created regardless of the given -ipythondir option. Thanks to Cory
2422 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2426 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2423
2427
2424 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2428 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2425 type confirmations. Will need to use it in all of IPython's code
2429 type confirmations. Will need to use it in all of IPython's code
2426 consistently.
2430 consistently.
2427
2431
2428 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2432 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2429 context to print 31 lines instead of the default 5. This will make
2433 context to print 31 lines instead of the default 5. This will make
2430 the crash reports extremely detailed in case the problem is in
2434 the crash reports extremely detailed in case the problem is in
2431 libraries I don't have access to.
2435 libraries I don't have access to.
2432
2436
2433 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2437 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2434 line of defense' code to still crash, but giving users fair
2438 line of defense' code to still crash, but giving users fair
2435 warning. I don't want internal errors to go unreported: if there's
2439 warning. I don't want internal errors to go unreported: if there's
2436 an internal problem, IPython should crash and generate a full
2440 an internal problem, IPython should crash and generate a full
2437 report.
2441 report.
2438
2442
2439 2002-11-08 Fernando Perez <fperez@colorado.edu>
2443 2002-11-08 Fernando Perez <fperez@colorado.edu>
2440
2444
2441 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2445 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2442 otherwise uncaught exceptions which can appear if people set
2446 otherwise uncaught exceptions which can appear if people set
2443 sys.stdout to something badly broken. Thanks to a crash report
2447 sys.stdout to something badly broken. Thanks to a crash report
2444 from henni-AT-mail.brainbot.com.
2448 from henni-AT-mail.brainbot.com.
2445
2449
2446 2002-11-04 Fernando Perez <fperez@colorado.edu>
2450 2002-11-04 Fernando Perez <fperez@colorado.edu>
2447
2451
2448 * IPython/iplib.py (InteractiveShell.interact): added
2452 * IPython/iplib.py (InteractiveShell.interact): added
2449 __IPYTHON__active to the builtins. It's a flag which goes on when
2453 __IPYTHON__active to the builtins. It's a flag which goes on when
2450 the interaction starts and goes off again when it stops. This
2454 the interaction starts and goes off again when it stops. This
2451 allows embedding code to detect being inside IPython. Before this
2455 allows embedding code to detect being inside IPython. Before this
2452 was done via __IPYTHON__, but that only shows that an IPython
2456 was done via __IPYTHON__, but that only shows that an IPython
2453 instance has been created.
2457 instance has been created.
2454
2458
2455 * IPython/Magic.py (Magic.magic_env): I realized that in a
2459 * IPython/Magic.py (Magic.magic_env): I realized that in a
2456 UserDict, instance.data holds the data as a normal dict. So I
2460 UserDict, instance.data holds the data as a normal dict. So I
2457 modified @env to return os.environ.data instead of rebuilding a
2461 modified @env to return os.environ.data instead of rebuilding a
2458 dict by hand.
2462 dict by hand.
2459
2463
2460 2002-11-02 Fernando Perez <fperez@colorado.edu>
2464 2002-11-02 Fernando Perez <fperez@colorado.edu>
2461
2465
2462 * IPython/genutils.py (warn): changed so that level 1 prints no
2466 * IPython/genutils.py (warn): changed so that level 1 prints no
2463 header. Level 2 is now the default (with 'WARNING' header, as
2467 header. Level 2 is now the default (with 'WARNING' header, as
2464 before). I think I tracked all places where changes were needed in
2468 before). I think I tracked all places where changes were needed in
2465 IPython, but outside code using the old level numbering may have
2469 IPython, but outside code using the old level numbering may have
2466 broken.
2470 broken.
2467
2471
2468 * IPython/iplib.py (InteractiveShell.runcode): added this to
2472 * IPython/iplib.py (InteractiveShell.runcode): added this to
2469 handle the tracebacks in SystemExit traps correctly. The previous
2473 handle the tracebacks in SystemExit traps correctly. The previous
2470 code (through interact) was printing more of the stack than
2474 code (through interact) was printing more of the stack than
2471 necessary, showing IPython internal code to the user.
2475 necessary, showing IPython internal code to the user.
2472
2476
2473 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2477 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2474 default. Now that the default at the confirmation prompt is yes,
2478 default. Now that the default at the confirmation prompt is yes,
2475 it's not so intrusive. François' argument that ipython sessions
2479 it's not so intrusive. François' argument that ipython sessions
2476 tend to be complex enough not to lose them from an accidental C-d,
2480 tend to be complex enough not to lose them from an accidental C-d,
2477 is a valid one.
2481 is a valid one.
2478
2482
2479 * IPython/iplib.py (InteractiveShell.interact): added a
2483 * IPython/iplib.py (InteractiveShell.interact): added a
2480 showtraceback() call to the SystemExit trap, and modified the exit
2484 showtraceback() call to the SystemExit trap, and modified the exit
2481 confirmation to have yes as the default.
2485 confirmation to have yes as the default.
2482
2486
2483 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2487 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2484 this file. It's been gone from the code for a long time, this was
2488 this file. It's been gone from the code for a long time, this was
2485 simply leftover junk.
2489 simply leftover junk.
2486
2490
2487 2002-11-01 Fernando Perez <fperez@colorado.edu>
2491 2002-11-01 Fernando Perez <fperez@colorado.edu>
2488
2492
2489 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2493 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2490 added. If set, IPython now traps EOF and asks for
2494 added. If set, IPython now traps EOF and asks for
2491 confirmation. After a request by François Pinard.
2495 confirmation. After a request by François Pinard.
2492
2496
2493 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2497 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2494 of @abort, and with a new (better) mechanism for handling the
2498 of @abort, and with a new (better) mechanism for handling the
2495 exceptions.
2499 exceptions.
2496
2500
2497 2002-10-27 Fernando Perez <fperez@colorado.edu>
2501 2002-10-27 Fernando Perez <fperez@colorado.edu>
2498
2502
2499 * IPython/usage.py (__doc__): updated the --help information and
2503 * IPython/usage.py (__doc__): updated the --help information and
2500 the ipythonrc file to indicate that -log generates
2504 the ipythonrc file to indicate that -log generates
2501 ./ipython.log. Also fixed the corresponding info in @logstart.
2505 ./ipython.log. Also fixed the corresponding info in @logstart.
2502 This and several other fixes in the manuals thanks to reports by
2506 This and several other fixes in the manuals thanks to reports by
2503 François Pinard <pinard-AT-iro.umontreal.ca>.
2507 François Pinard <pinard-AT-iro.umontreal.ca>.
2504
2508
2505 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2509 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2506 refer to @logstart (instead of @log, which doesn't exist).
2510 refer to @logstart (instead of @log, which doesn't exist).
2507
2511
2508 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2512 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2509 AttributeError crash. Thanks to Christopher Armstrong
2513 AttributeError crash. Thanks to Christopher Armstrong
2510 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2514 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2511 introduced recently (in 0.2.14pre37) with the fix to the eval
2515 introduced recently (in 0.2.14pre37) with the fix to the eval
2512 problem mentioned below.
2516 problem mentioned below.
2513
2517
2514 2002-10-17 Fernando Perez <fperez@colorado.edu>
2518 2002-10-17 Fernando Perez <fperez@colorado.edu>
2515
2519
2516 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2520 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2517 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2521 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2518
2522
2519 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2523 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2520 this function to fix a problem reported by Alex Schmolck. He saw
2524 this function to fix a problem reported by Alex Schmolck. He saw
2521 it with list comprehensions and generators, which were getting
2525 it with list comprehensions and generators, which were getting
2522 called twice. The real problem was an 'eval' call in testing for
2526 called twice. The real problem was an 'eval' call in testing for
2523 automagic which was evaluating the input line silently.
2527 automagic which was evaluating the input line silently.
2524
2528
2525 This is a potentially very nasty bug, if the input has side
2529 This is a potentially very nasty bug, if the input has side
2526 effects which must not be repeated. The code is much cleaner now,
2530 effects which must not be repeated. The code is much cleaner now,
2527 without any blanket 'except' left and with a regexp test for
2531 without any blanket 'except' left and with a regexp test for
2528 actual function names.
2532 actual function names.
2529
2533
2530 But an eval remains, which I'm not fully comfortable with. I just
2534 But an eval remains, which I'm not fully comfortable with. I just
2531 don't know how to find out if an expression could be a callable in
2535 don't know how to find out if an expression could be a callable in
2532 the user's namespace without doing an eval on the string. However
2536 the user's namespace without doing an eval on the string. However
2533 that string is now much more strictly checked so that no code
2537 that string is now much more strictly checked so that no code
2534 slips by, so the eval should only happen for things that can
2538 slips by, so the eval should only happen for things that can
2535 really be only function/method names.
2539 really be only function/method names.
2536
2540
2537 2002-10-15 Fernando Perez <fperez@colorado.edu>
2541 2002-10-15 Fernando Perez <fperez@colorado.edu>
2538
2542
2539 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2543 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2540 OSX information to main manual, removed README_Mac_OSX file from
2544 OSX information to main manual, removed README_Mac_OSX file from
2541 distribution. Also updated credits for recent additions.
2545 distribution. Also updated credits for recent additions.
2542
2546
2543 2002-10-10 Fernando Perez <fperez@colorado.edu>
2547 2002-10-10 Fernando Perez <fperez@colorado.edu>
2544
2548
2545 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2549 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2546 terminal-related issues. Many thanks to Andrea Riciputi
2550 terminal-related issues. Many thanks to Andrea Riciputi
2547 <andrea.riciputi-AT-libero.it> for writing it.
2551 <andrea.riciputi-AT-libero.it> for writing it.
2548
2552
2549 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2553 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2550 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2554 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2551
2555
2552 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2556 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2553 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2557 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2554 <syver-en-AT-online.no> who both submitted patches for this problem.
2558 <syver-en-AT-online.no> who both submitted patches for this problem.
2555
2559
2556 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2560 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2557 global embedding to make sure that things don't overwrite user
2561 global embedding to make sure that things don't overwrite user
2558 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2562 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2559
2563
2560 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2564 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2561 compatibility. Thanks to Hayden Callow
2565 compatibility. Thanks to Hayden Callow
2562 <h.callow-AT-elec.canterbury.ac.nz>
2566 <h.callow-AT-elec.canterbury.ac.nz>
2563
2567
2564 2002-10-04 Fernando Perez <fperez@colorado.edu>
2568 2002-10-04 Fernando Perez <fperez@colorado.edu>
2565
2569
2566 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2570 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2567 Gnuplot.File objects.
2571 Gnuplot.File objects.
2568
2572
2569 2002-07-23 Fernando Perez <fperez@colorado.edu>
2573 2002-07-23 Fernando Perez <fperez@colorado.edu>
2570
2574
2571 * IPython/genutils.py (timing): Added timings() and timing() for
2575 * IPython/genutils.py (timing): Added timings() and timing() for
2572 quick access to the most commonly needed data, the execution
2576 quick access to the most commonly needed data, the execution
2573 times. Old timing() renamed to timings_out().
2577 times. Old timing() renamed to timings_out().
2574
2578
2575 2002-07-18 Fernando Perez <fperez@colorado.edu>
2579 2002-07-18 Fernando Perez <fperez@colorado.edu>
2576
2580
2577 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2581 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2578 bug with nested instances disrupting the parent's tab completion.
2582 bug with nested instances disrupting the parent's tab completion.
2579
2583
2580 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2584 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2581 all_completions code to begin the emacs integration.
2585 all_completions code to begin the emacs integration.
2582
2586
2583 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2587 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2584 argument to allow titling individual arrays when plotting.
2588 argument to allow titling individual arrays when plotting.
2585
2589
2586 2002-07-15 Fernando Perez <fperez@colorado.edu>
2590 2002-07-15 Fernando Perez <fperez@colorado.edu>
2587
2591
2588 * setup.py (make_shortcut): changed to retrieve the value of
2592 * setup.py (make_shortcut): changed to retrieve the value of
2589 'Program Files' directory from the registry (this value changes in
2593 'Program Files' directory from the registry (this value changes in
2590 non-english versions of Windows). Thanks to Thomas Fanslau
2594 non-english versions of Windows). Thanks to Thomas Fanslau
2591 <tfanslau-AT-gmx.de> for the report.
2595 <tfanslau-AT-gmx.de> for the report.
2592
2596
2593 2002-07-10 Fernando Perez <fperez@colorado.edu>
2597 2002-07-10 Fernando Perez <fperez@colorado.edu>
2594
2598
2595 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2599 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2596 a bug in pdb, which crashes if a line with only whitespace is
2600 a bug in pdb, which crashes if a line with only whitespace is
2597 entered. Bug report submitted to sourceforge.
2601 entered. Bug report submitted to sourceforge.
2598
2602
2599 2002-07-09 Fernando Perez <fperez@colorado.edu>
2603 2002-07-09 Fernando Perez <fperez@colorado.edu>
2600
2604
2601 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2605 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2602 reporting exceptions (it's a bug in inspect.py, I just set a
2606 reporting exceptions (it's a bug in inspect.py, I just set a
2603 workaround).
2607 workaround).
2604
2608
2605 2002-07-08 Fernando Perez <fperez@colorado.edu>
2609 2002-07-08 Fernando Perez <fperez@colorado.edu>
2606
2610
2607 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2611 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2608 __IPYTHON__ in __builtins__ to show up in user_ns.
2612 __IPYTHON__ in __builtins__ to show up in user_ns.
2609
2613
2610 2002-07-03 Fernando Perez <fperez@colorado.edu>
2614 2002-07-03 Fernando Perez <fperez@colorado.edu>
2611
2615
2612 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2616 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2613 name from @gp_set_instance to @gp_set_default.
2617 name from @gp_set_instance to @gp_set_default.
2614
2618
2615 * IPython/ipmaker.py (make_IPython): default editor value set to
2619 * IPython/ipmaker.py (make_IPython): default editor value set to
2616 '0' (a string), to match the rc file. Otherwise will crash when
2620 '0' (a string), to match the rc file. Otherwise will crash when
2617 .strip() is called on it.
2621 .strip() is called on it.
2618
2622
2619
2623
2620 2002-06-28 Fernando Perez <fperez@colorado.edu>
2624 2002-06-28 Fernando Perez <fperez@colorado.edu>
2621
2625
2622 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2626 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2623 of files in current directory when a file is executed via
2627 of files in current directory when a file is executed via
2624 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2628 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2625
2629
2626 * setup.py (manfiles): fix for rpm builds, submitted by RA
2630 * setup.py (manfiles): fix for rpm builds, submitted by RA
2627 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2631 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2628
2632
2629 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2633 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2630 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2634 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2631 string!). A. Schmolck caught this one.
2635 string!). A. Schmolck caught this one.
2632
2636
2633 2002-06-27 Fernando Perez <fperez@colorado.edu>
2637 2002-06-27 Fernando Perez <fperez@colorado.edu>
2634
2638
2635 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2639 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2636 defined files at the cmd line. __name__ wasn't being set to
2640 defined files at the cmd line. __name__ wasn't being set to
2637 __main__.
2641 __main__.
2638
2642
2639 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2643 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2640 regular lists and tuples besides Numeric arrays.
2644 regular lists and tuples besides Numeric arrays.
2641
2645
2642 * IPython/Prompts.py (CachedOutput.__call__): Added output
2646 * IPython/Prompts.py (CachedOutput.__call__): Added output
2643 supression for input ending with ';'. Similar to Mathematica and
2647 supression for input ending with ';'. Similar to Mathematica and
2644 Matlab. The _* vars and Out[] list are still updated, just like
2648 Matlab. The _* vars and Out[] list are still updated, just like
2645 Mathematica behaves.
2649 Mathematica behaves.
2646
2650
2647 2002-06-25 Fernando Perez <fperez@colorado.edu>
2651 2002-06-25 Fernando Perez <fperez@colorado.edu>
2648
2652
2649 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2653 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2650 .ini extensions for profiels under Windows.
2654 .ini extensions for profiels under Windows.
2651
2655
2652 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2656 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2653 string form. Fix contributed by Alexander Schmolck
2657 string form. Fix contributed by Alexander Schmolck
2654 <a.schmolck-AT-gmx.net>
2658 <a.schmolck-AT-gmx.net>
2655
2659
2656 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2660 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2657 pre-configured Gnuplot instance.
2661 pre-configured Gnuplot instance.
2658
2662
2659 2002-06-21 Fernando Perez <fperez@colorado.edu>
2663 2002-06-21 Fernando Perez <fperez@colorado.edu>
2660
2664
2661 * IPython/numutils.py (exp_safe): new function, works around the
2665 * IPython/numutils.py (exp_safe): new function, works around the
2662 underflow problems in Numeric.
2666 underflow problems in Numeric.
2663 (log2): New fn. Safe log in base 2: returns exact integer answer
2667 (log2): New fn. Safe log in base 2: returns exact integer answer
2664 for exact integer powers of 2.
2668 for exact integer powers of 2.
2665
2669
2666 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
2670 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
2667 properly.
2671 properly.
2668
2672
2669 2002-06-20 Fernando Perez <fperez@colorado.edu>
2673 2002-06-20 Fernando Perez <fperez@colorado.edu>
2670
2674
2671 * IPython/genutils.py (timing): new function like
2675 * IPython/genutils.py (timing): new function like
2672 Mathematica's. Similar to time_test, but returns more info.
2676 Mathematica's. Similar to time_test, but returns more info.
2673
2677
2674 2002-06-18 Fernando Perez <fperez@colorado.edu>
2678 2002-06-18 Fernando Perez <fperez@colorado.edu>
2675
2679
2676 * IPython/Magic.py (Magic.magic_save): modified @save and @r
2680 * IPython/Magic.py (Magic.magic_save): modified @save and @r
2677 according to Mike Heeter's suggestions.
2681 according to Mike Heeter's suggestions.
2678
2682
2679 2002-06-16 Fernando Perez <fperez@colorado.edu>
2683 2002-06-16 Fernando Perez <fperez@colorado.edu>
2680
2684
2681 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
2685 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
2682 system. GnuplotMagic is gone as a user-directory option. New files
2686 system. GnuplotMagic is gone as a user-directory option. New files
2683 make it easier to use all the gnuplot stuff both from external
2687 make it easier to use all the gnuplot stuff both from external
2684 programs as well as from IPython. Had to rewrite part of
2688 programs as well as from IPython. Had to rewrite part of
2685 hardcopy() b/c of a strange bug: often the ps files simply don't
2689 hardcopy() b/c of a strange bug: often the ps files simply don't
2686 get created, and require a repeat of the command (often several
2690 get created, and require a repeat of the command (often several
2687 times).
2691 times).
2688
2692
2689 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
2693 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
2690 resolve output channel at call time, so that if sys.stderr has
2694 resolve output channel at call time, so that if sys.stderr has
2691 been redirected by user this gets honored.
2695 been redirected by user this gets honored.
2692
2696
2693 2002-06-13 Fernando Perez <fperez@colorado.edu>
2697 2002-06-13 Fernando Perez <fperez@colorado.edu>
2694
2698
2695 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
2699 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
2696 IPShell. Kept a copy with the old names to avoid breaking people's
2700 IPShell. Kept a copy with the old names to avoid breaking people's
2697 embedded code.
2701 embedded code.
2698
2702
2699 * IPython/ipython: simplified it to the bare minimum after
2703 * IPython/ipython: simplified it to the bare minimum after
2700 Holger's suggestions. Added info about how to use it in
2704 Holger's suggestions. Added info about how to use it in
2701 PYTHONSTARTUP.
2705 PYTHONSTARTUP.
2702
2706
2703 * IPython/Shell.py (IPythonShell): changed the options passing
2707 * IPython/Shell.py (IPythonShell): changed the options passing
2704 from a string with funky %s replacements to a straight list. Maybe
2708 from a string with funky %s replacements to a straight list. Maybe
2705 a bit more typing, but it follows sys.argv conventions, so there's
2709 a bit more typing, but it follows sys.argv conventions, so there's
2706 less special-casing to remember.
2710 less special-casing to remember.
2707
2711
2708 2002-06-12 Fernando Perez <fperez@colorado.edu>
2712 2002-06-12 Fernando Perez <fperez@colorado.edu>
2709
2713
2710 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
2714 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
2711 command. Thanks to a suggestion by Mike Heeter.
2715 command. Thanks to a suggestion by Mike Heeter.
2712 (Magic.magic_pfile): added behavior to look at filenames if given
2716 (Magic.magic_pfile): added behavior to look at filenames if given
2713 arg is not a defined object.
2717 arg is not a defined object.
2714 (Magic.magic_save): New @save function to save code snippets. Also
2718 (Magic.magic_save): New @save function to save code snippets. Also
2715 a Mike Heeter idea.
2719 a Mike Heeter idea.
2716
2720
2717 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
2721 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
2718 plot() and replot(). Much more convenient now, especially for
2722 plot() and replot(). Much more convenient now, especially for
2719 interactive use.
2723 interactive use.
2720
2724
2721 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
2725 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
2722 filenames.
2726 filenames.
2723
2727
2724 2002-06-02 Fernando Perez <fperez@colorado.edu>
2728 2002-06-02 Fernando Perez <fperez@colorado.edu>
2725
2729
2726 * IPython/Struct.py (Struct.__init__): modified to admit
2730 * IPython/Struct.py (Struct.__init__): modified to admit
2727 initialization via another struct.
2731 initialization via another struct.
2728
2732
2729 * IPython/genutils.py (SystemExec.__init__): New stateful
2733 * IPython/genutils.py (SystemExec.__init__): New stateful
2730 interface to xsys and bq. Useful for writing system scripts.
2734 interface to xsys and bq. Useful for writing system scripts.
2731
2735
2732 2002-05-30 Fernando Perez <fperez@colorado.edu>
2736 2002-05-30 Fernando Perez <fperez@colorado.edu>
2733
2737
2734 * MANIFEST.in: Changed docfile selection to exclude all the lyx
2738 * MANIFEST.in: Changed docfile selection to exclude all the lyx
2735 documents. This will make the user download smaller (it's getting
2739 documents. This will make the user download smaller (it's getting
2736 too big).
2740 too big).
2737
2741
2738 2002-05-29 Fernando Perez <fperez@colorado.edu>
2742 2002-05-29 Fernando Perez <fperez@colorado.edu>
2739
2743
2740 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
2744 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
2741 fix problems with shelve and pickle. Seems to work, but I don't
2745 fix problems with shelve and pickle. Seems to work, but I don't
2742 know if corner cases break it. Thanks to Mike Heeter
2746 know if corner cases break it. Thanks to Mike Heeter
2743 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
2747 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
2744
2748
2745 2002-05-24 Fernando Perez <fperez@colorado.edu>
2749 2002-05-24 Fernando Perez <fperez@colorado.edu>
2746
2750
2747 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
2751 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
2748 macros having broken.
2752 macros having broken.
2749
2753
2750 2002-05-21 Fernando Perez <fperez@colorado.edu>
2754 2002-05-21 Fernando Perez <fperez@colorado.edu>
2751
2755
2752 * IPython/Magic.py (Magic.magic_logstart): fixed recently
2756 * IPython/Magic.py (Magic.magic_logstart): fixed recently
2753 introduced logging bug: all history before logging started was
2757 introduced logging bug: all history before logging started was
2754 being written one character per line! This came from the redesign
2758 being written one character per line! This came from the redesign
2755 of the input history as a special list which slices to strings,
2759 of the input history as a special list which slices to strings,
2756 not to lists.
2760 not to lists.
2757
2761
2758 2002-05-20 Fernando Perez <fperez@colorado.edu>
2762 2002-05-20 Fernando Perez <fperez@colorado.edu>
2759
2763
2760 * IPython/Prompts.py (CachedOutput.__init__): made the color table
2764 * IPython/Prompts.py (CachedOutput.__init__): made the color table
2761 be an attribute of all classes in this module. The design of these
2765 be an attribute of all classes in this module. The design of these
2762 classes needs some serious overhauling.
2766 classes needs some serious overhauling.
2763
2767
2764 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
2768 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
2765 which was ignoring '_' in option names.
2769 which was ignoring '_' in option names.
2766
2770
2767 * IPython/ultraTB.py (FormattedTB.__init__): Changed
2771 * IPython/ultraTB.py (FormattedTB.__init__): Changed
2768 'Verbose_novars' to 'Context' and made it the new default. It's a
2772 'Verbose_novars' to 'Context' and made it the new default. It's a
2769 bit more readable and also safer than verbose.
2773 bit more readable and also safer than verbose.
2770
2774
2771 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
2775 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
2772 triple-quoted strings.
2776 triple-quoted strings.
2773
2777
2774 * IPython/OInspect.py (__all__): new module exposing the object
2778 * IPython/OInspect.py (__all__): new module exposing the object
2775 introspection facilities. Now the corresponding magics are dummy
2779 introspection facilities. Now the corresponding magics are dummy
2776 wrappers around this. Having this module will make it much easier
2780 wrappers around this. Having this module will make it much easier
2777 to put these functions into our modified pdb.
2781 to put these functions into our modified pdb.
2778 This new object inspector system uses the new colorizing module,
2782 This new object inspector system uses the new colorizing module,
2779 so source code and other things are nicely syntax highlighted.
2783 so source code and other things are nicely syntax highlighted.
2780
2784
2781 2002-05-18 Fernando Perez <fperez@colorado.edu>
2785 2002-05-18 Fernando Perez <fperez@colorado.edu>
2782
2786
2783 * IPython/ColorANSI.py: Split the coloring tools into a separate
2787 * IPython/ColorANSI.py: Split the coloring tools into a separate
2784 module so I can use them in other code easier (they were part of
2788 module so I can use them in other code easier (they were part of
2785 ultraTB).
2789 ultraTB).
2786
2790
2787 2002-05-17 Fernando Perez <fperez@colorado.edu>
2791 2002-05-17 Fernando Perez <fperez@colorado.edu>
2788
2792
2789 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2793 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2790 fixed it to set the global 'g' also to the called instance, as
2794 fixed it to set the global 'g' also to the called instance, as
2791 long as 'g' was still a gnuplot instance (so it doesn't overwrite
2795 long as 'g' was still a gnuplot instance (so it doesn't overwrite
2792 user's 'g' variables).
2796 user's 'g' variables).
2793
2797
2794 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
2798 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
2795 global variables (aliases to _ih,_oh) so that users which expect
2799 global variables (aliases to _ih,_oh) so that users which expect
2796 In[5] or Out[7] to work aren't unpleasantly surprised.
2800 In[5] or Out[7] to work aren't unpleasantly surprised.
2797 (InputList.__getslice__): new class to allow executing slices of
2801 (InputList.__getslice__): new class to allow executing slices of
2798 input history directly. Very simple class, complements the use of
2802 input history directly. Very simple class, complements the use of
2799 macros.
2803 macros.
2800
2804
2801 2002-05-16 Fernando Perez <fperez@colorado.edu>
2805 2002-05-16 Fernando Perez <fperez@colorado.edu>
2802
2806
2803 * setup.py (docdirbase): make doc directory be just doc/IPython
2807 * setup.py (docdirbase): make doc directory be just doc/IPython
2804 without version numbers, it will reduce clutter for users.
2808 without version numbers, it will reduce clutter for users.
2805
2809
2806 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
2810 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
2807 execfile call to prevent possible memory leak. See for details:
2811 execfile call to prevent possible memory leak. See for details:
2808 http://mail.python.org/pipermail/python-list/2002-February/088476.html
2812 http://mail.python.org/pipermail/python-list/2002-February/088476.html
2809
2813
2810 2002-05-15 Fernando Perez <fperez@colorado.edu>
2814 2002-05-15 Fernando Perez <fperez@colorado.edu>
2811
2815
2812 * IPython/Magic.py (Magic.magic_psource): made the object
2816 * IPython/Magic.py (Magic.magic_psource): made the object
2813 introspection names be more standard: pdoc, pdef, pfile and
2817 introspection names be more standard: pdoc, pdef, pfile and
2814 psource. They all print/page their output, and it makes
2818 psource. They all print/page their output, and it makes
2815 remembering them easier. Kept old names for compatibility as
2819 remembering them easier. Kept old names for compatibility as
2816 aliases.
2820 aliases.
2817
2821
2818 2002-05-14 Fernando Perez <fperez@colorado.edu>
2822 2002-05-14 Fernando Perez <fperez@colorado.edu>
2819
2823
2820 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
2824 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
2821 what the mouse problem was. The trick is to use gnuplot with temp
2825 what the mouse problem was. The trick is to use gnuplot with temp
2822 files and NOT with pipes (for data communication), because having
2826 files and NOT with pipes (for data communication), because having
2823 both pipes and the mouse on is bad news.
2827 both pipes and the mouse on is bad news.
2824
2828
2825 2002-05-13 Fernando Perez <fperez@colorado.edu>
2829 2002-05-13 Fernando Perez <fperez@colorado.edu>
2826
2830
2827 * IPython/Magic.py (Magic._ofind): fixed namespace order search
2831 * IPython/Magic.py (Magic._ofind): fixed namespace order search
2828 bug. Information would be reported about builtins even when
2832 bug. Information would be reported about builtins even when
2829 user-defined functions overrode them.
2833 user-defined functions overrode them.
2830
2834
2831 2002-05-11 Fernando Perez <fperez@colorado.edu>
2835 2002-05-11 Fernando Perez <fperez@colorado.edu>
2832
2836
2833 * IPython/__init__.py (__all__): removed FlexCompleter from
2837 * IPython/__init__.py (__all__): removed FlexCompleter from
2834 __all__ so that things don't fail in platforms without readline.
2838 __all__ so that things don't fail in platforms without readline.
2835
2839
2836 2002-05-10 Fernando Perez <fperez@colorado.edu>
2840 2002-05-10 Fernando Perez <fperez@colorado.edu>
2837
2841
2838 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
2842 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
2839 it requires Numeric, effectively making Numeric a dependency for
2843 it requires Numeric, effectively making Numeric a dependency for
2840 IPython.
2844 IPython.
2841
2845
2842 * Released 0.2.13
2846 * Released 0.2.13
2843
2847
2844 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
2848 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
2845 profiler interface. Now all the major options from the profiler
2849 profiler interface. Now all the major options from the profiler
2846 module are directly supported in IPython, both for single
2850 module are directly supported in IPython, both for single
2847 expressions (@prun) and for full programs (@run -p).
2851 expressions (@prun) and for full programs (@run -p).
2848
2852
2849 2002-05-09 Fernando Perez <fperez@colorado.edu>
2853 2002-05-09 Fernando Perez <fperez@colorado.edu>
2850
2854
2851 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
2855 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
2852 magic properly formatted for screen.
2856 magic properly formatted for screen.
2853
2857
2854 * setup.py (make_shortcut): Changed things to put pdf version in
2858 * setup.py (make_shortcut): Changed things to put pdf version in
2855 doc/ instead of doc/manual (had to change lyxport a bit).
2859 doc/ instead of doc/manual (had to change lyxport a bit).
2856
2860
2857 * IPython/Magic.py (Profile.string_stats): made profile runs go
2861 * IPython/Magic.py (Profile.string_stats): made profile runs go
2858 through pager (they are long and a pager allows searching, saving,
2862 through pager (they are long and a pager allows searching, saving,
2859 etc.)
2863 etc.)
2860
2864
2861 2002-05-08 Fernando Perez <fperez@colorado.edu>
2865 2002-05-08 Fernando Perez <fperez@colorado.edu>
2862
2866
2863 * Released 0.2.12
2867 * Released 0.2.12
2864
2868
2865 2002-05-06 Fernando Perez <fperez@colorado.edu>
2869 2002-05-06 Fernando Perez <fperez@colorado.edu>
2866
2870
2867 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
2871 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
2868 introduced); 'hist n1 n2' was broken.
2872 introduced); 'hist n1 n2' was broken.
2869 (Magic.magic_pdb): added optional on/off arguments to @pdb
2873 (Magic.magic_pdb): added optional on/off arguments to @pdb
2870 (Magic.magic_run): added option -i to @run, which executes code in
2874 (Magic.magic_run): added option -i to @run, which executes code in
2871 the IPython namespace instead of a clean one. Also added @irun as
2875 the IPython namespace instead of a clean one. Also added @irun as
2872 an alias to @run -i.
2876 an alias to @run -i.
2873
2877
2874 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2878 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
2875 fixed (it didn't really do anything, the namespaces were wrong).
2879 fixed (it didn't really do anything, the namespaces were wrong).
2876
2880
2877 * IPython/Debugger.py (__init__): Added workaround for python 2.1
2881 * IPython/Debugger.py (__init__): Added workaround for python 2.1
2878
2882
2879 * IPython/__init__.py (__all__): Fixed package namespace, now
2883 * IPython/__init__.py (__all__): Fixed package namespace, now
2880 'import IPython' does give access to IPython.<all> as
2884 'import IPython' does give access to IPython.<all> as
2881 expected. Also renamed __release__ to Release.
2885 expected. Also renamed __release__ to Release.
2882
2886
2883 * IPython/Debugger.py (__license__): created new Pdb class which
2887 * IPython/Debugger.py (__license__): created new Pdb class which
2884 functions like a drop-in for the normal pdb.Pdb but does NOT
2888 functions like a drop-in for the normal pdb.Pdb but does NOT
2885 import readline by default. This way it doesn't muck up IPython's
2889 import readline by default. This way it doesn't muck up IPython's
2886 readline handling, and now tab-completion finally works in the
2890 readline handling, and now tab-completion finally works in the
2887 debugger -- sort of. It completes things globally visible, but the
2891 debugger -- sort of. It completes things globally visible, but the
2888 completer doesn't track the stack as pdb walks it. That's a bit
2892 completer doesn't track the stack as pdb walks it. That's a bit
2889 tricky, and I'll have to implement it later.
2893 tricky, and I'll have to implement it later.
2890
2894
2891 2002-05-05 Fernando Perez <fperez@colorado.edu>
2895 2002-05-05 Fernando Perez <fperez@colorado.edu>
2892
2896
2893 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
2897 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
2894 magic docstrings when printed via ? (explicit \'s were being
2898 magic docstrings when printed via ? (explicit \'s were being
2895 printed).
2899 printed).
2896
2900
2897 * IPython/ipmaker.py (make_IPython): fixed namespace
2901 * IPython/ipmaker.py (make_IPython): fixed namespace
2898 identification bug. Now variables loaded via logs or command-line
2902 identification bug. Now variables loaded via logs or command-line
2899 files are recognized in the interactive namespace by @who.
2903 files are recognized in the interactive namespace by @who.
2900
2904
2901 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
2905 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
2902 log replay system stemming from the string form of Structs.
2906 log replay system stemming from the string form of Structs.
2903
2907
2904 * IPython/Magic.py (Macro.__init__): improved macros to properly
2908 * IPython/Magic.py (Macro.__init__): improved macros to properly
2905 handle magic commands in them.
2909 handle magic commands in them.
2906 (Magic.magic_logstart): usernames are now expanded so 'logstart
2910 (Magic.magic_logstart): usernames are now expanded so 'logstart
2907 ~/mylog' now works.
2911 ~/mylog' now works.
2908
2912
2909 * IPython/iplib.py (complete): fixed bug where paths starting with
2913 * IPython/iplib.py (complete): fixed bug where paths starting with
2910 '/' would be completed as magic names.
2914 '/' would be completed as magic names.
2911
2915
2912 2002-05-04 Fernando Perez <fperez@colorado.edu>
2916 2002-05-04 Fernando Perez <fperez@colorado.edu>
2913
2917
2914 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
2918 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
2915 allow running full programs under the profiler's control.
2919 allow running full programs under the profiler's control.
2916
2920
2917 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
2921 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
2918 mode to report exceptions verbosely but without formatting
2922 mode to report exceptions verbosely but without formatting
2919 variables. This addresses the issue of ipython 'freezing' (it's
2923 variables. This addresses the issue of ipython 'freezing' (it's
2920 not frozen, but caught in an expensive formatting loop) when huge
2924 not frozen, but caught in an expensive formatting loop) when huge
2921 variables are in the context of an exception.
2925 variables are in the context of an exception.
2922 (VerboseTB.text): Added '--->' markers at line where exception was
2926 (VerboseTB.text): Added '--->' markers at line where exception was
2923 triggered. Much clearer to read, especially in NoColor modes.
2927 triggered. Much clearer to read, especially in NoColor modes.
2924
2928
2925 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
2929 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
2926 implemented in reverse when changing to the new parse_options().
2930 implemented in reverse when changing to the new parse_options().
2927
2931
2928 2002-05-03 Fernando Perez <fperez@colorado.edu>
2932 2002-05-03 Fernando Perez <fperez@colorado.edu>
2929
2933
2930 * IPython/Magic.py (Magic.parse_options): new function so that
2934 * IPython/Magic.py (Magic.parse_options): new function so that
2931 magics can parse options easier.
2935 magics can parse options easier.
2932 (Magic.magic_prun): new function similar to profile.run(),
2936 (Magic.magic_prun): new function similar to profile.run(),
2933 suggested by Chris Hart.
2937 suggested by Chris Hart.
2934 (Magic.magic_cd): fixed behavior so that it only changes if
2938 (Magic.magic_cd): fixed behavior so that it only changes if
2935 directory actually is in history.
2939 directory actually is in history.
2936
2940
2937 * IPython/usage.py (__doc__): added information about potential
2941 * IPython/usage.py (__doc__): added information about potential
2938 slowness of Verbose exception mode when there are huge data
2942 slowness of Verbose exception mode when there are huge data
2939 structures to be formatted (thanks to Archie Paulson).
2943 structures to be formatted (thanks to Archie Paulson).
2940
2944
2941 * IPython/ipmaker.py (make_IPython): Changed default logging
2945 * IPython/ipmaker.py (make_IPython): Changed default logging
2942 (when simply called with -log) to use curr_dir/ipython.log in
2946 (when simply called with -log) to use curr_dir/ipython.log in
2943 rotate mode. Fixed crash which was occuring with -log before
2947 rotate mode. Fixed crash which was occuring with -log before
2944 (thanks to Jim Boyle).
2948 (thanks to Jim Boyle).
2945
2949
2946 2002-05-01 Fernando Perez <fperez@colorado.edu>
2950 2002-05-01 Fernando Perez <fperez@colorado.edu>
2947
2951
2948 * Released 0.2.11 for these fixes (mainly the ultraTB one which
2952 * Released 0.2.11 for these fixes (mainly the ultraTB one which
2949 was nasty -- though somewhat of a corner case).
2953 was nasty -- though somewhat of a corner case).
2950
2954
2951 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
2955 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
2952 text (was a bug).
2956 text (was a bug).
2953
2957
2954 2002-04-30 Fernando Perez <fperez@colorado.edu>
2958 2002-04-30 Fernando Perez <fperez@colorado.edu>
2955
2959
2956 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
2960 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
2957 a print after ^D or ^C from the user so that the In[] prompt
2961 a print after ^D or ^C from the user so that the In[] prompt
2958 doesn't over-run the gnuplot one.
2962 doesn't over-run the gnuplot one.
2959
2963
2960 2002-04-29 Fernando Perez <fperez@colorado.edu>
2964 2002-04-29 Fernando Perez <fperez@colorado.edu>
2961
2965
2962 * Released 0.2.10
2966 * Released 0.2.10
2963
2967
2964 * IPython/__release__.py (version): get date dynamically.
2968 * IPython/__release__.py (version): get date dynamically.
2965
2969
2966 * Misc. documentation updates thanks to Arnd's comments. Also ran
2970 * Misc. documentation updates thanks to Arnd's comments. Also ran
2967 a full spellcheck on the manual (hadn't been done in a while).
2971 a full spellcheck on the manual (hadn't been done in a while).
2968
2972
2969 2002-04-27 Fernando Perez <fperez@colorado.edu>
2973 2002-04-27 Fernando Perez <fperez@colorado.edu>
2970
2974
2971 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
2975 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
2972 starting a log in mid-session would reset the input history list.
2976 starting a log in mid-session would reset the input history list.
2973
2977
2974 2002-04-26 Fernando Perez <fperez@colorado.edu>
2978 2002-04-26 Fernando Perez <fperez@colorado.edu>
2975
2979
2976 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
2980 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
2977 all files were being included in an update. Now anything in
2981 all files were being included in an update. Now anything in
2978 UserConfig that matches [A-Za-z]*.py will go (this excludes
2982 UserConfig that matches [A-Za-z]*.py will go (this excludes
2979 __init__.py)
2983 __init__.py)
2980
2984
2981 2002-04-25 Fernando Perez <fperez@colorado.edu>
2985 2002-04-25 Fernando Perez <fperez@colorado.edu>
2982
2986
2983 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
2987 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
2984 to __builtins__ so that any form of embedded or imported code can
2988 to __builtins__ so that any form of embedded or imported code can
2985 test for being inside IPython.
2989 test for being inside IPython.
2986
2990
2987 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
2991 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
2988 changed to GnuplotMagic because it's now an importable module,
2992 changed to GnuplotMagic because it's now an importable module,
2989 this makes the name follow that of the standard Gnuplot module.
2993 this makes the name follow that of the standard Gnuplot module.
2990 GnuplotMagic can now be loaded at any time in mid-session.
2994 GnuplotMagic can now be loaded at any time in mid-session.
2991
2995
2992 2002-04-24 Fernando Perez <fperez@colorado.edu>
2996 2002-04-24 Fernando Perez <fperez@colorado.edu>
2993
2997
2994 * IPython/numutils.py: removed SIUnits. It doesn't properly set
2998 * IPython/numutils.py: removed SIUnits. It doesn't properly set
2995 the globals (IPython has its own namespace) and the
2999 the globals (IPython has its own namespace) and the
2996 PhysicalQuantity stuff is much better anyway.
3000 PhysicalQuantity stuff is much better anyway.
2997
3001
2998 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3002 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
2999 embedding example to standard user directory for
3003 embedding example to standard user directory for
3000 distribution. Also put it in the manual.
3004 distribution. Also put it in the manual.
3001
3005
3002 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3006 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3003 instance as first argument (so it doesn't rely on some obscure
3007 instance as first argument (so it doesn't rely on some obscure
3004 hidden global).
3008 hidden global).
3005
3009
3006 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3010 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3007 delimiters. While it prevents ().TAB from working, it allows
3011 delimiters. While it prevents ().TAB from working, it allows
3008 completions in open (... expressions. This is by far a more common
3012 completions in open (... expressions. This is by far a more common
3009 case.
3013 case.
3010
3014
3011 2002-04-23 Fernando Perez <fperez@colorado.edu>
3015 2002-04-23 Fernando Perez <fperez@colorado.edu>
3012
3016
3013 * IPython/Extensions/InterpreterPasteInput.py: new
3017 * IPython/Extensions/InterpreterPasteInput.py: new
3014 syntax-processing module for pasting lines with >>> or ... at the
3018 syntax-processing module for pasting lines with >>> or ... at the
3015 start.
3019 start.
3016
3020
3017 * IPython/Extensions/PhysicalQ_Interactive.py
3021 * IPython/Extensions/PhysicalQ_Interactive.py
3018 (PhysicalQuantityInteractive.__int__): fixed to work with either
3022 (PhysicalQuantityInteractive.__int__): fixed to work with either
3019 Numeric or math.
3023 Numeric or math.
3020
3024
3021 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3025 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3022 provided profiles. Now we have:
3026 provided profiles. Now we have:
3023 -math -> math module as * and cmath with its own namespace.
3027 -math -> math module as * and cmath with its own namespace.
3024 -numeric -> Numeric as *, plus gnuplot & grace
3028 -numeric -> Numeric as *, plus gnuplot & grace
3025 -physics -> same as before
3029 -physics -> same as before
3026
3030
3027 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3031 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3028 user-defined magics wouldn't be found by @magic if they were
3032 user-defined magics wouldn't be found by @magic if they were
3029 defined as class methods. Also cleaned up the namespace search
3033 defined as class methods. Also cleaned up the namespace search
3030 logic and the string building (to use %s instead of many repeated
3034 logic and the string building (to use %s instead of many repeated
3031 string adds).
3035 string adds).
3032
3036
3033 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3037 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3034 of user-defined magics to operate with class methods (cleaner, in
3038 of user-defined magics to operate with class methods (cleaner, in
3035 line with the gnuplot code).
3039 line with the gnuplot code).
3036
3040
3037 2002-04-22 Fernando Perez <fperez@colorado.edu>
3041 2002-04-22 Fernando Perez <fperez@colorado.edu>
3038
3042
3039 * setup.py: updated dependency list so that manual is updated when
3043 * setup.py: updated dependency list so that manual is updated when
3040 all included files change.
3044 all included files change.
3041
3045
3042 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3046 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3043 the delimiter removal option (the fix is ugly right now).
3047 the delimiter removal option (the fix is ugly right now).
3044
3048
3045 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3049 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3046 all of the math profile (quicker loading, no conflict between
3050 all of the math profile (quicker loading, no conflict between
3047 g-9.8 and g-gnuplot).
3051 g-9.8 and g-gnuplot).
3048
3052
3049 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3053 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3050 name of post-mortem files to IPython_crash_report.txt.
3054 name of post-mortem files to IPython_crash_report.txt.
3051
3055
3052 * Cleanup/update of the docs. Added all the new readline info and
3056 * Cleanup/update of the docs. Added all the new readline info and
3053 formatted all lists as 'real lists'.
3057 formatted all lists as 'real lists'.
3054
3058
3055 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3059 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3056 tab-completion options, since the full readline parse_and_bind is
3060 tab-completion options, since the full readline parse_and_bind is
3057 now accessible.
3061 now accessible.
3058
3062
3059 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3063 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3060 handling of readline options. Now users can specify any string to
3064 handling of readline options. Now users can specify any string to
3061 be passed to parse_and_bind(), as well as the delimiters to be
3065 be passed to parse_and_bind(), as well as the delimiters to be
3062 removed.
3066 removed.
3063 (InteractiveShell.__init__): Added __name__ to the global
3067 (InteractiveShell.__init__): Added __name__ to the global
3064 namespace so that things like Itpl which rely on its existence
3068 namespace so that things like Itpl which rely on its existence
3065 don't crash.
3069 don't crash.
3066 (InteractiveShell._prefilter): Defined the default with a _ so
3070 (InteractiveShell._prefilter): Defined the default with a _ so
3067 that prefilter() is easier to override, while the default one
3071 that prefilter() is easier to override, while the default one
3068 remains available.
3072 remains available.
3069
3073
3070 2002-04-18 Fernando Perez <fperez@colorado.edu>
3074 2002-04-18 Fernando Perez <fperez@colorado.edu>
3071
3075
3072 * Added information about pdb in the docs.
3076 * Added information about pdb in the docs.
3073
3077
3074 2002-04-17 Fernando Perez <fperez@colorado.edu>
3078 2002-04-17 Fernando Perez <fperez@colorado.edu>
3075
3079
3076 * IPython/ipmaker.py (make_IPython): added rc_override option to
3080 * IPython/ipmaker.py (make_IPython): added rc_override option to
3077 allow passing config options at creation time which may override
3081 allow passing config options at creation time which may override
3078 anything set in the config files or command line. This is
3082 anything set in the config files or command line. This is
3079 particularly useful for configuring embedded instances.
3083 particularly useful for configuring embedded instances.
3080
3084
3081 2002-04-15 Fernando Perez <fperez@colorado.edu>
3085 2002-04-15 Fernando Perez <fperez@colorado.edu>
3082
3086
3083 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3087 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3084 crash embedded instances because of the input cache falling out of
3088 crash embedded instances because of the input cache falling out of
3085 sync with the output counter.
3089 sync with the output counter.
3086
3090
3087 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3091 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3088 mode which calls pdb after an uncaught exception in IPython itself.
3092 mode which calls pdb after an uncaught exception in IPython itself.
3089
3093
3090 2002-04-14 Fernando Perez <fperez@colorado.edu>
3094 2002-04-14 Fernando Perez <fperez@colorado.edu>
3091
3095
3092 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3096 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3093 readline, fix it back after each call.
3097 readline, fix it back after each call.
3094
3098
3095 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3099 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3096 method to force all access via __call__(), which guarantees that
3100 method to force all access via __call__(), which guarantees that
3097 traceback references are properly deleted.
3101 traceback references are properly deleted.
3098
3102
3099 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3103 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3100 improve printing when pprint is in use.
3104 improve printing when pprint is in use.
3101
3105
3102 2002-04-13 Fernando Perez <fperez@colorado.edu>
3106 2002-04-13 Fernando Perez <fperez@colorado.edu>
3103
3107
3104 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3108 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3105 exceptions aren't caught anymore. If the user triggers one, he
3109 exceptions aren't caught anymore. If the user triggers one, he
3106 should know why he's doing it and it should go all the way up,
3110 should know why he's doing it and it should go all the way up,
3107 just like any other exception. So now @abort will fully kill the
3111 just like any other exception. So now @abort will fully kill the
3108 embedded interpreter and the embedding code (unless that happens
3112 embedded interpreter and the embedding code (unless that happens
3109 to catch SystemExit).
3113 to catch SystemExit).
3110
3114
3111 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3115 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3112 and a debugger() method to invoke the interactive pdb debugger
3116 and a debugger() method to invoke the interactive pdb debugger
3113 after printing exception information. Also added the corresponding
3117 after printing exception information. Also added the corresponding
3114 -pdb option and @pdb magic to control this feature, and updated
3118 -pdb option and @pdb magic to control this feature, and updated
3115 the docs. After a suggestion from Christopher Hart
3119 the docs. After a suggestion from Christopher Hart
3116 (hart-AT-caltech.edu).
3120 (hart-AT-caltech.edu).
3117
3121
3118 2002-04-12 Fernando Perez <fperez@colorado.edu>
3122 2002-04-12 Fernando Perez <fperez@colorado.edu>
3119
3123
3120 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3124 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3121 the exception handlers defined by the user (not the CrashHandler)
3125 the exception handlers defined by the user (not the CrashHandler)
3122 so that user exceptions don't trigger an ipython bug report.
3126 so that user exceptions don't trigger an ipython bug report.
3123
3127
3124 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3128 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3125 configurable (it should have always been so).
3129 configurable (it should have always been so).
3126
3130
3127 2002-03-26 Fernando Perez <fperez@colorado.edu>
3131 2002-03-26 Fernando Perez <fperez@colorado.edu>
3128
3132
3129 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3133 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3130 and there to fix embedding namespace issues. This should all be
3134 and there to fix embedding namespace issues. This should all be
3131 done in a more elegant way.
3135 done in a more elegant way.
3132
3136
3133 2002-03-25 Fernando Perez <fperez@colorado.edu>
3137 2002-03-25 Fernando Perez <fperez@colorado.edu>
3134
3138
3135 * IPython/genutils.py (get_home_dir): Try to make it work under
3139 * IPython/genutils.py (get_home_dir): Try to make it work under
3136 win9x also.
3140 win9x also.
3137
3141
3138 2002-03-20 Fernando Perez <fperez@colorado.edu>
3142 2002-03-20 Fernando Perez <fperez@colorado.edu>
3139
3143
3140 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3144 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3141 sys.displayhook untouched upon __init__.
3145 sys.displayhook untouched upon __init__.
3142
3146
3143 2002-03-19 Fernando Perez <fperez@colorado.edu>
3147 2002-03-19 Fernando Perez <fperez@colorado.edu>
3144
3148
3145 * Released 0.2.9 (for embedding bug, basically).
3149 * Released 0.2.9 (for embedding bug, basically).
3146
3150
3147 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3151 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3148 exceptions so that enclosing shell's state can be restored.
3152 exceptions so that enclosing shell's state can be restored.
3149
3153
3150 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3154 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3151 naming conventions in the .ipython/ dir.
3155 naming conventions in the .ipython/ dir.
3152
3156
3153 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3157 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3154 from delimiters list so filenames with - in them get expanded.
3158 from delimiters list so filenames with - in them get expanded.
3155
3159
3156 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3160 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3157 sys.displayhook not being properly restored after an embedded call.
3161 sys.displayhook not being properly restored after an embedded call.
3158
3162
3159 2002-03-18 Fernando Perez <fperez@colorado.edu>
3163 2002-03-18 Fernando Perez <fperez@colorado.edu>
3160
3164
3161 * Released 0.2.8
3165 * Released 0.2.8
3162
3166
3163 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3167 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3164 some files weren't being included in a -upgrade.
3168 some files weren't being included in a -upgrade.
3165 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3169 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3166 on' so that the first tab completes.
3170 on' so that the first tab completes.
3167 (InteractiveShell.handle_magic): fixed bug with spaces around
3171 (InteractiveShell.handle_magic): fixed bug with spaces around
3168 quotes breaking many magic commands.
3172 quotes breaking many magic commands.
3169
3173
3170 * setup.py: added note about ignoring the syntax error messages at
3174 * setup.py: added note about ignoring the syntax error messages at
3171 installation.
3175 installation.
3172
3176
3173 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3177 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3174 streamlining the gnuplot interface, now there's only one magic @gp.
3178 streamlining the gnuplot interface, now there's only one magic @gp.
3175
3179
3176 2002-03-17 Fernando Perez <fperez@colorado.edu>
3180 2002-03-17 Fernando Perez <fperez@colorado.edu>
3177
3181
3178 * IPython/UserConfig/magic_gnuplot.py: new name for the
3182 * IPython/UserConfig/magic_gnuplot.py: new name for the
3179 example-magic_pm.py file. Much enhanced system, now with a shell
3183 example-magic_pm.py file. Much enhanced system, now with a shell
3180 for communicating directly with gnuplot, one command at a time.
3184 for communicating directly with gnuplot, one command at a time.
3181
3185
3182 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3186 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3183 setting __name__=='__main__'.
3187 setting __name__=='__main__'.
3184
3188
3185 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3189 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3186 mini-shell for accessing gnuplot from inside ipython. Should
3190 mini-shell for accessing gnuplot from inside ipython. Should
3187 extend it later for grace access too. Inspired by Arnd's
3191 extend it later for grace access too. Inspired by Arnd's
3188 suggestion.
3192 suggestion.
3189
3193
3190 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3194 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3191 calling magic functions with () in their arguments. Thanks to Arnd
3195 calling magic functions with () in their arguments. Thanks to Arnd
3192 Baecker for pointing this to me.
3196 Baecker for pointing this to me.
3193
3197
3194 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3198 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3195 infinitely for integer or complex arrays (only worked with floats).
3199 infinitely for integer or complex arrays (only worked with floats).
3196
3200
3197 2002-03-16 Fernando Perez <fperez@colorado.edu>
3201 2002-03-16 Fernando Perez <fperez@colorado.edu>
3198
3202
3199 * setup.py: Merged setup and setup_windows into a single script
3203 * setup.py: Merged setup and setup_windows into a single script
3200 which properly handles things for windows users.
3204 which properly handles things for windows users.
3201
3205
3202 2002-03-15 Fernando Perez <fperez@colorado.edu>
3206 2002-03-15 Fernando Perez <fperez@colorado.edu>
3203
3207
3204 * Big change to the manual: now the magics are all automatically
3208 * Big change to the manual: now the magics are all automatically
3205 documented. This information is generated from their docstrings
3209 documented. This information is generated from their docstrings
3206 and put in a latex file included by the manual lyx file. This way
3210 and put in a latex file included by the manual lyx file. This way
3207 we get always up to date information for the magics. The manual
3211 we get always up to date information for the magics. The manual
3208 now also has proper version information, also auto-synced.
3212 now also has proper version information, also auto-synced.
3209
3213
3210 For this to work, an undocumented --magic_docstrings option was added.
3214 For this to work, an undocumented --magic_docstrings option was added.
3211
3215
3212 2002-03-13 Fernando Perez <fperez@colorado.edu>
3216 2002-03-13 Fernando Perez <fperez@colorado.edu>
3213
3217
3214 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3218 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3215 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3219 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3216
3220
3217 2002-03-12 Fernando Perez <fperez@colorado.edu>
3221 2002-03-12 Fernando Perez <fperez@colorado.edu>
3218
3222
3219 * IPython/ultraTB.py (TermColors): changed color escapes again to
3223 * IPython/ultraTB.py (TermColors): changed color escapes again to
3220 fix the (old, reintroduced) line-wrapping bug. Basically, if
3224 fix the (old, reintroduced) line-wrapping bug. Basically, if
3221 \001..\002 aren't given in the color escapes, lines get wrapped
3225 \001..\002 aren't given in the color escapes, lines get wrapped
3222 weirdly. But giving those screws up old xterms and emacs terms. So
3226 weirdly. But giving those screws up old xterms and emacs terms. So
3223 I added some logic for emacs terms to be ok, but I can't identify old
3227 I added some logic for emacs terms to be ok, but I can't identify old
3224 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3228 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3225
3229
3226 2002-03-10 Fernando Perez <fperez@colorado.edu>
3230 2002-03-10 Fernando Perez <fperez@colorado.edu>
3227
3231
3228 * IPython/usage.py (__doc__): Various documentation cleanups and
3232 * IPython/usage.py (__doc__): Various documentation cleanups and
3229 updates, both in usage docstrings and in the manual.
3233 updates, both in usage docstrings and in the manual.
3230
3234
3231 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3235 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3232 handling of caching. Set minimum acceptabe value for having a
3236 handling of caching. Set minimum acceptabe value for having a
3233 cache at 20 values.
3237 cache at 20 values.
3234
3238
3235 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3239 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3236 install_first_time function to a method, renamed it and added an
3240 install_first_time function to a method, renamed it and added an
3237 'upgrade' mode. Now people can update their config directory with
3241 'upgrade' mode. Now people can update their config directory with
3238 a simple command line switch (-upgrade, also new).
3242 a simple command line switch (-upgrade, also new).
3239
3243
3240 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3244 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3241 @file (convenient for automagic users under Python >= 2.2).
3245 @file (convenient for automagic users under Python >= 2.2).
3242 Removed @files (it seemed more like a plural than an abbrev. of
3246 Removed @files (it seemed more like a plural than an abbrev. of
3243 'file show').
3247 'file show').
3244
3248
3245 * IPython/iplib.py (install_first_time): Fixed crash if there were
3249 * IPython/iplib.py (install_first_time): Fixed crash if there were
3246 backup files ('~') in .ipython/ install directory.
3250 backup files ('~') in .ipython/ install directory.
3247
3251
3248 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3252 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3249 system. Things look fine, but these changes are fairly
3253 system. Things look fine, but these changes are fairly
3250 intrusive. Test them for a few days.
3254 intrusive. Test them for a few days.
3251
3255
3252 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3256 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3253 the prompts system. Now all in/out prompt strings are user
3257 the prompts system. Now all in/out prompt strings are user
3254 controllable. This is particularly useful for embedding, as one
3258 controllable. This is particularly useful for embedding, as one
3255 can tag embedded instances with particular prompts.
3259 can tag embedded instances with particular prompts.
3256
3260
3257 Also removed global use of sys.ps1/2, which now allows nested
3261 Also removed global use of sys.ps1/2, which now allows nested
3258 embeddings without any problems. Added command-line options for
3262 embeddings without any problems. Added command-line options for
3259 the prompt strings.
3263 the prompt strings.
3260
3264
3261 2002-03-08 Fernando Perez <fperez@colorado.edu>
3265 2002-03-08 Fernando Perez <fperez@colorado.edu>
3262
3266
3263 * IPython/UserConfig/example-embed-short.py (ipshell): added
3267 * IPython/UserConfig/example-embed-short.py (ipshell): added
3264 example file with the bare minimum code for embedding.
3268 example file with the bare minimum code for embedding.
3265
3269
3266 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3270 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3267 functionality for the embeddable shell to be activated/deactivated
3271 functionality for the embeddable shell to be activated/deactivated
3268 either globally or at each call.
3272 either globally or at each call.
3269
3273
3270 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3274 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3271 rewriting the prompt with '--->' for auto-inputs with proper
3275 rewriting the prompt with '--->' for auto-inputs with proper
3272 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3276 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3273 this is handled by the prompts class itself, as it should.
3277 this is handled by the prompts class itself, as it should.
3274
3278
3275 2002-03-05 Fernando Perez <fperez@colorado.edu>
3279 2002-03-05 Fernando Perez <fperez@colorado.edu>
3276
3280
3277 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3281 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3278 @logstart to avoid name clashes with the math log function.
3282 @logstart to avoid name clashes with the math log function.
3279
3283
3280 * Big updates to X/Emacs section of the manual.
3284 * Big updates to X/Emacs section of the manual.
3281
3285
3282 * Removed ipython_emacs. Milan explained to me how to pass
3286 * Removed ipython_emacs. Milan explained to me how to pass
3283 arguments to ipython through Emacs. Some day I'm going to end up
3287 arguments to ipython through Emacs. Some day I'm going to end up
3284 learning some lisp...
3288 learning some lisp...
3285
3289
3286 2002-03-04 Fernando Perez <fperez@colorado.edu>
3290 2002-03-04 Fernando Perez <fperez@colorado.edu>
3287
3291
3288 * IPython/ipython_emacs: Created script to be used as the
3292 * IPython/ipython_emacs: Created script to be used as the
3289 py-python-command Emacs variable so we can pass IPython
3293 py-python-command Emacs variable so we can pass IPython
3290 parameters. I can't figure out how to tell Emacs directly to pass
3294 parameters. I can't figure out how to tell Emacs directly to pass
3291 parameters to IPython, so a dummy shell script will do it.
3295 parameters to IPython, so a dummy shell script will do it.
3292
3296
3293 Other enhancements made for things to work better under Emacs'
3297 Other enhancements made for things to work better under Emacs'
3294 various types of terminals. Many thanks to Milan Zamazal
3298 various types of terminals. Many thanks to Milan Zamazal
3295 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3299 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3296
3300
3297 2002-03-01 Fernando Perez <fperez@colorado.edu>
3301 2002-03-01 Fernando Perez <fperez@colorado.edu>
3298
3302
3299 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3303 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3300 that loading of readline is now optional. This gives better
3304 that loading of readline is now optional. This gives better
3301 control to emacs users.
3305 control to emacs users.
3302
3306
3303 * IPython/ultraTB.py (__date__): Modified color escape sequences
3307 * IPython/ultraTB.py (__date__): Modified color escape sequences
3304 and now things work fine under xterm and in Emacs' term buffers
3308 and now things work fine under xterm and in Emacs' term buffers
3305 (though not shell ones). Well, in emacs you get colors, but all
3309 (though not shell ones). Well, in emacs you get colors, but all
3306 seem to be 'light' colors (no difference between dark and light
3310 seem to be 'light' colors (no difference between dark and light
3307 ones). But the garbage chars are gone, and also in xterms. It
3311 ones). But the garbage chars are gone, and also in xterms. It
3308 seems that now I'm using 'cleaner' ansi sequences.
3312 seems that now I'm using 'cleaner' ansi sequences.
3309
3313
3310 2002-02-21 Fernando Perez <fperez@colorado.edu>
3314 2002-02-21 Fernando Perez <fperez@colorado.edu>
3311
3315
3312 * Released 0.2.7 (mainly to publish the scoping fix).
3316 * Released 0.2.7 (mainly to publish the scoping fix).
3313
3317
3314 * IPython/Logger.py (Logger.logstate): added. A corresponding
3318 * IPython/Logger.py (Logger.logstate): added. A corresponding
3315 @logstate magic was created.
3319 @logstate magic was created.
3316
3320
3317 * IPython/Magic.py: fixed nested scoping problem under Python
3321 * IPython/Magic.py: fixed nested scoping problem under Python
3318 2.1.x (automagic wasn't working).
3322 2.1.x (automagic wasn't working).
3319
3323
3320 2002-02-20 Fernando Perez <fperez@colorado.edu>
3324 2002-02-20 Fernando Perez <fperez@colorado.edu>
3321
3325
3322 * Released 0.2.6.
3326 * Released 0.2.6.
3323
3327
3324 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3328 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3325 option so that logs can come out without any headers at all.
3329 option so that logs can come out without any headers at all.
3326
3330
3327 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3331 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3328 SciPy.
3332 SciPy.
3329
3333
3330 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3334 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3331 that embedded IPython calls don't require vars() to be explicitly
3335 that embedded IPython calls don't require vars() to be explicitly
3332 passed. Now they are extracted from the caller's frame (code
3336 passed. Now they are extracted from the caller's frame (code
3333 snatched from Eric Jones' weave). Added better documentation to
3337 snatched from Eric Jones' weave). Added better documentation to
3334 the section on embedding and the example file.
3338 the section on embedding and the example file.
3335
3339
3336 * IPython/genutils.py (page): Changed so that under emacs, it just
3340 * IPython/genutils.py (page): Changed so that under emacs, it just
3337 prints the string. You can then page up and down in the emacs
3341 prints the string. You can then page up and down in the emacs
3338 buffer itself. This is how the builtin help() works.
3342 buffer itself. This is how the builtin help() works.
3339
3343
3340 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3344 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3341 macro scoping: macros need to be executed in the user's namespace
3345 macro scoping: macros need to be executed in the user's namespace
3342 to work as if they had been typed by the user.
3346 to work as if they had been typed by the user.
3343
3347
3344 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3348 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3345 execute automatically (no need to type 'exec...'). They then
3349 execute automatically (no need to type 'exec...'). They then
3346 behave like 'true macros'. The printing system was also modified
3350 behave like 'true macros'. The printing system was also modified
3347 for this to work.
3351 for this to work.
3348
3352
3349 2002-02-19 Fernando Perez <fperez@colorado.edu>
3353 2002-02-19 Fernando Perez <fperez@colorado.edu>
3350
3354
3351 * IPython/genutils.py (page_file): new function for paging files
3355 * IPython/genutils.py (page_file): new function for paging files
3352 in an OS-independent way. Also necessary for file viewing to work
3356 in an OS-independent way. Also necessary for file viewing to work
3353 well inside Emacs buffers.
3357 well inside Emacs buffers.
3354 (page): Added checks for being in an emacs buffer.
3358 (page): Added checks for being in an emacs buffer.
3355 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3359 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3356 same bug in iplib.
3360 same bug in iplib.
3357
3361
3358 2002-02-18 Fernando Perez <fperez@colorado.edu>
3362 2002-02-18 Fernando Perez <fperez@colorado.edu>
3359
3363
3360 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3364 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3361 of readline so that IPython can work inside an Emacs buffer.
3365 of readline so that IPython can work inside an Emacs buffer.
3362
3366
3363 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3367 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3364 method signatures (they weren't really bugs, but it looks cleaner
3368 method signatures (they weren't really bugs, but it looks cleaner
3365 and keeps PyChecker happy).
3369 and keeps PyChecker happy).
3366
3370
3367 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3371 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3368 for implementing various user-defined hooks. Currently only
3372 for implementing various user-defined hooks. Currently only
3369 display is done.
3373 display is done.
3370
3374
3371 * IPython/Prompts.py (CachedOutput._display): changed display
3375 * IPython/Prompts.py (CachedOutput._display): changed display
3372 functions so that they can be dynamically changed by users easily.
3376 functions so that they can be dynamically changed by users easily.
3373
3377
3374 * IPython/Extensions/numeric_formats.py (num_display): added an
3378 * IPython/Extensions/numeric_formats.py (num_display): added an
3375 extension for printing NumPy arrays in flexible manners. It
3379 extension for printing NumPy arrays in flexible manners. It
3376 doesn't do anything yet, but all the structure is in
3380 doesn't do anything yet, but all the structure is in
3377 place. Ultimately the plan is to implement output format control
3381 place. Ultimately the plan is to implement output format control
3378 like in Octave.
3382 like in Octave.
3379
3383
3380 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3384 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3381 methods are found at run-time by all the automatic machinery.
3385 methods are found at run-time by all the automatic machinery.
3382
3386
3383 2002-02-17 Fernando Perez <fperez@colorado.edu>
3387 2002-02-17 Fernando Perez <fperez@colorado.edu>
3384
3388
3385 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3389 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3386 whole file a little.
3390 whole file a little.
3387
3391
3388 * ToDo: closed this document. Now there's a new_design.lyx
3392 * ToDo: closed this document. Now there's a new_design.lyx
3389 document for all new ideas. Added making a pdf of it for the
3393 document for all new ideas. Added making a pdf of it for the
3390 end-user distro.
3394 end-user distro.
3391
3395
3392 * IPython/Logger.py (Logger.switch_log): Created this to replace
3396 * IPython/Logger.py (Logger.switch_log): Created this to replace
3393 logon() and logoff(). It also fixes a nasty crash reported by
3397 logon() and logoff(). It also fixes a nasty crash reported by
3394 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3398 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3395
3399
3396 * IPython/iplib.py (complete): got auto-completion to work with
3400 * IPython/iplib.py (complete): got auto-completion to work with
3397 automagic (I had wanted this for a long time).
3401 automagic (I had wanted this for a long time).
3398
3402
3399 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3403 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3400 to @file, since file() is now a builtin and clashes with automagic
3404 to @file, since file() is now a builtin and clashes with automagic
3401 for @file.
3405 for @file.
3402
3406
3403 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3407 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3404 of this was previously in iplib, which had grown to more than 2000
3408 of this was previously in iplib, which had grown to more than 2000
3405 lines, way too long. No new functionality, but it makes managing
3409 lines, way too long. No new functionality, but it makes managing
3406 the code a bit easier.
3410 the code a bit easier.
3407
3411
3408 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3412 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3409 information to crash reports.
3413 information to crash reports.
3410
3414
3411 2002-02-12 Fernando Perez <fperez@colorado.edu>
3415 2002-02-12 Fernando Perez <fperez@colorado.edu>
3412
3416
3413 * Released 0.2.5.
3417 * Released 0.2.5.
3414
3418
3415 2002-02-11 Fernando Perez <fperez@colorado.edu>
3419 2002-02-11 Fernando Perez <fperez@colorado.edu>
3416
3420
3417 * Wrote a relatively complete Windows installer. It puts
3421 * Wrote a relatively complete Windows installer. It puts
3418 everything in place, creates Start Menu entries and fixes the
3422 everything in place, creates Start Menu entries and fixes the
3419 color issues. Nothing fancy, but it works.
3423 color issues. Nothing fancy, but it works.
3420
3424
3421 2002-02-10 Fernando Perez <fperez@colorado.edu>
3425 2002-02-10 Fernando Perez <fperez@colorado.edu>
3422
3426
3423 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3427 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3424 os.path.expanduser() call so that we can type @run ~/myfile.py and
3428 os.path.expanduser() call so that we can type @run ~/myfile.py and
3425 have thigs work as expected.
3429 have thigs work as expected.
3426
3430
3427 * IPython/genutils.py (page): fixed exception handling so things
3431 * IPython/genutils.py (page): fixed exception handling so things
3428 work both in Unix and Windows correctly. Quitting a pager triggers
3432 work both in Unix and Windows correctly. Quitting a pager triggers
3429 an IOError/broken pipe in Unix, and in windows not finding a pager
3433 an IOError/broken pipe in Unix, and in windows not finding a pager
3430 is also an IOError, so I had to actually look at the return value
3434 is also an IOError, so I had to actually look at the return value
3431 of the exception, not just the exception itself. Should be ok now.
3435 of the exception, not just the exception itself. Should be ok now.
3432
3436
3433 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3437 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3434 modified to allow case-insensitive color scheme changes.
3438 modified to allow case-insensitive color scheme changes.
3435
3439
3436 2002-02-09 Fernando Perez <fperez@colorado.edu>
3440 2002-02-09 Fernando Perez <fperez@colorado.edu>
3437
3441
3438 * IPython/genutils.py (native_line_ends): new function to leave
3442 * IPython/genutils.py (native_line_ends): new function to leave
3439 user config files with os-native line-endings.
3443 user config files with os-native line-endings.
3440
3444
3441 * README and manual updates.
3445 * README and manual updates.
3442
3446
3443 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3447 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3444 instead of StringType to catch Unicode strings.
3448 instead of StringType to catch Unicode strings.
3445
3449
3446 * IPython/genutils.py (filefind): fixed bug for paths with
3450 * IPython/genutils.py (filefind): fixed bug for paths with
3447 embedded spaces (very common in Windows).
3451 embedded spaces (very common in Windows).
3448
3452
3449 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3453 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3450 files under Windows, so that they get automatically associated
3454 files under Windows, so that they get automatically associated
3451 with a text editor. Windows makes it a pain to handle
3455 with a text editor. Windows makes it a pain to handle
3452 extension-less files.
3456 extension-less files.
3453
3457
3454 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3458 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3455 warning about readline only occur for Posix. In Windows there's no
3459 warning about readline only occur for Posix. In Windows there's no
3456 way to get readline, so why bother with the warning.
3460 way to get readline, so why bother with the warning.
3457
3461
3458 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3462 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3459 for __str__ instead of dir(self), since dir() changed in 2.2.
3463 for __str__ instead of dir(self), since dir() changed in 2.2.
3460
3464
3461 * Ported to Windows! Tested on XP, I suspect it should work fine
3465 * Ported to Windows! Tested on XP, I suspect it should work fine
3462 on NT/2000, but I don't think it will work on 98 et al. That
3466 on NT/2000, but I don't think it will work on 98 et al. That
3463 series of Windows is such a piece of junk anyway that I won't try
3467 series of Windows is such a piece of junk anyway that I won't try
3464 porting it there. The XP port was straightforward, showed a few
3468 porting it there. The XP port was straightforward, showed a few
3465 bugs here and there (fixed all), in particular some string
3469 bugs here and there (fixed all), in particular some string
3466 handling stuff which required considering Unicode strings (which
3470 handling stuff which required considering Unicode strings (which
3467 Windows uses). This is good, but hasn't been too tested :) No
3471 Windows uses). This is good, but hasn't been too tested :) No
3468 fancy installer yet, I'll put a note in the manual so people at
3472 fancy installer yet, I'll put a note in the manual so people at
3469 least make manually a shortcut.
3473 least make manually a shortcut.
3470
3474
3471 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3475 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3472 into a single one, "colors". This now controls both prompt and
3476 into a single one, "colors". This now controls both prompt and
3473 exception color schemes, and can be changed both at startup
3477 exception color schemes, and can be changed both at startup
3474 (either via command-line switches or via ipythonrc files) and at
3478 (either via command-line switches or via ipythonrc files) and at
3475 runtime, with @colors.
3479 runtime, with @colors.
3476 (Magic.magic_run): renamed @prun to @run and removed the old
3480 (Magic.magic_run): renamed @prun to @run and removed the old
3477 @run. The two were too similar to warrant keeping both.
3481 @run. The two were too similar to warrant keeping both.
3478
3482
3479 2002-02-03 Fernando Perez <fperez@colorado.edu>
3483 2002-02-03 Fernando Perez <fperez@colorado.edu>
3480
3484
3481 * IPython/iplib.py (install_first_time): Added comment on how to
3485 * IPython/iplib.py (install_first_time): Added comment on how to
3482 configure the color options for first-time users. Put a <return>
3486 configure the color options for first-time users. Put a <return>
3483 request at the end so that small-terminal users get a chance to
3487 request at the end so that small-terminal users get a chance to
3484 read the startup info.
3488 read the startup info.
3485
3489
3486 2002-01-23 Fernando Perez <fperez@colorado.edu>
3490 2002-01-23 Fernando Perez <fperez@colorado.edu>
3487
3491
3488 * IPython/iplib.py (CachedOutput.update): Changed output memory
3492 * IPython/iplib.py (CachedOutput.update): Changed output memory
3489 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3493 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3490 input history we still use _i. Did this b/c these variable are
3494 input history we still use _i. Did this b/c these variable are
3491 very commonly used in interactive work, so the less we need to
3495 very commonly used in interactive work, so the less we need to
3492 type the better off we are.
3496 type the better off we are.
3493 (Magic.magic_prun): updated @prun to better handle the namespaces
3497 (Magic.magic_prun): updated @prun to better handle the namespaces
3494 the file will run in, including a fix for __name__ not being set
3498 the file will run in, including a fix for __name__ not being set
3495 before.
3499 before.
3496
3500
3497 2002-01-20 Fernando Perez <fperez@colorado.edu>
3501 2002-01-20 Fernando Perez <fperez@colorado.edu>
3498
3502
3499 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3503 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3500 extra garbage for Python 2.2. Need to look more carefully into
3504 extra garbage for Python 2.2. Need to look more carefully into
3501 this later.
3505 this later.
3502
3506
3503 2002-01-19 Fernando Perez <fperez@colorado.edu>
3507 2002-01-19 Fernando Perez <fperez@colorado.edu>
3504
3508
3505 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3509 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3506 display SyntaxError exceptions properly formatted when they occur
3510 display SyntaxError exceptions properly formatted when they occur
3507 (they can be triggered by imported code).
3511 (they can be triggered by imported code).
3508
3512
3509 2002-01-18 Fernando Perez <fperez@colorado.edu>
3513 2002-01-18 Fernando Perez <fperez@colorado.edu>
3510
3514
3511 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3515 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3512 SyntaxError exceptions are reported nicely formatted, instead of
3516 SyntaxError exceptions are reported nicely formatted, instead of
3513 spitting out only offset information as before.
3517 spitting out only offset information as before.
3514 (Magic.magic_prun): Added the @prun function for executing
3518 (Magic.magic_prun): Added the @prun function for executing
3515 programs with command line args inside IPython.
3519 programs with command line args inside IPython.
3516
3520
3517 2002-01-16 Fernando Perez <fperez@colorado.edu>
3521 2002-01-16 Fernando Perez <fperez@colorado.edu>
3518
3522
3519 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3523 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3520 to *not* include the last item given in a range. This brings their
3524 to *not* include the last item given in a range. This brings their
3521 behavior in line with Python's slicing:
3525 behavior in line with Python's slicing:
3522 a[n1:n2] -> a[n1]...a[n2-1]
3526 a[n1:n2] -> a[n1]...a[n2-1]
3523 It may be a bit less convenient, but I prefer to stick to Python's
3527 It may be a bit less convenient, but I prefer to stick to Python's
3524 conventions *everywhere*, so users never have to wonder.
3528 conventions *everywhere*, so users never have to wonder.
3525 (Magic.magic_macro): Added @macro function to ease the creation of
3529 (Magic.magic_macro): Added @macro function to ease the creation of
3526 macros.
3530 macros.
3527
3531
3528 2002-01-05 Fernando Perez <fperez@colorado.edu>
3532 2002-01-05 Fernando Perez <fperez@colorado.edu>
3529
3533
3530 * Released 0.2.4.
3534 * Released 0.2.4.
3531
3535
3532 * IPython/iplib.py (Magic.magic_pdef):
3536 * IPython/iplib.py (Magic.magic_pdef):
3533 (InteractiveShell.safe_execfile): report magic lines and error
3537 (InteractiveShell.safe_execfile): report magic lines and error
3534 lines without line numbers so one can easily copy/paste them for
3538 lines without line numbers so one can easily copy/paste them for
3535 re-execution.
3539 re-execution.
3536
3540
3537 * Updated manual with recent changes.
3541 * Updated manual with recent changes.
3538
3542
3539 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3543 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3540 docstring printing when class? is called. Very handy for knowing
3544 docstring printing when class? is called. Very handy for knowing
3541 how to create class instances (as long as __init__ is well
3545 how to create class instances (as long as __init__ is well
3542 documented, of course :)
3546 documented, of course :)
3543 (Magic.magic_doc): print both class and constructor docstrings.
3547 (Magic.magic_doc): print both class and constructor docstrings.
3544 (Magic.magic_pdef): give constructor info if passed a class and
3548 (Magic.magic_pdef): give constructor info if passed a class and
3545 __call__ info for callable object instances.
3549 __call__ info for callable object instances.
3546
3550
3547 2002-01-04 Fernando Perez <fperez@colorado.edu>
3551 2002-01-04 Fernando Perez <fperez@colorado.edu>
3548
3552
3549 * Made deep_reload() off by default. It doesn't always work
3553 * Made deep_reload() off by default. It doesn't always work
3550 exactly as intended, so it's probably safer to have it off. It's
3554 exactly as intended, so it's probably safer to have it off. It's
3551 still available as dreload() anyway, so nothing is lost.
3555 still available as dreload() anyway, so nothing is lost.
3552
3556
3553 2002-01-02 Fernando Perez <fperez@colorado.edu>
3557 2002-01-02 Fernando Perez <fperez@colorado.edu>
3554
3558
3555 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3559 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3556 so I wanted an updated release).
3560 so I wanted an updated release).
3557
3561
3558 2001-12-27 Fernando Perez <fperez@colorado.edu>
3562 2001-12-27 Fernando Perez <fperez@colorado.edu>
3559
3563
3560 * IPython/iplib.py (InteractiveShell.interact): Added the original
3564 * IPython/iplib.py (InteractiveShell.interact): Added the original
3561 code from 'code.py' for this module in order to change the
3565 code from 'code.py' for this module in order to change the
3562 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3566 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3563 the history cache would break when the user hit Ctrl-C, and
3567 the history cache would break when the user hit Ctrl-C, and
3564 interact() offers no way to add any hooks to it.
3568 interact() offers no way to add any hooks to it.
3565
3569
3566 2001-12-23 Fernando Perez <fperez@colorado.edu>
3570 2001-12-23 Fernando Perez <fperez@colorado.edu>
3567
3571
3568 * setup.py: added check for 'MANIFEST' before trying to remove
3572 * setup.py: added check for 'MANIFEST' before trying to remove
3569 it. Thanks to Sean Reifschneider.
3573 it. Thanks to Sean Reifschneider.
3570
3574
3571 2001-12-22 Fernando Perez <fperez@colorado.edu>
3575 2001-12-22 Fernando Perez <fperez@colorado.edu>
3572
3576
3573 * Released 0.2.2.
3577 * Released 0.2.2.
3574
3578
3575 * Finished (reasonably) writing the manual. Later will add the
3579 * Finished (reasonably) writing the manual. Later will add the
3576 python-standard navigation stylesheets, but for the time being
3580 python-standard navigation stylesheets, but for the time being
3577 it's fairly complete. Distribution will include html and pdf
3581 it's fairly complete. Distribution will include html and pdf
3578 versions.
3582 versions.
3579
3583
3580 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3584 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3581 (MayaVi author).
3585 (MayaVi author).
3582
3586
3583 2001-12-21 Fernando Perez <fperez@colorado.edu>
3587 2001-12-21 Fernando Perez <fperez@colorado.edu>
3584
3588
3585 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3589 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3586 good public release, I think (with the manual and the distutils
3590 good public release, I think (with the manual and the distutils
3587 installer). The manual can use some work, but that can go
3591 installer). The manual can use some work, but that can go
3588 slowly. Otherwise I think it's quite nice for end users. Next
3592 slowly. Otherwise I think it's quite nice for end users. Next
3589 summer, rewrite the guts of it...
3593 summer, rewrite the guts of it...
3590
3594
3591 * Changed format of ipythonrc files to use whitespace as the
3595 * Changed format of ipythonrc files to use whitespace as the
3592 separator instead of an explicit '='. Cleaner.
3596 separator instead of an explicit '='. Cleaner.
3593
3597
3594 2001-12-20 Fernando Perez <fperez@colorado.edu>
3598 2001-12-20 Fernando Perez <fperez@colorado.edu>
3595
3599
3596 * Started a manual in LyX. For now it's just a quick merge of the
3600 * Started a manual in LyX. For now it's just a quick merge of the
3597 various internal docstrings and READMEs. Later it may grow into a
3601 various internal docstrings and READMEs. Later it may grow into a
3598 nice, full-blown manual.
3602 nice, full-blown manual.
3599
3603
3600 * Set up a distutils based installer. Installation should now be
3604 * Set up a distutils based installer. Installation should now be
3601 trivially simple for end-users.
3605 trivially simple for end-users.
3602
3606
3603 2001-12-11 Fernando Perez <fperez@colorado.edu>
3607 2001-12-11 Fernando Perez <fperez@colorado.edu>
3604
3608
3605 * Released 0.2.0. First public release, announced it at
3609 * Released 0.2.0. First public release, announced it at
3606 comp.lang.python. From now on, just bugfixes...
3610 comp.lang.python. From now on, just bugfixes...
3607
3611
3608 * Went through all the files, set copyright/license notices and
3612 * Went through all the files, set copyright/license notices and
3609 cleaned up things. Ready for release.
3613 cleaned up things. Ready for release.
3610
3614
3611 2001-12-10 Fernando Perez <fperez@colorado.edu>
3615 2001-12-10 Fernando Perez <fperez@colorado.edu>
3612
3616
3613 * Changed the first-time installer not to use tarfiles. It's more
3617 * Changed the first-time installer not to use tarfiles. It's more
3614 robust now and less unix-dependent. Also makes it easier for
3618 robust now and less unix-dependent. Also makes it easier for
3615 people to later upgrade versions.
3619 people to later upgrade versions.
3616
3620
3617 * Changed @exit to @abort to reflect the fact that it's pretty
3621 * Changed @exit to @abort to reflect the fact that it's pretty
3618 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3622 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3619 becomes significant only when IPyhton is embedded: in that case,
3623 becomes significant only when IPyhton is embedded: in that case,
3620 C-D closes IPython only, but @abort kills the enclosing program
3624 C-D closes IPython only, but @abort kills the enclosing program
3621 too (unless it had called IPython inside a try catching
3625 too (unless it had called IPython inside a try catching
3622 SystemExit).
3626 SystemExit).
3623
3627
3624 * Created Shell module which exposes the actuall IPython Shell
3628 * Created Shell module which exposes the actuall IPython Shell
3625 classes, currently the normal and the embeddable one. This at
3629 classes, currently the normal and the embeddable one. This at
3626 least offers a stable interface we won't need to change when
3630 least offers a stable interface we won't need to change when
3627 (later) the internals are rewritten. That rewrite will be confined
3631 (later) the internals are rewritten. That rewrite will be confined
3628 to iplib and ipmaker, but the Shell interface should remain as is.
3632 to iplib and ipmaker, but the Shell interface should remain as is.
3629
3633
3630 * Added embed module which offers an embeddable IPShell object,
3634 * Added embed module which offers an embeddable IPShell object,
3631 useful to fire up IPython *inside* a running program. Great for
3635 useful to fire up IPython *inside* a running program. Great for
3632 debugging or dynamical data analysis.
3636 debugging or dynamical data analysis.
3633
3637
3634 2001-12-08 Fernando Perez <fperez@colorado.edu>
3638 2001-12-08 Fernando Perez <fperez@colorado.edu>
3635
3639
3636 * Fixed small bug preventing seeing info from methods of defined
3640 * Fixed small bug preventing seeing info from methods of defined
3637 objects (incorrect namespace in _ofind()).
3641 objects (incorrect namespace in _ofind()).
3638
3642
3639 * Documentation cleanup. Moved the main usage docstrings to a
3643 * Documentation cleanup. Moved the main usage docstrings to a
3640 separate file, usage.py (cleaner to maintain, and hopefully in the
3644 separate file, usage.py (cleaner to maintain, and hopefully in the
3641 future some perlpod-like way of producing interactive, man and
3645 future some perlpod-like way of producing interactive, man and
3642 html docs out of it will be found).
3646 html docs out of it will be found).
3643
3647
3644 * Added @profile to see your profile at any time.
3648 * Added @profile to see your profile at any time.
3645
3649
3646 * Added @p as an alias for 'print'. It's especially convenient if
3650 * Added @p as an alias for 'print'. It's especially convenient if
3647 using automagic ('p x' prints x).
3651 using automagic ('p x' prints x).
3648
3652
3649 * Small cleanups and fixes after a pychecker run.
3653 * Small cleanups and fixes after a pychecker run.
3650
3654
3651 * Changed the @cd command to handle @cd - and @cd -<n> for
3655 * Changed the @cd command to handle @cd - and @cd -<n> for
3652 visiting any directory in _dh.
3656 visiting any directory in _dh.
3653
3657
3654 * Introduced _dh, a history of visited directories. @dhist prints
3658 * Introduced _dh, a history of visited directories. @dhist prints
3655 it out with numbers.
3659 it out with numbers.
3656
3660
3657 2001-12-07 Fernando Perez <fperez@colorado.edu>
3661 2001-12-07 Fernando Perez <fperez@colorado.edu>
3658
3662
3659 * Released 0.1.22
3663 * Released 0.1.22
3660
3664
3661 * Made initialization a bit more robust against invalid color
3665 * Made initialization a bit more robust against invalid color
3662 options in user input (exit, not traceback-crash).
3666 options in user input (exit, not traceback-crash).
3663
3667
3664 * Changed the bug crash reporter to write the report only in the
3668 * Changed the bug crash reporter to write the report only in the
3665 user's .ipython directory. That way IPython won't litter people's
3669 user's .ipython directory. That way IPython won't litter people's
3666 hard disks with crash files all over the place. Also print on
3670 hard disks with crash files all over the place. Also print on
3667 screen the necessary mail command.
3671 screen the necessary mail command.
3668
3672
3669 * With the new ultraTB, implemented LightBG color scheme for light
3673 * With the new ultraTB, implemented LightBG color scheme for light
3670 background terminals. A lot of people like white backgrounds, so I
3674 background terminals. A lot of people like white backgrounds, so I
3671 guess we should at least give them something readable.
3675 guess we should at least give them something readable.
3672
3676
3673 2001-12-06 Fernando Perez <fperez@colorado.edu>
3677 2001-12-06 Fernando Perez <fperez@colorado.edu>
3674
3678
3675 * Modified the structure of ultraTB. Now there's a proper class
3679 * Modified the structure of ultraTB. Now there's a proper class
3676 for tables of color schemes which allow adding schemes easily and
3680 for tables of color schemes which allow adding schemes easily and
3677 switching the active scheme without creating a new instance every
3681 switching the active scheme without creating a new instance every
3678 time (which was ridiculous). The syntax for creating new schemes
3682 time (which was ridiculous). The syntax for creating new schemes
3679 is also cleaner. I think ultraTB is finally done, with a clean
3683 is also cleaner. I think ultraTB is finally done, with a clean
3680 class structure. Names are also much cleaner (now there's proper
3684 class structure. Names are also much cleaner (now there's proper
3681 color tables, no need for every variable to also have 'color' in
3685 color tables, no need for every variable to also have 'color' in
3682 its name).
3686 its name).
3683
3687
3684 * Broke down genutils into separate files. Now genutils only
3688 * Broke down genutils into separate files. Now genutils only
3685 contains utility functions, and classes have been moved to their
3689 contains utility functions, and classes have been moved to their
3686 own files (they had enough independent functionality to warrant
3690 own files (they had enough independent functionality to warrant
3687 it): ConfigLoader, OutputTrap, Struct.
3691 it): ConfigLoader, OutputTrap, Struct.
3688
3692
3689 2001-12-05 Fernando Perez <fperez@colorado.edu>
3693 2001-12-05 Fernando Perez <fperez@colorado.edu>
3690
3694
3691 * IPython turns 21! Released version 0.1.21, as a candidate for
3695 * IPython turns 21! Released version 0.1.21, as a candidate for
3692 public consumption. If all goes well, release in a few days.
3696 public consumption. If all goes well, release in a few days.
3693
3697
3694 * Fixed path bug (files in Extensions/ directory wouldn't be found
3698 * Fixed path bug (files in Extensions/ directory wouldn't be found
3695 unless IPython/ was explicitly in sys.path).
3699 unless IPython/ was explicitly in sys.path).
3696
3700
3697 * Extended the FlexCompleter class as MagicCompleter to allow
3701 * Extended the FlexCompleter class as MagicCompleter to allow
3698 completion of @-starting lines.
3702 completion of @-starting lines.
3699
3703
3700 * Created __release__.py file as a central repository for release
3704 * Created __release__.py file as a central repository for release
3701 info that other files can read from.
3705 info that other files can read from.
3702
3706
3703 * Fixed small bug in logging: when logging was turned on in
3707 * Fixed small bug in logging: when logging was turned on in
3704 mid-session, old lines with special meanings (!@?) were being
3708 mid-session, old lines with special meanings (!@?) were being
3705 logged without the prepended comment, which is necessary since
3709 logged without the prepended comment, which is necessary since
3706 they are not truly valid python syntax. This should make session
3710 they are not truly valid python syntax. This should make session
3707 restores produce less errors.
3711 restores produce less errors.
3708
3712
3709 * The namespace cleanup forced me to make a FlexCompleter class
3713 * The namespace cleanup forced me to make a FlexCompleter class
3710 which is nothing but a ripoff of rlcompleter, but with selectable
3714 which is nothing but a ripoff of rlcompleter, but with selectable
3711 namespace (rlcompleter only works in __main__.__dict__). I'll try
3715 namespace (rlcompleter only works in __main__.__dict__). I'll try
3712 to submit a note to the authors to see if this change can be
3716 to submit a note to the authors to see if this change can be
3713 incorporated in future rlcompleter releases (Dec.6: done)
3717 incorporated in future rlcompleter releases (Dec.6: done)
3714
3718
3715 * More fixes to namespace handling. It was a mess! Now all
3719 * More fixes to namespace handling. It was a mess! Now all
3716 explicit references to __main__.__dict__ are gone (except when
3720 explicit references to __main__.__dict__ are gone (except when
3717 really needed) and everything is handled through the namespace
3721 really needed) and everything is handled through the namespace
3718 dicts in the IPython instance. We seem to be getting somewhere
3722 dicts in the IPython instance. We seem to be getting somewhere
3719 with this, finally...
3723 with this, finally...
3720
3724
3721 * Small documentation updates.
3725 * Small documentation updates.
3722
3726
3723 * Created the Extensions directory under IPython (with an
3727 * Created the Extensions directory under IPython (with an
3724 __init__.py). Put the PhysicalQ stuff there. This directory should
3728 __init__.py). Put the PhysicalQ stuff there. This directory should
3725 be used for all special-purpose extensions.
3729 be used for all special-purpose extensions.
3726
3730
3727 * File renaming:
3731 * File renaming:
3728 ipythonlib --> ipmaker
3732 ipythonlib --> ipmaker
3729 ipplib --> iplib
3733 ipplib --> iplib
3730 This makes a bit more sense in terms of what these files actually do.
3734 This makes a bit more sense in terms of what these files actually do.
3731
3735
3732 * Moved all the classes and functions in ipythonlib to ipplib, so
3736 * Moved all the classes and functions in ipythonlib to ipplib, so
3733 now ipythonlib only has make_IPython(). This will ease up its
3737 now ipythonlib only has make_IPython(). This will ease up its
3734 splitting in smaller functional chunks later.
3738 splitting in smaller functional chunks later.
3735
3739
3736 * Cleaned up (done, I think) output of @whos. Better column
3740 * Cleaned up (done, I think) output of @whos. Better column
3737 formatting, and now shows str(var) for as much as it can, which is
3741 formatting, and now shows str(var) for as much as it can, which is
3738 typically what one gets with a 'print var'.
3742 typically what one gets with a 'print var'.
3739
3743
3740 2001-12-04 Fernando Perez <fperez@colorado.edu>
3744 2001-12-04 Fernando Perez <fperez@colorado.edu>
3741
3745
3742 * Fixed namespace problems. Now builtin/IPyhton/user names get
3746 * Fixed namespace problems. Now builtin/IPyhton/user names get
3743 properly reported in their namespace. Internal namespace handling
3747 properly reported in their namespace. Internal namespace handling
3744 is finally getting decent (not perfect yet, but much better than
3748 is finally getting decent (not perfect yet, but much better than
3745 the ad-hoc mess we had).
3749 the ad-hoc mess we had).
3746
3750
3747 * Removed -exit option. If people just want to run a python
3751 * Removed -exit option. If people just want to run a python
3748 script, that's what the normal interpreter is for. Less
3752 script, that's what the normal interpreter is for. Less
3749 unnecessary options, less chances for bugs.
3753 unnecessary options, less chances for bugs.
3750
3754
3751 * Added a crash handler which generates a complete post-mortem if
3755 * Added a crash handler which generates a complete post-mortem if
3752 IPython crashes. This will help a lot in tracking bugs down the
3756 IPython crashes. This will help a lot in tracking bugs down the
3753 road.
3757 road.
3754
3758
3755 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
3759 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
3756 which were boud to functions being reassigned would bypass the
3760 which were boud to functions being reassigned would bypass the
3757 logger, breaking the sync of _il with the prompt counter. This
3761 logger, breaking the sync of _il with the prompt counter. This
3758 would then crash IPython later when a new line was logged.
3762 would then crash IPython later when a new line was logged.
3759
3763
3760 2001-12-02 Fernando Perez <fperez@colorado.edu>
3764 2001-12-02 Fernando Perez <fperez@colorado.edu>
3761
3765
3762 * Made IPython a package. This means people don't have to clutter
3766 * Made IPython a package. This means people don't have to clutter
3763 their sys.path with yet another directory. Changed the INSTALL
3767 their sys.path with yet another directory. Changed the INSTALL
3764 file accordingly.
3768 file accordingly.
3765
3769
3766 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
3770 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
3767 sorts its output (so @who shows it sorted) and @whos formats the
3771 sorts its output (so @who shows it sorted) and @whos formats the
3768 table according to the width of the first column. Nicer, easier to
3772 table according to the width of the first column. Nicer, easier to
3769 read. Todo: write a generic table_format() which takes a list of
3773 read. Todo: write a generic table_format() which takes a list of
3770 lists and prints it nicely formatted, with optional row/column
3774 lists and prints it nicely formatted, with optional row/column
3771 separators and proper padding and justification.
3775 separators and proper padding and justification.
3772
3776
3773 * Released 0.1.20
3777 * Released 0.1.20
3774
3778
3775 * Fixed bug in @log which would reverse the inputcache list (a
3779 * Fixed bug in @log which would reverse the inputcache list (a
3776 copy operation was missing).
3780 copy operation was missing).
3777
3781
3778 * Code cleanup. @config was changed to use page(). Better, since
3782 * Code cleanup. @config was changed to use page(). Better, since
3779 its output is always quite long.
3783 its output is always quite long.
3780
3784
3781 * Itpl is back as a dependency. I was having too many problems
3785 * Itpl is back as a dependency. I was having too many problems
3782 getting the parametric aliases to work reliably, and it's just
3786 getting the parametric aliases to work reliably, and it's just
3783 easier to code weird string operations with it than playing %()s
3787 easier to code weird string operations with it than playing %()s
3784 games. It's only ~6k, so I don't think it's too big a deal.
3788 games. It's only ~6k, so I don't think it's too big a deal.
3785
3789
3786 * Found (and fixed) a very nasty bug with history. !lines weren't
3790 * Found (and fixed) a very nasty bug with history. !lines weren't
3787 getting cached, and the out of sync caches would crash
3791 getting cached, and the out of sync caches would crash
3788 IPython. Fixed it by reorganizing the prefilter/handlers/logger
3792 IPython. Fixed it by reorganizing the prefilter/handlers/logger
3789 division of labor a bit better. Bug fixed, cleaner structure.
3793 division of labor a bit better. Bug fixed, cleaner structure.
3790
3794
3791 2001-12-01 Fernando Perez <fperez@colorado.edu>
3795 2001-12-01 Fernando Perez <fperez@colorado.edu>
3792
3796
3793 * Released 0.1.19
3797 * Released 0.1.19
3794
3798
3795 * Added option -n to @hist to prevent line number printing. Much
3799 * Added option -n to @hist to prevent line number printing. Much
3796 easier to copy/paste code this way.
3800 easier to copy/paste code this way.
3797
3801
3798 * Created global _il to hold the input list. Allows easy
3802 * Created global _il to hold the input list. Allows easy
3799 re-execution of blocks of code by slicing it (inspired by Janko's
3803 re-execution of blocks of code by slicing it (inspired by Janko's
3800 comment on 'macros').
3804 comment on 'macros').
3801
3805
3802 * Small fixes and doc updates.
3806 * Small fixes and doc updates.
3803
3807
3804 * Rewrote @history function (was @h). Renamed it to @hist, @h is
3808 * Rewrote @history function (was @h). Renamed it to @hist, @h is
3805 much too fragile with automagic. Handles properly multi-line
3809 much too fragile with automagic. Handles properly multi-line
3806 statements and takes parameters.
3810 statements and takes parameters.
3807
3811
3808 2001-11-30 Fernando Perez <fperez@colorado.edu>
3812 2001-11-30 Fernando Perez <fperez@colorado.edu>
3809
3813
3810 * Version 0.1.18 released.
3814 * Version 0.1.18 released.
3811
3815
3812 * Fixed nasty namespace bug in initial module imports.
3816 * Fixed nasty namespace bug in initial module imports.
3813
3817
3814 * Added copyright/license notes to all code files (except
3818 * Added copyright/license notes to all code files (except
3815 DPyGetOpt). For the time being, LGPL. That could change.
3819 DPyGetOpt). For the time being, LGPL. That could change.
3816
3820
3817 * Rewrote a much nicer README, updated INSTALL, cleaned up
3821 * Rewrote a much nicer README, updated INSTALL, cleaned up
3818 ipythonrc-* samples.
3822 ipythonrc-* samples.
3819
3823
3820 * Overall code/documentation cleanup. Basically ready for
3824 * Overall code/documentation cleanup. Basically ready for
3821 release. Only remaining thing: licence decision (LGPL?).
3825 release. Only remaining thing: licence decision (LGPL?).
3822
3826
3823 * Converted load_config to a class, ConfigLoader. Now recursion
3827 * Converted load_config to a class, ConfigLoader. Now recursion
3824 control is better organized. Doesn't include the same file twice.
3828 control is better organized. Doesn't include the same file twice.
3825
3829
3826 2001-11-29 Fernando Perez <fperez@colorado.edu>
3830 2001-11-29 Fernando Perez <fperez@colorado.edu>
3827
3831
3828 * Got input history working. Changed output history variables from
3832 * Got input history working. Changed output history variables from
3829 _p to _o so that _i is for input and _o for output. Just cleaner
3833 _p to _o so that _i is for input and _o for output. Just cleaner
3830 convention.
3834 convention.
3831
3835
3832 * Implemented parametric aliases. This pretty much allows the
3836 * Implemented parametric aliases. This pretty much allows the
3833 alias system to offer full-blown shell convenience, I think.
3837 alias system to offer full-blown shell convenience, I think.
3834
3838
3835 * Version 0.1.17 released, 0.1.18 opened.
3839 * Version 0.1.17 released, 0.1.18 opened.
3836
3840
3837 * dot_ipython/ipythonrc (alias): added documentation.
3841 * dot_ipython/ipythonrc (alias): added documentation.
3838 (xcolor): Fixed small bug (xcolors -> xcolor)
3842 (xcolor): Fixed small bug (xcolors -> xcolor)
3839
3843
3840 * Changed the alias system. Now alias is a magic command to define
3844 * Changed the alias system. Now alias is a magic command to define
3841 aliases just like the shell. Rationale: the builtin magics should
3845 aliases just like the shell. Rationale: the builtin magics should
3842 be there for things deeply connected to IPython's
3846 be there for things deeply connected to IPython's
3843 architecture. And this is a much lighter system for what I think
3847 architecture. And this is a much lighter system for what I think
3844 is the really important feature: allowing users to define quickly
3848 is the really important feature: allowing users to define quickly
3845 magics that will do shell things for them, so they can customize
3849 magics that will do shell things for them, so they can customize
3846 IPython easily to match their work habits. If someone is really
3850 IPython easily to match their work habits. If someone is really
3847 desperate to have another name for a builtin alias, they can
3851 desperate to have another name for a builtin alias, they can
3848 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
3852 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
3849 works.
3853 works.
3850
3854
3851 2001-11-28 Fernando Perez <fperez@colorado.edu>
3855 2001-11-28 Fernando Perez <fperez@colorado.edu>
3852
3856
3853 * Changed @file so that it opens the source file at the proper
3857 * Changed @file so that it opens the source file at the proper
3854 line. Since it uses less, if your EDITOR environment is
3858 line. Since it uses less, if your EDITOR environment is
3855 configured, typing v will immediately open your editor of choice
3859 configured, typing v will immediately open your editor of choice
3856 right at the line where the object is defined. Not as quick as
3860 right at the line where the object is defined. Not as quick as
3857 having a direct @edit command, but for all intents and purposes it
3861 having a direct @edit command, but for all intents and purposes it
3858 works. And I don't have to worry about writing @edit to deal with
3862 works. And I don't have to worry about writing @edit to deal with
3859 all the editors, less does that.
3863 all the editors, less does that.
3860
3864
3861 * Version 0.1.16 released, 0.1.17 opened.
3865 * Version 0.1.16 released, 0.1.17 opened.
3862
3866
3863 * Fixed some nasty bugs in the page/page_dumb combo that could
3867 * Fixed some nasty bugs in the page/page_dumb combo that could
3864 crash IPython.
3868 crash IPython.
3865
3869
3866 2001-11-27 Fernando Perez <fperez@colorado.edu>
3870 2001-11-27 Fernando Perez <fperez@colorado.edu>
3867
3871
3868 * Version 0.1.15 released, 0.1.16 opened.
3872 * Version 0.1.15 released, 0.1.16 opened.
3869
3873
3870 * Finally got ? and ?? to work for undefined things: now it's
3874 * Finally got ? and ?? to work for undefined things: now it's
3871 possible to type {}.get? and get information about the get method
3875 possible to type {}.get? and get information about the get method
3872 of dicts, or os.path? even if only os is defined (so technically
3876 of dicts, or os.path? even if only os is defined (so technically
3873 os.path isn't). Works at any level. For example, after import os,
3877 os.path isn't). Works at any level. For example, after import os,
3874 os?, os.path?, os.path.abspath? all work. This is great, took some
3878 os?, os.path?, os.path.abspath? all work. This is great, took some
3875 work in _ofind.
3879 work in _ofind.
3876
3880
3877 * Fixed more bugs with logging. The sanest way to do it was to add
3881 * Fixed more bugs with logging. The sanest way to do it was to add
3878 to @log a 'mode' parameter. Killed two in one shot (this mode
3882 to @log a 'mode' parameter. Killed two in one shot (this mode
3879 option was a request of Janko's). I think it's finally clean
3883 option was a request of Janko's). I think it's finally clean
3880 (famous last words).
3884 (famous last words).
3881
3885
3882 * Added a page_dumb() pager which does a decent job of paging on
3886 * Added a page_dumb() pager which does a decent job of paging on
3883 screen, if better things (like less) aren't available. One less
3887 screen, if better things (like less) aren't available. One less
3884 unix dependency (someday maybe somebody will port this to
3888 unix dependency (someday maybe somebody will port this to
3885 windows).
3889 windows).
3886
3890
3887 * Fixed problem in magic_log: would lock of logging out if log
3891 * Fixed problem in magic_log: would lock of logging out if log
3888 creation failed (because it would still think it had succeeded).
3892 creation failed (because it would still think it had succeeded).
3889
3893
3890 * Improved the page() function using curses to auto-detect screen
3894 * Improved the page() function using curses to auto-detect screen
3891 size. Now it can make a much better decision on whether to print
3895 size. Now it can make a much better decision on whether to print
3892 or page a string. Option screen_length was modified: a value 0
3896 or page a string. Option screen_length was modified: a value 0
3893 means auto-detect, and that's the default now.
3897 means auto-detect, and that's the default now.
3894
3898
3895 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
3899 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
3896 go out. I'll test it for a few days, then talk to Janko about
3900 go out. I'll test it for a few days, then talk to Janko about
3897 licences and announce it.
3901 licences and announce it.
3898
3902
3899 * Fixed the length of the auto-generated ---> prompt which appears
3903 * Fixed the length of the auto-generated ---> prompt which appears
3900 for auto-parens and auto-quotes. Getting this right isn't trivial,
3904 for auto-parens and auto-quotes. Getting this right isn't trivial,
3901 with all the color escapes, different prompt types and optional
3905 with all the color escapes, different prompt types and optional
3902 separators. But it seems to be working in all the combinations.
3906 separators. But it seems to be working in all the combinations.
3903
3907
3904 2001-11-26 Fernando Perez <fperez@colorado.edu>
3908 2001-11-26 Fernando Perez <fperez@colorado.edu>
3905
3909
3906 * Wrote a regexp filter to get option types from the option names
3910 * Wrote a regexp filter to get option types from the option names
3907 string. This eliminates the need to manually keep two duplicate
3911 string. This eliminates the need to manually keep two duplicate
3908 lists.
3912 lists.
3909
3913
3910 * Removed the unneeded check_option_names. Now options are handled
3914 * Removed the unneeded check_option_names. Now options are handled
3911 in a much saner manner and it's easy to visually check that things
3915 in a much saner manner and it's easy to visually check that things
3912 are ok.
3916 are ok.
3913
3917
3914 * Updated version numbers on all files I modified to carry a
3918 * Updated version numbers on all files I modified to carry a
3915 notice so Janko and Nathan have clear version markers.
3919 notice so Janko and Nathan have clear version markers.
3916
3920
3917 * Updated docstring for ultraTB with my changes. I should send
3921 * Updated docstring for ultraTB with my changes. I should send
3918 this to Nathan.
3922 this to Nathan.
3919
3923
3920 * Lots of small fixes. Ran everything through pychecker again.
3924 * Lots of small fixes. Ran everything through pychecker again.
3921
3925
3922 * Made loading of deep_reload an cmd line option. If it's not too
3926 * Made loading of deep_reload an cmd line option. If it's not too
3923 kosher, now people can just disable it. With -nodeep_reload it's
3927 kosher, now people can just disable it. With -nodeep_reload it's
3924 still available as dreload(), it just won't overwrite reload().
3928 still available as dreload(), it just won't overwrite reload().
3925
3929
3926 * Moved many options to the no| form (-opt and -noopt
3930 * Moved many options to the no| form (-opt and -noopt
3927 accepted). Cleaner.
3931 accepted). Cleaner.
3928
3932
3929 * Changed magic_log so that if called with no parameters, it uses
3933 * Changed magic_log so that if called with no parameters, it uses
3930 'rotate' mode. That way auto-generated logs aren't automatically
3934 'rotate' mode. That way auto-generated logs aren't automatically
3931 over-written. For normal logs, now a backup is made if it exists
3935 over-written. For normal logs, now a backup is made if it exists
3932 (only 1 level of backups). A new 'backup' mode was added to the
3936 (only 1 level of backups). A new 'backup' mode was added to the
3933 Logger class to support this. This was a request by Janko.
3937 Logger class to support this. This was a request by Janko.
3934
3938
3935 * Added @logoff/@logon to stop/restart an active log.
3939 * Added @logoff/@logon to stop/restart an active log.
3936
3940
3937 * Fixed a lot of bugs in log saving/replay. It was pretty
3941 * Fixed a lot of bugs in log saving/replay. It was pretty
3938 broken. Now special lines (!@,/) appear properly in the command
3942 broken. Now special lines (!@,/) appear properly in the command
3939 history after a log replay.
3943 history after a log replay.
3940
3944
3941 * Tried and failed to implement full session saving via pickle. My
3945 * Tried and failed to implement full session saving via pickle. My
3942 idea was to pickle __main__.__dict__, but modules can't be
3946 idea was to pickle __main__.__dict__, but modules can't be
3943 pickled. This would be a better alternative to replaying logs, but
3947 pickled. This would be a better alternative to replaying logs, but
3944 seems quite tricky to get to work. Changed -session to be called
3948 seems quite tricky to get to work. Changed -session to be called
3945 -logplay, which more accurately reflects what it does. And if we
3949 -logplay, which more accurately reflects what it does. And if we
3946 ever get real session saving working, -session is now available.
3950 ever get real session saving working, -session is now available.
3947
3951
3948 * Implemented color schemes for prompts also. As for tracebacks,
3952 * Implemented color schemes for prompts also. As for tracebacks,
3949 currently only NoColor and Linux are supported. But now the
3953 currently only NoColor and Linux are supported. But now the
3950 infrastructure is in place, based on a generic ColorScheme
3954 infrastructure is in place, based on a generic ColorScheme
3951 class. So writing and activating new schemes both for the prompts
3955 class. So writing and activating new schemes both for the prompts
3952 and the tracebacks should be straightforward.
3956 and the tracebacks should be straightforward.
3953
3957
3954 * Version 0.1.13 released, 0.1.14 opened.
3958 * Version 0.1.13 released, 0.1.14 opened.
3955
3959
3956 * Changed handling of options for output cache. Now counter is
3960 * Changed handling of options for output cache. Now counter is
3957 hardwired starting at 1 and one specifies the maximum number of
3961 hardwired starting at 1 and one specifies the maximum number of
3958 entries *in the outcache* (not the max prompt counter). This is
3962 entries *in the outcache* (not the max prompt counter). This is
3959 much better, since many statements won't increase the cache
3963 much better, since many statements won't increase the cache
3960 count. It also eliminated some confusing options, now there's only
3964 count. It also eliminated some confusing options, now there's only
3961 one: cache_size.
3965 one: cache_size.
3962
3966
3963 * Added 'alias' magic function and magic_alias option in the
3967 * Added 'alias' magic function and magic_alias option in the
3964 ipythonrc file. Now the user can easily define whatever names he
3968 ipythonrc file. Now the user can easily define whatever names he
3965 wants for the magic functions without having to play weird
3969 wants for the magic functions without having to play weird
3966 namespace games. This gives IPython a real shell-like feel.
3970 namespace games. This gives IPython a real shell-like feel.
3967
3971
3968 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
3972 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
3969 @ or not).
3973 @ or not).
3970
3974
3971 This was one of the last remaining 'visible' bugs (that I know
3975 This was one of the last remaining 'visible' bugs (that I know
3972 of). I think if I can clean up the session loading so it works
3976 of). I think if I can clean up the session loading so it works
3973 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
3977 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
3974 about licensing).
3978 about licensing).
3975
3979
3976 2001-11-25 Fernando Perez <fperez@colorado.edu>
3980 2001-11-25 Fernando Perez <fperez@colorado.edu>
3977
3981
3978 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
3982 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
3979 there's a cleaner distinction between what ? and ?? show.
3983 there's a cleaner distinction between what ? and ?? show.
3980
3984
3981 * Added screen_length option. Now the user can define his own
3985 * Added screen_length option. Now the user can define his own
3982 screen size for page() operations.
3986 screen size for page() operations.
3983
3987
3984 * Implemented magic shell-like functions with automatic code
3988 * Implemented magic shell-like functions with automatic code
3985 generation. Now adding another function is just a matter of adding
3989 generation. Now adding another function is just a matter of adding
3986 an entry to a dict, and the function is dynamically generated at
3990 an entry to a dict, and the function is dynamically generated at
3987 run-time. Python has some really cool features!
3991 run-time. Python has some really cool features!
3988
3992
3989 * Renamed many options to cleanup conventions a little. Now all
3993 * Renamed many options to cleanup conventions a little. Now all
3990 are lowercase, and only underscores where needed. Also in the code
3994 are lowercase, and only underscores where needed. Also in the code
3991 option name tables are clearer.
3995 option name tables are clearer.
3992
3996
3993 * Changed prompts a little. Now input is 'In [n]:' instead of
3997 * Changed prompts a little. Now input is 'In [n]:' instead of
3994 'In[n]:='. This allows it the numbers to be aligned with the
3998 'In[n]:='. This allows it the numbers to be aligned with the
3995 Out[n] numbers, and removes usage of ':=' which doesn't exist in
3999 Out[n] numbers, and removes usage of ':=' which doesn't exist in
3996 Python (it was a Mathematica thing). The '...' continuation prompt
4000 Python (it was a Mathematica thing). The '...' continuation prompt
3997 was also changed a little to align better.
4001 was also changed a little to align better.
3998
4002
3999 * Fixed bug when flushing output cache. Not all _p<n> variables
4003 * Fixed bug when flushing output cache. Not all _p<n> variables
4000 exist, so their deletion needs to be wrapped in a try:
4004 exist, so their deletion needs to be wrapped in a try:
4001
4005
4002 * Figured out how to properly use inspect.formatargspec() (it
4006 * Figured out how to properly use inspect.formatargspec() (it
4003 requires the args preceded by *). So I removed all the code from
4007 requires the args preceded by *). So I removed all the code from
4004 _get_pdef in Magic, which was just replicating that.
4008 _get_pdef in Magic, which was just replicating that.
4005
4009
4006 * Added test to prefilter to allow redefining magic function names
4010 * Added test to prefilter to allow redefining magic function names
4007 as variables. This is ok, since the @ form is always available,
4011 as variables. This is ok, since the @ form is always available,
4008 but whe should allow the user to define a variable called 'ls' if
4012 but whe should allow the user to define a variable called 'ls' if
4009 he needs it.
4013 he needs it.
4010
4014
4011 * Moved the ToDo information from README into a separate ToDo.
4015 * Moved the ToDo information from README into a separate ToDo.
4012
4016
4013 * General code cleanup and small bugfixes. I think it's close to a
4017 * General code cleanup and small bugfixes. I think it's close to a
4014 state where it can be released, obviously with a big 'beta'
4018 state where it can be released, obviously with a big 'beta'
4015 warning on it.
4019 warning on it.
4016
4020
4017 * Got the magic function split to work. Now all magics are defined
4021 * Got the magic function split to work. Now all magics are defined
4018 in a separate class. It just organizes things a bit, and now
4022 in a separate class. It just organizes things a bit, and now
4019 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4023 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4020 was too long).
4024 was too long).
4021
4025
4022 * Changed @clear to @reset to avoid potential confusions with
4026 * Changed @clear to @reset to avoid potential confusions with
4023 the shell command clear. Also renamed @cl to @clear, which does
4027 the shell command clear. Also renamed @cl to @clear, which does
4024 exactly what people expect it to from their shell experience.
4028 exactly what people expect it to from their shell experience.
4025
4029
4026 Added a check to the @reset command (since it's so
4030 Added a check to the @reset command (since it's so
4027 destructive, it's probably a good idea to ask for confirmation).
4031 destructive, it's probably a good idea to ask for confirmation).
4028 But now reset only works for full namespace resetting. Since the
4032 But now reset only works for full namespace resetting. Since the
4029 del keyword is already there for deleting a few specific
4033 del keyword is already there for deleting a few specific
4030 variables, I don't see the point of having a redundant magic
4034 variables, I don't see the point of having a redundant magic
4031 function for the same task.
4035 function for the same task.
4032
4036
4033 2001-11-24 Fernando Perez <fperez@colorado.edu>
4037 2001-11-24 Fernando Perez <fperez@colorado.edu>
4034
4038
4035 * Updated the builtin docs (esp. the ? ones).
4039 * Updated the builtin docs (esp. the ? ones).
4036
4040
4037 * Ran all the code through pychecker. Not terribly impressed with
4041 * Ran all the code through pychecker. Not terribly impressed with
4038 it: lots of spurious warnings and didn't really find anything of
4042 it: lots of spurious warnings and didn't really find anything of
4039 substance (just a few modules being imported and not used).
4043 substance (just a few modules being imported and not used).
4040
4044
4041 * Implemented the new ultraTB functionality into IPython. New
4045 * Implemented the new ultraTB functionality into IPython. New
4042 option: xcolors. This chooses color scheme. xmode now only selects
4046 option: xcolors. This chooses color scheme. xmode now only selects
4043 between Plain and Verbose. Better orthogonality.
4047 between Plain and Verbose. Better orthogonality.
4044
4048
4045 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4049 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4046 mode and color scheme for the exception handlers. Now it's
4050 mode and color scheme for the exception handlers. Now it's
4047 possible to have the verbose traceback with no coloring.
4051 possible to have the verbose traceback with no coloring.
4048
4052
4049 2001-11-23 Fernando Perez <fperez@colorado.edu>
4053 2001-11-23 Fernando Perez <fperez@colorado.edu>
4050
4054
4051 * Version 0.1.12 released, 0.1.13 opened.
4055 * Version 0.1.12 released, 0.1.13 opened.
4052
4056
4053 * Removed option to set auto-quote and auto-paren escapes by
4057 * Removed option to set auto-quote and auto-paren escapes by
4054 user. The chances of breaking valid syntax are just too high. If
4058 user. The chances of breaking valid syntax are just too high. If
4055 someone *really* wants, they can always dig into the code.
4059 someone *really* wants, they can always dig into the code.
4056
4060
4057 * Made prompt separators configurable.
4061 * Made prompt separators configurable.
4058
4062
4059 2001-11-22 Fernando Perez <fperez@colorado.edu>
4063 2001-11-22 Fernando Perez <fperez@colorado.edu>
4060
4064
4061 * Small bugfixes in many places.
4065 * Small bugfixes in many places.
4062
4066
4063 * Removed the MyCompleter class from ipplib. It seemed redundant
4067 * Removed the MyCompleter class from ipplib. It seemed redundant
4064 with the C-p,C-n history search functionality. Less code to
4068 with the C-p,C-n history search functionality. Less code to
4065 maintain.
4069 maintain.
4066
4070
4067 * Moved all the original ipython.py code into ipythonlib.py. Right
4071 * Moved all the original ipython.py code into ipythonlib.py. Right
4068 now it's just one big dump into a function called make_IPython, so
4072 now it's just one big dump into a function called make_IPython, so
4069 no real modularity has been gained. But at least it makes the
4073 no real modularity has been gained. But at least it makes the
4070 wrapper script tiny, and since ipythonlib is a module, it gets
4074 wrapper script tiny, and since ipythonlib is a module, it gets
4071 compiled and startup is much faster.
4075 compiled and startup is much faster.
4072
4076
4073 This is a reasobably 'deep' change, so we should test it for a
4077 This is a reasobably 'deep' change, so we should test it for a
4074 while without messing too much more with the code.
4078 while without messing too much more with the code.
4075
4079
4076 2001-11-21 Fernando Perez <fperez@colorado.edu>
4080 2001-11-21 Fernando Perez <fperez@colorado.edu>
4077
4081
4078 * Version 0.1.11 released, 0.1.12 opened for further work.
4082 * Version 0.1.11 released, 0.1.12 opened for further work.
4079
4083
4080 * Removed dependency on Itpl. It was only needed in one place. It
4084 * Removed dependency on Itpl. It was only needed in one place. It
4081 would be nice if this became part of python, though. It makes life
4085 would be nice if this became part of python, though. It makes life
4082 *a lot* easier in some cases.
4086 *a lot* easier in some cases.
4083
4087
4084 * Simplified the prefilter code a bit. Now all handlers are
4088 * Simplified the prefilter code a bit. Now all handlers are
4085 expected to explicitly return a value (at least a blank string).
4089 expected to explicitly return a value (at least a blank string).
4086
4090
4087 * Heavy edits in ipplib. Removed the help system altogether. Now
4091 * Heavy edits in ipplib. Removed the help system altogether. Now
4088 obj?/?? is used for inspecting objects, a magic @doc prints
4092 obj?/?? is used for inspecting objects, a magic @doc prints
4089 docstrings, and full-blown Python help is accessed via the 'help'
4093 docstrings, and full-blown Python help is accessed via the 'help'
4090 keyword. This cleans up a lot of code (less to maintain) and does
4094 keyword. This cleans up a lot of code (less to maintain) and does
4091 the job. Since 'help' is now a standard Python component, might as
4095 the job. Since 'help' is now a standard Python component, might as
4092 well use it and remove duplicate functionality.
4096 well use it and remove duplicate functionality.
4093
4097
4094 Also removed the option to use ipplib as a standalone program. By
4098 Also removed the option to use ipplib as a standalone program. By
4095 now it's too dependent on other parts of IPython to function alone.
4099 now it's too dependent on other parts of IPython to function alone.
4096
4100
4097 * Fixed bug in genutils.pager. It would crash if the pager was
4101 * Fixed bug in genutils.pager. It would crash if the pager was
4098 exited immediately after opening (broken pipe).
4102 exited immediately after opening (broken pipe).
4099
4103
4100 * Trimmed down the VerboseTB reporting a little. The header is
4104 * Trimmed down the VerboseTB reporting a little. The header is
4101 much shorter now and the repeated exception arguments at the end
4105 much shorter now and the repeated exception arguments at the end
4102 have been removed. For interactive use the old header seemed a bit
4106 have been removed. For interactive use the old header seemed a bit
4103 excessive.
4107 excessive.
4104
4108
4105 * Fixed small bug in output of @whos for variables with multi-word
4109 * Fixed small bug in output of @whos for variables with multi-word
4106 types (only first word was displayed).
4110 types (only first word was displayed).
4107
4111
4108 2001-11-17 Fernando Perez <fperez@colorado.edu>
4112 2001-11-17 Fernando Perez <fperez@colorado.edu>
4109
4113
4110 * Version 0.1.10 released, 0.1.11 opened for further work.
4114 * Version 0.1.10 released, 0.1.11 opened for further work.
4111
4115
4112 * Modified dirs and friends. dirs now *returns* the stack (not
4116 * Modified dirs and friends. dirs now *returns* the stack (not
4113 prints), so one can manipulate it as a variable. Convenient to
4117 prints), so one can manipulate it as a variable. Convenient to
4114 travel along many directories.
4118 travel along many directories.
4115
4119
4116 * Fixed bug in magic_pdef: would only work with functions with
4120 * Fixed bug in magic_pdef: would only work with functions with
4117 arguments with default values.
4121 arguments with default values.
4118
4122
4119 2001-11-14 Fernando Perez <fperez@colorado.edu>
4123 2001-11-14 Fernando Perez <fperez@colorado.edu>
4120
4124
4121 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4125 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4122 example with IPython. Various other minor fixes and cleanups.
4126 example with IPython. Various other minor fixes and cleanups.
4123
4127
4124 * Version 0.1.9 released, 0.1.10 opened for further work.
4128 * Version 0.1.9 released, 0.1.10 opened for further work.
4125
4129
4126 * Added sys.path to the list of directories searched in the
4130 * Added sys.path to the list of directories searched in the
4127 execfile= option. It used to be the current directory and the
4131 execfile= option. It used to be the current directory and the
4128 user's IPYTHONDIR only.
4132 user's IPYTHONDIR only.
4129
4133
4130 2001-11-13 Fernando Perez <fperez@colorado.edu>
4134 2001-11-13 Fernando Perez <fperez@colorado.edu>
4131
4135
4132 * Reinstated the raw_input/prefilter separation that Janko had
4136 * Reinstated the raw_input/prefilter separation that Janko had
4133 initially. This gives a more convenient setup for extending the
4137 initially. This gives a more convenient setup for extending the
4134 pre-processor from the outside: raw_input always gets a string,
4138 pre-processor from the outside: raw_input always gets a string,
4135 and prefilter has to process it. We can then redefine prefilter
4139 and prefilter has to process it. We can then redefine prefilter
4136 from the outside and implement extensions for special
4140 from the outside and implement extensions for special
4137 purposes.
4141 purposes.
4138
4142
4139 Today I got one for inputting PhysicalQuantity objects
4143 Today I got one for inputting PhysicalQuantity objects
4140 (from Scientific) without needing any function calls at
4144 (from Scientific) without needing any function calls at
4141 all. Extremely convenient, and it's all done as a user-level
4145 all. Extremely convenient, and it's all done as a user-level
4142 extension (no IPython code was touched). Now instead of:
4146 extension (no IPython code was touched). Now instead of:
4143 a = PhysicalQuantity(4.2,'m/s**2')
4147 a = PhysicalQuantity(4.2,'m/s**2')
4144 one can simply say
4148 one can simply say
4145 a = 4.2 m/s**2
4149 a = 4.2 m/s**2
4146 or even
4150 or even
4147 a = 4.2 m/s^2
4151 a = 4.2 m/s^2
4148
4152
4149 I use this, but it's also a proof of concept: IPython really is
4153 I use this, but it's also a proof of concept: IPython really is
4150 fully user-extensible, even at the level of the parsing of the
4154 fully user-extensible, even at the level of the parsing of the
4151 command line. It's not trivial, but it's perfectly doable.
4155 command line. It's not trivial, but it's perfectly doable.
4152
4156
4153 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4157 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4154 the problem of modules being loaded in the inverse order in which
4158 the problem of modules being loaded in the inverse order in which
4155 they were defined in
4159 they were defined in
4156
4160
4157 * Version 0.1.8 released, 0.1.9 opened for further work.
4161 * Version 0.1.8 released, 0.1.9 opened for further work.
4158
4162
4159 * Added magics pdef, source and file. They respectively show the
4163 * Added magics pdef, source and file. They respectively show the
4160 definition line ('prototype' in C), source code and full python
4164 definition line ('prototype' in C), source code and full python
4161 file for any callable object. The object inspector oinfo uses
4165 file for any callable object. The object inspector oinfo uses
4162 these to show the same information.
4166 these to show the same information.
4163
4167
4164 * Version 0.1.7 released, 0.1.8 opened for further work.
4168 * Version 0.1.7 released, 0.1.8 opened for further work.
4165
4169
4166 * Separated all the magic functions into a class called Magic. The
4170 * Separated all the magic functions into a class called Magic. The
4167 InteractiveShell class was becoming too big for Xemacs to handle
4171 InteractiveShell class was becoming too big for Xemacs to handle
4168 (de-indenting a line would lock it up for 10 seconds while it
4172 (de-indenting a line would lock it up for 10 seconds while it
4169 backtracked on the whole class!)
4173 backtracked on the whole class!)
4170
4174
4171 FIXME: didn't work. It can be done, but right now namespaces are
4175 FIXME: didn't work. It can be done, but right now namespaces are
4172 all messed up. Do it later (reverted it for now, so at least
4176 all messed up. Do it later (reverted it for now, so at least
4173 everything works as before).
4177 everything works as before).
4174
4178
4175 * Got the object introspection system (magic_oinfo) working! I
4179 * Got the object introspection system (magic_oinfo) working! I
4176 think this is pretty much ready for release to Janko, so he can
4180 think this is pretty much ready for release to Janko, so he can
4177 test it for a while and then announce it. Pretty much 100% of what
4181 test it for a while and then announce it. Pretty much 100% of what
4178 I wanted for the 'phase 1' release is ready. Happy, tired.
4182 I wanted for the 'phase 1' release is ready. Happy, tired.
4179
4183
4180 2001-11-12 Fernando Perez <fperez@colorado.edu>
4184 2001-11-12 Fernando Perez <fperez@colorado.edu>
4181
4185
4182 * Version 0.1.6 released, 0.1.7 opened for further work.
4186 * Version 0.1.6 released, 0.1.7 opened for further work.
4183
4187
4184 * Fixed bug in printing: it used to test for truth before
4188 * Fixed bug in printing: it used to test for truth before
4185 printing, so 0 wouldn't print. Now checks for None.
4189 printing, so 0 wouldn't print. Now checks for None.
4186
4190
4187 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4191 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4188 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4192 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4189 reaches by hand into the outputcache. Think of a better way to do
4193 reaches by hand into the outputcache. Think of a better way to do
4190 this later.
4194 this later.
4191
4195
4192 * Various small fixes thanks to Nathan's comments.
4196 * Various small fixes thanks to Nathan's comments.
4193
4197
4194 * Changed magic_pprint to magic_Pprint. This way it doesn't
4198 * Changed magic_pprint to magic_Pprint. This way it doesn't
4195 collide with pprint() and the name is consistent with the command
4199 collide with pprint() and the name is consistent with the command
4196 line option.
4200 line option.
4197
4201
4198 * Changed prompt counter behavior to be fully like
4202 * Changed prompt counter behavior to be fully like
4199 Mathematica's. That is, even input that doesn't return a result
4203 Mathematica's. That is, even input that doesn't return a result
4200 raises the prompt counter. The old behavior was kind of confusing
4204 raises the prompt counter. The old behavior was kind of confusing
4201 (getting the same prompt number several times if the operation
4205 (getting the same prompt number several times if the operation
4202 didn't return a result).
4206 didn't return a result).
4203
4207
4204 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4208 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4205
4209
4206 * Fixed -Classic mode (wasn't working anymore).
4210 * Fixed -Classic mode (wasn't working anymore).
4207
4211
4208 * Added colored prompts using Nathan's new code. Colors are
4212 * Added colored prompts using Nathan's new code. Colors are
4209 currently hardwired, they can be user-configurable. For
4213 currently hardwired, they can be user-configurable. For
4210 developers, they can be chosen in file ipythonlib.py, at the
4214 developers, they can be chosen in file ipythonlib.py, at the
4211 beginning of the CachedOutput class def.
4215 beginning of the CachedOutput class def.
4212
4216
4213 2001-11-11 Fernando Perez <fperez@colorado.edu>
4217 2001-11-11 Fernando Perez <fperez@colorado.edu>
4214
4218
4215 * Version 0.1.5 released, 0.1.6 opened for further work.
4219 * Version 0.1.5 released, 0.1.6 opened for further work.
4216
4220
4217 * Changed magic_env to *return* the environment as a dict (not to
4221 * Changed magic_env to *return* the environment as a dict (not to
4218 print it). This way it prints, but it can also be processed.
4222 print it). This way it prints, but it can also be processed.
4219
4223
4220 * Added Verbose exception reporting to interactive
4224 * Added Verbose exception reporting to interactive
4221 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4225 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4222 traceback. Had to make some changes to the ultraTB file. This is
4226 traceback. Had to make some changes to the ultraTB file. This is
4223 probably the last 'big' thing in my mental todo list. This ties
4227 probably the last 'big' thing in my mental todo list. This ties
4224 in with the next entry:
4228 in with the next entry:
4225
4229
4226 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4230 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4227 has to specify is Plain, Color or Verbose for all exception
4231 has to specify is Plain, Color or Verbose for all exception
4228 handling.
4232 handling.
4229
4233
4230 * Removed ShellServices option. All this can really be done via
4234 * Removed ShellServices option. All this can really be done via
4231 the magic system. It's easier to extend, cleaner and has automatic
4235 the magic system. It's easier to extend, cleaner and has automatic
4232 namespace protection and documentation.
4236 namespace protection and documentation.
4233
4237
4234 2001-11-09 Fernando Perez <fperez@colorado.edu>
4238 2001-11-09 Fernando Perez <fperez@colorado.edu>
4235
4239
4236 * Fixed bug in output cache flushing (missing parameter to
4240 * Fixed bug in output cache flushing (missing parameter to
4237 __init__). Other small bugs fixed (found using pychecker).
4241 __init__). Other small bugs fixed (found using pychecker).
4238
4242
4239 * Version 0.1.4 opened for bugfixing.
4243 * Version 0.1.4 opened for bugfixing.
4240
4244
4241 2001-11-07 Fernando Perez <fperez@colorado.edu>
4245 2001-11-07 Fernando Perez <fperez@colorado.edu>
4242
4246
4243 * Version 0.1.3 released, mainly because of the raw_input bug.
4247 * Version 0.1.3 released, mainly because of the raw_input bug.
4244
4248
4245 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4249 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4246 and when testing for whether things were callable, a call could
4250 and when testing for whether things were callable, a call could
4247 actually be made to certain functions. They would get called again
4251 actually be made to certain functions. They would get called again
4248 once 'really' executed, with a resulting double call. A disaster
4252 once 'really' executed, with a resulting double call. A disaster
4249 in many cases (list.reverse() would never work!).
4253 in many cases (list.reverse() would never work!).
4250
4254
4251 * Removed prefilter() function, moved its code to raw_input (which
4255 * Removed prefilter() function, moved its code to raw_input (which
4252 after all was just a near-empty caller for prefilter). This saves
4256 after all was just a near-empty caller for prefilter). This saves
4253 a function call on every prompt, and simplifies the class a tiny bit.
4257 a function call on every prompt, and simplifies the class a tiny bit.
4254
4258
4255 * Fix _ip to __ip name in magic example file.
4259 * Fix _ip to __ip name in magic example file.
4256
4260
4257 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4261 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4258 work with non-gnu versions of tar.
4262 work with non-gnu versions of tar.
4259
4263
4260 2001-11-06 Fernando Perez <fperez@colorado.edu>
4264 2001-11-06 Fernando Perez <fperez@colorado.edu>
4261
4265
4262 * Version 0.1.2. Just to keep track of the recent changes.
4266 * Version 0.1.2. Just to keep track of the recent changes.
4263
4267
4264 * Fixed nasty bug in output prompt routine. It used to check 'if
4268 * Fixed nasty bug in output prompt routine. It used to check 'if
4265 arg != None...'. Problem is, this fails if arg implements a
4269 arg != None...'. Problem is, this fails if arg implements a
4266 special comparison (__cmp__) which disallows comparing to
4270 special comparison (__cmp__) which disallows comparing to
4267 None. Found it when trying to use the PhysicalQuantity module from
4271 None. Found it when trying to use the PhysicalQuantity module from
4268 ScientificPython.
4272 ScientificPython.
4269
4273
4270 2001-11-05 Fernando Perez <fperez@colorado.edu>
4274 2001-11-05 Fernando Perez <fperez@colorado.edu>
4271
4275
4272 * Also added dirs. Now the pushd/popd/dirs family functions
4276 * Also added dirs. Now the pushd/popd/dirs family functions
4273 basically like the shell, with the added convenience of going home
4277 basically like the shell, with the added convenience of going home
4274 when called with no args.
4278 when called with no args.
4275
4279
4276 * pushd/popd slightly modified to mimic shell behavior more
4280 * pushd/popd slightly modified to mimic shell behavior more
4277 closely.
4281 closely.
4278
4282
4279 * Added env,pushd,popd from ShellServices as magic functions. I
4283 * Added env,pushd,popd from ShellServices as magic functions. I
4280 think the cleanest will be to port all desired functions from
4284 think the cleanest will be to port all desired functions from
4281 ShellServices as magics and remove ShellServices altogether. This
4285 ShellServices as magics and remove ShellServices altogether. This
4282 will provide a single, clean way of adding functionality
4286 will provide a single, clean way of adding functionality
4283 (shell-type or otherwise) to IP.
4287 (shell-type or otherwise) to IP.
4284
4288
4285 2001-11-04 Fernando Perez <fperez@colorado.edu>
4289 2001-11-04 Fernando Perez <fperez@colorado.edu>
4286
4290
4287 * Added .ipython/ directory to sys.path. This way users can keep
4291 * Added .ipython/ directory to sys.path. This way users can keep
4288 customizations there and access them via import.
4292 customizations there and access them via import.
4289
4293
4290 2001-11-03 Fernando Perez <fperez@colorado.edu>
4294 2001-11-03 Fernando Perez <fperez@colorado.edu>
4291
4295
4292 * Opened version 0.1.1 for new changes.
4296 * Opened version 0.1.1 for new changes.
4293
4297
4294 * Changed version number to 0.1.0: first 'public' release, sent to
4298 * Changed version number to 0.1.0: first 'public' release, sent to
4295 Nathan and Janko.
4299 Nathan and Janko.
4296
4300
4297 * Lots of small fixes and tweaks.
4301 * Lots of small fixes and tweaks.
4298
4302
4299 * Minor changes to whos format. Now strings are shown, snipped if
4303 * Minor changes to whos format. Now strings are shown, snipped if
4300 too long.
4304 too long.
4301
4305
4302 * Changed ShellServices to work on __main__ so they show up in @who
4306 * Changed ShellServices to work on __main__ so they show up in @who
4303
4307
4304 * Help also works with ? at the end of a line:
4308 * Help also works with ? at the end of a line:
4305 ?sin and sin?
4309 ?sin and sin?
4306 both produce the same effect. This is nice, as often I use the
4310 both produce the same effect. This is nice, as often I use the
4307 tab-complete to find the name of a method, but I used to then have
4311 tab-complete to find the name of a method, but I used to then have
4308 to go to the beginning of the line to put a ? if I wanted more
4312 to go to the beginning of the line to put a ? if I wanted more
4309 info. Now I can just add the ? and hit return. Convenient.
4313 info. Now I can just add the ? and hit return. Convenient.
4310
4314
4311 2001-11-02 Fernando Perez <fperez@colorado.edu>
4315 2001-11-02 Fernando Perez <fperez@colorado.edu>
4312
4316
4313 * Python version check (>=2.1) added.
4317 * Python version check (>=2.1) added.
4314
4318
4315 * Added LazyPython documentation. At this point the docs are quite
4319 * Added LazyPython documentation. At this point the docs are quite
4316 a mess. A cleanup is in order.
4320 a mess. A cleanup is in order.
4317
4321
4318 * Auto-installer created. For some bizarre reason, the zipfiles
4322 * Auto-installer created. For some bizarre reason, the zipfiles
4319 module isn't working on my system. So I made a tar version
4323 module isn't working on my system. So I made a tar version
4320 (hopefully the command line options in various systems won't kill
4324 (hopefully the command line options in various systems won't kill
4321 me).
4325 me).
4322
4326
4323 * Fixes to Struct in genutils. Now all dictionary-like methods are
4327 * Fixes to Struct in genutils. Now all dictionary-like methods are
4324 protected (reasonably).
4328 protected (reasonably).
4325
4329
4326 * Added pager function to genutils and changed ? to print usage
4330 * Added pager function to genutils and changed ? to print usage
4327 note through it (it was too long).
4331 note through it (it was too long).
4328
4332
4329 * Added the LazyPython functionality. Works great! I changed the
4333 * Added the LazyPython functionality. Works great! I changed the
4330 auto-quote escape to ';', it's on home row and next to '. But
4334 auto-quote escape to ';', it's on home row and next to '. But
4331 both auto-quote and auto-paren (still /) escapes are command-line
4335 both auto-quote and auto-paren (still /) escapes are command-line
4332 parameters.
4336 parameters.
4333
4337
4334
4338
4335 2001-11-01 Fernando Perez <fperez@colorado.edu>
4339 2001-11-01 Fernando Perez <fperez@colorado.edu>
4336
4340
4337 * Version changed to 0.0.7. Fairly large change: configuration now
4341 * Version changed to 0.0.7. Fairly large change: configuration now
4338 is all stored in a directory, by default .ipython. There, all
4342 is all stored in a directory, by default .ipython. There, all
4339 config files have normal looking names (not .names)
4343 config files have normal looking names (not .names)
4340
4344
4341 * Version 0.0.6 Released first to Lucas and Archie as a test
4345 * Version 0.0.6 Released first to Lucas and Archie as a test
4342 run. Since it's the first 'semi-public' release, change version to
4346 run. Since it's the first 'semi-public' release, change version to
4343 > 0.0.6 for any changes now.
4347 > 0.0.6 for any changes now.
4344
4348
4345 * Stuff I had put in the ipplib.py changelog:
4349 * Stuff I had put in the ipplib.py changelog:
4346
4350
4347 Changes to InteractiveShell:
4351 Changes to InteractiveShell:
4348
4352
4349 - Made the usage message a parameter.
4353 - Made the usage message a parameter.
4350
4354
4351 - Require the name of the shell variable to be given. It's a bit
4355 - Require the name of the shell variable to be given. It's a bit
4352 of a hack, but allows the name 'shell' not to be hardwire in the
4356 of a hack, but allows the name 'shell' not to be hardwire in the
4353 magic (@) handler, which is problematic b/c it requires
4357 magic (@) handler, which is problematic b/c it requires
4354 polluting the global namespace with 'shell'. This in turn is
4358 polluting the global namespace with 'shell'. This in turn is
4355 fragile: if a user redefines a variable called shell, things
4359 fragile: if a user redefines a variable called shell, things
4356 break.
4360 break.
4357
4361
4358 - magic @: all functions available through @ need to be defined
4362 - magic @: all functions available through @ need to be defined
4359 as magic_<name>, even though they can be called simply as
4363 as magic_<name>, even though they can be called simply as
4360 @<name>. This allows the special command @magic to gather
4364 @<name>. This allows the special command @magic to gather
4361 information automatically about all existing magic functions,
4365 information automatically about all existing magic functions,
4362 even if they are run-time user extensions, by parsing the shell
4366 even if they are run-time user extensions, by parsing the shell
4363 instance __dict__ looking for special magic_ names.
4367 instance __dict__ looking for special magic_ names.
4364
4368
4365 - mainloop: added *two* local namespace parameters. This allows
4369 - mainloop: added *two* local namespace parameters. This allows
4366 the class to differentiate between parameters which were there
4370 the class to differentiate between parameters which were there
4367 before and after command line initialization was processed. This
4371 before and after command line initialization was processed. This
4368 way, later @who can show things loaded at startup by the
4372 way, later @who can show things loaded at startup by the
4369 user. This trick was necessary to make session saving/reloading
4373 user. This trick was necessary to make session saving/reloading
4370 really work: ideally after saving/exiting/reloading a session,
4374 really work: ideally after saving/exiting/reloading a session,
4371 *everythin* should look the same, including the output of @who. I
4375 *everythin* should look the same, including the output of @who. I
4372 was only able to make this work with this double namespace
4376 was only able to make this work with this double namespace
4373 trick.
4377 trick.
4374
4378
4375 - added a header to the logfile which allows (almost) full
4379 - added a header to the logfile which allows (almost) full
4376 session restoring.
4380 session restoring.
4377
4381
4378 - prepend lines beginning with @ or !, with a and log
4382 - prepend lines beginning with @ or !, with a and log
4379 them. Why? !lines: may be useful to know what you did @lines:
4383 them. Why? !lines: may be useful to know what you did @lines:
4380 they may affect session state. So when restoring a session, at
4384 they may affect session state. So when restoring a session, at
4381 least inform the user of their presence. I couldn't quite get
4385 least inform the user of their presence. I couldn't quite get
4382 them to properly re-execute, but at least the user is warned.
4386 them to properly re-execute, but at least the user is warned.
4383
4387
4384 * Started ChangeLog.
4388 * Started ChangeLog.
General Comments 0
You need to be logged in to leave comments. Login now