##// END OF EJS Templates
rocky's pydb patch \#4
vivainio -
Show More
@@ -1,414 +1,416 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 Pdb debugger class.
4 4
5 5 Modified from the standard pdb.Pdb class to avoid including readline, so that
6 6 the command line completion of other programs which include this isn't
7 7 damaged.
8 8
9 9 In the future, this class will be expanded with improvements over the standard
10 10 pdb.
11 11
12 12 The code in this file is mainly lifted out of cmd.py in Python 2.2, with minor
13 13 changes. Licensing should therefore be under the standard Python terms. For
14 14 details on the PSF (Python Software Foundation) standard license, see:
15 15
16 16 http://www.python.org/2.2.3/license.html
17 17
18 $Id: Debugger.py 1955 2006-11-29 09:44:32Z vivainio $"""
18 $Id: Debugger.py 1961 2006-12-05 21:02:40Z vivainio $"""
19 19
20 20 #*****************************************************************************
21 21 #
22 22 # Since this file is essentially a modified copy of the pdb module which is
23 23 # part of the standard Python distribution, I assume that the proper procedure
24 24 # is to maintain its copyright as belonging to the Python Software Foundation
25 25 # (in addition to my own, for all new code).
26 26 #
27 27 # Copyright (C) 2001 Python Software Foundation, www.python.org
28 28 # Copyright (C) 2005-2006 Fernando Perez. <fperez@colorado.edu>
29 29 #
30 30 # Distributed under the terms of the BSD License. The full license is in
31 31 # the file COPYING, distributed as part of this software.
32 32 #
33 33 #*****************************************************************************
34 34
35 35 from IPython import Release
36 36 __author__ = '%s <%s>' % Release.authors['Fernando']
37 37 __license__ = 'Python'
38 38
39 39 import bdb
40 40 import cmd
41 41 import linecache
42 42 import os
43 43 import sys
44 44
45 45 from IPython import PyColorize, ColorANSI
46 46 from IPython.genutils import Term
47 47 from IPython.excolors import ExceptionColors
48 48
49 49 # See if we can use pydb.
50 50 has_pydb = False
51 51 prompt = 'ipdb>'
52 52 try:
53 53 import pydb
54 54 if hasattr(pydb.pydb, "runl"):
55 55 has_pydb = True
56 56 from pydb import Pdb as OldPdb
57 57 prompt = 'ipydb>'
58 58 except ImportError:
59 59 pass
60 60
61 61 if has_pydb:
62 62 from pydb import Pdb as OldPdb
63 63 else:
64 64 from pdb import Pdb as OldPdb
65 65
66 66 def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):
67 67 """Make new_fn have old_fn's doc string. This is particularly useful
68 68 for the do_... commands that hook into the help system.
69 69 Adapted from from a comp.lang.python posting
70 70 by Duncan Booth."""
71 71 def wrapper(*args, **kw):
72 72 return new_fn(*args, **kw)
73 73 if old_fn.__doc__:
74 74 wrapper.__doc__ = old_fn.__doc__ + additional_text
75 75 return wrapper
76 76
77 77 def _file_lines(fname):
78 78 """Return the contents of a named file as a list of lines.
79 79
80 80 This function never raises an IOError exception: if the file can't be
81 81 read, it simply returns an empty list."""
82 82
83 83 try:
84 84 outfile = open(fname)
85 85 except IOError:
86 86 return []
87 87 else:
88 88 out = outfile.readlines()
89 89 outfile.close()
90 90 return out
91 91
92 92 class Pdb(OldPdb):
93 93 """Modified Pdb class, does not load readline."""
94 94
95 95 if sys.version[:3] >= '2.5' or has_pydb:
96 96 def __init__(self,color_scheme='NoColor',completekey=None,
97 97 stdin=None, stdout=None):
98 98
99 99 # Parent constructor:
100 if has_pydb and completekey is None:
101 OldPdb.__init__(self,stdin=stdin,stdout=stdout)
102 else:
100 103 OldPdb.__init__(self,completekey,stdin,stdout)
104 self.prompt = prompt # The default prompt is '(Pdb)'
101 105
102 106 # IPython changes...
103 self.prompt = prompt # The default prompt is '(Pdb)'
104 self.is_pydb = prompt == 'ipydb>'
107 self.is_pydb = has_pydb
105 108
106 109 if self.is_pydb:
107 110
108 111 # iplib.py's ipalias seems to want pdb's checkline
109 112 # which located in pydb.fn
110 113 import pydb.fns
111 114 self.checkline = lambda filename, lineno: \
112 115 pydb.fns.checkline(self, filename, lineno)
113 116
114 117 self.curframe = None
115 118 self.do_restart = self.new_do_restart
116 119
117 120 self.old_all_completions = __IPYTHON__.Completer.all_completions
118 121 __IPYTHON__.Completer.all_completions=self.all_completions
119 122
120 # Do we have access to pydb's list command parser?
121 123 self.do_list = decorate_fn_with_doc(self.list_command_pydb,
122 124 OldPdb.do_list)
123 125 self.do_l = self.do_list
124 126 self.do_frame = decorate_fn_with_doc(self.new_do_frame,
125 127 OldPdb.do_frame)
126 128
127 129 self.aliases = {}
128 130
129 131 # Create color table: we copy the default one from the traceback
130 132 # module and add a few attributes needed for debugging
131 133 self.color_scheme_table = ExceptionColors.copy()
132 134
133 135 # shorthands
134 136 C = ColorANSI.TermColors
135 137 cst = self.color_scheme_table
136 138
137 139 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
138 140 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
139 141
140 142 cst['Linux'].colors.breakpoint_enabled = C.LightRed
141 143 cst['Linux'].colors.breakpoint_disabled = C.Red
142 144
143 145 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
144 146 cst['LightBG'].colors.breakpoint_disabled = C.Red
145 147
146 148 self.set_colors(color_scheme)
147 149
148 150 else:
149 151 # Ugly hack: for Python 2.3-2.4, we can't call the parent constructor,
150 152 # because it binds readline and breaks tab-completion. This means we
151 153 # have to COPY the constructor here.
152 154 def __init__(self,color_scheme='NoColor'):
153 155 bdb.Bdb.__init__(self)
154 156 cmd.Cmd.__init__(self,completekey=None) # don't load readline
155 157 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
156 158 self.aliases = {}
157 159
158 160 # These two lines are part of the py2.4 constructor, let's put them
159 161 # unconditionally here as they won't cause any problems in 2.3.
160 162 self.mainpyfile = ''
161 163 self._wait_for_mainpyfile = 0
162 164
163 165 # Read $HOME/.pdbrc and ./.pdbrc
164 166 try:
165 167 self.rcLines = _file_lines(os.path.join(os.environ['HOME'],
166 168 ".pdbrc"))
167 169 except KeyError:
168 170 self.rcLines = []
169 171 self.rcLines.extend(_file_lines(".pdbrc"))
170 172
171 173 # Create color table: we copy the default one from the traceback
172 174 # module and add a few attributes needed for debugging
173 175 self.color_scheme_table = ExceptionColors.copy()
174 176
175 177 # shorthands
176 178 C = ColorANSI.TermColors
177 179 cst = self.color_scheme_table
178 180
179 181 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
180 182 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
181 183
182 184 cst['Linux'].colors.breakpoint_enabled = C.LightRed
183 185 cst['Linux'].colors.breakpoint_disabled = C.Red
184 186
185 187 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
186 188 cst['LightBG'].colors.breakpoint_disabled = C.Red
187 189
188 190 self.set_colors(color_scheme)
189 191
190 192 def set_colors(self, scheme):
191 193 """Shorthand access to the color table scheme selector method."""
192 194 self.color_scheme_table.set_active_scheme(scheme)
193 195
194 196 def interaction(self, frame, traceback):
195 197 __IPYTHON__.set_completer_frame(frame)
196 198 OldPdb.interaction(self, frame, traceback)
197 199
198 200 def new_do_up(self, arg):
199 201 OldPdb.do_up(self, arg)
200 202 __IPYTHON__.set_completer_frame(self.curframe)
201 203 do_u = do_up = decorate_fn_with_doc(new_do_up, OldPdb.do_up)
202 204
203 205 def new_do_down(self, arg):
204 206 OldPdb.do_down(self, arg)
205 207 __IPYTHON__.set_completer_frame(self.curframe)
206 208
207 209 do_d = do_down = decorate_fn_with_doc(new_do_down, OldPdb.do_down)
208 210
209 211 def new_do_frame(self, arg):
210 212 OldPdb.do_frame(self, arg)
211 213 __IPYTHON__.set_completer_frame(self.curframe)
212 214
213 215 def new_do_quit(self, arg):
214 216
215 217 if hasattr(self, 'old_all_completions'):
216 218 __IPYTHON__.Completer.all_completions=self.old_all_completions
217 219
218 220
219 221 return OldPdb.do_quit(self, arg)
220 222
221 223 do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)
222 224
223 225 def new_do_restart(self, arg):
224 226 """Restart command. In the context of ipython this is exactly the same
225 227 thing as 'quit'."""
226 228 self.msg("Restart doesn't make sense here. Using 'quit' instead.")
227 229 return self.do_quit(arg)
228 230
229 231 def postloop(self):
230 232 __IPYTHON__.set_completer_frame(None)
231 233
232 234 def print_stack_trace(self):
233 235 try:
234 236 for frame_lineno in self.stack:
235 237 self.print_stack_entry(frame_lineno, context = 5)
236 238 except KeyboardInterrupt:
237 239 pass
238 240
239 241 def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
240 242 context = 3):
241 243 frame, lineno = frame_lineno
242 244 print >>Term.cout, self.format_stack_entry(frame_lineno, '', context)
243 245
244 246 def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3):
245 247 import linecache, repr
246 248
247 249 ret = []
248 250
249 251 Colors = self.color_scheme_table.active_colors
250 252 ColorsNormal = Colors.Normal
251 253 tpl_link = '%s%%s%s' % (Colors.filenameEm, ColorsNormal)
252 254 tpl_call = '%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
253 255 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
254 256 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
255 257 ColorsNormal)
256 258
257 259 frame, lineno = frame_lineno
258 260
259 261 return_value = ''
260 262 if '__return__' in frame.f_locals:
261 263 rv = frame.f_locals['__return__']
262 264 #return_value += '->'
263 265 return_value += repr.repr(rv) + '\n'
264 266 ret.append(return_value)
265 267
266 268 #s = filename + '(' + `lineno` + ')'
267 269 filename = self.canonic(frame.f_code.co_filename)
268 270 link = tpl_link % filename
269 271
270 272 if frame.f_code.co_name:
271 273 func = frame.f_code.co_name
272 274 else:
273 275 func = "<lambda>"
274 276
275 277 call = ''
276 278 if func != '?':
277 279 if '__args__' in frame.f_locals:
278 280 args = repr.repr(frame.f_locals['__args__'])
279 281 else:
280 282 args = '()'
281 283 call = tpl_call % (func, args)
282 284
283 285 # The level info should be generated in the same format pdb uses, to
284 286 # avoid breaking the pdbtrack functionality of python-mode in *emacs.
285 287 ret.append('> %s(%s)%s\n' % (link,lineno,call))
286 288
287 289 start = lineno - 1 - context//2
288 290 lines = linecache.getlines(filename)
289 291 start = max(start, 0)
290 292 start = min(start, len(lines) - context)
291 293 lines = lines[start : start + context]
292 294
293 295 for i,line in enumerate(lines):
294 296 show_arrow = (start + 1 + i == lineno)
295 297 ret.append(self.__format_line(tpl_line_em, filename,
296 298 start + 1 + i, line,
297 299 arrow = show_arrow) )
298 300
299 301 return ''.join(ret)
300 302
301 303 def __format_line(self, tpl_line, filename, lineno, line, arrow = False):
302 304 bp_mark = ""
303 305 bp_mark_color = ""
304 306
305 307 bp = None
306 308 if lineno in self.get_file_breaks(filename):
307 309 bps = self.get_breaks(filename, lineno)
308 310 bp = bps[-1]
309 311
310 312 if bp:
311 313 Colors = self.color_scheme_table.active_colors
312 314 bp_mark = str(bp.number)
313 315 bp_mark_color = Colors.breakpoint_enabled
314 316 if not bp.enabled:
315 317 bp_mark_color = Colors.breakpoint_disabled
316 318
317 319 numbers_width = 7
318 320 if arrow:
319 321 # This is the line with the error
320 322 pad = numbers_width - len(str(lineno)) - len(bp_mark)
321 323 if pad >= 3:
322 324 marker = '-'*(pad-3) + '-> '
323 325 elif pad == 2:
324 326 marker = '> '
325 327 elif pad == 1:
326 328 marker = '>'
327 329 else:
328 330 marker = ''
329 331 num = '%s%s' % (marker, str(lineno))
330 332 line = tpl_line % (bp_mark_color + bp_mark, num, line)
331 333 else:
332 334 num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
333 335 line = tpl_line % (bp_mark_color + bp_mark, num, line)
334 336
335 337 return line
336 338
337 339 def list_command_pydb(self, arg):
338 340 """List command to use if we have a newer pydb installed"""
339 341 filename, first, last = OldPdb.parse_list_cmd(self, arg)
340 342 if filename is not None:
341 343 self.print_list_lines(filename, first, last)
342 344
343 345 def print_list_lines(self, filename, first, last):
344 346 """The printing (as opposed to the parsing part of a 'list'
345 347 command."""
346 348 try:
347 349 Colors = self.color_scheme_table.active_colors
348 350 ColorsNormal = Colors.Normal
349 351 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
350 352 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal)
351 353 src = []
352 354 for lineno in range(first, last+1):
353 355 line = linecache.getline(filename, lineno)
354 356 if not line:
355 357 break
356 358
357 359 if lineno == self.curframe.f_lineno:
358 360 line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True)
359 361 else:
360 362 line = self.__format_line(tpl_line, filename, lineno, line, arrow = False)
361 363
362 364 src.append(line)
363 365 self.lineno = lineno
364 366
365 367 print >>Term.cout, ''.join(src)
366 368
367 369 except KeyboardInterrupt:
368 370 pass
369 371
370 372 def do_list(self, arg):
371 373 self.lastcmd = 'list'
372 374 last = None
373 375 if arg:
374 376 try:
375 377 x = eval(arg, {}, {})
376 378 if type(x) == type(()):
377 379 first, last = x
378 380 first = int(first)
379 381 last = int(last)
380 382 if last < first:
381 383 # Assume it's a count
382 384 last = first + last
383 385 else:
384 386 first = max(1, int(x) - 5)
385 387 except:
386 388 print '*** Error in argument:', `arg`
387 389 return
388 390 elif self.lineno is None:
389 391 first = max(1, self.curframe.f_lineno - 5)
390 392 else:
391 393 first = self.lineno + 1
392 394 if last is None:
393 395 last = first + 10
394 396 self.print_list_lines(self.curframe.f_code.co_filename, first, last)
395 397
396 398 do_l = do_list
397 399
398 400 def do_pdef(self, arg):
399 401 """The debugger interface to magic_pdef"""
400 402 namespaces = [('Locals', self.curframe.f_locals),
401 403 ('Globals', self.curframe.f_globals)]
402 404 __IPYTHON__.magic_pdef(arg, namespaces=namespaces)
403 405
404 406 def do_pdoc(self, arg):
405 407 """The debugger interface to magic_pdoc"""
406 408 namespaces = [('Locals', self.curframe.f_locals),
407 409 ('Globals', self.curframe.f_globals)]
408 410 __IPYTHON__.magic_pdoc(arg, namespaces=namespaces)
409 411
410 412 def do_pinfo(self, arg):
411 413 """The debugger equivalant of ?obj"""
412 414 namespaces = [('Locals', self.curframe.f_locals),
413 415 ('Globals', self.curframe.f_globals)]
414 416 __IPYTHON__.magic_pinfo("pinfo %s" % arg, namespaces=namespaces)
@@ -1,3058 +1,3057 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 1956 2006-11-30 05:22:31Z fperez $"""
4 $Id: Magic.py 1961 2006-12-05 21:02:40Z vivainio $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
8 8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
9 9 #
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #*****************************************************************************
13 13
14 14 #****************************************************************************
15 15 # Modules and globals
16 16
17 17 from IPython import Release
18 18 __author__ = '%s <%s>\n%s <%s>' % \
19 19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
20 20 __license__ = Release.license
21 21
22 22 # Python standard modules
23 23 import __builtin__
24 24 import bdb
25 25 import inspect
26 26 import os
27 27 import pdb
28 28 import pydoc
29 29 import sys
30 30 import re
31 31 import tempfile
32 32 import time
33 33 import cPickle as pickle
34 34 import textwrap
35 35 from cStringIO import StringIO
36 36 from getopt import getopt,GetoptError
37 37 from pprint import pprint, pformat
38 38
39 39 # cProfile was added in Python2.5
40 40 try:
41 41 import cProfile as profile
42 42 import pstats
43 43 except ImportError:
44 44 # profile isn't bundled by default in Debian for license reasons
45 45 try:
46 46 import profile,pstats
47 47 except ImportError:
48 48 profile = pstats = None
49 49
50 50 # Homebrewed
51 51 import IPython
52 52 from IPython import Debugger, OInspect, wildcard
53 53 from IPython.FakeModule import FakeModule
54 54 from IPython.Itpl import Itpl, itpl, printpl,itplns
55 55 from IPython.PyColorize import Parser
56 56 from IPython.ipstruct import Struct
57 57 from IPython.macro import Macro
58 58 from IPython.genutils import *
59 59 from IPython import platutils
60 60
61 61 #***************************************************************************
62 62 # Utility functions
63 63 def on_off(tag):
64 64 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
65 65 return ['OFF','ON'][tag]
66 66
67 67 class Bunch: pass
68 68
69 69 #***************************************************************************
70 70 # Main class implementing Magic functionality
71 71 class Magic:
72 72 """Magic functions for InteractiveShell.
73 73
74 74 Shell functions which can be reached as %function_name. All magic
75 75 functions should accept a string, which they can parse for their own
76 76 needs. This can make some functions easier to type, eg `%cd ../`
77 77 vs. `%cd("../")`
78 78
79 79 ALL definitions MUST begin with the prefix magic_. The user won't need it
80 80 at the command line, but it is is needed in the definition. """
81 81
82 82 # class globals
83 83 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
84 84 'Automagic is ON, % prefix NOT needed for magic functions.']
85 85
86 86 #......................................................................
87 87 # some utility functions
88 88
89 89 def __init__(self,shell):
90 90
91 91 self.options_table = {}
92 92 if profile is None:
93 93 self.magic_prun = self.profile_missing_notice
94 94 self.shell = shell
95 95
96 96 # namespace for holding state we may need
97 97 self._magic_state = Bunch()
98 98
99 99 def profile_missing_notice(self, *args, **kwargs):
100 100 error("""\
101 101 The profile module could not be found. If you are a Debian user,
102 102 it has been removed from the standard Debian package because of its non-free
103 103 license. To use profiling, please install"python2.3-profiler" from non-free.""")
104 104
105 105 def default_option(self,fn,optstr):
106 106 """Make an entry in the options_table for fn, with value optstr"""
107 107
108 108 if fn not in self.lsmagic():
109 109 error("%s is not a magic function" % fn)
110 110 self.options_table[fn] = optstr
111 111
112 112 def lsmagic(self):
113 113 """Return a list of currently available magic functions.
114 114
115 115 Gives a list of the bare names after mangling (['ls','cd', ...], not
116 116 ['magic_ls','magic_cd',...]"""
117 117
118 118 # FIXME. This needs a cleanup, in the way the magics list is built.
119 119
120 120 # magics in class definition
121 121 class_magic = lambda fn: fn.startswith('magic_') and \
122 122 callable(Magic.__dict__[fn])
123 123 # in instance namespace (run-time user additions)
124 124 inst_magic = lambda fn: fn.startswith('magic_') and \
125 125 callable(self.__dict__[fn])
126 126 # and bound magics by user (so they can access self):
127 127 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
128 128 callable(self.__class__.__dict__[fn])
129 129 magics = filter(class_magic,Magic.__dict__.keys()) + \
130 130 filter(inst_magic,self.__dict__.keys()) + \
131 131 filter(inst_bound_magic,self.__class__.__dict__.keys())
132 132 out = []
133 133 for fn in magics:
134 134 out.append(fn.replace('magic_','',1))
135 135 out.sort()
136 136 return out
137 137
138 138 def extract_input_slices(self,slices,raw=False):
139 139 """Return as a string a set of input history slices.
140 140
141 141 Inputs:
142 142
143 143 - slices: the set of slices is given as a list of strings (like
144 144 ['1','4:8','9'], since this function is for use by magic functions
145 145 which get their arguments as strings.
146 146
147 147 Optional inputs:
148 148
149 149 - raw(False): by default, the processed input is used. If this is
150 150 true, the raw input history is used instead.
151 151
152 152 Note that slices can be called with two notations:
153 153
154 154 N:M -> standard python form, means including items N...(M-1).
155 155
156 156 N-M -> include items N..M (closed endpoint)."""
157 157
158 158 if raw:
159 159 hist = self.shell.input_hist_raw
160 160 else:
161 161 hist = self.shell.input_hist
162 162
163 163 cmds = []
164 164 for chunk in slices:
165 165 if ':' in chunk:
166 166 ini,fin = map(int,chunk.split(':'))
167 167 elif '-' in chunk:
168 168 ini,fin = map(int,chunk.split('-'))
169 169 fin += 1
170 170 else:
171 171 ini = int(chunk)
172 172 fin = ini+1
173 173 cmds.append(hist[ini:fin])
174 174 return cmds
175 175
176 176 def _ofind(self, oname, namespaces=None):
177 177 """Find an object in the available namespaces.
178 178
179 179 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
180 180
181 181 Has special code to detect magic functions.
182 182 """
183 183
184 184 oname = oname.strip()
185 185
186 186 alias_ns = None
187 187 if namespaces is None:
188 188 # Namespaces to search in:
189 189 # Put them in a list. The order is important so that we
190 190 # find things in the same order that Python finds them.
191 191 namespaces = [ ('Interactive', self.shell.user_ns),
192 192 ('IPython internal', self.shell.internal_ns),
193 193 ('Python builtin', __builtin__.__dict__),
194 194 ('Alias', self.shell.alias_table),
195 195 ]
196 196 alias_ns = self.shell.alias_table
197 197
198 198 # initialize results to 'null'
199 199 found = 0; obj = None; ospace = None; ds = None;
200 200 ismagic = 0; isalias = 0; parent = None
201 201
202 202 # Look for the given name by splitting it in parts. If the head is
203 203 # found, then we look for all the remaining parts as members, and only
204 204 # declare success if we can find them all.
205 205 oname_parts = oname.split('.')
206 206 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
207 207 for nsname,ns in namespaces:
208 208 try:
209 209 obj = ns[oname_head]
210 210 except KeyError:
211 211 continue
212 212 else:
213 213 for part in oname_rest:
214 214 try:
215 215 parent = obj
216 216 obj = getattr(obj,part)
217 217 except:
218 218 # Blanket except b/c some badly implemented objects
219 219 # allow __getattr__ to raise exceptions other than
220 220 # AttributeError, which then crashes IPython.
221 221 break
222 222 else:
223 223 # If we finish the for loop (no break), we got all members
224 224 found = 1
225 225 ospace = nsname
226 226 if ns == alias_ns:
227 227 isalias = 1
228 228 break # namespace loop
229 229
230 230 # Try to see if it's magic
231 231 if not found:
232 232 if oname.startswith(self.shell.ESC_MAGIC):
233 233 oname = oname[1:]
234 234 obj = getattr(self,'magic_'+oname,None)
235 235 if obj is not None:
236 236 found = 1
237 237 ospace = 'IPython internal'
238 238 ismagic = 1
239 239
240 240 # Last try: special-case some literals like '', [], {}, etc:
241 241 if not found and oname_head in ["''",'""','[]','{}','()']:
242 242 obj = eval(oname_head)
243 243 found = 1
244 244 ospace = 'Interactive'
245 245
246 246 return {'found':found, 'obj':obj, 'namespace':ospace,
247 247 'ismagic':ismagic, 'isalias':isalias, 'parent':parent}
248 248
249 249 def arg_err(self,func):
250 250 """Print docstring if incorrect arguments were passed"""
251 251 print 'Error in arguments:'
252 252 print OInspect.getdoc(func)
253 253
254 254 def format_latex(self,strng):
255 255 """Format a string for latex inclusion."""
256 256
257 257 # Characters that need to be escaped for latex:
258 258 escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE)
259 259 # Magic command names as headers:
260 260 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
261 261 re.MULTILINE)
262 262 # Magic commands
263 263 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
264 264 re.MULTILINE)
265 265 # Paragraph continue
266 266 par_re = re.compile(r'\\$',re.MULTILINE)
267 267
268 268 # The "\n" symbol
269 269 newline_re = re.compile(r'\\n')
270 270
271 271 # Now build the string for output:
272 272 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
273 273 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
274 274 strng)
275 275 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
276 276 strng = par_re.sub(r'\\\\',strng)
277 277 strng = escape_re.sub(r'\\\1',strng)
278 278 strng = newline_re.sub(r'\\textbackslash{}n',strng)
279 279 return strng
280 280
281 281 def format_screen(self,strng):
282 282 """Format a string for screen printing.
283 283
284 284 This removes some latex-type format codes."""
285 285 # Paragraph continue
286 286 par_re = re.compile(r'\\$',re.MULTILINE)
287 287 strng = par_re.sub('',strng)
288 288 return strng
289 289
290 290 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
291 291 """Parse options passed to an argument string.
292 292
293 293 The interface is similar to that of getopt(), but it returns back a
294 294 Struct with the options as keys and the stripped argument string still
295 295 as a string.
296 296
297 297 arg_str is quoted as a true sys.argv vector by using shlex.split.
298 298 This allows us to easily expand variables, glob files, quote
299 299 arguments, etc.
300 300
301 301 Options:
302 302 -mode: default 'string'. If given as 'list', the argument string is
303 303 returned as a list (split on whitespace) instead of a string.
304 304
305 305 -list_all: put all option values in lists. Normally only options
306 306 appearing more than once are put in a list.
307 307
308 308 -posix (True): whether to split the input line in POSIX mode or not,
309 309 as per the conventions outlined in the shlex module from the
310 310 standard library."""
311 311
312 312 # inject default options at the beginning of the input line
313 313 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
314 314 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
315 315
316 316 mode = kw.get('mode','string')
317 317 if mode not in ['string','list']:
318 318 raise ValueError,'incorrect mode given: %s' % mode
319 319 # Get options
320 320 list_all = kw.get('list_all',0)
321 321 posix = kw.get('posix',True)
322 322
323 323 # Check if we have more than one argument to warrant extra processing:
324 324 odict = {} # Dictionary with options
325 325 args = arg_str.split()
326 326 if len(args) >= 1:
327 327 # If the list of inputs only has 0 or 1 thing in it, there's no
328 328 # need to look for options
329 329 argv = arg_split(arg_str,posix)
330 330 # Do regular option processing
331 331 try:
332 332 opts,args = getopt(argv,opt_str,*long_opts)
333 333 except GetoptError,e:
334 334 raise GetoptError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
335 335 " ".join(long_opts)))
336 336 for o,a in opts:
337 337 if o.startswith('--'):
338 338 o = o[2:]
339 339 else:
340 340 o = o[1:]
341 341 try:
342 342 odict[o].append(a)
343 343 except AttributeError:
344 344 odict[o] = [odict[o],a]
345 345 except KeyError:
346 346 if list_all:
347 347 odict[o] = [a]
348 348 else:
349 349 odict[o] = a
350 350
351 351 # Prepare opts,args for return
352 352 opts = Struct(odict)
353 353 if mode == 'string':
354 354 args = ' '.join(args)
355 355
356 356 return opts,args
357 357
358 358 #......................................................................
359 359 # And now the actual magic functions
360 360
361 361 # Functions for IPython shell work (vars,funcs, config, etc)
362 362 def magic_lsmagic(self, parameter_s = ''):
363 363 """List currently available magic functions."""
364 364 mesc = self.shell.ESC_MAGIC
365 365 print 'Available magic functions:\n'+mesc+\
366 366 (' '+mesc).join(self.lsmagic())
367 367 print '\n' + Magic.auto_status[self.shell.rc.automagic]
368 368 return None
369 369
370 370 def magic_magic(self, parameter_s = ''):
371 371 """Print information about the magic function system."""
372 372
373 373 mode = ''
374 374 try:
375 375 if parameter_s.split()[0] == '-latex':
376 376 mode = 'latex'
377 377 if parameter_s.split()[0] == '-brief':
378 378 mode = 'brief'
379 379 except:
380 380 pass
381 381
382 382 magic_docs = []
383 383 for fname in self.lsmagic():
384 384 mname = 'magic_' + fname
385 385 for space in (Magic,self,self.__class__):
386 386 try:
387 387 fn = space.__dict__[mname]
388 388 except KeyError:
389 389 pass
390 390 else:
391 391 break
392 392 if mode == 'brief':
393 393 # only first line
394 394 fndoc = fn.__doc__.split('\n',1)[0]
395 395 else:
396 396 fndoc = fn.__doc__
397 397
398 398 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
399 399 fname,fndoc))
400 400 magic_docs = ''.join(magic_docs)
401 401
402 402 if mode == 'latex':
403 403 print self.format_latex(magic_docs)
404 404 return
405 405 else:
406 406 magic_docs = self.format_screen(magic_docs)
407 407 if mode == 'brief':
408 408 return magic_docs
409 409
410 410 outmsg = """
411 411 IPython's 'magic' functions
412 412 ===========================
413 413
414 414 The magic function system provides a series of functions which allow you to
415 415 control the behavior of IPython itself, plus a lot of system-type
416 416 features. All these functions are prefixed with a % character, but parameters
417 417 are given without parentheses or quotes.
418 418
419 419 NOTE: If you have 'automagic' enabled (via the command line option or with the
420 420 %automagic function), you don't need to type in the % explicitly. By default,
421 421 IPython ships with automagic on, so you should only rarely need the % escape.
422 422
423 423 Example: typing '%cd mydir' (without the quotes) changes you working directory
424 424 to 'mydir', if it exists.
425 425
426 426 You can define your own magic functions to extend the system. See the supplied
427 427 ipythonrc and example-magic.py files for details (in your ipython
428 428 configuration directory, typically $HOME/.ipython/).
429 429
430 430 You can also define your own aliased names for magic functions. In your
431 431 ipythonrc file, placing a line like:
432 432
433 433 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
434 434
435 435 will define %pf as a new name for %profile.
436 436
437 437 You can also call magics in code using the ipmagic() function, which IPython
438 438 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
439 439
440 440 For a list of the available magic functions, use %lsmagic. For a description
441 441 of any of them, type %magic_name?, e.g. '%cd?'.
442 442
443 443 Currently the magic system has the following functions:\n"""
444 444
445 445 mesc = self.shell.ESC_MAGIC
446 446 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
447 447 "\n\n%s%s\n\n%s" % (outmsg,
448 448 magic_docs,mesc,mesc,
449 449 (' '+mesc).join(self.lsmagic()),
450 450 Magic.auto_status[self.shell.rc.automagic] ) )
451 451
452 452 page(outmsg,screen_lines=self.shell.rc.screen_length)
453 453
454 454 def magic_automagic(self, parameter_s = ''):
455 455 """Make magic functions callable without having to type the initial %.
456 456
457 457 Toggles on/off (when off, you must call it as %automagic, of
458 458 course). Note that magic functions have lowest priority, so if there's
459 459 a variable whose name collides with that of a magic fn, automagic
460 460 won't work for that function (you get the variable instead). However,
461 461 if you delete the variable (del var), the previously shadowed magic
462 462 function becomes visible to automagic again."""
463 463
464 464 rc = self.shell.rc
465 465 rc.automagic = not rc.automagic
466 466 print '\n' + Magic.auto_status[rc.automagic]
467 467
468 468 def magic_autocall(self, parameter_s = ''):
469 469 """Make functions callable without having to type parentheses.
470 470
471 471 Usage:
472 472
473 473 %autocall [mode]
474 474
475 475 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
476 476 value is toggled on and off (remembering the previous state)."""
477 477
478 478 rc = self.shell.rc
479 479
480 480 if parameter_s:
481 481 arg = int(parameter_s)
482 482 else:
483 483 arg = 'toggle'
484 484
485 485 if not arg in (0,1,2,'toggle'):
486 486 error('Valid modes: (0->Off, 1->Smart, 2->Full')
487 487 return
488 488
489 489 if arg in (0,1,2):
490 490 rc.autocall = arg
491 491 else: # toggle
492 492 if rc.autocall:
493 493 self._magic_state.autocall_save = rc.autocall
494 494 rc.autocall = 0
495 495 else:
496 496 try:
497 497 rc.autocall = self._magic_state.autocall_save
498 498 except AttributeError:
499 499 rc.autocall = self._magic_state.autocall_save = 1
500 500
501 501 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
502 502
503 503 def magic_autoindent(self, parameter_s = ''):
504 504 """Toggle autoindent on/off (if available)."""
505 505
506 506 self.shell.set_autoindent()
507 507 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
508 508
509 509 def magic_system_verbose(self, parameter_s = ''):
510 510 """Set verbose printing of system calls.
511 511
512 512 If called without an argument, act as a toggle"""
513 513
514 514 if parameter_s:
515 515 val = bool(eval(parameter_s))
516 516 else:
517 517 val = None
518 518
519 519 self.shell.rc_set_toggle('system_verbose',val)
520 520 print "System verbose printing is:",\
521 521 ['OFF','ON'][self.shell.rc.system_verbose]
522 522
523 523 def magic_history(self, parameter_s = ''):
524 524 """Print input history (_i<n> variables), with most recent last.
525 525
526 526 %history -> print at most 40 inputs (some may be multi-line)\\
527 527 %history n -> print at most n inputs\\
528 528 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
529 529
530 530 Each input's number <n> is shown, and is accessible as the
531 531 automatically generated variable _i<n>. Multi-line statements are
532 532 printed starting at a new line for easy copy/paste.
533 533
534 534
535 535 Options:
536 536
537 537 -n: do NOT print line numbers. This is useful if you want to get a
538 538 printout of many lines which can be directly pasted into a text
539 539 editor.
540 540
541 541 This feature is only available if numbered prompts are in use.
542 542
543 543 -r: print the 'raw' history. IPython filters your input and
544 544 converts it all into valid Python source before executing it (things
545 545 like magics or aliases are turned into function calls, for
546 546 example). With this option, you'll see the unfiltered history
547 547 instead of the filtered version: '%cd /' will be seen as '%cd /'
548 548 instead of '_ip.magic("%cd /")'.
549 549 """
550 550
551 551 shell = self.shell
552 552 if not shell.outputcache.do_full_cache:
553 553 print 'This feature is only available if numbered prompts are in use.'
554 554 return
555 555 opts,args = self.parse_options(parameter_s,'nr',mode='list')
556 556
557 557 if opts.has_key('r'):
558 558 input_hist = shell.input_hist_raw
559 559 else:
560 560 input_hist = shell.input_hist
561 561
562 562 default_length = 40
563 563 if len(args) == 0:
564 564 final = len(input_hist)
565 565 init = max(1,final-default_length)
566 566 elif len(args) == 1:
567 567 final = len(input_hist)
568 568 init = max(1,final-int(args[0]))
569 569 elif len(args) == 2:
570 570 init,final = map(int,args)
571 571 else:
572 572 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
573 573 print self.magic_hist.__doc__
574 574 return
575 575 width = len(str(final))
576 576 line_sep = ['','\n']
577 577 print_nums = not opts.has_key('n')
578 578 for in_num in range(init,final):
579 579 inline = input_hist[in_num]
580 580 multiline = int(inline.count('\n') > 1)
581 581 if print_nums:
582 582 print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
583 583 print inline,
584 584
585 585 def magic_hist(self, parameter_s=''):
586 586 """Alternate name for %history."""
587 587 return self.magic_history(parameter_s)
588 588
589 589 def magic_p(self, parameter_s=''):
590 590 """Just a short alias for Python's 'print'."""
591 591 exec 'print ' + parameter_s in self.shell.user_ns
592 592
593 593 def magic_r(self, parameter_s=''):
594 594 """Repeat previous input.
595 595
596 596 If given an argument, repeats the previous command which starts with
597 597 the same string, otherwise it just repeats the previous input.
598 598
599 599 Shell escaped commands (with ! as first character) are not recognized
600 600 by this system, only pure python code and magic commands.
601 601 """
602 602
603 603 start = parameter_s.strip()
604 604 esc_magic = self.shell.ESC_MAGIC
605 605 # Identify magic commands even if automagic is on (which means
606 606 # the in-memory version is different from that typed by the user).
607 607 if self.shell.rc.automagic:
608 608 start_magic = esc_magic+start
609 609 else:
610 610 start_magic = start
611 611 # Look through the input history in reverse
612 612 for n in range(len(self.shell.input_hist)-2,0,-1):
613 613 input = self.shell.input_hist[n]
614 614 # skip plain 'r' lines so we don't recurse to infinity
615 615 if input != '_ip.magic("r")\n' and \
616 616 (input.startswith(start) or input.startswith(start_magic)):
617 617 #print 'match',`input` # dbg
618 618 print 'Executing:',input,
619 619 self.shell.runlines(input)
620 620 return
621 621 print 'No previous input matching `%s` found.' % start
622 622
623 623 def magic_page(self, parameter_s=''):
624 624 """Pretty print the object and display it through a pager.
625 625
626 626 %page [options] OBJECT
627 627
628 628 If no object is given, use _ (last output).
629 629
630 630 Options:
631 631
632 632 -r: page str(object), don't pretty-print it."""
633 633
634 634 # After a function contributed by Olivier Aubert, slightly modified.
635 635
636 636 # Process options/args
637 637 opts,args = self.parse_options(parameter_s,'r')
638 638 raw = 'r' in opts
639 639
640 640 oname = args and args or '_'
641 641 info = self._ofind(oname)
642 642 if info['found']:
643 643 txt = (raw and str or pformat)( info['obj'] )
644 644 page(txt)
645 645 else:
646 646 print 'Object `%s` not found' % oname
647 647
648 648 def magic_profile(self, parameter_s=''):
649 649 """Print your currently active IPyhton profile."""
650 650 if self.shell.rc.profile:
651 651 printpl('Current IPython profile: $self.shell.rc.profile.')
652 652 else:
653 653 print 'No profile active.'
654 654
655 655 def _inspect(self,meth,oname,namespaces=None,**kw):
656 656 """Generic interface to the inspector system.
657 657
658 658 This function is meant to be called by pdef, pdoc & friends."""
659 659
660 660 oname = oname.strip()
661 661 info = Struct(self._ofind(oname, namespaces))
662 662
663 663 if info.found:
664 664 # Get the docstring of the class property if it exists.
665 665 path = oname.split('.')
666 666 root = '.'.join(path[:-1])
667 667 if info.parent is not None:
668 668 try:
669 669 target = getattr(info.parent, '__class__')
670 670 # The object belongs to a class instance.
671 671 try:
672 672 target = getattr(target, path[-1])
673 673 # The class defines the object.
674 674 if isinstance(target, property):
675 675 oname = root + '.__class__.' + path[-1]
676 676 info = Struct(self._ofind(oname))
677 677 except AttributeError: pass
678 678 except AttributeError: pass
679 679
680 680 pmethod = getattr(self.shell.inspector,meth)
681 681 formatter = info.ismagic and self.format_screen or None
682 682 if meth == 'pdoc':
683 683 pmethod(info.obj,oname,formatter)
684 684 elif meth == 'pinfo':
685 685 pmethod(info.obj,oname,formatter,info,**kw)
686 686 else:
687 687 pmethod(info.obj,oname)
688 688 else:
689 689 print 'Object `%s` not found.' % oname
690 690 return 'not found' # so callers can take other action
691 691
692 692 def magic_pdef(self, parameter_s='', namespaces=None):
693 693 """Print the definition header for any callable object.
694 694
695 695 If the object is a class, print the constructor information."""
696 print "+++"
697 696 self._inspect('pdef',parameter_s, namespaces)
698 697
699 698 def magic_pdoc(self, parameter_s='', namespaces=None):
700 699 """Print the docstring for an object.
701 700
702 701 If the given object is a class, it will print both the class and the
703 702 constructor docstrings."""
704 703 self._inspect('pdoc',parameter_s, namespaces)
705 704
706 705 def magic_psource(self, parameter_s='', namespaces=None):
707 706 """Print (or run through pager) the source code for an object."""
708 707 self._inspect('psource',parameter_s, namespaces)
709 708
710 709 def magic_pfile(self, parameter_s=''):
711 710 """Print (or run through pager) the file where an object is defined.
712 711
713 712 The file opens at the line where the object definition begins. IPython
714 713 will honor the environment variable PAGER if set, and otherwise will
715 714 do its best to print the file in a convenient form.
716 715
717 716 If the given argument is not an object currently defined, IPython will
718 717 try to interpret it as a filename (automatically adding a .py extension
719 718 if needed). You can thus use %pfile as a syntax highlighting code
720 719 viewer."""
721 720
722 721 # first interpret argument as an object name
723 722 out = self._inspect('pfile',parameter_s)
724 723 # if not, try the input as a filename
725 724 if out == 'not found':
726 725 try:
727 726 filename = get_py_filename(parameter_s)
728 727 except IOError,msg:
729 728 print msg
730 729 return
731 730 page(self.shell.inspector.format(file(filename).read()))
732 731
733 732 def magic_pinfo(self, parameter_s='', namespaces=None):
734 733 """Provide detailed information about an object.
735 734
736 735 '%pinfo object' is just a synonym for object? or ?object."""
737 736
738 737 #print 'pinfo par: <%s>' % parameter_s # dbg
739 738
740 739 # detail_level: 0 -> obj? , 1 -> obj??
741 740 detail_level = 0
742 741 # We need to detect if we got called as 'pinfo pinfo foo', which can
743 742 # happen if the user types 'pinfo foo?' at the cmd line.
744 743 pinfo,qmark1,oname,qmark2 = \
745 744 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
746 745 if pinfo or qmark1 or qmark2:
747 746 detail_level = 1
748 747 if "*" in oname:
749 748 self.magic_psearch(oname)
750 749 else:
751 750 self._inspect('pinfo', oname, detail_level=detail_level,
752 751 namespaces=namespaces)
753 752
754 753 def magic_psearch(self, parameter_s=''):
755 754 """Search for object in namespaces by wildcard.
756 755
757 756 %psearch [options] PATTERN [OBJECT TYPE]
758 757
759 758 Note: ? can be used as a synonym for %psearch, at the beginning or at
760 759 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
761 760 rest of the command line must be unchanged (options come first), so
762 761 for example the following forms are equivalent
763 762
764 763 %psearch -i a* function
765 764 -i a* function?
766 765 ?-i a* function
767 766
768 767 Arguments:
769 768
770 769 PATTERN
771 770
772 771 where PATTERN is a string containing * as a wildcard similar to its
773 772 use in a shell. The pattern is matched in all namespaces on the
774 773 search path. By default objects starting with a single _ are not
775 774 matched, many IPython generated objects have a single
776 775 underscore. The default is case insensitive matching. Matching is
777 776 also done on the attributes of objects and not only on the objects
778 777 in a module.
779 778
780 779 [OBJECT TYPE]
781 780
782 781 Is the name of a python type from the types module. The name is
783 782 given in lowercase without the ending type, ex. StringType is
784 783 written string. By adding a type here only objects matching the
785 784 given type are matched. Using all here makes the pattern match all
786 785 types (this is the default).
787 786
788 787 Options:
789 788
790 789 -a: makes the pattern match even objects whose names start with a
791 790 single underscore. These names are normally ommitted from the
792 791 search.
793 792
794 793 -i/-c: make the pattern case insensitive/sensitive. If neither of
795 794 these options is given, the default is read from your ipythonrc
796 795 file. The option name which sets this value is
797 796 'wildcards_case_sensitive'. If this option is not specified in your
798 797 ipythonrc file, IPython's internal default is to do a case sensitive
799 798 search.
800 799
801 800 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
802 801 specifiy can be searched in any of the following namespaces:
803 802 'builtin', 'user', 'user_global','internal', 'alias', where
804 803 'builtin' and 'user' are the search defaults. Note that you should
805 804 not use quotes when specifying namespaces.
806 805
807 806 'Builtin' contains the python module builtin, 'user' contains all
808 807 user data, 'alias' only contain the shell aliases and no python
809 808 objects, 'internal' contains objects used by IPython. The
810 809 'user_global' namespace is only used by embedded IPython instances,
811 810 and it contains module-level globals. You can add namespaces to the
812 811 search with -s or exclude them with -e (these options can be given
813 812 more than once).
814 813
815 814 Examples:
816 815
817 816 %psearch a* -> objects beginning with an a
818 817 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
819 818 %psearch a* function -> all functions beginning with an a
820 819 %psearch re.e* -> objects beginning with an e in module re
821 820 %psearch r*.e* -> objects that start with e in modules starting in r
822 821 %psearch r*.* string -> all strings in modules beginning with r
823 822
824 823 Case sensitve search:
825 824
826 825 %psearch -c a* list all object beginning with lower case a
827 826
828 827 Show objects beginning with a single _:
829 828
830 829 %psearch -a _* list objects beginning with a single underscore"""
831 830
832 831 # default namespaces to be searched
833 832 def_search = ['user','builtin']
834 833
835 834 # Process options/args
836 835 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
837 836 opt = opts.get
838 837 shell = self.shell
839 838 psearch = shell.inspector.psearch
840 839
841 840 # select case options
842 841 if opts.has_key('i'):
843 842 ignore_case = True
844 843 elif opts.has_key('c'):
845 844 ignore_case = False
846 845 else:
847 846 ignore_case = not shell.rc.wildcards_case_sensitive
848 847
849 848 # Build list of namespaces to search from user options
850 849 def_search.extend(opt('s',[]))
851 850 ns_exclude = ns_exclude=opt('e',[])
852 851 ns_search = [nm for nm in def_search if nm not in ns_exclude]
853 852
854 853 # Call the actual search
855 854 try:
856 855 psearch(args,shell.ns_table,ns_search,
857 856 show_all=opt('a'),ignore_case=ignore_case)
858 857 except:
859 858 shell.showtraceback()
860 859
861 860 def magic_who_ls(self, parameter_s=''):
862 861 """Return a sorted list of all interactive variables.
863 862
864 863 If arguments are given, only variables of types matching these
865 864 arguments are returned."""
866 865
867 866 user_ns = self.shell.user_ns
868 867 internal_ns = self.shell.internal_ns
869 868 user_config_ns = self.shell.user_config_ns
870 869 out = []
871 870 typelist = parameter_s.split()
872 871
873 872 for i in user_ns:
874 873 if not (i.startswith('_') or i.startswith('_i')) \
875 874 and not (i in internal_ns or i in user_config_ns):
876 875 if typelist:
877 876 if type(user_ns[i]).__name__ in typelist:
878 877 out.append(i)
879 878 else:
880 879 out.append(i)
881 880 out.sort()
882 881 return out
883 882
884 883 def magic_who(self, parameter_s=''):
885 884 """Print all interactive variables, with some minimal formatting.
886 885
887 886 If any arguments are given, only variables whose type matches one of
888 887 these are printed. For example:
889 888
890 889 %who function str
891 890
892 891 will only list functions and strings, excluding all other types of
893 892 variables. To find the proper type names, simply use type(var) at a
894 893 command line to see how python prints type names. For example:
895 894
896 895 In [1]: type('hello')\\
897 896 Out[1]: <type 'str'>
898 897
899 898 indicates that the type name for strings is 'str'.
900 899
901 900 %who always excludes executed names loaded through your configuration
902 901 file and things which are internal to IPython.
903 902
904 903 This is deliberate, as typically you may load many modules and the
905 904 purpose of %who is to show you only what you've manually defined."""
906 905
907 906 varlist = self.magic_who_ls(parameter_s)
908 907 if not varlist:
909 908 print 'Interactive namespace is empty.'
910 909 return
911 910
912 911 # if we have variables, move on...
913 912
914 913 # stupid flushing problem: when prompts have no separators, stdout is
915 914 # getting lost. I'm starting to think this is a python bug. I'm having
916 915 # to force a flush with a print because even a sys.stdout.flush
917 916 # doesn't seem to do anything!
918 917
919 918 count = 0
920 919 for i in varlist:
921 920 print i+'\t',
922 921 count += 1
923 922 if count > 8:
924 923 count = 0
925 924 print
926 925 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
927 926
928 927 print # well, this does force a flush at the expense of an extra \n
929 928
930 929 def magic_whos(self, parameter_s=''):
931 930 """Like %who, but gives some extra information about each variable.
932 931
933 932 The same type filtering of %who can be applied here.
934 933
935 934 For all variables, the type is printed. Additionally it prints:
936 935
937 936 - For {},[],(): their length.
938 937
939 938 - For Numeric arrays, a summary with shape, number of elements,
940 939 typecode and size in memory.
941 940
942 941 - Everything else: a string representation, snipping their middle if
943 942 too long."""
944 943
945 944 varnames = self.magic_who_ls(parameter_s)
946 945 if not varnames:
947 946 print 'Interactive namespace is empty.'
948 947 return
949 948
950 949 # if we have variables, move on...
951 950
952 951 # for these types, show len() instead of data:
953 952 seq_types = [types.DictType,types.ListType,types.TupleType]
954 953
955 954 # for Numeric arrays, display summary info
956 955 try:
957 956 import Numeric
958 957 except ImportError:
959 958 array_type = None
960 959 else:
961 960 array_type = Numeric.ArrayType.__name__
962 961
963 962 # Find all variable names and types so we can figure out column sizes
964 963
965 964 def get_vars(i):
966 965 return self.shell.user_ns[i]
967 966
968 967 # some types are well known and can be shorter
969 968 abbrevs = {'IPython.macro.Macro' : 'Macro'}
970 969 def type_name(v):
971 970 tn = type(v).__name__
972 971 return abbrevs.get(tn,tn)
973 972
974 973 varlist = map(get_vars,varnames)
975 974
976 975 typelist = []
977 976 for vv in varlist:
978 977 tt = type_name(vv)
979 978
980 979 if tt=='instance':
981 980 typelist.append( abbrevs.get(str(vv.__class__),str(vv.__class__)))
982 981 else:
983 982 typelist.append(tt)
984 983
985 984 # column labels and # of spaces as separator
986 985 varlabel = 'Variable'
987 986 typelabel = 'Type'
988 987 datalabel = 'Data/Info'
989 988 colsep = 3
990 989 # variable format strings
991 990 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
992 991 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
993 992 aformat = "%s: %s elems, type `%s`, %s bytes"
994 993 # find the size of the columns to format the output nicely
995 994 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
996 995 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
997 996 # table header
998 997 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
999 998 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
1000 999 # and the table itself
1001 1000 kb = 1024
1002 1001 Mb = 1048576 # kb**2
1003 1002 for vname,var,vtype in zip(varnames,varlist,typelist):
1004 1003 print itpl(vformat),
1005 1004 if vtype in seq_types:
1006 1005 print len(var)
1007 1006 elif vtype==array_type:
1008 1007 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
1009 1008 vsize = Numeric.size(var)
1010 1009 vbytes = vsize*var.itemsize()
1011 1010 if vbytes < 100000:
1012 1011 print aformat % (vshape,vsize,var.typecode(),vbytes)
1013 1012 else:
1014 1013 print aformat % (vshape,vsize,var.typecode(),vbytes),
1015 1014 if vbytes < Mb:
1016 1015 print '(%s kb)' % (vbytes/kb,)
1017 1016 else:
1018 1017 print '(%s Mb)' % (vbytes/Mb,)
1019 1018 else:
1020 1019 vstr = str(var).replace('\n','\\n')
1021 1020 if len(vstr) < 50:
1022 1021 print vstr
1023 1022 else:
1024 1023 printpl(vfmt_short)
1025 1024
1026 1025 def magic_reset(self, parameter_s=''):
1027 1026 """Resets the namespace by removing all names defined by the user.
1028 1027
1029 1028 Input/Output history are left around in case you need them."""
1030 1029
1031 1030 ans = self.shell.ask_yes_no(
1032 1031 "Once deleted, variables cannot be recovered. Proceed (y/[n])? ")
1033 1032 if not ans:
1034 1033 print 'Nothing done.'
1035 1034 return
1036 1035 user_ns = self.shell.user_ns
1037 1036 for i in self.magic_who_ls():
1038 1037 del(user_ns[i])
1039 1038
1040 1039 def magic_logstart(self,parameter_s=''):
1041 1040 """Start logging anywhere in a session.
1042 1041
1043 1042 %logstart [-o|-r|-t] [log_name [log_mode]]
1044 1043
1045 1044 If no name is given, it defaults to a file named 'ipython_log.py' in your
1046 1045 current directory, in 'rotate' mode (see below).
1047 1046
1048 1047 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
1049 1048 history up to that point and then continues logging.
1050 1049
1051 1050 %logstart takes a second optional parameter: logging mode. This can be one
1052 1051 of (note that the modes are given unquoted):\\
1053 1052 append: well, that says it.\\
1054 1053 backup: rename (if exists) to name~ and start name.\\
1055 1054 global: single logfile in your home dir, appended to.\\
1056 1055 over : overwrite existing log.\\
1057 1056 rotate: create rotating logs name.1~, name.2~, etc.
1058 1057
1059 1058 Options:
1060 1059
1061 1060 -o: log also IPython's output. In this mode, all commands which
1062 1061 generate an Out[NN] prompt are recorded to the logfile, right after
1063 1062 their corresponding input line. The output lines are always
1064 1063 prepended with a '#[Out]# ' marker, so that the log remains valid
1065 1064 Python code.
1066 1065
1067 1066 Since this marker is always the same, filtering only the output from
1068 1067 a log is very easy, using for example a simple awk call:
1069 1068
1070 1069 awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py
1071 1070
1072 1071 -r: log 'raw' input. Normally, IPython's logs contain the processed
1073 1072 input, so that user lines are logged in their final form, converted
1074 1073 into valid Python. For example, %Exit is logged as
1075 1074 '_ip.magic("Exit"). If the -r flag is given, all input is logged
1076 1075 exactly as typed, with no transformations applied.
1077 1076
1078 1077 -t: put timestamps before each input line logged (these are put in
1079 1078 comments)."""
1080 1079
1081 1080 opts,par = self.parse_options(parameter_s,'ort')
1082 1081 log_output = 'o' in opts
1083 1082 log_raw_input = 'r' in opts
1084 1083 timestamp = 't' in opts
1085 1084
1086 1085 rc = self.shell.rc
1087 1086 logger = self.shell.logger
1088 1087
1089 1088 # if no args are given, the defaults set in the logger constructor by
1090 1089 # ipytohn remain valid
1091 1090 if par:
1092 1091 try:
1093 1092 logfname,logmode = par.split()
1094 1093 except:
1095 1094 logfname = par
1096 1095 logmode = 'backup'
1097 1096 else:
1098 1097 logfname = logger.logfname
1099 1098 logmode = logger.logmode
1100 1099 # put logfname into rc struct as if it had been called on the command
1101 1100 # line, so it ends up saved in the log header Save it in case we need
1102 1101 # to restore it...
1103 1102 old_logfile = rc.opts.get('logfile','')
1104 1103 if logfname:
1105 1104 logfname = os.path.expanduser(logfname)
1106 1105 rc.opts.logfile = logfname
1107 1106 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
1108 1107 try:
1109 1108 started = logger.logstart(logfname,loghead,logmode,
1110 1109 log_output,timestamp,log_raw_input)
1111 1110 except:
1112 1111 rc.opts.logfile = old_logfile
1113 1112 warn("Couldn't start log: %s" % sys.exc_info()[1])
1114 1113 else:
1115 1114 # log input history up to this point, optionally interleaving
1116 1115 # output if requested
1117 1116
1118 1117 if timestamp:
1119 1118 # disable timestamping for the previous history, since we've
1120 1119 # lost those already (no time machine here).
1121 1120 logger.timestamp = False
1122 1121
1123 1122 if log_raw_input:
1124 1123 input_hist = self.shell.input_hist_raw
1125 1124 else:
1126 1125 input_hist = self.shell.input_hist
1127 1126
1128 1127 if log_output:
1129 1128 log_write = logger.log_write
1130 1129 output_hist = self.shell.output_hist
1131 1130 for n in range(1,len(input_hist)-1):
1132 1131 log_write(input_hist[n].rstrip())
1133 1132 if n in output_hist:
1134 1133 log_write(repr(output_hist[n]),'output')
1135 1134 else:
1136 1135 logger.log_write(input_hist[1:])
1137 1136 if timestamp:
1138 1137 # re-enable timestamping
1139 1138 logger.timestamp = True
1140 1139
1141 1140 print ('Activating auto-logging. '
1142 1141 'Current session state plus future input saved.')
1143 1142 logger.logstate()
1144 1143
1145 1144 def magic_logoff(self,parameter_s=''):
1146 1145 """Temporarily stop logging.
1147 1146
1148 1147 You must have previously started logging."""
1149 1148 self.shell.logger.switch_log(0)
1150 1149
1151 1150 def magic_logon(self,parameter_s=''):
1152 1151 """Restart logging.
1153 1152
1154 1153 This function is for restarting logging which you've temporarily
1155 1154 stopped with %logoff. For starting logging for the first time, you
1156 1155 must use the %logstart function, which allows you to specify an
1157 1156 optional log filename."""
1158 1157
1159 1158 self.shell.logger.switch_log(1)
1160 1159
1161 1160 def magic_logstate(self,parameter_s=''):
1162 1161 """Print the status of the logging system."""
1163 1162
1164 1163 self.shell.logger.logstate()
1165 1164
1166 1165 def magic_pdb(self, parameter_s=''):
1167 1166 """Control the automatic calling of the pdb interactive debugger.
1168 1167
1169 1168 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1170 1169 argument it works as a toggle.
1171 1170
1172 1171 When an exception is triggered, IPython can optionally call the
1173 1172 interactive pdb debugger after the traceback printout. %pdb toggles
1174 1173 this feature on and off.
1175 1174
1176 1175 The initial state of this feature is set in your ipythonrc
1177 1176 configuration file (the variable is called 'pdb').
1178 1177
1179 1178 If you want to just activate the debugger AFTER an exception has fired,
1180 1179 without having to type '%pdb on' and rerunning your code, you can use
1181 1180 the %debug magic."""
1182 1181
1183 1182 par = parameter_s.strip().lower()
1184 1183
1185 1184 if par:
1186 1185 try:
1187 1186 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1188 1187 except KeyError:
1189 1188 print ('Incorrect argument. Use on/1, off/0, '
1190 1189 'or nothing for a toggle.')
1191 1190 return
1192 1191 else:
1193 1192 # toggle
1194 1193 new_pdb = not self.shell.call_pdb
1195 1194
1196 1195 # set on the shell
1197 1196 self.shell.call_pdb = new_pdb
1198 1197 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1199 1198
1200 1199 def magic_debug(self, parameter_s=''):
1201 1200 """Activate the interactive debugger in post-mortem mode.
1202 1201
1203 1202 If an exception has just occurred, this lets you inspect its stack
1204 1203 frames interactively. Note that this will always work only on the last
1205 1204 traceback that occurred, so you must call this quickly after an
1206 1205 exception that you wish to inspect has fired, because if another one
1207 1206 occurs, it clobbers the previous one.
1208 1207
1209 1208 If you want IPython to automatically do this on every exception, see
1210 1209 the %pdb magic for more details.
1211 1210 """
1212 1211
1213 1212 self.shell.debugger(force=True)
1214 1213
1215 1214 def magic_prun(self, parameter_s ='',user_mode=1,
1216 1215 opts=None,arg_lst=None,prog_ns=None):
1217 1216
1218 1217 """Run a statement through the python code profiler.
1219 1218
1220 1219 Usage:\\
1221 1220 %prun [options] statement
1222 1221
1223 1222 The given statement (which doesn't require quote marks) is run via the
1224 1223 python profiler in a manner similar to the profile.run() function.
1225 1224 Namespaces are internally managed to work correctly; profile.run
1226 1225 cannot be used in IPython because it makes certain assumptions about
1227 1226 namespaces which do not hold under IPython.
1228 1227
1229 1228 Options:
1230 1229
1231 1230 -l <limit>: you can place restrictions on what or how much of the
1232 1231 profile gets printed. The limit value can be:
1233 1232
1234 1233 * A string: only information for function names containing this string
1235 1234 is printed.
1236 1235
1237 1236 * An integer: only these many lines are printed.
1238 1237
1239 1238 * A float (between 0 and 1): this fraction of the report is printed
1240 1239 (for example, use a limit of 0.4 to see the topmost 40% only).
1241 1240
1242 1241 You can combine several limits with repeated use of the option. For
1243 1242 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1244 1243 information about class constructors.
1245 1244
1246 1245 -r: return the pstats.Stats object generated by the profiling. This
1247 1246 object has all the information about the profile in it, and you can
1248 1247 later use it for further analysis or in other functions.
1249 1248
1250 1249 -s <key>: sort profile by given key. You can provide more than one key
1251 1250 by using the option several times: '-s key1 -s key2 -s key3...'. The
1252 1251 default sorting key is 'time'.
1253 1252
1254 1253 The following is copied verbatim from the profile documentation
1255 1254 referenced below:
1256 1255
1257 1256 When more than one key is provided, additional keys are used as
1258 1257 secondary criteria when the there is equality in all keys selected
1259 1258 before them.
1260 1259
1261 1260 Abbreviations can be used for any key names, as long as the
1262 1261 abbreviation is unambiguous. The following are the keys currently
1263 1262 defined:
1264 1263
1265 1264 Valid Arg Meaning\\
1266 1265 "calls" call count\\
1267 1266 "cumulative" cumulative time\\
1268 1267 "file" file name\\
1269 1268 "module" file name\\
1270 1269 "pcalls" primitive call count\\
1271 1270 "line" line number\\
1272 1271 "name" function name\\
1273 1272 "nfl" name/file/line\\
1274 1273 "stdname" standard name\\
1275 1274 "time" internal time
1276 1275
1277 1276 Note that all sorts on statistics are in descending order (placing
1278 1277 most time consuming items first), where as name, file, and line number
1279 1278 searches are in ascending order (i.e., alphabetical). The subtle
1280 1279 distinction between "nfl" and "stdname" is that the standard name is a
1281 1280 sort of the name as printed, which means that the embedded line
1282 1281 numbers get compared in an odd way. For example, lines 3, 20, and 40
1283 1282 would (if the file names were the same) appear in the string order
1284 1283 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1285 1284 line numbers. In fact, sort_stats("nfl") is the same as
1286 1285 sort_stats("name", "file", "line").
1287 1286
1288 1287 -T <filename>: save profile results as shown on screen to a text
1289 1288 file. The profile is still shown on screen.
1290 1289
1291 1290 -D <filename>: save (via dump_stats) profile statistics to given
1292 1291 filename. This data is in a format understod by the pstats module, and
1293 1292 is generated by a call to the dump_stats() method of profile
1294 1293 objects. The profile is still shown on screen.
1295 1294
1296 1295 If you want to run complete programs under the profiler's control, use
1297 1296 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1298 1297 contains profiler specific options as described here.
1299 1298
1300 1299 You can read the complete documentation for the profile module with:\\
1301 1300 In [1]: import profile; profile.help() """
1302 1301
1303 1302 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1304 1303 # protect user quote marks
1305 1304 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1306 1305
1307 1306 if user_mode: # regular user call
1308 1307 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1309 1308 list_all=1)
1310 1309 namespace = self.shell.user_ns
1311 1310 else: # called to run a program by %run -p
1312 1311 try:
1313 1312 filename = get_py_filename(arg_lst[0])
1314 1313 except IOError,msg:
1315 1314 error(msg)
1316 1315 return
1317 1316
1318 1317 arg_str = 'execfile(filename,prog_ns)'
1319 1318 namespace = locals()
1320 1319
1321 1320 opts.merge(opts_def)
1322 1321
1323 1322 prof = profile.Profile()
1324 1323 try:
1325 1324 prof = prof.runctx(arg_str,namespace,namespace)
1326 1325 sys_exit = ''
1327 1326 except SystemExit:
1328 1327 sys_exit = """*** SystemExit exception caught in code being profiled."""
1329 1328
1330 1329 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1331 1330
1332 1331 lims = opts.l
1333 1332 if lims:
1334 1333 lims = [] # rebuild lims with ints/floats/strings
1335 1334 for lim in opts.l:
1336 1335 try:
1337 1336 lims.append(int(lim))
1338 1337 except ValueError:
1339 1338 try:
1340 1339 lims.append(float(lim))
1341 1340 except ValueError:
1342 1341 lims.append(lim)
1343 1342
1344 1343 # trap output
1345 1344 sys_stdout = sys.stdout
1346 1345 stdout_trap = StringIO()
1347 1346 try:
1348 1347 sys.stdout = stdout_trap
1349 1348 stats.print_stats(*lims)
1350 1349 finally:
1351 1350 sys.stdout = sys_stdout
1352 1351 output = stdout_trap.getvalue()
1353 1352 output = output.rstrip()
1354 1353
1355 1354 page(output,screen_lines=self.shell.rc.screen_length)
1356 1355 print sys_exit,
1357 1356
1358 1357 dump_file = opts.D[0]
1359 1358 text_file = opts.T[0]
1360 1359 if dump_file:
1361 1360 prof.dump_stats(dump_file)
1362 1361 print '\n*** Profile stats marshalled to file',\
1363 1362 `dump_file`+'.',sys_exit
1364 1363 if text_file:
1365 1364 file(text_file,'w').write(output)
1366 1365 print '\n*** Profile printout saved to text file',\
1367 1366 `text_file`+'.',sys_exit
1368 1367
1369 1368 if opts.has_key('r'):
1370 1369 return stats
1371 1370 else:
1372 1371 return None
1373 1372
1374 1373 def magic_run(self, parameter_s ='',runner=None):
1375 1374 """Run the named file inside IPython as a program.
1376 1375
1377 1376 Usage:\\
1378 1377 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1379 1378
1380 1379 Parameters after the filename are passed as command-line arguments to
1381 1380 the program (put in sys.argv). Then, control returns to IPython's
1382 1381 prompt.
1383 1382
1384 1383 This is similar to running at a system prompt:\\
1385 1384 $ python file args\\
1386 1385 but with the advantage of giving you IPython's tracebacks, and of
1387 1386 loading all variables into your interactive namespace for further use
1388 1387 (unless -p is used, see below).
1389 1388
1390 1389 The file is executed in a namespace initially consisting only of
1391 1390 __name__=='__main__' and sys.argv constructed as indicated. It thus
1392 1391 sees its environment as if it were being run as a stand-alone
1393 1392 program. But after execution, the IPython interactive namespace gets
1394 1393 updated with all variables defined in the program (except for __name__
1395 1394 and sys.argv). This allows for very convenient loading of code for
1396 1395 interactive work, while giving each program a 'clean sheet' to run in.
1397 1396
1398 1397 Options:
1399 1398
1400 1399 -n: __name__ is NOT set to '__main__', but to the running file's name
1401 1400 without extension (as python does under import). This allows running
1402 1401 scripts and reloading the definitions in them without calling code
1403 1402 protected by an ' if __name__ == "__main__" ' clause.
1404 1403
1405 1404 -i: run the file in IPython's namespace instead of an empty one. This
1406 1405 is useful if you are experimenting with code written in a text editor
1407 1406 which depends on variables defined interactively.
1408 1407
1409 1408 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1410 1409 being run. This is particularly useful if IPython is being used to
1411 1410 run unittests, which always exit with a sys.exit() call. In such
1412 1411 cases you are interested in the output of the test results, not in
1413 1412 seeing a traceback of the unittest module.
1414 1413
1415 1414 -t: print timing information at the end of the run. IPython will give
1416 1415 you an estimated CPU time consumption for your script, which under
1417 1416 Unix uses the resource module to avoid the wraparound problems of
1418 1417 time.clock(). Under Unix, an estimate of time spent on system tasks
1419 1418 is also given (for Windows platforms this is reported as 0.0).
1420 1419
1421 1420 If -t is given, an additional -N<N> option can be given, where <N>
1422 1421 must be an integer indicating how many times you want the script to
1423 1422 run. The final timing report will include total and per run results.
1424 1423
1425 1424 For example (testing the script uniq_stable.py):
1426 1425
1427 1426 In [1]: run -t uniq_stable
1428 1427
1429 1428 IPython CPU timings (estimated):\\
1430 1429 User : 0.19597 s.\\
1431 1430 System: 0.0 s.\\
1432 1431
1433 1432 In [2]: run -t -N5 uniq_stable
1434 1433
1435 1434 IPython CPU timings (estimated):\\
1436 1435 Total runs performed: 5\\
1437 1436 Times : Total Per run\\
1438 1437 User : 0.910862 s, 0.1821724 s.\\
1439 1438 System: 0.0 s, 0.0 s.
1440 1439
1441 1440 -d: run your program under the control of pdb, the Python debugger.
1442 1441 This allows you to execute your program step by step, watch variables,
1443 1442 etc. Internally, what IPython does is similar to calling:
1444 1443
1445 1444 pdb.run('execfile("YOURFILENAME")')
1446 1445
1447 1446 with a breakpoint set on line 1 of your file. You can change the line
1448 1447 number for this automatic breakpoint to be <N> by using the -bN option
1449 1448 (where N must be an integer). For example:
1450 1449
1451 1450 %run -d -b40 myscript
1452 1451
1453 1452 will set the first breakpoint at line 40 in myscript.py. Note that
1454 1453 the first breakpoint must be set on a line which actually does
1455 1454 something (not a comment or docstring) for it to stop execution.
1456 1455
1457 1456 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1458 1457 first enter 'c' (without qoutes) to start execution up to the first
1459 1458 breakpoint.
1460 1459
1461 1460 Entering 'help' gives information about the use of the debugger. You
1462 1461 can easily see pdb's full documentation with "import pdb;pdb.help()"
1463 1462 at a prompt.
1464 1463
1465 1464 -p: run program under the control of the Python profiler module (which
1466 1465 prints a detailed report of execution times, function calls, etc).
1467 1466
1468 1467 You can pass other options after -p which affect the behavior of the
1469 1468 profiler itself. See the docs for %prun for details.
1470 1469
1471 1470 In this mode, the program's variables do NOT propagate back to the
1472 1471 IPython interactive namespace (because they remain in the namespace
1473 1472 where the profiler executes them).
1474 1473
1475 1474 Internally this triggers a call to %prun, see its documentation for
1476 1475 details on the options available specifically for profiling."""
1477 1476
1478 1477 # get arguments and set sys.argv for program to be run.
1479 1478 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1480 1479 mode='list',list_all=1)
1481 1480
1482 1481 try:
1483 1482 filename = get_py_filename(arg_lst[0])
1484 1483 except IndexError:
1485 1484 warn('you must provide at least a filename.')
1486 1485 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1487 1486 return
1488 1487 except IOError,msg:
1489 1488 error(msg)
1490 1489 return
1491 1490
1492 1491 # Control the response to exit() calls made by the script being run
1493 1492 exit_ignore = opts.has_key('e')
1494 1493
1495 1494 # Make sure that the running script gets a proper sys.argv as if it
1496 1495 # were run from a system shell.
1497 1496 save_argv = sys.argv # save it for later restoring
1498 1497 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1499 1498
1500 1499 if opts.has_key('i'):
1501 1500 prog_ns = self.shell.user_ns
1502 1501 __name__save = self.shell.user_ns['__name__']
1503 1502 prog_ns['__name__'] = '__main__'
1504 1503 else:
1505 1504 if opts.has_key('n'):
1506 1505 name = os.path.splitext(os.path.basename(filename))[0]
1507 1506 else:
1508 1507 name = '__main__'
1509 1508 prog_ns = {'__name__':name}
1510 1509
1511 1510 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1512 1511 # set the __file__ global in the script's namespace
1513 1512 prog_ns['__file__'] = filename
1514 1513
1515 1514 # pickle fix. See iplib for an explanation. But we need to make sure
1516 1515 # that, if we overwrite __main__, we replace it at the end
1517 1516 if prog_ns['__name__'] == '__main__':
1518 1517 restore_main = sys.modules['__main__']
1519 1518 else:
1520 1519 restore_main = False
1521 1520
1522 1521 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1523 1522
1524 1523 stats = None
1525 1524 try:
1526 1525 if self.shell.has_readline:
1527 1526 self.shell.savehist()
1528 1527
1529 1528 if opts.has_key('p'):
1530 1529 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1531 1530 else:
1532 1531 if opts.has_key('d'):
1533 1532 deb = Debugger.Pdb(self.shell.rc.colors)
1534 1533 # reset Breakpoint state, which is moronically kept
1535 1534 # in a class
1536 1535 bdb.Breakpoint.next = 1
1537 1536 bdb.Breakpoint.bplist = {}
1538 1537 bdb.Breakpoint.bpbynumber = [None]
1539 1538 # Set an initial breakpoint to stop execution
1540 1539 maxtries = 10
1541 1540 bp = int(opts.get('b',[1])[0])
1542 1541 checkline = deb.checkline(filename,bp)
1543 1542 if not checkline:
1544 1543 for bp in range(bp+1,bp+maxtries+1):
1545 1544 if deb.checkline(filename,bp):
1546 1545 break
1547 1546 else:
1548 1547 msg = ("\nI failed to find a valid line to set "
1549 1548 "a breakpoint\n"
1550 1549 "after trying up to line: %s.\n"
1551 1550 "Please set a valid breakpoint manually "
1552 1551 "with the -b option." % bp)
1553 1552 error(msg)
1554 1553 return
1555 1554 # if we find a good linenumber, set the breakpoint
1556 1555 deb.do_break('%s:%s' % (filename,bp))
1557 1556 # Start file run
1558 1557 print "NOTE: Enter 'c' at the",
1559 1558 print "%s prompt to start your script." % deb.prompt
1560 1559 try:
1561 1560 deb.run('execfile("%s")' % filename,prog_ns)
1562 1561
1563 1562 except:
1564 1563 etype, value, tb = sys.exc_info()
1565 1564 # Skip three frames in the traceback: the %run one,
1566 1565 # one inside bdb.py, and the command-line typed by the
1567 1566 # user (run by exec in pdb itself).
1568 1567 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1569 1568 else:
1570 1569 if runner is None:
1571 1570 runner = self.shell.safe_execfile
1572 1571 if opts.has_key('t'):
1573 1572 try:
1574 1573 nruns = int(opts['N'][0])
1575 1574 if nruns < 1:
1576 1575 error('Number of runs must be >=1')
1577 1576 return
1578 1577 except (KeyError):
1579 1578 nruns = 1
1580 1579 if nruns == 1:
1581 1580 t0 = clock2()
1582 1581 runner(filename,prog_ns,prog_ns,
1583 1582 exit_ignore=exit_ignore)
1584 1583 t1 = clock2()
1585 1584 t_usr = t1[0]-t0[0]
1586 1585 t_sys = t1[1]-t1[1]
1587 1586 print "\nIPython CPU timings (estimated):"
1588 1587 print " User : %10s s." % t_usr
1589 1588 print " System: %10s s." % t_sys
1590 1589 else:
1591 1590 runs = range(nruns)
1592 1591 t0 = clock2()
1593 1592 for nr in runs:
1594 1593 runner(filename,prog_ns,prog_ns,
1595 1594 exit_ignore=exit_ignore)
1596 1595 t1 = clock2()
1597 1596 t_usr = t1[0]-t0[0]
1598 1597 t_sys = t1[1]-t1[1]
1599 1598 print "\nIPython CPU timings (estimated):"
1600 1599 print "Total runs performed:",nruns
1601 1600 print " Times : %10s %10s" % ('Total','Per run')
1602 1601 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1603 1602 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1604 1603
1605 1604 else:
1606 1605 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1607 1606 if opts.has_key('i'):
1608 1607 self.shell.user_ns['__name__'] = __name__save
1609 1608 else:
1610 1609 # update IPython interactive namespace
1611 1610 del prog_ns['__name__']
1612 1611 self.shell.user_ns.update(prog_ns)
1613 1612 finally:
1614 1613 sys.argv = save_argv
1615 1614 if restore_main:
1616 1615 sys.modules['__main__'] = restore_main
1617 1616 if self.shell.has_readline:
1618 1617 self.shell.readline.read_history_file(self.shell.histfile)
1619 1618
1620 1619 return stats
1621 1620
1622 1621 def magic_runlog(self, parameter_s =''):
1623 1622 """Run files as logs.
1624 1623
1625 1624 Usage:\\
1626 1625 %runlog file1 file2 ...
1627 1626
1628 1627 Run the named files (treating them as log files) in sequence inside
1629 1628 the interpreter, and return to the prompt. This is much slower than
1630 1629 %run because each line is executed in a try/except block, but it
1631 1630 allows running files with syntax errors in them.
1632 1631
1633 1632 Normally IPython will guess when a file is one of its own logfiles, so
1634 1633 you can typically use %run even for logs. This shorthand allows you to
1635 1634 force any file to be treated as a log file."""
1636 1635
1637 1636 for f in parameter_s.split():
1638 1637 self.shell.safe_execfile(f,self.shell.user_ns,
1639 1638 self.shell.user_ns,islog=1)
1640 1639
1641 1640 def magic_timeit(self, parameter_s =''):
1642 1641 """Time execution of a Python statement or expression
1643 1642
1644 1643 Usage:\\
1645 1644 %timeit [-n<N> -r<R> [-t|-c]] statement
1646 1645
1647 1646 Time execution of a Python statement or expression using the timeit
1648 1647 module.
1649 1648
1650 1649 Options:
1651 1650 -n<N>: execute the given statement <N> times in a loop. If this value
1652 1651 is not given, a fitting value is chosen.
1653 1652
1654 1653 -r<R>: repeat the loop iteration <R> times and take the best result.
1655 1654 Default: 3
1656 1655
1657 1656 -t: use time.time to measure the time, which is the default on Unix.
1658 1657 This function measures wall time.
1659 1658
1660 1659 -c: use time.clock to measure the time, which is the default on
1661 1660 Windows and measures wall time. On Unix, resource.getrusage is used
1662 1661 instead and returns the CPU user time.
1663 1662
1664 1663 -p<P>: use a precision of <P> digits to display the timing result.
1665 1664 Default: 3
1666 1665
1667 1666
1668 1667 Examples:\\
1669 1668 In [1]: %timeit pass
1670 1669 10000000 loops, best of 3: 53.3 ns per loop
1671 1670
1672 1671 In [2]: u = None
1673 1672
1674 1673 In [3]: %timeit u is None
1675 1674 10000000 loops, best of 3: 184 ns per loop
1676 1675
1677 1676 In [4]: %timeit -r 4 u == None
1678 1677 1000000 loops, best of 4: 242 ns per loop
1679 1678
1680 1679 In [5]: import time
1681 1680
1682 1681 In [6]: %timeit -n1 time.sleep(2)
1683 1682 1 loops, best of 3: 2 s per loop
1684 1683
1685 1684
1686 1685 The times reported by %timeit will be slightly higher than those
1687 1686 reported by the timeit.py script when variables are accessed. This is
1688 1687 due to the fact that %timeit executes the statement in the namespace
1689 1688 of the shell, compared with timeit.py, which uses a single setup
1690 1689 statement to import function or create variables. Generally, the bias
1691 1690 does not matter as long as results from timeit.py are not mixed with
1692 1691 those from %timeit."""
1693 1692
1694 1693 import timeit
1695 1694 import math
1696 1695
1697 1696 units = ["s", "ms", "\xc2\xb5s", "ns"]
1698 1697 scaling = [1, 1e3, 1e6, 1e9]
1699 1698
1700 1699 opts, stmt = self.parse_options(parameter_s,'n:r:tcp:',
1701 1700 posix=False)
1702 1701 if stmt == "":
1703 1702 return
1704 1703 timefunc = timeit.default_timer
1705 1704 number = int(getattr(opts, "n", 0))
1706 1705 repeat = int(getattr(opts, "r", timeit.default_repeat))
1707 1706 precision = int(getattr(opts, "p", 3))
1708 1707 if hasattr(opts, "t"):
1709 1708 timefunc = time.time
1710 1709 if hasattr(opts, "c"):
1711 1710 timefunc = clock
1712 1711
1713 1712 timer = timeit.Timer(timer=timefunc)
1714 1713 # this code has tight coupling to the inner workings of timeit.Timer,
1715 1714 # but is there a better way to achieve that the code stmt has access
1716 1715 # to the shell namespace?
1717 1716
1718 1717 src = timeit.template % {'stmt': timeit.reindent(stmt, 8),
1719 1718 'setup': "pass"}
1720 1719 code = compile(src, "<magic-timeit>", "exec")
1721 1720 ns = {}
1722 1721 exec code in self.shell.user_ns, ns
1723 1722 timer.inner = ns["inner"]
1724 1723
1725 1724 if number == 0:
1726 1725 # determine number so that 0.2 <= total time < 2.0
1727 1726 number = 1
1728 1727 for i in range(1, 10):
1729 1728 number *= 10
1730 1729 if timer.timeit(number) >= 0.2:
1731 1730 break
1732 1731
1733 1732 best = min(timer.repeat(repeat, number)) / number
1734 1733
1735 1734 if best > 0.0:
1736 1735 order = min(-int(math.floor(math.log10(best)) // 3), 3)
1737 1736 else:
1738 1737 order = 3
1739 1738 print "%d loops, best of %d: %.*g %s per loop" % (number, repeat,
1740 1739 precision,
1741 1740 best * scaling[order],
1742 1741 units[order])
1743 1742
1744 1743 def magic_time(self,parameter_s = ''):
1745 1744 """Time execution of a Python statement or expression.
1746 1745
1747 1746 The CPU and wall clock times are printed, and the value of the
1748 1747 expression (if any) is returned. Note that under Win32, system time
1749 1748 is always reported as 0, since it can not be measured.
1750 1749
1751 1750 This function provides very basic timing functionality. In Python
1752 1751 2.3, the timeit module offers more control and sophistication, so this
1753 1752 could be rewritten to use it (patches welcome).
1754 1753
1755 1754 Some examples:
1756 1755
1757 1756 In [1]: time 2**128
1758 1757 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1759 1758 Wall time: 0.00
1760 1759 Out[1]: 340282366920938463463374607431768211456L
1761 1760
1762 1761 In [2]: n = 1000000
1763 1762
1764 1763 In [3]: time sum(range(n))
1765 1764 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1766 1765 Wall time: 1.37
1767 1766 Out[3]: 499999500000L
1768 1767
1769 1768 In [4]: time print 'hello world'
1770 1769 hello world
1771 1770 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1772 1771 Wall time: 0.00
1773 1772 """
1774 1773
1775 1774 # fail immediately if the given expression can't be compiled
1776 1775 try:
1777 1776 mode = 'eval'
1778 1777 code = compile(parameter_s,'<timed eval>',mode)
1779 1778 except SyntaxError:
1780 1779 mode = 'exec'
1781 1780 code = compile(parameter_s,'<timed exec>',mode)
1782 1781 # skew measurement as little as possible
1783 1782 glob = self.shell.user_ns
1784 1783 clk = clock2
1785 1784 wtime = time.time
1786 1785 # time execution
1787 1786 wall_st = wtime()
1788 1787 if mode=='eval':
1789 1788 st = clk()
1790 1789 out = eval(code,glob)
1791 1790 end = clk()
1792 1791 else:
1793 1792 st = clk()
1794 1793 exec code in glob
1795 1794 end = clk()
1796 1795 out = None
1797 1796 wall_end = wtime()
1798 1797 # Compute actual times and report
1799 1798 wall_time = wall_end-wall_st
1800 1799 cpu_user = end[0]-st[0]
1801 1800 cpu_sys = end[1]-st[1]
1802 1801 cpu_tot = cpu_user+cpu_sys
1803 1802 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1804 1803 (cpu_user,cpu_sys,cpu_tot)
1805 1804 print "Wall time: %.2f" % wall_time
1806 1805 return out
1807 1806
1808 1807 def magic_macro(self,parameter_s = ''):
1809 1808 """Define a set of input lines as a macro for future re-execution.
1810 1809
1811 1810 Usage:\\
1812 1811 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
1813 1812
1814 1813 Options:
1815 1814
1816 1815 -r: use 'raw' input. By default, the 'processed' history is used,
1817 1816 so that magics are loaded in their transformed version to valid
1818 1817 Python. If this option is given, the raw input as typed as the
1819 1818 command line is used instead.
1820 1819
1821 1820 This will define a global variable called `name` which is a string
1822 1821 made of joining the slices and lines you specify (n1,n2,... numbers
1823 1822 above) from your input history into a single string. This variable
1824 1823 acts like an automatic function which re-executes those lines as if
1825 1824 you had typed them. You just type 'name' at the prompt and the code
1826 1825 executes.
1827 1826
1828 1827 The notation for indicating number ranges is: n1-n2 means 'use line
1829 1828 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1830 1829 using the lines numbered 5,6 and 7.
1831 1830
1832 1831 Note: as a 'hidden' feature, you can also use traditional python slice
1833 1832 notation, where N:M means numbers N through M-1.
1834 1833
1835 1834 For example, if your history contains (%hist prints it):
1836 1835
1837 1836 44: x=1\\
1838 1837 45: y=3\\
1839 1838 46: z=x+y\\
1840 1839 47: print x\\
1841 1840 48: a=5\\
1842 1841 49: print 'x',x,'y',y\\
1843 1842
1844 1843 you can create a macro with lines 44 through 47 (included) and line 49
1845 1844 called my_macro with:
1846 1845
1847 1846 In [51]: %macro my_macro 44-47 49
1848 1847
1849 1848 Now, typing `my_macro` (without quotes) will re-execute all this code
1850 1849 in one pass.
1851 1850
1852 1851 You don't need to give the line-numbers in order, and any given line
1853 1852 number can appear multiple times. You can assemble macros with any
1854 1853 lines from your input history in any order.
1855 1854
1856 1855 The macro is a simple object which holds its value in an attribute,
1857 1856 but IPython's display system checks for macros and executes them as
1858 1857 code instead of printing them when you type their name.
1859 1858
1860 1859 You can view a macro's contents by explicitly printing it with:
1861 1860
1862 1861 'print macro_name'.
1863 1862
1864 1863 For one-off cases which DON'T contain magic function calls in them you
1865 1864 can obtain similar results by explicitly executing slices from your
1866 1865 input history with:
1867 1866
1868 1867 In [60]: exec In[44:48]+In[49]"""
1869 1868
1870 1869 opts,args = self.parse_options(parameter_s,'r',mode='list')
1871 1870 name,ranges = args[0], args[1:]
1872 1871 #print 'rng',ranges # dbg
1873 1872 lines = self.extract_input_slices(ranges,opts.has_key('r'))
1874 1873 macro = Macro(lines)
1875 1874 self.shell.user_ns.update({name:macro})
1876 1875 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1877 1876 print 'Macro contents:'
1878 1877 print macro,
1879 1878
1880 1879 def magic_save(self,parameter_s = ''):
1881 1880 """Save a set of lines to a given filename.
1882 1881
1883 1882 Usage:\\
1884 1883 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
1885 1884
1886 1885 Options:
1887 1886
1888 1887 -r: use 'raw' input. By default, the 'processed' history is used,
1889 1888 so that magics are loaded in their transformed version to valid
1890 1889 Python. If this option is given, the raw input as typed as the
1891 1890 command line is used instead.
1892 1891
1893 1892 This function uses the same syntax as %macro for line extraction, but
1894 1893 instead of creating a macro it saves the resulting string to the
1895 1894 filename you specify.
1896 1895
1897 1896 It adds a '.py' extension to the file if you don't do so yourself, and
1898 1897 it asks for confirmation before overwriting existing files."""
1899 1898
1900 1899 opts,args = self.parse_options(parameter_s,'r',mode='list')
1901 1900 fname,ranges = args[0], args[1:]
1902 1901 if not fname.endswith('.py'):
1903 1902 fname += '.py'
1904 1903 if os.path.isfile(fname):
1905 1904 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1906 1905 if ans.lower() not in ['y','yes']:
1907 1906 print 'Operation cancelled.'
1908 1907 return
1909 1908 cmds = ''.join(self.extract_input_slices(ranges,opts.has_key('r')))
1910 1909 f = file(fname,'w')
1911 1910 f.write(cmds)
1912 1911 f.close()
1913 1912 print 'The following commands were written to file `%s`:' % fname
1914 1913 print cmds
1915 1914
1916 1915 def _edit_macro(self,mname,macro):
1917 1916 """open an editor with the macro data in a file"""
1918 1917 filename = self.shell.mktempfile(macro.value)
1919 1918 self.shell.hooks.editor(filename)
1920 1919
1921 1920 # and make a new macro object, to replace the old one
1922 1921 mfile = open(filename)
1923 1922 mvalue = mfile.read()
1924 1923 mfile.close()
1925 1924 self.shell.user_ns[mname] = Macro(mvalue)
1926 1925
1927 1926 def magic_ed(self,parameter_s=''):
1928 1927 """Alias to %edit."""
1929 1928 return self.magic_edit(parameter_s)
1930 1929
1931 1930 def magic_edit(self,parameter_s='',last_call=['','']):
1932 1931 """Bring up an editor and execute the resulting code.
1933 1932
1934 1933 Usage:
1935 1934 %edit [options] [args]
1936 1935
1937 1936 %edit runs IPython's editor hook. The default version of this hook is
1938 1937 set to call the __IPYTHON__.rc.editor command. This is read from your
1939 1938 environment variable $EDITOR. If this isn't found, it will default to
1940 1939 vi under Linux/Unix and to notepad under Windows. See the end of this
1941 1940 docstring for how to change the editor hook.
1942 1941
1943 1942 You can also set the value of this editor via the command line option
1944 1943 '-editor' or in your ipythonrc file. This is useful if you wish to use
1945 1944 specifically for IPython an editor different from your typical default
1946 1945 (and for Windows users who typically don't set environment variables).
1947 1946
1948 1947 This command allows you to conveniently edit multi-line code right in
1949 1948 your IPython session.
1950 1949
1951 1950 If called without arguments, %edit opens up an empty editor with a
1952 1951 temporary file and will execute the contents of this file when you
1953 1952 close it (don't forget to save it!).
1954 1953
1955 1954
1956 1955 Options:
1957 1956
1958 1957 -n <number>: open the editor at a specified line number. By default,
1959 1958 the IPython editor hook uses the unix syntax 'editor +N filename', but
1960 1959 you can configure this by providing your own modified hook if your
1961 1960 favorite editor supports line-number specifications with a different
1962 1961 syntax.
1963 1962
1964 1963 -p: this will call the editor with the same data as the previous time
1965 1964 it was used, regardless of how long ago (in your current session) it
1966 1965 was.
1967 1966
1968 1967 -r: use 'raw' input. This option only applies to input taken from the
1969 1968 user's history. By default, the 'processed' history is used, so that
1970 1969 magics are loaded in their transformed version to valid Python. If
1971 1970 this option is given, the raw input as typed as the command line is
1972 1971 used instead. When you exit the editor, it will be executed by
1973 1972 IPython's own processor.
1974 1973
1975 1974 -x: do not execute the edited code immediately upon exit. This is
1976 1975 mainly useful if you are editing programs which need to be called with
1977 1976 command line arguments, which you can then do using %run.
1978 1977
1979 1978
1980 1979 Arguments:
1981 1980
1982 1981 If arguments are given, the following possibilites exist:
1983 1982
1984 1983 - The arguments are numbers or pairs of colon-separated numbers (like
1985 1984 1 4:8 9). These are interpreted as lines of previous input to be
1986 1985 loaded into the editor. The syntax is the same of the %macro command.
1987 1986
1988 1987 - If the argument doesn't start with a number, it is evaluated as a
1989 1988 variable and its contents loaded into the editor. You can thus edit
1990 1989 any string which contains python code (including the result of
1991 1990 previous edits).
1992 1991
1993 1992 - If the argument is the name of an object (other than a string),
1994 1993 IPython will try to locate the file where it was defined and open the
1995 1994 editor at the point where it is defined. You can use `%edit function`
1996 1995 to load an editor exactly at the point where 'function' is defined,
1997 1996 edit it and have the file be executed automatically.
1998 1997
1999 1998 If the object is a macro (see %macro for details), this opens up your
2000 1999 specified editor with a temporary file containing the macro's data.
2001 2000 Upon exit, the macro is reloaded with the contents of the file.
2002 2001
2003 2002 Note: opening at an exact line is only supported under Unix, and some
2004 2003 editors (like kedit and gedit up to Gnome 2.8) do not understand the
2005 2004 '+NUMBER' parameter necessary for this feature. Good editors like
2006 2005 (X)Emacs, vi, jed, pico and joe all do.
2007 2006
2008 2007 - If the argument is not found as a variable, IPython will look for a
2009 2008 file with that name (adding .py if necessary) and load it into the
2010 2009 editor. It will execute its contents with execfile() when you exit,
2011 2010 loading any code in the file into your interactive namespace.
2012 2011
2013 2012 After executing your code, %edit will return as output the code you
2014 2013 typed in the editor (except when it was an existing file). This way
2015 2014 you can reload the code in further invocations of %edit as a variable,
2016 2015 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
2017 2016 the output.
2018 2017
2019 2018 Note that %edit is also available through the alias %ed.
2020 2019
2021 2020 This is an example of creating a simple function inside the editor and
2022 2021 then modifying it. First, start up the editor:
2023 2022
2024 2023 In [1]: ed\\
2025 2024 Editing... done. Executing edited code...\\
2026 2025 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
2027 2026
2028 2027 We can then call the function foo():
2029 2028
2030 2029 In [2]: foo()\\
2031 2030 foo() was defined in an editing session
2032 2031
2033 2032 Now we edit foo. IPython automatically loads the editor with the
2034 2033 (temporary) file where foo() was previously defined:
2035 2034
2036 2035 In [3]: ed foo\\
2037 2036 Editing... done. Executing edited code...
2038 2037
2039 2038 And if we call foo() again we get the modified version:
2040 2039
2041 2040 In [4]: foo()\\
2042 2041 foo() has now been changed!
2043 2042
2044 2043 Here is an example of how to edit a code snippet successive
2045 2044 times. First we call the editor:
2046 2045
2047 2046 In [8]: ed\\
2048 2047 Editing... done. Executing edited code...\\
2049 2048 hello\\
2050 2049 Out[8]: "print 'hello'\\n"
2051 2050
2052 2051 Now we call it again with the previous output (stored in _):
2053 2052
2054 2053 In [9]: ed _\\
2055 2054 Editing... done. Executing edited code...\\
2056 2055 hello world\\
2057 2056 Out[9]: "print 'hello world'\\n"
2058 2057
2059 2058 Now we call it with the output #8 (stored in _8, also as Out[8]):
2060 2059
2061 2060 In [10]: ed _8\\
2062 2061 Editing... done. Executing edited code...\\
2063 2062 hello again\\
2064 2063 Out[10]: "print 'hello again'\\n"
2065 2064
2066 2065
2067 2066 Changing the default editor hook:
2068 2067
2069 2068 If you wish to write your own editor hook, you can put it in a
2070 2069 configuration file which you load at startup time. The default hook
2071 2070 is defined in the IPython.hooks module, and you can use that as a
2072 2071 starting example for further modifications. That file also has
2073 2072 general instructions on how to set a new hook for use once you've
2074 2073 defined it."""
2075 2074
2076 2075 # FIXME: This function has become a convoluted mess. It needs a
2077 2076 # ground-up rewrite with clean, simple logic.
2078 2077
2079 2078 def make_filename(arg):
2080 2079 "Make a filename from the given args"
2081 2080 try:
2082 2081 filename = get_py_filename(arg)
2083 2082 except IOError:
2084 2083 if args.endswith('.py'):
2085 2084 filename = arg
2086 2085 else:
2087 2086 filename = None
2088 2087 return filename
2089 2088
2090 2089 # custom exceptions
2091 2090 class DataIsObject(Exception): pass
2092 2091
2093 2092 opts,args = self.parse_options(parameter_s,'prxn:')
2094 2093 # Set a few locals from the options for convenience:
2095 2094 opts_p = opts.has_key('p')
2096 2095 opts_r = opts.has_key('r')
2097 2096
2098 2097 # Default line number value
2099 2098 lineno = opts.get('n',None)
2100 2099
2101 2100 if opts_p:
2102 2101 args = '_%s' % last_call[0]
2103 2102 if not self.shell.user_ns.has_key(args):
2104 2103 args = last_call[1]
2105 2104
2106 2105 # use last_call to remember the state of the previous call, but don't
2107 2106 # let it be clobbered by successive '-p' calls.
2108 2107 try:
2109 2108 last_call[0] = self.shell.outputcache.prompt_count
2110 2109 if not opts_p:
2111 2110 last_call[1] = parameter_s
2112 2111 except:
2113 2112 pass
2114 2113
2115 2114 # by default this is done with temp files, except when the given
2116 2115 # arg is a filename
2117 2116 use_temp = 1
2118 2117
2119 2118 if re.match(r'\d',args):
2120 2119 # Mode where user specifies ranges of lines, like in %macro.
2121 2120 # This means that you can't edit files whose names begin with
2122 2121 # numbers this way. Tough.
2123 2122 ranges = args.split()
2124 2123 data = ''.join(self.extract_input_slices(ranges,opts_r))
2125 2124 elif args.endswith('.py'):
2126 2125 filename = make_filename(args)
2127 2126 data = ''
2128 2127 use_temp = 0
2129 2128 elif args:
2130 2129 try:
2131 2130 # Load the parameter given as a variable. If not a string,
2132 2131 # process it as an object instead (below)
2133 2132
2134 2133 #print '*** args',args,'type',type(args) # dbg
2135 2134 data = eval(args,self.shell.user_ns)
2136 2135 if not type(data) in StringTypes:
2137 2136 raise DataIsObject
2138 2137
2139 2138 except (NameError,SyntaxError):
2140 2139 # given argument is not a variable, try as a filename
2141 2140 filename = make_filename(args)
2142 2141 if filename is None:
2143 2142 warn("Argument given (%s) can't be found as a variable "
2144 2143 "or as a filename." % args)
2145 2144 return
2146 2145
2147 2146 data = ''
2148 2147 use_temp = 0
2149 2148 except DataIsObject:
2150 2149
2151 2150 # macros have a special edit function
2152 2151 if isinstance(data,Macro):
2153 2152 self._edit_macro(args,data)
2154 2153 return
2155 2154
2156 2155 # For objects, try to edit the file where they are defined
2157 2156 try:
2158 2157 filename = inspect.getabsfile(data)
2159 2158 datafile = 1
2160 2159 except TypeError:
2161 2160 filename = make_filename(args)
2162 2161 datafile = 1
2163 2162 warn('Could not find file where `%s` is defined.\n'
2164 2163 'Opening a file named `%s`' % (args,filename))
2165 2164 # Now, make sure we can actually read the source (if it was in
2166 2165 # a temp file it's gone by now).
2167 2166 if datafile:
2168 2167 try:
2169 2168 if lineno is None:
2170 2169 lineno = inspect.getsourcelines(data)[1]
2171 2170 except IOError:
2172 2171 filename = make_filename(args)
2173 2172 if filename is None:
2174 2173 warn('The file `%s` where `%s` was defined cannot '
2175 2174 'be read.' % (filename,data))
2176 2175 return
2177 2176 use_temp = 0
2178 2177 else:
2179 2178 data = ''
2180 2179
2181 2180 if use_temp:
2182 2181 filename = self.shell.mktempfile(data)
2183 2182 print 'IPython will make a temporary file named:',filename
2184 2183
2185 2184 # do actual editing here
2186 2185 print 'Editing...',
2187 2186 sys.stdout.flush()
2188 2187 self.shell.hooks.editor(filename,lineno)
2189 2188 if opts.has_key('x'): # -x prevents actual execution
2190 2189 print
2191 2190 else:
2192 2191 print 'done. Executing edited code...'
2193 2192 if opts_r:
2194 2193 self.shell.runlines(file_read(filename))
2195 2194 else:
2196 2195 self.shell.safe_execfile(filename,self.shell.user_ns)
2197 2196 if use_temp:
2198 2197 try:
2199 2198 return open(filename).read()
2200 2199 except IOError,msg:
2201 2200 if msg.filename == filename:
2202 2201 warn('File not found. Did you forget to save?')
2203 2202 return
2204 2203 else:
2205 2204 self.shell.showtraceback()
2206 2205
2207 2206 def magic_xmode(self,parameter_s = ''):
2208 2207 """Switch modes for the exception handlers.
2209 2208
2210 2209 Valid modes: Plain, Context and Verbose.
2211 2210
2212 2211 If called without arguments, acts as a toggle."""
2213 2212
2214 2213 def xmode_switch_err(name):
2215 2214 warn('Error changing %s exception modes.\n%s' %
2216 2215 (name,sys.exc_info()[1]))
2217 2216
2218 2217 shell = self.shell
2219 2218 new_mode = parameter_s.strip().capitalize()
2220 2219 try:
2221 2220 shell.InteractiveTB.set_mode(mode=new_mode)
2222 2221 print 'Exception reporting mode:',shell.InteractiveTB.mode
2223 2222 except:
2224 2223 xmode_switch_err('user')
2225 2224
2226 2225 # threaded shells use a special handler in sys.excepthook
2227 2226 if shell.isthreaded:
2228 2227 try:
2229 2228 shell.sys_excepthook.set_mode(mode=new_mode)
2230 2229 except:
2231 2230 xmode_switch_err('threaded')
2232 2231
2233 2232 def magic_colors(self,parameter_s = ''):
2234 2233 """Switch color scheme for prompts, info system and exception handlers.
2235 2234
2236 2235 Currently implemented schemes: NoColor, Linux, LightBG.
2237 2236
2238 2237 Color scheme names are not case-sensitive."""
2239 2238
2240 2239 def color_switch_err(name):
2241 2240 warn('Error changing %s color schemes.\n%s' %
2242 2241 (name,sys.exc_info()[1]))
2243 2242
2244 2243
2245 2244 new_scheme = parameter_s.strip()
2246 2245 if not new_scheme:
2247 2246 print 'You must specify a color scheme.'
2248 2247 return
2249 2248 import IPython.rlineimpl as readline
2250 2249 if not readline.have_readline:
2251 2250 msg = """\
2252 2251 Proper color support under MS Windows requires the pyreadline library.
2253 2252 You can find it at:
2254 2253 http://ipython.scipy.org/moin/PyReadline/Intro
2255 2254 Gary's readline needs the ctypes module, from:
2256 2255 http://starship.python.net/crew/theller/ctypes
2257 2256 (Note that ctypes is already part of Python versions 2.5 and newer).
2258 2257
2259 2258 Defaulting color scheme to 'NoColor'"""
2260 2259 new_scheme = 'NoColor'
2261 2260 warn(msg)
2262 2261 # local shortcut
2263 2262 shell = self.shell
2264 2263
2265 2264 # Set prompt colors
2266 2265 try:
2267 2266 shell.outputcache.set_colors(new_scheme)
2268 2267 except:
2269 2268 color_switch_err('prompt')
2270 2269 else:
2271 2270 shell.rc.colors = \
2272 2271 shell.outputcache.color_table.active_scheme_name
2273 2272 # Set exception colors
2274 2273 try:
2275 2274 shell.InteractiveTB.set_colors(scheme = new_scheme)
2276 2275 shell.SyntaxTB.set_colors(scheme = new_scheme)
2277 2276 except:
2278 2277 color_switch_err('exception')
2279 2278
2280 2279 # threaded shells use a verbose traceback in sys.excepthook
2281 2280 if shell.isthreaded:
2282 2281 try:
2283 2282 shell.sys_excepthook.set_colors(scheme=new_scheme)
2284 2283 except:
2285 2284 color_switch_err('system exception handler')
2286 2285
2287 2286 # Set info (for 'object?') colors
2288 2287 if shell.rc.color_info:
2289 2288 try:
2290 2289 shell.inspector.set_active_scheme(new_scheme)
2291 2290 except:
2292 2291 color_switch_err('object inspector')
2293 2292 else:
2294 2293 shell.inspector.set_active_scheme('NoColor')
2295 2294
2296 2295 def magic_color_info(self,parameter_s = ''):
2297 2296 """Toggle color_info.
2298 2297
2299 2298 The color_info configuration parameter controls whether colors are
2300 2299 used for displaying object details (by things like %psource, %pfile or
2301 2300 the '?' system). This function toggles this value with each call.
2302 2301
2303 2302 Note that unless you have a fairly recent pager (less works better
2304 2303 than more) in your system, using colored object information displays
2305 2304 will not work properly. Test it and see."""
2306 2305
2307 2306 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2308 2307 self.magic_colors(self.shell.rc.colors)
2309 2308 print 'Object introspection functions have now coloring:',
2310 2309 print ['OFF','ON'][self.shell.rc.color_info]
2311 2310
2312 2311 def magic_Pprint(self, parameter_s=''):
2313 2312 """Toggle pretty printing on/off."""
2314 2313
2315 2314 self.shell.rc.pprint = 1 - self.shell.rc.pprint
2316 2315 print 'Pretty printing has been turned', \
2317 2316 ['OFF','ON'][self.shell.rc.pprint]
2318 2317
2319 2318 def magic_exit(self, parameter_s=''):
2320 2319 """Exit IPython, confirming if configured to do so.
2321 2320
2322 2321 You can configure whether IPython asks for confirmation upon exit by
2323 2322 setting the confirm_exit flag in the ipythonrc file."""
2324 2323
2325 2324 self.shell.exit()
2326 2325
2327 2326 def magic_quit(self, parameter_s=''):
2328 2327 """Exit IPython, confirming if configured to do so (like %exit)"""
2329 2328
2330 2329 self.shell.exit()
2331 2330
2332 2331 def magic_Exit(self, parameter_s=''):
2333 2332 """Exit IPython without confirmation."""
2334 2333
2335 2334 self.shell.exit_now = True
2336 2335
2337 2336 def magic_Quit(self, parameter_s=''):
2338 2337 """Exit IPython without confirmation (like %Exit)."""
2339 2338
2340 2339 self.shell.exit_now = True
2341 2340
2342 2341 #......................................................................
2343 2342 # Functions to implement unix shell-type things
2344 2343
2345 2344 def magic_alias(self, parameter_s = ''):
2346 2345 """Define an alias for a system command.
2347 2346
2348 2347 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2349 2348
2350 2349 Then, typing 'alias_name params' will execute the system command 'cmd
2351 2350 params' (from your underlying operating system).
2352 2351
2353 2352 Aliases have lower precedence than magic functions and Python normal
2354 2353 variables, so if 'foo' is both a Python variable and an alias, the
2355 2354 alias can not be executed until 'del foo' removes the Python variable.
2356 2355
2357 2356 You can use the %l specifier in an alias definition to represent the
2358 2357 whole line when the alias is called. For example:
2359 2358
2360 2359 In [2]: alias all echo "Input in brackets: <%l>"\\
2361 2360 In [3]: all hello world\\
2362 2361 Input in brackets: <hello world>
2363 2362
2364 2363 You can also define aliases with parameters using %s specifiers (one
2365 2364 per parameter):
2366 2365
2367 2366 In [1]: alias parts echo first %s second %s\\
2368 2367 In [2]: %parts A B\\
2369 2368 first A second B\\
2370 2369 In [3]: %parts A\\
2371 2370 Incorrect number of arguments: 2 expected.\\
2372 2371 parts is an alias to: 'echo first %s second %s'
2373 2372
2374 2373 Note that %l and %s are mutually exclusive. You can only use one or
2375 2374 the other in your aliases.
2376 2375
2377 2376 Aliases expand Python variables just like system calls using ! or !!
2378 2377 do: all expressions prefixed with '$' get expanded. For details of
2379 2378 the semantic rules, see PEP-215:
2380 2379 http://www.python.org/peps/pep-0215.html. This is the library used by
2381 2380 IPython for variable expansion. If you want to access a true shell
2382 2381 variable, an extra $ is necessary to prevent its expansion by IPython:
2383 2382
2384 2383 In [6]: alias show echo\\
2385 2384 In [7]: PATH='A Python string'\\
2386 2385 In [8]: show $PATH\\
2387 2386 A Python string\\
2388 2387 In [9]: show $$PATH\\
2389 2388 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2390 2389
2391 2390 You can use the alias facility to acess all of $PATH. See the %rehash
2392 2391 and %rehashx functions, which automatically create aliases for the
2393 2392 contents of your $PATH.
2394 2393
2395 2394 If called with no parameters, %alias prints the current alias table."""
2396 2395
2397 2396 par = parameter_s.strip()
2398 2397 if not par:
2399 2398 stored = self.db.get('stored_aliases', {} )
2400 2399 atab = self.shell.alias_table
2401 2400 aliases = atab.keys()
2402 2401 aliases.sort()
2403 2402 res = []
2404 2403 showlast = []
2405 2404 for alias in aliases:
2406 2405 tgt = atab[alias][1]
2407 2406 # 'interesting' aliases
2408 2407 if (alias in stored or
2409 2408 alias != os.path.splitext(tgt)[0] or
2410 2409 ' ' in tgt):
2411 2410 showlast.append((alias, tgt))
2412 2411 else:
2413 2412 res.append((alias, tgt ))
2414 2413
2415 2414 # show most interesting aliases last
2416 2415 res.extend(showlast)
2417 2416 print "Total number of aliases:",len(aliases)
2418 2417 return res
2419 2418 try:
2420 2419 alias,cmd = par.split(None,1)
2421 2420 except:
2422 2421 print OInspect.getdoc(self.magic_alias)
2423 2422 else:
2424 2423 nargs = cmd.count('%s')
2425 2424 if nargs>0 and cmd.find('%l')>=0:
2426 2425 error('The %s and %l specifiers are mutually exclusive '
2427 2426 'in alias definitions.')
2428 2427 else: # all looks OK
2429 2428 self.shell.alias_table[alias] = (nargs,cmd)
2430 2429 self.shell.alias_table_validate(verbose=0)
2431 2430 # end magic_alias
2432 2431
2433 2432 def magic_unalias(self, parameter_s = ''):
2434 2433 """Remove an alias"""
2435 2434
2436 2435 aname = parameter_s.strip()
2437 2436 if aname in self.shell.alias_table:
2438 2437 del self.shell.alias_table[aname]
2439 2438 stored = self.db.get('stored_aliases', {} )
2440 2439 if aname in stored:
2441 2440 print "Removing %stored alias",aname
2442 2441 del stored[aname]
2443 2442 self.db['stored_aliases'] = stored
2444 2443
2445 2444 def magic_rehash(self, parameter_s = ''):
2446 2445 """Update the alias table with all entries in $PATH.
2447 2446
2448 2447 This version does no checks on execute permissions or whether the
2449 2448 contents of $PATH are truly files (instead of directories or something
2450 2449 else). For such a safer (but slower) version, use %rehashx."""
2451 2450
2452 2451 # This function (and rehashx) manipulate the alias_table directly
2453 2452 # rather than calling magic_alias, for speed reasons. A rehash on a
2454 2453 # typical Linux box involves several thousand entries, so efficiency
2455 2454 # here is a top concern.
2456 2455
2457 2456 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2458 2457 alias_table = self.shell.alias_table
2459 2458 for pdir in path:
2460 2459 for ff in os.listdir(pdir):
2461 2460 # each entry in the alias table must be (N,name), where
2462 2461 # N is the number of positional arguments of the alias.
2463 2462 alias_table[ff] = (0,ff)
2464 2463 # Make sure the alias table doesn't contain keywords or builtins
2465 2464 self.shell.alias_table_validate()
2466 2465 # Call again init_auto_alias() so we get 'rm -i' and other modified
2467 2466 # aliases since %rehash will probably clobber them
2468 2467 self.shell.init_auto_alias()
2469 2468
2470 2469 def magic_rehashx(self, parameter_s = ''):
2471 2470 """Update the alias table with all executable files in $PATH.
2472 2471
2473 2472 This version explicitly checks that every entry in $PATH is a file
2474 2473 with execute access (os.X_OK), so it is much slower than %rehash.
2475 2474
2476 2475 Under Windows, it checks executability as a match agains a
2477 2476 '|'-separated string of extensions, stored in the IPython config
2478 2477 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2479 2478
2480 2479 path = [os.path.abspath(os.path.expanduser(p)) for p in
2481 2480 os.environ['PATH'].split(os.pathsep)]
2482 2481 path = filter(os.path.isdir,path)
2483 2482
2484 2483 alias_table = self.shell.alias_table
2485 2484 syscmdlist = []
2486 2485 if os.name == 'posix':
2487 2486 isexec = lambda fname:os.path.isfile(fname) and \
2488 2487 os.access(fname,os.X_OK)
2489 2488 else:
2490 2489
2491 2490 try:
2492 2491 winext = os.environ['pathext'].replace(';','|').replace('.','')
2493 2492 except KeyError:
2494 2493 winext = 'exe|com|bat|py'
2495 2494 if 'py' not in winext:
2496 2495 winext += '|py'
2497 2496 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2498 2497 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2499 2498 savedir = os.getcwd()
2500 2499 try:
2501 2500 # write the whole loop for posix/Windows so we don't have an if in
2502 2501 # the innermost part
2503 2502 if os.name == 'posix':
2504 2503 for pdir in path:
2505 2504 os.chdir(pdir)
2506 2505 for ff in os.listdir(pdir):
2507 2506 if isexec(ff) and ff not in self.shell.no_alias:
2508 2507 # each entry in the alias table must be (N,name),
2509 2508 # where N is the number of positional arguments of the
2510 2509 # alias.
2511 2510 alias_table[ff] = (0,ff)
2512 2511 syscmdlist.append(ff)
2513 2512 else:
2514 2513 for pdir in path:
2515 2514 os.chdir(pdir)
2516 2515 for ff in os.listdir(pdir):
2517 2516 base, ext = os.path.splitext(ff)
2518 2517 if isexec(ff) and base not in self.shell.no_alias:
2519 2518 if ext.lower() == '.exe':
2520 2519 ff = base
2521 2520 alias_table[base] = (0,ff)
2522 2521 syscmdlist.append(ff)
2523 2522 # Make sure the alias table doesn't contain keywords or builtins
2524 2523 self.shell.alias_table_validate()
2525 2524 # Call again init_auto_alias() so we get 'rm -i' and other
2526 2525 # modified aliases since %rehashx will probably clobber them
2527 2526 self.shell.init_auto_alias()
2528 2527 db = self.getapi().db
2529 2528 db['syscmdlist'] = syscmdlist
2530 2529 finally:
2531 2530 os.chdir(savedir)
2532 2531
2533 2532 def magic_pwd(self, parameter_s = ''):
2534 2533 """Return the current working directory path."""
2535 2534 return os.getcwd()
2536 2535
2537 2536 def magic_cd(self, parameter_s=''):
2538 2537 """Change the current working directory.
2539 2538
2540 2539 This command automatically maintains an internal list of directories
2541 2540 you visit during your IPython session, in the variable _dh. The
2542 2541 command %dhist shows this history nicely formatted.
2543 2542
2544 2543 Usage:
2545 2544
2546 2545 cd 'dir': changes to directory 'dir'.
2547 2546
2548 2547 cd -: changes to the last visited directory.
2549 2548
2550 2549 cd -<n>: changes to the n-th directory in the directory history.
2551 2550
2552 2551 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2553 2552 (note: cd <bookmark_name> is enough if there is no
2554 2553 directory <bookmark_name>, but a bookmark with the name exists.)
2555 2554
2556 2555 Options:
2557 2556
2558 2557 -q: quiet. Do not print the working directory after the cd command is
2559 2558 executed. By default IPython's cd command does print this directory,
2560 2559 since the default prompts do not display path information.
2561 2560
2562 2561 Note that !cd doesn't work for this purpose because the shell where
2563 2562 !command runs is immediately discarded after executing 'command'."""
2564 2563
2565 2564 parameter_s = parameter_s.strip()
2566 2565 #bkms = self.shell.persist.get("bookmarks",{})
2567 2566
2568 2567 numcd = re.match(r'(-)(\d+)$',parameter_s)
2569 2568 # jump in directory history by number
2570 2569 if numcd:
2571 2570 nn = int(numcd.group(2))
2572 2571 try:
2573 2572 ps = self.shell.user_ns['_dh'][nn]
2574 2573 except IndexError:
2575 2574 print 'The requested directory does not exist in history.'
2576 2575 return
2577 2576 else:
2578 2577 opts = {}
2579 2578 else:
2580 2579 #turn all non-space-escaping backslashes to slashes,
2581 2580 # for c:\windows\directory\names\
2582 2581 parameter_s = re.sub(r'\\(?! )','/', parameter_s)
2583 2582 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2584 2583 # jump to previous
2585 2584 if ps == '-':
2586 2585 try:
2587 2586 ps = self.shell.user_ns['_dh'][-2]
2588 2587 except IndexError:
2589 2588 print 'No previous directory to change to.'
2590 2589 return
2591 2590 # jump to bookmark if needed
2592 2591 else:
2593 2592 if not os.path.isdir(ps) or opts.has_key('b'):
2594 2593 bkms = self.db.get('bookmarks', {})
2595 2594
2596 2595 if bkms.has_key(ps):
2597 2596 target = bkms[ps]
2598 2597 print '(bookmark:%s) -> %s' % (ps,target)
2599 2598 ps = target
2600 2599 else:
2601 2600 if opts.has_key('b'):
2602 2601 error("Bookmark '%s' not found. "
2603 2602 "Use '%%bookmark -l' to see your bookmarks." % ps)
2604 2603 return
2605 2604
2606 2605 # at this point ps should point to the target dir
2607 2606 if ps:
2608 2607 try:
2609 2608 os.chdir(os.path.expanduser(ps))
2610 2609 ttitle = ("IPy:" + (
2611 2610 os.getcwd() == '/' and '/' or os.path.basename(os.getcwd())))
2612 2611 platutils.set_term_title(ttitle)
2613 2612 except OSError:
2614 2613 print sys.exc_info()[1]
2615 2614 else:
2616 2615 self.shell.user_ns['_dh'].append(os.getcwd())
2617 2616 else:
2618 2617 os.chdir(self.shell.home_dir)
2619 2618 platutils.set_term_title("IPy:~")
2620 2619 self.shell.user_ns['_dh'].append(os.getcwd())
2621 2620 if not 'q' in opts:
2622 2621 print self.shell.user_ns['_dh'][-1]
2623 2622
2624 2623 def magic_dhist(self, parameter_s=''):
2625 2624 """Print your history of visited directories.
2626 2625
2627 2626 %dhist -> print full history\\
2628 2627 %dhist n -> print last n entries only\\
2629 2628 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2630 2629
2631 2630 This history is automatically maintained by the %cd command, and
2632 2631 always available as the global list variable _dh. You can use %cd -<n>
2633 2632 to go to directory number <n>."""
2634 2633
2635 2634 dh = self.shell.user_ns['_dh']
2636 2635 if parameter_s:
2637 2636 try:
2638 2637 args = map(int,parameter_s.split())
2639 2638 except:
2640 2639 self.arg_err(Magic.magic_dhist)
2641 2640 return
2642 2641 if len(args) == 1:
2643 2642 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2644 2643 elif len(args) == 2:
2645 2644 ini,fin = args
2646 2645 else:
2647 2646 self.arg_err(Magic.magic_dhist)
2648 2647 return
2649 2648 else:
2650 2649 ini,fin = 0,len(dh)
2651 2650 nlprint(dh,
2652 2651 header = 'Directory history (kept in _dh)',
2653 2652 start=ini,stop=fin)
2654 2653
2655 2654 def magic_env(self, parameter_s=''):
2656 2655 """List environment variables."""
2657 2656
2658 2657 return os.environ.data
2659 2658
2660 2659 def magic_pushd(self, parameter_s=''):
2661 2660 """Place the current dir on stack and change directory.
2662 2661
2663 2662 Usage:\\
2664 2663 %pushd ['dirname']
2665 2664
2666 2665 %pushd with no arguments does a %pushd to your home directory.
2667 2666 """
2668 2667 if parameter_s == '': parameter_s = '~'
2669 2668 dir_s = self.shell.dir_stack
2670 2669 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2671 2670 os.path.expanduser(self.shell.dir_stack[0]):
2672 2671 try:
2673 2672 self.magic_cd(parameter_s)
2674 2673 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2675 2674 self.magic_dirs()
2676 2675 except:
2677 2676 print 'Invalid directory'
2678 2677 else:
2679 2678 print 'You are already there!'
2680 2679
2681 2680 def magic_popd(self, parameter_s=''):
2682 2681 """Change to directory popped off the top of the stack.
2683 2682 """
2684 2683 if len (self.shell.dir_stack) > 1:
2685 2684 self.shell.dir_stack.pop(0)
2686 2685 self.magic_cd(self.shell.dir_stack[0])
2687 2686 print self.shell.dir_stack[0]
2688 2687 else:
2689 2688 print "You can't remove the starting directory from the stack:",\
2690 2689 self.shell.dir_stack
2691 2690
2692 2691 def magic_dirs(self, parameter_s=''):
2693 2692 """Return the current directory stack."""
2694 2693
2695 2694 return self.shell.dir_stack[:]
2696 2695
2697 2696 def magic_sc(self, parameter_s=''):
2698 2697 """Shell capture - execute a shell command and capture its output.
2699 2698
2700 2699 DEPRECATED. Suboptimal, retained for backwards compatibility.
2701 2700
2702 2701 You should use the form 'var = !command' instead. Example:
2703 2702
2704 2703 "%sc -l myfiles = ls ~" should now be written as
2705 2704
2706 2705 "myfiles = !ls ~"
2707 2706
2708 2707 myfiles.s, myfiles.l and myfiles.n still apply as documented
2709 2708 below.
2710 2709
2711 2710 --
2712 2711 %sc [options] varname=command
2713 2712
2714 2713 IPython will run the given command using commands.getoutput(), and
2715 2714 will then update the user's interactive namespace with a variable
2716 2715 called varname, containing the value of the call. Your command can
2717 2716 contain shell wildcards, pipes, etc.
2718 2717
2719 2718 The '=' sign in the syntax is mandatory, and the variable name you
2720 2719 supply must follow Python's standard conventions for valid names.
2721 2720
2722 2721 (A special format without variable name exists for internal use)
2723 2722
2724 2723 Options:
2725 2724
2726 2725 -l: list output. Split the output on newlines into a list before
2727 2726 assigning it to the given variable. By default the output is stored
2728 2727 as a single string.
2729 2728
2730 2729 -v: verbose. Print the contents of the variable.
2731 2730
2732 2731 In most cases you should not need to split as a list, because the
2733 2732 returned value is a special type of string which can automatically
2734 2733 provide its contents either as a list (split on newlines) or as a
2735 2734 space-separated string. These are convenient, respectively, either
2736 2735 for sequential processing or to be passed to a shell command.
2737 2736
2738 2737 For example:
2739 2738
2740 2739 # Capture into variable a
2741 2740 In [9]: sc a=ls *py
2742 2741
2743 2742 # a is a string with embedded newlines
2744 2743 In [10]: a
2745 2744 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2746 2745
2747 2746 # which can be seen as a list:
2748 2747 In [11]: a.l
2749 2748 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2750 2749
2751 2750 # or as a whitespace-separated string:
2752 2751 In [12]: a.s
2753 2752 Out[12]: 'setup.py win32_manual_post_install.py'
2754 2753
2755 2754 # a.s is useful to pass as a single command line:
2756 2755 In [13]: !wc -l $a.s
2757 2756 146 setup.py
2758 2757 130 win32_manual_post_install.py
2759 2758 276 total
2760 2759
2761 2760 # while the list form is useful to loop over:
2762 2761 In [14]: for f in a.l:
2763 2762 ....: !wc -l $f
2764 2763 ....:
2765 2764 146 setup.py
2766 2765 130 win32_manual_post_install.py
2767 2766
2768 2767 Similiarly, the lists returned by the -l option are also special, in
2769 2768 the sense that you can equally invoke the .s attribute on them to
2770 2769 automatically get a whitespace-separated string from their contents:
2771 2770
2772 2771 In [1]: sc -l b=ls *py
2773 2772
2774 2773 In [2]: b
2775 2774 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2776 2775
2777 2776 In [3]: b.s
2778 2777 Out[3]: 'setup.py win32_manual_post_install.py'
2779 2778
2780 2779 In summary, both the lists and strings used for ouptut capture have
2781 2780 the following special attributes:
2782 2781
2783 2782 .l (or .list) : value as list.
2784 2783 .n (or .nlstr): value as newline-separated string.
2785 2784 .s (or .spstr): value as space-separated string.
2786 2785 """
2787 2786
2788 2787 opts,args = self.parse_options(parameter_s,'lv')
2789 2788 # Try to get a variable name and command to run
2790 2789 try:
2791 2790 # the variable name must be obtained from the parse_options
2792 2791 # output, which uses shlex.split to strip options out.
2793 2792 var,_ = args.split('=',1)
2794 2793 var = var.strip()
2795 2794 # But the the command has to be extracted from the original input
2796 2795 # parameter_s, not on what parse_options returns, to avoid the
2797 2796 # quote stripping which shlex.split performs on it.
2798 2797 _,cmd = parameter_s.split('=',1)
2799 2798 except ValueError:
2800 2799 var,cmd = '',''
2801 2800 # If all looks ok, proceed
2802 2801 out,err = self.shell.getoutputerror(cmd)
2803 2802 if err:
2804 2803 print >> Term.cerr,err
2805 2804 if opts.has_key('l'):
2806 2805 out = SList(out.split('\n'))
2807 2806 else:
2808 2807 out = LSString(out)
2809 2808 if opts.has_key('v'):
2810 2809 print '%s ==\n%s' % (var,pformat(out))
2811 2810 if var:
2812 2811 self.shell.user_ns.update({var:out})
2813 2812 else:
2814 2813 return out
2815 2814
2816 2815 def magic_sx(self, parameter_s=''):
2817 2816 """Shell execute - run a shell command and capture its output.
2818 2817
2819 2818 %sx command
2820 2819
2821 2820 IPython will run the given command using commands.getoutput(), and
2822 2821 return the result formatted as a list (split on '\\n'). Since the
2823 2822 output is _returned_, it will be stored in ipython's regular output
2824 2823 cache Out[N] and in the '_N' automatic variables.
2825 2824
2826 2825 Notes:
2827 2826
2828 2827 1) If an input line begins with '!!', then %sx is automatically
2829 2828 invoked. That is, while:
2830 2829 !ls
2831 2830 causes ipython to simply issue system('ls'), typing
2832 2831 !!ls
2833 2832 is a shorthand equivalent to:
2834 2833 %sx ls
2835 2834
2836 2835 2) %sx differs from %sc in that %sx automatically splits into a list,
2837 2836 like '%sc -l'. The reason for this is to make it as easy as possible
2838 2837 to process line-oriented shell output via further python commands.
2839 2838 %sc is meant to provide much finer control, but requires more
2840 2839 typing.
2841 2840
2842 2841 3) Just like %sc -l, this is a list with special attributes:
2843 2842
2844 2843 .l (or .list) : value as list.
2845 2844 .n (or .nlstr): value as newline-separated string.
2846 2845 .s (or .spstr): value as whitespace-separated string.
2847 2846
2848 2847 This is very useful when trying to use such lists as arguments to
2849 2848 system commands."""
2850 2849
2851 2850 if parameter_s:
2852 2851 out,err = self.shell.getoutputerror(parameter_s)
2853 2852 if err:
2854 2853 print >> Term.cerr,err
2855 2854 return SList(out.split('\n'))
2856 2855
2857 2856 def magic_bg(self, parameter_s=''):
2858 2857 """Run a job in the background, in a separate thread.
2859 2858
2860 2859 For example,
2861 2860
2862 2861 %bg myfunc(x,y,z=1)
2863 2862
2864 2863 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2865 2864 execution starts, a message will be printed indicating the job
2866 2865 number. If your job number is 5, you can use
2867 2866
2868 2867 myvar = jobs.result(5) or myvar = jobs[5].result
2869 2868
2870 2869 to assign this result to variable 'myvar'.
2871 2870
2872 2871 IPython has a job manager, accessible via the 'jobs' object. You can
2873 2872 type jobs? to get more information about it, and use jobs.<TAB> to see
2874 2873 its attributes. All attributes not starting with an underscore are
2875 2874 meant for public use.
2876 2875
2877 2876 In particular, look at the jobs.new() method, which is used to create
2878 2877 new jobs. This magic %bg function is just a convenience wrapper
2879 2878 around jobs.new(), for expression-based jobs. If you want to create a
2880 2879 new job with an explicit function object and arguments, you must call
2881 2880 jobs.new() directly.
2882 2881
2883 2882 The jobs.new docstring also describes in detail several important
2884 2883 caveats associated with a thread-based model for background job
2885 2884 execution. Type jobs.new? for details.
2886 2885
2887 2886 You can check the status of all jobs with jobs.status().
2888 2887
2889 2888 The jobs variable is set by IPython into the Python builtin namespace.
2890 2889 If you ever declare a variable named 'jobs', you will shadow this
2891 2890 name. You can either delete your global jobs variable to regain
2892 2891 access to the job manager, or make a new name and assign it manually
2893 2892 to the manager (stored in IPython's namespace). For example, to
2894 2893 assign the job manager to the Jobs name, use:
2895 2894
2896 2895 Jobs = __builtins__.jobs"""
2897 2896
2898 2897 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2899 2898
2900 2899
2901 2900 def magic_bookmark(self, parameter_s=''):
2902 2901 """Manage IPython's bookmark system.
2903 2902
2904 2903 %bookmark <name> - set bookmark to current dir
2905 2904 %bookmark <name> <dir> - set bookmark to <dir>
2906 2905 %bookmark -l - list all bookmarks
2907 2906 %bookmark -d <name> - remove bookmark
2908 2907 %bookmark -r - remove all bookmarks
2909 2908
2910 2909 You can later on access a bookmarked folder with:
2911 2910 %cd -b <name>
2912 2911 or simply '%cd <name>' if there is no directory called <name> AND
2913 2912 there is such a bookmark defined.
2914 2913
2915 2914 Your bookmarks persist through IPython sessions, but they are
2916 2915 associated with each profile."""
2917 2916
2918 2917 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2919 2918 if len(args) > 2:
2920 2919 error('You can only give at most two arguments')
2921 2920 return
2922 2921
2923 2922 bkms = self.db.get('bookmarks',{})
2924 2923
2925 2924 if opts.has_key('d'):
2926 2925 try:
2927 2926 todel = args[0]
2928 2927 except IndexError:
2929 2928 error('You must provide a bookmark to delete')
2930 2929 else:
2931 2930 try:
2932 2931 del bkms[todel]
2933 2932 except:
2934 2933 error("Can't delete bookmark '%s'" % todel)
2935 2934 elif opts.has_key('r'):
2936 2935 bkms = {}
2937 2936 elif opts.has_key('l'):
2938 2937 bks = bkms.keys()
2939 2938 bks.sort()
2940 2939 if bks:
2941 2940 size = max(map(len,bks))
2942 2941 else:
2943 2942 size = 0
2944 2943 fmt = '%-'+str(size)+'s -> %s'
2945 2944 print 'Current bookmarks:'
2946 2945 for bk in bks:
2947 2946 print fmt % (bk,bkms[bk])
2948 2947 else:
2949 2948 if not args:
2950 2949 error("You must specify the bookmark name")
2951 2950 elif len(args)==1:
2952 2951 bkms[args[0]] = os.getcwd()
2953 2952 elif len(args)==2:
2954 2953 bkms[args[0]] = args[1]
2955 2954 self.db['bookmarks'] = bkms
2956 2955
2957 2956 def magic_pycat(self, parameter_s=''):
2958 2957 """Show a syntax-highlighted file through a pager.
2959 2958
2960 2959 This magic is similar to the cat utility, but it will assume the file
2961 2960 to be Python source and will show it with syntax highlighting. """
2962 2961
2963 2962 try:
2964 2963 filename = get_py_filename(parameter_s)
2965 2964 cont = file_read(filename)
2966 2965 except IOError:
2967 2966 try:
2968 2967 cont = eval(parameter_s,self.user_ns)
2969 2968 except NameError:
2970 2969 cont = None
2971 2970 if cont is None:
2972 2971 print "Error: no such file or variable"
2973 2972 return
2974 2973
2975 2974 page(self.shell.pycolorize(cont),
2976 2975 screen_lines=self.shell.rc.screen_length)
2977 2976
2978 2977 def magic_cpaste(self, parameter_s=''):
2979 2978 """Allows you to paste & execute a pre-formatted code block from clipboard
2980 2979
2981 2980 You must terminate the block with '--' (two minus-signs) alone on the
2982 2981 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
2983 2982 is the new sentinel for this operation)
2984 2983
2985 2984 The block is dedented prior to execution to enable execution of
2986 2985 method definitions. '>' characters at the beginning of a line is
2987 2986 ignored, to allow pasting directly from e-mails. The executed block
2988 2987 is also assigned to variable named 'pasted_block' for later editing
2989 2988 with '%edit pasted_block'.
2990 2989
2991 2990 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
2992 2991 This assigns the pasted block to variable 'foo' as string, without
2993 2992 dedenting or executing it.
2994 2993
2995 2994 Do not be alarmed by garbled output on Windows (it's a readline bug).
2996 2995 Just press enter and type -- (and press enter again) and the block
2997 2996 will be what was just pasted.
2998 2997
2999 2998 IPython statements (magics, shell escapes) are not supported (yet).
3000 2999 """
3001 3000 opts,args = self.parse_options(parameter_s,'s:',mode='string')
3002 3001 par = args.strip()
3003 3002 sentinel = opts.get('s','--')
3004 3003
3005 3004 from IPython import iplib
3006 3005 lines = []
3007 3006 print "Pasting code; enter '%s' alone on the line to stop." % sentinel
3008 3007 while 1:
3009 3008 l = iplib.raw_input_original(':')
3010 3009 if l ==sentinel:
3011 3010 break
3012 3011 lines.append(l.lstrip('>'))
3013 3012 block = "\n".join(lines) + '\n'
3014 3013 #print "block:\n",block
3015 3014 if not par:
3016 3015 b = textwrap.dedent(block)
3017 3016 exec b in self.user_ns
3018 3017 self.user_ns['pasted_block'] = b
3019 3018 else:
3020 3019 self.user_ns[par] = block
3021 3020 print "Block assigned to '%s'" % par
3022 3021
3023 3022 def magic_quickref(self,arg):
3024 3023 """ Show a quick reference sheet """
3025 3024 import IPython.usage
3026 3025 qr = IPython.usage.quick_reference + self.magic_magic('-brief')
3027 3026
3028 3027 page(qr)
3029 3028
3030 3029 def magic_upgrade(self,arg):
3031 3030 """ Upgrade your IPython installation
3032 3031
3033 3032 This will copy the config files that don't yet exist in your
3034 3033 ipython dir from the system config dir. Use this after upgrading
3035 3034 IPython if you don't wish to delete your .ipython dir.
3036 3035
3037 3036 Call with -nolegacy to get rid of ipythonrc* files (recommended for
3038 3037 new users)
3039 3038
3040 3039 """
3041 3040 ip = self.getapi()
3042 3041 ipinstallation = path(IPython.__file__).dirname()
3043 3042 upgrade_script = '%s "%s"' % (sys.executable,ipinstallation / 'upgrade_dir.py')
3044 3043 src_config = ipinstallation / 'UserConfig'
3045 3044 userdir = path(ip.options.ipythondir)
3046 3045 cmd = '%s "%s" "%s"' % (upgrade_script, src_config, userdir)
3047 3046 print ">",cmd
3048 3047 shell(cmd)
3049 3048 if arg == '-nolegacy':
3050 3049 legacy = userdir.files('ipythonrc*')
3051 3050 print "Nuking legacy files:",legacy
3052 3051
3053 3052 [p.remove() for p in legacy]
3054 3053 suffix = (sys.platform == 'win32' and '.ini' or '')
3055 3054 (userdir / ('ipythonrc' + suffix)).write_text('# Empty, see ipy_user_conf.py\n')
3056 3055
3057 3056
3058 3057 # end Magic
@@ -1,86 +1,86 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Release data for the IPython project.
3 3
4 $Id: Release.py 1955 2006-11-29 09:44:32Z vivainio $"""
4 $Id: Release.py 1961 2006-12-05 21:02:40Z vivainio $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
8 8 #
9 9 # Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and Nathaniel Gray
10 10 # <n8gray@caltech.edu>
11 11 #
12 12 # Distributed under the terms of the BSD License. The full license is in
13 13 # the file COPYING, distributed as part of this software.
14 14 #*****************************************************************************
15 15
16 16 # Name of the package for release purposes. This is the name which labels
17 17 # the tarballs and RPMs made by distutils, so it's best to lowercase it.
18 18 name = 'ipython'
19 19
20 20 # For versions with substrings (like 0.6.16.svn), use an extra . to separate
21 21 # the new substring. We have to avoid using either dashes or underscores,
22 22 # because bdist_rpm does not accept dashes (an RPM) convention, and
23 23 # bdist_deb does not accept underscores (a Debian convention).
24 24
25 revision = '1954'
25 revision = '1955'
26 26
27 27 #version = '0.7.3.svn'
28 28
29 29 version = '0.7.3.svn.r' + revision.rstrip('M')
30 30
31 31
32 32 description = "An enhanced interactive Python shell."
33 33
34 34 long_description = \
35 35 """
36 36 IPython provides a replacement for the interactive Python interpreter with
37 37 extra functionality.
38 38
39 39 Main features:
40 40
41 41 * Comprehensive object introspection.
42 42
43 43 * Input history, persistent across sessions.
44 44
45 45 * Caching of output results during a session with automatically generated
46 46 references.
47 47
48 48 * Readline based name completion.
49 49
50 50 * Extensible system of 'magic' commands for controlling the environment and
51 51 performing many tasks related either to IPython or the operating system.
52 52
53 53 * Configuration system with easy switching between different setups (simpler
54 54 than changing $PYTHONSTARTUP environment variables every time).
55 55
56 56 * Session logging and reloading.
57 57
58 58 * Extensible syntax processing for special purpose situations.
59 59
60 60 * Access to the system shell with user-extensible alias system.
61 61
62 62 * Easily embeddable in other Python programs.
63 63
64 64 * Integrated access to the pdb debugger and the Python profiler.
65 65
66 66 The latest development version is always available at the IPython subversion
67 67 repository_.
68 68
69 69 .. _repository: http://ipython.scipy.org/svn/ipython/ipython/trunk#egg=ipython-dev
70 70 """
71 71
72 72 license = 'BSD'
73 73
74 74 authors = {'Fernando' : ('Fernando Perez','fperez@colorado.edu'),
75 75 'Janko' : ('Janko Hauser','jhauser@zscout.de'),
76 76 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu'),
77 77 'Ville' : ('Ville Vainio','vivainio@gmail.com')
78 78 }
79 79
80 80 url = 'http://ipython.scipy.org'
81 81
82 82 download_url = 'http://ipython.scipy.org/dist'
83 83
84 84 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
85 85
86 86 keywords = ['Interactive','Interpreter','Shell']
@@ -1,2535 +1,2534 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 IPython -- An enhanced Interactive Python
4 4
5 5 Requires Python 2.3 or newer.
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 1956 2006-11-30 05:22:31Z fperez $
9 $Id: iplib.py 1961 2006-12-05 21:02:40Z vivainio $
10 10 """
11 11
12 12 #*****************************************************************************
13 13 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
14 14 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
15 15 #
16 16 # Distributed under the terms of the BSD License. The full license is in
17 17 # the file COPYING, distributed as part of this software.
18 18 #
19 19 # Note: this code originally subclassed code.InteractiveConsole from the
20 20 # Python standard library. Over time, all of that class has been copied
21 21 # verbatim here for modifications which could not be accomplished by
22 22 # subclassing. At this point, there are no dependencies at all on the code
23 23 # module anymore (it is not even imported). The Python License (sec. 2)
24 24 # allows for this, but it's always nice to acknowledge credit where credit is
25 25 # due.
26 26 #*****************************************************************************
27 27
28 28 #****************************************************************************
29 29 # Modules and globals
30 30
31 31 from IPython import Release
32 32 __author__ = '%s <%s>\n%s <%s>' % \
33 33 ( Release.authors['Janko'] + Release.authors['Fernando'] )
34 34 __license__ = Release.license
35 35 __version__ = Release.version
36 36
37 37 # Python standard modules
38 38 import __main__
39 39 import __builtin__
40 40 import StringIO
41 41 import bdb
42 42 import cPickle as pickle
43 43 import codeop
44 44 import exceptions
45 45 import glob
46 46 import inspect
47 47 import keyword
48 48 import new
49 49 import os
50 50 import pydoc
51 51 import re
52 52 import shutil
53 53 import string
54 54 import sys
55 55 import tempfile
56 56 import traceback
57 57 import types
58 58 import pickleshare
59 59 from sets import Set
60 60 from pprint import pprint, pformat
61 61
62 62 # IPython's own modules
63 63 import IPython
64 64 from IPython import OInspect,PyColorize,ultraTB
65 65 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
66 66 from IPython.FakeModule import FakeModule
67 67 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
68 68 from IPython.Logger import Logger
69 69 from IPython.Magic import Magic
70 70 from IPython.Prompts import CachedOutput
71 71 from IPython.ipstruct import Struct
72 72 from IPython.background_jobs import BackgroundJobManager
73 73 from IPython.usage import cmd_line_usage,interactive_usage
74 74 from IPython.genutils import *
75 75 from IPython.strdispatch import StrDispatch
76 76 import IPython.ipapi
77 77
78 78 # Globals
79 79
80 80 # store the builtin raw_input globally, and use this always, in case user code
81 81 # overwrites it (like wx.py.PyShell does)
82 82 raw_input_original = raw_input
83 83
84 84 # compiled regexps for autoindent management
85 85 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
86 86
87 87
88 88 #****************************************************************************
89 89 # Some utility function definitions
90 90
91 91 ini_spaces_re = re.compile(r'^(\s+)')
92 92
93 93 def num_ini_spaces(strng):
94 94 """Return the number of initial spaces in a string"""
95 95
96 96 ini_spaces = ini_spaces_re.match(strng)
97 97 if ini_spaces:
98 98 return ini_spaces.end()
99 99 else:
100 100 return 0
101 101
102 102 def softspace(file, newvalue):
103 103 """Copied from code.py, to remove the dependency"""
104 104
105 105 oldvalue = 0
106 106 try:
107 107 oldvalue = file.softspace
108 108 except AttributeError:
109 109 pass
110 110 try:
111 111 file.softspace = newvalue
112 112 except (AttributeError, TypeError):
113 113 # "attribute-less object" or "read-only attributes"
114 114 pass
115 115 return oldvalue
116 116
117 117
118 118 #****************************************************************************
119 119 # Local use exceptions
120 120 class SpaceInInput(exceptions.Exception): pass
121 121
122 122
123 123 #****************************************************************************
124 124 # Local use classes
125 125 class Bunch: pass
126 126
127 127 class Undefined: pass
128 128
129 129 class Quitter(object):
130 130 """Simple class to handle exit, similar to Python 2.5's.
131 131
132 132 It handles exiting in an ipython-safe manner, which the one in Python 2.5
133 133 doesn't do (obviously, since it doesn't know about ipython)."""
134 134
135 135 def __init__(self,shell,name):
136 136 self.shell = shell
137 137 self.name = name
138 138
139 139 def __repr__(self):
140 140 return 'Type %s() to exit.' % self.name
141 141 __str__ = __repr__
142 142
143 143 def __call__(self):
144 144 self.shell.exit()
145 145
146 146 class InputList(list):
147 147 """Class to store user input.
148 148
149 149 It's basically a list, but slices return a string instead of a list, thus
150 150 allowing things like (assuming 'In' is an instance):
151 151
152 152 exec In[4:7]
153 153
154 154 or
155 155
156 156 exec In[5:9] + In[14] + In[21:25]"""
157 157
158 158 def __getslice__(self,i,j):
159 159 return ''.join(list.__getslice__(self,i,j))
160 160
161 161 class SyntaxTB(ultraTB.ListTB):
162 162 """Extension which holds some state: the last exception value"""
163 163
164 164 def __init__(self,color_scheme = 'NoColor'):
165 165 ultraTB.ListTB.__init__(self,color_scheme)
166 166 self.last_syntax_error = None
167 167
168 168 def __call__(self, etype, value, elist):
169 169 self.last_syntax_error = value
170 170 ultraTB.ListTB.__call__(self,etype,value,elist)
171 171
172 172 def clear_err_state(self):
173 173 """Return the current error state and clear it"""
174 174 e = self.last_syntax_error
175 175 self.last_syntax_error = None
176 176 return e
177 177
178 178 #****************************************************************************
179 179 # Main IPython class
180 180
181 181 # FIXME: the Magic class is a mixin for now, and will unfortunately remain so
182 182 # until a full rewrite is made. I've cleaned all cross-class uses of
183 183 # attributes and methods, but too much user code out there relies on the
184 184 # equlity %foo == __IP.magic_foo, so I can't actually remove the mixin usage.
185 185 #
186 186 # But at least now, all the pieces have been separated and we could, in
187 187 # principle, stop using the mixin. This will ease the transition to the
188 188 # chainsaw branch.
189 189
190 190 # For reference, the following is the list of 'self.foo' uses in the Magic
191 191 # class as of 2005-12-28. These are names we CAN'T use in the main ipython
192 192 # class, to prevent clashes.
193 193
194 194 # ['self.__class__', 'self.__dict__', 'self._inspect', 'self._ofind',
195 195 # 'self.arg_err', 'self.extract_input', 'self.format_', 'self.lsmagic',
196 196 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
197 197 # 'self.value']
198 198
199 199 class InteractiveShell(object,Magic):
200 200 """An enhanced console for Python."""
201 201
202 202 # class attribute to indicate whether the class supports threads or not.
203 203 # Subclasses with thread support should override this as needed.
204 204 isthreaded = False
205 205
206 206 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
207 207 user_ns = None,user_global_ns=None,banner2='',
208 208 custom_exceptions=((),None),embedded=False):
209 209
210 210 # log system
211 211 self.logger = Logger(self,logfname='ipython_log.py',logmode='rotate')
212 212
213 213 # some minimal strict typechecks. For some core data structures, I
214 214 # want actual basic python types, not just anything that looks like
215 215 # one. This is especially true for namespaces.
216 216 for ns in (user_ns,user_global_ns):
217 217 if ns is not None and type(ns) != types.DictType:
218 218 raise TypeError,'namespace must be a dictionary'
219 219
220 220 # Job manager (for jobs run as background threads)
221 221 self.jobs = BackgroundJobManager()
222 222
223 223 # Store the actual shell's name
224 224 self.name = name
225 225
226 226 # We need to know whether the instance is meant for embedding, since
227 227 # global/local namespaces need to be handled differently in that case
228 228 self.embedded = embedded
229 229
230 230 # command compiler
231 231 self.compile = codeop.CommandCompiler()
232 232
233 233 # User input buffer
234 234 self.buffer = []
235 235
236 236 # Default name given in compilation of code
237 237 self.filename = '<ipython console>'
238 238
239 239 # Install our own quitter instead of the builtins. For python2.3-2.4,
240 240 # this brings in behavior like 2.5, and for 2.5 it's identical.
241 241 __builtin__.exit = Quitter(self,'exit')
242 242 __builtin__.quit = Quitter(self,'quit')
243 243
244 244 # Make an empty namespace, which extension writers can rely on both
245 245 # existing and NEVER being used by ipython itself. This gives them a
246 246 # convenient location for storing additional information and state
247 247 # their extensions may require, without fear of collisions with other
248 248 # ipython names that may develop later.
249 249 self.meta = Struct()
250 250
251 251 # Create the namespace where the user will operate. user_ns is
252 252 # normally the only one used, and it is passed to the exec calls as
253 253 # the locals argument. But we do carry a user_global_ns namespace
254 254 # given as the exec 'globals' argument, This is useful in embedding
255 255 # situations where the ipython shell opens in a context where the
256 256 # distinction between locals and globals is meaningful.
257 257
258 258 # FIXME. For some strange reason, __builtins__ is showing up at user
259 259 # level as a dict instead of a module. This is a manual fix, but I
260 260 # should really track down where the problem is coming from. Alex
261 261 # Schmolck reported this problem first.
262 262
263 263 # A useful post by Alex Martelli on this topic:
264 264 # Re: inconsistent value from __builtins__
265 265 # Von: Alex Martelli <aleaxit@yahoo.com>
266 266 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
267 267 # Gruppen: comp.lang.python
268 268
269 269 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
270 270 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
271 271 # > <type 'dict'>
272 272 # > >>> print type(__builtins__)
273 273 # > <type 'module'>
274 274 # > Is this difference in return value intentional?
275 275
276 276 # Well, it's documented that '__builtins__' can be either a dictionary
277 277 # or a module, and it's been that way for a long time. Whether it's
278 278 # intentional (or sensible), I don't know. In any case, the idea is
279 279 # that if you need to access the built-in namespace directly, you
280 280 # should start with "import __builtin__" (note, no 's') which will
281 281 # definitely give you a module. Yeah, it's somewhat confusing:-(.
282 282
283 283 # These routines return properly built dicts as needed by the rest of
284 284 # the code, and can also be used by extension writers to generate
285 285 # properly initialized namespaces.
286 286 user_ns = IPython.ipapi.make_user_ns(user_ns)
287 287 user_global_ns = IPython.ipapi.make_user_global_ns(user_global_ns)
288 288
289 289 # Assign namespaces
290 290 # This is the namespace where all normal user variables live
291 291 self.user_ns = user_ns
292 292 # Embedded instances require a separate namespace for globals.
293 293 # Normally this one is unused by non-embedded instances.
294 294 self.user_global_ns = user_global_ns
295 295 # A namespace to keep track of internal data structures to prevent
296 296 # them from cluttering user-visible stuff. Will be updated later
297 297 self.internal_ns = {}
298 298
299 299 # Namespace of system aliases. Each entry in the alias
300 300 # table must be a 2-tuple of the form (N,name), where N is the number
301 301 # of positional arguments of the alias.
302 302 self.alias_table = {}
303 303
304 304 # A table holding all the namespaces IPython deals with, so that
305 305 # introspection facilities can search easily.
306 306 self.ns_table = {'user':user_ns,
307 307 'user_global':user_global_ns,
308 308 'alias':self.alias_table,
309 309 'internal':self.internal_ns,
310 310 'builtin':__builtin__.__dict__
311 311 }
312 312
313 313 # The user namespace MUST have a pointer to the shell itself.
314 314 self.user_ns[name] = self
315 315
316 316 # We need to insert into sys.modules something that looks like a
317 317 # module but which accesses the IPython namespace, for shelve and
318 318 # pickle to work interactively. Normally they rely on getting
319 319 # everything out of __main__, but for embedding purposes each IPython
320 320 # instance has its own private namespace, so we can't go shoving
321 321 # everything into __main__.
322 322
323 323 # note, however, that we should only do this for non-embedded
324 324 # ipythons, which really mimic the __main__.__dict__ with their own
325 325 # namespace. Embedded instances, on the other hand, should not do
326 326 # this because they need to manage the user local/global namespaces
327 327 # only, but they live within a 'normal' __main__ (meaning, they
328 328 # shouldn't overtake the execution environment of the script they're
329 329 # embedded in).
330 330
331 331 if not embedded:
332 332 try:
333 333 main_name = self.user_ns['__name__']
334 334 except KeyError:
335 335 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
336 336 else:
337 337 #print "pickle hack in place" # dbg
338 338 #print 'main_name:',main_name # dbg
339 339 sys.modules[main_name] = FakeModule(self.user_ns)
340 340
341 341 # List of input with multi-line handling.
342 342 # Fill its zero entry, user counter starts at 1
343 343 self.input_hist = InputList(['\n'])
344 344 # This one will hold the 'raw' input history, without any
345 345 # pre-processing. This will allow users to retrieve the input just as
346 346 # it was exactly typed in by the user, with %hist -r.
347 347 self.input_hist_raw = InputList(['\n'])
348 348
349 349 # list of visited directories
350 350 try:
351 351 self.dir_hist = [os.getcwd()]
352 352 except IOError, e:
353 353 self.dir_hist = []
354 354
355 355 # dict of output history
356 356 self.output_hist = {}
357 357
358 358 # dict of things NOT to alias (keywords, builtins and some magics)
359 359 no_alias = {}
360 360 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
361 361 for key in keyword.kwlist + no_alias_magics:
362 362 no_alias[key] = 1
363 363 no_alias.update(__builtin__.__dict__)
364 364 self.no_alias = no_alias
365 365
366 366 # make global variables for user access to these
367 367 self.user_ns['_ih'] = self.input_hist
368 368 self.user_ns['_oh'] = self.output_hist
369 369 self.user_ns['_dh'] = self.dir_hist
370 370
371 371 # user aliases to input and output histories
372 372 self.user_ns['In'] = self.input_hist
373 373 self.user_ns['Out'] = self.output_hist
374 374
375 375 # Object variable to store code object waiting execution. This is
376 376 # used mainly by the multithreaded shells, but it can come in handy in
377 377 # other situations. No need to use a Queue here, since it's a single
378 378 # item which gets cleared once run.
379 379 self.code_to_run = None
380 380
381 381 # escapes for automatic behavior on the command line
382 382 self.ESC_SHELL = '!'
383 383 self.ESC_HELP = '?'
384 384 self.ESC_MAGIC = '%'
385 385 self.ESC_QUOTE = ','
386 386 self.ESC_QUOTE2 = ';'
387 387 self.ESC_PAREN = '/'
388 388
389 389 # And their associated handlers
390 390 self.esc_handlers = {self.ESC_PAREN : self.handle_auto,
391 391 self.ESC_QUOTE : self.handle_auto,
392 392 self.ESC_QUOTE2 : self.handle_auto,
393 393 self.ESC_MAGIC : self.handle_magic,
394 394 self.ESC_HELP : self.handle_help,
395 395 self.ESC_SHELL : self.handle_shell_escape,
396 396 }
397 397
398 398 # class initializations
399 399 Magic.__init__(self,self)
400 400
401 401 # Python source parser/formatter for syntax highlighting
402 402 pyformat = PyColorize.Parser().format
403 403 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
404 404
405 405 # hooks holds pointers used for user-side customizations
406 406 self.hooks = Struct()
407 407
408 408 self.strdispatchers = {}
409 409
410 410 # Set all default hooks, defined in the IPython.hooks module.
411 411 hooks = IPython.hooks
412 412 for hook_name in hooks.__all__:
413 413 # default hooks have priority 100, i.e. low; user hooks should have 0-100 priority
414 414 self.set_hook(hook_name,getattr(hooks,hook_name), 100)
415 415 #print "bound hook",hook_name
416 416
417 417 # Flag to mark unconditional exit
418 418 self.exit_now = False
419 419
420 420 self.usage_min = """\
421 421 An enhanced console for Python.
422 422 Some of its features are:
423 423 - Readline support if the readline library is present.
424 424 - Tab completion in the local namespace.
425 425 - Logging of input, see command-line options.
426 426 - System shell escape via ! , eg !ls.
427 427 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
428 428 - Keeps track of locally defined variables via %who, %whos.
429 429 - Show object information with a ? eg ?x or x? (use ?? for more info).
430 430 """
431 431 if usage: self.usage = usage
432 432 else: self.usage = self.usage_min
433 433
434 434 # Storage
435 435 self.rc = rc # This will hold all configuration information
436 436 self.pager = 'less'
437 437 # temporary files used for various purposes. Deleted at exit.
438 438 self.tempfiles = []
439 439
440 440 # Keep track of readline usage (later set by init_readline)
441 441 self.has_readline = False
442 442
443 443 # template for logfile headers. It gets resolved at runtime by the
444 444 # logstart method.
445 445 self.loghead_tpl = \
446 446 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
447 447 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
448 448 #log# opts = %s
449 449 #log# args = %s
450 450 #log# It is safe to make manual edits below here.
451 451 #log#-----------------------------------------------------------------------
452 452 """
453 453 # for pushd/popd management
454 454 try:
455 455 self.home_dir = get_home_dir()
456 456 except HomeDirError,msg:
457 457 fatal(msg)
458 458
459 459 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
460 460
461 461 # Functions to call the underlying shell.
462 462
463 463 # The first is similar to os.system, but it doesn't return a value,
464 464 # and it allows interpolation of variables in the user's namespace.
465 465 self.system = lambda cmd: \
466 466 shell(self.var_expand(cmd,depth=2),
467 467 header=self.rc.system_header,
468 468 verbose=self.rc.system_verbose)
469 469
470 470 # These are for getoutput and getoutputerror:
471 471 self.getoutput = lambda cmd: \
472 472 getoutput(self.var_expand(cmd,depth=2),
473 473 header=self.rc.system_header,
474 474 verbose=self.rc.system_verbose)
475 475
476 476 self.getoutputerror = lambda cmd: \
477 477 getoutputerror(self.var_expand(cmd,depth=2),
478 478 header=self.rc.system_header,
479 479 verbose=self.rc.system_verbose)
480 480
481 481 # RegExp for splitting line contents into pre-char//first
482 482 # word-method//rest. For clarity, each group in on one line.
483 483
484 484 # WARNING: update the regexp if the above escapes are changed, as they
485 485 # are hardwired in.
486 486
487 487 # Don't get carried away with trying to make the autocalling catch too
488 488 # much: it's better to be conservative rather than to trigger hidden
489 489 # evals() somewhere and end up causing side effects.
490 490
491 491 self.line_split = re.compile(r'^([\s*,;/])'
492 492 r'([\?\w\.]+\w*\s*)'
493 493 r'(\(?.*$)')
494 494
495 495 # Original re, keep around for a while in case changes break something
496 496 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
497 497 # r'(\s*[\?\w\.]+\w*\s*)'
498 498 # r'(\(?.*$)')
499 499
500 500 # RegExp to identify potential function names
501 501 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
502 502
503 503 # RegExp to exclude strings with this start from autocalling. In
504 504 # particular, all binary operators should be excluded, so that if foo
505 505 # is callable, foo OP bar doesn't become foo(OP bar), which is
506 506 # invalid. The characters '!=()' don't need to be checked for, as the
507 507 # _prefilter routine explicitely does so, to catch direct calls and
508 508 # rebindings of existing names.
509 509
510 510 # Warning: the '-' HAS TO BE AT THE END of the first group, otherwise
511 511 # it affects the rest of the group in square brackets.
512 512 self.re_exclude_auto = re.compile(r'^[<>,&^\|\*/\+-]'
513 513 '|^is |^not |^in |^and |^or ')
514 514
515 515 # try to catch also methods for stuff in lists/tuples/dicts: off
516 516 # (experimental). For this to work, the line_split regexp would need
517 517 # to be modified so it wouldn't break things at '['. That line is
518 518 # nasty enough that I shouldn't change it until I can test it _well_.
519 519 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
520 520
521 521 # keep track of where we started running (mainly for crash post-mortem)
522 522 self.starting_dir = os.getcwd()
523 523
524 524 # Various switches which can be set
525 525 self.CACHELENGTH = 5000 # this is cheap, it's just text
526 526 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
527 527 self.banner2 = banner2
528 528
529 529 # TraceBack handlers:
530 530
531 531 # Syntax error handler.
532 532 self.SyntaxTB = SyntaxTB(color_scheme='NoColor')
533 533
534 534 # The interactive one is initialized with an offset, meaning we always
535 535 # want to remove the topmost item in the traceback, which is our own
536 536 # internal code. Valid modes: ['Plain','Context','Verbose']
537 537 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
538 538 color_scheme='NoColor',
539 539 tb_offset = 1)
540 540
541 541 # IPython itself shouldn't crash. This will produce a detailed
542 542 # post-mortem if it does. But we only install the crash handler for
543 543 # non-threaded shells, the threaded ones use a normal verbose reporter
544 544 # and lose the crash handler. This is because exceptions in the main
545 545 # thread (such as in GUI code) propagate directly to sys.excepthook,
546 546 # and there's no point in printing crash dumps for every user exception.
547 547 if self.isthreaded:
548 548 ipCrashHandler = ultraTB.FormattedTB()
549 549 else:
550 550 from IPython import CrashHandler
551 551 ipCrashHandler = CrashHandler.IPythonCrashHandler(self)
552 552 self.set_crash_handler(ipCrashHandler)
553 553
554 554 # and add any custom exception handlers the user may have specified
555 555 self.set_custom_exc(*custom_exceptions)
556 556
557 557 # indentation management
558 558 self.autoindent = False
559 559 self.indent_current_nsp = 0
560 560
561 561 # Make some aliases automatically
562 562 # Prepare list of shell aliases to auto-define
563 563 if os.name == 'posix':
564 564 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
565 565 'mv mv -i','rm rm -i','cp cp -i',
566 566 'cat cat','less less','clear clear',
567 567 # a better ls
568 568 'ls ls -F',
569 569 # long ls
570 570 'll ls -lF')
571 571 # Extra ls aliases with color, which need special treatment on BSD
572 572 # variants
573 573 ls_extra = ( # color ls
574 574 'lc ls -F -o --color',
575 575 # ls normal files only
576 576 'lf ls -F -o --color %l | grep ^-',
577 577 # ls symbolic links
578 578 'lk ls -F -o --color %l | grep ^l',
579 579 # directories or links to directories,
580 580 'ldir ls -F -o --color %l | grep /$',
581 581 # things which are executable
582 582 'lx ls -F -o --color %l | grep ^-..x',
583 583 )
584 584 # The BSDs don't ship GNU ls, so they don't understand the
585 585 # --color switch out of the box
586 586 if 'bsd' in sys.platform:
587 587 ls_extra = ( # ls normal files only
588 588 'lf ls -lF | grep ^-',
589 589 # ls symbolic links
590 590 'lk ls -lF | grep ^l',
591 591 # directories or links to directories,
592 592 'ldir ls -lF | grep /$',
593 593 # things which are executable
594 594 'lx ls -lF | grep ^-..x',
595 595 )
596 596 auto_alias = auto_alias + ls_extra
597 597 elif os.name in ['nt','dos']:
598 598 auto_alias = ('dir dir /on', 'ls dir /on',
599 599 'ddir dir /ad /on', 'ldir dir /ad /on',
600 600 'mkdir mkdir','rmdir rmdir','echo echo',
601 601 'ren ren','cls cls','copy copy')
602 602 else:
603 603 auto_alias = ()
604 604 self.auto_alias = [s.split(None,1) for s in auto_alias]
605 605 # Call the actual (public) initializer
606 606 self.init_auto_alias()
607 607
608 608 # Produce a public API instance
609 609 self.api = IPython.ipapi.IPApi(self)
610 610
611 611 # track which builtins we add, so we can clean up later
612 612 self.builtins_added = {}
613 613 # This method will add the necessary builtins for operation, but
614 614 # tracking what it did via the builtins_added dict.
615 615 self.add_builtins()
616 616
617 617 # end __init__
618 618
619 619 def var_expand(self,cmd,depth=0):
620 620 """Expand python variables in a string.
621 621
622 622 The depth argument indicates how many frames above the caller should
623 623 be walked to look for the local namespace where to expand variables.
624 624
625 625 The global namespace for expansion is always the user's interactive
626 626 namespace.
627 627 """
628 628
629 629 return str(ItplNS(cmd.replace('#','\#'),
630 630 self.user_ns, # globals
631 631 # Skip our own frame in searching for locals:
632 632 sys._getframe(depth+1).f_locals # locals
633 633 ))
634 634
635 635 def pre_config_initialization(self):
636 636 """Pre-configuration init method
637 637
638 638 This is called before the configuration files are processed to
639 639 prepare the services the config files might need.
640 640
641 641 self.rc already has reasonable default values at this point.
642 642 """
643 643 rc = self.rc
644 644
645 645 self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db")
646 646
647 647 def post_config_initialization(self):
648 648 """Post configuration init method
649 649
650 650 This is called after the configuration files have been processed to
651 651 'finalize' the initialization."""
652 652
653 653 rc = self.rc
654 654
655 655 # Object inspector
656 656 self.inspector = OInspect.Inspector(OInspect.InspectColors,
657 657 PyColorize.ANSICodeColors,
658 658 'NoColor',
659 659 rc.object_info_string_level)
660 660
661 661 # Load readline proper
662 662 if rc.readline:
663 663 self.init_readline()
664 664
665 665 # local shortcut, this is used a LOT
666 666 self.log = self.logger.log
667 667
668 668 # Initialize cache, set in/out prompts and printing system
669 669 self.outputcache = CachedOutput(self,
670 670 rc.cache_size,
671 671 rc.pprint,
672 672 input_sep = rc.separate_in,
673 673 output_sep = rc.separate_out,
674 674 output_sep2 = rc.separate_out2,
675 675 ps1 = rc.prompt_in1,
676 676 ps2 = rc.prompt_in2,
677 677 ps_out = rc.prompt_out,
678 678 pad_left = rc.prompts_pad_left)
679 679
680 680 # user may have over-ridden the default print hook:
681 681 try:
682 682 self.outputcache.__class__.display = self.hooks.display
683 683 except AttributeError:
684 684 pass
685 685
686 686 # I don't like assigning globally to sys, because it means when
687 687 # embedding instances, each embedded instance overrides the previous
688 688 # choice. But sys.displayhook seems to be called internally by exec,
689 689 # so I don't see a way around it. We first save the original and then
690 690 # overwrite it.
691 691 self.sys_displayhook = sys.displayhook
692 692 sys.displayhook = self.outputcache
693 693
694 694 # Set user colors (don't do it in the constructor above so that it
695 695 # doesn't crash if colors option is invalid)
696 696 self.magic_colors(rc.colors)
697 697
698 698 # Set calling of pdb on exceptions
699 699 self.call_pdb = rc.pdb
700 700
701 701 # Load user aliases
702 702 for alias in rc.alias:
703 703 self.magic_alias(alias)
704 704 self.hooks.late_startup_hook()
705 705
706 706 batchrun = False
707 707 for batchfile in [path(arg) for arg in self.rc.args
708 708 if arg.lower().endswith('.ipy')]:
709 709 if not batchfile.isfile():
710 710 print "No such batch file:", batchfile
711 711 continue
712 712 self.api.runlines(batchfile.text())
713 713 batchrun = True
714 714 if batchrun:
715 715 self.exit_now = True
716 716
717 717 def add_builtins(self):
718 718 """Store ipython references into the builtin namespace.
719 719
720 720 Some parts of ipython operate via builtins injected here, which hold a
721 721 reference to IPython itself."""
722 722
723 723 # TODO: deprecate all except _ip; 'jobs' should be installed
724 724 # by an extension and the rest are under _ip, ipalias is redundant
725 725 builtins_new = dict(__IPYTHON__ = self,
726 726 ip_set_hook = self.set_hook,
727 727 jobs = self.jobs,
728 728 ipmagic = wrap_deprecated(self.ipmagic,'_ip.magic()'),
729 729 ipalias = wrap_deprecated(self.ipalias),
730 730 ipsystem = wrap_deprecated(self.ipsystem,'_ip.system()'),
731 731 _ip = self.api
732 732 )
733 733 for biname,bival in builtins_new.items():
734 734 try:
735 735 # store the orignal value so we can restore it
736 736 self.builtins_added[biname] = __builtin__.__dict__[biname]
737 737 except KeyError:
738 738 # or mark that it wasn't defined, and we'll just delete it at
739 739 # cleanup
740 740 self.builtins_added[biname] = Undefined
741 741 __builtin__.__dict__[biname] = bival
742 742
743 743 # Keep in the builtins a flag for when IPython is active. We set it
744 744 # with setdefault so that multiple nested IPythons don't clobber one
745 745 # another. Each will increase its value by one upon being activated,
746 746 # which also gives us a way to determine the nesting level.
747 747 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
748 748
749 749 def clean_builtins(self):
750 750 """Remove any builtins which might have been added by add_builtins, or
751 751 restore overwritten ones to their previous values."""
752 752 for biname,bival in self.builtins_added.items():
753 753 if bival is Undefined:
754 754 del __builtin__.__dict__[biname]
755 755 else:
756 756 __builtin__.__dict__[biname] = bival
757 757 self.builtins_added.clear()
758 758
759 759 def set_hook(self,name,hook, priority = 50, str_key = None, re_key = None):
760 760 """set_hook(name,hook) -> sets an internal IPython hook.
761 761
762 762 IPython exposes some of its internal API as user-modifiable hooks. By
763 763 adding your function to one of these hooks, you can modify IPython's
764 764 behavior to call at runtime your own routines."""
765 765
766 766 # At some point in the future, this should validate the hook before it
767 767 # accepts it. Probably at least check that the hook takes the number
768 768 # of args it's supposed to.
769 769
770 770 f = new.instancemethod(hook,self,self.__class__)
771 771
772 772 # check if the hook is for strdispatcher first
773 773 if str_key is not None:
774 774 sdp = self.strdispatchers.get(name, StrDispatch())
775 775 sdp.add_s(str_key, f, priority )
776 776 self.strdispatchers[name] = sdp
777 777 return
778 778 if re_key is not None:
779 779 sdp = self.strdispatchers.get(name, StrDispatch())
780 780 sdp.add_re(re.compile(re_key), f, priority )
781 781 self.strdispatchers[name] = sdp
782 782 return
783 783
784 784 dp = getattr(self.hooks, name, None)
785 785 if name not in IPython.hooks.__all__:
786 786 print "Warning! Hook '%s' is not one of %s" % (name, IPython.hooks.__all__ )
787 787 if not dp:
788 788 dp = IPython.hooks.CommandChainDispatcher()
789 789
790 790 try:
791 791 dp.add(f,priority)
792 792 except AttributeError:
793 793 # it was not commandchain, plain old func - replace
794 794 dp = f
795 795
796 796 setattr(self.hooks,name, dp)
797 797
798 798
799 799 #setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
800 800
801 801 def set_crash_handler(self,crashHandler):
802 802 """Set the IPython crash handler.
803 803
804 804 This must be a callable with a signature suitable for use as
805 805 sys.excepthook."""
806 806
807 807 # Install the given crash handler as the Python exception hook
808 808 sys.excepthook = crashHandler
809 809
810 810 # The instance will store a pointer to this, so that runtime code
811 811 # (such as magics) can access it. This is because during the
812 812 # read-eval loop, it gets temporarily overwritten (to deal with GUI
813 813 # frameworks).
814 814 self.sys_excepthook = sys.excepthook
815 815
816 816
817 817 def set_custom_exc(self,exc_tuple,handler):
818 818 """set_custom_exc(exc_tuple,handler)
819 819
820 820 Set a custom exception handler, which will be called if any of the
821 821 exceptions in exc_tuple occur in the mainloop (specifically, in the
822 822 runcode() method.
823 823
824 824 Inputs:
825 825
826 826 - exc_tuple: a *tuple* of valid exceptions to call the defined
827 827 handler for. It is very important that you use a tuple, and NOT A
828 828 LIST here, because of the way Python's except statement works. If
829 829 you only want to trap a single exception, use a singleton tuple:
830 830
831 831 exc_tuple == (MyCustomException,)
832 832
833 833 - handler: this must be defined as a function with the following
834 834 basic interface: def my_handler(self,etype,value,tb).
835 835
836 836 This will be made into an instance method (via new.instancemethod)
837 837 of IPython itself, and it will be called if any of the exceptions
838 838 listed in the exc_tuple are caught. If the handler is None, an
839 839 internal basic one is used, which just prints basic info.
840 840
841 841 WARNING: by putting in your own exception handler into IPython's main
842 842 execution loop, you run a very good chance of nasty crashes. This
843 843 facility should only be used if you really know what you are doing."""
844 844
845 845 assert type(exc_tuple)==type(()) , \
846 846 "The custom exceptions must be given AS A TUPLE."
847 847
848 848 def dummy_handler(self,etype,value,tb):
849 849 print '*** Simple custom exception handler ***'
850 850 print 'Exception type :',etype
851 851 print 'Exception value:',value
852 852 print 'Traceback :',tb
853 853 print 'Source code :','\n'.join(self.buffer)
854 854
855 855 if handler is None: handler = dummy_handler
856 856
857 857 self.CustomTB = new.instancemethod(handler,self,self.__class__)
858 858 self.custom_exceptions = exc_tuple
859 859
860 860 def set_custom_completer(self,completer,pos=0):
861 861 """set_custom_completer(completer,pos=0)
862 862
863 863 Adds a new custom completer function.
864 864
865 865 The position argument (defaults to 0) is the index in the completers
866 866 list where you want the completer to be inserted."""
867 867
868 868 newcomp = new.instancemethod(completer,self.Completer,
869 869 self.Completer.__class__)
870 870 self.Completer.matchers.insert(pos,newcomp)
871 871
872 872 def _get_call_pdb(self):
873 873 return self._call_pdb
874 874
875 875 def _set_call_pdb(self,val):
876 876
877 877 if val not in (0,1,False,True):
878 878 raise ValueError,'new call_pdb value must be boolean'
879 879
880 880 # store value in instance
881 881 self._call_pdb = val
882 882
883 883 # notify the actual exception handlers
884 884 self.InteractiveTB.call_pdb = val
885 885 if self.isthreaded:
886 886 try:
887 887 self.sys_excepthook.call_pdb = val
888 888 except:
889 889 warn('Failed to activate pdb for threaded exception handler')
890 890
891 891 call_pdb = property(_get_call_pdb,_set_call_pdb,None,
892 892 'Control auto-activation of pdb at exceptions')
893 893
894 894
895 895 # These special functions get installed in the builtin namespace, to
896 896 # provide programmatic (pure python) access to magics, aliases and system
897 897 # calls. This is important for logging, user scripting, and more.
898 898
899 899 # We are basically exposing, via normal python functions, the three
900 900 # mechanisms in which ipython offers special call modes (magics for
901 901 # internal control, aliases for direct system access via pre-selected
902 902 # names, and !cmd for calling arbitrary system commands).
903 903
904 904 def ipmagic(self,arg_s):
905 905 """Call a magic function by name.
906 906
907 907 Input: a string containing the name of the magic function to call and any
908 908 additional arguments to be passed to the magic.
909 909
910 910 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
911 911 prompt:
912 912
913 913 In[1]: %name -opt foo bar
914 914
915 915 To call a magic without arguments, simply use ipmagic('name').
916 916
917 917 This provides a proper Python function to call IPython's magics in any
918 918 valid Python code you can type at the interpreter, including loops and
919 919 compound statements. It is added by IPython to the Python builtin
920 920 namespace upon initialization."""
921 921
922 922 args = arg_s.split(' ',1)
923 923 magic_name = args[0]
924 924 magic_name = magic_name.lstrip(self.ESC_MAGIC)
925 925
926 926 try:
927 927 magic_args = args[1]
928 928 except IndexError:
929 929 magic_args = ''
930 930 fn = getattr(self,'magic_'+magic_name,None)
931 931 if fn is None:
932 932 error("Magic function `%s` not found." % magic_name)
933 933 else:
934 934 magic_args = self.var_expand(magic_args,1)
935 935 return fn(magic_args)
936 936
937 937 def ipalias(self,arg_s):
938 938 """Call an alias by name.
939 939
940 940 Input: a string containing the name of the alias to call and any
941 941 additional arguments to be passed to the magic.
942 942
943 943 ipalias('name -opt foo bar') is equivalent to typing at the ipython
944 944 prompt:
945 945
946 946 In[1]: name -opt foo bar
947 947
948 948 To call an alias without arguments, simply use ipalias('name').
949 949
950 950 This provides a proper Python function to call IPython's aliases in any
951 951 valid Python code you can type at the interpreter, including loops and
952 952 compound statements. It is added by IPython to the Python builtin
953 953 namespace upon initialization."""
954 954
955 955 args = arg_s.split(' ',1)
956 956 alias_name = args[0]
957 957 try:
958 958 alias_args = args[1]
959 959 except IndexError:
960 960 alias_args = ''
961 961 if alias_name in self.alias_table:
962 962 self.call_alias(alias_name,alias_args)
963 963 else:
964 964 error("Alias `%s` not found." % alias_name)
965 965
966 966 def ipsystem(self,arg_s):
967 967 """Make a system call, using IPython."""
968 968
969 969 self.system(arg_s)
970 970
971 971 def complete(self,text):
972 972 """Return a sorted list of all possible completions on text.
973 973
974 974 Inputs:
975 975
976 976 - text: a string of text to be completed on.
977 977
978 978 This is a wrapper around the completion mechanism, similar to what
979 979 readline does at the command line when the TAB key is hit. By
980 980 exposing it as a method, it can be used by other non-readline
981 981 environments (such as GUIs) for text completion.
982 982
983 983 Simple usage example:
984 984
985 985 In [1]: x = 'hello'
986 986
987 987 In [2]: __IP.complete('x.l')
988 988 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
989 989
990 990 complete = self.Completer.complete
991 991 state = 0
992 992 # use a dict so we get unique keys, since ipyhton's multiple
993 993 # completers can return duplicates.
994 994 comps = {}
995 995 while True:
996 996 newcomp = complete(text,state)
997 997 if newcomp is None:
998 998 break
999 999 comps[newcomp] = 1
1000 1000 state += 1
1001 1001 outcomps = comps.keys()
1002 1002 outcomps.sort()
1003 1003 return outcomps
1004 1004
1005 1005 def set_completer_frame(self, frame=None):
1006 1006 if frame:
1007 1007 self.Completer.namespace = frame.f_locals
1008 1008 self.Completer.global_namespace = frame.f_globals
1009 1009 else:
1010 1010 self.Completer.namespace = self.user_ns
1011 1011 self.Completer.global_namespace = self.user_global_ns
1012 1012
1013 1013 def init_auto_alias(self):
1014 1014 """Define some aliases automatically.
1015 1015
1016 1016 These are ALL parameter-less aliases"""
1017 1017
1018 1018 for alias,cmd in self.auto_alias:
1019 1019 self.alias_table[alias] = (0,cmd)
1020 1020
1021 1021 def alias_table_validate(self,verbose=0):
1022 1022 """Update information about the alias table.
1023 1023
1024 1024 In particular, make sure no Python keywords/builtins are in it."""
1025 1025
1026 1026 no_alias = self.no_alias
1027 1027 for k in self.alias_table.keys():
1028 1028 if k in no_alias:
1029 1029 del self.alias_table[k]
1030 1030 if verbose:
1031 1031 print ("Deleting alias <%s>, it's a Python "
1032 1032 "keyword or builtin." % k)
1033 1033
1034 1034 def set_autoindent(self,value=None):
1035 1035 """Set the autoindent flag, checking for readline support.
1036 1036
1037 1037 If called with no arguments, it acts as a toggle."""
1038 1038
1039 1039 if not self.has_readline:
1040 1040 if os.name == 'posix':
1041 1041 warn("The auto-indent feature requires the readline library")
1042 1042 self.autoindent = 0
1043 1043 return
1044 1044 if value is None:
1045 1045 self.autoindent = not self.autoindent
1046 1046 else:
1047 1047 self.autoindent = value
1048 1048
1049 1049 def rc_set_toggle(self,rc_field,value=None):
1050 1050 """Set or toggle a field in IPython's rc config. structure.
1051 1051
1052 1052 If called with no arguments, it acts as a toggle.
1053 1053
1054 1054 If called with a non-existent field, the resulting AttributeError
1055 1055 exception will propagate out."""
1056 1056
1057 1057 rc_val = getattr(self.rc,rc_field)
1058 1058 if value is None:
1059 1059 value = not rc_val
1060 1060 setattr(self.rc,rc_field,value)
1061 1061
1062 1062 def user_setup(self,ipythondir,rc_suffix,mode='install'):
1063 1063 """Install the user configuration directory.
1064 1064
1065 1065 Can be called when running for the first time or to upgrade the user's
1066 1066 .ipython/ directory with the mode parameter. Valid modes are 'install'
1067 1067 and 'upgrade'."""
1068 1068
1069 1069 def wait():
1070 1070 try:
1071 1071 raw_input("Please press <RETURN> to start IPython.")
1072 1072 except EOFError:
1073 1073 print >> Term.cout
1074 1074 print '*'*70
1075 1075
1076 1076 cwd = os.getcwd() # remember where we started
1077 1077 glb = glob.glob
1078 1078 print '*'*70
1079 1079 if mode == 'install':
1080 1080 print \
1081 1081 """Welcome to IPython. I will try to create a personal configuration directory
1082 1082 where you can customize many aspects of IPython's functionality in:\n"""
1083 1083 else:
1084 1084 print 'I am going to upgrade your configuration in:'
1085 1085
1086 1086 print ipythondir
1087 1087
1088 1088 rcdirend = os.path.join('IPython','UserConfig')
1089 1089 cfg = lambda d: os.path.join(d,rcdirend)
1090 1090 try:
1091 1091 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
1092 1092 except IOError:
1093 1093 warning = """
1094 1094 Installation error. IPython's directory was not found.
1095 1095
1096 1096 Check the following:
1097 1097
1098 1098 The ipython/IPython directory should be in a directory belonging to your
1099 1099 PYTHONPATH environment variable (that is, it should be in a directory
1100 1100 belonging to sys.path). You can copy it explicitly there or just link to it.
1101 1101
1102 1102 IPython will proceed with builtin defaults.
1103 1103 """
1104 1104 warn(warning)
1105 1105 wait()
1106 1106 return
1107 1107
1108 1108 if mode == 'install':
1109 1109 try:
1110 1110 shutil.copytree(rcdir,ipythondir)
1111 1111 os.chdir(ipythondir)
1112 1112 rc_files = glb("ipythonrc*")
1113 1113 for rc_file in rc_files:
1114 1114 os.rename(rc_file,rc_file+rc_suffix)
1115 1115 except:
1116 1116 warning = """
1117 1117
1118 1118 There was a problem with the installation:
1119 1119 %s
1120 1120 Try to correct it or contact the developers if you think it's a bug.
1121 1121 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
1122 1122 warn(warning)
1123 1123 wait()
1124 1124 return
1125 1125
1126 1126 elif mode == 'upgrade':
1127 1127 try:
1128 1128 os.chdir(ipythondir)
1129 1129 except:
1130 1130 print """
1131 1131 Can not upgrade: changing to directory %s failed. Details:
1132 1132 %s
1133 1133 """ % (ipythondir,sys.exc_info()[1])
1134 1134 wait()
1135 1135 return
1136 1136 else:
1137 1137 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
1138 1138 for new_full_path in sources:
1139 1139 new_filename = os.path.basename(new_full_path)
1140 1140 if new_filename.startswith('ipythonrc'):
1141 1141 new_filename = new_filename + rc_suffix
1142 1142 # The config directory should only contain files, skip any
1143 1143 # directories which may be there (like CVS)
1144 1144 if os.path.isdir(new_full_path):
1145 1145 continue
1146 1146 if os.path.exists(new_filename):
1147 1147 old_file = new_filename+'.old'
1148 1148 if os.path.exists(old_file):
1149 1149 os.remove(old_file)
1150 1150 os.rename(new_filename,old_file)
1151 1151 shutil.copy(new_full_path,new_filename)
1152 1152 else:
1153 1153 raise ValueError,'unrecognized mode for install:',`mode`
1154 1154
1155 1155 # Fix line-endings to those native to each platform in the config
1156 1156 # directory.
1157 1157 try:
1158 1158 os.chdir(ipythondir)
1159 1159 except:
1160 1160 print """
1161 1161 Problem: changing to directory %s failed.
1162 1162 Details:
1163 1163 %s
1164 1164
1165 1165 Some configuration files may have incorrect line endings. This should not
1166 1166 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
1167 1167 wait()
1168 1168 else:
1169 1169 for fname in glb('ipythonrc*'):
1170 1170 try:
1171 1171 native_line_ends(fname,backup=0)
1172 1172 except IOError:
1173 1173 pass
1174 1174
1175 1175 if mode == 'install':
1176 1176 print """
1177 1177 Successful installation!
1178 1178
1179 1179 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
1180 1180 IPython manual (there are both HTML and PDF versions supplied with the
1181 1181 distribution) to make sure that your system environment is properly configured
1182 1182 to take advantage of IPython's features.
1183 1183
1184 1184 Important note: the configuration system has changed! The old system is
1185 1185 still in place, but its setting may be partly overridden by the settings in
1186 1186 "~/.ipython/ipy_user_conf.py" config file. Please take a look at the file
1187 1187 if some of the new settings bother you.
1188 1188
1189 1189 """
1190 1190 else:
1191 1191 print """
1192 1192 Successful upgrade!
1193 1193
1194 1194 All files in your directory:
1195 1195 %(ipythondir)s
1196 1196 which would have been overwritten by the upgrade were backed up with a .old
1197 1197 extension. If you had made particular customizations in those files you may
1198 1198 want to merge them back into the new files.""" % locals()
1199 1199 wait()
1200 1200 os.chdir(cwd)
1201 1201 # end user_setup()
1202 1202
1203 1203 def atexit_operations(self):
1204 1204 """This will be executed at the time of exit.
1205 1205
1206 1206 Saving of persistent data should be performed here. """
1207 1207
1208 1208 #print '*** IPython exit cleanup ***' # dbg
1209 1209 # input history
1210 1210 self.savehist()
1211 1211
1212 1212 # Cleanup all tempfiles left around
1213 1213 for tfile in self.tempfiles:
1214 1214 try:
1215 1215 os.unlink(tfile)
1216 1216 except OSError:
1217 1217 pass
1218 1218
1219 1219 # save the "persistent data" catch-all dictionary
1220 1220 self.hooks.shutdown_hook()
1221 1221
1222 1222 def savehist(self):
1223 1223 """Save input history to a file (via readline library)."""
1224 1224 try:
1225 1225 self.readline.write_history_file(self.histfile)
1226 1226 except:
1227 1227 print 'Unable to save IPython command history to file: ' + \
1228 1228 `self.histfile`
1229 1229
1230 1230 def history_saving_wrapper(self, func):
1231 1231 """ Wrap func for readline history saving
1232 1232
1233 1233 Convert func into callable that saves & restores
1234 1234 history around the call """
1235 1235
1236 1236 if not self.has_readline:
1237 1237 return func
1238 1238
1239 1239 def wrapper():
1240 1240 self.savehist()
1241 1241 try:
1242 1242 func()
1243 1243 finally:
1244 1244 readline.read_history_file(self.histfile)
1245 1245 return wrapper
1246 1246
1247 1247
1248 1248 def pre_readline(self):
1249 1249 """readline hook to be used at the start of each line.
1250 1250
1251 1251 Currently it handles auto-indent only."""
1252 1252
1253 1253 #debugx('self.indent_current_nsp','pre_readline:')
1254 1254 self.readline.insert_text(self.indent_current_str())
1255 1255
1256 1256 def init_readline(self):
1257 1257 """Command history completion/saving/reloading."""
1258 1258
1259 1259 import IPython.rlineimpl as readline
1260 1260 if not readline.have_readline:
1261 1261 self.has_readline = 0
1262 1262 self.readline = None
1263 1263 # no point in bugging windows users with this every time:
1264 1264 warn('Readline services not available on this platform.')
1265 1265 else:
1266 1266 sys.modules['readline'] = readline
1267 1267 import atexit
1268 1268 from IPython.completer import IPCompleter
1269 1269 self.Completer = IPCompleter(self,
1270 1270 self.user_ns,
1271 1271 self.user_global_ns,
1272 1272 self.rc.readline_omit__names,
1273 1273 self.alias_table)
1274 1274 sdisp = self.strdispatchers.get('complete_command', StrDispatch())
1275 1275 self.strdispatchers['complete_command'] = sdisp
1276 1276 self.Completer.custom_completers = sdisp
1277 1277 # Platform-specific configuration
1278 1278 if os.name == 'nt':
1279 1279 self.readline_startup_hook = readline.set_pre_input_hook
1280 1280 else:
1281 1281 self.readline_startup_hook = readline.set_startup_hook
1282 1282
1283 1283 # Load user's initrc file (readline config)
1284 1284 inputrc_name = os.environ.get('INPUTRC')
1285 1285 if inputrc_name is None:
1286 1286 home_dir = get_home_dir()
1287 1287 if home_dir is not None:
1288 1288 inputrc_name = os.path.join(home_dir,'.inputrc')
1289 1289 if os.path.isfile(inputrc_name):
1290 1290 try:
1291 1291 readline.read_init_file(inputrc_name)
1292 1292 except:
1293 1293 warn('Problems reading readline initialization file <%s>'
1294 1294 % inputrc_name)
1295 1295
1296 1296 self.has_readline = 1
1297 1297 self.readline = readline
1298 1298 # save this in sys so embedded copies can restore it properly
1299 1299 sys.ipcompleter = self.Completer.complete
1300 1300 readline.set_completer(self.Completer.complete)
1301 1301
1302 1302 # Configure readline according to user's prefs
1303 1303 for rlcommand in self.rc.readline_parse_and_bind:
1304 1304 readline.parse_and_bind(rlcommand)
1305 1305
1306 1306 # remove some chars from the delimiters list
1307 1307 delims = readline.get_completer_delims()
1308 1308 delims = delims.translate(string._idmap,
1309 1309 self.rc.readline_remove_delims)
1310 1310 readline.set_completer_delims(delims)
1311 1311 # otherwise we end up with a monster history after a while:
1312 1312 readline.set_history_length(1000)
1313 1313 try:
1314 1314 #print '*** Reading readline history' # dbg
1315 1315 readline.read_history_file(self.histfile)
1316 1316 except IOError:
1317 1317 pass # It doesn't exist yet.
1318 1318
1319 1319 atexit.register(self.atexit_operations)
1320 1320 del atexit
1321 1321
1322 1322 # Configure auto-indent for all platforms
1323 1323 self.set_autoindent(self.rc.autoindent)
1324 1324
1325 1325 def ask_yes_no(self,prompt,default=True):
1326 1326 if self.rc.quiet:
1327 1327 return True
1328 1328 return ask_yes_no(prompt,default)
1329 1329
1330 1330 def _should_recompile(self,e):
1331 1331 """Utility routine for edit_syntax_error"""
1332 1332
1333 1333 if e.filename in ('<ipython console>','<input>','<string>',
1334 1334 '<console>','<BackgroundJob compilation>',
1335 1335 None):
1336 1336
1337 1337 return False
1338 1338 try:
1339 1339 if (self.rc.autoedit_syntax and
1340 1340 not self.ask_yes_no('Return to editor to correct syntax error? '
1341 1341 '[Y/n] ','y')):
1342 1342 return False
1343 1343 except EOFError:
1344 1344 return False
1345 1345
1346 1346 def int0(x):
1347 1347 try:
1348 1348 return int(x)
1349 1349 except TypeError:
1350 1350 return 0
1351 1351 # always pass integer line and offset values to editor hook
1352 1352 self.hooks.fix_error_editor(e.filename,
1353 1353 int0(e.lineno),int0(e.offset),e.msg)
1354 1354 return True
1355 1355
1356 1356 def edit_syntax_error(self):
1357 1357 """The bottom half of the syntax error handler called in the main loop.
1358 1358
1359 1359 Loop until syntax error is fixed or user cancels.
1360 1360 """
1361 1361
1362 1362 while self.SyntaxTB.last_syntax_error:
1363 1363 # copy and clear last_syntax_error
1364 1364 err = self.SyntaxTB.clear_err_state()
1365 1365 if not self._should_recompile(err):
1366 1366 return
1367 1367 try:
1368 1368 # may set last_syntax_error again if a SyntaxError is raised
1369 1369 self.safe_execfile(err.filename,self.user_ns)
1370 1370 except:
1371 1371 self.showtraceback()
1372 1372 else:
1373 1373 try:
1374 1374 f = file(err.filename)
1375 1375 try:
1376 1376 sys.displayhook(f.read())
1377 1377 finally:
1378 1378 f.close()
1379 1379 except:
1380 1380 self.showtraceback()
1381 1381
1382 1382 def showsyntaxerror(self, filename=None):
1383 1383 """Display the syntax error that just occurred.
1384 1384
1385 1385 This doesn't display a stack trace because there isn't one.
1386 1386
1387 1387 If a filename is given, it is stuffed in the exception instead
1388 1388 of what was there before (because Python's parser always uses
1389 1389 "<string>" when reading from a string).
1390 1390 """
1391 1391 etype, value, last_traceback = sys.exc_info()
1392 1392
1393 1393 # See note about these variables in showtraceback() below
1394 1394 sys.last_type = etype
1395 1395 sys.last_value = value
1396 1396 sys.last_traceback = last_traceback
1397 1397
1398 1398 if filename and etype is SyntaxError:
1399 1399 # Work hard to stuff the correct filename in the exception
1400 1400 try:
1401 1401 msg, (dummy_filename, lineno, offset, line) = value
1402 1402 except:
1403 1403 # Not the format we expect; leave it alone
1404 1404 pass
1405 1405 else:
1406 1406 # Stuff in the right filename
1407 1407 try:
1408 1408 # Assume SyntaxError is a class exception
1409 1409 value = SyntaxError(msg, (filename, lineno, offset, line))
1410 1410 except:
1411 1411 # If that failed, assume SyntaxError is a string
1412 1412 value = msg, (filename, lineno, offset, line)
1413 1413 self.SyntaxTB(etype,value,[])
1414 1414
1415 1415 def debugger(self,force=False):
1416 1416 """Call the pydb/pdb debugger.
1417 1417
1418 1418 Keywords:
1419 1419
1420 1420 - force(False): by default, this routine checks the instance call_pdb
1421 1421 flag and does not actually invoke the debugger if the flag is false.
1422 1422 The 'force' option forces the debugger to activate even if the flag
1423 1423 is false.
1424 1424 """
1425 1425
1426 1426 if not (force or self.call_pdb):
1427 1427 return
1428 1428
1429 1429 have_pydb = False
1430 if sys.version[:3] >= '2.5':
1431 1430 # use pydb if available
1432 1431 try:
1433 1432 from pydb import pm
1434 1433 have_pydb = True
1435 1434 except ImportError:
1436 1435 pass
1437 1436 if not have_pydb:
1438 1437 # fallback to our internal debugger
1439 1438 pm = lambda : self.InteractiveTB.debugger(force=True)
1440 1439 self.history_saving_wrapper(pm)()
1441 1440
1442 1441 def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None):
1443 1442 """Display the exception that just occurred.
1444 1443
1445 1444 If nothing is known about the exception, this is the method which
1446 1445 should be used throughout the code for presenting user tracebacks,
1447 1446 rather than directly invoking the InteractiveTB object.
1448 1447
1449 1448 A specific showsyntaxerror() also exists, but this method can take
1450 1449 care of calling it if needed, so unless you are explicitly catching a
1451 1450 SyntaxError exception, don't try to analyze the stack manually and
1452 1451 simply call this method."""
1453 1452
1454 1453 # Though this won't be called by syntax errors in the input line,
1455 1454 # there may be SyntaxError cases whith imported code.
1456 1455 if exc_tuple is None:
1457 1456 etype, value, tb = sys.exc_info()
1458 1457 else:
1459 1458 etype, value, tb = exc_tuple
1460 1459 if etype is SyntaxError:
1461 1460 self.showsyntaxerror(filename)
1462 1461 else:
1463 1462 # WARNING: these variables are somewhat deprecated and not
1464 1463 # necessarily safe to use in a threaded environment, but tools
1465 1464 # like pdb depend on their existence, so let's set them. If we
1466 1465 # find problems in the field, we'll need to revisit their use.
1467 1466 sys.last_type = etype
1468 1467 sys.last_value = value
1469 1468 sys.last_traceback = tb
1470 1469
1471 1470 self.InteractiveTB(etype,value,tb,tb_offset=tb_offset)
1472 1471 if self.InteractiveTB.call_pdb and self.has_readline:
1473 1472 # pdb mucks up readline, fix it back
1474 1473 self.readline.set_completer(self.Completer.complete)
1475 1474
1476 1475 def mainloop(self,banner=None):
1477 1476 """Creates the local namespace and starts the mainloop.
1478 1477
1479 1478 If an optional banner argument is given, it will override the
1480 1479 internally created default banner."""
1481 1480
1482 1481 if self.rc.c: # Emulate Python's -c option
1483 1482 self.exec_init_cmd()
1484 1483 if banner is None:
1485 1484 if not self.rc.banner:
1486 1485 banner = ''
1487 1486 # banner is string? Use it directly!
1488 1487 elif isinstance(self.rc.banner,basestring):
1489 1488 banner = self.rc.banner
1490 1489 else:
1491 1490 banner = self.BANNER+self.banner2
1492 1491
1493 1492 self.interact(banner)
1494 1493
1495 1494 def exec_init_cmd(self):
1496 1495 """Execute a command given at the command line.
1497 1496
1498 1497 This emulates Python's -c option."""
1499 1498
1500 1499 #sys.argv = ['-c']
1501 1500 self.push(self.rc.c)
1502 1501
1503 1502 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1504 1503 """Embeds IPython into a running python program.
1505 1504
1506 1505 Input:
1507 1506
1508 1507 - header: An optional header message can be specified.
1509 1508
1510 1509 - local_ns, global_ns: working namespaces. If given as None, the
1511 1510 IPython-initialized one is updated with __main__.__dict__, so that
1512 1511 program variables become visible but user-specific configuration
1513 1512 remains possible.
1514 1513
1515 1514 - stack_depth: specifies how many levels in the stack to go to
1516 1515 looking for namespaces (when local_ns and global_ns are None). This
1517 1516 allows an intermediate caller to make sure that this function gets
1518 1517 the namespace from the intended level in the stack. By default (0)
1519 1518 it will get its locals and globals from the immediate caller.
1520 1519
1521 1520 Warning: it's possible to use this in a program which is being run by
1522 1521 IPython itself (via %run), but some funny things will happen (a few
1523 1522 globals get overwritten). In the future this will be cleaned up, as
1524 1523 there is no fundamental reason why it can't work perfectly."""
1525 1524
1526 1525 # Get locals and globals from caller
1527 1526 if local_ns is None or global_ns is None:
1528 1527 call_frame = sys._getframe(stack_depth).f_back
1529 1528
1530 1529 if local_ns is None:
1531 1530 local_ns = call_frame.f_locals
1532 1531 if global_ns is None:
1533 1532 global_ns = call_frame.f_globals
1534 1533
1535 1534 # Update namespaces and fire up interpreter
1536 1535
1537 1536 # The global one is easy, we can just throw it in
1538 1537 self.user_global_ns = global_ns
1539 1538
1540 1539 # but the user/local one is tricky: ipython needs it to store internal
1541 1540 # data, but we also need the locals. We'll copy locals in the user
1542 1541 # one, but will track what got copied so we can delete them at exit.
1543 1542 # This is so that a later embedded call doesn't see locals from a
1544 1543 # previous call (which most likely existed in a separate scope).
1545 1544 local_varnames = local_ns.keys()
1546 1545 self.user_ns.update(local_ns)
1547 1546
1548 1547 # Patch for global embedding to make sure that things don't overwrite
1549 1548 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1550 1549 # FIXME. Test this a bit more carefully (the if.. is new)
1551 1550 if local_ns is None and global_ns is None:
1552 1551 self.user_global_ns.update(__main__.__dict__)
1553 1552
1554 1553 # make sure the tab-completer has the correct frame information, so it
1555 1554 # actually completes using the frame's locals/globals
1556 1555 self.set_completer_frame()
1557 1556
1558 1557 # before activating the interactive mode, we need to make sure that
1559 1558 # all names in the builtin namespace needed by ipython point to
1560 1559 # ourselves, and not to other instances.
1561 1560 self.add_builtins()
1562 1561
1563 1562 self.interact(header)
1564 1563
1565 1564 # now, purge out the user namespace from anything we might have added
1566 1565 # from the caller's local namespace
1567 1566 delvar = self.user_ns.pop
1568 1567 for var in local_varnames:
1569 1568 delvar(var,None)
1570 1569 # and clean builtins we may have overridden
1571 1570 self.clean_builtins()
1572 1571
1573 1572 def interact(self, banner=None):
1574 1573 """Closely emulate the interactive Python console.
1575 1574
1576 1575 The optional banner argument specify the banner to print
1577 1576 before the first interaction; by default it prints a banner
1578 1577 similar to the one printed by the real Python interpreter,
1579 1578 followed by the current class name in parentheses (so as not
1580 1579 to confuse this with the real interpreter -- since it's so
1581 1580 close!).
1582 1581
1583 1582 """
1584 1583
1585 1584 if self.exit_now:
1586 1585 # batch run -> do not interact
1587 1586 return
1588 1587 cprt = 'Type "copyright", "credits" or "license" for more information.'
1589 1588 if banner is None:
1590 1589 self.write("Python %s on %s\n%s\n(%s)\n" %
1591 1590 (sys.version, sys.platform, cprt,
1592 1591 self.__class__.__name__))
1593 1592 else:
1594 1593 self.write(banner)
1595 1594
1596 1595 more = 0
1597 1596
1598 1597 # Mark activity in the builtins
1599 1598 __builtin__.__dict__['__IPYTHON__active'] += 1
1600 1599
1601 1600 # exit_now is set by a call to %Exit or %Quit
1602 1601 while not self.exit_now:
1603 1602 if more:
1604 1603 prompt = self.hooks.generate_prompt(True)
1605 1604 if self.autoindent:
1606 1605 self.readline_startup_hook(self.pre_readline)
1607 1606 else:
1608 1607 prompt = self.hooks.generate_prompt(False)
1609 1608 try:
1610 1609 line = self.raw_input(prompt,more)
1611 1610 if self.exit_now:
1612 1611 # quick exit on sys.std[in|out] close
1613 1612 break
1614 1613 if self.autoindent:
1615 1614 self.readline_startup_hook(None)
1616 1615 except KeyboardInterrupt:
1617 1616 self.write('\nKeyboardInterrupt\n')
1618 1617 self.resetbuffer()
1619 1618 # keep cache in sync with the prompt counter:
1620 1619 self.outputcache.prompt_count -= 1
1621 1620
1622 1621 if self.autoindent:
1623 1622 self.indent_current_nsp = 0
1624 1623 more = 0
1625 1624 except EOFError:
1626 1625 if self.autoindent:
1627 1626 self.readline_startup_hook(None)
1628 1627 self.write('\n')
1629 1628 self.exit()
1630 1629 except bdb.BdbQuit:
1631 1630 warn('The Python debugger has exited with a BdbQuit exception.\n'
1632 1631 'Because of how pdb handles the stack, it is impossible\n'
1633 1632 'for IPython to properly format this particular exception.\n'
1634 1633 'IPython will resume normal operation.')
1635 1634 except:
1636 1635 # exceptions here are VERY RARE, but they can be triggered
1637 1636 # asynchronously by signal handlers, for example.
1638 1637 self.showtraceback()
1639 1638 else:
1640 1639 more = self.push(line)
1641 1640 if (self.SyntaxTB.last_syntax_error and
1642 1641 self.rc.autoedit_syntax):
1643 1642 self.edit_syntax_error()
1644 1643
1645 1644 # We are off again...
1646 1645 __builtin__.__dict__['__IPYTHON__active'] -= 1
1647 1646
1648 1647 def excepthook(self, etype, value, tb):
1649 1648 """One more defense for GUI apps that call sys.excepthook.
1650 1649
1651 1650 GUI frameworks like wxPython trap exceptions and call
1652 1651 sys.excepthook themselves. I guess this is a feature that
1653 1652 enables them to keep running after exceptions that would
1654 1653 otherwise kill their mainloop. This is a bother for IPython
1655 1654 which excepts to catch all of the program exceptions with a try:
1656 1655 except: statement.
1657 1656
1658 1657 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1659 1658 any app directly invokes sys.excepthook, it will look to the user like
1660 1659 IPython crashed. In order to work around this, we can disable the
1661 1660 CrashHandler and replace it with this excepthook instead, which prints a
1662 1661 regular traceback using our InteractiveTB. In this fashion, apps which
1663 1662 call sys.excepthook will generate a regular-looking exception from
1664 1663 IPython, and the CrashHandler will only be triggered by real IPython
1665 1664 crashes.
1666 1665
1667 1666 This hook should be used sparingly, only in places which are not likely
1668 1667 to be true IPython errors.
1669 1668 """
1670 1669 self.showtraceback((etype,value,tb),tb_offset=0)
1671 1670
1672 1671 def expand_aliases(self,fn,rest):
1673 1672 """ Expand multiple levels of aliases:
1674 1673
1675 1674 if:
1676 1675
1677 1676 alias foo bar /tmp
1678 1677 alias baz foo
1679 1678
1680 1679 then:
1681 1680
1682 1681 baz huhhahhei -> bar /tmp huhhahhei
1683 1682
1684 1683 """
1685 1684 line = fn + " " + rest
1686 1685
1687 1686 done = Set()
1688 1687 while 1:
1689 1688 pre,fn,rest = self.split_user_input(line)
1690 1689 if fn in self.alias_table:
1691 1690 if fn in done:
1692 1691 warn("Cyclic alias definition, repeated '%s'" % fn)
1693 1692 return ""
1694 1693 done.add(fn)
1695 1694
1696 1695 l2 = self.transform_alias(fn,rest)
1697 1696 # dir -> dir
1698 1697 # print "alias",line, "->",l2 #dbg
1699 1698 if l2 == line:
1700 1699 break
1701 1700 # ls -> ls -F should not recurse forever
1702 1701 if l2.split(None,1)[0] == line.split(None,1)[0]:
1703 1702 line = l2
1704 1703 break
1705 1704
1706 1705 line=l2
1707 1706
1708 1707
1709 1708 # print "al expand to",line #dbg
1710 1709 else:
1711 1710 break
1712 1711
1713 1712 return line
1714 1713
1715 1714 def transform_alias(self, alias,rest=''):
1716 1715 """ Transform alias to system command string.
1717 1716 """
1718 1717 nargs,cmd = self.alias_table[alias]
1719 1718 if ' ' in cmd and os.path.isfile(cmd):
1720 1719 cmd = '"%s"' % cmd
1721 1720
1722 1721 # Expand the %l special to be the user's input line
1723 1722 if cmd.find('%l') >= 0:
1724 1723 cmd = cmd.replace('%l',rest)
1725 1724 rest = ''
1726 1725 if nargs==0:
1727 1726 # Simple, argument-less aliases
1728 1727 cmd = '%s %s' % (cmd,rest)
1729 1728 else:
1730 1729 # Handle aliases with positional arguments
1731 1730 args = rest.split(None,nargs)
1732 1731 if len(args)< nargs:
1733 1732 error('Alias <%s> requires %s arguments, %s given.' %
1734 1733 (alias,nargs,len(args)))
1735 1734 return None
1736 1735 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1737 1736 # Now call the macro, evaluating in the user's namespace
1738 1737 #print 'new command: <%r>' % cmd # dbg
1739 1738 return cmd
1740 1739
1741 1740 def call_alias(self,alias,rest=''):
1742 1741 """Call an alias given its name and the rest of the line.
1743 1742
1744 1743 This is only used to provide backwards compatibility for users of
1745 1744 ipalias(), use of which is not recommended for anymore."""
1746 1745
1747 1746 # Now call the macro, evaluating in the user's namespace
1748 1747 cmd = self.transform_alias(alias, rest)
1749 1748 try:
1750 1749 self.system(cmd)
1751 1750 except:
1752 1751 self.showtraceback()
1753 1752
1754 1753 def indent_current_str(self):
1755 1754 """return the current level of indentation as a string"""
1756 1755 return self.indent_current_nsp * ' '
1757 1756
1758 1757 def autoindent_update(self,line):
1759 1758 """Keep track of the indent level."""
1760 1759
1761 1760 #debugx('line')
1762 1761 #debugx('self.indent_current_nsp')
1763 1762 if self.autoindent:
1764 1763 if line:
1765 1764 inisp = num_ini_spaces(line)
1766 1765 if inisp < self.indent_current_nsp:
1767 1766 self.indent_current_nsp = inisp
1768 1767
1769 1768 if line[-1] == ':':
1770 1769 self.indent_current_nsp += 4
1771 1770 elif dedent_re.match(line):
1772 1771 self.indent_current_nsp -= 4
1773 1772 else:
1774 1773 self.indent_current_nsp = 0
1775 1774
1776 1775 def runlines(self,lines):
1777 1776 """Run a string of one or more lines of source.
1778 1777
1779 1778 This method is capable of running a string containing multiple source
1780 1779 lines, as if they had been entered at the IPython prompt. Since it
1781 1780 exposes IPython's processing machinery, the given strings can contain
1782 1781 magic calls (%magic), special shell access (!cmd), etc."""
1783 1782
1784 1783 # We must start with a clean buffer, in case this is run from an
1785 1784 # interactive IPython session (via a magic, for example).
1786 1785 self.resetbuffer()
1787 1786 lines = lines.split('\n')
1788 1787 more = 0
1789 1788 for line in lines:
1790 1789 # skip blank lines so we don't mess up the prompt counter, but do
1791 1790 # NOT skip even a blank line if we are in a code block (more is
1792 1791 # true)
1793 1792 if line or more:
1794 1793 more = self.push(self.prefilter(line,more))
1795 1794 # IPython's runsource returns None if there was an error
1796 1795 # compiling the code. This allows us to stop processing right
1797 1796 # away, so the user gets the error message at the right place.
1798 1797 if more is None:
1799 1798 break
1800 1799 # final newline in case the input didn't have it, so that the code
1801 1800 # actually does get executed
1802 1801 if more:
1803 1802 self.push('\n')
1804 1803
1805 1804 def runsource(self, source, filename='<input>', symbol='single'):
1806 1805 """Compile and run some source in the interpreter.
1807 1806
1808 1807 Arguments are as for compile_command().
1809 1808
1810 1809 One several things can happen:
1811 1810
1812 1811 1) The input is incorrect; compile_command() raised an
1813 1812 exception (SyntaxError or OverflowError). A syntax traceback
1814 1813 will be printed by calling the showsyntaxerror() method.
1815 1814
1816 1815 2) The input is incomplete, and more input is required;
1817 1816 compile_command() returned None. Nothing happens.
1818 1817
1819 1818 3) The input is complete; compile_command() returned a code
1820 1819 object. The code is executed by calling self.runcode() (which
1821 1820 also handles run-time exceptions, except for SystemExit).
1822 1821
1823 1822 The return value is:
1824 1823
1825 1824 - True in case 2
1826 1825
1827 1826 - False in the other cases, unless an exception is raised, where
1828 1827 None is returned instead. This can be used by external callers to
1829 1828 know whether to continue feeding input or not.
1830 1829
1831 1830 The return value can be used to decide whether to use sys.ps1 or
1832 1831 sys.ps2 to prompt the next line."""
1833 1832
1834 1833 # if the source code has leading blanks, add 'if 1:\n' to it
1835 1834 # this allows execution of indented pasted code. It is tempting
1836 1835 # to add '\n' at the end of source to run commands like ' a=1'
1837 1836 # directly, but this fails for more complicated scenarios
1838 1837 if source[:1] in [' ', '\t']:
1839 1838 source = 'if 1:\n%s' % source
1840 1839
1841 1840 try:
1842 1841 code = self.compile(source,filename,symbol)
1843 1842 except (OverflowError, SyntaxError, ValueError):
1844 1843 # Case 1
1845 1844 self.showsyntaxerror(filename)
1846 1845 return None
1847 1846
1848 1847 if code is None:
1849 1848 # Case 2
1850 1849 return True
1851 1850
1852 1851 # Case 3
1853 1852 # We store the code object so that threaded shells and
1854 1853 # custom exception handlers can access all this info if needed.
1855 1854 # The source corresponding to this can be obtained from the
1856 1855 # buffer attribute as '\n'.join(self.buffer).
1857 1856 self.code_to_run = code
1858 1857 # now actually execute the code object
1859 1858 if self.runcode(code) == 0:
1860 1859 return False
1861 1860 else:
1862 1861 return None
1863 1862
1864 1863 def runcode(self,code_obj):
1865 1864 """Execute a code object.
1866 1865
1867 1866 When an exception occurs, self.showtraceback() is called to display a
1868 1867 traceback.
1869 1868
1870 1869 Return value: a flag indicating whether the code to be run completed
1871 1870 successfully:
1872 1871
1873 1872 - 0: successful execution.
1874 1873 - 1: an error occurred.
1875 1874 """
1876 1875
1877 1876 # Set our own excepthook in case the user code tries to call it
1878 1877 # directly, so that the IPython crash handler doesn't get triggered
1879 1878 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1880 1879
1881 1880 # we save the original sys.excepthook in the instance, in case config
1882 1881 # code (such as magics) needs access to it.
1883 1882 self.sys_excepthook = old_excepthook
1884 1883 outflag = 1 # happens in more places, so it's easier as default
1885 1884 try:
1886 1885 try:
1887 1886 # Embedded instances require separate global/local namespaces
1888 1887 # so they can see both the surrounding (local) namespace and
1889 1888 # the module-level globals when called inside another function.
1890 1889 if self.embedded:
1891 1890 exec code_obj in self.user_global_ns, self.user_ns
1892 1891 # Normal (non-embedded) instances should only have a single
1893 1892 # namespace for user code execution, otherwise functions won't
1894 1893 # see interactive top-level globals.
1895 1894 else:
1896 1895 exec code_obj in self.user_ns
1897 1896 finally:
1898 1897 # Reset our crash handler in place
1899 1898 sys.excepthook = old_excepthook
1900 1899 except SystemExit:
1901 1900 self.resetbuffer()
1902 1901 self.showtraceback()
1903 1902 warn("Type %exit or %quit to exit IPython "
1904 1903 "(%Exit or %Quit do so unconditionally).",level=1)
1905 1904 except self.custom_exceptions:
1906 1905 etype,value,tb = sys.exc_info()
1907 1906 self.CustomTB(etype,value,tb)
1908 1907 except:
1909 1908 self.showtraceback()
1910 1909 else:
1911 1910 outflag = 0
1912 1911 if softspace(sys.stdout, 0):
1913 1912 print
1914 1913 # Flush out code object which has been run (and source)
1915 1914 self.code_to_run = None
1916 1915 return outflag
1917 1916
1918 1917 def push(self, line):
1919 1918 """Push a line to the interpreter.
1920 1919
1921 1920 The line should not have a trailing newline; it may have
1922 1921 internal newlines. The line is appended to a buffer and the
1923 1922 interpreter's runsource() method is called with the
1924 1923 concatenated contents of the buffer as source. If this
1925 1924 indicates that the command was executed or invalid, the buffer
1926 1925 is reset; otherwise, the command is incomplete, and the buffer
1927 1926 is left as it was after the line was appended. The return
1928 1927 value is 1 if more input is required, 0 if the line was dealt
1929 1928 with in some way (this is the same as runsource()).
1930 1929 """
1931 1930
1932 1931 # autoindent management should be done here, and not in the
1933 1932 # interactive loop, since that one is only seen by keyboard input. We
1934 1933 # need this done correctly even for code run via runlines (which uses
1935 1934 # push).
1936 1935
1937 1936 #print 'push line: <%s>' % line # dbg
1938 1937 for subline in line.splitlines():
1939 1938 self.autoindent_update(subline)
1940 1939 self.buffer.append(line)
1941 1940 more = self.runsource('\n'.join(self.buffer), self.filename)
1942 1941 if not more:
1943 1942 self.resetbuffer()
1944 1943 return more
1945 1944
1946 1945 def resetbuffer(self):
1947 1946 """Reset the input buffer."""
1948 1947 self.buffer[:] = []
1949 1948
1950 1949 def raw_input(self,prompt='',continue_prompt=False):
1951 1950 """Write a prompt and read a line.
1952 1951
1953 1952 The returned line does not include the trailing newline.
1954 1953 When the user enters the EOF key sequence, EOFError is raised.
1955 1954
1956 1955 Optional inputs:
1957 1956
1958 1957 - prompt(''): a string to be printed to prompt the user.
1959 1958
1960 1959 - continue_prompt(False): whether this line is the first one or a
1961 1960 continuation in a sequence of inputs.
1962 1961 """
1963 1962
1964 1963 try:
1965 1964 line = raw_input_original(prompt)
1966 1965 except ValueError:
1967 1966 warn("\n********\nYou or a %run:ed script called sys.stdin.close() or sys.stdout.close()!\nExiting IPython!")
1968 1967 self.exit_now = True
1969 1968 return ""
1970 1969
1971 1970
1972 1971 # Try to be reasonably smart about not re-indenting pasted input more
1973 1972 # than necessary. We do this by trimming out the auto-indent initial
1974 1973 # spaces, if the user's actual input started itself with whitespace.
1975 1974 #debugx('self.buffer[-1]')
1976 1975
1977 1976 if self.autoindent:
1978 1977 if num_ini_spaces(line) > self.indent_current_nsp:
1979 1978 line = line[self.indent_current_nsp:]
1980 1979 self.indent_current_nsp = 0
1981 1980
1982 1981 # store the unfiltered input before the user has any chance to modify
1983 1982 # it.
1984 1983 if line.strip():
1985 1984 if continue_prompt:
1986 1985 self.input_hist_raw[-1] += '%s\n' % line
1987 1986 if self.has_readline: # and some config option is set?
1988 1987 try:
1989 1988 histlen = self.readline.get_current_history_length()
1990 1989 newhist = self.input_hist_raw[-1].rstrip()
1991 1990 self.readline.remove_history_item(histlen-1)
1992 1991 self.readline.replace_history_item(histlen-2,newhist)
1993 1992 except AttributeError:
1994 1993 pass # re{move,place}_history_item are new in 2.4.
1995 1994 else:
1996 1995 self.input_hist_raw.append('%s\n' % line)
1997 1996
1998 1997 try:
1999 1998 lineout = self.prefilter(line,continue_prompt)
2000 1999 except:
2001 2000 # blanket except, in case a user-defined prefilter crashes, so it
2002 2001 # can't take all of ipython with it.
2003 2002 self.showtraceback()
2004 2003 return ''
2005 2004 else:
2006 2005 return lineout
2007 2006
2008 2007 def split_user_input(self,line):
2009 2008 """Split user input into pre-char, function part and rest."""
2010 2009
2011 2010 lsplit = self.line_split.match(line)
2012 2011 if lsplit is None: # no regexp match returns None
2013 2012 try:
2014 2013 iFun,theRest = line.split(None,1)
2015 2014 except ValueError:
2016 2015 iFun,theRest = line,''
2017 2016 pre = re.match('^(\s*)(.*)',line).groups()[0]
2018 2017 else:
2019 2018 pre,iFun,theRest = lsplit.groups()
2020 2019
2021 2020 #print 'line:<%s>' % line # dbg
2022 2021 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
2023 2022 return pre,iFun.strip(),theRest
2024 2023
2025 2024 def _prefilter(self, line, continue_prompt):
2026 2025 """Calls different preprocessors, depending on the form of line."""
2027 2026
2028 2027 # All handlers *must* return a value, even if it's blank ('').
2029 2028
2030 2029 # Lines are NOT logged here. Handlers should process the line as
2031 2030 # needed, update the cache AND log it (so that the input cache array
2032 2031 # stays synced).
2033 2032
2034 2033 # This function is _very_ delicate, and since it's also the one which
2035 2034 # determines IPython's response to user input, it must be as efficient
2036 2035 # as possible. For this reason it has _many_ returns in it, trying
2037 2036 # always to exit as quickly as it can figure out what it needs to do.
2038 2037
2039 2038 # This function is the main responsible for maintaining IPython's
2040 2039 # behavior respectful of Python's semantics. So be _very_ careful if
2041 2040 # making changes to anything here.
2042 2041
2043 2042 #.....................................................................
2044 2043 # Code begins
2045 2044
2046 2045 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
2047 2046
2048 2047 # save the line away in case we crash, so the post-mortem handler can
2049 2048 # record it
2050 2049 self._last_input_line = line
2051 2050
2052 2051 #print '***line: <%s>' % line # dbg
2053 2052
2054 2053 # the input history needs to track even empty lines
2055 2054 stripped = line.strip()
2056 2055
2057 2056 if not stripped:
2058 2057 if not continue_prompt:
2059 2058 self.outputcache.prompt_count -= 1
2060 2059 return self.handle_normal(line,continue_prompt)
2061 2060 #return self.handle_normal('',continue_prompt)
2062 2061
2063 2062 # print '***cont',continue_prompt # dbg
2064 2063 # special handlers are only allowed for single line statements
2065 2064 if continue_prompt and not self.rc.multi_line_specials:
2066 2065 return self.handle_normal(line,continue_prompt)
2067 2066
2068 2067
2069 2068 # For the rest, we need the structure of the input
2070 2069 pre,iFun,theRest = self.split_user_input(line)
2071 2070
2072 2071 # See whether any pre-existing handler can take care of it
2073 2072
2074 2073 rewritten = self.hooks.input_prefilter(stripped)
2075 2074 if rewritten != stripped: # ok, some prefilter did something
2076 2075 rewritten = pre + rewritten # add indentation
2077 2076 return self.handle_normal(rewritten)
2078 2077
2079 2078 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
2080 2079
2081 2080 # First check for explicit escapes in the last/first character
2082 2081 handler = None
2083 2082 if line[-1] == self.ESC_HELP:
2084 2083 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
2085 2084 if handler is None:
2086 2085 # look at the first character of iFun, NOT of line, so we skip
2087 2086 # leading whitespace in multiline input
2088 2087 handler = self.esc_handlers.get(iFun[0:1])
2089 2088 if handler is not None:
2090 2089 return handler(line,continue_prompt,pre,iFun,theRest)
2091 2090 # Emacs ipython-mode tags certain input lines
2092 2091 if line.endswith('# PYTHON-MODE'):
2093 2092 return self.handle_emacs(line,continue_prompt)
2094 2093
2095 2094 # Next, check if we can automatically execute this thing
2096 2095
2097 2096 # Allow ! in multi-line statements if multi_line_specials is on:
2098 2097 if continue_prompt and self.rc.multi_line_specials and \
2099 2098 iFun.startswith(self.ESC_SHELL):
2100 2099 return self.handle_shell_escape(line,continue_prompt,
2101 2100 pre=pre,iFun=iFun,
2102 2101 theRest=theRest)
2103 2102
2104 2103 # Let's try to find if the input line is a magic fn
2105 2104 oinfo = None
2106 2105 if hasattr(self,'magic_'+iFun):
2107 2106 # WARNING: _ofind uses getattr(), so it can consume generators and
2108 2107 # cause other side effects.
2109 2108 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
2110 2109 if oinfo['ismagic']:
2111 2110 # Be careful not to call magics when a variable assignment is
2112 2111 # being made (ls='hi', for example)
2113 2112 if self.rc.automagic and \
2114 2113 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
2115 2114 (self.rc.multi_line_specials or not continue_prompt):
2116 2115 return self.handle_magic(line,continue_prompt,
2117 2116 pre,iFun,theRest)
2118 2117 else:
2119 2118 return self.handle_normal(line,continue_prompt)
2120 2119
2121 2120 # If the rest of the line begins with an (in)equality, assginment or
2122 2121 # function call, we should not call _ofind but simply execute it.
2123 2122 # This avoids spurious geattr() accesses on objects upon assignment.
2124 2123 #
2125 2124 # It also allows users to assign to either alias or magic names true
2126 2125 # python variables (the magic/alias systems always take second seat to
2127 2126 # true python code).
2128 2127 if theRest and theRest[0] in '!=()':
2129 2128 return self.handle_normal(line,continue_prompt)
2130 2129
2131 2130 if oinfo is None:
2132 2131 # let's try to ensure that _oinfo is ONLY called when autocall is
2133 2132 # on. Since it has inevitable potential side effects, at least
2134 2133 # having autocall off should be a guarantee to the user that no
2135 2134 # weird things will happen.
2136 2135
2137 2136 if self.rc.autocall:
2138 2137 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
2139 2138 else:
2140 2139 # in this case, all that's left is either an alias or
2141 2140 # processing the line normally.
2142 2141 if iFun in self.alias_table:
2143 2142 # if autocall is off, by not running _ofind we won't know
2144 2143 # whether the given name may also exist in one of the
2145 2144 # user's namespace. At this point, it's best to do a
2146 2145 # quick check just to be sure that we don't let aliases
2147 2146 # shadow variables.
2148 2147 head = iFun.split('.',1)[0]
2149 2148 if head in self.user_ns or head in self.internal_ns \
2150 2149 or head in __builtin__.__dict__:
2151 2150 return self.handle_normal(line,continue_prompt)
2152 2151 else:
2153 2152 return self.handle_alias(line,continue_prompt,
2154 2153 pre,iFun,theRest)
2155 2154
2156 2155 else:
2157 2156 return self.handle_normal(line,continue_prompt)
2158 2157
2159 2158 if not oinfo['found']:
2160 2159 return self.handle_normal(line,continue_prompt)
2161 2160 else:
2162 2161 #print 'pre<%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
2163 2162 if oinfo['isalias']:
2164 2163 return self.handle_alias(line,continue_prompt,
2165 2164 pre,iFun,theRest)
2166 2165
2167 2166 if (self.rc.autocall
2168 2167 and
2169 2168 (
2170 2169 #only consider exclusion re if not "," or ";" autoquoting
2171 2170 (pre == self.ESC_QUOTE or pre == self.ESC_QUOTE2
2172 2171 or pre == self.ESC_PAREN) or
2173 2172 (not self.re_exclude_auto.match(theRest)))
2174 2173 and
2175 2174 self.re_fun_name.match(iFun) and
2176 2175 callable(oinfo['obj'])) :
2177 2176 #print 'going auto' # dbg
2178 2177 return self.handle_auto(line,continue_prompt,
2179 2178 pre,iFun,theRest,oinfo['obj'])
2180 2179 else:
2181 2180 #print 'was callable?', callable(oinfo['obj']) # dbg
2182 2181 return self.handle_normal(line,continue_prompt)
2183 2182
2184 2183 # If we get here, we have a normal Python line. Log and return.
2185 2184 return self.handle_normal(line,continue_prompt)
2186 2185
2187 2186 def _prefilter_dumb(self, line, continue_prompt):
2188 2187 """simple prefilter function, for debugging"""
2189 2188 return self.handle_normal(line,continue_prompt)
2190 2189
2191 2190
2192 2191 def multiline_prefilter(self, line, continue_prompt):
2193 2192 """ Run _prefilter for each line of input
2194 2193
2195 2194 Covers cases where there are multiple lines in the user entry,
2196 2195 which is the case when the user goes back to a multiline history
2197 2196 entry and presses enter.
2198 2197
2199 2198 """
2200 2199 out = []
2201 2200 for l in line.rstrip('\n').split('\n'):
2202 2201 out.append(self._prefilter(l, continue_prompt))
2203 2202 return '\n'.join(out)
2204 2203
2205 2204 # Set the default prefilter() function (this can be user-overridden)
2206 2205 prefilter = multiline_prefilter
2207 2206
2208 2207 def handle_normal(self,line,continue_prompt=None,
2209 2208 pre=None,iFun=None,theRest=None):
2210 2209 """Handle normal input lines. Use as a template for handlers."""
2211 2210
2212 2211 # With autoindent on, we need some way to exit the input loop, and I
2213 2212 # don't want to force the user to have to backspace all the way to
2214 2213 # clear the line. The rule will be in this case, that either two
2215 2214 # lines of pure whitespace in a row, or a line of pure whitespace but
2216 2215 # of a size different to the indent level, will exit the input loop.
2217 2216
2218 2217 if (continue_prompt and self.autoindent and line.isspace() and
2219 2218 (0 < abs(len(line) - self.indent_current_nsp) <= 2 or
2220 2219 (self.buffer[-1]).isspace() )):
2221 2220 line = ''
2222 2221
2223 2222 self.log(line,line,continue_prompt)
2224 2223 return line
2225 2224
2226 2225 def handle_alias(self,line,continue_prompt=None,
2227 2226 pre=None,iFun=None,theRest=None):
2228 2227 """Handle alias input lines. """
2229 2228
2230 2229 # pre is needed, because it carries the leading whitespace. Otherwise
2231 2230 # aliases won't work in indented sections.
2232 2231 transformed = self.expand_aliases(iFun, theRest)
2233 2232 line_out = '%s_ip.system(%s)' % (pre, make_quoted_expr( transformed ))
2234 2233 self.log(line,line_out,continue_prompt)
2235 2234 #print 'line out:',line_out # dbg
2236 2235 return line_out
2237 2236
2238 2237 def handle_shell_escape(self, line, continue_prompt=None,
2239 2238 pre=None,iFun=None,theRest=None):
2240 2239 """Execute the line in a shell, empty return value"""
2241 2240
2242 2241 #print 'line in :', `line` # dbg
2243 2242 # Example of a special handler. Others follow a similar pattern.
2244 2243 if line.lstrip().startswith('!!'):
2245 2244 # rewrite iFun/theRest to properly hold the call to %sx and
2246 2245 # the actual command to be executed, so handle_magic can work
2247 2246 # correctly
2248 2247 theRest = '%s %s' % (iFun[2:],theRest)
2249 2248 iFun = 'sx'
2250 2249 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,
2251 2250 line.lstrip()[2:]),
2252 2251 continue_prompt,pre,iFun,theRest)
2253 2252 else:
2254 2253 cmd=line.lstrip().lstrip('!')
2255 2254 line_out = '%s_ip.system(%s)' % (pre,make_quoted_expr(cmd))
2256 2255 # update cache/log and return
2257 2256 self.log(line,line_out,continue_prompt)
2258 2257 return line_out
2259 2258
2260 2259 def handle_magic(self, line, continue_prompt=None,
2261 2260 pre=None,iFun=None,theRest=None):
2262 2261 """Execute magic functions."""
2263 2262
2264 2263
2265 2264 cmd = '%s_ip.magic(%s)' % (pre,make_quoted_expr(iFun + " " + theRest))
2266 2265 self.log(line,cmd,continue_prompt)
2267 2266 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
2268 2267 return cmd
2269 2268
2270 2269 def handle_auto(self, line, continue_prompt=None,
2271 2270 pre=None,iFun=None,theRest=None,obj=None):
2272 2271 """Hande lines which can be auto-executed, quoting if requested."""
2273 2272
2274 2273 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
2275 2274
2276 2275 # This should only be active for single-line input!
2277 2276 if continue_prompt:
2278 2277 self.log(line,line,continue_prompt)
2279 2278 return line
2280 2279
2281 2280 auto_rewrite = True
2282 2281
2283 2282 if pre == self.ESC_QUOTE:
2284 2283 # Auto-quote splitting on whitespace
2285 2284 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
2286 2285 elif pre == self.ESC_QUOTE2:
2287 2286 # Auto-quote whole string
2288 2287 newcmd = '%s("%s")' % (iFun,theRest)
2289 2288 elif pre == self.ESC_PAREN:
2290 2289 newcmd = '%s(%s)' % (iFun,",".join(theRest.split()))
2291 2290 else:
2292 2291 # Auto-paren.
2293 2292 # We only apply it to argument-less calls if the autocall
2294 2293 # parameter is set to 2. We only need to check that autocall is <
2295 2294 # 2, since this function isn't called unless it's at least 1.
2296 2295 if not theRest and (self.rc.autocall < 2):
2297 2296 newcmd = '%s %s' % (iFun,theRest)
2298 2297 auto_rewrite = False
2299 2298 else:
2300 2299 if theRest.startswith('['):
2301 2300 if hasattr(obj,'__getitem__'):
2302 2301 # Don't autocall in this case: item access for an object
2303 2302 # which is BOTH callable and implements __getitem__.
2304 2303 newcmd = '%s %s' % (iFun,theRest)
2305 2304 auto_rewrite = False
2306 2305 else:
2307 2306 # if the object doesn't support [] access, go ahead and
2308 2307 # autocall
2309 2308 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
2310 2309 elif theRest.endswith(';'):
2311 2310 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
2312 2311 else:
2313 2312 newcmd = '%s(%s)' % (iFun.rstrip(), theRest)
2314 2313
2315 2314 if auto_rewrite:
2316 2315 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
2317 2316 # log what is now valid Python, not the actual user input (without the
2318 2317 # final newline)
2319 2318 self.log(line,newcmd,continue_prompt)
2320 2319 return newcmd
2321 2320
2322 2321 def handle_help(self, line, continue_prompt=None,
2323 2322 pre=None,iFun=None,theRest=None):
2324 2323 """Try to get some help for the object.
2325 2324
2326 2325 obj? or ?obj -> basic information.
2327 2326 obj?? or ??obj -> more details.
2328 2327 """
2329 2328
2330 2329 # We need to make sure that we don't process lines which would be
2331 2330 # otherwise valid python, such as "x=1 # what?"
2332 2331 try:
2333 2332 codeop.compile_command(line)
2334 2333 except SyntaxError:
2335 2334 # We should only handle as help stuff which is NOT valid syntax
2336 2335 if line[0]==self.ESC_HELP:
2337 2336 line = line[1:]
2338 2337 elif line[-1]==self.ESC_HELP:
2339 2338 line = line[:-1]
2340 2339 self.log(line,'#?'+line,continue_prompt)
2341 2340 if line:
2342 2341 self.magic_pinfo(line)
2343 2342 else:
2344 2343 page(self.usage,screen_lines=self.rc.screen_length)
2345 2344 return '' # Empty string is needed here!
2346 2345 except:
2347 2346 # Pass any other exceptions through to the normal handler
2348 2347 return self.handle_normal(line,continue_prompt)
2349 2348 else:
2350 2349 # If the code compiles ok, we should handle it normally
2351 2350 return self.handle_normal(line,continue_prompt)
2352 2351
2353 2352 def getapi(self):
2354 2353 """ Get an IPApi object for this shell instance
2355 2354
2356 2355 Getting an IPApi object is always preferable to accessing the shell
2357 2356 directly, but this holds true especially for extensions.
2358 2357
2359 2358 It should always be possible to implement an extension with IPApi
2360 2359 alone. If not, contact maintainer to request an addition.
2361 2360
2362 2361 """
2363 2362 return self.api
2364 2363
2365 2364 def handle_emacs(self,line,continue_prompt=None,
2366 2365 pre=None,iFun=None,theRest=None):
2367 2366 """Handle input lines marked by python-mode."""
2368 2367
2369 2368 # Currently, nothing is done. Later more functionality can be added
2370 2369 # here if needed.
2371 2370
2372 2371 # The input cache shouldn't be updated
2373 2372
2374 2373 return line
2375 2374
2376 2375 def mktempfile(self,data=None):
2377 2376 """Make a new tempfile and return its filename.
2378 2377
2379 2378 This makes a call to tempfile.mktemp, but it registers the created
2380 2379 filename internally so ipython cleans it up at exit time.
2381 2380
2382 2381 Optional inputs:
2383 2382
2384 2383 - data(None): if data is given, it gets written out to the temp file
2385 2384 immediately, and the file is closed again."""
2386 2385
2387 2386 filename = tempfile.mktemp('.py','ipython_edit_')
2388 2387 self.tempfiles.append(filename)
2389 2388
2390 2389 if data:
2391 2390 tmp_file = open(filename,'w')
2392 2391 tmp_file.write(data)
2393 2392 tmp_file.close()
2394 2393 return filename
2395 2394
2396 2395 def write(self,data):
2397 2396 """Write a string to the default output"""
2398 2397 Term.cout.write(data)
2399 2398
2400 2399 def write_err(self,data):
2401 2400 """Write a string to the default error output"""
2402 2401 Term.cerr.write(data)
2403 2402
2404 2403 def exit(self):
2405 2404 """Handle interactive exit.
2406 2405
2407 2406 This method sets the exit_now attribute."""
2408 2407
2409 2408 if self.rc.confirm_exit:
2410 2409 if self.ask_yes_no('Do you really want to exit ([y]/n)?','y'):
2411 2410 self.exit_now = True
2412 2411 else:
2413 2412 self.exit_now = True
2414 2413
2415 2414 def safe_execfile(self,fname,*where,**kw):
2416 2415 """A safe version of the builtin execfile().
2417 2416
2418 2417 This version will never throw an exception, and knows how to handle
2419 2418 ipython logs as well."""
2420 2419
2421 2420 def syspath_cleanup():
2422 2421 """Internal cleanup routine for sys.path."""
2423 2422 if add_dname:
2424 2423 try:
2425 2424 sys.path.remove(dname)
2426 2425 except ValueError:
2427 2426 # For some reason the user has already removed it, ignore.
2428 2427 pass
2429 2428
2430 2429 fname = os.path.expanduser(fname)
2431 2430
2432 2431 # Find things also in current directory. This is needed to mimic the
2433 2432 # behavior of running a script from the system command line, where
2434 2433 # Python inserts the script's directory into sys.path
2435 2434 dname = os.path.dirname(os.path.abspath(fname))
2436 2435 add_dname = False
2437 2436 if dname not in sys.path:
2438 2437 sys.path.insert(0,dname)
2439 2438 add_dname = True
2440 2439
2441 2440 try:
2442 2441 xfile = open(fname)
2443 2442 except:
2444 2443 print >> Term.cerr, \
2445 2444 'Could not open file <%s> for safe execution.' % fname
2446 2445 syspath_cleanup()
2447 2446 return None
2448 2447
2449 2448 kw.setdefault('islog',0)
2450 2449 kw.setdefault('quiet',1)
2451 2450 kw.setdefault('exit_ignore',0)
2452 2451 first = xfile.readline()
2453 2452 loghead = str(self.loghead_tpl).split('\n',1)[0].strip()
2454 2453 xfile.close()
2455 2454 # line by line execution
2456 2455 if first.startswith(loghead) or kw['islog']:
2457 2456 print 'Loading log file <%s> one line at a time...' % fname
2458 2457 if kw['quiet']:
2459 2458 stdout_save = sys.stdout
2460 2459 sys.stdout = StringIO.StringIO()
2461 2460 try:
2462 2461 globs,locs = where[0:2]
2463 2462 except:
2464 2463 try:
2465 2464 globs = locs = where[0]
2466 2465 except:
2467 2466 globs = locs = globals()
2468 2467 badblocks = []
2469 2468
2470 2469 # we also need to identify indented blocks of code when replaying
2471 2470 # logs and put them together before passing them to an exec
2472 2471 # statement. This takes a bit of regexp and look-ahead work in the
2473 2472 # file. It's easiest if we swallow the whole thing in memory
2474 2473 # first, and manually walk through the lines list moving the
2475 2474 # counter ourselves.
2476 2475 indent_re = re.compile('\s+\S')
2477 2476 xfile = open(fname)
2478 2477 filelines = xfile.readlines()
2479 2478 xfile.close()
2480 2479 nlines = len(filelines)
2481 2480 lnum = 0
2482 2481 while lnum < nlines:
2483 2482 line = filelines[lnum]
2484 2483 lnum += 1
2485 2484 # don't re-insert logger status info into cache
2486 2485 if line.startswith('#log#'):
2487 2486 continue
2488 2487 else:
2489 2488 # build a block of code (maybe a single line) for execution
2490 2489 block = line
2491 2490 try:
2492 2491 next = filelines[lnum] # lnum has already incremented
2493 2492 except:
2494 2493 next = None
2495 2494 while next and indent_re.match(next):
2496 2495 block += next
2497 2496 lnum += 1
2498 2497 try:
2499 2498 next = filelines[lnum]
2500 2499 except:
2501 2500 next = None
2502 2501 # now execute the block of one or more lines
2503 2502 try:
2504 2503 exec block in globs,locs
2505 2504 except SystemExit:
2506 2505 pass
2507 2506 except:
2508 2507 badblocks.append(block.rstrip())
2509 2508 if kw['quiet']: # restore stdout
2510 2509 sys.stdout.close()
2511 2510 sys.stdout = stdout_save
2512 2511 print 'Finished replaying log file <%s>' % fname
2513 2512 if badblocks:
2514 2513 print >> sys.stderr, ('\nThe following lines/blocks in file '
2515 2514 '<%s> reported errors:' % fname)
2516 2515
2517 2516 for badline in badblocks:
2518 2517 print >> sys.stderr, badline
2519 2518 else: # regular file execution
2520 2519 try:
2521 2520 execfile(fname,*where)
2522 2521 except SyntaxError:
2523 2522 self.showsyntaxerror()
2524 2523 warn('Failure executing file: <%s>' % fname)
2525 2524 except SystemExit,status:
2526 2525 if not kw['exit_ignore']:
2527 2526 self.showtraceback()
2528 2527 warn('Failure executing file: <%s>' % fname)
2529 2528 except:
2530 2529 self.showtraceback()
2531 2530 warn('Failure executing file: <%s>' % fname)
2532 2531
2533 2532 syspath_cleanup()
2534 2533
2535 2534 #************************* end of file <iplib.py> *****************************
@@ -1,6043 +1,6048 b''
1 2006-12-5 Ville Vainio <vivainio@gmail.com>
2
3 * Magic.py, iplib.py, completer.py: Apply R. Bernstein's
4 pydb patch 4 (rm debug printing, py 2.5 checking)
5
1 6 2006-11-30 Walter Doerwald <walter@livinglogic.de>
2 7 * IPython/Extensions/ibrowse.py: Add two new commands to ibrowse:
3 8 "refresh" (mapped to "r") refreshes the screen by restarting the iterator.
4 9 "refreshfind" (mapped to "R") does the same but tries to go back to the same
5 10 object the cursor was on before the refresh. The command "markrange" is
6 11 mapped to "%" now.
7 12 * IPython/Extensions/ibrowse.py: Make igrpentry and ipwdentry comparable.
8 13
9 14 2006-11-29 Fernando Perez <Fernando.Perez@colorado.edu>
10 15
11 16 * IPython/Magic.py (magic_debug): new %debug magic to activate the
12 17 interactive debugger on the last traceback, without having to call
13 18 %pdb and rerun your code. Made minor changes in various modules,
14 19 should automatically recognize pydb if available.
15 20
16 21 2006-11-28 Ville Vainio <vivainio@gmail.com>
17 22
18 23 * completer.py: If the text start with !, show file completions
19 24 properly. This helps when trying to complete command name
20 25 for shell escapes.
21 26
22 27 2006-11-27 Ville Vainio <vivainio@gmail.com>
23 28
24 29 * ipy_stock_completers.py: bzr completer submitted by Stefan van
25 30 der Walt. Clean up svn and hg completers by using a common
26 31 vcs_completer.
27 32
28 33 2006-11-26 Ville Vainio <vivainio@gmail.com>
29 34
30 35 * Remove ipconfig and %config; you should use _ip.options structure
31 36 directly instead!
32 37
33 38 * genutils.py: add wrap_deprecated function for deprecating callables
34 39
35 40 * iplib.py: deprecate ipmagic, ipsystem, ipalias. Use _ip.magic and
36 41 _ip.system instead. ipalias is redundant.
37 42
38 43 * Magic.py: %rehashdir no longer aliases 'cmdname' to 'cmdname.exe' on
39 44 win32, but just 'cmdname'. Other extensions (non-'exe') are still made
40 45 explicit.
41 46
42 47 * ipy_stock_completers.py: 'hg' (mercurial VCS) now has a custom
43 48 completer. Try it by entering 'hg ' and pressing tab.
44 49
45 50 * macro.py: Give Macro a useful __repr__ method
46 51
47 52 * Magic.py: %whos abbreviates the typename of Macro for brevity.
48 53
49 54 2006-11-24 Walter Doerwald <walter@livinglogic.de>
50 55 * IPython/Extensions/astyle.py: Do a relative import of ipipe, so that
51 56 we don't get a duplicate ipipe module, where registration of the xrepr
52 57 implementation for Text is useless.
53 58
54 59 * IPython/Extensions/ipipe.py: Fix __xrepr__() implementation for ils.
55 60
56 61 * IPython/Extensions/ibrowse.py: Fix keymapping for the enter command.
57 62
58 63 2006-11-24 Ville Vainio <vivainio@gmail.com>
59 64
60 65 * Magic.py, manual_base.lyx: Kirill Smelkov patch:
61 66 try to use "cProfile" instead of the slower pure python
62 67 "profile"
63 68
64 69 2006-11-23 Ville Vainio <vivainio@gmail.com>
65 70
66 71 * manual_base.lyx: Kirill Smelkov patch: Fix wrong
67 72 Qt+IPython+Designer link in documentation.
68 73
69 74 * Extensions/ipy_pydb.py: R. Bernstein's patch for passing
70 75 correct Pdb object to %pydb.
71 76
72 77
73 78 2006-11-22 Walter Doerwald <walter@livinglogic.de>
74 79 * IPython/Extensions/astyle.py: Text needs it's own implemenation of the
75 80 generic xrepr(), otherwise the list implementation would kick in.
76 81
77 82 2006-11-21 Ville Vainio <vivainio@gmail.com>
78 83
79 84 * upgrade_dir.py: Now actually overwrites a nonmodified user file
80 85 with one from UserConfig.
81 86
82 87 * ipy_profile_sh.py: Add dummy "depth" to var_expand lambda,
83 88 it was missing which broke the sh profile.
84 89
85 90 * completer.py: file completer now uses explicit '/' instead
86 91 of os.path.join, expansion of 'foo' was broken on win32
87 92 if there was one directory with name 'foobar'.
88 93
89 94 * A bunch of patches from Kirill Smelkov:
90 95
91 96 * [patch 9/9] doc: point bug-tracker URL to IPythons trac-tickets.
92 97
93 98 * [patch 7/9] Implement %page -r (page in raw mode) -
94 99
95 100 * [patch 5/9] ScientificPython webpage has moved
96 101
97 102 * [patch 4/9] The manual mentions %ds, should be %dhist
98 103
99 104 * [patch 3/9] Kill old bits from %prun doc.
100 105
101 106 * [patch 1/9] Fix typos here and there.
102 107
103 108 2006-11-08 Ville Vainio <vivainio@gmail.com>
104 109
105 110 * completer.py (attr_matches): catch all exceptions raised
106 111 by eval of expr with dots.
107 112
108 113 2006-11-07 Fernando Perez <Fernando.Perez@colorado.edu>
109 114
110 115 * IPython/iplib.py (runsource): Prepend an 'if 1:' to the user
111 116 input if it starts with whitespace. This allows you to paste
112 117 indented input from any editor without manually having to type in
113 118 the 'if 1:', which is convenient when working interactively.
114 119 Slightly modifed version of a patch by Bo Peng
115 120 <bpeng-AT-rice.edu>.
116 121
117 122 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu>
118 123
119 124 * IPython/irunner.py (main): modified irunner so it automatically
120 125 recognizes the right runner to use based on the extension (.py for
121 126 python, .ipy for ipython and .sage for sage).
122 127
123 128 * IPython/iplib.py (InteractiveShell.ipconfig): new builtin, also
124 129 visible in ipapi as ip.config(), to programatically control the
125 130 internal rc object. There's an accompanying %config magic for
126 131 interactive use, which has been enhanced to match the
127 132 funtionality in ipconfig.
128 133
129 134 * IPython/Magic.py (magic_system_verbose): Change %system_verbose
130 135 so it's not just a toggle, it now takes an argument. Add support
131 136 for a customizable header when making system calls, as the new
132 137 system_header variable in the ipythonrc file.
133 138
134 139 2006-11-03 Walter Doerwald <walter@livinglogic.de>
135 140
136 141 * IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now
137 142 generic functions (using Philip J. Eby's simplegeneric package).
138 143 This makes it possible to customize the display of third-party classes
139 144 without having to monkeypatch them. xiter() no longer supports a mode
140 145 argument and the XMode class has been removed. The same functionality can
141 146 be implemented via IterAttributeDescriptor and IterMethodDescriptor.
142 147 One consequence of the switch to generic functions is that xrepr() and
143 148 xattrs() implementation must define the default value for the mode
144 149 argument themselves and xattrs() implementations must return real
145 150 descriptors.
146 151
147 152 * IPython/external: This new subpackage will contain all third-party
148 153 packages that are bundled with IPython. (The first one is simplegeneric).
149 154
150 155 * IPython/Extensions/ipipe.py (ifile/ils): Readd output of the parent
151 156 directory which as been dropped in r1703.
152 157
153 158 * IPython/Extensions/ipipe.py (iless): Fixed.
154 159
155 160 * IPython/Extensions/ibrowse: Fixed sorting under Python 2.3.
156 161
157 162 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu>
158 163
159 164 * IPython/iplib.py (InteractiveShell.var_expand): fix stack
160 165 handling in variable expansion so that shells and magics recognize
161 166 function local scopes correctly. Bug reported by Brian.
162 167
163 168 * scripts/ipython: remove the very first entry in sys.path which
164 169 Python auto-inserts for scripts, so that sys.path under IPython is
165 170 as similar as possible to that under plain Python.
166 171
167 172 * IPython/completer.py (IPCompleter.file_matches): Fix
168 173 tab-completion so that quotes are not closed unless the completion
169 174 is unambiguous. After a request by Stefan. Minor cleanups in
170 175 ipy_stock_completers.
171 176
172 177 2006-11-02 Ville Vainio <vivainio@gmail.com>
173 178
174 179 * ipy_stock_completers.py: Add %run and %cd completers.
175 180
176 181 * completer.py: Try running custom completer for both
177 182 "foo" and "%foo" if the command is just "foo". Ignore case
178 183 when filtering possible completions.
179 184
180 185 * UserConfig/ipy_user_conf.py: install stock completers as default
181 186
182 187 * iplib.py (history_saving_wrapper), debugger(), ipy_pydb.py:
183 188 simplified readline history save / restore through a wrapper
184 189 function
185 190
186 191
187 192 2006-10-31 Ville Vainio <vivainio@gmail.com>
188 193
189 194 * strdispatch.py, completer.py, ipy_stock_completers.py:
190 195 Allow str_key ("command") in completer hooks. Implement
191 196 trivial completer for 'import' (stdlib modules only). Rename
192 197 ipy_linux_package_managers.py to ipy_stock_completers.py.
193 198 SVN completer.
194 199
195 200 * Extensions/ledit.py: %magic line editor for easily and
196 201 incrementally manipulating lists of strings. The magic command
197 202 name is %led.
198 203
199 204 2006-10-30 Ville Vainio <vivainio@gmail.com>
200 205
201 206 * Debugger.py, iplib.py (debugger()): Add last set of Rocky
202 207 Bernsteins's patches for pydb integration.
203 208 http://bashdb.sourceforge.net/pydb/
204 209
205 210 * strdispatch.py, iplib.py, completer.py, IPython/__init__.py,
206 211 Extensions/ipy_linux_package_managers.py, hooks.py: Implement
207 212 custom completer hook to allow the users to implement their own
208 213 completers. See ipy_linux_package_managers.py for example. The
209 214 hook name is 'complete_command'.
210 215
211 216 2006-10-28 Fernando Perez <Fernando.Perez@colorado.edu>
212 217
213 218 * IPython/UserConfig/ipythonrc-scipy: minor cleanups to remove old
214 219 Numeric leftovers.
215 220
216 221 * ipython.el (py-execute-region): apply Stefan's patch to fix
217 222 garbled results if the python shell hasn't been previously started.
218 223
219 224 * IPython/genutils.py (arg_split): moved to genutils, since it's a
220 225 pretty generic function and useful for other things.
221 226
222 227 * IPython/OInspect.py (getsource): Add customizable source
223 228 extractor. After a request/patch form W. Stein (SAGE).
224 229
225 230 * IPython/irunner.py (InteractiveRunner.run_source): reset tty
226 231 window size to a more reasonable value from what pexpect does,
227 232 since their choice causes wrapping bugs with long input lines.
228 233
229 234 2006-10-28 Ville Vainio <vivainio@gmail.com>
230 235
231 236 * Magic.py (%run): Save and restore the readline history from
232 237 file around %run commands to prevent side effects from
233 238 %runned programs that might use readline (e.g. pydb).
234 239
235 240 * extensions/ipy_pydb.py: Adds %pydb magic when imported, for
236 241 invoking the pydb enhanced debugger.
237 242
238 243 2006-10-23 Walter Doerwald <walter@livinglogic.de>
239 244
240 245 * IPython/Extensions/ipipe.py (ifile): Remove all methods that
241 246 call the base class method and propagate the return value to
242 247 ifile. This is now done by path itself.
243 248
244 249 2006-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
245 250
246 251 * IPython/ipapi.py (IPApi.__init__): Added new entry to public
247 252 api: set_crash_handler(), to expose the ability to change the
248 253 internal crash handler.
249 254
250 255 * IPython/CrashHandler.py (CrashHandler.__init__): abstract out
251 256 the various parameters of the crash handler so that apps using
252 257 IPython as their engine can customize crash handling. Ipmlemented
253 258 at the request of SAGE.
254 259
255 260 2006-10-14 Ville Vainio <vivainio@gmail.com>
256 261
257 262 * Magic.py, ipython.el: applied first "safe" part of Rocky
258 263 Bernstein's patch set for pydb integration.
259 264
260 265 * Magic.py (%unalias, %alias): %store'd aliases can now be
261 266 removed with '%unalias'. %alias w/o args now shows most
262 267 interesting (stored / manually defined) aliases last
263 268 where they catch the eye w/o scrolling.
264 269
265 270 * Magic.py (%rehashx), ext_rehashdir.py: files with
266 271 'py' extension are always considered executable, even
267 272 when not in PATHEXT environment variable.
268 273
269 274 2006-10-12 Ville Vainio <vivainio@gmail.com>
270 275
271 276 * jobctrl.py: Add new "jobctrl" extension for spawning background
272 277 processes with "&find /". 'import jobctrl' to try it out. Requires
273 278 'subprocess' module, standard in python 2.4+.
274 279
275 280 * iplib.py (expand_aliases, handle_alias): Aliases expand transitively,
276 281 so if foo -> bar and bar -> baz, then foo -> baz.
277 282
278 283 2006-10-09 Fernando Perez <Fernando.Perez@colorado.edu>
279 284
280 285 * IPython/Magic.py (Magic.parse_options): add a new posix option
281 286 to allow parsing of input args in magics that doesn't strip quotes
282 287 (if posix=False). This also closes %timeit bug reported by
283 288 Stefan.
284 289
285 290 2006-10-03 Ville Vainio <vivainio@gmail.com>
286 291
287 292 * iplib.py (raw_input, interact): Return ValueError catching for
288 293 raw_input. Fixes infinite loop for sys.stdin.close() or
289 294 sys.stdout.close().
290 295
291 296 2006-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
292 297
293 298 * IPython/irunner.py (InteractiveRunner.run_source): small fixes
294 299 to help in handling doctests. irunner is now pretty useful for
295 300 running standalone scripts and simulate a full interactive session
296 301 in a format that can be then pasted as a doctest.
297 302
298 303 * IPython/iplib.py (InteractiveShell.__init__): Install exit/quit
299 304 on top of the default (useless) ones. This also fixes the nasty
300 305 way in which 2.5's Quitter() exits (reverted [1785]).
301 306
302 307 * IPython/Debugger.py (Pdb.__init__): Fix ipdb to work with python
303 308 2.5.
304 309
305 310 * IPython/ultraTB.py (TBTools.set_colors): Make sure that ipdb
306 311 color scheme is updated as well when color scheme is changed
307 312 interactively.
308 313
309 314 2006-09-27 Ville Vainio <vivainio@gmail.com>
310 315
311 316 * iplib.py (raw_input): python 2.5 closes stdin on quit -> avoid
312 317 infinite loop and just exit. It's a hack, but will do for a while.
313 318
314 319 2006-08-25 Walter Doerwald <walter@livinglogic.de>
315 320
316 321 * IPython/Extensions/ipipe.py (ils): Add arguments dirs and files to
317 322 the constructor, this makes it possible to get a list of only directories
318 323 or only files.
319 324
320 325 2006-08-12 Ville Vainio <vivainio@gmail.com>
321 326
322 327 * Fakemodule.py, OInspect.py: Reverted 2006-08-11 mods,
323 328 they broke unittest
324 329
325 330 2006-08-11 Ville Vainio <vivainio@gmail.com>
326 331
327 332 * Fakemodule.py, OInspect.py: remove 2006-08-09 monkepatch
328 333 by resolving issue properly, i.e. by inheriting FakeModule
329 334 from types.ModuleType. Pickling ipython interactive data
330 335 should still work as usual (testing appreciated).
331 336
332 337 2006-08-09 Fernando Perez <Fernando.Perez@colorado.edu>
333 338
334 339 * IPython/OInspect.py: monkeypatch inspect from the stdlib if
335 340 running under python 2.3 with code from 2.4 to fix a bug with
336 341 help(). Reported by the Debian maintainers, Norbert Tretkowski
337 342 <norbert-AT-tretkowski.de> and Alexandre Fayolle
338 343 <afayolle-AT-debian.org>.
339 344
340 345 2006-08-04 Walter Doerwald <walter@livinglogic.de>
341 346
342 347 * IPython/Extensions/ibrowse.py: Fixed the help message in the footer
343 348 (which was displaying "quit" twice).
344 349
345 350 2006-07-28 Walter Doerwald <walter@livinglogic.de>
346 351
347 352 * IPython/Extensions/ipipe.py: Fix isort.__iter__() (was still using
348 353 the mode argument).
349 354
350 355 2006-07-27 Walter Doerwald <walter@livinglogic.de>
351 356
352 357 * IPython/Extensions/ipipe.py: Fix getglobals() if we're
353 358 not running under IPython.
354 359
355 360 * IPython/Extensions/ipipe.py: Rename XAttr to AttributeDetail
356 361 and make it iterable (iterating over the attribute itself). Add two new
357 362 magic strings for __xattrs__(): If the string starts with "-", the attribute
358 363 will not be displayed in ibrowse's detail view (but it can still be
359 364 iterated over). This makes it possible to add attributes that are large
360 365 lists or generator methods to the detail view. Replace magic attribute names
361 366 and _attrname() and _getattr() with "descriptors": For each type of magic
362 367 attribute name there's a subclass of Descriptor: None -> SelfDescriptor();
363 368 "foo" -> AttributeDescriptor("foo"); "foo()" -> MethodDescriptor("foo");
364 369 "-foo" -> IterAttributeDescriptor("foo"); "-foo()" -> IterMethodDescriptor("foo");
365 370 foo() -> FunctionDescriptor(foo). Magic strings returned from __xattrs__()
366 371 are still supported.
367 372
368 373 * IPython/Extensions/ibrowse.py: If fetching the next row from the input
369 374 fails in ibrowse.fetch(), the exception object is added as the last item
370 375 and item fetching is canceled. This prevents ibrowse from aborting if e.g.
371 376 a generator throws an exception midway through execution.
372 377
373 378 * IPython/Extensions/ipipe.py: Turn ifile's properties mimetype and
374 379 encoding into methods.
375 380
376 381 2006-07-26 Ville Vainio <vivainio@gmail.com>
377 382
378 383 * iplib.py: history now stores multiline input as single
379 384 history entries. Patch by Jorgen Cederlof.
380 385
381 386 2006-07-18 Walter Doerwald <walter@livinglogic.de>
382 387
383 388 * IPython/Extensions/ibrowse.py: Make cursor visible over
384 389 non existing attributes.
385 390
386 391 2006-07-14 Walter Doerwald <walter@livinglogic.de>
387 392
388 393 * IPython/Extensions/ipipe.py (ix): Use os.popen4() so that the
389 394 error output of the running command doesn't mess up the screen.
390 395
391 396 2006-07-13 Walter Doerwald <walter@livinglogic.de>
392 397
393 398 * IPython/Extensions/ipipe.py (isort): Make isort usable without
394 399 argument. This sorts the items themselves.
395 400
396 401 2006-07-12 Walter Doerwald <walter@livinglogic.de>
397 402
398 403 * IPython/Extensions/ipipe.py (eval, ifilter, isort, ieval):
399 404 Compile expression strings into code objects. This should speed
400 405 up ifilter and friends somewhat.
401 406
402 407 2006-07-08 Ville Vainio <vivainio@gmail.com>
403 408
404 409 * Magic.py: %cpaste now strips > from the beginning of lines
405 410 to ease pasting quoted code from emails. Contributed by
406 411 Stefan van der Walt.
407 412
408 413 2006-06-29 Ville Vainio <vivainio@gmail.com>
409 414
410 415 * ipmaker.py, Shell.py: qt4agg matplotlib backend support for pylab
411 416 mode, patch contributed by Darren Dale. NEEDS TESTING!
412 417
413 418 2006-06-28 Walter Doerwald <walter@livinglogic.de>
414 419
415 420 * IPython/Extensions/ibrowse.py: Give the ibrowse cursor row
416 421 a blue background. Fix fetching new display rows when the browser
417 422 scrolls more than a screenful (e.g. by using the goto command).
418 423
419 424 2006-06-27 Ville Vainio <vivainio@gmail.com>
420 425
421 426 * Magic.py (_inspect, _ofind) Apply David Huard's
422 427 patch for displaying the correct docstring for 'property'
423 428 attributes.
424 429
425 430 2006-06-23 Walter Doerwald <walter@livinglogic.de>
426 431
427 432 * IPython/Extensions/ibrowse.py: Put the documentation of the keyboard
428 433 commands into the methods implementing them.
429 434
430 435 2006-06-22 Fernando Perez <Fernando.Perez@colorado.edu>
431 436
432 437 * ipython.el (ipython-indentation-hook): cleanup patch, submitted
433 438 by Kov Chai <tchaikov-AT-gmail.com>. He notes that the original
434 439 autoindent support was authored by Jin Liu.
435 440
436 441 2006-06-22 Walter Doerwald <walter@livinglogic.de>
437 442
438 443 * IPython/Extensions/ibrowse.py: Replace the plain dictionaries used
439 444 for keymaps with a custom class that simplifies handling.
440 445
441 446 2006-06-19 Walter Doerwald <walter@livinglogic.de>
442 447
443 448 * IPython/Extensions/ibrowse.py: ibrowse now properly handles terminal
444 449 resizing. This requires Python 2.5 to work.
445 450
446 451 2006-06-16 Walter Doerwald <walter@livinglogic.de>
447 452
448 453 * IPython/Extensions/ibrowse.py: Add two new commands to
449 454 ibrowse: "hideattr" (mapped to "h") hides the attribute under
450 455 the cursor. "unhiderattrs" (mapped to "H") reveals all hidden
451 456 attributes again. Remapped the help command to "?". Display
452 457 keycodes in the range 0x01-0x1F as CTRL-xx. Add CTRL-a and CTRL-e
453 458 as keys for the "home" and "end" commands. Add three new commands
454 459 to the input mode for "find" and friends: "delend" (CTRL-K)
455 460 deletes to the end of line. "incsearchup" searches upwards in the
456 461 command history for an input that starts with the text before the cursor.
457 462 "incsearchdown" does the same downwards. Removed a bogus mapping of
458 463 the x key to "delete".
459 464
460 465 2006-06-15 Ville Vainio <vivainio@gmail.com>
461 466
462 467 * iplib.py, hooks.py: Added new generate_prompt hook that can be
463 468 used to create prompts dynamically, instead of the "old" way of
464 469 assigning "magic" strings to prompt_in1 and prompt_in2. The old
465 470 way still works (it's invoked by the default hook), of course.
466 471
467 472 * Prompts.py: added generate_output_prompt hook for altering output
468 473 prompt
469 474
470 475 * Release.py: Changed version string to 0.7.3.svn.
471 476
472 477 2006-06-15 Walter Doerwald <walter@livinglogic.de>
473 478
474 479 * IPython/Extensions/ibrowse.py: Change _BrowserLevel.moveto() so that
475 480 the call to fetch() always tries to fetch enough data for at least one
476 481 full screen. This makes it possible to simply call moveto(0,0,True) in
477 482 the constructor. Fix typos and removed the obsolete goto attribute.
478 483
479 484 2006-06-12 Ville Vainio <vivainio@gmail.com>
480 485
481 486 * ipy_profile_sh.py: applied Krisha Mohan Gundu's patch for
482 487 allowing $variable interpolation within multiline statements,
483 488 though so far only with "sh" profile for a testing period.
484 489 The patch also enables splitting long commands with \ but it
485 490 doesn't work properly yet.
486 491
487 492 2006-06-12 Walter Doerwald <walter@livinglogic.de>
488 493
489 494 * IPython/Extensions/ibrowse.py (_dodisplay): Display the length of the
490 495 input history and the position of the cursor in the input history for
491 496 the find, findbackwards and goto command.
492 497
493 498 2006-06-10 Walter Doerwald <walter@livinglogic.de>
494 499
495 500 * IPython/Extensions/ibrowse.py: Add a class _CommandInput that
496 501 implements the basic functionality of browser commands that require
497 502 input. Reimplement the goto, find and findbackwards commands as
498 503 subclasses of _CommandInput. Add an input history and keymaps to those
499 504 commands. Add "\r" as a keyboard shortcut for the enterdefault and
500 505 execute commands.
501 506
502 507 2006-06-07 Ville Vainio <vivainio@gmail.com>
503 508
504 509 * iplib.py: ipython mybatch.ipy exits ipython immediately after
505 510 running the batch files instead of leaving the session open.
506 511
507 512 2006-06-07 Fernando Perez <Fernando.Perez@colorado.edu>
508 513
509 514 * IPython/iplib.py (InteractiveShell.__init__): update BSD fix, as
510 515 the original fix was incomplete. Patch submitted by W. Maier.
511 516
512 517 2006-06-07 Ville Vainio <vivainio@gmail.com>
513 518
514 519 * iplib.py,Magic.py, ipmaker.py (magic_rehashx):
515 520 Confirmation prompts can be supressed by 'quiet' option.
516 521 _ip.options.quiet = 1 means "assume yes for all yes/no queries".
517 522
518 523 2006-06-06 *** Released version 0.7.2
519 524
520 525 2006-06-06 Fernando Perez <Fernando.Perez@colorado.edu>
521 526
522 527 * IPython/Release.py (version): Made 0.7.2 final for release.
523 528 Repo tagged and release cut.
524 529
525 530 2006-06-05 Ville Vainio <vivainio@gmail.com>
526 531
527 532 * Magic.py (magic_rehashx): Honor no_alias list earlier in
528 533 %rehashx, to avoid clobbering builtins in ipy_profile_sh.py
529 534
530 535 * upgrade_dir.py: try import 'path' module a bit harder
531 536 (for %upgrade)
532 537
533 538 2006-06-03 Fernando Perez <Fernando.Perez@colorado.edu>
534 539
535 540 * IPython/genutils.py (ask_yes_no): treat EOF as a default answer
536 541 instead of looping 20 times.
537 542
538 543 * IPython/ipmaker.py (make_IPython): honor -ipythondir flag
539 544 correctly at initialization time. Bug reported by Krishna Mohan
540 545 Gundu <gkmohan-AT-gmail.com> on the user list.
541 546
542 547 * IPython/Release.py (version): Mark 0.7.2 version to start
543 548 testing for release on 06/06.
544 549
545 550 2006-05-31 Fernando Perez <Fernando.Perez@colorado.edu>
546 551
547 552 * scripts/irunner: thin script interface so users don't have to
548 553 find the module and call it as an executable, since modules rarely
549 554 live in people's PATH.
550 555
551 556 * IPython/irunner.py (InteractiveRunner.__init__): added
552 557 delaybeforesend attribute to control delays with newer versions of
553 558 pexpect. Thanks to detailed help from pexpect's author, Noah
554 559 Spurrier <noah-AT-noah.org>. Noted how to use the SAGE runner
555 560 correctly (it works in NoColor mode).
556 561
557 562 * IPython/iplib.py (handle_normal): fix nasty crash reported on
558 563 SAGE list, from improper log() calls.
559 564
560 565 2006-05-31 Ville Vainio <vivainio@gmail.com>
561 566
562 567 * upgrade_dir.py, Magic.py (magic_upgrade): call upgrade_dir
563 568 with args in parens to work correctly with dirs that have spaces.
564 569
565 570 2006-05-30 Fernando Perez <Fernando.Perez@colorado.edu>
566 571
567 572 * IPython/Logger.py (Logger.logstart): add option to log raw input
568 573 instead of the processed one. A -r flag was added to the
569 574 %logstart magic used for controlling logging.
570 575
571 576 2006-05-29 Fernando Perez <Fernando.Perez@colorado.edu>
572 577
573 578 * IPython/iplib.py (InteractiveShell.__init__): add check for the
574 579 *BSDs to omit --color from all 'ls' aliases, since *BSD ls doesn't
575 580 recognize the option. After a bug report by Will Maier. This
576 581 closes #64 (will do it after confirmation from W. Maier).
577 582
578 583 * IPython/irunner.py: New module to run scripts as if manually
579 584 typed into an interactive environment, based on pexpect. After a
580 585 submission by Ken Schutte <kschutte-AT-csail.mit.edu> on the
581 586 ipython-user list. Simple unittests in the tests/ directory.
582 587
583 588 * tools/release: add Will Maier, OpenBSD port maintainer, to
584 589 recepients list. We are now officially part of the OpenBSD ports:
585 590 http://www.openbsd.org/ports.html ! Many thanks to Will for the
586 591 work.
587 592
588 593 2006-05-26 Fernando Perez <Fernando.Perez@colorado.edu>
589 594
590 595 * IPython/ipmaker.py (make_IPython): modify sys.argv fix (below)
591 596 so that it doesn't break tkinter apps.
592 597
593 598 * IPython/iplib.py (_prefilter): fix bug where aliases would
594 599 shadow variables when autocall was fully off. Reported by SAGE
595 600 author William Stein.
596 601
597 602 * IPython/OInspect.py (Inspector.__init__): add a flag to control
598 603 at what detail level strings are computed when foo? is requested.
599 604 This allows users to ask for example that the string form of an
600 605 object is only computed when foo?? is called, or even never, by
601 606 setting the object_info_string_level >= 2 in the configuration
602 607 file. This new option has been added and documented. After a
603 608 request by SAGE to be able to control the printing of very large
604 609 objects more easily.
605 610
606 611 2006-05-25 Fernando Perez <Fernando.Perez@colorado.edu>
607 612
608 613 * IPython/ipmaker.py (make_IPython): remove the ipython call path
609 614 from sys.argv, to be 100% consistent with how Python itself works
610 615 (as seen for example with python -i file.py). After a bug report
611 616 by Jeffrey Collins.
612 617
613 618 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix
614 619 nasty bug which was preventing custom namespaces with -pylab,
615 620 reported by M. Foord. Minor cleanup, remove old matplotlib.matlab
616 621 compatibility (long gone from mpl).
617 622
618 623 * IPython/ipapi.py (make_session): name change: create->make. We
619 624 use make in other places (ipmaker,...), it's shorter and easier to
620 625 type and say, etc. I'm trying to clean things before 0.7.2 so
621 626 that I can keep things stable wrt to ipapi in the chainsaw branch.
622 627
623 628 * ipython.el: fix the py-pdbtrack-input-prompt variable so that
624 629 python-mode recognizes our debugger mode. Add support for
625 630 autoindent inside (X)emacs. After a patch sent in by Jin Liu
626 631 <m.liu.jin-AT-gmail.com> originally written by
627 632 doxgen-AT-newsmth.net (with minor modifications for xemacs
628 633 compatibility)
629 634
630 635 * IPython/Debugger.py (Pdb.format_stack_entry): fix formatting of
631 636 tracebacks when walking the stack so that the stack tracking system
632 637 in emacs' python-mode can identify the frames correctly.
633 638
634 639 * IPython/ipmaker.py (make_IPython): make the internal (and
635 640 default config) autoedit_syntax value false by default. Too many
636 641 users have complained to me (both on and off-list) about problems
637 642 with this option being on by default, so I'm making it default to
638 643 off. It can still be enabled by anyone via the usual mechanisms.
639 644
640 645 * IPython/completer.py (Completer.attr_matches): add support for
641 646 PyCrust-style _getAttributeNames magic method. Patch contributed
642 647 by <mscott-AT-goldenspud.com>. Closes #50.
643 648
644 649 * IPython/iplib.py (InteractiveShell.__init__): remove the
645 650 deletion of exit/quit from __builtin__, which can break
646 651 third-party tools like the Zope debugging console. The
647 652 %exit/%quit magics remain. In general, it's probably a good idea
648 653 not to delete anything from __builtin__, since we never know what
649 654 that will break. In any case, python now (for 2.5) will support
650 655 'real' exit/quit, so this issue is moot. Closes #55.
651 656
652 657 * IPython/genutils.py (with_obj): rename the 'with' function to
653 658 'withobj' to avoid incompatibilities with Python 2.5, where 'with'
654 659 becomes a language keyword. Closes #53.
655 660
656 661 * IPython/FakeModule.py (FakeModule.__init__): add a proper
657 662 __file__ attribute to this so it fools more things into thinking
658 663 it is a real module. Closes #59.
659 664
660 665 * IPython/Magic.py (magic_edit): add -n option to open the editor
661 666 at a specific line number. After a patch by Stefan van der Walt.
662 667
663 668 2006-05-23 Fernando Perez <Fernando.Perez@colorado.edu>
664 669
665 670 * IPython/iplib.py (edit_syntax_error): fix crash when for some
666 671 reason the file could not be opened. After automatic crash
667 672 reports sent by James Graham <jgraham-AT-ast.cam.ac.uk> and
668 673 Charles Dolan <charlespatrickdolan-AT-yahoo.com>.
669 674 (_should_recompile): Don't fire editor if using %bg, since there
670 675 is no file in the first place. From the same report as above.
671 676 (raw_input): protect against faulty third-party prefilters. After
672 677 an automatic crash report sent by Dirk Laurie <dirk-AT-sun.ac.za>
673 678 while running under SAGE.
674 679
675 680 2006-05-23 Ville Vainio <vivainio@gmail.com>
676 681
677 682 * ipapi.py: Stripped down ip.to_user_ns() to work only as
678 683 ip.to_user_ns("x1 y1"), which exposes vars x1 and y1. ipapi.get()
679 684 now returns None (again), unless dummy is specifically allowed by
680 685 ipapi.get(allow_dummy=True).
681 686
682 687 2006-05-18 Fernando Perez <Fernando.Perez@colorado.edu>
683 688
684 689 * IPython: remove all 2.2-compatibility objects and hacks from
685 690 everywhere, since we only support 2.3 at this point. Docs
686 691 updated.
687 692
688 693 * IPython/ipapi.py (IPApi.__init__): Cleanup of all getters.
689 694 Anything requiring extra validation can be turned into a Python
690 695 property in the future. I used a property for the db one b/c
691 696 there was a nasty circularity problem with the initialization
692 697 order, which right now I don't have time to clean up.
693 698
694 699 * IPython/Shell.py (MTInteractiveShell.runcode): Fix, I think,
695 700 another locking bug reported by Jorgen. I'm not 100% sure though,
696 701 so more testing is needed...
697 702
698 703 2006-05-17 Fernando Perez <Fernando.Perez@colorado.edu>
699 704
700 705 * IPython/ipapi.py (IPApi.to_user_ns): New function to inject
701 706 local variables from any routine in user code (typically executed
702 707 with %run) directly into the interactive namespace. Very useful
703 708 when doing complex debugging.
704 709 (IPythonNotRunning): Changed the default None object to a dummy
705 710 whose attributes can be queried as well as called without
706 711 exploding, to ease writing code which works transparently both in
707 712 and out of ipython and uses some of this API.
708 713
709 714 2006-05-16 Fernando Perez <Fernando.Perez@colorado.edu>
710 715
711 716 * IPython/hooks.py (result_display): Fix the fact that our display
712 717 hook was using str() instead of repr(), as the default python
713 718 console does. This had gone unnoticed b/c it only happened if
714 719 %Pprint was off, but the inconsistency was there.
715 720
716 721 2006-05-15 Ville Vainio <vivainio@gmail.com>
717 722
718 723 * Oinspect.py: Only show docstring for nonexisting/binary files
719 724 when doing object??, closing ticket #62
720 725
721 726 2006-05-13 Fernando Perez <Fernando.Perez@colorado.edu>
722 727
723 728 * IPython/Shell.py (MTInteractiveShell.runsource): Fix threading
724 729 bug, closes http://www.scipy.net/roundup/ipython/issue55. A lock
725 730 was being released in a routine which hadn't checked if it had
726 731 been the one to acquire it.
727 732
728 733 2006-05-07 Fernando Perez <Fernando.Perez@colorado.edu>
729 734
730 735 * IPython/Release.py (version): put out 0.7.2.rc1 for testing.
731 736
732 737 2006-04-11 Ville Vainio <vivainio@gmail.com>
733 738
734 739 * iplib.py, ipmaker.py: .ipy extension now means "ipython batch file"
735 740 in command line. E.g. "ipython test.ipy" runs test.ipy with ipython
736 741 prefilters, allowing stuff like magics and aliases in the file.
737 742
738 743 * Prompts.py, Extensions/clearcmd.py, ipy_system_conf.py: %clear magic
739 744 added. Supported now are "%clear in" and "%clear out" (clear input and
740 745 output history, respectively). Also fixed CachedOutput.flush to
741 746 properly flush the output cache.
742 747
743 748 * Extensions/pspersistence.py: Fix %store to avoid "%store obj.attr"
744 749 half-success (and fail explicitly).
745 750
746 751 2006-03-28 Ville Vainio <vivainio@gmail.com>
747 752
748 753 * iplib.py: Fix quoting of aliases so that only argless ones
749 754 are quoted
750 755
751 756 2006-03-28 Ville Vainio <vivainio@gmail.com>
752 757
753 758 * iplib.py: Quote aliases with spaces in the name.
754 759 "c:\program files\blah\bin" is now legal alias target.
755 760
756 761 * ext_rehashdir.py: Space no longer allowed as arg
757 762 separator, since space is legal in path names.
758 763
759 764 2006-03-16 Ville Vainio <vivainio@gmail.com>
760 765
761 766 * upgrade_dir.py: Take path.py from Extensions, correcting
762 767 %upgrade magic
763 768
764 769 * ipmaker.py: Suggest using %upgrade if ipy_user_conf.py isn't found.
765 770
766 771 * hooks.py: Only enclose editor binary in quotes if legal and
767 772 necessary (space in the name, and is an existing file). Fixes a bug
768 773 reported by Zachary Pincus.
769 774
770 775 2006-03-13 Fernando Perez <Fernando.Perez@colorado.edu>
771 776
772 777 * Manual: thanks to a tip on proper color handling for Emacs, by
773 778 Eric J Haywiser <ejh1-AT-MIT.EDU>.
774 779
775 780 * ipython.el: close http://www.scipy.net/roundup/ipython/issue57
776 781 by applying the provided patch. Thanks to Liu Jin
777 782 <m.liu.jin-AT-gmail.com> for the contribution. No problems under
778 783 XEmacs/Linux, I'm trusting the submitter that it actually helps
779 784 under win32/GNU Emacs. Will revisit if any problems are reported.
780 785
781 786 2006-03-12 Fernando Perez <Fernando.Perez@colorado.edu>
782 787
783 788 * IPython/Gnuplot2.py (_FileClass): update for current Gnuplot.py
784 789 from SVN, thanks to a patch by Ryan Woodard <rywo@bas.ac.uk>.
785 790
786 791 2006-03-12 Ville Vainio <vivainio@gmail.com>
787 792
788 793 * Magic.py (magic_timeit): Added %timeit magic, contributed by
789 794 Torsten Marek.
790 795
791 796 2006-03-12 Fernando Perez <Fernando.Perez@colorado.edu>
792 797
793 798 * IPython/Magic.py (magic_macro): fix so that the n1-n2 syntax for
794 799 line ranges works again.
795 800
796 801 2006-03-11 Fernando Perez <Fernando.Perez@colorado.edu>
797 802
798 803 * IPython/iplib.py (showtraceback): add back sys.last_traceback
799 804 and friends, after a discussion with Zach Pincus on ipython-user.
800 805 I'm not 100% sure, but after thinking about it quite a bit, it may
801 806 be OK. Testing with the multithreaded shells didn't reveal any
802 807 problems, but let's keep an eye out.
803 808
804 809 In the process, I fixed a few things which were calling
805 810 self.InteractiveTB() directly (like safe_execfile), which is a
806 811 mistake: ALL exception reporting should be done by calling
807 812 self.showtraceback(), which handles state and tab-completion and
808 813 more.
809 814
810 815 2006-03-01 Ville Vainio <vivainio@gmail.com>
811 816
812 817 * Extensions/ipipe.py: Added Walter Doerwald's "ipipe" module.
813 818 To use, do "from ipipe import *".
814 819
815 820 2006-02-24 Ville Vainio <vivainio@gmail.com>
816 821
817 822 * Magic.py, upgrade_dir.py: %upgrade magic added. Does things more
818 823 "cleanly" and safely than the older upgrade mechanism.
819 824
820 825 2006-02-21 Ville Vainio <vivainio@gmail.com>
821 826
822 827 * Magic.py: %save works again.
823 828
824 829 2006-02-15 Ville Vainio <vivainio@gmail.com>
825 830
826 831 * Magic.py: %Pprint works again
827 832
828 833 * Extensions/ipy_sane_defaults.py: Provide everything provided
829 834 in default ipythonrc, to make it possible to have a completely empty
830 835 ipythonrc (and thus completely rc-file free configuration)
831 836
832 837 2006-02-11 Fernando Perez <Fernando.Perez@colorado.edu>
833 838
834 839 * IPython/hooks.py (editor): quote the call to the editor command,
835 840 to allow commands with spaces in them. Problem noted by watching
836 841 Ian Oswald's video about textpad under win32 at
837 842 http://showmedo.com/videoListPage?listKey=PythonIPythonSeries
838 843
839 844 * IPython/UserConfig/ipythonrc: Replace @ signs with % when
840 845 describing magics (we haven't used @ for a loong time).
841 846
842 847 * IPython/ultraTB.py (VerboseTB.text.text_repr): Added patch
843 848 contributed by marienz to close
844 849 http://www.scipy.net/roundup/ipython/issue53.
845 850
846 851 2006-02-10 Ville Vainio <vivainio@gmail.com>
847 852
848 853 * genutils.py: getoutput now works in win32 too
849 854
850 855 * completer.py: alias and magic completion only invoked
851 856 at the first "item" in the line, to avoid "cd %store"
852 857 nonsense.
853 858
854 859 2006-02-09 Ville Vainio <vivainio@gmail.com>
855 860
856 861 * test/*: Added a unit testing framework (finally).
857 862 '%run runtests.py' to run test_*.
858 863
859 864 * ipapi.py: Exposed runlines and set_custom_exc
860 865
861 866 2006-02-07 Ville Vainio <vivainio@gmail.com>
862 867
863 868 * iplib.py: don't split "f 1 2" to "f(1,2)" in autocall,
864 869 instead use "f(1 2)" as before.
865 870
866 871 2006-02-05 Fernando Perez <Fernando.Perez@colorado.edu>
867 872
868 873 * IPython/demo.py (IPythonDemo): Add new classes to the demo
869 874 facilities, for demos processed by the IPython input filter
870 875 (IPythonDemo), and for running a script one-line-at-a-time as a
871 876 demo, both for pure Python (LineDemo) and for IPython-processed
872 877 input (IPythonLineDemo). After a request by Dave Kohel, from the
873 878 SAGE team.
874 879 (Demo.edit): added an edit() method to the demo objects, to edit
875 880 the in-memory copy of the last executed block.
876 881
877 882 * IPython/Magic.py (magic_edit): add '-r' option for 'raw'
878 883 processing to %edit, %macro and %save. These commands can now be
879 884 invoked on the unprocessed input as it was typed by the user
880 885 (without any prefilters applied). After requests by the SAGE team
881 886 at SAGE days 2006: http://modular.ucsd.edu/sage/days1/schedule.html.
882 887
883 888 2006-02-01 Ville Vainio <vivainio@gmail.com>
884 889
885 890 * setup.py, eggsetup.py: easy_install ipython==dev works
886 891 correctly now (on Linux)
887 892
888 893 * ipy_user_conf,ipmaker: user config changes, removed spurious
889 894 warnings
890 895
891 896 * iplib: if rc.banner is string, use it as is.
892 897
893 898 * Magic: %pycat accepts a string argument and pages it's contents.
894 899
895 900
896 901 2006-01-30 Ville Vainio <vivainio@gmail.com>
897 902
898 903 * pickleshare,pspersistence,ipapi,Magic: persistence overhaul.
899 904 Now %store and bookmarks work through PickleShare, meaning that
900 905 concurrent access is possible and all ipython sessions see the
901 906 same database situation all the time, instead of snapshot of
902 907 the situation when the session was started. Hence, %bookmark
903 908 results are immediately accessible from othes sessions. The database
904 909 is also available for use by user extensions. See:
905 910 http://www.python.org/pypi/pickleshare
906 911
907 912 * hooks.py: Two new hooks, 'shutdown_hook' and 'late_startup_hook'.
908 913
909 914 * aliases can now be %store'd
910 915
911 916 * path.py moved to Extensions so that pickleshare does not need
912 917 IPython-specific import. Extensions added to pythonpath right
913 918 at __init__.
914 919
915 920 * iplib.py: ipalias deprecated/redundant; aliases are converted and
916 921 called with _ip.system and the pre-transformed command string.
917 922
918 923 2006-01-29 Fernando Perez <Fernando.Perez@colorado.edu>
919 924
920 925 * IPython/iplib.py (interact): Fix that we were not catching
921 926 KeyboardInterrupt exceptions properly. I'm not quite sure why the
922 927 logic here had to change, but it's fixed now.
923 928
924 929 2006-01-29 Ville Vainio <vivainio@gmail.com>
925 930
926 931 * iplib.py: Try to import pyreadline on Windows.
927 932
928 933 2006-01-27 Ville Vainio <vivainio@gmail.com>
929 934
930 935 * iplib.py: Expose ipapi as _ip in builtin namespace.
931 936 Makes ipmagic (-> _ip.magic), ipsystem (-> _ip.system)
932 937 and ip_set_hook (-> _ip.set_hook) redundant. % and !
933 938 syntax now produce _ip.* variant of the commands.
934 939
935 940 * "_ip.options().autoedit_syntax = 2" automatically throws
936 941 user to editor for syntax error correction without prompting.
937 942
938 943 2006-01-27 Ville Vainio <vivainio@gmail.com>
939 944
940 945 * ipmaker.py: Give "realistic" sys.argv for scripts (without
941 946 'ipython' at argv[0]) executed through command line.
942 947 NOTE: this DEPRECATES calling ipython with multiple scripts
943 948 ("ipython a.py b.py c.py")
944 949
945 950 * iplib.py, hooks.py: Added configurable input prefilter,
946 951 named 'input_prefilter'. See ext_rescapture.py for example
947 952 usage.
948 953
949 954 * ext_rescapture.py, Magic.py: Better system command output capture
950 955 through 'var = !ls' (deprecates user-visible %sc). Same notation
951 956 applies for magics, 'var = %alias' assigns alias list to var.
952 957
953 958 * ipapi.py: added meta() for accessing extension-usable data store.
954 959
955 960 * iplib.py: added InteractiveShell.getapi(). New magics should be
956 961 written doing self.getapi() instead of using the shell directly.
957 962
958 963 * Magic.py: %store now allows doing %store foo > ~/myfoo.txt and
959 964 %store foo >> ~/myfoo.txt to store variables to files (in clean
960 965 textual form, not a restorable pickle).
961 966
962 967 * ipmaker.py: now import ipy_profile_PROFILENAME automatically
963 968
964 969 * usage.py, Magic.py: added %quickref
965 970
966 971 * iplib.py: ESC_PAREN fixes: /f 1 2 -> f(1,2), not f(1 2).
967 972
968 973 * GetoptErrors when invoking magics etc. with wrong args
969 974 are now more helpful:
970 975 GetoptError: option -l not recognized (allowed: "qb" )
971 976
972 977 2006-01-25 Fernando Perez <Fernando.Perez@colorado.edu>
973 978
974 979 * IPython/demo.py (Demo.show): Flush stdout after each block, so
975 980 computationally intensive blocks don't appear to stall the demo.
976 981
977 982 2006-01-24 Ville Vainio <vivainio@gmail.com>
978 983
979 984 * iplib.py, hooks.py: 'result_display' hook can return a non-None
980 985 value to manipulate resulting history entry.
981 986
982 987 * ipapi.py: Moved TryNext here from hooks.py. Moved functions
983 988 to instance methods of IPApi class, to make extending an embedded
984 989 IPython feasible. See ext_rehashdir.py for example usage.
985 990
986 991 * Merged 1071-1076 from branches/0.7.1
987 992
988 993
989 994 2006-01-23 Fernando Perez <Fernando.Perez@colorado.edu>
990 995
991 996 * tools/release (daystamp): Fix build tools to use the new
992 997 eggsetup.py script to build lightweight eggs.
993 998
994 999 * Applied changesets 1062 and 1064 before 0.7.1 release.
995 1000
996 1001 * IPython/Magic.py (magic_history): Add '-r' option to %hist, to
997 1002 see the raw input history (without conversions like %ls ->
998 1003 ipmagic("ls")). After a request from W. Stein, SAGE
999 1004 (http://modular.ucsd.edu/sage) developer. This information is
1000 1005 stored in the input_hist_raw attribute of the IPython instance, so
1001 1006 developers can access it if needed (it's an InputList instance).
1002 1007
1003 1008 * Versionstring = 0.7.2.svn
1004 1009
1005 1010 * eggsetup.py: A separate script for constructing eggs, creates
1006 1011 proper launch scripts even on Windows (an .exe file in
1007 1012 \python24\scripts).
1008 1013
1009 1014 * ipapi.py: launch_new_instance, launch entry point needed for the
1010 1015 egg.
1011 1016
1012 1017 2006-01-23 Ville Vainio <vivainio@gmail.com>
1013 1018
1014 1019 * Added %cpaste magic for pasting python code
1015 1020
1016 1021 2006-01-22 Ville Vainio <vivainio@gmail.com>
1017 1022
1018 1023 * Merge from branches/0.7.1 into trunk, revs 1052-1057
1019 1024
1020 1025 * Versionstring = 0.7.2.svn
1021 1026
1022 1027 * eggsetup.py: A separate script for constructing eggs, creates
1023 1028 proper launch scripts even on Windows (an .exe file in
1024 1029 \python24\scripts).
1025 1030
1026 1031 * ipapi.py: launch_new_instance, launch entry point needed for the
1027 1032 egg.
1028 1033
1029 1034 2006-01-22 Fernando Perez <Fernando.Perez@colorado.edu>
1030 1035
1031 1036 * IPython/OInspect.py (Inspector.pinfo): fix bug where foo?? or
1032 1037 %pfile foo would print the file for foo even if it was a binary.
1033 1038 Now, extensions '.so' and '.dll' are skipped.
1034 1039
1035 1040 * IPython/Shell.py (MTInteractiveShell.__init__): Fix threading
1036 1041 bug, where macros would fail in all threaded modes. I'm not 100%
1037 1042 sure, so I'm going to put out an rc instead of making a release
1038 1043 today, and wait for feedback for at least a few days.
1039 1044
1040 1045 * IPython/iplib.py (handle_normal): fix (finally? somehow I doubt
1041 1046 it...) the handling of pasting external code with autoindent on.
1042 1047 To get out of a multiline input, the rule will appear for most
1043 1048 users unchanged: two blank lines or change the indent level
1044 1049 proposed by IPython. But there is a twist now: you can
1045 1050 add/subtract only *one or two spaces*. If you add/subtract three
1046 1051 or more (unless you completely delete the line), IPython will
1047 1052 accept that line, and you'll need to enter a second one of pure
1048 1053 whitespace. I know it sounds complicated, but I can't find a
1049 1054 different solution that covers all the cases, with the right
1050 1055 heuristics. Hopefully in actual use, nobody will really notice
1051 1056 all these strange rules and things will 'just work'.
1052 1057
1053 1058 2006-01-21 Fernando Perez <Fernando.Perez@colorado.edu>
1054 1059
1055 1060 * IPython/iplib.py (interact): catch exceptions which can be
1056 1061 triggered asynchronously by signal handlers. Thanks to an
1057 1062 automatic crash report, submitted by Colin Kingsley
1058 1063 <tercel-AT-gentoo.org>.
1059 1064
1060 1065 2006-01-20 Ville Vainio <vivainio@gmail.com>
1061 1066
1062 1067 * Ipython/Extensions/ext_rehashdir.py: Created a usable example
1063 1068 (%rehashdir, very useful, try it out) of how to extend ipython
1064 1069 with new magics. Also added Extensions dir to pythonpath to make
1065 1070 importing extensions easy.
1066 1071
1067 1072 * %store now complains when trying to store interactively declared
1068 1073 classes / instances of those classes.
1069 1074
1070 1075 * Extensions/ipy_system_conf.py, UserConfig/ipy_user_conf.py,
1071 1076 ipmaker.py: Config rehaul. Now ipy_..._conf.py are always imported
1072 1077 if they exist, and ipy_user_conf.py with some defaults is created for
1073 1078 the user.
1074 1079
1075 1080 * Startup rehashing done by the config file, not InterpreterExec.
1076 1081 This means system commands are available even without selecting the
1077 1082 pysh profile. It's the sensible default after all.
1078 1083
1079 1084 2006-01-20 Fernando Perez <Fernando.Perez@colorado.edu>
1080 1085
1081 1086 * IPython/iplib.py (raw_input): I _think_ I got the pasting of
1082 1087 multiline code with autoindent on working. But I am really not
1083 1088 sure, so this needs more testing. Will commit a debug-enabled
1084 1089 version for now, while I test it some more, so that Ville and
1085 1090 others may also catch any problems. Also made
1086 1091 self.indent_current_str() a method, to ensure that there's no
1087 1092 chance of the indent space count and the corresponding string
1088 1093 falling out of sync. All code needing the string should just call
1089 1094 the method.
1090 1095
1091 1096 2006-01-18 Fernando Perez <Fernando.Perez@colorado.edu>
1092 1097
1093 1098 * IPython/Magic.py (magic_edit): fix check for when users don't
1094 1099 save their output files, the try/except was in the wrong section.
1095 1100
1096 1101 2006-01-17 Fernando Perez <Fernando.Perez@colorado.edu>
1097 1102
1098 1103 * IPython/Magic.py (magic_run): fix __file__ global missing from
1099 1104 script's namespace when executed via %run. After a report by
1100 1105 Vivian.
1101 1106
1102 1107 * IPython/Debugger.py (Pdb.__init__): Fix breakage with '%run -d'
1103 1108 when using python 2.4. The parent constructor changed in 2.4, and
1104 1109 we need to track it directly (we can't call it, as it messes up
1105 1110 readline and tab-completion inside our pdb would stop working).
1106 1111 After a bug report by R. Bernstein <rocky-AT-panix.com>.
1107 1112
1108 1113 2006-01-16 Ville Vainio <vivainio@gmail.com>
1109 1114
1110 1115 * Ipython/magic.py: Reverted back to old %edit functionality
1111 1116 that returns file contents on exit.
1112 1117
1113 1118 * IPython/path.py: Added Jason Orendorff's "path" module to
1114 1119 IPython tree, http://www.jorendorff.com/articles/python/path/.
1115 1120 You can get path objects conveniently through %sc, and !!, e.g.:
1116 1121 sc files=ls
1117 1122 for p in files.paths: # or files.p
1118 1123 print p,p.mtime
1119 1124
1120 1125 * Ipython/iplib.py:"," and ";" autoquoting-upon-autocall
1121 1126 now work again without considering the exclusion regexp -
1122 1127 hence, things like ',foo my/path' turn to 'foo("my/path")'
1123 1128 instead of syntax error.
1124 1129
1125 1130
1126 1131 2006-01-14 Ville Vainio <vivainio@gmail.com>
1127 1132
1128 1133 * IPython/ipapi.py (ashook, asmagic, options): Added convenience
1129 1134 ipapi decorators for python 2.4 users, options() provides access to rc
1130 1135 data.
1131 1136
1132 1137 * IPython/Magic.py (magic_cd): %cd now accepts backslashes
1133 1138 as path separators (even on Linux ;-). Space character after
1134 1139 backslash (as yielded by tab completer) is still space;
1135 1140 "%cd long\ name" works as expected.
1136 1141
1137 1142 * IPython/ipapi.py,hooks.py,iplib.py: Hooks now implemented
1138 1143 as "chain of command", with priority. API stays the same,
1139 1144 TryNext exception raised by a hook function signals that
1140 1145 current hook failed and next hook should try handling it, as
1141 1146 suggested by Walter DΓΆrwald <walter@livinglogic.de>. Walter also
1142 1147 requested configurable display hook, which is now implemented.
1143 1148
1144 1149 2006-01-13 Ville Vainio <vivainio@gmail.com>
1145 1150
1146 1151 * IPython/platutils*.py: platform specific utility functions,
1147 1152 so far only set_term_title is implemented (change terminal
1148 1153 label in windowing systems). %cd now changes the title to
1149 1154 current dir.
1150 1155
1151 1156 * IPython/Release.py: Added myself to "authors" list,
1152 1157 had to create new files.
1153 1158
1154 1159 * IPython/iplib.py (handle_shell_escape): fixed logical flaw in
1155 1160 shell escape; not a known bug but had potential to be one in the
1156 1161 future.
1157 1162
1158 1163 * IPython/ipapi.py (added),OInspect.py,iplib.py: "Public"
1159 1164 extension API for IPython! See the module for usage example. Fix
1160 1165 OInspect for docstring-less magic functions.
1161 1166
1162 1167
1163 1168 2006-01-13 Fernando Perez <Fernando.Perez@colorado.edu>
1164 1169
1165 1170 * IPython/iplib.py (raw_input): temporarily deactivate all
1166 1171 attempts at allowing pasting of code with autoindent on. It
1167 1172 introduced bugs (reported by Prabhu) and I can't seem to find a
1168 1173 robust combination which works in all cases. Will have to revisit
1169 1174 later.
1170 1175
1171 1176 * IPython/genutils.py: remove isspace() function. We've dropped
1172 1177 2.2 compatibility, so it's OK to use the string method.
1173 1178
1174 1179 2006-01-12 Fernando Perez <Fernando.Perez@colorado.edu>
1175 1180
1176 1181 * IPython/iplib.py (InteractiveShell.__init__): fix regexp
1177 1182 matching what NOT to autocall on, to include all python binary
1178 1183 operators (including things like 'and', 'or', 'is' and 'in').
1179 1184 Prompted by a bug report on 'foo & bar', but I realized we had
1180 1185 many more potential bug cases with other operators. The regexp is
1181 1186 self.re_exclude_auto, it's fairly commented.
1182 1187
1183 1188 2006-01-12 Ville Vainio <vivainio@gmail.com>
1184 1189
1185 1190 * IPython/iplib.py (make_quoted_expr,handle_shell_escape):
1186 1191 Prettified and hardened string/backslash quoting with ipsystem(),
1187 1192 ipalias() and ipmagic(). Now even \ characters are passed to
1188 1193 %magics, !shell escapes and aliases exactly as they are in the
1189 1194 ipython command line. Should improve backslash experience,
1190 1195 particularly in Windows (path delimiter for some commands that
1191 1196 won't understand '/'), but Unix benefits as well (regexps). %cd
1192 1197 magic still doesn't support backslash path delimiters, though. Also
1193 1198 deleted all pretense of supporting multiline command strings in
1194 1199 !system or %magic commands. Thanks to Jerry McRae for suggestions.
1195 1200
1196 1201 * doc/build_doc_instructions.txt added. Documentation on how to
1197 1202 use doc/update_manual.py, added yesterday. Both files contributed
1198 1203 by JΓΆrgen Stenarson <jorgen.stenarson-AT-bostream.nu>. This slates
1199 1204 doc/*.sh for deprecation at a later date.
1200 1205
1201 1206 * /ipython.py Added ipython.py to root directory for
1202 1207 zero-installation (tar xzvf ipython.tgz; cd ipython; python
1203 1208 ipython.py) and development convenience (no need to keep doing
1204 1209 "setup.py install" between changes).
1205 1210
1206 1211 * Made ! and !! shell escapes work (again) in multiline expressions:
1207 1212 if 1:
1208 1213 !ls
1209 1214 !!ls
1210 1215
1211 1216 2006-01-12 Fernando Perez <Fernando.Perez@colorado.edu>
1212 1217
1213 1218 * IPython/ipstruct.py (Struct): Rename IPython.Struct to
1214 1219 IPython.ipstruct, to avoid local shadowing of the stdlib 'struct'
1215 1220 module in case-insensitive installation. Was causing crashes
1216 1221 under win32. Closes http://www.scipy.net/roundup/ipython/issue49.
1217 1222
1218 1223 * IPython/Magic.py (magic_pycat): Fix pycat, patch by Marien Zwart
1219 1224 <marienz-AT-gentoo.org>, closes
1220 1225 http://www.scipy.net/roundup/ipython/issue51.
1221 1226
1222 1227 2006-01-11 Fernando Perez <Fernando.Perez@colorado.edu>
1223 1228
1224 1229 * IPython/Shell.py (IPShellGTK.on_timer): Finally fix the
1225 1230 problem of excessive CPU usage under *nix and keyboard lag under
1226 1231 win32.
1227 1232
1228 1233 2006-01-10 *** Released version 0.7.0
1229 1234
1230 1235 2006-01-10 Fernando Perez <Fernando.Perez@colorado.edu>
1231 1236
1232 1237 * IPython/Release.py (revision): tag version number to 0.7.0,
1233 1238 ready for release.
1234 1239
1235 1240 * IPython/Magic.py (magic_edit): Add print statement to %edit so
1236 1241 it informs the user of the name of the temp. file used. This can
1237 1242 help if you decide later to reuse that same file, so you know
1238 1243 where to copy the info from.
1239 1244
1240 1245 2006-01-09 Fernando Perez <Fernando.Perez@colorado.edu>
1241 1246
1242 1247 * setup_bdist_egg.py: little script to build an egg. Added
1243 1248 support in the release tools as well.
1244 1249
1245 1250 2006-01-08 Fernando Perez <Fernando.Perez@colorado.edu>
1246 1251
1247 1252 * IPython/Shell.py (IPShellWX.__init__): add support for WXPython
1248 1253 version selection (new -wxversion command line and ipythonrc
1249 1254 parameter). Patch contributed by Arnd Baecker
1250 1255 <arnd.baecker-AT-web.de>.
1251 1256
1252 1257 * IPython/iplib.py (embed_mainloop): fix tab-completion in
1253 1258 embedded instances, for variables defined at the interactive
1254 1259 prompt of the embedded ipython. Reported by Arnd.
1255 1260
1256 1261 * IPython/Magic.py (magic_autocall): Fix %autocall magic. Now
1257 1262 it can be used as a (stateful) toggle, or with a direct parameter.
1258 1263
1259 1264 * IPython/ultraTB.py (_fixed_getinnerframes): remove debug assert which
1260 1265 could be triggered in certain cases and cause the traceback
1261 1266 printer not to work.
1262 1267
1263 1268 2006-01-07 Fernando Perez <Fernando.Perez@colorado.edu>
1264 1269
1265 1270 * IPython/iplib.py (_should_recompile): Small fix, closes
1266 1271 http://www.scipy.net/roundup/ipython/issue48. Patch by Scott.
1267 1272
1268 1273 2006-01-04 Fernando Perez <Fernando.Perez@colorado.edu>
1269 1274
1270 1275 * IPython/Shell.py (IPShellGTK.mainloop): fix bug in the GTK
1271 1276 backend for matplotlib (100% cpu utiliziation). Thanks to Charlie
1272 1277 Moad for help with tracking it down.
1273 1278
1274 1279 * IPython/iplib.py (handle_auto): fix autocall handling for
1275 1280 objects which support BOTH __getitem__ and __call__ (so that f [x]
1276 1281 is left alone, instead of becoming f([x]) automatically).
1277 1282
1278 1283 * IPython/Magic.py (magic_cd): fix crash when cd -b was used.
1279 1284 Ville's patch.
1280 1285
1281 1286 2006-01-03 Fernando Perez <Fernando.Perez@colorado.edu>
1282 1287
1283 1288 * IPython/iplib.py (handle_auto): changed autocall semantics to
1284 1289 include 'smart' mode, where the autocall transformation is NOT
1285 1290 applied if there are no arguments on the line. This allows you to
1286 1291 just type 'foo' if foo is a callable to see its internal form,
1287 1292 instead of having it called with no arguments (typically a
1288 1293 mistake). The old 'full' autocall still exists: for that, you
1289 1294 need to set the 'autocall' parameter to 2 in your ipythonrc file.
1290 1295
1291 1296 * IPython/completer.py (Completer.attr_matches): add
1292 1297 tab-completion support for Enthoughts' traits. After a report by
1293 1298 Arnd and a patch by Prabhu.
1294 1299
1295 1300 2006-01-02 Fernando Perez <Fernando.Perez@colorado.edu>
1296 1301
1297 1302 * IPython/ultraTB.py (_fixed_getinnerframes): added Alex
1298 1303 Schmolck's patch to fix inspect.getinnerframes().
1299 1304
1300 1305 * IPython/iplib.py (InteractiveShell.__init__): significant fixes
1301 1306 for embedded instances, regarding handling of namespaces and items
1302 1307 added to the __builtin__ one. Multiple embedded instances and
1303 1308 recursive embeddings should work better now (though I'm not sure
1304 1309 I've got all the corner cases fixed, that code is a bit of a brain
1305 1310 twister).
1306 1311
1307 1312 * IPython/Magic.py (magic_edit): added support to edit in-memory
1308 1313 macros (automatically creates the necessary temp files). %edit
1309 1314 also doesn't return the file contents anymore, it's just noise.
1310 1315
1311 1316 * IPython/completer.py (Completer.attr_matches): revert change to
1312 1317 complete only on attributes listed in __all__. I realized it
1313 1318 cripples the tab-completion system as a tool for exploring the
1314 1319 internals of unknown libraries (it renders any non-__all__
1315 1320 attribute off-limits). I got bit by this when trying to see
1316 1321 something inside the dis module.
1317 1322
1318 1323 2005-12-31 Fernando Perez <Fernando.Perez@colorado.edu>
1319 1324
1320 1325 * IPython/iplib.py (InteractiveShell.__init__): add .meta
1321 1326 namespace for users and extension writers to hold data in. This
1322 1327 follows the discussion in
1323 1328 http://projects.scipy.org/ipython/ipython/wiki/RefactoringIPython.
1324 1329
1325 1330 * IPython/completer.py (IPCompleter.complete): small patch to help
1326 1331 tab-completion under Emacs, after a suggestion by John Barnard
1327 1332 <barnarj-AT-ccf.org>.
1328 1333
1329 1334 * IPython/Magic.py (Magic.extract_input_slices): added support for
1330 1335 the slice notation in magics to use N-M to represent numbers N...M
1331 1336 (closed endpoints). This is used by %macro and %save.
1332 1337
1333 1338 * IPython/completer.py (Completer.attr_matches): for modules which
1334 1339 define __all__, complete only on those. After a patch by Jeffrey
1335 1340 Collins <jcollins_boulder-AT-earthlink.net>. Also, clean up and
1336 1341 speed up this routine.
1337 1342
1338 1343 * IPython/Logger.py (Logger.log): fix a history handling bug. I
1339 1344 don't know if this is the end of it, but the behavior now is
1340 1345 certainly much more correct. Note that coupled with macros,
1341 1346 slightly surprising (at first) behavior may occur: a macro will in
1342 1347 general expand to multiple lines of input, so upon exiting, the
1343 1348 in/out counters will both be bumped by the corresponding amount
1344 1349 (as if the macro's contents had been typed interactively). Typing
1345 1350 %hist will reveal the intermediate (silently processed) lines.
1346 1351
1347 1352 * IPython/Magic.py (magic_run): fix a subtle bug which could cause
1348 1353 pickle to fail (%run was overwriting __main__ and not restoring
1349 1354 it, but pickle relies on __main__ to operate).
1350 1355
1351 1356 * IPython/iplib.py (InteractiveShell): fix pdb calling: I'm now
1352 1357 using properties, but forgot to make the main InteractiveShell
1353 1358 class a new-style class. Properties fail silently, and
1354 1359 mysteriously, with old-style class (getters work, but
1355 1360 setters don't do anything).
1356 1361
1357 1362 2005-12-30 Fernando Perez <Fernando.Perez@colorado.edu>
1358 1363
1359 1364 * IPython/Magic.py (magic_history): fix history reporting bug (I
1360 1365 know some nasties are still there, I just can't seem to find a
1361 1366 reproducible test case to track them down; the input history is
1362 1367 falling out of sync...)
1363 1368
1364 1369 * IPython/iplib.py (handle_shell_escape): fix bug where both
1365 1370 aliases and system accesses where broken for indented code (such
1366 1371 as loops).
1367 1372
1368 1373 * IPython/genutils.py (shell): fix small but critical bug for
1369 1374 win32 system access.
1370 1375
1371 1376 2005-12-29 Fernando Perez <Fernando.Perez@colorado.edu>
1372 1377
1373 1378 * IPython/iplib.py (showtraceback): remove use of the
1374 1379 sys.last_{type/value/traceback} structures, which are non
1375 1380 thread-safe.
1376 1381 (_prefilter): change control flow to ensure that we NEVER
1377 1382 introspect objects when autocall is off. This will guarantee that
1378 1383 having an input line of the form 'x.y', where access to attribute
1379 1384 'y' has side effects, doesn't trigger the side effect TWICE. It
1380 1385 is important to note that, with autocall on, these side effects
1381 1386 can still happen.
1382 1387 (ipsystem): new builtin, to complete the ip{magic/alias/system}
1383 1388 trio. IPython offers these three kinds of special calls which are
1384 1389 not python code, and it's a good thing to have their call method
1385 1390 be accessible as pure python functions (not just special syntax at
1386 1391 the command line). It gives us a better internal implementation
1387 1392 structure, as well as exposing these for user scripting more
1388 1393 cleanly.
1389 1394
1390 1395 * IPython/macro.py (Macro.__init__): moved macros to a standalone
1391 1396 file. Now that they'll be more likely to be used with the
1392 1397 persistance system (%store), I want to make sure their module path
1393 1398 doesn't change in the future, so that we don't break things for
1394 1399 users' persisted data.
1395 1400
1396 1401 * IPython/iplib.py (autoindent_update): move indentation
1397 1402 management into the _text_ processing loop, not the keyboard
1398 1403 interactive one. This is necessary to correctly process non-typed
1399 1404 multiline input (such as macros).
1400 1405
1401 1406 * IPython/Magic.py (Magic.format_latex): patch by Stefan van der
1402 1407 Walt <stefan-AT-sun.ac.za> to fix latex formatting of docstrings,
1403 1408 which was producing problems in the resulting manual.
1404 1409 (magic_whos): improve reporting of instances (show their class,
1405 1410 instead of simply printing 'instance' which isn't terribly
1406 1411 informative).
1407 1412
1408 1413 * IPython/genutils.py (shell): commit Jorgen Stenarson's patch
1409 1414 (minor mods) to support network shares under win32.
1410 1415
1411 1416 * IPython/winconsole.py (get_console_size): add new winconsole
1412 1417 module and fixes to page_dumb() to improve its behavior under
1413 1418 win32. Contributed by Alexander Belchenko <bialix-AT-ukr.net>.
1414 1419
1415 1420 * IPython/Magic.py (Macro): simplified Macro class to just
1416 1421 subclass list. We've had only 2.2 compatibility for a very long
1417 1422 time, yet I was still avoiding subclassing the builtin types. No
1418 1423 more (I'm also starting to use properties, though I won't shift to
1419 1424 2.3-specific features quite yet).
1420 1425 (magic_store): added Ville's patch for lightweight variable
1421 1426 persistence, after a request on the user list by Matt Wilkie
1422 1427 <maphew-AT-gmail.com>. The new %store magic's docstring has full
1423 1428 details.
1424 1429
1425 1430 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1426 1431 changed the default logfile name from 'ipython.log' to
1427 1432 'ipython_log.py'. These logs are real python files, and now that
1428 1433 we have much better multiline support, people are more likely to
1429 1434 want to use them as such. Might as well name them correctly.
1430 1435
1431 1436 * IPython/Magic.py: substantial cleanup. While we can't stop
1432 1437 using magics as mixins, due to the existing customizations 'out
1433 1438 there' which rely on the mixin naming conventions, at least I
1434 1439 cleaned out all cross-class name usage. So once we are OK with
1435 1440 breaking compatibility, the two systems can be separated.
1436 1441
1437 1442 * IPython/Logger.py: major cleanup. This one is NOT a mixin
1438 1443 anymore, and the class is a fair bit less hideous as well. New
1439 1444 features were also introduced: timestamping of input, and logging
1440 1445 of output results. These are user-visible with the -t and -o
1441 1446 options to %logstart. Closes
1442 1447 http://www.scipy.net/roundup/ipython/issue11 and a request by
1443 1448 William Stein (SAGE developer - http://modular.ucsd.edu/sage).
1444 1449
1445 1450 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
1446 1451
1447 1452 * IPython/iplib.py (handle_shell_escape): add Ville's patch to
1448 1453 better handle backslashes in paths. See the thread 'More Windows
1449 1454 questions part 2 - \/ characters revisited' on the iypthon user
1450 1455 list:
1451 1456 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
1452 1457
1453 1458 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
1454 1459
1455 1460 (InteractiveShell.__init__): change threaded shells to not use the
1456 1461 ipython crash handler. This was causing more problems than not,
1457 1462 as exceptions in the main thread (GUI code, typically) would
1458 1463 always show up as a 'crash', when they really weren't.
1459 1464
1460 1465 The colors and exception mode commands (%colors/%xmode) have been
1461 1466 synchronized to also take this into account, so users can get
1462 1467 verbose exceptions for their threaded code as well. I also added
1463 1468 support for activating pdb inside this exception handler as well,
1464 1469 so now GUI authors can use IPython's enhanced pdb at runtime.
1465 1470
1466 1471 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
1467 1472 true by default, and add it to the shipped ipythonrc file. Since
1468 1473 this asks the user before proceeding, I think it's OK to make it
1469 1474 true by default.
1470 1475
1471 1476 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
1472 1477 of the previous special-casing of input in the eval loop. I think
1473 1478 this is cleaner, as they really are commands and shouldn't have
1474 1479 a special role in the middle of the core code.
1475 1480
1476 1481 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
1477 1482
1478 1483 * IPython/iplib.py (edit_syntax_error): added support for
1479 1484 automatically reopening the editor if the file had a syntax error
1480 1485 in it. Thanks to scottt who provided the patch at:
1481 1486 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
1482 1487 version committed).
1483 1488
1484 1489 * IPython/iplib.py (handle_normal): add suport for multi-line
1485 1490 input with emtpy lines. This fixes
1486 1491 http://www.scipy.net/roundup/ipython/issue43 and a similar
1487 1492 discussion on the user list.
1488 1493
1489 1494 WARNING: a behavior change is necessarily introduced to support
1490 1495 blank lines: now a single blank line with whitespace does NOT
1491 1496 break the input loop, which means that when autoindent is on, by
1492 1497 default hitting return on the next (indented) line does NOT exit.
1493 1498
1494 1499 Instead, to exit a multiline input you can either have:
1495 1500
1496 1501 - TWO whitespace lines (just hit return again), or
1497 1502 - a single whitespace line of a different length than provided
1498 1503 by the autoindent (add or remove a space).
1499 1504
1500 1505 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
1501 1506 module to better organize all readline-related functionality.
1502 1507 I've deleted FlexCompleter and put all completion clases here.
1503 1508
1504 1509 * IPython/iplib.py (raw_input): improve indentation management.
1505 1510 It is now possible to paste indented code with autoindent on, and
1506 1511 the code is interpreted correctly (though it still looks bad on
1507 1512 screen, due to the line-oriented nature of ipython).
1508 1513 (MagicCompleter.complete): change behavior so that a TAB key on an
1509 1514 otherwise empty line actually inserts a tab, instead of completing
1510 1515 on the entire global namespace. This makes it easier to use the
1511 1516 TAB key for indentation. After a request by Hans Meine
1512 1517 <hans_meine-AT-gmx.net>
1513 1518 (_prefilter): add support so that typing plain 'exit' or 'quit'
1514 1519 does a sensible thing. Originally I tried to deviate as little as
1515 1520 possible from the default python behavior, but even that one may
1516 1521 change in this direction (thread on python-dev to that effect).
1517 1522 Regardless, ipython should do the right thing even if CPython's
1518 1523 '>>>' prompt doesn't.
1519 1524 (InteractiveShell): removed subclassing code.InteractiveConsole
1520 1525 class. By now we'd overridden just about all of its methods: I've
1521 1526 copied the remaining two over, and now ipython is a standalone
1522 1527 class. This will provide a clearer picture for the chainsaw
1523 1528 branch refactoring.
1524 1529
1525 1530 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
1526 1531
1527 1532 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
1528 1533 failures for objects which break when dir() is called on them.
1529 1534
1530 1535 * IPython/FlexCompleter.py (Completer.__init__): Added support for
1531 1536 distinct local and global namespaces in the completer API. This
1532 1537 change allows us to properly handle completion with distinct
1533 1538 scopes, including in embedded instances (this had never really
1534 1539 worked correctly).
1535 1540
1536 1541 Note: this introduces a change in the constructor for
1537 1542 MagicCompleter, as a new global_namespace parameter is now the
1538 1543 second argument (the others were bumped one position).
1539 1544
1540 1545 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
1541 1546
1542 1547 * IPython/iplib.py (embed_mainloop): fix tab-completion in
1543 1548 embedded instances (which can be done now thanks to Vivian's
1544 1549 frame-handling fixes for pdb).
1545 1550 (InteractiveShell.__init__): Fix namespace handling problem in
1546 1551 embedded instances. We were overwriting __main__ unconditionally,
1547 1552 and this should only be done for 'full' (non-embedded) IPython;
1548 1553 embedded instances must respect the caller's __main__. Thanks to
1549 1554 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
1550 1555
1551 1556 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
1552 1557
1553 1558 * setup.py: added download_url to setup(). This registers the
1554 1559 download address at PyPI, which is not only useful to humans
1555 1560 browsing the site, but is also picked up by setuptools (the Eggs
1556 1561 machinery). Thanks to Ville and R. Kern for the info/discussion
1557 1562 on this.
1558 1563
1559 1564 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
1560 1565
1561 1566 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
1562 1567 This brings a lot of nice functionality to the pdb mode, which now
1563 1568 has tab-completion, syntax highlighting, and better stack handling
1564 1569 than before. Many thanks to Vivian De Smedt
1565 1570 <vivian-AT-vdesmedt.com> for the original patches.
1566 1571
1567 1572 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
1568 1573
1569 1574 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
1570 1575 sequence to consistently accept the banner argument. The
1571 1576 inconsistency was tripping SAGE, thanks to Gary Zablackis
1572 1577 <gzabl-AT-yahoo.com> for the report.
1573 1578
1574 1579 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
1575 1580
1576 1581 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1577 1582 Fix bug where a naked 'alias' call in the ipythonrc file would
1578 1583 cause a crash. Bug reported by Jorgen Stenarson.
1579 1584
1580 1585 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
1581 1586
1582 1587 * IPython/ipmaker.py (make_IPython): cleanups which should improve
1583 1588 startup time.
1584 1589
1585 1590 * IPython/iplib.py (runcode): my globals 'fix' for embedded
1586 1591 instances had introduced a bug with globals in normal code. Now
1587 1592 it's working in all cases.
1588 1593
1589 1594 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
1590 1595 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
1591 1596 has been introduced to set the default case sensitivity of the
1592 1597 searches. Users can still select either mode at runtime on a
1593 1598 per-search basis.
1594 1599
1595 1600 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
1596 1601
1597 1602 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
1598 1603 attributes in wildcard searches for subclasses. Modified version
1599 1604 of a patch by Jorgen.
1600 1605
1601 1606 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
1602 1607
1603 1608 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
1604 1609 embedded instances. I added a user_global_ns attribute to the
1605 1610 InteractiveShell class to handle this.
1606 1611
1607 1612 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
1608 1613
1609 1614 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
1610 1615 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
1611 1616 (reported under win32, but may happen also in other platforms).
1612 1617 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
1613 1618
1614 1619 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
1615 1620
1616 1621 * IPython/Magic.py (magic_psearch): new support for wildcard
1617 1622 patterns. Now, typing ?a*b will list all names which begin with a
1618 1623 and end in b, for example. The %psearch magic has full
1619 1624 docstrings. Many thanks to JΓΆrgen Stenarson
1620 1625 <jorgen.stenarson-AT-bostream.nu>, author of the patches
1621 1626 implementing this functionality.
1622 1627
1623 1628 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
1624 1629
1625 1630 * Manual: fixed long-standing annoyance of double-dashes (as in
1626 1631 --prefix=~, for example) being stripped in the HTML version. This
1627 1632 is a latex2html bug, but a workaround was provided. Many thanks
1628 1633 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
1629 1634 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
1630 1635 rolling. This seemingly small issue had tripped a number of users
1631 1636 when first installing, so I'm glad to see it gone.
1632 1637
1633 1638 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
1634 1639
1635 1640 * IPython/Extensions/numeric_formats.py: fix missing import,
1636 1641 reported by Stephen Walton.
1637 1642
1638 1643 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
1639 1644
1640 1645 * IPython/demo.py: finish demo module, fully documented now.
1641 1646
1642 1647 * IPython/genutils.py (file_read): simple little utility to read a
1643 1648 file and ensure it's closed afterwards.
1644 1649
1645 1650 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
1646 1651
1647 1652 * IPython/demo.py (Demo.__init__): added support for individually
1648 1653 tagging blocks for automatic execution.
1649 1654
1650 1655 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
1651 1656 syntax-highlighted python sources, requested by John.
1652 1657
1653 1658 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
1654 1659
1655 1660 * IPython/demo.py (Demo.again): fix bug where again() blocks after
1656 1661 finishing.
1657 1662
1658 1663 * IPython/genutils.py (shlex_split): moved from Magic to here,
1659 1664 where all 2.2 compatibility stuff lives. I needed it for demo.py.
1660 1665
1661 1666 * IPython/demo.py (Demo.__init__): added support for silent
1662 1667 blocks, improved marks as regexps, docstrings written.
1663 1668 (Demo.__init__): better docstring, added support for sys.argv.
1664 1669
1665 1670 * IPython/genutils.py (marquee): little utility used by the demo
1666 1671 code, handy in general.
1667 1672
1668 1673 * IPython/demo.py (Demo.__init__): new class for interactive
1669 1674 demos. Not documented yet, I just wrote it in a hurry for
1670 1675 scipy'05. Will docstring later.
1671 1676
1672 1677 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
1673 1678
1674 1679 * IPython/Shell.py (sigint_handler): Drastic simplification which
1675 1680 also seems to make Ctrl-C work correctly across threads! This is
1676 1681 so simple, that I can't beleive I'd missed it before. Needs more
1677 1682 testing, though.
1678 1683 (KBINT): Never mind, revert changes. I'm sure I'd tried something
1679 1684 like this before...
1680 1685
1681 1686 * IPython/genutils.py (get_home_dir): add protection against
1682 1687 non-dirs in win32 registry.
1683 1688
1684 1689 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
1685 1690 bug where dict was mutated while iterating (pysh crash).
1686 1691
1687 1692 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
1688 1693
1689 1694 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
1690 1695 spurious newlines added by this routine. After a report by
1691 1696 F. Mantegazza.
1692 1697
1693 1698 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
1694 1699
1695 1700 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
1696 1701 calls. These were a leftover from the GTK 1.x days, and can cause
1697 1702 problems in certain cases (after a report by John Hunter).
1698 1703
1699 1704 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
1700 1705 os.getcwd() fails at init time. Thanks to patch from David Remahl
1701 1706 <chmod007-AT-mac.com>.
1702 1707 (InteractiveShell.__init__): prevent certain special magics from
1703 1708 being shadowed by aliases. Closes
1704 1709 http://www.scipy.net/roundup/ipython/issue41.
1705 1710
1706 1711 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
1707 1712
1708 1713 * IPython/iplib.py (InteractiveShell.complete): Added new
1709 1714 top-level completion method to expose the completion mechanism
1710 1715 beyond readline-based environments.
1711 1716
1712 1717 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
1713 1718
1714 1719 * tools/ipsvnc (svnversion): fix svnversion capture.
1715 1720
1716 1721 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
1717 1722 attribute to self, which was missing. Before, it was set by a
1718 1723 routine which in certain cases wasn't being called, so the
1719 1724 instance could end up missing the attribute. This caused a crash.
1720 1725 Closes http://www.scipy.net/roundup/ipython/issue40.
1721 1726
1722 1727 2005-08-16 Fernando Perez <fperez@colorado.edu>
1723 1728
1724 1729 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
1725 1730 contains non-string attribute. Closes
1726 1731 http://www.scipy.net/roundup/ipython/issue38.
1727 1732
1728 1733 2005-08-14 Fernando Perez <fperez@colorado.edu>
1729 1734
1730 1735 * tools/ipsvnc: Minor improvements, to add changeset info.
1731 1736
1732 1737 2005-08-12 Fernando Perez <fperez@colorado.edu>
1733 1738
1734 1739 * IPython/iplib.py (runsource): remove self.code_to_run_src
1735 1740 attribute. I realized this is nothing more than
1736 1741 '\n'.join(self.buffer), and having the same data in two different
1737 1742 places is just asking for synchronization bugs. This may impact
1738 1743 people who have custom exception handlers, so I need to warn
1739 1744 ipython-dev about it (F. Mantegazza may use them).
1740 1745
1741 1746 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
1742 1747
1743 1748 * IPython/genutils.py: fix 2.2 compatibility (generators)
1744 1749
1745 1750 2005-07-18 Fernando Perez <fperez@colorado.edu>
1746 1751
1747 1752 * IPython/genutils.py (get_home_dir): fix to help users with
1748 1753 invalid $HOME under win32.
1749 1754
1750 1755 2005-07-17 Fernando Perez <fperez@colorado.edu>
1751 1756
1752 1757 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
1753 1758 some old hacks and clean up a bit other routines; code should be
1754 1759 simpler and a bit faster.
1755 1760
1756 1761 * IPython/iplib.py (interact): removed some last-resort attempts
1757 1762 to survive broken stdout/stderr. That code was only making it
1758 1763 harder to abstract out the i/o (necessary for gui integration),
1759 1764 and the crashes it could prevent were extremely rare in practice
1760 1765 (besides being fully user-induced in a pretty violent manner).
1761 1766
1762 1767 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
1763 1768 Nothing major yet, but the code is simpler to read; this should
1764 1769 make it easier to do more serious modifications in the future.
1765 1770
1766 1771 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
1767 1772 which broke in .15 (thanks to a report by Ville).
1768 1773
1769 1774 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
1770 1775 be quite correct, I know next to nothing about unicode). This
1771 1776 will allow unicode strings to be used in prompts, amongst other
1772 1777 cases. It also will prevent ipython from crashing when unicode
1773 1778 shows up unexpectedly in many places. If ascii encoding fails, we
1774 1779 assume utf_8. Currently the encoding is not a user-visible
1775 1780 setting, though it could be made so if there is demand for it.
1776 1781
1777 1782 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
1778 1783
1779 1784 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
1780 1785
1781 1786 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
1782 1787
1783 1788 * IPython/genutils.py: Add 2.2 compatibility here, so all other
1784 1789 code can work transparently for 2.2/2.3.
1785 1790
1786 1791 2005-07-16 Fernando Perez <fperez@colorado.edu>
1787 1792
1788 1793 * IPython/ultraTB.py (ExceptionColors): Make a global variable
1789 1794 out of the color scheme table used for coloring exception
1790 1795 tracebacks. This allows user code to add new schemes at runtime.
1791 1796 This is a minimally modified version of the patch at
1792 1797 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
1793 1798 for the contribution.
1794 1799
1795 1800 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
1796 1801 slightly modified version of the patch in
1797 1802 http://www.scipy.net/roundup/ipython/issue34, which also allows me
1798 1803 to remove the previous try/except solution (which was costlier).
1799 1804 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
1800 1805
1801 1806 2005-06-08 Fernando Perez <fperez@colorado.edu>
1802 1807
1803 1808 * IPython/iplib.py (write/write_err): Add methods to abstract all
1804 1809 I/O a bit more.
1805 1810
1806 1811 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
1807 1812 warning, reported by Aric Hagberg, fix by JD Hunter.
1808 1813
1809 1814 2005-06-02 *** Released version 0.6.15
1810 1815
1811 1816 2005-06-01 Fernando Perez <fperez@colorado.edu>
1812 1817
1813 1818 * IPython/iplib.py (MagicCompleter.file_matches): Fix
1814 1819 tab-completion of filenames within open-quoted strings. Note that
1815 1820 this requires that in ~/.ipython/ipythonrc, users change the
1816 1821 readline delimiters configuration to read:
1817 1822
1818 1823 readline_remove_delims -/~
1819 1824
1820 1825
1821 1826 2005-05-31 *** Released version 0.6.14
1822 1827
1823 1828 2005-05-29 Fernando Perez <fperez@colorado.edu>
1824 1829
1825 1830 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
1826 1831 with files not on the filesystem. Reported by Eliyahu Sandler
1827 1832 <eli@gondolin.net>
1828 1833
1829 1834 2005-05-22 Fernando Perez <fperez@colorado.edu>
1830 1835
1831 1836 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
1832 1837 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
1833 1838
1834 1839 2005-05-19 Fernando Perez <fperez@colorado.edu>
1835 1840
1836 1841 * IPython/iplib.py (safe_execfile): close a file which could be
1837 1842 left open (causing problems in win32, which locks open files).
1838 1843 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
1839 1844
1840 1845 2005-05-18 Fernando Perez <fperez@colorado.edu>
1841 1846
1842 1847 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
1843 1848 keyword arguments correctly to safe_execfile().
1844 1849
1845 1850 2005-05-13 Fernando Perez <fperez@colorado.edu>
1846 1851
1847 1852 * ipython.1: Added info about Qt to manpage, and threads warning
1848 1853 to usage page (invoked with --help).
1849 1854
1850 1855 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
1851 1856 new matcher (it goes at the end of the priority list) to do
1852 1857 tab-completion on named function arguments. Submitted by George
1853 1858 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
1854 1859 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
1855 1860 for more details.
1856 1861
1857 1862 * IPython/Magic.py (magic_run): Added new -e flag to ignore
1858 1863 SystemExit exceptions in the script being run. Thanks to a report
1859 1864 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
1860 1865 producing very annoying behavior when running unit tests.
1861 1866
1862 1867 2005-05-12 Fernando Perez <fperez@colorado.edu>
1863 1868
1864 1869 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
1865 1870 which I'd broken (again) due to a changed regexp. In the process,
1866 1871 added ';' as an escape to auto-quote the whole line without
1867 1872 splitting its arguments. Thanks to a report by Jerry McRae
1868 1873 <qrs0xyc02-AT-sneakemail.com>.
1869 1874
1870 1875 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
1871 1876 possible crashes caused by a TokenError. Reported by Ed Schofield
1872 1877 <schofield-AT-ftw.at>.
1873 1878
1874 1879 2005-05-06 Fernando Perez <fperez@colorado.edu>
1875 1880
1876 1881 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
1877 1882
1878 1883 2005-04-29 Fernando Perez <fperez@colorado.edu>
1879 1884
1880 1885 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
1881 1886 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
1882 1887 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
1883 1888 which provides support for Qt interactive usage (similar to the
1884 1889 existing one for WX and GTK). This had been often requested.
1885 1890
1886 1891 2005-04-14 *** Released version 0.6.13
1887 1892
1888 1893 2005-04-08 Fernando Perez <fperez@colorado.edu>
1889 1894
1890 1895 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
1891 1896 from _ofind, which gets called on almost every input line. Now,
1892 1897 we only try to get docstrings if they are actually going to be
1893 1898 used (the overhead of fetching unnecessary docstrings can be
1894 1899 noticeable for certain objects, such as Pyro proxies).
1895 1900
1896 1901 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
1897 1902 for completers. For some reason I had been passing them the state
1898 1903 variable, which completers never actually need, and was in
1899 1904 conflict with the rlcompleter API. Custom completers ONLY need to
1900 1905 take the text parameter.
1901 1906
1902 1907 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
1903 1908 work correctly in pysh. I've also moved all the logic which used
1904 1909 to be in pysh.py here, which will prevent problems with future
1905 1910 upgrades. However, this time I must warn users to update their
1906 1911 pysh profile to include the line
1907 1912
1908 1913 import_all IPython.Extensions.InterpreterExec
1909 1914
1910 1915 because otherwise things won't work for them. They MUST also
1911 1916 delete pysh.py and the line
1912 1917
1913 1918 execfile pysh.py
1914 1919
1915 1920 from their ipythonrc-pysh.
1916 1921
1917 1922 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
1918 1923 robust in the face of objects whose dir() returns non-strings
1919 1924 (which it shouldn't, but some broken libs like ITK do). Thanks to
1920 1925 a patch by John Hunter (implemented differently, though). Also
1921 1926 minor improvements by using .extend instead of + on lists.
1922 1927
1923 1928 * pysh.py:
1924 1929
1925 1930 2005-04-06 Fernando Perez <fperez@colorado.edu>
1926 1931
1927 1932 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
1928 1933 by default, so that all users benefit from it. Those who don't
1929 1934 want it can still turn it off.
1930 1935
1931 1936 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
1932 1937 config file, I'd forgotten about this, so users were getting it
1933 1938 off by default.
1934 1939
1935 1940 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
1936 1941 consistency. Now magics can be called in multiline statements,
1937 1942 and python variables can be expanded in magic calls via $var.
1938 1943 This makes the magic system behave just like aliases or !system
1939 1944 calls.
1940 1945
1941 1946 2005-03-28 Fernando Perez <fperez@colorado.edu>
1942 1947
1943 1948 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
1944 1949 expensive string additions for building command. Add support for
1945 1950 trailing ';' when autocall is used.
1946 1951
1947 1952 2005-03-26 Fernando Perez <fperez@colorado.edu>
1948 1953
1949 1954 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
1950 1955 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
1951 1956 ipython.el robust against prompts with any number of spaces
1952 1957 (including 0) after the ':' character.
1953 1958
1954 1959 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
1955 1960 continuation prompt, which misled users to think the line was
1956 1961 already indented. Closes debian Bug#300847, reported to me by
1957 1962 Norbert Tretkowski <tretkowski-AT-inittab.de>.
1958 1963
1959 1964 2005-03-23 Fernando Perez <fperez@colorado.edu>
1960 1965
1961 1966 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
1962 1967 properly aligned if they have embedded newlines.
1963 1968
1964 1969 * IPython/iplib.py (runlines): Add a public method to expose
1965 1970 IPython's code execution machinery, so that users can run strings
1966 1971 as if they had been typed at the prompt interactively.
1967 1972 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
1968 1973 methods which can call the system shell, but with python variable
1969 1974 expansion. The three such methods are: __IPYTHON__.system,
1970 1975 .getoutput and .getoutputerror. These need to be documented in a
1971 1976 'public API' section (to be written) of the manual.
1972 1977
1973 1978 2005-03-20 Fernando Perez <fperez@colorado.edu>
1974 1979
1975 1980 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
1976 1981 for custom exception handling. This is quite powerful, and it
1977 1982 allows for user-installable exception handlers which can trap
1978 1983 custom exceptions at runtime and treat them separately from
1979 1984 IPython's default mechanisms. At the request of FrΓ©dΓ©ric
1980 1985 Mantegazza <mantegazza-AT-ill.fr>.
1981 1986 (InteractiveShell.set_custom_completer): public API function to
1982 1987 add new completers at runtime.
1983 1988
1984 1989 2005-03-19 Fernando Perez <fperez@colorado.edu>
1985 1990
1986 1991 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
1987 1992 allow objects which provide their docstrings via non-standard
1988 1993 mechanisms (like Pyro proxies) to still be inspected by ipython's
1989 1994 ? system.
1990 1995
1991 1996 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
1992 1997 automatic capture system. I tried quite hard to make it work
1993 1998 reliably, and simply failed. I tried many combinations with the
1994 1999 subprocess module, but eventually nothing worked in all needed
1995 2000 cases (not blocking stdin for the child, duplicating stdout
1996 2001 without blocking, etc). The new %sc/%sx still do capture to these
1997 2002 magical list/string objects which make shell use much more
1998 2003 conveninent, so not all is lost.
1999 2004
2000 2005 XXX - FIX MANUAL for the change above!
2001 2006
2002 2007 (runsource): I copied code.py's runsource() into ipython to modify
2003 2008 it a bit. Now the code object and source to be executed are
2004 2009 stored in ipython. This makes this info accessible to third-party
2005 2010 tools, like custom exception handlers. After a request by FrΓ©dΓ©ric
2006 2011 Mantegazza <mantegazza-AT-ill.fr>.
2007 2012
2008 2013 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
2009 2014 history-search via readline (like C-p/C-n). I'd wanted this for a
2010 2015 long time, but only recently found out how to do it. For users
2011 2016 who already have their ipythonrc files made and want this, just
2012 2017 add:
2013 2018
2014 2019 readline_parse_and_bind "\e[A": history-search-backward
2015 2020 readline_parse_and_bind "\e[B": history-search-forward
2016 2021
2017 2022 2005-03-18 Fernando Perez <fperez@colorado.edu>
2018 2023
2019 2024 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
2020 2025 LSString and SList classes which allow transparent conversions
2021 2026 between list mode and whitespace-separated string.
2022 2027 (magic_r): Fix recursion problem in %r.
2023 2028
2024 2029 * IPython/genutils.py (LSString): New class to be used for
2025 2030 automatic storage of the results of all alias/system calls in _o
2026 2031 and _e (stdout/err). These provide a .l/.list attribute which
2027 2032 does automatic splitting on newlines. This means that for most
2028 2033 uses, you'll never need to do capturing of output with %sc/%sx
2029 2034 anymore, since ipython keeps this always done for you. Note that
2030 2035 only the LAST results are stored, the _o/e variables are
2031 2036 overwritten on each call. If you need to save their contents
2032 2037 further, simply bind them to any other name.
2033 2038
2034 2039 2005-03-17 Fernando Perez <fperez@colorado.edu>
2035 2040
2036 2041 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
2037 2042 prompt namespace handling.
2038 2043
2039 2044 2005-03-16 Fernando Perez <fperez@colorado.edu>
2040 2045
2041 2046 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
2042 2047 classic prompts to be '>>> ' (final space was missing, and it
2043 2048 trips the emacs python mode).
2044 2049 (BasePrompt.__str__): Added safe support for dynamic prompt
2045 2050 strings. Now you can set your prompt string to be '$x', and the
2046 2051 value of x will be printed from your interactive namespace. The
2047 2052 interpolation syntax includes the full Itpl support, so
2048 2053 ${foo()+x+bar()} is a valid prompt string now, and the function
2049 2054 calls will be made at runtime.
2050 2055
2051 2056 2005-03-15 Fernando Perez <fperez@colorado.edu>
2052 2057
2053 2058 * IPython/Magic.py (magic_history): renamed %hist to %history, to
2054 2059 avoid name clashes in pylab. %hist still works, it just forwards
2055 2060 the call to %history.
2056 2061
2057 2062 2005-03-02 *** Released version 0.6.12
2058 2063
2059 2064 2005-03-02 Fernando Perez <fperez@colorado.edu>
2060 2065
2061 2066 * IPython/iplib.py (handle_magic): log magic calls properly as
2062 2067 ipmagic() function calls.
2063 2068
2064 2069 * IPython/Magic.py (magic_time): Improved %time to support
2065 2070 statements and provide wall-clock as well as CPU time.
2066 2071
2067 2072 2005-02-27 Fernando Perez <fperez@colorado.edu>
2068 2073
2069 2074 * IPython/hooks.py: New hooks module, to expose user-modifiable
2070 2075 IPython functionality in a clean manner. For now only the editor
2071 2076 hook is actually written, and other thigns which I intend to turn
2072 2077 into proper hooks aren't yet there. The display and prefilter
2073 2078 stuff, for example, should be hooks. But at least now the
2074 2079 framework is in place, and the rest can be moved here with more
2075 2080 time later. IPython had had a .hooks variable for a long time for
2076 2081 this purpose, but I'd never actually used it for anything.
2077 2082
2078 2083 2005-02-26 Fernando Perez <fperez@colorado.edu>
2079 2084
2080 2085 * IPython/ipmaker.py (make_IPython): make the default ipython
2081 2086 directory be called _ipython under win32, to follow more the
2082 2087 naming peculiarities of that platform (where buggy software like
2083 2088 Visual Sourcesafe breaks with .named directories). Reported by
2084 2089 Ville Vainio.
2085 2090
2086 2091 2005-02-23 Fernando Perez <fperez@colorado.edu>
2087 2092
2088 2093 * IPython/iplib.py (InteractiveShell.__init__): removed a few
2089 2094 auto_aliases for win32 which were causing problems. Users can
2090 2095 define the ones they personally like.
2091 2096
2092 2097 2005-02-21 Fernando Perez <fperez@colorado.edu>
2093 2098
2094 2099 * IPython/Magic.py (magic_time): new magic to time execution of
2095 2100 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
2096 2101
2097 2102 2005-02-19 Fernando Perez <fperez@colorado.edu>
2098 2103
2099 2104 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
2100 2105 into keys (for prompts, for example).
2101 2106
2102 2107 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
2103 2108 prompts in case users want them. This introduces a small behavior
2104 2109 change: ipython does not automatically add a space to all prompts
2105 2110 anymore. To get the old prompts with a space, users should add it
2106 2111 manually to their ipythonrc file, so for example prompt_in1 should
2107 2112 now read 'In [\#]: ' instead of 'In [\#]:'.
2108 2113 (BasePrompt.__init__): New option prompts_pad_left (only in rc
2109 2114 file) to control left-padding of secondary prompts.
2110 2115
2111 2116 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
2112 2117 the profiler can't be imported. Fix for Debian, which removed
2113 2118 profile.py because of License issues. I applied a slightly
2114 2119 modified version of the original Debian patch at
2115 2120 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
2116 2121
2117 2122 2005-02-17 Fernando Perez <fperez@colorado.edu>
2118 2123
2119 2124 * IPython/genutils.py (native_line_ends): Fix bug which would
2120 2125 cause improper line-ends under win32 b/c I was not opening files
2121 2126 in binary mode. Bug report and fix thanks to Ville.
2122 2127
2123 2128 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
2124 2129 trying to catch spurious foo[1] autocalls. My fix actually broke
2125 2130 ',/' autoquote/call with explicit escape (bad regexp).
2126 2131
2127 2132 2005-02-15 *** Released version 0.6.11
2128 2133
2129 2134 2005-02-14 Fernando Perez <fperez@colorado.edu>
2130 2135
2131 2136 * IPython/background_jobs.py: New background job management
2132 2137 subsystem. This is implemented via a new set of classes, and
2133 2138 IPython now provides a builtin 'jobs' object for background job
2134 2139 execution. A convenience %bg magic serves as a lightweight
2135 2140 frontend for starting the more common type of calls. This was
2136 2141 inspired by discussions with B. Granger and the BackgroundCommand
2137 2142 class described in the book Python Scripting for Computational
2138 2143 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
2139 2144 (although ultimately no code from this text was used, as IPython's
2140 2145 system is a separate implementation).
2141 2146
2142 2147 * IPython/iplib.py (MagicCompleter.python_matches): add new option
2143 2148 to control the completion of single/double underscore names
2144 2149 separately. As documented in the example ipytonrc file, the
2145 2150 readline_omit__names variable can now be set to 2, to omit even
2146 2151 single underscore names. Thanks to a patch by Brian Wong
2147 2152 <BrianWong-AT-AirgoNetworks.Com>.
2148 2153 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
2149 2154 be autocalled as foo([1]) if foo were callable. A problem for
2150 2155 things which are both callable and implement __getitem__.
2151 2156 (init_readline): Fix autoindentation for win32. Thanks to a patch
2152 2157 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
2153 2158
2154 2159 2005-02-12 Fernando Perez <fperez@colorado.edu>
2155 2160
2156 2161 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
2157 2162 which I had written long ago to sort out user error messages which
2158 2163 may occur during startup. This seemed like a good idea initially,
2159 2164 but it has proven a disaster in retrospect. I don't want to
2160 2165 change much code for now, so my fix is to set the internal 'debug'
2161 2166 flag to true everywhere, whose only job was precisely to control
2162 2167 this subsystem. This closes issue 28 (as well as avoiding all
2163 2168 sorts of strange hangups which occur from time to time).
2164 2169
2165 2170 2005-02-07 Fernando Perez <fperez@colorado.edu>
2166 2171
2167 2172 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
2168 2173 previous call produced a syntax error.
2169 2174
2170 2175 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
2171 2176 classes without constructor.
2172 2177
2173 2178 2005-02-06 Fernando Perez <fperez@colorado.edu>
2174 2179
2175 2180 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
2176 2181 completions with the results of each matcher, so we return results
2177 2182 to the user from all namespaces. This breaks with ipython
2178 2183 tradition, but I think it's a nicer behavior. Now you get all
2179 2184 possible completions listed, from all possible namespaces (python,
2180 2185 filesystem, magics...) After a request by John Hunter
2181 2186 <jdhunter-AT-nitace.bsd.uchicago.edu>.
2182 2187
2183 2188 2005-02-05 Fernando Perez <fperez@colorado.edu>
2184 2189
2185 2190 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
2186 2191 the call had quote characters in it (the quotes were stripped).
2187 2192
2188 2193 2005-01-31 Fernando Perez <fperez@colorado.edu>
2189 2194
2190 2195 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
2191 2196 Itpl.itpl() to make the code more robust against psyco
2192 2197 optimizations.
2193 2198
2194 2199 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
2195 2200 of causing an exception. Quicker, cleaner.
2196 2201
2197 2202 2005-01-28 Fernando Perez <fperez@colorado.edu>
2198 2203
2199 2204 * scripts/ipython_win_post_install.py (install): hardcode
2200 2205 sys.prefix+'python.exe' as the executable path. It turns out that
2201 2206 during the post-installation run, sys.executable resolves to the
2202 2207 name of the binary installer! I should report this as a distutils
2203 2208 bug, I think. I updated the .10 release with this tiny fix, to
2204 2209 avoid annoying the lists further.
2205 2210
2206 2211 2005-01-27 *** Released version 0.6.10
2207 2212
2208 2213 2005-01-27 Fernando Perez <fperez@colorado.edu>
2209 2214
2210 2215 * IPython/numutils.py (norm): Added 'inf' as optional name for
2211 2216 L-infinity norm, included references to mathworld.com for vector
2212 2217 norm definitions.
2213 2218 (amin/amax): added amin/amax for array min/max. Similar to what
2214 2219 pylab ships with after the recent reorganization of names.
2215 2220 (spike/spike_odd): removed deprecated spike/spike_odd functions.
2216 2221
2217 2222 * ipython.el: committed Alex's recent fixes and improvements.
2218 2223 Tested with python-mode from CVS, and it looks excellent. Since
2219 2224 python-mode hasn't released anything in a while, I'm temporarily
2220 2225 putting a copy of today's CVS (v 4.70) of python-mode in:
2221 2226 http://ipython.scipy.org/tmp/python-mode.el
2222 2227
2223 2228 * scripts/ipython_win_post_install.py (install): Win32 fix to use
2224 2229 sys.executable for the executable name, instead of assuming it's
2225 2230 called 'python.exe' (the post-installer would have produced broken
2226 2231 setups on systems with a differently named python binary).
2227 2232
2228 2233 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
2229 2234 references to os.linesep, to make the code more
2230 2235 platform-independent. This is also part of the win32 coloring
2231 2236 fixes.
2232 2237
2233 2238 * IPython/genutils.py (page_dumb): Remove attempts to chop long
2234 2239 lines, which actually cause coloring bugs because the length of
2235 2240 the line is very difficult to correctly compute with embedded
2236 2241 escapes. This was the source of all the coloring problems under
2237 2242 Win32. I think that _finally_, Win32 users have a properly
2238 2243 working ipython in all respects. This would never have happened
2239 2244 if not for Gary Bishop and Viktor Ransmayr's great help and work.
2240 2245
2241 2246 2005-01-26 *** Released version 0.6.9
2242 2247
2243 2248 2005-01-25 Fernando Perez <fperez@colorado.edu>
2244 2249
2245 2250 * setup.py: finally, we have a true Windows installer, thanks to
2246 2251 the excellent work of Viktor Ransmayr
2247 2252 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
2248 2253 Windows users. The setup routine is quite a bit cleaner thanks to
2249 2254 this, and the post-install script uses the proper functions to
2250 2255 allow a clean de-installation using the standard Windows Control
2251 2256 Panel.
2252 2257
2253 2258 * IPython/genutils.py (get_home_dir): changed to use the $HOME
2254 2259 environment variable under all OSes (including win32) if
2255 2260 available. This will give consistency to win32 users who have set
2256 2261 this variable for any reason. If os.environ['HOME'] fails, the
2257 2262 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
2258 2263
2259 2264 2005-01-24 Fernando Perez <fperez@colorado.edu>
2260 2265
2261 2266 * IPython/numutils.py (empty_like): add empty_like(), similar to
2262 2267 zeros_like() but taking advantage of the new empty() Numeric routine.
2263 2268
2264 2269 2005-01-23 *** Released version 0.6.8
2265 2270
2266 2271 2005-01-22 Fernando Perez <fperez@colorado.edu>
2267 2272
2268 2273 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
2269 2274 automatic show() calls. After discussing things with JDH, it
2270 2275 turns out there are too many corner cases where this can go wrong.
2271 2276 It's best not to try to be 'too smart', and simply have ipython
2272 2277 reproduce as much as possible the default behavior of a normal
2273 2278 python shell.
2274 2279
2275 2280 * IPython/iplib.py (InteractiveShell.__init__): Modified the
2276 2281 line-splitting regexp and _prefilter() to avoid calling getattr()
2277 2282 on assignments. This closes
2278 2283 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
2279 2284 readline uses getattr(), so a simple <TAB> keypress is still
2280 2285 enough to trigger getattr() calls on an object.
2281 2286
2282 2287 2005-01-21 Fernando Perez <fperez@colorado.edu>
2283 2288
2284 2289 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
2285 2290 docstring under pylab so it doesn't mask the original.
2286 2291
2287 2292 2005-01-21 *** Released version 0.6.7
2288 2293
2289 2294 2005-01-21 Fernando Perez <fperez@colorado.edu>
2290 2295
2291 2296 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
2292 2297 signal handling for win32 users in multithreaded mode.
2293 2298
2294 2299 2005-01-17 Fernando Perez <fperez@colorado.edu>
2295 2300
2296 2301 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
2297 2302 instances with no __init__. After a crash report by Norbert Nemec
2298 2303 <Norbert-AT-nemec-online.de>.
2299 2304
2300 2305 2005-01-14 Fernando Perez <fperez@colorado.edu>
2301 2306
2302 2307 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
2303 2308 names for verbose exceptions, when multiple dotted names and the
2304 2309 'parent' object were present on the same line.
2305 2310
2306 2311 2005-01-11 Fernando Perez <fperez@colorado.edu>
2307 2312
2308 2313 * IPython/genutils.py (flag_calls): new utility to trap and flag
2309 2314 calls in functions. I need it to clean up matplotlib support.
2310 2315 Also removed some deprecated code in genutils.
2311 2316
2312 2317 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
2313 2318 that matplotlib scripts called with %run, which don't call show()
2314 2319 themselves, still have their plotting windows open.
2315 2320
2316 2321 2005-01-05 Fernando Perez <fperez@colorado.edu>
2317 2322
2318 2323 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
2319 2324 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
2320 2325
2321 2326 2004-12-19 Fernando Perez <fperez@colorado.edu>
2322 2327
2323 2328 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
2324 2329 parent_runcode, which was an eyesore. The same result can be
2325 2330 obtained with Python's regular superclass mechanisms.
2326 2331
2327 2332 2004-12-17 Fernando Perez <fperez@colorado.edu>
2328 2333
2329 2334 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
2330 2335 reported by Prabhu.
2331 2336 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
2332 2337 sys.stderr) instead of explicitly calling sys.stderr. This helps
2333 2338 maintain our I/O abstractions clean, for future GUI embeddings.
2334 2339
2335 2340 * IPython/genutils.py (info): added new utility for sys.stderr
2336 2341 unified info message handling (thin wrapper around warn()).
2337 2342
2338 2343 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
2339 2344 composite (dotted) names on verbose exceptions.
2340 2345 (VerboseTB.nullrepr): harden against another kind of errors which
2341 2346 Python's inspect module can trigger, and which were crashing
2342 2347 IPython. Thanks to a report by Marco Lombardi
2343 2348 <mlombard-AT-ma010192.hq.eso.org>.
2344 2349
2345 2350 2004-12-13 *** Released version 0.6.6
2346 2351
2347 2352 2004-12-12 Fernando Perez <fperez@colorado.edu>
2348 2353
2349 2354 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
2350 2355 generated by pygtk upon initialization if it was built without
2351 2356 threads (for matplotlib users). After a crash reported by
2352 2357 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
2353 2358
2354 2359 * IPython/ipmaker.py (make_IPython): fix small bug in the
2355 2360 import_some parameter for multiple imports.
2356 2361
2357 2362 * IPython/iplib.py (ipmagic): simplified the interface of
2358 2363 ipmagic() to take a single string argument, just as it would be
2359 2364 typed at the IPython cmd line.
2360 2365 (ipalias): Added new ipalias() with an interface identical to
2361 2366 ipmagic(). This completes exposing a pure python interface to the
2362 2367 alias and magic system, which can be used in loops or more complex
2363 2368 code where IPython's automatic line mangling is not active.
2364 2369
2365 2370 * IPython/genutils.py (timing): changed interface of timing to
2366 2371 simply run code once, which is the most common case. timings()
2367 2372 remains unchanged, for the cases where you want multiple runs.
2368 2373
2369 2374 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
2370 2375 bug where Python2.2 crashes with exec'ing code which does not end
2371 2376 in a single newline. Python 2.3 is OK, so I hadn't noticed this
2372 2377 before.
2373 2378
2374 2379 2004-12-10 Fernando Perez <fperez@colorado.edu>
2375 2380
2376 2381 * IPython/Magic.py (Magic.magic_prun): changed name of option from
2377 2382 -t to -T, to accomodate the new -t flag in %run (the %run and
2378 2383 %prun options are kind of intermixed, and it's not easy to change
2379 2384 this with the limitations of python's getopt).
2380 2385
2381 2386 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
2382 2387 the execution of scripts. It's not as fine-tuned as timeit.py,
2383 2388 but it works from inside ipython (and under 2.2, which lacks
2384 2389 timeit.py). Optionally a number of runs > 1 can be given for
2385 2390 timing very short-running code.
2386 2391
2387 2392 * IPython/genutils.py (uniq_stable): new routine which returns a
2388 2393 list of unique elements in any iterable, but in stable order of
2389 2394 appearance. I needed this for the ultraTB fixes, and it's a handy
2390 2395 utility.
2391 2396
2392 2397 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
2393 2398 dotted names in Verbose exceptions. This had been broken since
2394 2399 the very start, now x.y will properly be printed in a Verbose
2395 2400 traceback, instead of x being shown and y appearing always as an
2396 2401 'undefined global'. Getting this to work was a bit tricky,
2397 2402 because by default python tokenizers are stateless. Saved by
2398 2403 python's ability to easily add a bit of state to an arbitrary
2399 2404 function (without needing to build a full-blown callable object).
2400 2405
2401 2406 Also big cleanup of this code, which had horrendous runtime
2402 2407 lookups of zillions of attributes for colorization. Moved all
2403 2408 this code into a few templates, which make it cleaner and quicker.
2404 2409
2405 2410 Printout quality was also improved for Verbose exceptions: one
2406 2411 variable per line, and memory addresses are printed (this can be
2407 2412 quite handy in nasty debugging situations, which is what Verbose
2408 2413 is for).
2409 2414
2410 2415 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
2411 2416 the command line as scripts to be loaded by embedded instances.
2412 2417 Doing so has the potential for an infinite recursion if there are
2413 2418 exceptions thrown in the process. This fixes a strange crash
2414 2419 reported by Philippe MULLER <muller-AT-irit.fr>.
2415 2420
2416 2421 2004-12-09 Fernando Perez <fperez@colorado.edu>
2417 2422
2418 2423 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
2419 2424 to reflect new names in matplotlib, which now expose the
2420 2425 matlab-compatible interface via a pylab module instead of the
2421 2426 'matlab' name. The new code is backwards compatible, so users of
2422 2427 all matplotlib versions are OK. Patch by J. Hunter.
2423 2428
2424 2429 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
2425 2430 of __init__ docstrings for instances (class docstrings are already
2426 2431 automatically printed). Instances with customized docstrings
2427 2432 (indep. of the class) are also recognized and all 3 separate
2428 2433 docstrings are printed (instance, class, constructor). After some
2429 2434 comments/suggestions by J. Hunter.
2430 2435
2431 2436 2004-12-05 Fernando Perez <fperez@colorado.edu>
2432 2437
2433 2438 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
2434 2439 warnings when tab-completion fails and triggers an exception.
2435 2440
2436 2441 2004-12-03 Fernando Perez <fperez@colorado.edu>
2437 2442
2438 2443 * IPython/Magic.py (magic_prun): Fix bug where an exception would
2439 2444 be triggered when using 'run -p'. An incorrect option flag was
2440 2445 being set ('d' instead of 'D').
2441 2446 (manpage): fix missing escaped \- sign.
2442 2447
2443 2448 2004-11-30 *** Released version 0.6.5
2444 2449
2445 2450 2004-11-30 Fernando Perez <fperez@colorado.edu>
2446 2451
2447 2452 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
2448 2453 setting with -d option.
2449 2454
2450 2455 * setup.py (docfiles): Fix problem where the doc glob I was using
2451 2456 was COMPLETELY BROKEN. It was giving the right files by pure
2452 2457 accident, but failed once I tried to include ipython.el. Note:
2453 2458 glob() does NOT allow you to do exclusion on multiple endings!
2454 2459
2455 2460 2004-11-29 Fernando Perez <fperez@colorado.edu>
2456 2461
2457 2462 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
2458 2463 the manpage as the source. Better formatting & consistency.
2459 2464
2460 2465 * IPython/Magic.py (magic_run): Added new -d option, to run
2461 2466 scripts under the control of the python pdb debugger. Note that
2462 2467 this required changing the %prun option -d to -D, to avoid a clash
2463 2468 (since %run must pass options to %prun, and getopt is too dumb to
2464 2469 handle options with string values with embedded spaces). Thanks
2465 2470 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
2466 2471 (magic_who_ls): added type matching to %who and %whos, so that one
2467 2472 can filter their output to only include variables of certain
2468 2473 types. Another suggestion by Matthew.
2469 2474 (magic_whos): Added memory summaries in kb and Mb for arrays.
2470 2475 (magic_who): Improve formatting (break lines every 9 vars).
2471 2476
2472 2477 2004-11-28 Fernando Perez <fperez@colorado.edu>
2473 2478
2474 2479 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
2475 2480 cache when empty lines were present.
2476 2481
2477 2482 2004-11-24 Fernando Perez <fperez@colorado.edu>
2478 2483
2479 2484 * IPython/usage.py (__doc__): document the re-activated threading
2480 2485 options for WX and GTK.
2481 2486
2482 2487 2004-11-23 Fernando Perez <fperez@colorado.edu>
2483 2488
2484 2489 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
2485 2490 the -wthread and -gthread options, along with a new -tk one to try
2486 2491 and coordinate Tk threading with wx/gtk. The tk support is very
2487 2492 platform dependent, since it seems to require Tcl and Tk to be
2488 2493 built with threads (Fedora1/2 appears NOT to have it, but in
2489 2494 Prabhu's Debian boxes it works OK). But even with some Tk
2490 2495 limitations, this is a great improvement.
2491 2496
2492 2497 * IPython/Prompts.py (prompt_specials_color): Added \t for time
2493 2498 info in user prompts. Patch by Prabhu.
2494 2499
2495 2500 2004-11-18 Fernando Perez <fperez@colorado.edu>
2496 2501
2497 2502 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
2498 2503 EOFErrors and bail, to avoid infinite loops if a non-terminating
2499 2504 file is fed into ipython. Patch submitted in issue 19 by user,
2500 2505 many thanks.
2501 2506
2502 2507 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
2503 2508 autoquote/parens in continuation prompts, which can cause lots of
2504 2509 problems. Closes roundup issue 20.
2505 2510
2506 2511 2004-11-17 Fernando Perez <fperez@colorado.edu>
2507 2512
2508 2513 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
2509 2514 reported as debian bug #280505. I'm not sure my local changelog
2510 2515 entry has the proper debian format (Jack?).
2511 2516
2512 2517 2004-11-08 *** Released version 0.6.4
2513 2518
2514 2519 2004-11-08 Fernando Perez <fperez@colorado.edu>
2515 2520
2516 2521 * IPython/iplib.py (init_readline): Fix exit message for Windows
2517 2522 when readline is active. Thanks to a report by Eric Jones
2518 2523 <eric-AT-enthought.com>.
2519 2524
2520 2525 2004-11-07 Fernando Perez <fperez@colorado.edu>
2521 2526
2522 2527 * IPython/genutils.py (page): Add a trap for OSError exceptions,
2523 2528 sometimes seen by win2k/cygwin users.
2524 2529
2525 2530 2004-11-06 Fernando Perez <fperez@colorado.edu>
2526 2531
2527 2532 * IPython/iplib.py (interact): Change the handling of %Exit from
2528 2533 trying to propagate a SystemExit to an internal ipython flag.
2529 2534 This is less elegant than using Python's exception mechanism, but
2530 2535 I can't get that to work reliably with threads, so under -pylab
2531 2536 %Exit was hanging IPython. Cross-thread exception handling is
2532 2537 really a bitch. Thaks to a bug report by Stephen Walton
2533 2538 <stephen.walton-AT-csun.edu>.
2534 2539
2535 2540 2004-11-04 Fernando Perez <fperez@colorado.edu>
2536 2541
2537 2542 * IPython/iplib.py (raw_input_original): store a pointer to the
2538 2543 true raw_input to harden against code which can modify it
2539 2544 (wx.py.PyShell does this and would otherwise crash ipython).
2540 2545 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
2541 2546
2542 2547 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
2543 2548 Ctrl-C problem, which does not mess up the input line.
2544 2549
2545 2550 2004-11-03 Fernando Perez <fperez@colorado.edu>
2546 2551
2547 2552 * IPython/Release.py: Changed licensing to BSD, in all files.
2548 2553 (name): lowercase name for tarball/RPM release.
2549 2554
2550 2555 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
2551 2556 use throughout ipython.
2552 2557
2553 2558 * IPython/Magic.py (Magic._ofind): Switch to using the new
2554 2559 OInspect.getdoc() function.
2555 2560
2556 2561 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
2557 2562 of the line currently being canceled via Ctrl-C. It's extremely
2558 2563 ugly, but I don't know how to do it better (the problem is one of
2559 2564 handling cross-thread exceptions).
2560 2565
2561 2566 2004-10-28 Fernando Perez <fperez@colorado.edu>
2562 2567
2563 2568 * IPython/Shell.py (signal_handler): add signal handlers to trap
2564 2569 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
2565 2570 report by Francesc Alted.
2566 2571
2567 2572 2004-10-21 Fernando Perez <fperez@colorado.edu>
2568 2573
2569 2574 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
2570 2575 to % for pysh syntax extensions.
2571 2576
2572 2577 2004-10-09 Fernando Perez <fperez@colorado.edu>
2573 2578
2574 2579 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
2575 2580 arrays to print a more useful summary, without calling str(arr).
2576 2581 This avoids the problem of extremely lengthy computations which
2577 2582 occur if arr is large, and appear to the user as a system lockup
2578 2583 with 100% cpu activity. After a suggestion by Kristian Sandberg
2579 2584 <Kristian.Sandberg@colorado.edu>.
2580 2585 (Magic.__init__): fix bug in global magic escapes not being
2581 2586 correctly set.
2582 2587
2583 2588 2004-10-08 Fernando Perez <fperez@colorado.edu>
2584 2589
2585 2590 * IPython/Magic.py (__license__): change to absolute imports of
2586 2591 ipython's own internal packages, to start adapting to the absolute
2587 2592 import requirement of PEP-328.
2588 2593
2589 2594 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
2590 2595 files, and standardize author/license marks through the Release
2591 2596 module instead of having per/file stuff (except for files with
2592 2597 particular licenses, like the MIT/PSF-licensed codes).
2593 2598
2594 2599 * IPython/Debugger.py: remove dead code for python 2.1
2595 2600
2596 2601 2004-10-04 Fernando Perez <fperez@colorado.edu>
2597 2602
2598 2603 * IPython/iplib.py (ipmagic): New function for accessing magics
2599 2604 via a normal python function call.
2600 2605
2601 2606 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
2602 2607 from '@' to '%', to accomodate the new @decorator syntax of python
2603 2608 2.4.
2604 2609
2605 2610 2004-09-29 Fernando Perez <fperez@colorado.edu>
2606 2611
2607 2612 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
2608 2613 matplotlib.use to prevent running scripts which try to switch
2609 2614 interactive backends from within ipython. This will just crash
2610 2615 the python interpreter, so we can't allow it (but a detailed error
2611 2616 is given to the user).
2612 2617
2613 2618 2004-09-28 Fernando Perez <fperez@colorado.edu>
2614 2619
2615 2620 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
2616 2621 matplotlib-related fixes so that using @run with non-matplotlib
2617 2622 scripts doesn't pop up spurious plot windows. This requires
2618 2623 matplotlib >= 0.63, where I had to make some changes as well.
2619 2624
2620 2625 * IPython/ipmaker.py (make_IPython): update version requirement to
2621 2626 python 2.2.
2622 2627
2623 2628 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
2624 2629 banner arg for embedded customization.
2625 2630
2626 2631 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
2627 2632 explicit uses of __IP as the IPython's instance name. Now things
2628 2633 are properly handled via the shell.name value. The actual code
2629 2634 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
2630 2635 is much better than before. I'll clean things completely when the
2631 2636 magic stuff gets a real overhaul.
2632 2637
2633 2638 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
2634 2639 minor changes to debian dir.
2635 2640
2636 2641 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
2637 2642 pointer to the shell itself in the interactive namespace even when
2638 2643 a user-supplied dict is provided. This is needed for embedding
2639 2644 purposes (found by tests with Michel Sanner).
2640 2645
2641 2646 2004-09-27 Fernando Perez <fperez@colorado.edu>
2642 2647
2643 2648 * IPython/UserConfig/ipythonrc: remove []{} from
2644 2649 readline_remove_delims, so that things like [modname.<TAB> do
2645 2650 proper completion. This disables [].TAB, but that's a less common
2646 2651 case than module names in list comprehensions, for example.
2647 2652 Thanks to a report by Andrea Riciputi.
2648 2653
2649 2654 2004-09-09 Fernando Perez <fperez@colorado.edu>
2650 2655
2651 2656 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
2652 2657 blocking problems in win32 and osx. Fix by John.
2653 2658
2654 2659 2004-09-08 Fernando Perez <fperez@colorado.edu>
2655 2660
2656 2661 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
2657 2662 for Win32 and OSX. Fix by John Hunter.
2658 2663
2659 2664 2004-08-30 *** Released version 0.6.3
2660 2665
2661 2666 2004-08-30 Fernando Perez <fperez@colorado.edu>
2662 2667
2663 2668 * setup.py (isfile): Add manpages to list of dependent files to be
2664 2669 updated.
2665 2670
2666 2671 2004-08-27 Fernando Perez <fperez@colorado.edu>
2667 2672
2668 2673 * IPython/Shell.py (start): I've disabled -wthread and -gthread
2669 2674 for now. They don't really work with standalone WX/GTK code
2670 2675 (though matplotlib IS working fine with both of those backends).
2671 2676 This will neeed much more testing. I disabled most things with
2672 2677 comments, so turning it back on later should be pretty easy.
2673 2678
2674 2679 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
2675 2680 autocalling of expressions like r'foo', by modifying the line
2676 2681 split regexp. Closes
2677 2682 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
2678 2683 Riley <ipythonbugs-AT-sabi.net>.
2679 2684 (InteractiveShell.mainloop): honor --nobanner with banner
2680 2685 extensions.
2681 2686
2682 2687 * IPython/Shell.py: Significant refactoring of all classes, so
2683 2688 that we can really support ALL matplotlib backends and threading
2684 2689 models (John spotted a bug with Tk which required this). Now we
2685 2690 should support single-threaded, WX-threads and GTK-threads, both
2686 2691 for generic code and for matplotlib.
2687 2692
2688 2693 * IPython/ipmaker.py (__call__): Changed -mpthread option to
2689 2694 -pylab, to simplify things for users. Will also remove the pylab
2690 2695 profile, since now all of matplotlib configuration is directly
2691 2696 handled here. This also reduces startup time.
2692 2697
2693 2698 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
2694 2699 shell wasn't being correctly called. Also in IPShellWX.
2695 2700
2696 2701 * IPython/iplib.py (InteractiveShell.__init__): Added option to
2697 2702 fine-tune banner.
2698 2703
2699 2704 * IPython/numutils.py (spike): Deprecate these spike functions,
2700 2705 delete (long deprecated) gnuplot_exec handler.
2701 2706
2702 2707 2004-08-26 Fernando Perez <fperez@colorado.edu>
2703 2708
2704 2709 * ipython.1: Update for threading options, plus some others which
2705 2710 were missing.
2706 2711
2707 2712 * IPython/ipmaker.py (__call__): Added -wthread option for
2708 2713 wxpython thread handling. Make sure threading options are only
2709 2714 valid at the command line.
2710 2715
2711 2716 * scripts/ipython: moved shell selection into a factory function
2712 2717 in Shell.py, to keep the starter script to a minimum.
2713 2718
2714 2719 2004-08-25 Fernando Perez <fperez@colorado.edu>
2715 2720
2716 2721 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
2717 2722 John. Along with some recent changes he made to matplotlib, the
2718 2723 next versions of both systems should work very well together.
2719 2724
2720 2725 2004-08-24 Fernando Perez <fperez@colorado.edu>
2721 2726
2722 2727 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
2723 2728 tried to switch the profiling to using hotshot, but I'm getting
2724 2729 strange errors from prof.runctx() there. I may be misreading the
2725 2730 docs, but it looks weird. For now the profiling code will
2726 2731 continue to use the standard profiler.
2727 2732
2728 2733 2004-08-23 Fernando Perez <fperez@colorado.edu>
2729 2734
2730 2735 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
2731 2736 threaded shell, by John Hunter. It's not quite ready yet, but
2732 2737 close.
2733 2738
2734 2739 2004-08-22 Fernando Perez <fperez@colorado.edu>
2735 2740
2736 2741 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
2737 2742 in Magic and ultraTB.
2738 2743
2739 2744 * ipython.1: document threading options in manpage.
2740 2745
2741 2746 * scripts/ipython: Changed name of -thread option to -gthread,
2742 2747 since this is GTK specific. I want to leave the door open for a
2743 2748 -wthread option for WX, which will most likely be necessary. This
2744 2749 change affects usage and ipmaker as well.
2745 2750
2746 2751 * IPython/Shell.py (matplotlib_shell): Add a factory function to
2747 2752 handle the matplotlib shell issues. Code by John Hunter
2748 2753 <jdhunter-AT-nitace.bsd.uchicago.edu>.
2749 2754 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
2750 2755 broken (and disabled for end users) for now, but it puts the
2751 2756 infrastructure in place.
2752 2757
2753 2758 2004-08-21 Fernando Perez <fperez@colorado.edu>
2754 2759
2755 2760 * ipythonrc-pylab: Add matplotlib support.
2756 2761
2757 2762 * matplotlib_config.py: new files for matplotlib support, part of
2758 2763 the pylab profile.
2759 2764
2760 2765 * IPython/usage.py (__doc__): documented the threading options.
2761 2766
2762 2767 2004-08-20 Fernando Perez <fperez@colorado.edu>
2763 2768
2764 2769 * ipython: Modified the main calling routine to handle the -thread
2765 2770 and -mpthread options. This needs to be done as a top-level hack,
2766 2771 because it determines which class to instantiate for IPython
2767 2772 itself.
2768 2773
2769 2774 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
2770 2775 classes to support multithreaded GTK operation without blocking,
2771 2776 and matplotlib with all backends. This is a lot of still very
2772 2777 experimental code, and threads are tricky. So it may still have a
2773 2778 few rough edges... This code owes a lot to
2774 2779 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
2775 2780 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
2776 2781 to John Hunter for all the matplotlib work.
2777 2782
2778 2783 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
2779 2784 options for gtk thread and matplotlib support.
2780 2785
2781 2786 2004-08-16 Fernando Perez <fperez@colorado.edu>
2782 2787
2783 2788 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
2784 2789 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
2785 2790 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
2786 2791
2787 2792 2004-08-11 Fernando Perez <fperez@colorado.edu>
2788 2793
2789 2794 * setup.py (isfile): Fix build so documentation gets updated for
2790 2795 rpms (it was only done for .tgz builds).
2791 2796
2792 2797 2004-08-10 Fernando Perez <fperez@colorado.edu>
2793 2798
2794 2799 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
2795 2800
2796 2801 * iplib.py : Silence syntax error exceptions in tab-completion.
2797 2802
2798 2803 2004-08-05 Fernando Perez <fperez@colorado.edu>
2799 2804
2800 2805 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
2801 2806 'color off' mark for continuation prompts. This was causing long
2802 2807 continuation lines to mis-wrap.
2803 2808
2804 2809 2004-08-01 Fernando Perez <fperez@colorado.edu>
2805 2810
2806 2811 * IPython/ipmaker.py (make_IPython): Allow the shell class used
2807 2812 for building ipython to be a parameter. All this is necessary
2808 2813 right now to have a multithreaded version, but this insane
2809 2814 non-design will be cleaned up soon. For now, it's a hack that
2810 2815 works.
2811 2816
2812 2817 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
2813 2818 args in various places. No bugs so far, but it's a dangerous
2814 2819 practice.
2815 2820
2816 2821 2004-07-31 Fernando Perez <fperez@colorado.edu>
2817 2822
2818 2823 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
2819 2824 fix completion of files with dots in their names under most
2820 2825 profiles (pysh was OK because the completion order is different).
2821 2826
2822 2827 2004-07-27 Fernando Perez <fperez@colorado.edu>
2823 2828
2824 2829 * IPython/iplib.py (InteractiveShell.__init__): build dict of
2825 2830 keywords manually, b/c the one in keyword.py was removed in python
2826 2831 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
2827 2832 This is NOT a bug under python 2.3 and earlier.
2828 2833
2829 2834 2004-07-26 Fernando Perez <fperez@colorado.edu>
2830 2835
2831 2836 * IPython/ultraTB.py (VerboseTB.text): Add another
2832 2837 linecache.checkcache() call to try to prevent inspect.py from
2833 2838 crashing under python 2.3. I think this fixes
2834 2839 http://www.scipy.net/roundup/ipython/issue17.
2835 2840
2836 2841 2004-07-26 *** Released version 0.6.2
2837 2842
2838 2843 2004-07-26 Fernando Perez <fperez@colorado.edu>
2839 2844
2840 2845 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
2841 2846 fail for any number.
2842 2847 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
2843 2848 empty bookmarks.
2844 2849
2845 2850 2004-07-26 *** Released version 0.6.1
2846 2851
2847 2852 2004-07-26 Fernando Perez <fperez@colorado.edu>
2848 2853
2849 2854 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
2850 2855
2851 2856 * IPython/iplib.py (protect_filename): Applied Ville's patch for
2852 2857 escaping '()[]{}' in filenames.
2853 2858
2854 2859 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
2855 2860 Python 2.2 users who lack a proper shlex.split.
2856 2861
2857 2862 2004-07-19 Fernando Perez <fperez@colorado.edu>
2858 2863
2859 2864 * IPython/iplib.py (InteractiveShell.init_readline): Add support
2860 2865 for reading readline's init file. I follow the normal chain:
2861 2866 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
2862 2867 report by Mike Heeter. This closes
2863 2868 http://www.scipy.net/roundup/ipython/issue16.
2864 2869
2865 2870 2004-07-18 Fernando Perez <fperez@colorado.edu>
2866 2871
2867 2872 * IPython/iplib.py (__init__): Add better handling of '\' under
2868 2873 Win32 for filenames. After a patch by Ville.
2869 2874
2870 2875 2004-07-17 Fernando Perez <fperez@colorado.edu>
2871 2876
2872 2877 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
2873 2878 autocalling would be triggered for 'foo is bar' if foo is
2874 2879 callable. I also cleaned up the autocall detection code to use a
2875 2880 regexp, which is faster. Bug reported by Alexander Schmolck.
2876 2881
2877 2882 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
2878 2883 '?' in them would confuse the help system. Reported by Alex
2879 2884 Schmolck.
2880 2885
2881 2886 2004-07-16 Fernando Perez <fperez@colorado.edu>
2882 2887
2883 2888 * IPython/GnuplotInteractive.py (__all__): added plot2.
2884 2889
2885 2890 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
2886 2891 plotting dictionaries, lists or tuples of 1d arrays.
2887 2892
2888 2893 * IPython/Magic.py (Magic.magic_hist): small clenaups and
2889 2894 optimizations.
2890 2895
2891 2896 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
2892 2897 the information which was there from Janko's original IPP code:
2893 2898
2894 2899 03.05.99 20:53 porto.ifm.uni-kiel.de
2895 2900 --Started changelog.
2896 2901 --make clear do what it say it does
2897 2902 --added pretty output of lines from inputcache
2898 2903 --Made Logger a mixin class, simplifies handling of switches
2899 2904 --Added own completer class. .string<TAB> expands to last history
2900 2905 line which starts with string. The new expansion is also present
2901 2906 with Ctrl-r from the readline library. But this shows, who this
2902 2907 can be done for other cases.
2903 2908 --Added convention that all shell functions should accept a
2904 2909 parameter_string This opens the door for different behaviour for
2905 2910 each function. @cd is a good example of this.
2906 2911
2907 2912 04.05.99 12:12 porto.ifm.uni-kiel.de
2908 2913 --added logfile rotation
2909 2914 --added new mainloop method which freezes first the namespace
2910 2915
2911 2916 07.05.99 21:24 porto.ifm.uni-kiel.de
2912 2917 --added the docreader classes. Now there is a help system.
2913 2918 -This is only a first try. Currently it's not easy to put new
2914 2919 stuff in the indices. But this is the way to go. Info would be
2915 2920 better, but HTML is every where and not everybody has an info
2916 2921 system installed and it's not so easy to change html-docs to info.
2917 2922 --added global logfile option
2918 2923 --there is now a hook for object inspection method pinfo needs to
2919 2924 be provided for this. Can be reached by two '??'.
2920 2925
2921 2926 08.05.99 20:51 porto.ifm.uni-kiel.de
2922 2927 --added a README
2923 2928 --bug in rc file. Something has changed so functions in the rc
2924 2929 file need to reference the shell and not self. Not clear if it's a
2925 2930 bug or feature.
2926 2931 --changed rc file for new behavior
2927 2932
2928 2933 2004-07-15 Fernando Perez <fperez@colorado.edu>
2929 2934
2930 2935 * IPython/Logger.py (Logger.log): fixed recent bug where the input
2931 2936 cache was falling out of sync in bizarre manners when multi-line
2932 2937 input was present. Minor optimizations and cleanup.
2933 2938
2934 2939 (Logger): Remove old Changelog info for cleanup. This is the
2935 2940 information which was there from Janko's original code:
2936 2941
2937 2942 Changes to Logger: - made the default log filename a parameter
2938 2943
2939 2944 - put a check for lines beginning with !@? in log(). Needed
2940 2945 (even if the handlers properly log their lines) for mid-session
2941 2946 logging activation to work properly. Without this, lines logged
2942 2947 in mid session, which get read from the cache, would end up
2943 2948 'bare' (with !@? in the open) in the log. Now they are caught
2944 2949 and prepended with a #.
2945 2950
2946 2951 * IPython/iplib.py (InteractiveShell.init_readline): added check
2947 2952 in case MagicCompleter fails to be defined, so we don't crash.
2948 2953
2949 2954 2004-07-13 Fernando Perez <fperez@colorado.edu>
2950 2955
2951 2956 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
2952 2957 of EPS if the requested filename ends in '.eps'.
2953 2958
2954 2959 2004-07-04 Fernando Perez <fperez@colorado.edu>
2955 2960
2956 2961 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
2957 2962 escaping of quotes when calling the shell.
2958 2963
2959 2964 2004-07-02 Fernando Perez <fperez@colorado.edu>
2960 2965
2961 2966 * IPython/Prompts.py (CachedOutput.update): Fix problem with
2962 2967 gettext not working because we were clobbering '_'. Fixes
2963 2968 http://www.scipy.net/roundup/ipython/issue6.
2964 2969
2965 2970 2004-07-01 Fernando Perez <fperez@colorado.edu>
2966 2971
2967 2972 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
2968 2973 into @cd. Patch by Ville.
2969 2974
2970 2975 * IPython/iplib.py (InteractiveShell.post_config_initialization):
2971 2976 new function to store things after ipmaker runs. Patch by Ville.
2972 2977 Eventually this will go away once ipmaker is removed and the class
2973 2978 gets cleaned up, but for now it's ok. Key functionality here is
2974 2979 the addition of the persistent storage mechanism, a dict for
2975 2980 keeping data across sessions (for now just bookmarks, but more can
2976 2981 be implemented later).
2977 2982
2978 2983 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
2979 2984 persistent across sections. Patch by Ville, I modified it
2980 2985 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
2981 2986 added a '-l' option to list all bookmarks.
2982 2987
2983 2988 * IPython/iplib.py (InteractiveShell.atexit_operations): new
2984 2989 center for cleanup. Registered with atexit.register(). I moved
2985 2990 here the old exit_cleanup(). After a patch by Ville.
2986 2991
2987 2992 * IPython/Magic.py (get_py_filename): added '~' to the accepted
2988 2993 characters in the hacked shlex_split for python 2.2.
2989 2994
2990 2995 * IPython/iplib.py (file_matches): more fixes to filenames with
2991 2996 whitespace in them. It's not perfect, but limitations in python's
2992 2997 readline make it impossible to go further.
2993 2998
2994 2999 2004-06-29 Fernando Perez <fperez@colorado.edu>
2995 3000
2996 3001 * IPython/iplib.py (file_matches): escape whitespace correctly in
2997 3002 filename completions. Bug reported by Ville.
2998 3003
2999 3004 2004-06-28 Fernando Perez <fperez@colorado.edu>
3000 3005
3001 3006 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
3002 3007 the history file will be called 'history-PROFNAME' (or just
3003 3008 'history' if no profile is loaded). I was getting annoyed at
3004 3009 getting my Numerical work history clobbered by pysh sessions.
3005 3010
3006 3011 * IPython/iplib.py (InteractiveShell.__init__): Internal
3007 3012 getoutputerror() function so that we can honor the system_verbose
3008 3013 flag for _all_ system calls. I also added escaping of #
3009 3014 characters here to avoid confusing Itpl.
3010 3015
3011 3016 * IPython/Magic.py (shlex_split): removed call to shell in
3012 3017 parse_options and replaced it with shlex.split(). The annoying
3013 3018 part was that in Python 2.2, shlex.split() doesn't exist, so I had
3014 3019 to backport it from 2.3, with several frail hacks (the shlex
3015 3020 module is rather limited in 2.2). Thanks to a suggestion by Ville
3016 3021 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
3017 3022 problem.
3018 3023
3019 3024 (Magic.magic_system_verbose): new toggle to print the actual
3020 3025 system calls made by ipython. Mainly for debugging purposes.
3021 3026
3022 3027 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
3023 3028 doesn't support persistence. Reported (and fix suggested) by
3024 3029 Travis Caldwell <travis_caldwell2000@yahoo.com>.
3025 3030
3026 3031 2004-06-26 Fernando Perez <fperez@colorado.edu>
3027 3032
3028 3033 * IPython/Logger.py (Logger.log): fix to handle correctly empty
3029 3034 continue prompts.
3030 3035
3031 3036 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
3032 3037 function (basically a big docstring) and a few more things here to
3033 3038 speedup startup. pysh.py is now very lightweight. We want because
3034 3039 it gets execfile'd, while InterpreterExec gets imported, so
3035 3040 byte-compilation saves time.
3036 3041
3037 3042 2004-06-25 Fernando Perez <fperez@colorado.edu>
3038 3043
3039 3044 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
3040 3045 -NUM', which was recently broken.
3041 3046
3042 3047 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
3043 3048 in multi-line input (but not !!, which doesn't make sense there).
3044 3049
3045 3050 * IPython/UserConfig/ipythonrc: made autoindent on by default.
3046 3051 It's just too useful, and people can turn it off in the less
3047 3052 common cases where it's a problem.
3048 3053
3049 3054 2004-06-24 Fernando Perez <fperez@colorado.edu>
3050 3055
3051 3056 * IPython/iplib.py (InteractiveShell._prefilter): big change -
3052 3057 special syntaxes (like alias calling) is now allied in multi-line
3053 3058 input. This is still _very_ experimental, but it's necessary for
3054 3059 efficient shell usage combining python looping syntax with system
3055 3060 calls. For now it's restricted to aliases, I don't think it
3056 3061 really even makes sense to have this for magics.
3057 3062
3058 3063 2004-06-23 Fernando Perez <fperez@colorado.edu>
3059 3064
3060 3065 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
3061 3066 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
3062 3067
3063 3068 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
3064 3069 extensions under Windows (after code sent by Gary Bishop). The
3065 3070 extensions considered 'executable' are stored in IPython's rc
3066 3071 structure as win_exec_ext.
3067 3072
3068 3073 * IPython/genutils.py (shell): new function, like system() but
3069 3074 without return value. Very useful for interactive shell work.
3070 3075
3071 3076 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
3072 3077 delete aliases.
3073 3078
3074 3079 * IPython/iplib.py (InteractiveShell.alias_table_update): make
3075 3080 sure that the alias table doesn't contain python keywords.
3076 3081
3077 3082 2004-06-21 Fernando Perez <fperez@colorado.edu>
3078 3083
3079 3084 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
3080 3085 non-existent items are found in $PATH. Reported by Thorsten.
3081 3086
3082 3087 2004-06-20 Fernando Perez <fperez@colorado.edu>
3083 3088
3084 3089 * IPython/iplib.py (complete): modified the completer so that the
3085 3090 order of priorities can be easily changed at runtime.
3086 3091
3087 3092 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
3088 3093 Modified to auto-execute all lines beginning with '~', '/' or '.'.
3089 3094
3090 3095 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
3091 3096 expand Python variables prepended with $ in all system calls. The
3092 3097 same was done to InteractiveShell.handle_shell_escape. Now all
3093 3098 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
3094 3099 expansion of python variables and expressions according to the
3095 3100 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
3096 3101
3097 3102 Though PEP-215 has been rejected, a similar (but simpler) one
3098 3103 seems like it will go into Python 2.4, PEP-292 -
3099 3104 http://www.python.org/peps/pep-0292.html.
3100 3105
3101 3106 I'll keep the full syntax of PEP-215, since IPython has since the
3102 3107 start used Ka-Ping Yee's reference implementation discussed there
3103 3108 (Itpl), and I actually like the powerful semantics it offers.
3104 3109
3105 3110 In order to access normal shell variables, the $ has to be escaped
3106 3111 via an extra $. For example:
3107 3112
3108 3113 In [7]: PATH='a python variable'
3109 3114
3110 3115 In [8]: !echo $PATH
3111 3116 a python variable
3112 3117
3113 3118 In [9]: !echo $$PATH
3114 3119 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
3115 3120
3116 3121 (Magic.parse_options): escape $ so the shell doesn't evaluate
3117 3122 things prematurely.
3118 3123
3119 3124 * IPython/iplib.py (InteractiveShell.call_alias): added the
3120 3125 ability for aliases to expand python variables via $.
3121 3126
3122 3127 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
3123 3128 system, now there's a @rehash/@rehashx pair of magics. These work
3124 3129 like the csh rehash command, and can be invoked at any time. They
3125 3130 build a table of aliases to everything in the user's $PATH
3126 3131 (@rehash uses everything, @rehashx is slower but only adds
3127 3132 executable files). With this, the pysh.py-based shell profile can
3128 3133 now simply call rehash upon startup, and full access to all
3129 3134 programs in the user's path is obtained.
3130 3135
3131 3136 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
3132 3137 functionality is now fully in place. I removed the old dynamic
3133 3138 code generation based approach, in favor of a much lighter one
3134 3139 based on a simple dict. The advantage is that this allows me to
3135 3140 now have thousands of aliases with negligible cost (unthinkable
3136 3141 with the old system).
3137 3142
3138 3143 2004-06-19 Fernando Perez <fperez@colorado.edu>
3139 3144
3140 3145 * IPython/iplib.py (__init__): extended MagicCompleter class to
3141 3146 also complete (last in priority) on user aliases.
3142 3147
3143 3148 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
3144 3149 call to eval.
3145 3150 (ItplNS.__init__): Added a new class which functions like Itpl,
3146 3151 but allows configuring the namespace for the evaluation to occur
3147 3152 in.
3148 3153
3149 3154 2004-06-18 Fernando Perez <fperez@colorado.edu>
3150 3155
3151 3156 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
3152 3157 better message when 'exit' or 'quit' are typed (a common newbie
3153 3158 confusion).
3154 3159
3155 3160 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
3156 3161 check for Windows users.
3157 3162
3158 3163 * IPython/iplib.py (InteractiveShell.user_setup): removed
3159 3164 disabling of colors for Windows. I'll test at runtime and issue a
3160 3165 warning if Gary's readline isn't found, as to nudge users to
3161 3166 download it.
3162 3167
3163 3168 2004-06-16 Fernando Perez <fperez@colorado.edu>
3164 3169
3165 3170 * IPython/genutils.py (Stream.__init__): changed to print errors
3166 3171 to sys.stderr. I had a circular dependency here. Now it's
3167 3172 possible to run ipython as IDLE's shell (consider this pre-alpha,
3168 3173 since true stdout things end up in the starting terminal instead
3169 3174 of IDLE's out).
3170 3175
3171 3176 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
3172 3177 users who haven't # updated their prompt_in2 definitions. Remove
3173 3178 eventually.
3174 3179 (multiple_replace): added credit to original ASPN recipe.
3175 3180
3176 3181 2004-06-15 Fernando Perez <fperez@colorado.edu>
3177 3182
3178 3183 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
3179 3184 list of auto-defined aliases.
3180 3185
3181 3186 2004-06-13 Fernando Perez <fperez@colorado.edu>
3182 3187
3183 3188 * setup.py (scriptfiles): Don't trigger win_post_install unless an
3184 3189 install was really requested (so setup.py can be used for other
3185 3190 things under Windows).
3186 3191
3187 3192 2004-06-10 Fernando Perez <fperez@colorado.edu>
3188 3193
3189 3194 * IPython/Logger.py (Logger.create_log): Manually remove any old
3190 3195 backup, since os.remove may fail under Windows. Fixes bug
3191 3196 reported by Thorsten.
3192 3197
3193 3198 2004-06-09 Fernando Perez <fperez@colorado.edu>
3194 3199
3195 3200 * examples/example-embed.py: fixed all references to %n (replaced
3196 3201 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
3197 3202 for all examples and the manual as well.
3198 3203
3199 3204 2004-06-08 Fernando Perez <fperez@colorado.edu>
3200 3205
3201 3206 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
3202 3207 alignment and color management. All 3 prompt subsystems now
3203 3208 inherit from BasePrompt.
3204 3209
3205 3210 * tools/release: updates for windows installer build and tag rpms
3206 3211 with python version (since paths are fixed).
3207 3212
3208 3213 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
3209 3214 which will become eventually obsolete. Also fixed the default
3210 3215 prompt_in2 to use \D, so at least new users start with the correct
3211 3216 defaults.
3212 3217 WARNING: Users with existing ipythonrc files will need to apply
3213 3218 this fix manually!
3214 3219
3215 3220 * setup.py: make windows installer (.exe). This is finally the
3216 3221 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
3217 3222 which I hadn't included because it required Python 2.3 (or recent
3218 3223 distutils).
3219 3224
3220 3225 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
3221 3226 usage of new '\D' escape.
3222 3227
3223 3228 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
3224 3229 lacks os.getuid())
3225 3230 (CachedOutput.set_colors): Added the ability to turn coloring
3226 3231 on/off with @colors even for manually defined prompt colors. It
3227 3232 uses a nasty global, but it works safely and via the generic color
3228 3233 handling mechanism.
3229 3234 (Prompt2.__init__): Introduced new escape '\D' for continuation
3230 3235 prompts. It represents the counter ('\#') as dots.
3231 3236 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
3232 3237 need to update their ipythonrc files and replace '%n' with '\D' in
3233 3238 their prompt_in2 settings everywhere. Sorry, but there's
3234 3239 otherwise no clean way to get all prompts to properly align. The
3235 3240 ipythonrc shipped with IPython has been updated.
3236 3241
3237 3242 2004-06-07 Fernando Perez <fperez@colorado.edu>
3238 3243
3239 3244 * setup.py (isfile): Pass local_icons option to latex2html, so the
3240 3245 resulting HTML file is self-contained. Thanks to
3241 3246 dryice-AT-liu.com.cn for the tip.
3242 3247
3243 3248 * pysh.py: I created a new profile 'shell', which implements a
3244 3249 _rudimentary_ IPython-based shell. This is in NO WAY a realy
3245 3250 system shell, nor will it become one anytime soon. It's mainly
3246 3251 meant to illustrate the use of the new flexible bash-like prompts.
3247 3252 I guess it could be used by hardy souls for true shell management,
3248 3253 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
3249 3254 profile. This uses the InterpreterExec extension provided by
3250 3255 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
3251 3256
3252 3257 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
3253 3258 auto-align itself with the length of the previous input prompt
3254 3259 (taking into account the invisible color escapes).
3255 3260 (CachedOutput.__init__): Large restructuring of this class. Now
3256 3261 all three prompts (primary1, primary2, output) are proper objects,
3257 3262 managed by the 'parent' CachedOutput class. The code is still a
3258 3263 bit hackish (all prompts share state via a pointer to the cache),
3259 3264 but it's overall far cleaner than before.
3260 3265
3261 3266 * IPython/genutils.py (getoutputerror): modified to add verbose,
3262 3267 debug and header options. This makes the interface of all getout*
3263 3268 functions uniform.
3264 3269 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
3265 3270
3266 3271 * IPython/Magic.py (Magic.default_option): added a function to
3267 3272 allow registering default options for any magic command. This
3268 3273 makes it easy to have profiles which customize the magics globally
3269 3274 for a certain use. The values set through this function are
3270 3275 picked up by the parse_options() method, which all magics should
3271 3276 use to parse their options.
3272 3277
3273 3278 * IPython/genutils.py (warn): modified the warnings framework to
3274 3279 use the Term I/O class. I'm trying to slowly unify all of
3275 3280 IPython's I/O operations to pass through Term.
3276 3281
3277 3282 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
3278 3283 the secondary prompt to correctly match the length of the primary
3279 3284 one for any prompt. Now multi-line code will properly line up
3280 3285 even for path dependent prompts, such as the new ones available
3281 3286 via the prompt_specials.
3282 3287
3283 3288 2004-06-06 Fernando Perez <fperez@colorado.edu>
3284 3289
3285 3290 * IPython/Prompts.py (prompt_specials): Added the ability to have
3286 3291 bash-like special sequences in the prompts, which get
3287 3292 automatically expanded. Things like hostname, current working
3288 3293 directory and username are implemented already, but it's easy to
3289 3294 add more in the future. Thanks to a patch by W.J. van der Laan
3290 3295 <gnufnork-AT-hetdigitalegat.nl>
3291 3296 (prompt_specials): Added color support for prompt strings, so
3292 3297 users can define arbitrary color setups for their prompts.
3293 3298
3294 3299 2004-06-05 Fernando Perez <fperez@colorado.edu>
3295 3300
3296 3301 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
3297 3302 code to load Gary Bishop's readline and configure it
3298 3303 automatically. Thanks to Gary for help on this.
3299 3304
3300 3305 2004-06-01 Fernando Perez <fperez@colorado.edu>
3301 3306
3302 3307 * IPython/Logger.py (Logger.create_log): fix bug for logging
3303 3308 with no filename (previous fix was incomplete).
3304 3309
3305 3310 2004-05-25 Fernando Perez <fperez@colorado.edu>
3306 3311
3307 3312 * IPython/Magic.py (Magic.parse_options): fix bug where naked
3308 3313 parens would get passed to the shell.
3309 3314
3310 3315 2004-05-20 Fernando Perez <fperez@colorado.edu>
3311 3316
3312 3317 * IPython/Magic.py (Magic.magic_prun): changed default profile
3313 3318 sort order to 'time' (the more common profiling need).
3314 3319
3315 3320 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
3316 3321 so that source code shown is guaranteed in sync with the file on
3317 3322 disk (also changed in psource). Similar fix to the one for
3318 3323 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
3319 3324 <yann.ledu-AT-noos.fr>.
3320 3325
3321 3326 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
3322 3327 with a single option would not be correctly parsed. Closes
3323 3328 http://www.scipy.net/roundup/ipython/issue14. This bug had been
3324 3329 introduced in 0.6.0 (on 2004-05-06).
3325 3330
3326 3331 2004-05-13 *** Released version 0.6.0
3327 3332
3328 3333 2004-05-13 Fernando Perez <fperez@colorado.edu>
3329 3334
3330 3335 * debian/: Added debian/ directory to CVS, so that debian support
3331 3336 is publicly accessible. The debian package is maintained by Jack
3332 3337 Moffit <jack-AT-xiph.org>.
3333 3338
3334 3339 * Documentation: included the notes about an ipython-based system
3335 3340 shell (the hypothetical 'pysh') into the new_design.pdf document,
3336 3341 so that these ideas get distributed to users along with the
3337 3342 official documentation.
3338 3343
3339 3344 2004-05-10 Fernando Perez <fperez@colorado.edu>
3340 3345
3341 3346 * IPython/Logger.py (Logger.create_log): fix recently introduced
3342 3347 bug (misindented line) where logstart would fail when not given an
3343 3348 explicit filename.
3344 3349
3345 3350 2004-05-09 Fernando Perez <fperez@colorado.edu>
3346 3351
3347 3352 * IPython/Magic.py (Magic.parse_options): skip system call when
3348 3353 there are no options to look for. Faster, cleaner for the common
3349 3354 case.
3350 3355
3351 3356 * Documentation: many updates to the manual: describing Windows
3352 3357 support better, Gnuplot updates, credits, misc small stuff. Also
3353 3358 updated the new_design doc a bit.
3354 3359
3355 3360 2004-05-06 *** Released version 0.6.0.rc1
3356 3361
3357 3362 2004-05-06 Fernando Perez <fperez@colorado.edu>
3358 3363
3359 3364 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
3360 3365 operations to use the vastly more efficient list/''.join() method.
3361 3366 (FormattedTB.text): Fix
3362 3367 http://www.scipy.net/roundup/ipython/issue12 - exception source
3363 3368 extract not updated after reload. Thanks to Mike Salib
3364 3369 <msalib-AT-mit.edu> for pinning the source of the problem.
3365 3370 Fortunately, the solution works inside ipython and doesn't require
3366 3371 any changes to python proper.
3367 3372
3368 3373 * IPython/Magic.py (Magic.parse_options): Improved to process the
3369 3374 argument list as a true shell would (by actually using the
3370 3375 underlying system shell). This way, all @magics automatically get
3371 3376 shell expansion for variables. Thanks to a comment by Alex
3372 3377 Schmolck.
3373 3378
3374 3379 2004-04-04 Fernando Perez <fperez@colorado.edu>
3375 3380
3376 3381 * IPython/iplib.py (InteractiveShell.interact): Added a special
3377 3382 trap for a debugger quit exception, which is basically impossible
3378 3383 to handle by normal mechanisms, given what pdb does to the stack.
3379 3384 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
3380 3385
3381 3386 2004-04-03 Fernando Perez <fperez@colorado.edu>
3382 3387
3383 3388 * IPython/genutils.py (Term): Standardized the names of the Term
3384 3389 class streams to cin/cout/cerr, following C++ naming conventions
3385 3390 (I can't use in/out/err because 'in' is not a valid attribute
3386 3391 name).
3387 3392
3388 3393 * IPython/iplib.py (InteractiveShell.interact): don't increment
3389 3394 the prompt if there's no user input. By Daniel 'Dang' Griffith
3390 3395 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
3391 3396 Francois Pinard.
3392 3397
3393 3398 2004-04-02 Fernando Perez <fperez@colorado.edu>
3394 3399
3395 3400 * IPython/genutils.py (Stream.__init__): Modified to survive at
3396 3401 least importing in contexts where stdin/out/err aren't true file
3397 3402 objects, such as PyCrust (they lack fileno() and mode). However,
3398 3403 the recovery facilities which rely on these things existing will
3399 3404 not work.
3400 3405
3401 3406 2004-04-01 Fernando Perez <fperez@colorado.edu>
3402 3407
3403 3408 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
3404 3409 use the new getoutputerror() function, so it properly
3405 3410 distinguishes stdout/err.
3406 3411
3407 3412 * IPython/genutils.py (getoutputerror): added a function to
3408 3413 capture separately the standard output and error of a command.
3409 3414 After a comment from dang on the mailing lists. This code is
3410 3415 basically a modified version of commands.getstatusoutput(), from
3411 3416 the standard library.
3412 3417
3413 3418 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
3414 3419 '!!' as a special syntax (shorthand) to access @sx.
3415 3420
3416 3421 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
3417 3422 command and return its output as a list split on '\n'.
3418 3423
3419 3424 2004-03-31 Fernando Perez <fperez@colorado.edu>
3420 3425
3421 3426 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
3422 3427 method to dictionaries used as FakeModule instances if they lack
3423 3428 it. At least pydoc in python2.3 breaks for runtime-defined
3424 3429 functions without this hack. At some point I need to _really_
3425 3430 understand what FakeModule is doing, because it's a gross hack.
3426 3431 But it solves Arnd's problem for now...
3427 3432
3428 3433 2004-02-27 Fernando Perez <fperez@colorado.edu>
3429 3434
3430 3435 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
3431 3436 mode would behave erratically. Also increased the number of
3432 3437 possible logs in rotate mod to 999. Thanks to Rod Holland
3433 3438 <rhh@StructureLABS.com> for the report and fixes.
3434 3439
3435 3440 2004-02-26 Fernando Perez <fperez@colorado.edu>
3436 3441
3437 3442 * IPython/genutils.py (page): Check that the curses module really
3438 3443 has the initscr attribute before trying to use it. For some
3439 3444 reason, the Solaris curses module is missing this. I think this
3440 3445 should be considered a Solaris python bug, but I'm not sure.
3441 3446
3442 3447 2004-01-17 Fernando Perez <fperez@colorado.edu>
3443 3448
3444 3449 * IPython/genutils.py (Stream.__init__): Changes to try to make
3445 3450 ipython robust against stdin/out/err being closed by the user.
3446 3451 This is 'user error' (and blocks a normal python session, at least
3447 3452 the stdout case). However, Ipython should be able to survive such
3448 3453 instances of abuse as gracefully as possible. To simplify the
3449 3454 coding and maintain compatibility with Gary Bishop's Term
3450 3455 contributions, I've made use of classmethods for this. I think
3451 3456 this introduces a dependency on python 2.2.
3452 3457
3453 3458 2004-01-13 Fernando Perez <fperez@colorado.edu>
3454 3459
3455 3460 * IPython/numutils.py (exp_safe): simplified the code a bit and
3456 3461 removed the need for importing the kinds module altogether.
3457 3462
3458 3463 2004-01-06 Fernando Perez <fperez@colorado.edu>
3459 3464
3460 3465 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
3461 3466 a magic function instead, after some community feedback. No
3462 3467 special syntax will exist for it, but its name is deliberately
3463 3468 very short.
3464 3469
3465 3470 2003-12-20 Fernando Perez <fperez@colorado.edu>
3466 3471
3467 3472 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
3468 3473 new functionality, to automagically assign the result of a shell
3469 3474 command to a variable. I'll solicit some community feedback on
3470 3475 this before making it permanent.
3471 3476
3472 3477 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
3473 3478 requested about callables for which inspect couldn't obtain a
3474 3479 proper argspec. Thanks to a crash report sent by Etienne
3475 3480 Posthumus <etienne-AT-apple01.cs.vu.nl>.
3476 3481
3477 3482 2003-12-09 Fernando Perez <fperez@colorado.edu>
3478 3483
3479 3484 * IPython/genutils.py (page): patch for the pager to work across
3480 3485 various versions of Windows. By Gary Bishop.
3481 3486
3482 3487 2003-12-04 Fernando Perez <fperez@colorado.edu>
3483 3488
3484 3489 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
3485 3490 Gnuplot.py version 1.7, whose internal names changed quite a bit.
3486 3491 While I tested this and it looks ok, there may still be corner
3487 3492 cases I've missed.
3488 3493
3489 3494 2003-12-01 Fernando Perez <fperez@colorado.edu>
3490 3495
3491 3496 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
3492 3497 where a line like 'p,q=1,2' would fail because the automagic
3493 3498 system would be triggered for @p.
3494 3499
3495 3500 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
3496 3501 cleanups, code unmodified.
3497 3502
3498 3503 * IPython/genutils.py (Term): added a class for IPython to handle
3499 3504 output. In most cases it will just be a proxy for stdout/err, but
3500 3505 having this allows modifications to be made for some platforms,
3501 3506 such as handling color escapes under Windows. All of this code
3502 3507 was contributed by Gary Bishop, with minor modifications by me.
3503 3508 The actual changes affect many files.
3504 3509
3505 3510 2003-11-30 Fernando Perez <fperez@colorado.edu>
3506 3511
3507 3512 * IPython/iplib.py (file_matches): new completion code, courtesy
3508 3513 of Jeff Collins. This enables filename completion again under
3509 3514 python 2.3, which disabled it at the C level.
3510 3515
3511 3516 2003-11-11 Fernando Perez <fperez@colorado.edu>
3512 3517
3513 3518 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
3514 3519 for Numeric.array(map(...)), but often convenient.
3515 3520
3516 3521 2003-11-05 Fernando Perez <fperez@colorado.edu>
3517 3522
3518 3523 * IPython/numutils.py (frange): Changed a call from int() to
3519 3524 int(round()) to prevent a problem reported with arange() in the
3520 3525 numpy list.
3521 3526
3522 3527 2003-10-06 Fernando Perez <fperez@colorado.edu>
3523 3528
3524 3529 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
3525 3530 prevent crashes if sys lacks an argv attribute (it happens with
3526 3531 embedded interpreters which build a bare-bones sys module).
3527 3532 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
3528 3533
3529 3534 2003-09-24 Fernando Perez <fperez@colorado.edu>
3530 3535
3531 3536 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
3532 3537 to protect against poorly written user objects where __getattr__
3533 3538 raises exceptions other than AttributeError. Thanks to a bug
3534 3539 report by Oliver Sander <osander-AT-gmx.de>.
3535 3540
3536 3541 * IPython/FakeModule.py (FakeModule.__repr__): this method was
3537 3542 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
3538 3543
3539 3544 2003-09-09 Fernando Perez <fperez@colorado.edu>
3540 3545
3541 3546 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
3542 3547 unpacking a list whith a callable as first element would
3543 3548 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
3544 3549 Collins.
3545 3550
3546 3551 2003-08-25 *** Released version 0.5.0
3547 3552
3548 3553 2003-08-22 Fernando Perez <fperez@colorado.edu>
3549 3554
3550 3555 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
3551 3556 improperly defined user exceptions. Thanks to feedback from Mark
3552 3557 Russell <mrussell-AT-verio.net>.
3553 3558
3554 3559 2003-08-20 Fernando Perez <fperez@colorado.edu>
3555 3560
3556 3561 * IPython/OInspect.py (Inspector.pinfo): changed String Form
3557 3562 printing so that it would print multi-line string forms starting
3558 3563 with a new line. This way the formatting is better respected for
3559 3564 objects which work hard to make nice string forms.
3560 3565
3561 3566 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
3562 3567 autocall would overtake data access for objects with both
3563 3568 __getitem__ and __call__.
3564 3569
3565 3570 2003-08-19 *** Released version 0.5.0-rc1
3566 3571
3567 3572 2003-08-19 Fernando Perez <fperez@colorado.edu>
3568 3573
3569 3574 * IPython/deep_reload.py (load_tail): single tiny change here
3570 3575 seems to fix the long-standing bug of dreload() failing to work
3571 3576 for dotted names. But this module is pretty tricky, so I may have
3572 3577 missed some subtlety. Needs more testing!.
3573 3578
3574 3579 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
3575 3580 exceptions which have badly implemented __str__ methods.
3576 3581 (VerboseTB.text): harden against inspect.getinnerframes crashing,
3577 3582 which I've been getting reports about from Python 2.3 users. I
3578 3583 wish I had a simple test case to reproduce the problem, so I could
3579 3584 either write a cleaner workaround or file a bug report if
3580 3585 necessary.
3581 3586
3582 3587 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
3583 3588 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
3584 3589 a bug report by Tjabo Kloppenburg.
3585 3590
3586 3591 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
3587 3592 crashes. Wrapped the pdb call in a blanket try/except, since pdb
3588 3593 seems rather unstable. Thanks to a bug report by Tjabo
3589 3594 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
3590 3595
3591 3596 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
3592 3597 this out soon because of the critical fixes in the inner loop for
3593 3598 generators.
3594 3599
3595 3600 * IPython/Magic.py (Magic.getargspec): removed. This (and
3596 3601 _get_def) have been obsoleted by OInspect for a long time, I
3597 3602 hadn't noticed that they were dead code.
3598 3603 (Magic._ofind): restored _ofind functionality for a few literals
3599 3604 (those in ["''",'""','[]','{}','()']). But it won't work anymore
3600 3605 for things like "hello".capitalize?, since that would require a
3601 3606 potentially dangerous eval() again.
3602 3607
3603 3608 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
3604 3609 logic a bit more to clean up the escapes handling and minimize the
3605 3610 use of _ofind to only necessary cases. The interactive 'feel' of
3606 3611 IPython should have improved quite a bit with the changes in
3607 3612 _prefilter and _ofind (besides being far safer than before).
3608 3613
3609 3614 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
3610 3615 obscure, never reported). Edit would fail to find the object to
3611 3616 edit under some circumstances.
3612 3617 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
3613 3618 which were causing double-calling of generators. Those eval calls
3614 3619 were _very_ dangerous, since code with side effects could be
3615 3620 triggered. As they say, 'eval is evil'... These were the
3616 3621 nastiest evals in IPython. Besides, _ofind is now far simpler,
3617 3622 and it should also be quite a bit faster. Its use of inspect is
3618 3623 also safer, so perhaps some of the inspect-related crashes I've
3619 3624 seen lately with Python 2.3 might be taken care of. That will
3620 3625 need more testing.
3621 3626
3622 3627 2003-08-17 Fernando Perez <fperez@colorado.edu>
3623 3628
3624 3629 * IPython/iplib.py (InteractiveShell._prefilter): significant
3625 3630 simplifications to the logic for handling user escapes. Faster
3626 3631 and simpler code.
3627 3632
3628 3633 2003-08-14 Fernando Perez <fperez@colorado.edu>
3629 3634
3630 3635 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
3631 3636 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
3632 3637 but it should be quite a bit faster. And the recursive version
3633 3638 generated O(log N) intermediate storage for all rank>1 arrays,
3634 3639 even if they were contiguous.
3635 3640 (l1norm): Added this function.
3636 3641 (norm): Added this function for arbitrary norms (including
3637 3642 l-infinity). l1 and l2 are still special cases for convenience
3638 3643 and speed.
3639 3644
3640 3645 2003-08-03 Fernando Perez <fperez@colorado.edu>
3641 3646
3642 3647 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
3643 3648 exceptions, which now raise PendingDeprecationWarnings in Python
3644 3649 2.3. There were some in Magic and some in Gnuplot2.
3645 3650
3646 3651 2003-06-30 Fernando Perez <fperez@colorado.edu>
3647 3652
3648 3653 * IPython/genutils.py (page): modified to call curses only for
3649 3654 terminals where TERM=='xterm'. After problems under many other
3650 3655 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
3651 3656
3652 3657 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
3653 3658 would be triggered when readline was absent. This was just an old
3654 3659 debugging statement I'd forgotten to take out.
3655 3660
3656 3661 2003-06-20 Fernando Perez <fperez@colorado.edu>
3657 3662
3658 3663 * IPython/genutils.py (clock): modified to return only user time
3659 3664 (not counting system time), after a discussion on scipy. While
3660 3665 system time may be a useful quantity occasionally, it may much
3661 3666 more easily be skewed by occasional swapping or other similar
3662 3667 activity.
3663 3668
3664 3669 2003-06-05 Fernando Perez <fperez@colorado.edu>
3665 3670
3666 3671 * IPython/numutils.py (identity): new function, for building
3667 3672 arbitrary rank Kronecker deltas (mostly backwards compatible with
3668 3673 Numeric.identity)
3669 3674
3670 3675 2003-06-03 Fernando Perez <fperez@colorado.edu>
3671 3676
3672 3677 * IPython/iplib.py (InteractiveShell.handle_magic): protect
3673 3678 arguments passed to magics with spaces, to allow trailing '\' to
3674 3679 work normally (mainly for Windows users).
3675 3680
3676 3681 2003-05-29 Fernando Perez <fperez@colorado.edu>
3677 3682
3678 3683 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
3679 3684 instead of pydoc.help. This fixes a bizarre behavior where
3680 3685 printing '%s' % locals() would trigger the help system. Now
3681 3686 ipython behaves like normal python does.
3682 3687
3683 3688 Note that if one does 'from pydoc import help', the bizarre
3684 3689 behavior returns, but this will also happen in normal python, so
3685 3690 it's not an ipython bug anymore (it has to do with how pydoc.help
3686 3691 is implemented).
3687 3692
3688 3693 2003-05-22 Fernando Perez <fperez@colorado.edu>
3689 3694
3690 3695 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
3691 3696 return [] instead of None when nothing matches, also match to end
3692 3697 of line. Patch by Gary Bishop.
3693 3698
3694 3699 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
3695 3700 protection as before, for files passed on the command line. This
3696 3701 prevents the CrashHandler from kicking in if user files call into
3697 3702 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
3698 3703 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
3699 3704
3700 3705 2003-05-20 *** Released version 0.4.0
3701 3706
3702 3707 2003-05-20 Fernando Perez <fperez@colorado.edu>
3703 3708
3704 3709 * setup.py: added support for manpages. It's a bit hackish b/c of
3705 3710 a bug in the way the bdist_rpm distutils target handles gzipped
3706 3711 manpages, but it works. After a patch by Jack.
3707 3712
3708 3713 2003-05-19 Fernando Perez <fperez@colorado.edu>
3709 3714
3710 3715 * IPython/numutils.py: added a mockup of the kinds module, since
3711 3716 it was recently removed from Numeric. This way, numutils will
3712 3717 work for all users even if they are missing kinds.
3713 3718
3714 3719 * IPython/Magic.py (Magic._ofind): Harden against an inspect
3715 3720 failure, which can occur with SWIG-wrapped extensions. After a
3716 3721 crash report from Prabhu.
3717 3722
3718 3723 2003-05-16 Fernando Perez <fperez@colorado.edu>
3719 3724
3720 3725 * IPython/iplib.py (InteractiveShell.excepthook): New method to
3721 3726 protect ipython from user code which may call directly
3722 3727 sys.excepthook (this looks like an ipython crash to the user, even
3723 3728 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
3724 3729 This is especially important to help users of WxWindows, but may
3725 3730 also be useful in other cases.
3726 3731
3727 3732 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
3728 3733 an optional tb_offset to be specified, and to preserve exception
3729 3734 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
3730 3735
3731 3736 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
3732 3737
3733 3738 2003-05-15 Fernando Perez <fperez@colorado.edu>
3734 3739
3735 3740 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
3736 3741 installing for a new user under Windows.
3737 3742
3738 3743 2003-05-12 Fernando Perez <fperez@colorado.edu>
3739 3744
3740 3745 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
3741 3746 handler for Emacs comint-based lines. Currently it doesn't do
3742 3747 much (but importantly, it doesn't update the history cache). In
3743 3748 the future it may be expanded if Alex needs more functionality
3744 3749 there.
3745 3750
3746 3751 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
3747 3752 info to crash reports.
3748 3753
3749 3754 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
3750 3755 just like Python's -c. Also fixed crash with invalid -color
3751 3756 option value at startup. Thanks to Will French
3752 3757 <wfrench-AT-bestweb.net> for the bug report.
3753 3758
3754 3759 2003-05-09 Fernando Perez <fperez@colorado.edu>
3755 3760
3756 3761 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
3757 3762 to EvalDict (it's a mapping, after all) and simplified its code
3758 3763 quite a bit, after a nice discussion on c.l.py where Gustavo
3759 3764 CΓ³rdova <gcordova-AT-sismex.com> suggested the new version.
3760 3765
3761 3766 2003-04-30 Fernando Perez <fperez@colorado.edu>
3762 3767
3763 3768 * IPython/genutils.py (timings_out): modified it to reduce its
3764 3769 overhead in the common reps==1 case.
3765 3770
3766 3771 2003-04-29 Fernando Perez <fperez@colorado.edu>
3767 3772
3768 3773 * IPython/genutils.py (timings_out): Modified to use the resource
3769 3774 module, which avoids the wraparound problems of time.clock().
3770 3775
3771 3776 2003-04-17 *** Released version 0.2.15pre4
3772 3777
3773 3778 2003-04-17 Fernando Perez <fperez@colorado.edu>
3774 3779
3775 3780 * setup.py (scriptfiles): Split windows-specific stuff over to a
3776 3781 separate file, in an attempt to have a Windows GUI installer.
3777 3782 That didn't work, but part of the groundwork is done.
3778 3783
3779 3784 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
3780 3785 indent/unindent with 4 spaces. Particularly useful in combination
3781 3786 with the new auto-indent option.
3782 3787
3783 3788 2003-04-16 Fernando Perez <fperez@colorado.edu>
3784 3789
3785 3790 * IPython/Magic.py: various replacements of self.rc for
3786 3791 self.shell.rc. A lot more remains to be done to fully disentangle
3787 3792 this class from the main Shell class.
3788 3793
3789 3794 * IPython/GnuplotRuntime.py: added checks for mouse support so
3790 3795 that we don't try to enable it if the current gnuplot doesn't
3791 3796 really support it. Also added checks so that we don't try to
3792 3797 enable persist under Windows (where Gnuplot doesn't recognize the
3793 3798 option).
3794 3799
3795 3800 * IPython/iplib.py (InteractiveShell.interact): Added optional
3796 3801 auto-indenting code, after a patch by King C. Shu
3797 3802 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
3798 3803 get along well with pasting indented code. If I ever figure out
3799 3804 how to make that part go well, it will become on by default.
3800 3805
3801 3806 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
3802 3807 crash ipython if there was an unmatched '%' in the user's prompt
3803 3808 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
3804 3809
3805 3810 * IPython/iplib.py (InteractiveShell.interact): removed the
3806 3811 ability to ask the user whether he wants to crash or not at the
3807 3812 'last line' exception handler. Calling functions at that point
3808 3813 changes the stack, and the error reports would have incorrect
3809 3814 tracebacks.
3810 3815
3811 3816 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
3812 3817 pass through a peger a pretty-printed form of any object. After a
3813 3818 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
3814 3819
3815 3820 2003-04-14 Fernando Perez <fperez@colorado.edu>
3816 3821
3817 3822 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
3818 3823 all files in ~ would be modified at first install (instead of
3819 3824 ~/.ipython). This could be potentially disastrous, as the
3820 3825 modification (make line-endings native) could damage binary files.
3821 3826
3822 3827 2003-04-10 Fernando Perez <fperez@colorado.edu>
3823 3828
3824 3829 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
3825 3830 handle only lines which are invalid python. This now means that
3826 3831 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
3827 3832 for the bug report.
3828 3833
3829 3834 2003-04-01 Fernando Perez <fperez@colorado.edu>
3830 3835
3831 3836 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
3832 3837 where failing to set sys.last_traceback would crash pdb.pm().
3833 3838 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
3834 3839 report.
3835 3840
3836 3841 2003-03-25 Fernando Perez <fperez@colorado.edu>
3837 3842
3838 3843 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
3839 3844 before printing it (it had a lot of spurious blank lines at the
3840 3845 end).
3841 3846
3842 3847 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
3843 3848 output would be sent 21 times! Obviously people don't use this
3844 3849 too often, or I would have heard about it.
3845 3850
3846 3851 2003-03-24 Fernando Perez <fperez@colorado.edu>
3847 3852
3848 3853 * setup.py (scriptfiles): renamed the data_files parameter from
3849 3854 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
3850 3855 for the patch.
3851 3856
3852 3857 2003-03-20 Fernando Perez <fperez@colorado.edu>
3853 3858
3854 3859 * IPython/genutils.py (error): added error() and fatal()
3855 3860 functions.
3856 3861
3857 3862 2003-03-18 *** Released version 0.2.15pre3
3858 3863
3859 3864 2003-03-18 Fernando Perez <fperez@colorado.edu>
3860 3865
3861 3866 * setupext/install_data_ext.py
3862 3867 (install_data_ext.initialize_options): Class contributed by Jack
3863 3868 Moffit for fixing the old distutils hack. He is sending this to
3864 3869 the distutils folks so in the future we may not need it as a
3865 3870 private fix.
3866 3871
3867 3872 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
3868 3873 changes for Debian packaging. See his patch for full details.
3869 3874 The old distutils hack of making the ipythonrc* files carry a
3870 3875 bogus .py extension is gone, at last. Examples were moved to a
3871 3876 separate subdir under doc/, and the separate executable scripts
3872 3877 now live in their own directory. Overall a great cleanup. The
3873 3878 manual was updated to use the new files, and setup.py has been
3874 3879 fixed for this setup.
3875 3880
3876 3881 * IPython/PyColorize.py (Parser.usage): made non-executable and
3877 3882 created a pycolor wrapper around it to be included as a script.
3878 3883
3879 3884 2003-03-12 *** Released version 0.2.15pre2
3880 3885
3881 3886 2003-03-12 Fernando Perez <fperez@colorado.edu>
3882 3887
3883 3888 * IPython/ColorANSI.py (make_color_table): Finally fixed the
3884 3889 long-standing problem with garbage characters in some terminals.
3885 3890 The issue was really that the \001 and \002 escapes must _only_ be
3886 3891 passed to input prompts (which call readline), but _never_ to
3887 3892 normal text to be printed on screen. I changed ColorANSI to have
3888 3893 two classes: TermColors and InputTermColors, each with the
3889 3894 appropriate escapes for input prompts or normal text. The code in
3890 3895 Prompts.py got slightly more complicated, but this very old and
3891 3896 annoying bug is finally fixed.
3892 3897
3893 3898 All the credit for nailing down the real origin of this problem
3894 3899 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
3895 3900 *Many* thanks to him for spending quite a bit of effort on this.
3896 3901
3897 3902 2003-03-05 *** Released version 0.2.15pre1
3898 3903
3899 3904 2003-03-03 Fernando Perez <fperez@colorado.edu>
3900 3905
3901 3906 * IPython/FakeModule.py: Moved the former _FakeModule to a
3902 3907 separate file, because it's also needed by Magic (to fix a similar
3903 3908 pickle-related issue in @run).
3904 3909
3905 3910 2003-03-02 Fernando Perez <fperez@colorado.edu>
3906 3911
3907 3912 * IPython/Magic.py (Magic.magic_autocall): new magic to control
3908 3913 the autocall option at runtime.
3909 3914 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
3910 3915 across Magic.py to start separating Magic from InteractiveShell.
3911 3916 (Magic._ofind): Fixed to return proper namespace for dotted
3912 3917 names. Before, a dotted name would always return 'not currently
3913 3918 defined', because it would find the 'parent'. s.x would be found,
3914 3919 but since 'x' isn't defined by itself, it would get confused.
3915 3920 (Magic.magic_run): Fixed pickling problems reported by Ralf
3916 3921 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
3917 3922 that I'd used when Mike Heeter reported similar issues at the
3918 3923 top-level, but now for @run. It boils down to injecting the
3919 3924 namespace where code is being executed with something that looks
3920 3925 enough like a module to fool pickle.dump(). Since a pickle stores
3921 3926 a named reference to the importing module, we need this for
3922 3927 pickles to save something sensible.
3923 3928
3924 3929 * IPython/ipmaker.py (make_IPython): added an autocall option.
3925 3930
3926 3931 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
3927 3932 the auto-eval code. Now autocalling is an option, and the code is
3928 3933 also vastly safer. There is no more eval() involved at all.
3929 3934
3930 3935 2003-03-01 Fernando Perez <fperez@colorado.edu>
3931 3936
3932 3937 * IPython/Magic.py (Magic._ofind): Changed interface to return a
3933 3938 dict with named keys instead of a tuple.
3934 3939
3935 3940 * IPython: Started using CVS for IPython as of 0.2.15pre1.
3936 3941
3937 3942 * setup.py (make_shortcut): Fixed message about directories
3938 3943 created during Windows installation (the directories were ok, just
3939 3944 the printed message was misleading). Thanks to Chris Liechti
3940 3945 <cliechti-AT-gmx.net> for the heads up.
3941 3946
3942 3947 2003-02-21 Fernando Perez <fperez@colorado.edu>
3943 3948
3944 3949 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
3945 3950 of ValueError exception when checking for auto-execution. This
3946 3951 one is raised by things like Numeric arrays arr.flat when the
3947 3952 array is non-contiguous.
3948 3953
3949 3954 2003-01-31 Fernando Perez <fperez@colorado.edu>
3950 3955
3951 3956 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
3952 3957 not return any value at all (even though the command would get
3953 3958 executed).
3954 3959 (xsys): Flush stdout right after printing the command to ensure
3955 3960 proper ordering of commands and command output in the total
3956 3961 output.
3957 3962 (SystemExec/xsys/bq): Switched the names of xsys/bq and
3958 3963 system/getoutput as defaults. The old ones are kept for
3959 3964 compatibility reasons, so no code which uses this library needs
3960 3965 changing.
3961 3966
3962 3967 2003-01-27 *** Released version 0.2.14
3963 3968
3964 3969 2003-01-25 Fernando Perez <fperez@colorado.edu>
3965 3970
3966 3971 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
3967 3972 functions defined in previous edit sessions could not be re-edited
3968 3973 (because the temp files were immediately removed). Now temp files
3969 3974 are removed only at IPython's exit.
3970 3975 (Magic.magic_run): Improved @run to perform shell-like expansions
3971 3976 on its arguments (~users and $VARS). With this, @run becomes more
3972 3977 like a normal command-line.
3973 3978
3974 3979 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
3975 3980 bugs related to embedding and cleaned up that code. A fairly
3976 3981 important one was the impossibility to access the global namespace
3977 3982 through the embedded IPython (only local variables were visible).
3978 3983
3979 3984 2003-01-14 Fernando Perez <fperez@colorado.edu>
3980 3985
3981 3986 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
3982 3987 auto-calling to be a bit more conservative. Now it doesn't get
3983 3988 triggered if any of '!=()<>' are in the rest of the input line, to
3984 3989 allow comparing callables. Thanks to Alex for the heads up.
3985 3990
3986 3991 2003-01-07 Fernando Perez <fperez@colorado.edu>
3987 3992
3988 3993 * IPython/genutils.py (page): fixed estimation of the number of
3989 3994 lines in a string to be paged to simply count newlines. This
3990 3995 prevents over-guessing due to embedded escape sequences. A better
3991 3996 long-term solution would involve stripping out the control chars
3992 3997 for the count, but it's potentially so expensive I just don't
3993 3998 think it's worth doing.
3994 3999
3995 4000 2002-12-19 *** Released version 0.2.14pre50
3996 4001
3997 4002 2002-12-19 Fernando Perez <fperez@colorado.edu>
3998 4003
3999 4004 * tools/release (version): Changed release scripts to inform
4000 4005 Andrea and build a NEWS file with a list of recent changes.
4001 4006
4002 4007 * IPython/ColorANSI.py (__all__): changed terminal detection
4003 4008 code. Seems to work better for xterms without breaking
4004 4009 konsole. Will need more testing to determine if WinXP and Mac OSX
4005 4010 also work ok.
4006 4011
4007 4012 2002-12-18 *** Released version 0.2.14pre49
4008 4013
4009 4014 2002-12-18 Fernando Perez <fperez@colorado.edu>
4010 4015
4011 4016 * Docs: added new info about Mac OSX, from Andrea.
4012 4017
4013 4018 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
4014 4019 allow direct plotting of python strings whose format is the same
4015 4020 of gnuplot data files.
4016 4021
4017 4022 2002-12-16 Fernando Perez <fperez@colorado.edu>
4018 4023
4019 4024 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
4020 4025 value of exit question to be acknowledged.
4021 4026
4022 4027 2002-12-03 Fernando Perez <fperez@colorado.edu>
4023 4028
4024 4029 * IPython/ipmaker.py: removed generators, which had been added
4025 4030 by mistake in an earlier debugging run. This was causing trouble
4026 4031 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
4027 4032 for pointing this out.
4028 4033
4029 4034 2002-11-17 Fernando Perez <fperez@colorado.edu>
4030 4035
4031 4036 * Manual: updated the Gnuplot section.
4032 4037
4033 4038 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
4034 4039 a much better split of what goes in Runtime and what goes in
4035 4040 Interactive.
4036 4041
4037 4042 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
4038 4043 being imported from iplib.
4039 4044
4040 4045 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
4041 4046 for command-passing. Now the global Gnuplot instance is called
4042 4047 'gp' instead of 'g', which was really a far too fragile and
4043 4048 common name.
4044 4049
4045 4050 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
4046 4051 bounding boxes generated by Gnuplot for square plots.
4047 4052
4048 4053 * IPython/genutils.py (popkey): new function added. I should
4049 4054 suggest this on c.l.py as a dict method, it seems useful.
4050 4055
4051 4056 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
4052 4057 to transparently handle PostScript generation. MUCH better than
4053 4058 the previous plot_eps/replot_eps (which I removed now). The code
4054 4059 is also fairly clean and well documented now (including
4055 4060 docstrings).
4056 4061
4057 4062 2002-11-13 Fernando Perez <fperez@colorado.edu>
4058 4063
4059 4064 * IPython/Magic.py (Magic.magic_edit): fixed docstring
4060 4065 (inconsistent with options).
4061 4066
4062 4067 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
4063 4068 manually disabled, I don't know why. Fixed it.
4064 4069 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
4065 4070 eps output.
4066 4071
4067 4072 2002-11-12 Fernando Perez <fperez@colorado.edu>
4068 4073
4069 4074 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
4070 4075 don't propagate up to caller. Fixes crash reported by François
4071 4076 Pinard.
4072 4077
4073 4078 2002-11-09 Fernando Perez <fperez@colorado.edu>
4074 4079
4075 4080 * IPython/ipmaker.py (make_IPython): fixed problem with writing
4076 4081 history file for new users.
4077 4082 (make_IPython): fixed bug where initial install would leave the
4078 4083 user running in the .ipython dir.
4079 4084 (make_IPython): fixed bug where config dir .ipython would be
4080 4085 created regardless of the given -ipythondir option. Thanks to Cory
4081 4086 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
4082 4087
4083 4088 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
4084 4089 type confirmations. Will need to use it in all of IPython's code
4085 4090 consistently.
4086 4091
4087 4092 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
4088 4093 context to print 31 lines instead of the default 5. This will make
4089 4094 the crash reports extremely detailed in case the problem is in
4090 4095 libraries I don't have access to.
4091 4096
4092 4097 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
4093 4098 line of defense' code to still crash, but giving users fair
4094 4099 warning. I don't want internal errors to go unreported: if there's
4095 4100 an internal problem, IPython should crash and generate a full
4096 4101 report.
4097 4102
4098 4103 2002-11-08 Fernando Perez <fperez@colorado.edu>
4099 4104
4100 4105 * IPython/iplib.py (InteractiveShell.interact): added code to trap
4101 4106 otherwise uncaught exceptions which can appear if people set
4102 4107 sys.stdout to something badly broken. Thanks to a crash report
4103 4108 from henni-AT-mail.brainbot.com.
4104 4109
4105 4110 2002-11-04 Fernando Perez <fperez@colorado.edu>
4106 4111
4107 4112 * IPython/iplib.py (InteractiveShell.interact): added
4108 4113 __IPYTHON__active to the builtins. It's a flag which goes on when
4109 4114 the interaction starts and goes off again when it stops. This
4110 4115 allows embedding code to detect being inside IPython. Before this
4111 4116 was done via __IPYTHON__, but that only shows that an IPython
4112 4117 instance has been created.
4113 4118
4114 4119 * IPython/Magic.py (Magic.magic_env): I realized that in a
4115 4120 UserDict, instance.data holds the data as a normal dict. So I
4116 4121 modified @env to return os.environ.data instead of rebuilding a
4117 4122 dict by hand.
4118 4123
4119 4124 2002-11-02 Fernando Perez <fperez@colorado.edu>
4120 4125
4121 4126 * IPython/genutils.py (warn): changed so that level 1 prints no
4122 4127 header. Level 2 is now the default (with 'WARNING' header, as
4123 4128 before). I think I tracked all places where changes were needed in
4124 4129 IPython, but outside code using the old level numbering may have
4125 4130 broken.
4126 4131
4127 4132 * IPython/iplib.py (InteractiveShell.runcode): added this to
4128 4133 handle the tracebacks in SystemExit traps correctly. The previous
4129 4134 code (through interact) was printing more of the stack than
4130 4135 necessary, showing IPython internal code to the user.
4131 4136
4132 4137 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
4133 4138 default. Now that the default at the confirmation prompt is yes,
4134 4139 it's not so intrusive. François' argument that ipython sessions
4135 4140 tend to be complex enough not to lose them from an accidental C-d,
4136 4141 is a valid one.
4137 4142
4138 4143 * IPython/iplib.py (InteractiveShell.interact): added a
4139 4144 showtraceback() call to the SystemExit trap, and modified the exit
4140 4145 confirmation to have yes as the default.
4141 4146
4142 4147 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
4143 4148 this file. It's been gone from the code for a long time, this was
4144 4149 simply leftover junk.
4145 4150
4146 4151 2002-11-01 Fernando Perez <fperez@colorado.edu>
4147 4152
4148 4153 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
4149 4154 added. If set, IPython now traps EOF and asks for
4150 4155 confirmation. After a request by François Pinard.
4151 4156
4152 4157 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
4153 4158 of @abort, and with a new (better) mechanism for handling the
4154 4159 exceptions.
4155 4160
4156 4161 2002-10-27 Fernando Perez <fperez@colorado.edu>
4157 4162
4158 4163 * IPython/usage.py (__doc__): updated the --help information and
4159 4164 the ipythonrc file to indicate that -log generates
4160 4165 ./ipython.log. Also fixed the corresponding info in @logstart.
4161 4166 This and several other fixes in the manuals thanks to reports by
4162 4167 François Pinard <pinard-AT-iro.umontreal.ca>.
4163 4168
4164 4169 * IPython/Logger.py (Logger.switch_log): Fixed error message to
4165 4170 refer to @logstart (instead of @log, which doesn't exist).
4166 4171
4167 4172 * IPython/iplib.py (InteractiveShell._prefilter): fixed
4168 4173 AttributeError crash. Thanks to Christopher Armstrong
4169 4174 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
4170 4175 introduced recently (in 0.2.14pre37) with the fix to the eval
4171 4176 problem mentioned below.
4172 4177
4173 4178 2002-10-17 Fernando Perez <fperez@colorado.edu>
4174 4179
4175 4180 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
4176 4181 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
4177 4182
4178 4183 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
4179 4184 this function to fix a problem reported by Alex Schmolck. He saw
4180 4185 it with list comprehensions and generators, which were getting
4181 4186 called twice. The real problem was an 'eval' call in testing for
4182 4187 automagic which was evaluating the input line silently.
4183 4188
4184 4189 This is a potentially very nasty bug, if the input has side
4185 4190 effects which must not be repeated. The code is much cleaner now,
4186 4191 without any blanket 'except' left and with a regexp test for
4187 4192 actual function names.
4188 4193
4189 4194 But an eval remains, which I'm not fully comfortable with. I just
4190 4195 don't know how to find out if an expression could be a callable in
4191 4196 the user's namespace without doing an eval on the string. However
4192 4197 that string is now much more strictly checked so that no code
4193 4198 slips by, so the eval should only happen for things that can
4194 4199 really be only function/method names.
4195 4200
4196 4201 2002-10-15 Fernando Perez <fperez@colorado.edu>
4197 4202
4198 4203 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
4199 4204 OSX information to main manual, removed README_Mac_OSX file from
4200 4205 distribution. Also updated credits for recent additions.
4201 4206
4202 4207 2002-10-10 Fernando Perez <fperez@colorado.edu>
4203 4208
4204 4209 * README_Mac_OSX: Added a README for Mac OSX users for fixing
4205 4210 terminal-related issues. Many thanks to Andrea Riciputi
4206 4211 <andrea.riciputi-AT-libero.it> for writing it.
4207 4212
4208 4213 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
4209 4214 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
4210 4215
4211 4216 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
4212 4217 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
4213 4218 <syver-en-AT-online.no> who both submitted patches for this problem.
4214 4219
4215 4220 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
4216 4221 global embedding to make sure that things don't overwrite user
4217 4222 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
4218 4223
4219 4224 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
4220 4225 compatibility. Thanks to Hayden Callow
4221 4226 <h.callow-AT-elec.canterbury.ac.nz>
4222 4227
4223 4228 2002-10-04 Fernando Perez <fperez@colorado.edu>
4224 4229
4225 4230 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
4226 4231 Gnuplot.File objects.
4227 4232
4228 4233 2002-07-23 Fernando Perez <fperez@colorado.edu>
4229 4234
4230 4235 * IPython/genutils.py (timing): Added timings() and timing() for
4231 4236 quick access to the most commonly needed data, the execution
4232 4237 times. Old timing() renamed to timings_out().
4233 4238
4234 4239 2002-07-18 Fernando Perez <fperez@colorado.edu>
4235 4240
4236 4241 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
4237 4242 bug with nested instances disrupting the parent's tab completion.
4238 4243
4239 4244 * IPython/iplib.py (all_completions): Added Alex Schmolck's
4240 4245 all_completions code to begin the emacs integration.
4241 4246
4242 4247 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
4243 4248 argument to allow titling individual arrays when plotting.
4244 4249
4245 4250 2002-07-15 Fernando Perez <fperez@colorado.edu>
4246 4251
4247 4252 * setup.py (make_shortcut): changed to retrieve the value of
4248 4253 'Program Files' directory from the registry (this value changes in
4249 4254 non-english versions of Windows). Thanks to Thomas Fanslau
4250 4255 <tfanslau-AT-gmx.de> for the report.
4251 4256
4252 4257 2002-07-10 Fernando Perez <fperez@colorado.edu>
4253 4258
4254 4259 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
4255 4260 a bug in pdb, which crashes if a line with only whitespace is
4256 4261 entered. Bug report submitted to sourceforge.
4257 4262
4258 4263 2002-07-09 Fernando Perez <fperez@colorado.edu>
4259 4264
4260 4265 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
4261 4266 reporting exceptions (it's a bug in inspect.py, I just set a
4262 4267 workaround).
4263 4268
4264 4269 2002-07-08 Fernando Perez <fperez@colorado.edu>
4265 4270
4266 4271 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
4267 4272 __IPYTHON__ in __builtins__ to show up in user_ns.
4268 4273
4269 4274 2002-07-03 Fernando Perez <fperez@colorado.edu>
4270 4275
4271 4276 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
4272 4277 name from @gp_set_instance to @gp_set_default.
4273 4278
4274 4279 * IPython/ipmaker.py (make_IPython): default editor value set to
4275 4280 '0' (a string), to match the rc file. Otherwise will crash when
4276 4281 .strip() is called on it.
4277 4282
4278 4283
4279 4284 2002-06-28 Fernando Perez <fperez@colorado.edu>
4280 4285
4281 4286 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
4282 4287 of files in current directory when a file is executed via
4283 4288 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
4284 4289
4285 4290 * setup.py (manfiles): fix for rpm builds, submitted by RA
4286 4291 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
4287 4292
4288 4293 * IPython/ipmaker.py (make_IPython): fixed lookup of default
4289 4294 editor when set to '0'. Problem was, '0' evaluates to True (it's a
4290 4295 string!). A. Schmolck caught this one.
4291 4296
4292 4297 2002-06-27 Fernando Perez <fperez@colorado.edu>
4293 4298
4294 4299 * IPython/ipmaker.py (make_IPython): fixed bug when running user
4295 4300 defined files at the cmd line. __name__ wasn't being set to
4296 4301 __main__.
4297 4302
4298 4303 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
4299 4304 regular lists and tuples besides Numeric arrays.
4300 4305
4301 4306 * IPython/Prompts.py (CachedOutput.__call__): Added output
4302 4307 supression for input ending with ';'. Similar to Mathematica and
4303 4308 Matlab. The _* vars and Out[] list are still updated, just like
4304 4309 Mathematica behaves.
4305 4310
4306 4311 2002-06-25 Fernando Perez <fperez@colorado.edu>
4307 4312
4308 4313 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
4309 4314 .ini extensions for profiels under Windows.
4310 4315
4311 4316 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
4312 4317 string form. Fix contributed by Alexander Schmolck
4313 4318 <a.schmolck-AT-gmx.net>
4314 4319
4315 4320 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
4316 4321 pre-configured Gnuplot instance.
4317 4322
4318 4323 2002-06-21 Fernando Perez <fperez@colorado.edu>
4319 4324
4320 4325 * IPython/numutils.py (exp_safe): new function, works around the
4321 4326 underflow problems in Numeric.
4322 4327 (log2): New fn. Safe log in base 2: returns exact integer answer
4323 4328 for exact integer powers of 2.
4324 4329
4325 4330 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
4326 4331 properly.
4327 4332
4328 4333 2002-06-20 Fernando Perez <fperez@colorado.edu>
4329 4334
4330 4335 * IPython/genutils.py (timing): new function like
4331 4336 Mathematica's. Similar to time_test, but returns more info.
4332 4337
4333 4338 2002-06-18 Fernando Perez <fperez@colorado.edu>
4334 4339
4335 4340 * IPython/Magic.py (Magic.magic_save): modified @save and @r
4336 4341 according to Mike Heeter's suggestions.
4337 4342
4338 4343 2002-06-16 Fernando Perez <fperez@colorado.edu>
4339 4344
4340 4345 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
4341 4346 system. GnuplotMagic is gone as a user-directory option. New files
4342 4347 make it easier to use all the gnuplot stuff both from external
4343 4348 programs as well as from IPython. Had to rewrite part of
4344 4349 hardcopy() b/c of a strange bug: often the ps files simply don't
4345 4350 get created, and require a repeat of the command (often several
4346 4351 times).
4347 4352
4348 4353 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
4349 4354 resolve output channel at call time, so that if sys.stderr has
4350 4355 been redirected by user this gets honored.
4351 4356
4352 4357 2002-06-13 Fernando Perez <fperez@colorado.edu>
4353 4358
4354 4359 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
4355 4360 IPShell. Kept a copy with the old names to avoid breaking people's
4356 4361 embedded code.
4357 4362
4358 4363 * IPython/ipython: simplified it to the bare minimum after
4359 4364 Holger's suggestions. Added info about how to use it in
4360 4365 PYTHONSTARTUP.
4361 4366
4362 4367 * IPython/Shell.py (IPythonShell): changed the options passing
4363 4368 from a string with funky %s replacements to a straight list. Maybe
4364 4369 a bit more typing, but it follows sys.argv conventions, so there's
4365 4370 less special-casing to remember.
4366 4371
4367 4372 2002-06-12 Fernando Perez <fperez@colorado.edu>
4368 4373
4369 4374 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
4370 4375 command. Thanks to a suggestion by Mike Heeter.
4371 4376 (Magic.magic_pfile): added behavior to look at filenames if given
4372 4377 arg is not a defined object.
4373 4378 (Magic.magic_save): New @save function to save code snippets. Also
4374 4379 a Mike Heeter idea.
4375 4380
4376 4381 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
4377 4382 plot() and replot(). Much more convenient now, especially for
4378 4383 interactive use.
4379 4384
4380 4385 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
4381 4386 filenames.
4382 4387
4383 4388 2002-06-02 Fernando Perez <fperez@colorado.edu>
4384 4389
4385 4390 * IPython/Struct.py (Struct.__init__): modified to admit
4386 4391 initialization via another struct.
4387 4392
4388 4393 * IPython/genutils.py (SystemExec.__init__): New stateful
4389 4394 interface to xsys and bq. Useful for writing system scripts.
4390 4395
4391 4396 2002-05-30 Fernando Perez <fperez@colorado.edu>
4392 4397
4393 4398 * MANIFEST.in: Changed docfile selection to exclude all the lyx
4394 4399 documents. This will make the user download smaller (it's getting
4395 4400 too big).
4396 4401
4397 4402 2002-05-29 Fernando Perez <fperez@colorado.edu>
4398 4403
4399 4404 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
4400 4405 fix problems with shelve and pickle. Seems to work, but I don't
4401 4406 know if corner cases break it. Thanks to Mike Heeter
4402 4407 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
4403 4408
4404 4409 2002-05-24 Fernando Perez <fperez@colorado.edu>
4405 4410
4406 4411 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
4407 4412 macros having broken.
4408 4413
4409 4414 2002-05-21 Fernando Perez <fperez@colorado.edu>
4410 4415
4411 4416 * IPython/Magic.py (Magic.magic_logstart): fixed recently
4412 4417 introduced logging bug: all history before logging started was
4413 4418 being written one character per line! This came from the redesign
4414 4419 of the input history as a special list which slices to strings,
4415 4420 not to lists.
4416 4421
4417 4422 2002-05-20 Fernando Perez <fperez@colorado.edu>
4418 4423
4419 4424 * IPython/Prompts.py (CachedOutput.__init__): made the color table
4420 4425 be an attribute of all classes in this module. The design of these
4421 4426 classes needs some serious overhauling.
4422 4427
4423 4428 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
4424 4429 which was ignoring '_' in option names.
4425 4430
4426 4431 * IPython/ultraTB.py (FormattedTB.__init__): Changed
4427 4432 'Verbose_novars' to 'Context' and made it the new default. It's a
4428 4433 bit more readable and also safer than verbose.
4429 4434
4430 4435 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
4431 4436 triple-quoted strings.
4432 4437
4433 4438 * IPython/OInspect.py (__all__): new module exposing the object
4434 4439 introspection facilities. Now the corresponding magics are dummy
4435 4440 wrappers around this. Having this module will make it much easier
4436 4441 to put these functions into our modified pdb.
4437 4442 This new object inspector system uses the new colorizing module,
4438 4443 so source code and other things are nicely syntax highlighted.
4439 4444
4440 4445 2002-05-18 Fernando Perez <fperez@colorado.edu>
4441 4446
4442 4447 * IPython/ColorANSI.py: Split the coloring tools into a separate
4443 4448 module so I can use them in other code easier (they were part of
4444 4449 ultraTB).
4445 4450
4446 4451 2002-05-17 Fernando Perez <fperez@colorado.edu>
4447 4452
4448 4453 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
4449 4454 fixed it to set the global 'g' also to the called instance, as
4450 4455 long as 'g' was still a gnuplot instance (so it doesn't overwrite
4451 4456 user's 'g' variables).
4452 4457
4453 4458 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
4454 4459 global variables (aliases to _ih,_oh) so that users which expect
4455 4460 In[5] or Out[7] to work aren't unpleasantly surprised.
4456 4461 (InputList.__getslice__): new class to allow executing slices of
4457 4462 input history directly. Very simple class, complements the use of
4458 4463 macros.
4459 4464
4460 4465 2002-05-16 Fernando Perez <fperez@colorado.edu>
4461 4466
4462 4467 * setup.py (docdirbase): make doc directory be just doc/IPython
4463 4468 without version numbers, it will reduce clutter for users.
4464 4469
4465 4470 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
4466 4471 execfile call to prevent possible memory leak. See for details:
4467 4472 http://mail.python.org/pipermail/python-list/2002-February/088476.html
4468 4473
4469 4474 2002-05-15 Fernando Perez <fperez@colorado.edu>
4470 4475
4471 4476 * IPython/Magic.py (Magic.magic_psource): made the object
4472 4477 introspection names be more standard: pdoc, pdef, pfile and
4473 4478 psource. They all print/page their output, and it makes
4474 4479 remembering them easier. Kept old names for compatibility as
4475 4480 aliases.
4476 4481
4477 4482 2002-05-14 Fernando Perez <fperez@colorado.edu>
4478 4483
4479 4484 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
4480 4485 what the mouse problem was. The trick is to use gnuplot with temp
4481 4486 files and NOT with pipes (for data communication), because having
4482 4487 both pipes and the mouse on is bad news.
4483 4488
4484 4489 2002-05-13 Fernando Perez <fperez@colorado.edu>
4485 4490
4486 4491 * IPython/Magic.py (Magic._ofind): fixed namespace order search
4487 4492 bug. Information would be reported about builtins even when
4488 4493 user-defined functions overrode them.
4489 4494
4490 4495 2002-05-11 Fernando Perez <fperez@colorado.edu>
4491 4496
4492 4497 * IPython/__init__.py (__all__): removed FlexCompleter from
4493 4498 __all__ so that things don't fail in platforms without readline.
4494 4499
4495 4500 2002-05-10 Fernando Perez <fperez@colorado.edu>
4496 4501
4497 4502 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
4498 4503 it requires Numeric, effectively making Numeric a dependency for
4499 4504 IPython.
4500 4505
4501 4506 * Released 0.2.13
4502 4507
4503 4508 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
4504 4509 profiler interface. Now all the major options from the profiler
4505 4510 module are directly supported in IPython, both for single
4506 4511 expressions (@prun) and for full programs (@run -p).
4507 4512
4508 4513 2002-05-09 Fernando Perez <fperez@colorado.edu>
4509 4514
4510 4515 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
4511 4516 magic properly formatted for screen.
4512 4517
4513 4518 * setup.py (make_shortcut): Changed things to put pdf version in
4514 4519 doc/ instead of doc/manual (had to change lyxport a bit).
4515 4520
4516 4521 * IPython/Magic.py (Profile.string_stats): made profile runs go
4517 4522 through pager (they are long and a pager allows searching, saving,
4518 4523 etc.)
4519 4524
4520 4525 2002-05-08 Fernando Perez <fperez@colorado.edu>
4521 4526
4522 4527 * Released 0.2.12
4523 4528
4524 4529 2002-05-06 Fernando Perez <fperez@colorado.edu>
4525 4530
4526 4531 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
4527 4532 introduced); 'hist n1 n2' was broken.
4528 4533 (Magic.magic_pdb): added optional on/off arguments to @pdb
4529 4534 (Magic.magic_run): added option -i to @run, which executes code in
4530 4535 the IPython namespace instead of a clean one. Also added @irun as
4531 4536 an alias to @run -i.
4532 4537
4533 4538 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
4534 4539 fixed (it didn't really do anything, the namespaces were wrong).
4535 4540
4536 4541 * IPython/Debugger.py (__init__): Added workaround for python 2.1
4537 4542
4538 4543 * IPython/__init__.py (__all__): Fixed package namespace, now
4539 4544 'import IPython' does give access to IPython.<all> as
4540 4545 expected. Also renamed __release__ to Release.
4541 4546
4542 4547 * IPython/Debugger.py (__license__): created new Pdb class which
4543 4548 functions like a drop-in for the normal pdb.Pdb but does NOT
4544 4549 import readline by default. This way it doesn't muck up IPython's
4545 4550 readline handling, and now tab-completion finally works in the
4546 4551 debugger -- sort of. It completes things globally visible, but the
4547 4552 completer doesn't track the stack as pdb walks it. That's a bit
4548 4553 tricky, and I'll have to implement it later.
4549 4554
4550 4555 2002-05-05 Fernando Perez <fperez@colorado.edu>
4551 4556
4552 4557 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
4553 4558 magic docstrings when printed via ? (explicit \'s were being
4554 4559 printed).
4555 4560
4556 4561 * IPython/ipmaker.py (make_IPython): fixed namespace
4557 4562 identification bug. Now variables loaded via logs or command-line
4558 4563 files are recognized in the interactive namespace by @who.
4559 4564
4560 4565 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
4561 4566 log replay system stemming from the string form of Structs.
4562 4567
4563 4568 * IPython/Magic.py (Macro.__init__): improved macros to properly
4564 4569 handle magic commands in them.
4565 4570 (Magic.magic_logstart): usernames are now expanded so 'logstart
4566 4571 ~/mylog' now works.
4567 4572
4568 4573 * IPython/iplib.py (complete): fixed bug where paths starting with
4569 4574 '/' would be completed as magic names.
4570 4575
4571 4576 2002-05-04 Fernando Perez <fperez@colorado.edu>
4572 4577
4573 4578 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
4574 4579 allow running full programs under the profiler's control.
4575 4580
4576 4581 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
4577 4582 mode to report exceptions verbosely but without formatting
4578 4583 variables. This addresses the issue of ipython 'freezing' (it's
4579 4584 not frozen, but caught in an expensive formatting loop) when huge
4580 4585 variables are in the context of an exception.
4581 4586 (VerboseTB.text): Added '--->' markers at line where exception was
4582 4587 triggered. Much clearer to read, especially in NoColor modes.
4583 4588
4584 4589 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
4585 4590 implemented in reverse when changing to the new parse_options().
4586 4591
4587 4592 2002-05-03 Fernando Perez <fperez@colorado.edu>
4588 4593
4589 4594 * IPython/Magic.py (Magic.parse_options): new function so that
4590 4595 magics can parse options easier.
4591 4596 (Magic.magic_prun): new function similar to profile.run(),
4592 4597 suggested by Chris Hart.
4593 4598 (Magic.magic_cd): fixed behavior so that it only changes if
4594 4599 directory actually is in history.
4595 4600
4596 4601 * IPython/usage.py (__doc__): added information about potential
4597 4602 slowness of Verbose exception mode when there are huge data
4598 4603 structures to be formatted (thanks to Archie Paulson).
4599 4604
4600 4605 * IPython/ipmaker.py (make_IPython): Changed default logging
4601 4606 (when simply called with -log) to use curr_dir/ipython.log in
4602 4607 rotate mode. Fixed crash which was occuring with -log before
4603 4608 (thanks to Jim Boyle).
4604 4609
4605 4610 2002-05-01 Fernando Perez <fperez@colorado.edu>
4606 4611
4607 4612 * Released 0.2.11 for these fixes (mainly the ultraTB one which
4608 4613 was nasty -- though somewhat of a corner case).
4609 4614
4610 4615 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
4611 4616 text (was a bug).
4612 4617
4613 4618 2002-04-30 Fernando Perez <fperez@colorado.edu>
4614 4619
4615 4620 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
4616 4621 a print after ^D or ^C from the user so that the In[] prompt
4617 4622 doesn't over-run the gnuplot one.
4618 4623
4619 4624 2002-04-29 Fernando Perez <fperez@colorado.edu>
4620 4625
4621 4626 * Released 0.2.10
4622 4627
4623 4628 * IPython/__release__.py (version): get date dynamically.
4624 4629
4625 4630 * Misc. documentation updates thanks to Arnd's comments. Also ran
4626 4631 a full spellcheck on the manual (hadn't been done in a while).
4627 4632
4628 4633 2002-04-27 Fernando Perez <fperez@colorado.edu>
4629 4634
4630 4635 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
4631 4636 starting a log in mid-session would reset the input history list.
4632 4637
4633 4638 2002-04-26 Fernando Perez <fperez@colorado.edu>
4634 4639
4635 4640 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
4636 4641 all files were being included in an update. Now anything in
4637 4642 UserConfig that matches [A-Za-z]*.py will go (this excludes
4638 4643 __init__.py)
4639 4644
4640 4645 2002-04-25 Fernando Perez <fperez@colorado.edu>
4641 4646
4642 4647 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
4643 4648 to __builtins__ so that any form of embedded or imported code can
4644 4649 test for being inside IPython.
4645 4650
4646 4651 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
4647 4652 changed to GnuplotMagic because it's now an importable module,
4648 4653 this makes the name follow that of the standard Gnuplot module.
4649 4654 GnuplotMagic can now be loaded at any time in mid-session.
4650 4655
4651 4656 2002-04-24 Fernando Perez <fperez@colorado.edu>
4652 4657
4653 4658 * IPython/numutils.py: removed SIUnits. It doesn't properly set
4654 4659 the globals (IPython has its own namespace) and the
4655 4660 PhysicalQuantity stuff is much better anyway.
4656 4661
4657 4662 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
4658 4663 embedding example to standard user directory for
4659 4664 distribution. Also put it in the manual.
4660 4665
4661 4666 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
4662 4667 instance as first argument (so it doesn't rely on some obscure
4663 4668 hidden global).
4664 4669
4665 4670 * IPython/UserConfig/ipythonrc.py: put () back in accepted
4666 4671 delimiters. While it prevents ().TAB from working, it allows
4667 4672 completions in open (... expressions. This is by far a more common
4668 4673 case.
4669 4674
4670 4675 2002-04-23 Fernando Perez <fperez@colorado.edu>
4671 4676
4672 4677 * IPython/Extensions/InterpreterPasteInput.py: new
4673 4678 syntax-processing module for pasting lines with >>> or ... at the
4674 4679 start.
4675 4680
4676 4681 * IPython/Extensions/PhysicalQ_Interactive.py
4677 4682 (PhysicalQuantityInteractive.__int__): fixed to work with either
4678 4683 Numeric or math.
4679 4684
4680 4685 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
4681 4686 provided profiles. Now we have:
4682 4687 -math -> math module as * and cmath with its own namespace.
4683 4688 -numeric -> Numeric as *, plus gnuplot & grace
4684 4689 -physics -> same as before
4685 4690
4686 4691 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
4687 4692 user-defined magics wouldn't be found by @magic if they were
4688 4693 defined as class methods. Also cleaned up the namespace search
4689 4694 logic and the string building (to use %s instead of many repeated
4690 4695 string adds).
4691 4696
4692 4697 * IPython/UserConfig/example-magic.py (magic_foo): updated example
4693 4698 of user-defined magics to operate with class methods (cleaner, in
4694 4699 line with the gnuplot code).
4695 4700
4696 4701 2002-04-22 Fernando Perez <fperez@colorado.edu>
4697 4702
4698 4703 * setup.py: updated dependency list so that manual is updated when
4699 4704 all included files change.
4700 4705
4701 4706 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
4702 4707 the delimiter removal option (the fix is ugly right now).
4703 4708
4704 4709 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
4705 4710 all of the math profile (quicker loading, no conflict between
4706 4711 g-9.8 and g-gnuplot).
4707 4712
4708 4713 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
4709 4714 name of post-mortem files to IPython_crash_report.txt.
4710 4715
4711 4716 * Cleanup/update of the docs. Added all the new readline info and
4712 4717 formatted all lists as 'real lists'.
4713 4718
4714 4719 * IPython/ipmaker.py (make_IPython): removed now-obsolete
4715 4720 tab-completion options, since the full readline parse_and_bind is
4716 4721 now accessible.
4717 4722
4718 4723 * IPython/iplib.py (InteractiveShell.init_readline): Changed
4719 4724 handling of readline options. Now users can specify any string to
4720 4725 be passed to parse_and_bind(), as well as the delimiters to be
4721 4726 removed.
4722 4727 (InteractiveShell.__init__): Added __name__ to the global
4723 4728 namespace so that things like Itpl which rely on its existence
4724 4729 don't crash.
4725 4730 (InteractiveShell._prefilter): Defined the default with a _ so
4726 4731 that prefilter() is easier to override, while the default one
4727 4732 remains available.
4728 4733
4729 4734 2002-04-18 Fernando Perez <fperez@colorado.edu>
4730 4735
4731 4736 * Added information about pdb in the docs.
4732 4737
4733 4738 2002-04-17 Fernando Perez <fperez@colorado.edu>
4734 4739
4735 4740 * IPython/ipmaker.py (make_IPython): added rc_override option to
4736 4741 allow passing config options at creation time which may override
4737 4742 anything set in the config files or command line. This is
4738 4743 particularly useful for configuring embedded instances.
4739 4744
4740 4745 2002-04-15 Fernando Perez <fperez@colorado.edu>
4741 4746
4742 4747 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
4743 4748 crash embedded instances because of the input cache falling out of
4744 4749 sync with the output counter.
4745 4750
4746 4751 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
4747 4752 mode which calls pdb after an uncaught exception in IPython itself.
4748 4753
4749 4754 2002-04-14 Fernando Perez <fperez@colorado.edu>
4750 4755
4751 4756 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
4752 4757 readline, fix it back after each call.
4753 4758
4754 4759 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
4755 4760 method to force all access via __call__(), which guarantees that
4756 4761 traceback references are properly deleted.
4757 4762
4758 4763 * IPython/Prompts.py (CachedOutput._display): minor fixes to
4759 4764 improve printing when pprint is in use.
4760 4765
4761 4766 2002-04-13 Fernando Perez <fperez@colorado.edu>
4762 4767
4763 4768 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
4764 4769 exceptions aren't caught anymore. If the user triggers one, he
4765 4770 should know why he's doing it and it should go all the way up,
4766 4771 just like any other exception. So now @abort will fully kill the
4767 4772 embedded interpreter and the embedding code (unless that happens
4768 4773 to catch SystemExit).
4769 4774
4770 4775 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
4771 4776 and a debugger() method to invoke the interactive pdb debugger
4772 4777 after printing exception information. Also added the corresponding
4773 4778 -pdb option and @pdb magic to control this feature, and updated
4774 4779 the docs. After a suggestion from Christopher Hart
4775 4780 (hart-AT-caltech.edu).
4776 4781
4777 4782 2002-04-12 Fernando Perez <fperez@colorado.edu>
4778 4783
4779 4784 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
4780 4785 the exception handlers defined by the user (not the CrashHandler)
4781 4786 so that user exceptions don't trigger an ipython bug report.
4782 4787
4783 4788 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
4784 4789 configurable (it should have always been so).
4785 4790
4786 4791 2002-03-26 Fernando Perez <fperez@colorado.edu>
4787 4792
4788 4793 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
4789 4794 and there to fix embedding namespace issues. This should all be
4790 4795 done in a more elegant way.
4791 4796
4792 4797 2002-03-25 Fernando Perez <fperez@colorado.edu>
4793 4798
4794 4799 * IPython/genutils.py (get_home_dir): Try to make it work under
4795 4800 win9x also.
4796 4801
4797 4802 2002-03-20 Fernando Perez <fperez@colorado.edu>
4798 4803
4799 4804 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
4800 4805 sys.displayhook untouched upon __init__.
4801 4806
4802 4807 2002-03-19 Fernando Perez <fperez@colorado.edu>
4803 4808
4804 4809 * Released 0.2.9 (for embedding bug, basically).
4805 4810
4806 4811 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
4807 4812 exceptions so that enclosing shell's state can be restored.
4808 4813
4809 4814 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
4810 4815 naming conventions in the .ipython/ dir.
4811 4816
4812 4817 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
4813 4818 from delimiters list so filenames with - in them get expanded.
4814 4819
4815 4820 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
4816 4821 sys.displayhook not being properly restored after an embedded call.
4817 4822
4818 4823 2002-03-18 Fernando Perez <fperez@colorado.edu>
4819 4824
4820 4825 * Released 0.2.8
4821 4826
4822 4827 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
4823 4828 some files weren't being included in a -upgrade.
4824 4829 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
4825 4830 on' so that the first tab completes.
4826 4831 (InteractiveShell.handle_magic): fixed bug with spaces around
4827 4832 quotes breaking many magic commands.
4828 4833
4829 4834 * setup.py: added note about ignoring the syntax error messages at
4830 4835 installation.
4831 4836
4832 4837 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
4833 4838 streamlining the gnuplot interface, now there's only one magic @gp.
4834 4839
4835 4840 2002-03-17 Fernando Perez <fperez@colorado.edu>
4836 4841
4837 4842 * IPython/UserConfig/magic_gnuplot.py: new name for the
4838 4843 example-magic_pm.py file. Much enhanced system, now with a shell
4839 4844 for communicating directly with gnuplot, one command at a time.
4840 4845
4841 4846 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
4842 4847 setting __name__=='__main__'.
4843 4848
4844 4849 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
4845 4850 mini-shell for accessing gnuplot from inside ipython. Should
4846 4851 extend it later for grace access too. Inspired by Arnd's
4847 4852 suggestion.
4848 4853
4849 4854 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
4850 4855 calling magic functions with () in their arguments. Thanks to Arnd
4851 4856 Baecker for pointing this to me.
4852 4857
4853 4858 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
4854 4859 infinitely for integer or complex arrays (only worked with floats).
4855 4860
4856 4861 2002-03-16 Fernando Perez <fperez@colorado.edu>
4857 4862
4858 4863 * setup.py: Merged setup and setup_windows into a single script
4859 4864 which properly handles things for windows users.
4860 4865
4861 4866 2002-03-15 Fernando Perez <fperez@colorado.edu>
4862 4867
4863 4868 * Big change to the manual: now the magics are all automatically
4864 4869 documented. This information is generated from their docstrings
4865 4870 and put in a latex file included by the manual lyx file. This way
4866 4871 we get always up to date information for the magics. The manual
4867 4872 now also has proper version information, also auto-synced.
4868 4873
4869 4874 For this to work, an undocumented --magic_docstrings option was added.
4870 4875
4871 4876 2002-03-13 Fernando Perez <fperez@colorado.edu>
4872 4877
4873 4878 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
4874 4879 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
4875 4880
4876 4881 2002-03-12 Fernando Perez <fperez@colorado.edu>
4877 4882
4878 4883 * IPython/ultraTB.py (TermColors): changed color escapes again to
4879 4884 fix the (old, reintroduced) line-wrapping bug. Basically, if
4880 4885 \001..\002 aren't given in the color escapes, lines get wrapped
4881 4886 weirdly. But giving those screws up old xterms and emacs terms. So
4882 4887 I added some logic for emacs terms to be ok, but I can't identify old
4883 4888 xterms separately ($TERM=='xterm' for many terminals, like konsole).
4884 4889
4885 4890 2002-03-10 Fernando Perez <fperez@colorado.edu>
4886 4891
4887 4892 * IPython/usage.py (__doc__): Various documentation cleanups and
4888 4893 updates, both in usage docstrings and in the manual.
4889 4894
4890 4895 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
4891 4896 handling of caching. Set minimum acceptabe value for having a
4892 4897 cache at 20 values.
4893 4898
4894 4899 * IPython/iplib.py (InteractiveShell.user_setup): moved the
4895 4900 install_first_time function to a method, renamed it and added an
4896 4901 'upgrade' mode. Now people can update their config directory with
4897 4902 a simple command line switch (-upgrade, also new).
4898 4903
4899 4904 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
4900 4905 @file (convenient for automagic users under Python >= 2.2).
4901 4906 Removed @files (it seemed more like a plural than an abbrev. of
4902 4907 'file show').
4903 4908
4904 4909 * IPython/iplib.py (install_first_time): Fixed crash if there were
4905 4910 backup files ('~') in .ipython/ install directory.
4906 4911
4907 4912 * IPython/ipmaker.py (make_IPython): fixes for new prompt
4908 4913 system. Things look fine, but these changes are fairly
4909 4914 intrusive. Test them for a few days.
4910 4915
4911 4916 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
4912 4917 the prompts system. Now all in/out prompt strings are user
4913 4918 controllable. This is particularly useful for embedding, as one
4914 4919 can tag embedded instances with particular prompts.
4915 4920
4916 4921 Also removed global use of sys.ps1/2, which now allows nested
4917 4922 embeddings without any problems. Added command-line options for
4918 4923 the prompt strings.
4919 4924
4920 4925 2002-03-08 Fernando Perez <fperez@colorado.edu>
4921 4926
4922 4927 * IPython/UserConfig/example-embed-short.py (ipshell): added
4923 4928 example file with the bare minimum code for embedding.
4924 4929
4925 4930 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
4926 4931 functionality for the embeddable shell to be activated/deactivated
4927 4932 either globally or at each call.
4928 4933
4929 4934 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
4930 4935 rewriting the prompt with '--->' for auto-inputs with proper
4931 4936 coloring. Now the previous UGLY hack in handle_auto() is gone, and
4932 4937 this is handled by the prompts class itself, as it should.
4933 4938
4934 4939 2002-03-05 Fernando Perez <fperez@colorado.edu>
4935 4940
4936 4941 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
4937 4942 @logstart to avoid name clashes with the math log function.
4938 4943
4939 4944 * Big updates to X/Emacs section of the manual.
4940 4945
4941 4946 * Removed ipython_emacs. Milan explained to me how to pass
4942 4947 arguments to ipython through Emacs. Some day I'm going to end up
4943 4948 learning some lisp...
4944 4949
4945 4950 2002-03-04 Fernando Perez <fperez@colorado.edu>
4946 4951
4947 4952 * IPython/ipython_emacs: Created script to be used as the
4948 4953 py-python-command Emacs variable so we can pass IPython
4949 4954 parameters. I can't figure out how to tell Emacs directly to pass
4950 4955 parameters to IPython, so a dummy shell script will do it.
4951 4956
4952 4957 Other enhancements made for things to work better under Emacs'
4953 4958 various types of terminals. Many thanks to Milan Zamazal
4954 4959 <pdm-AT-zamazal.org> for all the suggestions and pointers.
4955 4960
4956 4961 2002-03-01 Fernando Perez <fperez@colorado.edu>
4957 4962
4958 4963 * IPython/ipmaker.py (make_IPython): added a --readline! option so
4959 4964 that loading of readline is now optional. This gives better
4960 4965 control to emacs users.
4961 4966
4962 4967 * IPython/ultraTB.py (__date__): Modified color escape sequences
4963 4968 and now things work fine under xterm and in Emacs' term buffers
4964 4969 (though not shell ones). Well, in emacs you get colors, but all
4965 4970 seem to be 'light' colors (no difference between dark and light
4966 4971 ones). But the garbage chars are gone, and also in xterms. It
4967 4972 seems that now I'm using 'cleaner' ansi sequences.
4968 4973
4969 4974 2002-02-21 Fernando Perez <fperez@colorado.edu>
4970 4975
4971 4976 * Released 0.2.7 (mainly to publish the scoping fix).
4972 4977
4973 4978 * IPython/Logger.py (Logger.logstate): added. A corresponding
4974 4979 @logstate magic was created.
4975 4980
4976 4981 * IPython/Magic.py: fixed nested scoping problem under Python
4977 4982 2.1.x (automagic wasn't working).
4978 4983
4979 4984 2002-02-20 Fernando Perez <fperez@colorado.edu>
4980 4985
4981 4986 * Released 0.2.6.
4982 4987
4983 4988 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
4984 4989 option so that logs can come out without any headers at all.
4985 4990
4986 4991 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
4987 4992 SciPy.
4988 4993
4989 4994 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
4990 4995 that embedded IPython calls don't require vars() to be explicitly
4991 4996 passed. Now they are extracted from the caller's frame (code
4992 4997 snatched from Eric Jones' weave). Added better documentation to
4993 4998 the section on embedding and the example file.
4994 4999
4995 5000 * IPython/genutils.py (page): Changed so that under emacs, it just
4996 5001 prints the string. You can then page up and down in the emacs
4997 5002 buffer itself. This is how the builtin help() works.
4998 5003
4999 5004 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
5000 5005 macro scoping: macros need to be executed in the user's namespace
5001 5006 to work as if they had been typed by the user.
5002 5007
5003 5008 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
5004 5009 execute automatically (no need to type 'exec...'). They then
5005 5010 behave like 'true macros'. The printing system was also modified
5006 5011 for this to work.
5007 5012
5008 5013 2002-02-19 Fernando Perez <fperez@colorado.edu>
5009 5014
5010 5015 * IPython/genutils.py (page_file): new function for paging files
5011 5016 in an OS-independent way. Also necessary for file viewing to work
5012 5017 well inside Emacs buffers.
5013 5018 (page): Added checks for being in an emacs buffer.
5014 5019 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
5015 5020 same bug in iplib.
5016 5021
5017 5022 2002-02-18 Fernando Perez <fperez@colorado.edu>
5018 5023
5019 5024 * IPython/iplib.py (InteractiveShell.init_readline): modified use
5020 5025 of readline so that IPython can work inside an Emacs buffer.
5021 5026
5022 5027 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
5023 5028 method signatures (they weren't really bugs, but it looks cleaner
5024 5029 and keeps PyChecker happy).
5025 5030
5026 5031 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
5027 5032 for implementing various user-defined hooks. Currently only
5028 5033 display is done.
5029 5034
5030 5035 * IPython/Prompts.py (CachedOutput._display): changed display
5031 5036 functions so that they can be dynamically changed by users easily.
5032 5037
5033 5038 * IPython/Extensions/numeric_formats.py (num_display): added an
5034 5039 extension for printing NumPy arrays in flexible manners. It
5035 5040 doesn't do anything yet, but all the structure is in
5036 5041 place. Ultimately the plan is to implement output format control
5037 5042 like in Octave.
5038 5043
5039 5044 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
5040 5045 methods are found at run-time by all the automatic machinery.
5041 5046
5042 5047 2002-02-17 Fernando Perez <fperez@colorado.edu>
5043 5048
5044 5049 * setup_Windows.py (make_shortcut): documented. Cleaned up the
5045 5050 whole file a little.
5046 5051
5047 5052 * ToDo: closed this document. Now there's a new_design.lyx
5048 5053 document for all new ideas. Added making a pdf of it for the
5049 5054 end-user distro.
5050 5055
5051 5056 * IPython/Logger.py (Logger.switch_log): Created this to replace
5052 5057 logon() and logoff(). It also fixes a nasty crash reported by
5053 5058 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
5054 5059
5055 5060 * IPython/iplib.py (complete): got auto-completion to work with
5056 5061 automagic (I had wanted this for a long time).
5057 5062
5058 5063 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
5059 5064 to @file, since file() is now a builtin and clashes with automagic
5060 5065 for @file.
5061 5066
5062 5067 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
5063 5068 of this was previously in iplib, which had grown to more than 2000
5064 5069 lines, way too long. No new functionality, but it makes managing
5065 5070 the code a bit easier.
5066 5071
5067 5072 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
5068 5073 information to crash reports.
5069 5074
5070 5075 2002-02-12 Fernando Perez <fperez@colorado.edu>
5071 5076
5072 5077 * Released 0.2.5.
5073 5078
5074 5079 2002-02-11 Fernando Perez <fperez@colorado.edu>
5075 5080
5076 5081 * Wrote a relatively complete Windows installer. It puts
5077 5082 everything in place, creates Start Menu entries and fixes the
5078 5083 color issues. Nothing fancy, but it works.
5079 5084
5080 5085 2002-02-10 Fernando Perez <fperez@colorado.edu>
5081 5086
5082 5087 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
5083 5088 os.path.expanduser() call so that we can type @run ~/myfile.py and
5084 5089 have thigs work as expected.
5085 5090
5086 5091 * IPython/genutils.py (page): fixed exception handling so things
5087 5092 work both in Unix and Windows correctly. Quitting a pager triggers
5088 5093 an IOError/broken pipe in Unix, and in windows not finding a pager
5089 5094 is also an IOError, so I had to actually look at the return value
5090 5095 of the exception, not just the exception itself. Should be ok now.
5091 5096
5092 5097 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
5093 5098 modified to allow case-insensitive color scheme changes.
5094 5099
5095 5100 2002-02-09 Fernando Perez <fperez@colorado.edu>
5096 5101
5097 5102 * IPython/genutils.py (native_line_ends): new function to leave
5098 5103 user config files with os-native line-endings.
5099 5104
5100 5105 * README and manual updates.
5101 5106
5102 5107 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
5103 5108 instead of StringType to catch Unicode strings.
5104 5109
5105 5110 * IPython/genutils.py (filefind): fixed bug for paths with
5106 5111 embedded spaces (very common in Windows).
5107 5112
5108 5113 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
5109 5114 files under Windows, so that they get automatically associated
5110 5115 with a text editor. Windows makes it a pain to handle
5111 5116 extension-less files.
5112 5117
5113 5118 * IPython/iplib.py (InteractiveShell.init_readline): Made the
5114 5119 warning about readline only occur for Posix. In Windows there's no
5115 5120 way to get readline, so why bother with the warning.
5116 5121
5117 5122 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
5118 5123 for __str__ instead of dir(self), since dir() changed in 2.2.
5119 5124
5120 5125 * Ported to Windows! Tested on XP, I suspect it should work fine
5121 5126 on NT/2000, but I don't think it will work on 98 et al. That
5122 5127 series of Windows is such a piece of junk anyway that I won't try
5123 5128 porting it there. The XP port was straightforward, showed a few
5124 5129 bugs here and there (fixed all), in particular some string
5125 5130 handling stuff which required considering Unicode strings (which
5126 5131 Windows uses). This is good, but hasn't been too tested :) No
5127 5132 fancy installer yet, I'll put a note in the manual so people at
5128 5133 least make manually a shortcut.
5129 5134
5130 5135 * IPython/iplib.py (Magic.magic_colors): Unified the color options
5131 5136 into a single one, "colors". This now controls both prompt and
5132 5137 exception color schemes, and can be changed both at startup
5133 5138 (either via command-line switches or via ipythonrc files) and at
5134 5139 runtime, with @colors.
5135 5140 (Magic.magic_run): renamed @prun to @run and removed the old
5136 5141 @run. The two were too similar to warrant keeping both.
5137 5142
5138 5143 2002-02-03 Fernando Perez <fperez@colorado.edu>
5139 5144
5140 5145 * IPython/iplib.py (install_first_time): Added comment on how to
5141 5146 configure the color options for first-time users. Put a <return>
5142 5147 request at the end so that small-terminal users get a chance to
5143 5148 read the startup info.
5144 5149
5145 5150 2002-01-23 Fernando Perez <fperez@colorado.edu>
5146 5151
5147 5152 * IPython/iplib.py (CachedOutput.update): Changed output memory
5148 5153 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
5149 5154 input history we still use _i. Did this b/c these variable are
5150 5155 very commonly used in interactive work, so the less we need to
5151 5156 type the better off we are.
5152 5157 (Magic.magic_prun): updated @prun to better handle the namespaces
5153 5158 the file will run in, including a fix for __name__ not being set
5154 5159 before.
5155 5160
5156 5161 2002-01-20 Fernando Perez <fperez@colorado.edu>
5157 5162
5158 5163 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
5159 5164 extra garbage for Python 2.2. Need to look more carefully into
5160 5165 this later.
5161 5166
5162 5167 2002-01-19 Fernando Perez <fperez@colorado.edu>
5163 5168
5164 5169 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
5165 5170 display SyntaxError exceptions properly formatted when they occur
5166 5171 (they can be triggered by imported code).
5167 5172
5168 5173 2002-01-18 Fernando Perez <fperez@colorado.edu>
5169 5174
5170 5175 * IPython/iplib.py (InteractiveShell.safe_execfile): now
5171 5176 SyntaxError exceptions are reported nicely formatted, instead of
5172 5177 spitting out only offset information as before.
5173 5178 (Magic.magic_prun): Added the @prun function for executing
5174 5179 programs with command line args inside IPython.
5175 5180
5176 5181 2002-01-16 Fernando Perez <fperez@colorado.edu>
5177 5182
5178 5183 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
5179 5184 to *not* include the last item given in a range. This brings their
5180 5185 behavior in line with Python's slicing:
5181 5186 a[n1:n2] -> a[n1]...a[n2-1]
5182 5187 It may be a bit less convenient, but I prefer to stick to Python's
5183 5188 conventions *everywhere*, so users never have to wonder.
5184 5189 (Magic.magic_macro): Added @macro function to ease the creation of
5185 5190 macros.
5186 5191
5187 5192 2002-01-05 Fernando Perez <fperez@colorado.edu>
5188 5193
5189 5194 * Released 0.2.4.
5190 5195
5191 5196 * IPython/iplib.py (Magic.magic_pdef):
5192 5197 (InteractiveShell.safe_execfile): report magic lines and error
5193 5198 lines without line numbers so one can easily copy/paste them for
5194 5199 re-execution.
5195 5200
5196 5201 * Updated manual with recent changes.
5197 5202
5198 5203 * IPython/iplib.py (Magic.magic_oinfo): added constructor
5199 5204 docstring printing when class? is called. Very handy for knowing
5200 5205 how to create class instances (as long as __init__ is well
5201 5206 documented, of course :)
5202 5207 (Magic.magic_doc): print both class and constructor docstrings.
5203 5208 (Magic.magic_pdef): give constructor info if passed a class and
5204 5209 __call__ info for callable object instances.
5205 5210
5206 5211 2002-01-04 Fernando Perez <fperez@colorado.edu>
5207 5212
5208 5213 * Made deep_reload() off by default. It doesn't always work
5209 5214 exactly as intended, so it's probably safer to have it off. It's
5210 5215 still available as dreload() anyway, so nothing is lost.
5211 5216
5212 5217 2002-01-02 Fernando Perez <fperez@colorado.edu>
5213 5218
5214 5219 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
5215 5220 so I wanted an updated release).
5216 5221
5217 5222 2001-12-27 Fernando Perez <fperez@colorado.edu>
5218 5223
5219 5224 * IPython/iplib.py (InteractiveShell.interact): Added the original
5220 5225 code from 'code.py' for this module in order to change the
5221 5226 handling of a KeyboardInterrupt. This was necessary b/c otherwise
5222 5227 the history cache would break when the user hit Ctrl-C, and
5223 5228 interact() offers no way to add any hooks to it.
5224 5229
5225 5230 2001-12-23 Fernando Perez <fperez@colorado.edu>
5226 5231
5227 5232 * setup.py: added check for 'MANIFEST' before trying to remove
5228 5233 it. Thanks to Sean Reifschneider.
5229 5234
5230 5235 2001-12-22 Fernando Perez <fperez@colorado.edu>
5231 5236
5232 5237 * Released 0.2.2.
5233 5238
5234 5239 * Finished (reasonably) writing the manual. Later will add the
5235 5240 python-standard navigation stylesheets, but for the time being
5236 5241 it's fairly complete. Distribution will include html and pdf
5237 5242 versions.
5238 5243
5239 5244 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
5240 5245 (MayaVi author).
5241 5246
5242 5247 2001-12-21 Fernando Perez <fperez@colorado.edu>
5243 5248
5244 5249 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
5245 5250 good public release, I think (with the manual and the distutils
5246 5251 installer). The manual can use some work, but that can go
5247 5252 slowly. Otherwise I think it's quite nice for end users. Next
5248 5253 summer, rewrite the guts of it...
5249 5254
5250 5255 * Changed format of ipythonrc files to use whitespace as the
5251 5256 separator instead of an explicit '='. Cleaner.
5252 5257
5253 5258 2001-12-20 Fernando Perez <fperez@colorado.edu>
5254 5259
5255 5260 * Started a manual in LyX. For now it's just a quick merge of the
5256 5261 various internal docstrings and READMEs. Later it may grow into a
5257 5262 nice, full-blown manual.
5258 5263
5259 5264 * Set up a distutils based installer. Installation should now be
5260 5265 trivially simple for end-users.
5261 5266
5262 5267 2001-12-11 Fernando Perez <fperez@colorado.edu>
5263 5268
5264 5269 * Released 0.2.0. First public release, announced it at
5265 5270 comp.lang.python. From now on, just bugfixes...
5266 5271
5267 5272 * Went through all the files, set copyright/license notices and
5268 5273 cleaned up things. Ready for release.
5269 5274
5270 5275 2001-12-10 Fernando Perez <fperez@colorado.edu>
5271 5276
5272 5277 * Changed the first-time installer not to use tarfiles. It's more
5273 5278 robust now and less unix-dependent. Also makes it easier for
5274 5279 people to later upgrade versions.
5275 5280
5276 5281 * Changed @exit to @abort to reflect the fact that it's pretty
5277 5282 brutal (a sys.exit()). The difference between @abort and Ctrl-D
5278 5283 becomes significant only when IPyhton is embedded: in that case,
5279 5284 C-D closes IPython only, but @abort kills the enclosing program
5280 5285 too (unless it had called IPython inside a try catching
5281 5286 SystemExit).
5282 5287
5283 5288 * Created Shell module which exposes the actuall IPython Shell
5284 5289 classes, currently the normal and the embeddable one. This at
5285 5290 least offers a stable interface we won't need to change when
5286 5291 (later) the internals are rewritten. That rewrite will be confined
5287 5292 to iplib and ipmaker, but the Shell interface should remain as is.
5288 5293
5289 5294 * Added embed module which offers an embeddable IPShell object,
5290 5295 useful to fire up IPython *inside* a running program. Great for
5291 5296 debugging or dynamical data analysis.
5292 5297
5293 5298 2001-12-08 Fernando Perez <fperez@colorado.edu>
5294 5299
5295 5300 * Fixed small bug preventing seeing info from methods of defined
5296 5301 objects (incorrect namespace in _ofind()).
5297 5302
5298 5303 * Documentation cleanup. Moved the main usage docstrings to a
5299 5304 separate file, usage.py (cleaner to maintain, and hopefully in the
5300 5305 future some perlpod-like way of producing interactive, man and
5301 5306 html docs out of it will be found).
5302 5307
5303 5308 * Added @profile to see your profile at any time.
5304 5309
5305 5310 * Added @p as an alias for 'print'. It's especially convenient if
5306 5311 using automagic ('p x' prints x).
5307 5312
5308 5313 * Small cleanups and fixes after a pychecker run.
5309 5314
5310 5315 * Changed the @cd command to handle @cd - and @cd -<n> for
5311 5316 visiting any directory in _dh.
5312 5317
5313 5318 * Introduced _dh, a history of visited directories. @dhist prints
5314 5319 it out with numbers.
5315 5320
5316 5321 2001-12-07 Fernando Perez <fperez@colorado.edu>
5317 5322
5318 5323 * Released 0.1.22
5319 5324
5320 5325 * Made initialization a bit more robust against invalid color
5321 5326 options in user input (exit, not traceback-crash).
5322 5327
5323 5328 * Changed the bug crash reporter to write the report only in the
5324 5329 user's .ipython directory. That way IPython won't litter people's
5325 5330 hard disks with crash files all over the place. Also print on
5326 5331 screen the necessary mail command.
5327 5332
5328 5333 * With the new ultraTB, implemented LightBG color scheme for light
5329 5334 background terminals. A lot of people like white backgrounds, so I
5330 5335 guess we should at least give them something readable.
5331 5336
5332 5337 2001-12-06 Fernando Perez <fperez@colorado.edu>
5333 5338
5334 5339 * Modified the structure of ultraTB. Now there's a proper class
5335 5340 for tables of color schemes which allow adding schemes easily and
5336 5341 switching the active scheme without creating a new instance every
5337 5342 time (which was ridiculous). The syntax for creating new schemes
5338 5343 is also cleaner. I think ultraTB is finally done, with a clean
5339 5344 class structure. Names are also much cleaner (now there's proper
5340 5345 color tables, no need for every variable to also have 'color' in
5341 5346 its name).
5342 5347
5343 5348 * Broke down genutils into separate files. Now genutils only
5344 5349 contains utility functions, and classes have been moved to their
5345 5350 own files (they had enough independent functionality to warrant
5346 5351 it): ConfigLoader, OutputTrap, Struct.
5347 5352
5348 5353 2001-12-05 Fernando Perez <fperez@colorado.edu>
5349 5354
5350 5355 * IPython turns 21! Released version 0.1.21, as a candidate for
5351 5356 public consumption. If all goes well, release in a few days.
5352 5357
5353 5358 * Fixed path bug (files in Extensions/ directory wouldn't be found
5354 5359 unless IPython/ was explicitly in sys.path).
5355 5360
5356 5361 * Extended the FlexCompleter class as MagicCompleter to allow
5357 5362 completion of @-starting lines.
5358 5363
5359 5364 * Created __release__.py file as a central repository for release
5360 5365 info that other files can read from.
5361 5366
5362 5367 * Fixed small bug in logging: when logging was turned on in
5363 5368 mid-session, old lines with special meanings (!@?) were being
5364 5369 logged without the prepended comment, which is necessary since
5365 5370 they are not truly valid python syntax. This should make session
5366 5371 restores produce less errors.
5367 5372
5368 5373 * The namespace cleanup forced me to make a FlexCompleter class
5369 5374 which is nothing but a ripoff of rlcompleter, but with selectable
5370 5375 namespace (rlcompleter only works in __main__.__dict__). I'll try
5371 5376 to submit a note to the authors to see if this change can be
5372 5377 incorporated in future rlcompleter releases (Dec.6: done)
5373 5378
5374 5379 * More fixes to namespace handling. It was a mess! Now all
5375 5380 explicit references to __main__.__dict__ are gone (except when
5376 5381 really needed) and everything is handled through the namespace
5377 5382 dicts in the IPython instance. We seem to be getting somewhere
5378 5383 with this, finally...
5379 5384
5380 5385 * Small documentation updates.
5381 5386
5382 5387 * Created the Extensions directory under IPython (with an
5383 5388 __init__.py). Put the PhysicalQ stuff there. This directory should
5384 5389 be used for all special-purpose extensions.
5385 5390
5386 5391 * File renaming:
5387 5392 ipythonlib --> ipmaker
5388 5393 ipplib --> iplib
5389 5394 This makes a bit more sense in terms of what these files actually do.
5390 5395
5391 5396 * Moved all the classes and functions in ipythonlib to ipplib, so
5392 5397 now ipythonlib only has make_IPython(). This will ease up its
5393 5398 splitting in smaller functional chunks later.
5394 5399
5395 5400 * Cleaned up (done, I think) output of @whos. Better column
5396 5401 formatting, and now shows str(var) for as much as it can, which is
5397 5402 typically what one gets with a 'print var'.
5398 5403
5399 5404 2001-12-04 Fernando Perez <fperez@colorado.edu>
5400 5405
5401 5406 * Fixed namespace problems. Now builtin/IPyhton/user names get
5402 5407 properly reported in their namespace. Internal namespace handling
5403 5408 is finally getting decent (not perfect yet, but much better than
5404 5409 the ad-hoc mess we had).
5405 5410
5406 5411 * Removed -exit option. If people just want to run a python
5407 5412 script, that's what the normal interpreter is for. Less
5408 5413 unnecessary options, less chances for bugs.
5409 5414
5410 5415 * Added a crash handler which generates a complete post-mortem if
5411 5416 IPython crashes. This will help a lot in tracking bugs down the
5412 5417 road.
5413 5418
5414 5419 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
5415 5420 which were boud to functions being reassigned would bypass the
5416 5421 logger, breaking the sync of _il with the prompt counter. This
5417 5422 would then crash IPython later when a new line was logged.
5418 5423
5419 5424 2001-12-02 Fernando Perez <fperez@colorado.edu>
5420 5425
5421 5426 * Made IPython a package. This means people don't have to clutter
5422 5427 their sys.path with yet another directory. Changed the INSTALL
5423 5428 file accordingly.
5424 5429
5425 5430 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
5426 5431 sorts its output (so @who shows it sorted) and @whos formats the
5427 5432 table according to the width of the first column. Nicer, easier to
5428 5433 read. Todo: write a generic table_format() which takes a list of
5429 5434 lists and prints it nicely formatted, with optional row/column
5430 5435 separators and proper padding and justification.
5431 5436
5432 5437 * Released 0.1.20
5433 5438
5434 5439 * Fixed bug in @log which would reverse the inputcache list (a
5435 5440 copy operation was missing).
5436 5441
5437 5442 * Code cleanup. @config was changed to use page(). Better, since
5438 5443 its output is always quite long.
5439 5444
5440 5445 * Itpl is back as a dependency. I was having too many problems
5441 5446 getting the parametric aliases to work reliably, and it's just
5442 5447 easier to code weird string operations with it than playing %()s
5443 5448 games. It's only ~6k, so I don't think it's too big a deal.
5444 5449
5445 5450 * Found (and fixed) a very nasty bug with history. !lines weren't
5446 5451 getting cached, and the out of sync caches would crash
5447 5452 IPython. Fixed it by reorganizing the prefilter/handlers/logger
5448 5453 division of labor a bit better. Bug fixed, cleaner structure.
5449 5454
5450 5455 2001-12-01 Fernando Perez <fperez@colorado.edu>
5451 5456
5452 5457 * Released 0.1.19
5453 5458
5454 5459 * Added option -n to @hist to prevent line number printing. Much
5455 5460 easier to copy/paste code this way.
5456 5461
5457 5462 * Created global _il to hold the input list. Allows easy
5458 5463 re-execution of blocks of code by slicing it (inspired by Janko's
5459 5464 comment on 'macros').
5460 5465
5461 5466 * Small fixes and doc updates.
5462 5467
5463 5468 * Rewrote @history function (was @h). Renamed it to @hist, @h is
5464 5469 much too fragile with automagic. Handles properly multi-line
5465 5470 statements and takes parameters.
5466 5471
5467 5472 2001-11-30 Fernando Perez <fperez@colorado.edu>
5468 5473
5469 5474 * Version 0.1.18 released.
5470 5475
5471 5476 * Fixed nasty namespace bug in initial module imports.
5472 5477
5473 5478 * Added copyright/license notes to all code files (except
5474 5479 DPyGetOpt). For the time being, LGPL. That could change.
5475 5480
5476 5481 * Rewrote a much nicer README, updated INSTALL, cleaned up
5477 5482 ipythonrc-* samples.
5478 5483
5479 5484 * Overall code/documentation cleanup. Basically ready for
5480 5485 release. Only remaining thing: licence decision (LGPL?).
5481 5486
5482 5487 * Converted load_config to a class, ConfigLoader. Now recursion
5483 5488 control is better organized. Doesn't include the same file twice.
5484 5489
5485 5490 2001-11-29 Fernando Perez <fperez@colorado.edu>
5486 5491
5487 5492 * Got input history working. Changed output history variables from
5488 5493 _p to _o so that _i is for input and _o for output. Just cleaner
5489 5494 convention.
5490 5495
5491 5496 * Implemented parametric aliases. This pretty much allows the
5492 5497 alias system to offer full-blown shell convenience, I think.
5493 5498
5494 5499 * Version 0.1.17 released, 0.1.18 opened.
5495 5500
5496 5501 * dot_ipython/ipythonrc (alias): added documentation.
5497 5502 (xcolor): Fixed small bug (xcolors -> xcolor)
5498 5503
5499 5504 * Changed the alias system. Now alias is a magic command to define
5500 5505 aliases just like the shell. Rationale: the builtin magics should
5501 5506 be there for things deeply connected to IPython's
5502 5507 architecture. And this is a much lighter system for what I think
5503 5508 is the really important feature: allowing users to define quickly
5504 5509 magics that will do shell things for them, so they can customize
5505 5510 IPython easily to match their work habits. If someone is really
5506 5511 desperate to have another name for a builtin alias, they can
5507 5512 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
5508 5513 works.
5509 5514
5510 5515 2001-11-28 Fernando Perez <fperez@colorado.edu>
5511 5516
5512 5517 * Changed @file so that it opens the source file at the proper
5513 5518 line. Since it uses less, if your EDITOR environment is
5514 5519 configured, typing v will immediately open your editor of choice
5515 5520 right at the line where the object is defined. Not as quick as
5516 5521 having a direct @edit command, but for all intents and purposes it
5517 5522 works. And I don't have to worry about writing @edit to deal with
5518 5523 all the editors, less does that.
5519 5524
5520 5525 * Version 0.1.16 released, 0.1.17 opened.
5521 5526
5522 5527 * Fixed some nasty bugs in the page/page_dumb combo that could
5523 5528 crash IPython.
5524 5529
5525 5530 2001-11-27 Fernando Perez <fperez@colorado.edu>
5526 5531
5527 5532 * Version 0.1.15 released, 0.1.16 opened.
5528 5533
5529 5534 * Finally got ? and ?? to work for undefined things: now it's
5530 5535 possible to type {}.get? and get information about the get method
5531 5536 of dicts, or os.path? even if only os is defined (so technically
5532 5537 os.path isn't). Works at any level. For example, after import os,
5533 5538 os?, os.path?, os.path.abspath? all work. This is great, took some
5534 5539 work in _ofind.
5535 5540
5536 5541 * Fixed more bugs with logging. The sanest way to do it was to add
5537 5542 to @log a 'mode' parameter. Killed two in one shot (this mode
5538 5543 option was a request of Janko's). I think it's finally clean
5539 5544 (famous last words).
5540 5545
5541 5546 * Added a page_dumb() pager which does a decent job of paging on
5542 5547 screen, if better things (like less) aren't available. One less
5543 5548 unix dependency (someday maybe somebody will port this to
5544 5549 windows).
5545 5550
5546 5551 * Fixed problem in magic_log: would lock of logging out if log
5547 5552 creation failed (because it would still think it had succeeded).
5548 5553
5549 5554 * Improved the page() function using curses to auto-detect screen
5550 5555 size. Now it can make a much better decision on whether to print
5551 5556 or page a string. Option screen_length was modified: a value 0
5552 5557 means auto-detect, and that's the default now.
5553 5558
5554 5559 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
5555 5560 go out. I'll test it for a few days, then talk to Janko about
5556 5561 licences and announce it.
5557 5562
5558 5563 * Fixed the length of the auto-generated ---> prompt which appears
5559 5564 for auto-parens and auto-quotes. Getting this right isn't trivial,
5560 5565 with all the color escapes, different prompt types and optional
5561 5566 separators. But it seems to be working in all the combinations.
5562 5567
5563 5568 2001-11-26 Fernando Perez <fperez@colorado.edu>
5564 5569
5565 5570 * Wrote a regexp filter to get option types from the option names
5566 5571 string. This eliminates the need to manually keep two duplicate
5567 5572 lists.
5568 5573
5569 5574 * Removed the unneeded check_option_names. Now options are handled
5570 5575 in a much saner manner and it's easy to visually check that things
5571 5576 are ok.
5572 5577
5573 5578 * Updated version numbers on all files I modified to carry a
5574 5579 notice so Janko and Nathan have clear version markers.
5575 5580
5576 5581 * Updated docstring for ultraTB with my changes. I should send
5577 5582 this to Nathan.
5578 5583
5579 5584 * Lots of small fixes. Ran everything through pychecker again.
5580 5585
5581 5586 * Made loading of deep_reload an cmd line option. If it's not too
5582 5587 kosher, now people can just disable it. With -nodeep_reload it's
5583 5588 still available as dreload(), it just won't overwrite reload().
5584 5589
5585 5590 * Moved many options to the no| form (-opt and -noopt
5586 5591 accepted). Cleaner.
5587 5592
5588 5593 * Changed magic_log so that if called with no parameters, it uses
5589 5594 'rotate' mode. That way auto-generated logs aren't automatically
5590 5595 over-written. For normal logs, now a backup is made if it exists
5591 5596 (only 1 level of backups). A new 'backup' mode was added to the
5592 5597 Logger class to support this. This was a request by Janko.
5593 5598
5594 5599 * Added @logoff/@logon to stop/restart an active log.
5595 5600
5596 5601 * Fixed a lot of bugs in log saving/replay. It was pretty
5597 5602 broken. Now special lines (!@,/) appear properly in the command
5598 5603 history after a log replay.
5599 5604
5600 5605 * Tried and failed to implement full session saving via pickle. My
5601 5606 idea was to pickle __main__.__dict__, but modules can't be
5602 5607 pickled. This would be a better alternative to replaying logs, but
5603 5608 seems quite tricky to get to work. Changed -session to be called
5604 5609 -logplay, which more accurately reflects what it does. And if we
5605 5610 ever get real session saving working, -session is now available.
5606 5611
5607 5612 * Implemented color schemes for prompts also. As for tracebacks,
5608 5613 currently only NoColor and Linux are supported. But now the
5609 5614 infrastructure is in place, based on a generic ColorScheme
5610 5615 class. So writing and activating new schemes both for the prompts
5611 5616 and the tracebacks should be straightforward.
5612 5617
5613 5618 * Version 0.1.13 released, 0.1.14 opened.
5614 5619
5615 5620 * Changed handling of options for output cache. Now counter is
5616 5621 hardwired starting at 1 and one specifies the maximum number of
5617 5622 entries *in the outcache* (not the max prompt counter). This is
5618 5623 much better, since many statements won't increase the cache
5619 5624 count. It also eliminated some confusing options, now there's only
5620 5625 one: cache_size.
5621 5626
5622 5627 * Added 'alias' magic function and magic_alias option in the
5623 5628 ipythonrc file. Now the user can easily define whatever names he
5624 5629 wants for the magic functions without having to play weird
5625 5630 namespace games. This gives IPython a real shell-like feel.
5626 5631
5627 5632 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
5628 5633 @ or not).
5629 5634
5630 5635 This was one of the last remaining 'visible' bugs (that I know
5631 5636 of). I think if I can clean up the session loading so it works
5632 5637 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
5633 5638 about licensing).
5634 5639
5635 5640 2001-11-25 Fernando Perez <fperez@colorado.edu>
5636 5641
5637 5642 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
5638 5643 there's a cleaner distinction between what ? and ?? show.
5639 5644
5640 5645 * Added screen_length option. Now the user can define his own
5641 5646 screen size for page() operations.
5642 5647
5643 5648 * Implemented magic shell-like functions with automatic code
5644 5649 generation. Now adding another function is just a matter of adding
5645 5650 an entry to a dict, and the function is dynamically generated at
5646 5651 run-time. Python has some really cool features!
5647 5652
5648 5653 * Renamed many options to cleanup conventions a little. Now all
5649 5654 are lowercase, and only underscores where needed. Also in the code
5650 5655 option name tables are clearer.
5651 5656
5652 5657 * Changed prompts a little. Now input is 'In [n]:' instead of
5653 5658 'In[n]:='. This allows it the numbers to be aligned with the
5654 5659 Out[n] numbers, and removes usage of ':=' which doesn't exist in
5655 5660 Python (it was a Mathematica thing). The '...' continuation prompt
5656 5661 was also changed a little to align better.
5657 5662
5658 5663 * Fixed bug when flushing output cache. Not all _p<n> variables
5659 5664 exist, so their deletion needs to be wrapped in a try:
5660 5665
5661 5666 * Figured out how to properly use inspect.formatargspec() (it
5662 5667 requires the args preceded by *). So I removed all the code from
5663 5668 _get_pdef in Magic, which was just replicating that.
5664 5669
5665 5670 * Added test to prefilter to allow redefining magic function names
5666 5671 as variables. This is ok, since the @ form is always available,
5667 5672 but whe should allow the user to define a variable called 'ls' if
5668 5673 he needs it.
5669 5674
5670 5675 * Moved the ToDo information from README into a separate ToDo.
5671 5676
5672 5677 * General code cleanup and small bugfixes. I think it's close to a
5673 5678 state where it can be released, obviously with a big 'beta'
5674 5679 warning on it.
5675 5680
5676 5681 * Got the magic function split to work. Now all magics are defined
5677 5682 in a separate class. It just organizes things a bit, and now
5678 5683 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
5679 5684 was too long).
5680 5685
5681 5686 * Changed @clear to @reset to avoid potential confusions with
5682 5687 the shell command clear. Also renamed @cl to @clear, which does
5683 5688 exactly what people expect it to from their shell experience.
5684 5689
5685 5690 Added a check to the @reset command (since it's so
5686 5691 destructive, it's probably a good idea to ask for confirmation).
5687 5692 But now reset only works for full namespace resetting. Since the
5688 5693 del keyword is already there for deleting a few specific
5689 5694 variables, I don't see the point of having a redundant magic
5690 5695 function for the same task.
5691 5696
5692 5697 2001-11-24 Fernando Perez <fperez@colorado.edu>
5693 5698
5694 5699 * Updated the builtin docs (esp. the ? ones).
5695 5700
5696 5701 * Ran all the code through pychecker. Not terribly impressed with
5697 5702 it: lots of spurious warnings and didn't really find anything of
5698 5703 substance (just a few modules being imported and not used).
5699 5704
5700 5705 * Implemented the new ultraTB functionality into IPython. New
5701 5706 option: xcolors. This chooses color scheme. xmode now only selects
5702 5707 between Plain and Verbose. Better orthogonality.
5703 5708
5704 5709 * Large rewrite of ultraTB. Much cleaner now, with a separation of
5705 5710 mode and color scheme for the exception handlers. Now it's
5706 5711 possible to have the verbose traceback with no coloring.
5707 5712
5708 5713 2001-11-23 Fernando Perez <fperez@colorado.edu>
5709 5714
5710 5715 * Version 0.1.12 released, 0.1.13 opened.
5711 5716
5712 5717 * Removed option to set auto-quote and auto-paren escapes by
5713 5718 user. The chances of breaking valid syntax are just too high. If
5714 5719 someone *really* wants, they can always dig into the code.
5715 5720
5716 5721 * Made prompt separators configurable.
5717 5722
5718 5723 2001-11-22 Fernando Perez <fperez@colorado.edu>
5719 5724
5720 5725 * Small bugfixes in many places.
5721 5726
5722 5727 * Removed the MyCompleter class from ipplib. It seemed redundant
5723 5728 with the C-p,C-n history search functionality. Less code to
5724 5729 maintain.
5725 5730
5726 5731 * Moved all the original ipython.py code into ipythonlib.py. Right
5727 5732 now it's just one big dump into a function called make_IPython, so
5728 5733 no real modularity has been gained. But at least it makes the
5729 5734 wrapper script tiny, and since ipythonlib is a module, it gets
5730 5735 compiled and startup is much faster.
5731 5736
5732 5737 This is a reasobably 'deep' change, so we should test it for a
5733 5738 while without messing too much more with the code.
5734 5739
5735 5740 2001-11-21 Fernando Perez <fperez@colorado.edu>
5736 5741
5737 5742 * Version 0.1.11 released, 0.1.12 opened for further work.
5738 5743
5739 5744 * Removed dependency on Itpl. It was only needed in one place. It
5740 5745 would be nice if this became part of python, though. It makes life
5741 5746 *a lot* easier in some cases.
5742 5747
5743 5748 * Simplified the prefilter code a bit. Now all handlers are
5744 5749 expected to explicitly return a value (at least a blank string).
5745 5750
5746 5751 * Heavy edits in ipplib. Removed the help system altogether. Now
5747 5752 obj?/?? is used for inspecting objects, a magic @doc prints
5748 5753 docstrings, and full-blown Python help is accessed via the 'help'
5749 5754 keyword. This cleans up a lot of code (less to maintain) and does
5750 5755 the job. Since 'help' is now a standard Python component, might as
5751 5756 well use it and remove duplicate functionality.
5752 5757
5753 5758 Also removed the option to use ipplib as a standalone program. By
5754 5759 now it's too dependent on other parts of IPython to function alone.
5755 5760
5756 5761 * Fixed bug in genutils.pager. It would crash if the pager was
5757 5762 exited immediately after opening (broken pipe).
5758 5763
5759 5764 * Trimmed down the VerboseTB reporting a little. The header is
5760 5765 much shorter now and the repeated exception arguments at the end
5761 5766 have been removed. For interactive use the old header seemed a bit
5762 5767 excessive.
5763 5768
5764 5769 * Fixed small bug in output of @whos for variables with multi-word
5765 5770 types (only first word was displayed).
5766 5771
5767 5772 2001-11-17 Fernando Perez <fperez@colorado.edu>
5768 5773
5769 5774 * Version 0.1.10 released, 0.1.11 opened for further work.
5770 5775
5771 5776 * Modified dirs and friends. dirs now *returns* the stack (not
5772 5777 prints), so one can manipulate it as a variable. Convenient to
5773 5778 travel along many directories.
5774 5779
5775 5780 * Fixed bug in magic_pdef: would only work with functions with
5776 5781 arguments with default values.
5777 5782
5778 5783 2001-11-14 Fernando Perez <fperez@colorado.edu>
5779 5784
5780 5785 * Added the PhysicsInput stuff to dot_ipython so it ships as an
5781 5786 example with IPython. Various other minor fixes and cleanups.
5782 5787
5783 5788 * Version 0.1.9 released, 0.1.10 opened for further work.
5784 5789
5785 5790 * Added sys.path to the list of directories searched in the
5786 5791 execfile= option. It used to be the current directory and the
5787 5792 user's IPYTHONDIR only.
5788 5793
5789 5794 2001-11-13 Fernando Perez <fperez@colorado.edu>
5790 5795
5791 5796 * Reinstated the raw_input/prefilter separation that Janko had
5792 5797 initially. This gives a more convenient setup for extending the
5793 5798 pre-processor from the outside: raw_input always gets a string,
5794 5799 and prefilter has to process it. We can then redefine prefilter
5795 5800 from the outside and implement extensions for special
5796 5801 purposes.
5797 5802
5798 5803 Today I got one for inputting PhysicalQuantity objects
5799 5804 (from Scientific) without needing any function calls at
5800 5805 all. Extremely convenient, and it's all done as a user-level
5801 5806 extension (no IPython code was touched). Now instead of:
5802 5807 a = PhysicalQuantity(4.2,'m/s**2')
5803 5808 one can simply say
5804 5809 a = 4.2 m/s**2
5805 5810 or even
5806 5811 a = 4.2 m/s^2
5807 5812
5808 5813 I use this, but it's also a proof of concept: IPython really is
5809 5814 fully user-extensible, even at the level of the parsing of the
5810 5815 command line. It's not trivial, but it's perfectly doable.
5811 5816
5812 5817 * Added 'add_flip' method to inclusion conflict resolver. Fixes
5813 5818 the problem of modules being loaded in the inverse order in which
5814 5819 they were defined in
5815 5820
5816 5821 * Version 0.1.8 released, 0.1.9 opened for further work.
5817 5822
5818 5823 * Added magics pdef, source and file. They respectively show the
5819 5824 definition line ('prototype' in C), source code and full python
5820 5825 file for any callable object. The object inspector oinfo uses
5821 5826 these to show the same information.
5822 5827
5823 5828 * Version 0.1.7 released, 0.1.8 opened for further work.
5824 5829
5825 5830 * Separated all the magic functions into a class called Magic. The
5826 5831 InteractiveShell class was becoming too big for Xemacs to handle
5827 5832 (de-indenting a line would lock it up for 10 seconds while it
5828 5833 backtracked on the whole class!)
5829 5834
5830 5835 FIXME: didn't work. It can be done, but right now namespaces are
5831 5836 all messed up. Do it later (reverted it for now, so at least
5832 5837 everything works as before).
5833 5838
5834 5839 * Got the object introspection system (magic_oinfo) working! I
5835 5840 think this is pretty much ready for release to Janko, so he can
5836 5841 test it for a while and then announce it. Pretty much 100% of what
5837 5842 I wanted for the 'phase 1' release is ready. Happy, tired.
5838 5843
5839 5844 2001-11-12 Fernando Perez <fperez@colorado.edu>
5840 5845
5841 5846 * Version 0.1.6 released, 0.1.7 opened for further work.
5842 5847
5843 5848 * Fixed bug in printing: it used to test for truth before
5844 5849 printing, so 0 wouldn't print. Now checks for None.
5845 5850
5846 5851 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
5847 5852 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
5848 5853 reaches by hand into the outputcache. Think of a better way to do
5849 5854 this later.
5850 5855
5851 5856 * Various small fixes thanks to Nathan's comments.
5852 5857
5853 5858 * Changed magic_pprint to magic_Pprint. This way it doesn't
5854 5859 collide with pprint() and the name is consistent with the command
5855 5860 line option.
5856 5861
5857 5862 * Changed prompt counter behavior to be fully like
5858 5863 Mathematica's. That is, even input that doesn't return a result
5859 5864 raises the prompt counter. The old behavior was kind of confusing
5860 5865 (getting the same prompt number several times if the operation
5861 5866 didn't return a result).
5862 5867
5863 5868 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
5864 5869
5865 5870 * Fixed -Classic mode (wasn't working anymore).
5866 5871
5867 5872 * Added colored prompts using Nathan's new code. Colors are
5868 5873 currently hardwired, they can be user-configurable. For
5869 5874 developers, they can be chosen in file ipythonlib.py, at the
5870 5875 beginning of the CachedOutput class def.
5871 5876
5872 5877 2001-11-11 Fernando Perez <fperez@colorado.edu>
5873 5878
5874 5879 * Version 0.1.5 released, 0.1.6 opened for further work.
5875 5880
5876 5881 * Changed magic_env to *return* the environment as a dict (not to
5877 5882 print it). This way it prints, but it can also be processed.
5878 5883
5879 5884 * Added Verbose exception reporting to interactive
5880 5885 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
5881 5886 traceback. Had to make some changes to the ultraTB file. This is
5882 5887 probably the last 'big' thing in my mental todo list. This ties
5883 5888 in with the next entry:
5884 5889
5885 5890 * Changed -Xi and -Xf to a single -xmode option. Now all the user
5886 5891 has to specify is Plain, Color or Verbose for all exception
5887 5892 handling.
5888 5893
5889 5894 * Removed ShellServices option. All this can really be done via
5890 5895 the magic system. It's easier to extend, cleaner and has automatic
5891 5896 namespace protection and documentation.
5892 5897
5893 5898 2001-11-09 Fernando Perez <fperez@colorado.edu>
5894 5899
5895 5900 * Fixed bug in output cache flushing (missing parameter to
5896 5901 __init__). Other small bugs fixed (found using pychecker).
5897 5902
5898 5903 * Version 0.1.4 opened for bugfixing.
5899 5904
5900 5905 2001-11-07 Fernando Perez <fperez@colorado.edu>
5901 5906
5902 5907 * Version 0.1.3 released, mainly because of the raw_input bug.
5903 5908
5904 5909 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
5905 5910 and when testing for whether things were callable, a call could
5906 5911 actually be made to certain functions. They would get called again
5907 5912 once 'really' executed, with a resulting double call. A disaster
5908 5913 in many cases (list.reverse() would never work!).
5909 5914
5910 5915 * Removed prefilter() function, moved its code to raw_input (which
5911 5916 after all was just a near-empty caller for prefilter). This saves
5912 5917 a function call on every prompt, and simplifies the class a tiny bit.
5913 5918
5914 5919 * Fix _ip to __ip name in magic example file.
5915 5920
5916 5921 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
5917 5922 work with non-gnu versions of tar.
5918 5923
5919 5924 2001-11-06 Fernando Perez <fperez@colorado.edu>
5920 5925
5921 5926 * Version 0.1.2. Just to keep track of the recent changes.
5922 5927
5923 5928 * Fixed nasty bug in output prompt routine. It used to check 'if
5924 5929 arg != None...'. Problem is, this fails if arg implements a
5925 5930 special comparison (__cmp__) which disallows comparing to
5926 5931 None. Found it when trying to use the PhysicalQuantity module from
5927 5932 ScientificPython.
5928 5933
5929 5934 2001-11-05 Fernando Perez <fperez@colorado.edu>
5930 5935
5931 5936 * Also added dirs. Now the pushd/popd/dirs family functions
5932 5937 basically like the shell, with the added convenience of going home
5933 5938 when called with no args.
5934 5939
5935 5940 * pushd/popd slightly modified to mimic shell behavior more
5936 5941 closely.
5937 5942
5938 5943 * Added env,pushd,popd from ShellServices as magic functions. I
5939 5944 think the cleanest will be to port all desired functions from
5940 5945 ShellServices as magics and remove ShellServices altogether. This
5941 5946 will provide a single, clean way of adding functionality
5942 5947 (shell-type or otherwise) to IP.
5943 5948
5944 5949 2001-11-04 Fernando Perez <fperez@colorado.edu>
5945 5950
5946 5951 * Added .ipython/ directory to sys.path. This way users can keep
5947 5952 customizations there and access them via import.
5948 5953
5949 5954 2001-11-03 Fernando Perez <fperez@colorado.edu>
5950 5955
5951 5956 * Opened version 0.1.1 for new changes.
5952 5957
5953 5958 * Changed version number to 0.1.0: first 'public' release, sent to
5954 5959 Nathan and Janko.
5955 5960
5956 5961 * Lots of small fixes and tweaks.
5957 5962
5958 5963 * Minor changes to whos format. Now strings are shown, snipped if
5959 5964 too long.
5960 5965
5961 5966 * Changed ShellServices to work on __main__ so they show up in @who
5962 5967
5963 5968 * Help also works with ? at the end of a line:
5964 5969 ?sin and sin?
5965 5970 both produce the same effect. This is nice, as often I use the
5966 5971 tab-complete to find the name of a method, but I used to then have
5967 5972 to go to the beginning of the line to put a ? if I wanted more
5968 5973 info. Now I can just add the ? and hit return. Convenient.
5969 5974
5970 5975 2001-11-02 Fernando Perez <fperez@colorado.edu>
5971 5976
5972 5977 * Python version check (>=2.1) added.
5973 5978
5974 5979 * Added LazyPython documentation. At this point the docs are quite
5975 5980 a mess. A cleanup is in order.
5976 5981
5977 5982 * Auto-installer created. For some bizarre reason, the zipfiles
5978 5983 module isn't working on my system. So I made a tar version
5979 5984 (hopefully the command line options in various systems won't kill
5980 5985 me).
5981 5986
5982 5987 * Fixes to Struct in genutils. Now all dictionary-like methods are
5983 5988 protected (reasonably).
5984 5989
5985 5990 * Added pager function to genutils and changed ? to print usage
5986 5991 note through it (it was too long).
5987 5992
5988 5993 * Added the LazyPython functionality. Works great! I changed the
5989 5994 auto-quote escape to ';', it's on home row and next to '. But
5990 5995 both auto-quote and auto-paren (still /) escapes are command-line
5991 5996 parameters.
5992 5997
5993 5998
5994 5999 2001-11-01 Fernando Perez <fperez@colorado.edu>
5995 6000
5996 6001 * Version changed to 0.0.7. Fairly large change: configuration now
5997 6002 is all stored in a directory, by default .ipython. There, all
5998 6003 config files have normal looking names (not .names)
5999 6004
6000 6005 * Version 0.0.6 Released first to Lucas and Archie as a test
6001 6006 run. Since it's the first 'semi-public' release, change version to
6002 6007 > 0.0.6 for any changes now.
6003 6008
6004 6009 * Stuff I had put in the ipplib.py changelog:
6005 6010
6006 6011 Changes to InteractiveShell:
6007 6012
6008 6013 - Made the usage message a parameter.
6009 6014
6010 6015 - Require the name of the shell variable to be given. It's a bit
6011 6016 of a hack, but allows the name 'shell' not to be hardwired in the
6012 6017 magic (@) handler, which is problematic b/c it requires
6013 6018 polluting the global namespace with 'shell'. This in turn is
6014 6019 fragile: if a user redefines a variable called shell, things
6015 6020 break.
6016 6021
6017 6022 - magic @: all functions available through @ need to be defined
6018 6023 as magic_<name>, even though they can be called simply as
6019 6024 @<name>. This allows the special command @magic to gather
6020 6025 information automatically about all existing magic functions,
6021 6026 even if they are run-time user extensions, by parsing the shell
6022 6027 instance __dict__ looking for special magic_ names.
6023 6028
6024 6029 - mainloop: added *two* local namespace parameters. This allows
6025 6030 the class to differentiate between parameters which were there
6026 6031 before and after command line initialization was processed. This
6027 6032 way, later @who can show things loaded at startup by the
6028 6033 user. This trick was necessary to make session saving/reloading
6029 6034 really work: ideally after saving/exiting/reloading a session,
6030 6035 *everything* should look the same, including the output of @who. I
6031 6036 was only able to make this work with this double namespace
6032 6037 trick.
6033 6038
6034 6039 - added a header to the logfile which allows (almost) full
6035 6040 session restoring.
6036 6041
6037 6042 - prepend lines beginning with @ or !, with a and log
6038 6043 them. Why? !lines: may be useful to know what you did @lines:
6039 6044 they may affect session state. So when restoring a session, at
6040 6045 least inform the user of their presence. I couldn't quite get
6041 6046 them to properly re-execute, but at least the user is warned.
6042 6047
6043 6048 * Started ChangeLog.
General Comments 0
You need to be logged in to leave comments. Login now